Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small utility improvements #592

Merged
merged 7 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Instantiable.abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface InstantiableConfig {
circuitsFolder?: string
}

export async function generateIntantiableConfigFromConfig(
export async function generateInstantiableConfigFromConfig(
config: NeverminedOptions,
): Promise<Partial<InstantiableConfig>> {
const logLevel =
Expand Down
4 changes: 2 additions & 2 deletions src/keeper/Keeper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class Keeper extends Instantiable {
nftSalesTemplate: NFTSalesTemplate.getInstance(this.instanceConfig),
nft721SalesTemplate: NFT721SalesTemplate.getInstance(this.instanceConfig),
standardRoyalties: StandardRoyalties.getInstance(this.instanceConfig), // optional
rewardsDistributor: RewardsDistributor.getInstance(this.instanceConfig),
rewardsDistributor: undefined, // RewardsDistributor.getInstance(this.instanceConfig), // optional
nftUpgradeable: Nft1155Contract.getInstance(this.instanceConfig),
})

Expand All @@ -125,7 +125,7 @@ export class Keeper extends Instantiable {
curve: undefined,
}

this.rewardsDistributor = this.instances.rewardsDistributor
this.rewardsDistributor = undefined // this.instances.rewardsDistributor

const templates = [
this.instances.accessTemplate,
Expand Down
5 changes: 4 additions & 1 deletion src/keeper/contracts/NFTContractsBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class NFTContractsBase extends ContractBase {
* @returns Contract Receipt
*/
protected async _createClone(
ercType: 721 | 1155,
name: string,
symbol: string,
uri: string,
Expand All @@ -43,7 +44,9 @@ export class NFTContractsBase extends ContractBase {
try {
const contractReceipt: ContractTransactionReceipt = await this.sendFrom(
'createClone',
cap ? [name, symbol, uri, String(cap), operators] : [name, symbol, uri, operators],
ercType === 721
? [name, symbol, uri, String(cap), operators]
: [name, symbol, uri, operators],
from,
txParams,
)
Expand Down
2 changes: 1 addition & 1 deletion src/keeper/contracts/Nft1155Contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class Nft1155Contract extends NFTContractsBase {
from?: Account,
txParams?: TxParameters,
) {
return this._createClone(name, symbol, uri, undefined, operators, from, txParams)
return this._createClone(1155, name, symbol, uri, undefined, operators, from, txParams)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/keeper/contracts/Nft721Contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class Nft721Contract extends NFTContractsBase {
from?: Account,
txParams?: TxParameters,
) {
return this._createClone(name, symbol, uri, cap, operators, from, txParams)
return this._createClone(721, name, symbol, uri, cap, operators, from, txParams)
}

public async mint(did: string, from: string, txParams?: TxParameters) {
Expand Down
4 changes: 2 additions & 2 deletions src/nevermined/Nevermined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ProvenanceApi } from './api/ProvenanceApi'
import { UtilsApi } from './api/UtilsApi'
import { Keeper, CustomToken, Nft1155Contract, Nft721Contract } from '../keeper'
import { NeverminedOptions } from '../models'
import { Instantiable, generateIntantiableConfigFromConfig } from '../Instantiable.abstract'
import { Instantiable, generateInstantiableConfigFromConfig } from '../Instantiable.abstract'
import { NFT1155Api } from './api/nfts/NFT1155Api'
import { NFT721Api } from './api/nfts/NFT721Api'
import { SearchApi } from './api/SearchApi'
Expand Down Expand Up @@ -35,7 +35,7 @@ export class Nevermined extends Instantiable {
const instance = new Nevermined()

const instanceConfig = {
...(await generateIntantiableConfigFromConfig(config)),
...(await generateInstantiableConfigFromConfig(config)),
nevermined: instance,
}
instance.setInstanceConfig(instanceConfig)
Expand Down
12 changes: 10 additions & 2 deletions src/utils/MakeAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { Mnemonic, ethers, getIndexedAccountPath } from 'ethers'

export function makeAccounts(seedphrase: string): ethers.Wallet[] {
export function makeAccounts(seedphrase: string, numAccounts = 10): ethers.Wallet[] {
const mnemonic = Mnemonic.fromPhrase(seedphrase)
const node = ethers.HDNodeWallet.fromSeed(mnemonic.computeSeed())
const accounts: ethers.Wallet[] = []

for (let i = 0; i < 10; i++) {
for (let i = 0; i < numAccounts; i++) {
const acc = node.derivePath(getIndexedAccountPath(i))
const wallet = new ethers.Wallet(acc.privateKey)
accounts.push(wallet)
}
return accounts
}

export function makeAccount(seedphrase: string, accountIndex: number = 0): ethers.Wallet {
const mnemonic = Mnemonic.fromPhrase(seedphrase)
const node = ethers.HDNodeWallet.fromSeed(mnemonic.computeSeed())

const acc = node.derivePath(getIndexedAccountPath(accountIndex))
return new ethers.Wallet(acc.privateKey)
}