difftreelog
Fix error
in: master
6 files changed
.envdiffbeforeafterboth--- a/.env
+++ b/.env
@@ -1,7 +1,7 @@
RUST_TOOLCHAIN=nightly-2022-11-15
POLKADOT_BUILD_BRANCH=release-v0.9.37
POLKADOT_LAUNCH_BRANCH=unique-network
-RELAY_CHAIN_TYPE=westend
+RELAY_CHAIN_TYPE=rococo
POLKADOT_MAINNET_BRANCH=release-v0.9.37
STATEMINT_BUILD_BRANCH=release-parachains-v9370
tests/src/benchmarks/mintFee/index.tsdiffbeforeafterboth--- a/tests/src/benchmarks/mintFee/index.ts
+++ b/tests/src/benchmarks/mintFee/index.ts
@@ -8,7 +8,7 @@
import {Contract} from 'web3-eth-contract';
import {createObjectCsvWriter} from 'csv-writer';
import {convertToTokens, createCollectionForBenchmarks, PERMISSIONS, PROPERTIES} from '../utils/common';
-import {makeNames} from '../utils';
+import {makeNames} from '../../util';
import {ContractImports} from '../../eth/util/playgrounds/types';
const {dirname} = makeNames(import.meta.url);
tests/src/benchmarks/opsFee/index.tsdiffbeforeafterboth1import {EthUniqueHelper, usingEthPlaygrounds} from '../../eth/util';2import {readFile} from 'fs/promises';3import {CollectionLimitField, TokenPermissionField} from '../../eth/util/playgrounds/types';4import {IKeyringPair} from '@polkadot/types/types';5import {UniqueFTCollection, UniqueNFTCollection} from '../../util/playgrounds/unique';6import {Contract} from 'web3-eth-contract';7import {createObjectCsvWriter} from 'csv-writer';8import {FunctionFeeVM, IFunctionFee} from '../utils/types';9import {convertToTokens, createCollectionForBenchmarks, PERMISSIONS, PROPERTIES, SUBS_PROPERTIES} from '../utils/common';10111213const main = async () => {1415 const headers = [16 'function',17 'ethFee',18 'ethGas',19 'substrate',20 'zeppelinFee',21 'zeppelinGas',22 ];2324 const csvWriter20 = createObjectCsvWriter({25 path: 'erc20.csv',26 header: headers,27 });2829 const csvWriter721 = createObjectCsvWriter({30 path: 'erc721.csv',31 header: headers,32 });3334 await usingEthPlaygrounds(async (helper, privateKey) => {35 console.log('\n ERC20 ops fees');36 const erc20 = FunctionFeeVM.fromModel(await erc20CalculateFeeGas(helper, privateKey));37 console.table(erc20);38 await csvWriter20.writeRecords(FunctionFeeVM.toCsv(erc20));3940 console.log('\n ERC721 ops fees');41 const erc721 = FunctionFeeVM.fromModel(await erc721CalculateFeeGas(helper, privateKey));42 console.table(erc721);4344 await csvWriter721.writeRecords(FunctionFeeVM.toCsv(erc721));45 });46};4748main()49 .then(() => process.exit(0))50 .catch((e) => {51 console.log(e);52 process.exit(1);53 });5455async function erc721CalculateFeeGas(56 helper: EthUniqueHelper,57 privateKey: (seed: string) => Promise<IKeyringPair>,58): Promise<IFunctionFee> {59 const res: IFunctionFee = {};60 const donor = await privateKey('//Alice');61 const [subReceiver] = await helper.arrange.createAccounts([10n], donor);62 const ethSigner = await helper.eth.createAccountWithBalance(donor, 100n);63 const ethReceiver = await helper.eth.createAccountWithBalance(donor, 10n);64 const crossSigner = helper.ethCrossAccount.fromAddress(ethSigner);65 const crossReceiver = helper.ethCrossAccount.fromAddress(ethReceiver);66 const collection = (await createCollectionForBenchmarks(67 'nft',68 helper,69 privateKey,70 ethSigner,71 null,72 PERMISSIONS,73 )) as UniqueNFTCollection;7475 const helperContract = await helper.ethNativeContract.collectionHelpers(ethSigner);76 let zeppelelinContract: Contract | null = null;77 const ZEPPELIN_OBJECT = '0x' + (await readFile(`${dirname}/../utils/openZeppelin/ERC721/bin/ZeppelinContract.bin`)).toString();78 const ZEPPELIN_ABI = JSON.parse((await readFile(`${dirname}/../utils/openZeppelin/ERC721/bin/ZeppelinContract.abi`)).toString());7980 const evmContract = await helper.ethNativeContract.collection(81 helper.ethAddress.fromCollectionId(collection.collectionId),82 'nft',83 ethSigner,84 true,85 );8687 res['createCollection'] = await helper.arrange.calculcateFeeGas(88 {Ethereum: ethSigner},89 () => helperContract.methods.createNFTCollection('test','test','test').send({from: ethSigner, value: Number(2n * helper.balance.getOneTokenNominal())}),90 );9192 res['createCollection'].substrate = convertToTokens((await helper.arrange.calculcateFee(93 {Substrate: donor.address},94 () => helper.nft.mintCollection(95 donor,96 {name: 'test', description: 'test', tokenPrefix: 'test'},97 ),98 )));99100 res['createCollection'].zeppelin = await helper.arrange.calculcateFeeGas(101 {Ethereum: ethSigner},102 async () => {103 zeppelelinContract = await helper.ethContract.deployByAbi(104 ethSigner,105 ZEPPELIN_ABI,106 ZEPPELIN_OBJECT,107 );108 },109 );110111 res['mint'] =112 await helper.arrange.calculcateFeeGas(113 {Ethereum: ethSigner},114 () => evmContract.methods.mint(ethSigner).send(),115 );116117 res['mint'].zeppelin =118 await helper.arrange.calculcateFeeGas(119 {Ethereum: ethSigner},120 () => zeppelelinContract!.methods.safeMint(ethSigner, '').send({from: ethSigner}),121 );122123 res['mintCross'] =124 await helper.arrange.calculcateFeeGas(125 {Ethereum: ethSigner},126 () => evmContract.methods.mintCross(crossSigner, []).send(),127 );128129 res['mint'].substrate = convertToTokens((await helper.arrange.calculcateFee(130 {Substrate: donor.address},131 () => collection.mintToken(132 donor,133 {Substrate: donor.address},134 ),135 )));136137 res['mintCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(138 {Substrate: donor.address},139 () => collection.mintMultipleTokens(donor, [{140 owner: {Substrate: donor.address},141 }]),142 )));143144 res['mintWithTokenURI'] =145 await helper.arrange.calculcateFeeGas(146 {Ethereum: ethSigner},147 () => evmContract.methods.mintWithTokenURI(ethSigner, 'Test URI').send(),148 );149150 res['mintWithTokenURI'].substrate = convertToTokens((await helper.arrange.calculcateFee(151 {Substrate: donor.address},152 () => collection.mintToken(153 donor,154 {Ethereum: ethSigner},155 [{key: 'URI', value: 'Test URI'}],156 ),157 )));158159 res['mintWithTokenURI'].zeppelin =160 await helper.arrange.calculcateFeeGas(161 {Ethereum: ethSigner},162 () => zeppelelinContract!.methods.safeMint(ethSigner, 'Test URI').send({from: ethSigner}),163 );164165 res['setProperties'] =166 await helper.arrange.calculcateFeeGas(167 {Ethereum: ethSigner},168 () => evmContract.methods.setProperties(1, PROPERTIES.slice(0,1)).send(),169 );170171 res['deleteProperties'] =172 await helper.arrange.calculcateFeeGas(173 {Ethereum: ethSigner},174 () => evmContract.methods.deleteProperties(1, [PROPERTIES[0].key]).send(),175 );176177 res['setProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(178 {Substrate: donor.address},179 () => collection.setTokenProperties(180 donor,181 1,182 SUBS_PROPERTIES.slice(0, 1),183 ),184 )));185186 res['deleteProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(187 {Substrate: donor.address},188 () => collection.deleteTokenProperties(189 donor,190 1,191 SUBS_PROPERTIES.slice(0, 1)192 .map(p => p.key),193 ),194 )));195196 res['transfer'] =197 await helper.arrange.calculcateFeeGas(198 {Ethereum: ethSigner},199 () => evmContract.methods.transfer(ethReceiver, 1).send(),200 );201202 res['safeTransferFrom*'] = {203 zeppelin:204 await helper.arrange.calculcateFeeGas(205 {Ethereum: ethSigner},206 () => zeppelelinContract!.methods.safeTransferFrom(ethSigner, ethReceiver, 0).send({from: ethSigner}),207 ),208 };209210 res['transferCross'] =211 await helper.arrange.calculcateFeeGas(212 {Ethereum: ethReceiver},213 () => evmContract.methods.transferCross(crossSigner, 1).send({from: ethReceiver}),214 );215216 res['transferCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(217 {Substrate: donor.address},218 () => collection.transferToken(219 donor,220 3,221 {Substrate: subReceiver.address},222 ),223 )));224 await collection.approveToken(subReceiver, 3, {Substrate: donor.address});225226 res['transferFrom*'] =227 await helper.arrange.calculcateFeeGas(228 {Ethereum: ethSigner},229 () => evmContract.methods.transferFrom(ethSigner, ethReceiver, 1).send(),230 );231232 res['transferFrom*'].zeppelin =233 await helper.arrange.calculcateFeeGas(234 {Ethereum: ethReceiver},235 () => zeppelelinContract!.methods.transferFrom(ethReceiver, ethSigner, 0).send({from: ethReceiver}),236 );237238239 res['transferFromCross'] =240 await helper.arrange.calculcateFeeGas(241 {Ethereum: ethReceiver},242 () => evmContract.methods.transferFromCross(crossReceiver, crossSigner, 1).send({from:ethReceiver}),243 );244245 res['transferFromCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(246 {Substrate: donor.address},247 () => collection.transferTokenFrom(donor, 3, {Substrate: subReceiver.address}, {Substrate: donor.address}),248 )));249250 res['burn'] =251 await helper.arrange.calculcateFeeGas(252 {Ethereum: ethSigner},253 () => evmContract.methods.burn(1).send(),254 );255256 res['burn'].substrate = convertToTokens((await helper.arrange.calculcateFee(257 {Substrate: donor.address},258 () => collection.burnToken(donor, 3),259 )));260261 res['approve*'] =262 await helper.arrange.calculcateFeeGas(263 {Ethereum: ethSigner},264 () => evmContract.methods.approve(ethReceiver, 2).send(),265 );266267 res['approve*'].zeppelin =268 await helper.arrange.calculcateFeeGas(269 {Ethereum: ethSigner},270 () => zeppelelinContract!.methods.approve(ethReceiver, 0).send({from: ethSigner}),271 );272273 res['approveCross'] =274 await helper.arrange.calculcateFeeGas(275 {Ethereum: ethSigner},276 () => evmContract.methods.approveCross(crossReceiver, 2).send(),277 );278279 res['approveCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(280 {Substrate: donor.address},281 () => collection.approveToken(donor, 4, {Substrate: subReceiver.address}),282 )));283284 res['setApprovalForAll*'] =285 await helper.arrange.calculcateFeeGas(286 {Ethereum: ethSigner},287 () => evmContract.methods.setApprovalForAll(ethReceiver, true).send(),288 );289290 res['setApprovalForAll*'].zeppelin =291 await helper.arrange.calculcateFeeGas(292 {Ethereum: ethSigner},293 () => zeppelelinContract!.methods.setApprovalForAll(ethReceiver, true).send({from: ethSigner}),294 );295296 res['setApprovalForAll*'].substrate = convertToTokens((await helper.arrange.calculcateFee(297 {Substrate: donor.address},298 () => helper.nft.setAllowanceForAll(donor, collection.collectionId, {Substrate: subReceiver.address}, true),299 )));300301 res['burnFromCross'] =302 await helper.arrange.calculcateFeeGas(303 {Ethereum: ethReceiver},304 () => evmContract.methods.burnFromCross(crossSigner, 2).send({from:ethReceiver}),305 );306307 res['burnFromCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(308 {Substrate: subReceiver.address},309 () => collection.burnTokenFrom(subReceiver, 4, {Substrate: donor.address}),310 )));311312 res['setTokenPropertyPermissions'] =313 await helper.arrange.calculcateFeeGas(314 {Ethereum: ethSigner},315 () => evmContract.methods.setTokenPropertyPermissions([316 ['url', [317 [TokenPermissionField.Mutable, true],318 [TokenPermissionField.TokenOwner, true],319 [TokenPermissionField.CollectionAdmin, true]],320 ],321 ]).send(),322 );323324 res['setTokenPropertyPermissions'].substrate = convertToTokens((await helper.arrange.calculcateFee(325 {Substrate: donor.address},326 () => collection.setTokenPropertyPermissions(donor, [{key: 'url', permission: {327 tokenOwner: true,328 collectionAdmin: true,329 mutable: true,330 }}]),331 )));332333 res['setCollectionSponsorCross'] =334 await helper.arrange.calculcateFeeGas(335 {Ethereum: ethSigner},336 () => evmContract.methods.setCollectionSponsorCross(crossReceiver).send(),337 );338339 res['confirmCollectionSponsorship'] =340 await helper.arrange.calculcateFeeGas(341 {Ethereum: ethReceiver},342 () => evmContract.methods.confirmCollectionSponsorship().send({from: ethReceiver}),343 );344345 res['removeCollectionSponsor'] =346 await helper.arrange.calculcateFeeGas(347 {Ethereum: ethSigner},348 () => evmContract.methods.removeCollectionSponsor().send(),349 );350351 res['setCollectionSponsorCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(352 {Substrate: donor.address},353 () => collection.setSponsor(donor, subReceiver.address),354 )));355356 res['confirmCollectionSponsorship'].substrate = convertToTokens((await helper.arrange.calculcateFee(357 {Substrate: subReceiver.address},358 () => collection.confirmSponsorship(subReceiver),359 )));360361 res['removeCollectionSponsor'].substrate = convertToTokens((await helper.arrange.calculcateFee(362 {Substrate: donor.address},363 () => collection.removeSponsor(donor),364 )));365366 res['setCollectionProperties'] =367 await helper.arrange.calculcateFeeGas(368 {Ethereum: ethSigner},369 () => evmContract.methods.setCollectionProperties(PROPERTIES.slice(0, 1)).send(),370 );371372 res['deleteCollectionProperties'] =373 await helper.arrange.calculcateFeeGas(374 {Ethereum: ethSigner},375 () => evmContract.methods.deleteCollectionProperties(PROPERTIES.slice(0,1).map(p => p.key)).send(),376 );377 res['setCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(378 {Substrate: donor.address},379 () => collection.setProperties(donor, PROPERTIES.slice(0, 1)380 .map(p => { return {key: p.key, value: p.value.toString()}; })),381 )));382383 res['deleteCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(384 {Substrate: donor.address},385 () => collection.deleteProperties(donor, PROPERTIES.slice(0, 1)386 .map(p => p.key)),387 )));388389 res['setCollectionLimit'] =390 await helper.arrange.calculcateFeeGas(391 {Ethereum: ethSigner},392 () => evmContract.methods.setCollectionLimit({field: CollectionLimitField.AccountTokenOwnership, value: {status: true, value: 1000}}).send(),393 );394395 res['setCollectionLimit'].substrate = convertToTokens((await helper.arrange.calculcateFee(396 {Substrate: donor.address},397 () => collection.setLimits(donor, {accountTokenOwnershipLimit: 1000}),398 )));399400 const {collectionAddress} = await helper.eth.createCollection('nft', ethSigner, 'A', 'B', 'C');401 const collectionWithEthOwner = await helper.ethNativeContract.collection(collectionAddress, 'nft', ethSigner, true);402403404 res['addCollectionAdminCross'] =405 await helper.arrange.calculcateFeeGas(406 {Ethereum: ethSigner},407 () => collectionWithEthOwner.methods.addCollectionAdminCross(crossReceiver).send(),408 );409410 res['removeCollectionAdminCross'] =411 await helper.arrange.calculcateFeeGas(412 {Ethereum: ethSigner},413 () => collectionWithEthOwner.methods.removeCollectionAdminCross(crossReceiver).send(),414 );415416 res['addCollectionAdminCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(417 {Substrate: donor.address},418 () => collection.addAdmin(donor, {Ethereum: ethReceiver}),419 )));420421 res['removeCollectionAdminCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(422 {Substrate: donor.address},423 () => collection.removeAdmin(donor, {Ethereum: ethReceiver}),424 )));425426 res['setCollectionNesting'] =427 await helper.arrange.calculcateFeeGas(428 {Ethereum: ethSigner},429 () => evmContract.methods.setCollectionNesting(true).send(),430 );431432 res['setCollectionNesting[]'] =433 await helper.arrange.calculcateFeeGas(434 {Ethereum: ethSigner},435 () => evmContract.methods.setCollectionNesting(true, [collectionAddress]).send(),436 );437438 res['setCollectionNesting'].substrate = convertToTokens((await helper.arrange.calculcateFee(439 {Substrate: donor.address},440 () => collection.disableNesting(donor),441 )));442443 res['setCollectionNesting[]'].substrate = convertToTokens((await helper.arrange.calculcateFee(444 {Substrate: donor.address},445 () => collection.setPermissions(446 donor,447 {448 nesting: {449 tokenOwner: true,450 restricted: [collection.collectionId],451 },452 },453 ),454 )));455456 res['setCollectionAccess'] =457 await helper.arrange.calculcateFeeGas(458 {Ethereum: ethSigner},459 () => evmContract.methods.setCollectionAccess(1).send(),460 );461462 res['setCollectionAccess'].substrate = convertToTokens((await helper.arrange.calculcateFee(463 {Substrate: donor.address},464 () => collection.setPermissions(donor, {access: 'AllowList'}),465 )));466467 res['addToCollectionAllowListCross'] =468 await helper.arrange.calculcateFeeGas(469 {Ethereum: ethSigner},470 () => evmContract.methods.addToCollectionAllowListCross(crossReceiver).send(),471 );472473 res['removeFromCollectionAllowListCross'] =474 await helper.arrange.calculcateFeeGas(475 {Ethereum: ethSigner},476 () => evmContract.methods.removeFromCollectionAllowListCross(crossReceiver).send(),477 );478479 res['addToCollectionAllowListCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(480 {Substrate: donor.address},481 () => collection.addToAllowList(donor, {Ethereum: ethReceiver}),482 )));483484 res['removeFromCollectionAllowListCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(485 {Substrate: donor.address},486 () => collection.removeFromAllowList(donor, {Ethereum: ethReceiver}),487 )));488489 res['setCollectionMintMode'] =490 await helper.arrange.calculcateFeeGas(491 {Ethereum: ethSigner},492 () => evmContract.methods.setCollectionMintMode(true).send(),493 );494495 res['setCollectionMintMode'].substrate = convertToTokens((await helper.arrange.calculcateFee(496 {Substrate: donor.address},497 () => collection.setPermissions(donor, {mintMode: false}),498 )));499500 res['changeCollectionOwnerCross'] =501 await helper.arrange.calculcateFeeGas(502 {Ethereum: ethSigner},503 () => collectionWithEthOwner.methods.changeCollectionOwnerCross(crossReceiver).send(),504 );505506 res['changeCollectionOwnerCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(507 {Substrate: donor.address},508 () => collection.changeOwner(donor, subReceiver.address),509 )));510511 return res;512}513514async function erc20CalculateFeeGas(515 helper: EthUniqueHelper,516 privateKey: (seed: string) => Promise<IKeyringPair>,517518): Promise<IFunctionFee> {519 const res: IFunctionFee = {};520 const donor = await privateKey('//Alice');521 const [subReceiver] = await helper.arrange.createAccounts([10n], donor);522 const ethSigner = await helper.eth.createAccountWithBalance(donor, 100n);523 const ethReceiver = await helper.eth.createAccountWithBalance(donor, 10n);524 const crossSigner = helper.ethCrossAccount.fromAddress(ethSigner);525 const crossReceiver = helper.ethCrossAccount.fromAddress(ethReceiver);526 const collection = (await createCollectionForBenchmarks(527 'ft',528 helper,529 privateKey,530 ethSigner,531 null,532 PERMISSIONS,533 )) as UniqueFTCollection;534535 const helperContract = await helper.ethNativeContract.collectionHelpers(ethSigner);536 let zeppelelinContract: Contract | null = null;537 const ZEPPELIN_OBJECT = '0x' + (await readFile(`${dirname}/../utils/openZeppelin/ERC20/bin/ZeppelinContract.bin`)).toString();538 const ZEPPELIN_ABI = JSON.parse((await readFile(`${dirname}/../utils/openZeppelin/ERC20/bin/ZeppelinContract.abi`)).toString());539540 const evmContract = await helper.ethNativeContract.collection(541 helper.ethAddress.fromCollectionId(collection.collectionId),542 'ft',543 ethSigner,544 true,545 );546547 res['createCollection'] = await helper.arrange.calculcateFeeGas(548 {Ethereum: ethSigner},549 () => helperContract.methods.createFTCollection('test', 18,'test','test').send({from: ethSigner, value: Number(2n * helper.balance.getOneTokenNominal())}),550 );551552 res['createCollection'].substrate = convertToTokens((await helper.arrange.calculcateFee(553 {Substrate: donor.address},554 () => helper.ft.mintCollection(555 donor,556 {name: 'test', description: 'test', tokenPrefix: 'test'},557 18,558 ),559 )));560561 res['createCollection'].zeppelin = await helper.arrange.calculcateFeeGas(562 {Ethereum: ethSigner},563 async () => {564 zeppelelinContract = await helper.ethContract.deployByAbi(565 ethSigner,566 ZEPPELIN_ABI,567 ZEPPELIN_OBJECT,568 );569 },570 );571572 res['mint'] =573 await helper.arrange.calculcateFeeGas(574 {Ethereum: ethSigner},575 () => evmContract.methods.mint(ethSigner, 1).send(),576 );577578 res['mint'].zeppelin =579 await helper.arrange.calculcateFeeGas(580 {Ethereum: ethSigner},581 () => zeppelelinContract!.methods.mint(ethSigner, 1).send(),582 );583584 res['mintCross'] =585 await helper.arrange.calculcateFeeGas(586 {Ethereum: ethSigner},587 () => evmContract.methods.mintCross(crossSigner, 1).send(),588 );589590 res['mintCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(591 {Substrate: donor.address},592 () => collection.mint(593 donor,594 10n,595 {Substrate: donor.address},596 ),597 )));598599 res['mintBulk'] =600 await helper.arrange.calculcateFeeGas(601 {Ethereum: ethSigner},602 () => evmContract.methods.mintBulk([{to: ethSigner, amount: 1}]).send(),603 );604605 res['mintBulk'].substrate = convertToTokens((await helper.arrange.calculcateFee(606 {Substrate: donor.address},607 () => helper.executeExtrinsic(donor, 'api.tx.unique.createMultipleItemsEx',[collection.collectionId, {608 Fungible: new Map([609 [JSON.stringify({Ethereum: ethSigner}), 1],610 ]),611 }], true),612 )));613614 res['transfer*'] =615 await helper.arrange.calculcateFeeGas(616 {Ethereum: ethSigner},617 () => evmContract.methods.transfer(ethReceiver, 1).send(),618 );619620 res['transfer*'].zeppelin =621 await helper.arrange.calculcateFeeGas(622 {Ethereum: ethSigner},623 () => zeppelelinContract!.methods.transfer(ethReceiver, 1).send(),624 );625626 res['transferCross'] =627 await helper.arrange.calculcateFeeGas(628 {Ethereum: ethReceiver},629 () => evmContract.methods.transferCross(crossSigner, 1).send({from: ethReceiver}),630 );631632 res['transferCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(633 {Substrate: donor.address},634 () => collection.transfer(635 donor,636 {Substrate: subReceiver.address},637 1n,638 ),639 )));640 await collection.approveTokens(subReceiver, {Substrate: donor.address}, 1n);641642 res['transferFrom*'] =643 await helper.arrange.calculcateFeeGas(644 {Ethereum: ethSigner},645 () => evmContract.methods.transferFrom(ethSigner, ethReceiver, 1).send(),646 );647648 await zeppelelinContract!.methods.approve(ethSigner, 10).send({from: ethReceiver});649650 res['transferFrom*'].zeppelin =651 await helper.arrange.calculcateFeeGas(652 {Ethereum: ethSigner},653 () => zeppelelinContract!.methods.transferFrom(ethReceiver, ethSigner, 1).send({from: ethSigner}),654 );655656 res['transferFromCross'] =657 await helper.arrange.calculcateFeeGas(658 {Ethereum: ethReceiver},659 () => evmContract.methods.transferFromCross(crossReceiver, crossSigner, 1).send({from:ethReceiver}),660 );661662 res['transferFromCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(663 {Substrate: donor.address},664 () => collection.transferFrom(donor, {Substrate: subReceiver.address}, {Substrate: donor.address}, 1n),665 )));666667668 res['burnTokens'] = {fee: 0n, gas: 0n};669 res['burnTokens'].substrate = convertToTokens((await helper.arrange.calculcateFee(670 {Substrate: donor.address},671 () => collection.burnTokens(donor, 1n),672 )));673674675 res['approve*'] =676 await helper.arrange.calculcateFeeGas(677 {Ethereum: ethSigner},678 () => evmContract.methods.approve(ethReceiver, 2).send(),679 );680681 res['approve*'].zeppelin =682 await helper.arrange.calculcateFeeGas(683 {Ethereum: ethSigner},684 () => zeppelelinContract!.methods.approve(ethReceiver, 10).send(),685 );686687 res['approveCross'] =688 await helper.arrange.calculcateFeeGas(689 {Ethereum: ethSigner},690 () => evmContract.methods.approveCross(crossReceiver, 2).send(),691 );692693 res['approveCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(694 {Substrate: donor.address},695 () => collection.approveTokens(donor, {Substrate: subReceiver.address}, 1n),696 )));697698 res['burnFromCross'] =699 await helper.arrange.calculcateFeeGas(700 {Ethereum: ethReceiver},701 () => evmContract.methods.burnFromCross(crossSigner, 1).send({from:ethReceiver}),702 );703704 res['burnFromCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(705 {Substrate: subReceiver.address},706 () => collection.burnTokensFrom(subReceiver, {Substrate: donor.address}, 1n),707 )));708709 res['setCollectionSponsorCross'] =710 await helper.arrange.calculcateFeeGas(711 {Ethereum: ethSigner},712 () => evmContract.methods.setCollectionSponsorCross(crossReceiver).send(),713 );714715 res['confirmCollectionSponsorship'] =716 await helper.arrange.calculcateFeeGas(717 {Ethereum: ethReceiver},718 () => evmContract.methods.confirmCollectionSponsorship().send({from: ethReceiver}),719 );720721 res['removeCollectionSponsor'] =722 await helper.arrange.calculcateFeeGas(723 {Ethereum: ethSigner},724 () => evmContract.methods.removeCollectionSponsor().send(),725 );726727 res['setCollectionSponsorCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(728 {Substrate: donor.address},729 () => collection.setSponsor(donor, subReceiver.address),730 )));731732 res['confirmCollectionSponsorship'].substrate = convertToTokens((await helper.arrange.calculcateFee(733 {Substrate: subReceiver.address},734 () => collection.confirmSponsorship(subReceiver),735 )));736737 res['removeCollectionSponsor'].substrate = convertToTokens((await helper.arrange.calculcateFee(738 {Substrate: donor.address},739 () => collection.removeSponsor(donor),740 )));741742 res['setCollectionProperties'] =743 await helper.arrange.calculcateFeeGas(744 {Ethereum: ethSigner},745 () => evmContract.methods.setCollectionProperties(PROPERTIES.slice(0, 1)).send(),746 );747748 res['deleteCollectionProperties'] =749 await helper.arrange.calculcateFeeGas(750 {Ethereum: ethSigner},751 () => evmContract.methods.deleteCollectionProperties(PROPERTIES.slice(0,1).map(p => p.key)).send(),752 );753 res['setCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(754 {Substrate: donor.address},755 () => collection.setProperties(donor, PROPERTIES.slice(0, 1)756 .map(p => { return {key: p.key, value: p.value.toString()}; })),757 )));758759 res['deleteCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(760 {Substrate: donor.address},761 () => collection.deleteProperties(donor, PROPERTIES.slice(0, 1)762 .map(p => p.key)),763 )));764765 res['setCollectionLimit'] =766 await helper.arrange.calculcateFeeGas(767 {Ethereum: ethSigner},768 () => evmContract.methods.setCollectionLimit({field: CollectionLimitField.AccountTokenOwnership, value: {status: true, value: 1000}}).send(),769 );770771 res['setCollectionLimit'].substrate = convertToTokens((await helper.arrange.calculcateFee(772 {Substrate: donor.address},773 () => collection.setLimits(donor, {accountTokenOwnershipLimit: 1000}),774 )));775776 const {collectionAddress} = await helper.eth.createCollection('nft', ethSigner, 'A', 'B', 'C');777 const collectionWithEthOwner = await helper.ethNativeContract.collection(collectionAddress, 'nft', ethSigner, true);778779780 res['addCollectionAdminCross'] =781 await helper.arrange.calculcateFeeGas(782 {Ethereum: ethSigner},783 () => collectionWithEthOwner.methods.addCollectionAdminCross(crossReceiver).send(),784 );785786 res['removeCollectionAdminCross'] =787 await helper.arrange.calculcateFeeGas(788 {Ethereum: ethSigner},789 () => collectionWithEthOwner.methods.removeCollectionAdminCross(crossReceiver).send(),790 );791792 res['addCollectionAdminCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(793 {Substrate: donor.address},794 () => collection.addAdmin(donor, {Ethereum: ethReceiver}),795 )));796797 res['removeCollectionAdminCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(798 {Substrate: donor.address},799 () => collection.removeAdmin(donor, {Ethereum: ethReceiver}),800 )));801802 res['setCollectionNesting'] =803 await helper.arrange.calculcateFeeGas(804 {Ethereum: ethSigner},805 () => evmContract.methods.setCollectionNesting(true).send(),806 );807808 res['setCollectionNesting[]'] =809 await helper.arrange.calculcateFeeGas(810 {Ethereum: ethSigner},811 () => evmContract.methods.setCollectionNesting(true, [collectionAddress]).send(),812 );813814 res['setCollectionNesting'].substrate = convertToTokens((await helper.arrange.calculcateFee(815 {Substrate: donor.address},816 () => collection.disableNesting(donor),817 )));818819 res['setCollectionNesting[]'].substrate = convertToTokens((await helper.arrange.calculcateFee(820 {Substrate: donor.address},821 () => collection.setPermissions(822 donor,823 {824 nesting: {825 tokenOwner: true,826 restricted: [collection.collectionId],827 },828 },829 ),830 )));831832 res['setCollectionAccess'] =833 await helper.arrange.calculcateFeeGas(834 {Ethereum: ethSigner},835 () => evmContract.methods.setCollectionAccess(1).send(),836 );837838 res['setCollectionAccess'].substrate = convertToTokens((await helper.arrange.calculcateFee(839 {Substrate: donor.address},840 () => collection.setPermissions(donor, {access: 'AllowList'}),841 )));842843 res['addToCollectionAllowListCross'] =844 await helper.arrange.calculcateFeeGas(845 {Ethereum: ethSigner},846 () => evmContract.methods.addToCollectionAllowListCross(crossReceiver).send(),847 );848849 res['removeFromCollectionAllowListCross'] =850 await helper.arrange.calculcateFeeGas(851 {Ethereum: ethSigner},852 () => evmContract.methods.removeFromCollectionAllowListCross(crossReceiver).send(),853 );854855 res['addToCollectionAllowListCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(856 {Substrate: donor.address},857 () => collection.addToAllowList(donor, {Ethereum: ethReceiver}),858 )));859860 res['removeFromCollectionAllowListCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(861 {Substrate: donor.address},862 () => collection.removeFromAllowList(donor, {Ethereum: ethReceiver}),863 )));864865 res['setCollectionMintMode'] =866 await helper.arrange.calculcateFeeGas(867 {Ethereum: ethSigner},868 () => evmContract.methods.setCollectionMintMode(true).send(),869 );870871 res['setCollectionMintMode'].substrate = convertToTokens((await helper.arrange.calculcateFee(872 {Substrate: donor.address},873 () => collection.setPermissions(donor, {mintMode: false}),874 )));875876 res['changeCollectionOwnerCross'] =877 await helper.arrange.calculcateFeeGas(878 {Ethereum: ethSigner},879 () => collectionWithEthOwner.methods.changeCollectionOwnerCross(crossReceiver).send(),880 );881882 res['changeCollectionOwnerCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(883 {Substrate: donor.address},884 () => collection.changeOwner(donor, subReceiver.address),885 )));886887 return res;888}1import {EthUniqueHelper, usingEthPlaygrounds} from '../../eth/util';2import {readFile} from 'fs/promises';3import {CollectionLimitField, TokenPermissionField} from '../../eth/util/playgrounds/types';4import {IKeyringPair} from '@polkadot/types/types';5import {UniqueFTCollection, UniqueNFTCollection} from '../../util/playgrounds/unique';6import {Contract} from 'web3-eth-contract';7import {createObjectCsvWriter} from 'csv-writer';8import {FunctionFeeVM, IFunctionFee} from '../utils/types';9import {convertToTokens, createCollectionForBenchmarks, PERMISSIONS, PROPERTIES, SUBS_PROPERTIES} from '../utils/common';10import {makeNames} from '../../util';111213const {dirname} = makeNames(import.meta.url);1415const main = async () => {1617 const headers = [18 'function',19 'ethFee',20 'ethGas',21 'substrate',22 'zeppelinFee',23 'zeppelinGas',24 ];2526 const csvWriter20 = createObjectCsvWriter({27 path: 'erc20.csv',28 header: headers,29 });3031 const csvWriter721 = createObjectCsvWriter({32 path: 'erc721.csv',33 header: headers,34 });3536 await usingEthPlaygrounds(async (helper, privateKey) => {37 console.log('\n ERC20 ops fees');38 const erc20 = FunctionFeeVM.fromModel(await erc20CalculateFeeGas(helper, privateKey));39 console.table(erc20);40 await csvWriter20.writeRecords(FunctionFeeVM.toCsv(erc20));4142 console.log('\n ERC721 ops fees');43 const erc721 = FunctionFeeVM.fromModel(await erc721CalculateFeeGas(helper, privateKey));44 console.table(erc721);4546 await csvWriter721.writeRecords(FunctionFeeVM.toCsv(erc721));47 });48};4950main()51 .then(() => process.exit(0))52 .catch((e) => {53 console.log(e);54 process.exit(1);55 });5657async function erc721CalculateFeeGas(58 helper: EthUniqueHelper,59 privateKey: (seed: string) => Promise<IKeyringPair>,60): Promise<IFunctionFee> {61 const res: IFunctionFee = {};62 const donor = await privateKey('//Alice');63 const [subReceiver] = await helper.arrange.createAccounts([10n], donor);64 const ethSigner = await helper.eth.createAccountWithBalance(donor, 100n);65 const ethReceiver = await helper.eth.createAccountWithBalance(donor, 10n);66 const crossSigner = helper.ethCrossAccount.fromAddress(ethSigner);67 const crossReceiver = helper.ethCrossAccount.fromAddress(ethReceiver);68 const collection = (await createCollectionForBenchmarks(69 'nft',70 helper,71 privateKey,72 ethSigner,73 null,74 PERMISSIONS,75 )) as UniqueNFTCollection;7677 const helperContract = await helper.ethNativeContract.collectionHelpers(ethSigner);78 let zeppelelinContract: Contract | null = null;79 const ZEPPELIN_OBJECT = '0x' + (await readFile(`${dirname}/../utils/openZeppelin/ERC721/bin/ZeppelinContract.bin`)).toString();80 const ZEPPELIN_ABI = JSON.parse((await readFile(`${dirname}/../utils/openZeppelin/ERC721/bin/ZeppelinContract.abi`)).toString());8182 const evmContract = await helper.ethNativeContract.collection(83 helper.ethAddress.fromCollectionId(collection.collectionId),84 'nft',85 ethSigner,86 true,87 );8889 res['createCollection'] = await helper.arrange.calculcateFeeGas(90 {Ethereum: ethSigner},91 () => helperContract.methods.createNFTCollection('test','test','test').send({from: ethSigner, value: Number(2n * helper.balance.getOneTokenNominal())}),92 );9394 res['createCollection'].substrate = convertToTokens((await helper.arrange.calculcateFee(95 {Substrate: donor.address},96 () => helper.nft.mintCollection(97 donor,98 {name: 'test', description: 'test', tokenPrefix: 'test'},99 ),100 )));101102 res['createCollection'].zeppelin = await helper.arrange.calculcateFeeGas(103 {Ethereum: ethSigner},104 async () => {105 zeppelelinContract = await helper.ethContract.deployByAbi(106 ethSigner,107 ZEPPELIN_ABI,108 ZEPPELIN_OBJECT,109 );110 },111 );112113 res['mint'] =114 await helper.arrange.calculcateFeeGas(115 {Ethereum: ethSigner},116 () => evmContract.methods.mint(ethSigner).send(),117 );118119 res['mint'].zeppelin =120 await helper.arrange.calculcateFeeGas(121 {Ethereum: ethSigner},122 () => zeppelelinContract!.methods.safeMint(ethSigner, '').send({from: ethSigner}),123 );124125 res['mintCross'] =126 await helper.arrange.calculcateFeeGas(127 {Ethereum: ethSigner},128 () => evmContract.methods.mintCross(crossSigner, []).send(),129 );130131 res['mint'].substrate = convertToTokens((await helper.arrange.calculcateFee(132 {Substrate: donor.address},133 () => collection.mintToken(134 donor,135 {Substrate: donor.address},136 ),137 )));138139 res['mintCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(140 {Substrate: donor.address},141 () => collection.mintMultipleTokens(donor, [{142 owner: {Substrate: donor.address},143 }]),144 )));145146 res['mintWithTokenURI'] =147 await helper.arrange.calculcateFeeGas(148 {Ethereum: ethSigner},149 () => evmContract.methods.mintWithTokenURI(ethSigner, 'Test URI').send(),150 );151152 res['mintWithTokenURI'].substrate = convertToTokens((await helper.arrange.calculcateFee(153 {Substrate: donor.address},154 () => collection.mintToken(155 donor,156 {Ethereum: ethSigner},157 [{key: 'URI', value: 'Test URI'}],158 ),159 )));160161 res['mintWithTokenURI'].zeppelin =162 await helper.arrange.calculcateFeeGas(163 {Ethereum: ethSigner},164 () => zeppelelinContract!.methods.safeMint(ethSigner, 'Test URI').send({from: ethSigner}),165 );166167 res['setProperties'] =168 await helper.arrange.calculcateFeeGas(169 {Ethereum: ethSigner},170 () => evmContract.methods.setProperties(1, PROPERTIES.slice(0,1)).send(),171 );172173 res['deleteProperties'] =174 await helper.arrange.calculcateFeeGas(175 {Ethereum: ethSigner},176 () => evmContract.methods.deleteProperties(1, [PROPERTIES[0].key]).send(),177 );178179 res['setProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(180 {Substrate: donor.address},181 () => collection.setTokenProperties(182 donor,183 1,184 SUBS_PROPERTIES.slice(0, 1),185 ),186 )));187188 res['deleteProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(189 {Substrate: donor.address},190 () => collection.deleteTokenProperties(191 donor,192 1,193 SUBS_PROPERTIES.slice(0, 1)194 .map(p => p.key),195 ),196 )));197198 res['transfer'] =199 await helper.arrange.calculcateFeeGas(200 {Ethereum: ethSigner},201 () => evmContract.methods.transfer(ethReceiver, 1).send(),202 );203204 res['safeTransferFrom*'] = {205 zeppelin:206 await helper.arrange.calculcateFeeGas(207 {Ethereum: ethSigner},208 () => zeppelelinContract!.methods.safeTransferFrom(ethSigner, ethReceiver, 0).send({from: ethSigner}),209 ),210 };211212 res['transferCross'] =213 await helper.arrange.calculcateFeeGas(214 {Ethereum: ethReceiver},215 () => evmContract.methods.transferCross(crossSigner, 1).send({from: ethReceiver}),216 );217218 res['transferCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(219 {Substrate: donor.address},220 () => collection.transferToken(221 donor,222 3,223 {Substrate: subReceiver.address},224 ),225 )));226 await collection.approveToken(subReceiver, 3, {Substrate: donor.address});227228 res['transferFrom*'] =229 await helper.arrange.calculcateFeeGas(230 {Ethereum: ethSigner},231 () => evmContract.methods.transferFrom(ethSigner, ethReceiver, 1).send(),232 );233234 res['transferFrom*'].zeppelin =235 await helper.arrange.calculcateFeeGas(236 {Ethereum: ethReceiver},237 () => zeppelelinContract!.methods.transferFrom(ethReceiver, ethSigner, 0).send({from: ethReceiver}),238 );239240241 res['transferFromCross'] =242 await helper.arrange.calculcateFeeGas(243 {Ethereum: ethReceiver},244 () => evmContract.methods.transferFromCross(crossReceiver, crossSigner, 1).send({from:ethReceiver}),245 );246247 res['transferFromCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(248 {Substrate: donor.address},249 () => collection.transferTokenFrom(donor, 3, {Substrate: subReceiver.address}, {Substrate: donor.address}),250 )));251252 res['burn'] =253 await helper.arrange.calculcateFeeGas(254 {Ethereum: ethSigner},255 () => evmContract.methods.burn(1).send(),256 );257258 res['burn'].substrate = convertToTokens((await helper.arrange.calculcateFee(259 {Substrate: donor.address},260 () => collection.burnToken(donor, 3),261 )));262263 res['approve*'] =264 await helper.arrange.calculcateFeeGas(265 {Ethereum: ethSigner},266 () => evmContract.methods.approve(ethReceiver, 2).send(),267 );268269 res['approve*'].zeppelin =270 await helper.arrange.calculcateFeeGas(271 {Ethereum: ethSigner},272 () => zeppelelinContract!.methods.approve(ethReceiver, 0).send({from: ethSigner}),273 );274275 res['approveCross'] =276 await helper.arrange.calculcateFeeGas(277 {Ethereum: ethSigner},278 () => evmContract.methods.approveCross(crossReceiver, 2).send(),279 );280281 res['approveCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(282 {Substrate: donor.address},283 () => collection.approveToken(donor, 4, {Substrate: subReceiver.address}),284 )));285286 res['setApprovalForAll*'] =287 await helper.arrange.calculcateFeeGas(288 {Ethereum: ethSigner},289 () => evmContract.methods.setApprovalForAll(ethReceiver, true).send(),290 );291292 res['setApprovalForAll*'].zeppelin =293 await helper.arrange.calculcateFeeGas(294 {Ethereum: ethSigner},295 () => zeppelelinContract!.methods.setApprovalForAll(ethReceiver, true).send({from: ethSigner}),296 );297298 res['setApprovalForAll*'].substrate = convertToTokens((await helper.arrange.calculcateFee(299 {Substrate: donor.address},300 () => helper.nft.setAllowanceForAll(donor, collection.collectionId, {Substrate: subReceiver.address}, true),301 )));302303 res['burnFromCross'] =304 await helper.arrange.calculcateFeeGas(305 {Ethereum: ethReceiver},306 () => evmContract.methods.burnFromCross(crossSigner, 2).send({from:ethReceiver}),307 );308309 res['burnFromCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(310 {Substrate: subReceiver.address},311 () => collection.burnTokenFrom(subReceiver, 4, {Substrate: donor.address}),312 )));313314 res['setTokenPropertyPermissions'] =315 await helper.arrange.calculcateFeeGas(316 {Ethereum: ethSigner},317 () => evmContract.methods.setTokenPropertyPermissions([318 ['url', [319 [TokenPermissionField.Mutable, true],320 [TokenPermissionField.TokenOwner, true],321 [TokenPermissionField.CollectionAdmin, true]],322 ],323 ]).send(),324 );325326 res['setTokenPropertyPermissions'].substrate = convertToTokens((await helper.arrange.calculcateFee(327 {Substrate: donor.address},328 () => collection.setTokenPropertyPermissions(donor, [{key: 'url', permission: {329 tokenOwner: true,330 collectionAdmin: true,331 mutable: true,332 }}]),333 )));334335 res['setCollectionSponsorCross'] =336 await helper.arrange.calculcateFeeGas(337 {Ethereum: ethSigner},338 () => evmContract.methods.setCollectionSponsorCross(crossReceiver).send(),339 );340341 res['confirmCollectionSponsorship'] =342 await helper.arrange.calculcateFeeGas(343 {Ethereum: ethReceiver},344 () => evmContract.methods.confirmCollectionSponsorship().send({from: ethReceiver}),345 );346347 res['removeCollectionSponsor'] =348 await helper.arrange.calculcateFeeGas(349 {Ethereum: ethSigner},350 () => evmContract.methods.removeCollectionSponsor().send(),351 );352353 res['setCollectionSponsorCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(354 {Substrate: donor.address},355 () => collection.setSponsor(donor, subReceiver.address),356 )));357358 res['confirmCollectionSponsorship'].substrate = convertToTokens((await helper.arrange.calculcateFee(359 {Substrate: subReceiver.address},360 () => collection.confirmSponsorship(subReceiver),361 )));362363 res['removeCollectionSponsor'].substrate = convertToTokens((await helper.arrange.calculcateFee(364 {Substrate: donor.address},365 () => collection.removeSponsor(donor),366 )));367368 res['setCollectionProperties'] =369 await helper.arrange.calculcateFeeGas(370 {Ethereum: ethSigner},371 () => evmContract.methods.setCollectionProperties(PROPERTIES.slice(0, 1)).send(),372 );373374 res['deleteCollectionProperties'] =375 await helper.arrange.calculcateFeeGas(376 {Ethereum: ethSigner},377 () => evmContract.methods.deleteCollectionProperties(PROPERTIES.slice(0,1).map(p => p.key)).send(),378 );379 res['setCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(380 {Substrate: donor.address},381 () => collection.setProperties(donor, PROPERTIES.slice(0, 1)382 .map(p => { return {key: p.key, value: p.value.toString()}; })),383 )));384385 res['deleteCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(386 {Substrate: donor.address},387 () => collection.deleteProperties(donor, PROPERTIES.slice(0, 1)388 .map(p => p.key)),389 )));390391 res['setCollectionLimit'] =392 await helper.arrange.calculcateFeeGas(393 {Ethereum: ethSigner},394 () => evmContract.methods.setCollectionLimit({field: CollectionLimitField.AccountTokenOwnership, value: {status: true, value: 1000}}).send(),395 );396397 res['setCollectionLimit'].substrate = convertToTokens((await helper.arrange.calculcateFee(398 {Substrate: donor.address},399 () => collection.setLimits(donor, {accountTokenOwnershipLimit: 1000}),400 )));401402 const {collectionAddress} = await helper.eth.createCollection('nft', ethSigner, 'A', 'B', 'C');403 const collectionWithEthOwner = await helper.ethNativeContract.collection(collectionAddress, 'nft', ethSigner, true);404405406 res['addCollectionAdminCross'] =407 await helper.arrange.calculcateFeeGas(408 {Ethereum: ethSigner},409 () => collectionWithEthOwner.methods.addCollectionAdminCross(crossReceiver).send(),410 );411412 res['removeCollectionAdminCross'] =413 await helper.arrange.calculcateFeeGas(414 {Ethereum: ethSigner},415 () => collectionWithEthOwner.methods.removeCollectionAdminCross(crossReceiver).send(),416 );417418 res['addCollectionAdminCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(419 {Substrate: donor.address},420 () => collection.addAdmin(donor, {Ethereum: ethReceiver}),421 )));422423 res['removeCollectionAdminCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(424 {Substrate: donor.address},425 () => collection.removeAdmin(donor, {Ethereum: ethReceiver}),426 )));427428 res['setCollectionNesting'] =429 await helper.arrange.calculcateFeeGas(430 {Ethereum: ethSigner},431 () => evmContract.methods.setCollectionNesting(true).send(),432 );433434 res['setCollectionNesting[]'] =435 await helper.arrange.calculcateFeeGas(436 {Ethereum: ethSigner},437 () => evmContract.methods.setCollectionNesting(true, [collectionAddress]).send(),438 );439440 res['setCollectionNesting'].substrate = convertToTokens((await helper.arrange.calculcateFee(441 {Substrate: donor.address},442 () => collection.disableNesting(donor),443 )));444445 res['setCollectionNesting[]'].substrate = convertToTokens((await helper.arrange.calculcateFee(446 {Substrate: donor.address},447 () => collection.setPermissions(448 donor,449 {450 nesting: {451 tokenOwner: true,452 restricted: [collection.collectionId],453 },454 },455 ),456 )));457458 res['setCollectionAccess'] =459 await helper.arrange.calculcateFeeGas(460 {Ethereum: ethSigner},461 () => evmContract.methods.setCollectionAccess(1).send(),462 );463464 res['setCollectionAccess'].substrate = convertToTokens((await helper.arrange.calculcateFee(465 {Substrate: donor.address},466 () => collection.setPermissions(donor, {access: 'AllowList'}),467 )));468469 res['addToCollectionAllowListCross'] =470 await helper.arrange.calculcateFeeGas(471 {Ethereum: ethSigner},472 () => evmContract.methods.addToCollectionAllowListCross(crossReceiver).send(),473 );474475 res['removeFromCollectionAllowListCross'] =476 await helper.arrange.calculcateFeeGas(477 {Ethereum: ethSigner},478 () => evmContract.methods.removeFromCollectionAllowListCross(crossReceiver).send(),479 );480481 res['addToCollectionAllowListCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(482 {Substrate: donor.address},483 () => collection.addToAllowList(donor, {Ethereum: ethReceiver}),484 )));485486 res['removeFromCollectionAllowListCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(487 {Substrate: donor.address},488 () => collection.removeFromAllowList(donor, {Ethereum: ethReceiver}),489 )));490491 res['setCollectionMintMode'] =492 await helper.arrange.calculcateFeeGas(493 {Ethereum: ethSigner},494 () => evmContract.methods.setCollectionMintMode(true).send(),495 );496497 res['setCollectionMintMode'].substrate = convertToTokens((await helper.arrange.calculcateFee(498 {Substrate: donor.address},499 () => collection.setPermissions(donor, {mintMode: false}),500 )));501502 res['changeCollectionOwnerCross'] =503 await helper.arrange.calculcateFeeGas(504 {Ethereum: ethSigner},505 () => collectionWithEthOwner.methods.changeCollectionOwnerCross(crossReceiver).send(),506 );507508 res['changeCollectionOwnerCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(509 {Substrate: donor.address},510 () => collection.changeOwner(donor, subReceiver.address),511 )));512513 return res;514}515516async function erc20CalculateFeeGas(517 helper: EthUniqueHelper,518 privateKey: (seed: string) => Promise<IKeyringPair>,519520): Promise<IFunctionFee> {521 const res: IFunctionFee = {};522 const donor = await privateKey('//Alice');523 const [subReceiver] = await helper.arrange.createAccounts([10n], donor);524 const ethSigner = await helper.eth.createAccountWithBalance(donor, 100n);525 const ethReceiver = await helper.eth.createAccountWithBalance(donor, 10n);526 const crossSigner = helper.ethCrossAccount.fromAddress(ethSigner);527 const crossReceiver = helper.ethCrossAccount.fromAddress(ethReceiver);528 const collection = (await createCollectionForBenchmarks(529 'ft',530 helper,531 privateKey,532 ethSigner,533 null,534 PERMISSIONS,535 )) as UniqueFTCollection;536537 const helperContract = await helper.ethNativeContract.collectionHelpers(ethSigner);538 let zeppelelinContract: Contract | null = null;539 const ZEPPELIN_OBJECT = '0x' + (await readFile(`${dirname}/../utils/openZeppelin/ERC20/bin/ZeppelinContract.bin`)).toString();540 const ZEPPELIN_ABI = JSON.parse((await readFile(`${dirname}/../utils/openZeppelin/ERC20/bin/ZeppelinContract.abi`)).toString());541542 const evmContract = await helper.ethNativeContract.collection(543 helper.ethAddress.fromCollectionId(collection.collectionId),544 'ft',545 ethSigner,546 true,547 );548549 res['createCollection'] = await helper.arrange.calculcateFeeGas(550 {Ethereum: ethSigner},551 () => helperContract.methods.createFTCollection('test', 18,'test','test').send({from: ethSigner, value: Number(2n * helper.balance.getOneTokenNominal())}),552 );553554 res['createCollection'].substrate = convertToTokens((await helper.arrange.calculcateFee(555 {Substrate: donor.address},556 () => helper.ft.mintCollection(557 donor,558 {name: 'test', description: 'test', tokenPrefix: 'test'},559 18,560 ),561 )));562563 res['createCollection'].zeppelin = await helper.arrange.calculcateFeeGas(564 {Ethereum: ethSigner},565 async () => {566 zeppelelinContract = await helper.ethContract.deployByAbi(567 ethSigner,568 ZEPPELIN_ABI,569 ZEPPELIN_OBJECT,570 );571 },572 );573574 res['mint'] =575 await helper.arrange.calculcateFeeGas(576 {Ethereum: ethSigner},577 () => evmContract.methods.mint(ethSigner, 1).send(),578 );579580 res['mint'].zeppelin =581 await helper.arrange.calculcateFeeGas(582 {Ethereum: ethSigner},583 () => zeppelelinContract!.methods.mint(ethSigner, 1).send(),584 );585586 res['mintCross'] =587 await helper.arrange.calculcateFeeGas(588 {Ethereum: ethSigner},589 () => evmContract.methods.mintCross(crossSigner, 1).send(),590 );591592 res['mintCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(593 {Substrate: donor.address},594 () => collection.mint(595 donor,596 10n,597 {Substrate: donor.address},598 ),599 )));600601 res['mintBulk'] =602 await helper.arrange.calculcateFeeGas(603 {Ethereum: ethSigner},604 () => evmContract.methods.mintBulk([{to: ethSigner, amount: 1}]).send(),605 );606607 res['mintBulk'].substrate = convertToTokens((await helper.arrange.calculcateFee(608 {Substrate: donor.address},609 () => helper.executeExtrinsic(donor, 'api.tx.unique.createMultipleItemsEx',[collection.collectionId, {610 Fungible: new Map([611 [JSON.stringify({Ethereum: ethSigner}), 1],612 ]),613 }], true),614 )));615616 res['transfer*'] =617 await helper.arrange.calculcateFeeGas(618 {Ethereum: ethSigner},619 () => evmContract.methods.transfer(ethReceiver, 1).send(),620 );621622 res['transfer*'].zeppelin =623 await helper.arrange.calculcateFeeGas(624 {Ethereum: ethSigner},625 () => zeppelelinContract!.methods.transfer(ethReceiver, 1).send(),626 );627628 res['transferCross'] =629 await helper.arrange.calculcateFeeGas(630 {Ethereum: ethReceiver},631 () => evmContract.methods.transferCross(crossSigner, 1).send({from: ethReceiver}),632 );633634 res['transferCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(635 {Substrate: donor.address},636 () => collection.transfer(637 donor,638 {Substrate: subReceiver.address},639 1n,640 ),641 )));642 await collection.approveTokens(subReceiver, {Substrate: donor.address}, 1n);643644 res['transferFrom*'] =645 await helper.arrange.calculcateFeeGas(646 {Ethereum: ethSigner},647 () => evmContract.methods.transferFrom(ethSigner, ethReceiver, 1).send(),648 );649650 await zeppelelinContract!.methods.approve(ethSigner, 10).send({from: ethReceiver});651652 res['transferFrom*'].zeppelin =653 await helper.arrange.calculcateFeeGas(654 {Ethereum: ethSigner},655 () => zeppelelinContract!.methods.transferFrom(ethReceiver, ethSigner, 1).send({from: ethSigner}),656 );657658 res['transferFromCross'] =659 await helper.arrange.calculcateFeeGas(660 {Ethereum: ethReceiver},661 () => evmContract.methods.transferFromCross(crossReceiver, crossSigner, 1).send({from:ethReceiver}),662 );663664 res['transferFromCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(665 {Substrate: donor.address},666 () => collection.transferFrom(donor, {Substrate: subReceiver.address}, {Substrate: donor.address}, 1n),667 )));668669670 res['burnTokens'] = {fee: 0n, gas: 0n};671 res['burnTokens'].substrate = convertToTokens((await helper.arrange.calculcateFee(672 {Substrate: donor.address},673 () => collection.burnTokens(donor, 1n),674 )));675676677 res['approve*'] =678 await helper.arrange.calculcateFeeGas(679 {Ethereum: ethSigner},680 () => evmContract.methods.approve(ethReceiver, 2).send(),681 );682683 res['approve*'].zeppelin =684 await helper.arrange.calculcateFeeGas(685 {Ethereum: ethSigner},686 () => zeppelelinContract!.methods.approve(ethReceiver, 10).send(),687 );688689 res['approveCross'] =690 await helper.arrange.calculcateFeeGas(691 {Ethereum: ethSigner},692 () => evmContract.methods.approveCross(crossReceiver, 2).send(),693 );694695 res['approveCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(696 {Substrate: donor.address},697 () => collection.approveTokens(donor, {Substrate: subReceiver.address}, 1n),698 )));699700 res['burnFromCross'] =701 await helper.arrange.calculcateFeeGas(702 {Ethereum: ethReceiver},703 () => evmContract.methods.burnFromCross(crossSigner, 1).send({from:ethReceiver}),704 );705706 res['burnFromCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(707 {Substrate: subReceiver.address},708 () => collection.burnTokensFrom(subReceiver, {Substrate: donor.address}, 1n),709 )));710711 res['setCollectionSponsorCross'] =712 await helper.arrange.calculcateFeeGas(713 {Ethereum: ethSigner},714 () => evmContract.methods.setCollectionSponsorCross(crossReceiver).send(),715 );716717 res['confirmCollectionSponsorship'] =718 await helper.arrange.calculcateFeeGas(719 {Ethereum: ethReceiver},720 () => evmContract.methods.confirmCollectionSponsorship().send({from: ethReceiver}),721 );722723 res['removeCollectionSponsor'] =724 await helper.arrange.calculcateFeeGas(725 {Ethereum: ethSigner},726 () => evmContract.methods.removeCollectionSponsor().send(),727 );728729 res['setCollectionSponsorCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(730 {Substrate: donor.address},731 () => collection.setSponsor(donor, subReceiver.address),732 )));733734 res['confirmCollectionSponsorship'].substrate = convertToTokens((await helper.arrange.calculcateFee(735 {Substrate: subReceiver.address},736 () => collection.confirmSponsorship(subReceiver),737 )));738739 res['removeCollectionSponsor'].substrate = convertToTokens((await helper.arrange.calculcateFee(740 {Substrate: donor.address},741 () => collection.removeSponsor(donor),742 )));743744 res['setCollectionProperties'] =745 await helper.arrange.calculcateFeeGas(746 {Ethereum: ethSigner},747 () => evmContract.methods.setCollectionProperties(PROPERTIES.slice(0, 1)).send(),748 );749750 res['deleteCollectionProperties'] =751 await helper.arrange.calculcateFeeGas(752 {Ethereum: ethSigner},753 () => evmContract.methods.deleteCollectionProperties(PROPERTIES.slice(0,1).map(p => p.key)).send(),754 );755 res['setCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(756 {Substrate: donor.address},757 () => collection.setProperties(donor, PROPERTIES.slice(0, 1)758 .map(p => { return {key: p.key, value: p.value.toString()}; })),759 )));760761 res['deleteCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(762 {Substrate: donor.address},763 () => collection.deleteProperties(donor, PROPERTIES.slice(0, 1)764 .map(p => p.key)),765 )));766767 res['setCollectionLimit'] =768 await helper.arrange.calculcateFeeGas(769 {Ethereum: ethSigner},770 () => evmContract.methods.setCollectionLimit({field: CollectionLimitField.AccountTokenOwnership, value: {status: true, value: 1000}}).send(),771 );772773 res['setCollectionLimit'].substrate = convertToTokens((await helper.arrange.calculcateFee(774 {Substrate: donor.address},775 () => collection.setLimits(donor, {accountTokenOwnershipLimit: 1000}),776 )));777778 const {collectionAddress} = await helper.eth.createCollection('nft', ethSigner, 'A', 'B', 'C');779 const collectionWithEthOwner = await helper.ethNativeContract.collection(collectionAddress, 'nft', ethSigner, true);780781782 res['addCollectionAdminCross'] =783 await helper.arrange.calculcateFeeGas(784 {Ethereum: ethSigner},785 () => collectionWithEthOwner.methods.addCollectionAdminCross(crossReceiver).send(),786 );787788 res['removeCollectionAdminCross'] =789 await helper.arrange.calculcateFeeGas(790 {Ethereum: ethSigner},791 () => collectionWithEthOwner.methods.removeCollectionAdminCross(crossReceiver).send(),792 );793794 res['addCollectionAdminCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(795 {Substrate: donor.address},796 () => collection.addAdmin(donor, {Ethereum: ethReceiver}),797 )));798799 res['removeCollectionAdminCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(800 {Substrate: donor.address},801 () => collection.removeAdmin(donor, {Ethereum: ethReceiver}),802 )));803804 res['setCollectionNesting'] =805 await helper.arrange.calculcateFeeGas(806 {Ethereum: ethSigner},807 () => evmContract.methods.setCollectionNesting(true).send(),808 );809810 res['setCollectionNesting[]'] =811 await helper.arrange.calculcateFeeGas(812 {Ethereum: ethSigner},813 () => evmContract.methods.setCollectionNesting(true, [collectionAddress]).send(),814 );815816 res['setCollectionNesting'].substrate = convertToTokens((await helper.arrange.calculcateFee(817 {Substrate: donor.address},818 () => collection.disableNesting(donor),819 )));820821 res['setCollectionNesting[]'].substrate = convertToTokens((await helper.arrange.calculcateFee(822 {Substrate: donor.address},823 () => collection.setPermissions(824 donor,825 {826 nesting: {827 tokenOwner: true,828 restricted: [collection.collectionId],829 },830 },831 ),832 )));833834 res['setCollectionAccess'] =835 await helper.arrange.calculcateFeeGas(836 {Ethereum: ethSigner},837 () => evmContract.methods.setCollectionAccess(1).send(),838 );839840 res['setCollectionAccess'].substrate = convertToTokens((await helper.arrange.calculcateFee(841 {Substrate: donor.address},842 () => collection.setPermissions(donor, {access: 'AllowList'}),843 )));844845 res['addToCollectionAllowListCross'] =846 await helper.arrange.calculcateFeeGas(847 {Ethereum: ethSigner},848 () => evmContract.methods.addToCollectionAllowListCross(crossReceiver).send(),849 );850851 res['removeFromCollectionAllowListCross'] =852 await helper.arrange.calculcateFeeGas(853 {Ethereum: ethSigner},854 () => evmContract.methods.removeFromCollectionAllowListCross(crossReceiver).send(),855 );856857 res['addToCollectionAllowListCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(858 {Substrate: donor.address},859 () => collection.addToAllowList(donor, {Ethereum: ethReceiver}),860 )));861862 res['removeFromCollectionAllowListCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(863 {Substrate: donor.address},864 () => collection.removeFromAllowList(donor, {Ethereum: ethReceiver}),865 )));866867 res['setCollectionMintMode'] =868 await helper.arrange.calculcateFeeGas(869 {Ethereum: ethSigner},870 () => evmContract.methods.setCollectionMintMode(true).send(),871 );872873 res['setCollectionMintMode'].substrate = convertToTokens((await helper.arrange.calculcateFee(874 {Substrate: donor.address},875 () => collection.setPermissions(donor, {mintMode: false}),876 )));877878 res['changeCollectionOwnerCross'] =879 await helper.arrange.calculcateFeeGas(880 {Ethereum: ethSigner},881 () => collectionWithEthOwner.methods.changeCollectionOwnerCross(crossReceiver).send(),882 );883884 res['changeCollectionOwnerCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(885 {Substrate: donor.address},886 () => collection.changeOwner(donor, subReceiver.address),887 )));888889 return res;890}tests/src/eth/util/index.tsdiffbeforeafterboth--- a/tests/src/eth/util/index.ts
+++ b/tests/src/eth/util/index.ts
@@ -59,7 +59,7 @@
}
return account;
};
- await code(helper, privateKey);
+ return;
}
finally {
await helper.disconnect();
tests/src/nesting/collectionProperties.test.tsdiffbeforeafterboth--- a/tests/src/nesting/collectionProperties.test.ts
+++ b/tests/src/nesting/collectionProperties.test.ts
@@ -235,7 +235,7 @@
itSub('Fails to set properties that exceed the limits', async ({helper}) => {
const collection = await helper[testSuite.mode].mintCollection(alice);
- const spaceLimit = helper.getApi().consts.unique.maxCollectionPropertiesSize.toNumber();
+ const spaceLimit = Number(helper.getApi().consts.unique.maxCollectionPropertiesSize);
// Mute the general tx parsing error, too many bytes to process
{
tests/src/util/index.tsdiffbeforeafterboth--- a/tests/src/util/index.ts
+++ b/tests/src/util/index.ts
@@ -57,7 +57,7 @@
}
return account;
};
- await code(helper, privateKey);
+ return;
}
finally {
await helper.disconnect();