difftreelog
feat changed measurements algo for `mint`
in: master
1 file changed
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, 'test').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['setProperties'] =160 await helper.arrange.calculcateFeeGas(161 {Ethereum: ethSigner},162 () => evmContract.methods.setProperties(1, PROPERTIES.slice(0,1)).send(),163 );164165 res['deleteProperties'] =166 await helper.arrange.calculcateFeeGas(167 {Ethereum: ethSigner},168 () => evmContract.methods.deleteProperties(1, [PROPERTIES[0].key]).send(),169 );170171 res['setProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(172 {Substrate: donor.address},173 () => collection.setTokenProperties(174 donor,175 1,176 SUBS_PROPERTIES.slice(0, 1),177 ),178 )));179180 res['deleteProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(181 {Substrate: donor.address},182 () => collection.deleteTokenProperties(183 donor,184 1,185 SUBS_PROPERTIES.slice(0, 1)186 .map(p => p.key),187 ),188 )));189190 res['transfer'] =191 await helper.arrange.calculcateFeeGas(192 {Ethereum: ethSigner},193 () => evmContract.methods.transfer(ethReceiver, 1).send(),194 );195196 res['safeTransferFrom*'] = {197 zeppelin:198 await helper.arrange.calculcateFeeGas(199 {Ethereum: ethSigner},200 () => zeppelelinContract!.methods.safeTransferFrom(ethSigner, ethReceiver, 0).send({from: ethSigner}),201 ),202 };203204 res['transferCross'] =205 await helper.arrange.calculcateFeeGas(206 {Ethereum: ethReceiver},207 () => evmContract.methods.transferCross(crossSigner, 1).send({from: ethReceiver}),208 );209210 res['transferCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(211 {Substrate: donor.address},212 () => collection.transferToken(213 donor,214 3,215 {Substrate: subReceiver.address},216 ),217 )));218 await collection.approveToken(subReceiver, 3, {Substrate: donor.address});219220 res['transferFrom*'] =221 await helper.arrange.calculcateFeeGas(222 {Ethereum: ethSigner},223 () => evmContract.methods.transferFrom(ethSigner, ethReceiver, 1).send(),224 );225226 res['transferFrom*'].zeppelin =227 await helper.arrange.calculcateFeeGas(228 {Ethereum: ethReceiver},229 () => zeppelelinContract!.methods.transferFrom(ethReceiver, ethSigner, 0).send({from: ethReceiver}),230 );231232233 res['transferFromCross'] =234 await helper.arrange.calculcateFeeGas(235 {Ethereum: ethReceiver},236 () => evmContract.methods.transferFromCross(crossReceiver, crossSigner, 1).send({from:ethReceiver}),237 );238239 res['transferFromCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(240 {Substrate: donor.address},241 () => collection.transferTokenFrom(donor, 3, {Substrate: subReceiver.address}, {Substrate: donor.address}),242 )));243244 res['burn'] =245 await helper.arrange.calculcateFeeGas(246 {Ethereum: ethSigner},247 () => evmContract.methods.burn(1).send(),248 );249250 res['burn'].substrate = convertToTokens((await helper.arrange.calculcateFee(251 {Substrate: donor.address},252 () => collection.burnToken(donor, 3),253 )));254255 res['approve*'] =256 await helper.arrange.calculcateFeeGas(257 {Ethereum: ethSigner},258 () => evmContract.methods.approve(ethReceiver, 2).send(),259 );260261 res['approve*'].zeppelin =262 await helper.arrange.calculcateFeeGas(263 {Ethereum: ethSigner},264 () => zeppelelinContract!.methods.approve(ethReceiver, 0).send({from: ethSigner}),265 );266267 res['approveCross'] =268 await helper.arrange.calculcateFeeGas(269 {Ethereum: ethSigner},270 () => evmContract.methods.approveCross(crossReceiver, 2).send(),271 );272273 res['approveCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(274 {Substrate: donor.address},275 () => collection.approveToken(donor, 4, {Substrate: subReceiver.address}),276 )));277278 res['setApprovalForAll*'] =279 await helper.arrange.calculcateFeeGas(280 {Ethereum: ethSigner},281 () => evmContract.methods.setApprovalForAll(ethReceiver, true).send(),282 );283284 res['setApprovalForAll*'].zeppelin =285 await helper.arrange.calculcateFeeGas(286 {Ethereum: ethSigner},287 () => zeppelelinContract!.methods.setApprovalForAll(ethReceiver, true).send({from: ethSigner}),288 );289290 res['setApprovalForAll*'].substrate = convertToTokens((await helper.arrange.calculcateFee(291 {Substrate: donor.address},292 () => helper.nft.setAllowanceForAll(donor, collection.collectionId, {Substrate: subReceiver.address}, true),293 )));294295 res['burnFromCross'] =296 await helper.arrange.calculcateFeeGas(297 {Ethereum: ethReceiver},298 () => evmContract.methods.burnFromCross(crossSigner, 2).send({from:ethReceiver}),299 );300301 res['burnFromCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(302 {Substrate: subReceiver.address},303 () => collection.burnTokenFrom(subReceiver, 4, {Substrate: donor.address}),304 )));305306 res['setTokenPropertyPermissions'] =307 await helper.arrange.calculcateFeeGas(308 {Ethereum: ethSigner},309 () => evmContract.methods.setTokenPropertyPermissions([310 ['url', [311 [TokenPermissionField.Mutable, true],312 [TokenPermissionField.TokenOwner, true],313 [TokenPermissionField.CollectionAdmin, true]],314 ],315 ]).send(),316 );317318 res['setTokenPropertyPermissions'].substrate = convertToTokens((await helper.arrange.calculcateFee(319 {Substrate: donor.address},320 () => collection.setTokenPropertyPermissions(donor, [{key: 'url', permission: {321 tokenOwner: true,322 collectionAdmin: true,323 mutable: true,324 }}]),325 )));326327 res['setCollectionSponsorCross'] =328 await helper.arrange.calculcateFeeGas(329 {Ethereum: ethSigner},330 () => evmContract.methods.setCollectionSponsorCross(crossReceiver).send(),331 );332333 res['confirmCollectionSponsorship'] =334 await helper.arrange.calculcateFeeGas(335 {Ethereum: ethReceiver},336 () => evmContract.methods.confirmCollectionSponsorship().send({from: ethReceiver}),337 );338339 res['removeCollectionSponsor'] =340 await helper.arrange.calculcateFeeGas(341 {Ethereum: ethSigner},342 () => evmContract.methods.removeCollectionSponsor().send(),343 );344345 res['setCollectionSponsorCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(346 {Substrate: donor.address},347 () => collection.setSponsor(donor, subReceiver.address),348 )));349350 res['confirmCollectionSponsorship'].substrate = convertToTokens((await helper.arrange.calculcateFee(351 {Substrate: subReceiver.address},352 () => collection.confirmSponsorship(subReceiver),353 )));354355 res['removeCollectionSponsor'].substrate = convertToTokens((await helper.arrange.calculcateFee(356 {Substrate: donor.address},357 () => collection.removeSponsor(donor),358 )));359360 res['setCollectionProperties'] =361 await helper.arrange.calculcateFeeGas(362 {Ethereum: ethSigner},363 () => evmContract.methods.setCollectionProperties(PROPERTIES.slice(0, 1)).send(),364 );365366 res['deleteCollectionProperties'] =367 await helper.arrange.calculcateFeeGas(368 {Ethereum: ethSigner},369 () => evmContract.methods.deleteCollectionProperties(PROPERTIES.slice(0,1).map(p => p.key)).send(),370 );371 res['setCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(372 {Substrate: donor.address},373 () => collection.setProperties(donor, PROPERTIES.slice(0, 1)374 .map(p => { return {key: p.key, value: p.value.toString()}; })),375 )));376377 res['deleteCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(378 {Substrate: donor.address},379 () => collection.deleteProperties(donor, PROPERTIES.slice(0, 1)380 .map(p => p.key)),381 )));382383 res['setCollectionLimit'] =384 await helper.arrange.calculcateFeeGas(385 {Ethereum: ethSigner},386 () => evmContract.methods.setCollectionLimit({field: CollectionLimitField.AccountTokenOwnership, value: {status: true, value: 1000}}).send(),387 );388389 res['setCollectionLimit'].substrate = convertToTokens((await helper.arrange.calculcateFee(390 {Substrate: donor.address},391 () => collection.setLimits(donor, {accountTokenOwnershipLimit: 1000}),392 )));393394 const {collectionAddress} = await helper.eth.createCollection('nft', ethSigner, 'A', 'B', 'C');395 const collectionWithEthOwner = await helper.ethNativeContract.collection(collectionAddress, 'nft', ethSigner, true);396397398 res['addCollectionAdminCross'] =399 await helper.arrange.calculcateFeeGas(400 {Ethereum: ethSigner},401 () => collectionWithEthOwner.methods.addCollectionAdminCross(crossReceiver).send(),402 );403404 res['removeCollectionAdminCross'] =405 await helper.arrange.calculcateFeeGas(406 {Ethereum: ethSigner},407 () => collectionWithEthOwner.methods.removeCollectionAdminCross(crossReceiver).send(),408 );409410 res['addCollectionAdminCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(411 {Substrate: donor.address},412 () => collection.addAdmin(donor, {Ethereum: ethReceiver}),413 )));414415 res['removeCollectionAdminCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(416 {Substrate: donor.address},417 () => collection.removeAdmin(donor, {Ethereum: ethReceiver}),418 )));419420 res['setCollectionNesting'] =421 await helper.arrange.calculcateFeeGas(422 {Ethereum: ethSigner},423 () => evmContract.methods.setCollectionNesting(true).send(),424 );425426 res['setCollectionNesting[]'] =427 await helper.arrange.calculcateFeeGas(428 {Ethereum: ethSigner},429 () => evmContract.methods.setCollectionNesting(true, [collectionAddress]).send(),430 );431432 res['setCollectionNesting'].substrate = convertToTokens((await helper.arrange.calculcateFee(433 {Substrate: donor.address},434 () => collection.disableNesting(donor),435 )));436437 res['setCollectionNesting[]'].substrate = convertToTokens((await helper.arrange.calculcateFee(438 {Substrate: donor.address},439 () => collection.setPermissions(440 donor,441 {442 nesting: {443 tokenOwner: true,444 restricted: [collection.collectionId],445 },446 },447 ),448 )));449450 res['setCollectionAccess'] =451 await helper.arrange.calculcateFeeGas(452 {Ethereum: ethSigner},453 () => evmContract.methods.setCollectionAccess(1).send(),454 );455456 res['setCollectionAccess'].substrate = convertToTokens((await helper.arrange.calculcateFee(457 {Substrate: donor.address},458 () => collection.setPermissions(donor, {access: 'AllowList'}),459 )));460461 res['addToCollectionAllowListCross'] =462 await helper.arrange.calculcateFeeGas(463 {Ethereum: ethSigner},464 () => evmContract.methods.addToCollectionAllowListCross(crossReceiver).send(),465 );466467 res['removeFromCollectionAllowListCross'] =468 await helper.arrange.calculcateFeeGas(469 {Ethereum: ethSigner},470 () => evmContract.methods.removeFromCollectionAllowListCross(crossReceiver).send(),471 );472473 res['addToCollectionAllowListCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(474 {Substrate: donor.address},475 () => collection.addToAllowList(donor, {Ethereum: ethReceiver}),476 )));477478 res['removeFromCollectionAllowListCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(479 {Substrate: donor.address},480 () => collection.removeFromAllowList(donor, {Ethereum: ethReceiver}),481 )));482483 res['setCollectionMintMode'] =484 await helper.arrange.calculcateFeeGas(485 {Ethereum: ethSigner},486 () => evmContract.methods.setCollectionMintMode(true).send(),487 );488489 res['setCollectionMintMode'].substrate = convertToTokens((await helper.arrange.calculcateFee(490 {Substrate: donor.address},491 () => collection.setPermissions(donor, {mintMode: false}),492 )));493494 res['changeCollectionOwnerCross'] =495 await helper.arrange.calculcateFeeGas(496 {Ethereum: ethSigner},497 () => collectionWithEthOwner.methods.changeCollectionOwnerCross(crossReceiver).send(),498 );499500 res['changeCollectionOwnerCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(501 {Substrate: donor.address},502 () => collection.changeOwner(donor, subReceiver.address),503 )));504505 return res;506}507508async function erc20CalculateFeeGas(509 helper: EthUniqueHelper,510 privateKey: (seed: string) => Promise<IKeyringPair>,511512): Promise<IFunctionFee> {513 const res: IFunctionFee = {};514 const donor = await privateKey('//Alice');515 const [subReceiver] = await helper.arrange.createAccounts([10n], donor);516 const ethSigner = await helper.eth.createAccountWithBalance(donor, 100n);517 const ethReceiver = await helper.eth.createAccountWithBalance(donor, 10n);518 const crossSigner = helper.ethCrossAccount.fromAddress(ethSigner);519 const crossReceiver = helper.ethCrossAccount.fromAddress(ethReceiver);520 const collection = (await createCollectionForBenchmarks(521 'ft',522 helper,523 privateKey,524 ethSigner,525 null,526 PERMISSIONS,527 )) as UniqueFTCollection;528529 const helperContract = await helper.ethNativeContract.collectionHelpers(ethSigner);530 let zeppelelinContract: Contract | null = null;531 const ZEPPELIN_OBJECT = '0x' + (await readFile(`${__dirname}/../utils/openZeppelin/ERC20/bin/ZeppelinContract.bin`)).toString();532 const ZEPPELIN_ABI = JSON.parse((await readFile(`${__dirname}/../utils/openZeppelin/ERC20/bin/ZeppelinContract.abi`)).toString());533534 const evmContract = await helper.ethNativeContract.collection(535 helper.ethAddress.fromCollectionId(collection.collectionId),536 'ft',537 ethSigner,538 true,539 );540541 res['createCollection'] = await helper.arrange.calculcateFeeGas(542 {Ethereum: ethSigner},543 () => helperContract.methods.createFTCollection('test', 18,'test','test').send({from: ethSigner, value: Number(2n * helper.balance.getOneTokenNominal())}),544 );545546 res['createCollection'].substrate = convertToTokens((await helper.arrange.calculcateFee(547 {Substrate: donor.address},548 () => helper.ft.mintCollection(549 donor,550 {name: 'test', description: 'test', tokenPrefix: 'test'},551 18,552 ),553 )));554555 res['createCollection'].zeppelin = await helper.arrange.calculcateFeeGas(556 {Ethereum: ethSigner},557 async () => {558 zeppelelinContract = await helper.ethContract.deployByAbi(559 ethSigner,560 ZEPPELIN_ABI,561 ZEPPELIN_OBJECT,562 );563 },564 );565566 res['mint'] =567 await helper.arrange.calculcateFeeGas(568 {Ethereum: ethSigner},569 () => evmContract.methods.mint(ethSigner, 1).send(),570 );571572 res['mint'].zeppelin =573 await helper.arrange.calculcateFeeGas(574 {Ethereum: ethSigner},575 () => zeppelelinContract!.methods.mint(ethSigner, 1).send(),576 );577578 res['mintCross'] =579 await helper.arrange.calculcateFeeGas(580 {Ethereum: ethSigner},581 () => evmContract.methods.mintCross(crossSigner, 1).send(),582 );583584 res['mintCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(585 {Substrate: donor.address},586 () => collection.mint(587 donor,588 10n,589 {Substrate: donor.address},590 ),591 )));592593 res['mintBulk'] =594 await helper.arrange.calculcateFeeGas(595 {Ethereum: ethSigner},596 () => evmContract.methods.mintBulk([{to: ethSigner, amount: 1}]).send(),597 );598599 res['mintBulk'].substrate = convertToTokens((await helper.arrange.calculcateFee(600 {Substrate: donor.address},601 () => helper.executeExtrinsic(donor, 'api.tx.unique.createMultipleItemsEx',[collection.collectionId, {602 Fungible: new Map([603 [JSON.stringify({Ethereum: ethSigner}), 1],604 ]),605 }], true),606 )));607608 res['transfer*'] =609 await helper.arrange.calculcateFeeGas(610 {Ethereum: ethSigner},611 () => evmContract.methods.transfer(ethReceiver, 1).send(),612 );613614 res['transfer*'].zeppelin =615 await helper.arrange.calculcateFeeGas(616 {Ethereum: ethSigner},617 () => zeppelelinContract!.methods.transfer(ethReceiver, 1).send(),618 );619620 res['transferCross'] =621 await helper.arrange.calculcateFeeGas(622 {Ethereum: ethReceiver},623 () => evmContract.methods.transferCross(crossSigner, 1).send({from: ethReceiver}),624 );625626 res['transferCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(627 {Substrate: donor.address},628 () => collection.transfer(629 donor,630 {Substrate: subReceiver.address},631 1n,632 ),633 )));634 await collection.approveTokens(subReceiver, {Substrate: donor.address}, 1n);635636 res['transferFrom*'] =637 await helper.arrange.calculcateFeeGas(638 {Ethereum: ethSigner},639 () => evmContract.methods.transferFrom(ethSigner, ethReceiver, 1).send(),640 );641642 await zeppelelinContract!.methods.approve(ethSigner, 10).send({from: ethReceiver});643644 res['transferFrom*'].zeppelin =645 await helper.arrange.calculcateFeeGas(646 {Ethereum: ethSigner},647 () => zeppelelinContract!.methods.transferFrom(ethReceiver, ethSigner, 1).send({from: ethSigner}),648 );649650 res['transferFromCross'] =651 await helper.arrange.calculcateFeeGas(652 {Ethereum: ethReceiver},653 () => evmContract.methods.transferFromCross(crossReceiver, crossSigner, 1).send({from:ethReceiver}),654 );655656 res['transferFromCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(657 {Substrate: donor.address},658 () => collection.transferFrom(donor, {Substrate: subReceiver.address}, {Substrate: donor.address}, 1n),659 )));660661662 res['burnTokens'] = {fee: 0n, gas: 0n};663 res['burnTokens'].substrate = convertToTokens((await helper.arrange.calculcateFee(664 {Substrate: donor.address},665 () => collection.burnTokens(donor, 1n),666 )));667668669 res['approve*'] =670 await helper.arrange.calculcateFeeGas(671 {Ethereum: ethSigner},672 () => evmContract.methods.approve(ethReceiver, 2).send(),673 );674675 res['approve*'].zeppelin =676 await helper.arrange.calculcateFeeGas(677 {Ethereum: ethSigner},678 () => zeppelelinContract!.methods.approve(ethReceiver, 10).send(),679 );680681 res['approveCross'] =682 await helper.arrange.calculcateFeeGas(683 {Ethereum: ethSigner},684 () => evmContract.methods.approveCross(crossReceiver, 2).send(),685 );686687 res['approveCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(688 {Substrate: donor.address},689 () => collection.approveTokens(donor, {Substrate: subReceiver.address}, 1n),690 )));691692 res['burnFromCross'] =693 await helper.arrange.calculcateFeeGas(694 {Ethereum: ethReceiver},695 () => evmContract.methods.burnFromCross(crossSigner, 1).send({from:ethReceiver}),696 );697698 res['burnFromCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(699 {Substrate: subReceiver.address},700 () => collection.burnTokensFrom(subReceiver, {Substrate: donor.address}, 1n),701 )));702703 res['setCollectionSponsorCross'] =704 await helper.arrange.calculcateFeeGas(705 {Ethereum: ethSigner},706 () => evmContract.methods.setCollectionSponsorCross(crossReceiver).send(),707 );708709 res['confirmCollectionSponsorship'] =710 await helper.arrange.calculcateFeeGas(711 {Ethereum: ethReceiver},712 () => evmContract.methods.confirmCollectionSponsorship().send({from: ethReceiver}),713 );714715 res['removeCollectionSponsor'] =716 await helper.arrange.calculcateFeeGas(717 {Ethereum: ethSigner},718 () => evmContract.methods.removeCollectionSponsor().send(),719 );720721 res['setCollectionSponsorCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(722 {Substrate: donor.address},723 () => collection.setSponsor(donor, subReceiver.address),724 )));725726 res['confirmCollectionSponsorship'].substrate = convertToTokens((await helper.arrange.calculcateFee(727 {Substrate: subReceiver.address},728 () => collection.confirmSponsorship(subReceiver),729 )));730731 res['removeCollectionSponsor'].substrate = convertToTokens((await helper.arrange.calculcateFee(732 {Substrate: donor.address},733 () => collection.removeSponsor(donor),734 )));735736 res['setCollectionProperties'] =737 await helper.arrange.calculcateFeeGas(738 {Ethereum: ethSigner},739 () => evmContract.methods.setCollectionProperties(PROPERTIES.slice(0, 1)).send(),740 );741742 res['deleteCollectionProperties'] =743 await helper.arrange.calculcateFeeGas(744 {Ethereum: ethSigner},745 () => evmContract.methods.deleteCollectionProperties(PROPERTIES.slice(0,1).map(p => p.key)).send(),746 );747 res['setCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(748 {Substrate: donor.address},749 () => collection.setProperties(donor, PROPERTIES.slice(0, 1)750 .map(p => { return {key: p.key, value: p.value.toString()}; })),751 )));752753 res['deleteCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(754 {Substrate: donor.address},755 () => collection.deleteProperties(donor, PROPERTIES.slice(0, 1)756 .map(p => p.key)),757 )));758759 res['setCollectionLimit'] =760 await helper.arrange.calculcateFeeGas(761 {Ethereum: ethSigner},762 () => evmContract.methods.setCollectionLimit({field: CollectionLimitField.AccountTokenOwnership, value: {status: true, value: 1000}}).send(),763 );764765 res['setCollectionLimit'].substrate = convertToTokens((await helper.arrange.calculcateFee(766 {Substrate: donor.address},767 () => collection.setLimits(donor, {accountTokenOwnershipLimit: 1000}),768 )));769770 const {collectionAddress} = await helper.eth.createCollection('nft', ethSigner, 'A', 'B', 'C');771 const collectionWithEthOwner = await helper.ethNativeContract.collection(collectionAddress, 'nft', ethSigner, true);772773774 res['addCollectionAdminCross'] =775 await helper.arrange.calculcateFeeGas(776 {Ethereum: ethSigner},777 () => collectionWithEthOwner.methods.addCollectionAdminCross(crossReceiver).send(),778 );779780 res['removeCollectionAdminCross'] =781 await helper.arrange.calculcateFeeGas(782 {Ethereum: ethSigner},783 () => collectionWithEthOwner.methods.removeCollectionAdminCross(crossReceiver).send(),784 );785786 res['addCollectionAdminCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(787 {Substrate: donor.address},788 () => collection.addAdmin(donor, {Ethereum: ethReceiver}),789 )));790791 res['removeCollectionAdminCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(792 {Substrate: donor.address},793 () => collection.removeAdmin(donor, {Ethereum: ethReceiver}),794 )));795796 res['setCollectionNesting'] =797 await helper.arrange.calculcateFeeGas(798 {Ethereum: ethSigner},799 () => evmContract.methods.setCollectionNesting(true).send(),800 );801802 res['setCollectionNesting[]'] =803 await helper.arrange.calculcateFeeGas(804 {Ethereum: ethSigner},805 () => evmContract.methods.setCollectionNesting(true, [collectionAddress]).send(),806 );807808 res['setCollectionNesting'].substrate = convertToTokens((await helper.arrange.calculcateFee(809 {Substrate: donor.address},810 () => collection.disableNesting(donor),811 )));812813 res['setCollectionNesting[]'].substrate = convertToTokens((await helper.arrange.calculcateFee(814 {Substrate: donor.address},815 () => collection.setPermissions(816 donor,817 {818 nesting: {819 tokenOwner: true,820 restricted: [collection.collectionId],821 },822 },823 ),824 )));825826 res['setCollectionAccess'] =827 await helper.arrange.calculcateFeeGas(828 {Ethereum: ethSigner},829 () => evmContract.methods.setCollectionAccess(1).send(),830 );831832 res['setCollectionAccess'].substrate = convertToTokens((await helper.arrange.calculcateFee(833 {Substrate: donor.address},834 () => collection.setPermissions(donor, {access: 'AllowList'}),835 )));836837 res['addToCollectionAllowListCross'] =838 await helper.arrange.calculcateFeeGas(839 {Ethereum: ethSigner},840 () => evmContract.methods.addToCollectionAllowListCross(crossReceiver).send(),841 );842843 res['removeFromCollectionAllowListCross'] =844 await helper.arrange.calculcateFeeGas(845 {Ethereum: ethSigner},846 () => evmContract.methods.removeFromCollectionAllowListCross(crossReceiver).send(),847 );848849 res['addToCollectionAllowListCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(850 {Substrate: donor.address},851 () => collection.addToAllowList(donor, {Ethereum: ethReceiver}),852 )));853854 res['removeFromCollectionAllowListCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(855 {Substrate: donor.address},856 () => collection.removeFromAllowList(donor, {Ethereum: ethReceiver}),857 )));858859 res['setCollectionMintMode'] =860 await helper.arrange.calculcateFeeGas(861 {Ethereum: ethSigner},862 () => evmContract.methods.setCollectionMintMode(true).send(),863 );864865 res['setCollectionMintMode'].substrate = convertToTokens((await helper.arrange.calculcateFee(866 {Substrate: donor.address},867 () => collection.setPermissions(donor, {mintMode: false}),868 )));869870 res['changeCollectionOwnerCross'] =871 await helper.arrange.calculcateFeeGas(872 {Ethereum: ethSigner},873 () => collectionWithEthOwner.methods.changeCollectionOwnerCross(crossReceiver).send(),874 );875876 res['changeCollectionOwnerCross'].substrate = convertToTokens((await helper.arrange.calculcateFee(877 {Substrate: donor.address},878 () => collection.changeOwner(donor, subReceiver.address),879 )));880881 return res;882}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';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}