git.delta.rocks / unique-network / refs/commits / f92119204848

difftreelog

source

js-packages/scripts/benchmarks/utils/common.ts2.6 KiBsourcehistory
1import {EthUniqueHelper} from '@unique/tests/eth/util/playgrounds/unique.dev.js';2import {UniqueNFTCollection, UniqueRFTCollection} from '@unique-nft/playgrounds/unique.js';3import type {ITokenPropertyPermission, TCollectionMode} from '@unique-nft/playgrounds/types.js';4import type {IKeyringPair} from '@polkadot/types/types';56export const PROPERTIES = Array(40)7  .fill(0)8  .map((_, i) => ({9    key: `key_${i}`,10    value: Uint8Array.from(Buffer.from(`value_${i}`)),11  }));1213export const SUBS_PROPERTIES = Array(40)14  .fill(0)15  .map((_, i) => ({16    key: `key_${i}`,17    value: `value_${i}`,18  }));1920export const PERMISSIONS: ITokenPropertyPermission[] = PROPERTIES.map((p) => ({21  key: p.key,22  permission: {23    tokenOwner: true,24    collectionAdmin: true,25    mutable: true,26  },27}));2829export function convertToTokens(value: bigint, nominal = 1000_000_000_000_000_000n): number {30  return Number((value * 1000n) / nominal) / 1000;31}3233export async function createCollectionForBenchmarks(34  mode : TCollectionMode,35  helper: EthUniqueHelper,36  privateKey: (seed: string) => Promise<IKeyringPair>,37  ethSigner: string,38  proxyContract: string | null,39  permissions: ITokenPropertyPermission[],40) {41  const donor = await privateKey('//Alice');4243  const collection = await helper[mode].mintCollection(donor, {44    name: 'test mintToSubstrate',45    description: 'EVMHelpers',46    tokenPrefix: mode,47    ...(mode != 'ft' ? {48      tokenPropertyPermissions: [49        {50          key: 'url',51          permission: {52            tokenOwner: true,53            collectionAdmin: true,54            mutable: true,55          },56        },57        {58          key: 'URI',59          permission: {60            tokenOwner: true,61            collectionAdmin: true,62            mutable: true,63          },64        },65      ],66    } : {}),67    limits: {sponsorTransferTimeout: 0, sponsorApproveTimeout: 0},68    permissions: {mintMode: true},69  });7071  await collection.addToAllowList(donor, {72    Ethereum: helper.address.substrateToEth(donor.address),73  });74  await collection.addToAllowList(donor, {Substrate: donor.address});75  await collection.addAdmin(donor, {Ethereum: ethSigner});76  await collection.addAdmin(donor, {77    Ethereum: helper.address.substrateToEth(donor.address),78  });7980  if(proxyContract) {81    await collection.addToAllowList(donor, {Ethereum: proxyContract});82    await collection.addAdmin(donor, {Ethereum: proxyContract});83  }84  if(collection instanceof UniqueNFTCollection || collection instanceof UniqueRFTCollection)85    await collection.setTokenPropertyPermissions(donor, permissions);8687  return collection;88}