1import { EthUniqueHelper, usingEthPlaygrounds } from '../util';2import { readFile } from 'fs/promises';3import { ContractImports } from '../util/playgrounds/types';4import { Contract } from '@polkadot/api-contract/base';5import Web3 from 'web3';6import {7 IProperty,8 ITokenPropertyPermission,9} from '../../util/playgrounds/types';10import { addressToEvm, decodeAddress } from '@polkadot/util-crypto';11import nonFungibleAbi from '../nonFungibleAbi.json';12import { IKeyringPair } from '@polkadot/types/types';1314enum SponsoringMode {15 Disabled = 0,16 Allowlisted = 1,17 Generous = 2,18}1920const WS_ENDPOINT = 'wss://ws-rc.unique.network';21const CONTRACT_IMPORT: ContractImports[] = [22 {23 fsPath: `${__dirname}/../api/CollectionHelpers.sol`,24 solPath: 'api/CollectionHelpers.sol',25 },26 {27 fsPath: `${__dirname}/../api/ContractHelpers.sol`,28 solPath: 'api/ContractHelpers.sol',29 },30 {31 fsPath: `${__dirname}/../api/UniqueRefungibleToken.sol`,32 solPath: 'api/UniqueRefungibleToken.sol',33 },34 {35 fsPath: `${__dirname}/../api/UniqueRefungible.sol`,36 solPath: 'api/UniqueRefungible.sol',37 },38 {39 fsPath: `${__dirname}/../api/UniqueNFT.sol`,40 solPath: 'api/UniqueNFT.sol',41 },42];4344const main = async () => {45 await usingEthPlaygrounds(async (helper, privateKey) => {46 const contract_source = (47 await readFile(`${__dirname}/EvmToSubstrateHelper.sol`)48 ).toString();4950 const donor = await privateKey('//Alice'); 51 const myAccount = await privateKey('//Bob'); 52 const signer = await helper.eth.createAccountWithBalance(donor, 100n);53 console.log(`signer data: ${Uint8Array.from(Buffer.from(signer.slice(2), 'hex'))}`)54 const collection = await helper.nft.mintCollection(donor, {55 name: 'test mintToSubstrate',56 description: 'EVMHelpers',57 tokenPrefix: 'ap',58 tokenPropertyPermissions: [59 {60 key: 'url',61 permission: {62 tokenOwner: true,63 collectionAdmin: true,64 mutable: true,65 },66 },67 ],68 limits: { sponsorTransferTimeout: 0, sponsorApproveTimeout: 0 },69 permissions: { mintMode: true },70 });7172 await collection.addToAllowList(donor, {73 Ethereum: helper.address.substrateToEth(donor.address),74 });75 await collection.addToAllowList(donor, { Substrate: donor.address });76 await collection.addAdmin(donor, { Ethereum: signer });77 await collection.addAdmin(donor, {78 Ethereum: helper.address.substrateToEth(donor.address),79 });8081 console.log('collection admin(s)): ', await collection.getAdmins());82 console.log('collection owner(s)): ', await collection.getAllowList());8384 const collectionEthAddress = helper.ethAddress.fromCollectionId(85 collection.collectionId,86 );8788 const collectionEthContract = helper.ethNativeContract.collection(89 collectionEthAddress,90 'nft',91 );9293 const receiverEthAddress = helper.address.substrateToEth(myAccount.address);94 95 const contract = await helper.ethContract.deployByCode(96 signer,97 'EvmToSubstrate',98 contract_source,99 CONTRACT_IMPORT,100 );101 console.log(`contract has been deployed\naddres: ${contract.options.address} || ${Uint8Array.from(Buffer.from(contract.options.address.slice(2), 'hex'))}`);102103 await helper.eth.transferBalanceFromSubstrate(104 donor,105 contract.options.address,106 100n,107 );108109 console.log(`transfer has been completed`);110111 await collection.addToAllowList(donor, {112 Ethereum: contract.options.address,113 });114 await collection.addAdmin(donor, { Ethereum: contract.options.address });115116 console.log(`setup has been completed`);117118 console.log('\t\t\t *** Properties Fees ***\n');119120 const propertiesNumber = 20;121122 const properties = Array(40)123 .fill(0)124 .map((_, i) => {125 return {126 key: `key_${i}`,127 value: Uint8Array.from(Buffer.from(`value_${i}`)),128 };129 });130131 const permissions: ITokenPropertyPermission[] = properties.map((p) => {132 return {133 key: p.key,134 permission: {135 tokenOwner: true,136 collectionAdmin: true,137 mutable: true,138 },139 };140 });141142 143144 const token = await collection.mintToken(donor, { Ethereum: signer });145146 const mintWithBulkPropProxyContractFee = await helper.arrange.calculcateFee(147 { Ethereum: signer },148 async () => {149 await contract.methods150 .proxyProperties(151 collectionEthContract.options.address,152 token.tokenId,153 properties.slice(0, propertiesNumber).map((p) => {154 return { field_0: p.key, field_1: p.value };155 }),156 )157 .send({ from: signer });158 },159 );160 console.log(161 `token mint from contract(with bulk prop.) to the Substrate Id: ${mintWithBulkPropProxyContractFee}`,162 );163164 console.log('All done');165 });166};167168main()169 .then(() => process.exit(0))170 .catch((e) => {171 console.log(e);172 process.exit(1);173 });174175async function createCollectionForPropertiesBenchmarks(176 helper: EthUniqueHelper,177 privateKey: (seed: string) => Promise<IKeyringPair>,178 ethSigner: string,179 proxyContract: string,180 permissions: ITokenPropertyPermission[],181) {182 const donor = await privateKey('//Alice'); 183184 const collection = await helper.nft.mintCollection(donor, {185 name: 'test mintToSubstrate',186 description: 'EVMHelpers',187 tokenPrefix: 'ap',188 tokenPropertyPermissions: [189 {190 key: 'url',191 permission: {192 tokenOwner: true,193 collectionAdmin: true,194 mutable: true,195 },196 },197 ],198 limits: { sponsorTransferTimeout: 0, sponsorApproveTimeout: 0 },199 permissions: { mintMode: true },200 });201202 await collection.addToAllowList(donor, {203 Ethereum: helper.address.substrateToEth(donor.address),204 });205 await collection.addToAllowList(donor, { Substrate: donor.address });206 await collection.addAdmin(donor, { Ethereum: ethSigner });207 await collection.addAdmin(donor, {208 Ethereum: helper.address.substrateToEth(donor.address),209 });210 await collection.addToAllowList(donor, { Ethereum: proxyContract });211 await collection.addAdmin(donor, { Ethereum: proxyContract });212 await collection.setTokenPropertyPermissions(donor, permissions);213214 return collection;215}