12import {EthUniqueHelper, usingEthPlaygrounds} from '../util/playgrounds';3import {readFile} from 'fs/promises';4import {ContractImports} from '../util/playgrounds/types';5import {Contract} from '@polkadot/api-contract/base';6import Web3 from 'web3';7import {IProperty, ITokenPropertyPermission} from '../../util/playgrounds/types';8import {addressToEvm, decodeAddress} from '@polkadot/util-crypto';9import nonFungibleAbi from '../nonFungibleAbi.json';10import {CrossAccountId} from '../../util/helpers';11import {IKeyringPair} from '@polkadot/types/types';1213enum SponsoringMode {14 Disabled = 0,15 Allowlisted = 1,16 Generous = 2,17}1819const WS_ENDPOINT = 'wss://ws-rc.unique.network';20const CONTRACT_IMPORT: ContractImports[] = [21 {22 fsPath: `${__dirname}/../api/CollectionHelpers.sol`,23 solPath: 'api/CollectionHelpers.sol',24 },25 {26 fsPath: `${__dirname}/../api/ContractHelpers.sol`,27 solPath: 'api/ContractHelpers.sol',28 },29 {30 fsPath: `${__dirname}/../api/UniqueRefungibleToken.sol`,31 solPath: 'api/UniqueRefungibleToken.sol',32 },33 {34 fsPath: `${__dirname}/../api/UniqueRefungible.sol`,35 solPath: 'api/UniqueRefungible.sol',36 },37 {38 fsPath: `${__dirname}/../api/UniqueNFT.sol`,39 solPath: 'api/UniqueNFT.sol',40 },41];42const main = async () => {43 await usingEthPlaygrounds(async (helper, privateKey) => {44 const contract_source = (45 await readFile(`${__dirname}/EvmToSubstrateHelper.sol`)46 ).toString();47 48 49 const donor = privateKey('//Alice'); 50 const myAccount = privateKey('//Bob'); 51 console.log('donor raw sub: ', donor.addressRaw);52 console.log('donor sub->eth->sub: ', decodeAddress(await helper.address.ethToSubstrate(helper.address.substrateToEth(donor.address))));53 console.log('donor sub: ', donor.address);5455 console.log('donor raw eth: ', Uint8Array.from(Buffer.from(helper.address.substrateToEth(donor.address).slice(2), 'hex')));56 console.log('donor eth: ', helper.address.substrateToEth(donor.address));57 58 const signer = await helper.eth.createAccountWithBalance(donor, 100n);59 60 console.log('\nsigner eth: ', signer);61 console.log('signer raw eth: ', Uint8Array.from(Buffer.from(signer.slice(2), 'hex')));62 console.log('signer raw sub: ', decodeAddress(await helper.address.ethToSubstrate(signer)));6364 const collection = await helper.nft.mintCollection(donor, {65 name: 'test mintToSubstrate',66 description: 'EVMHelpers',67 tokenPrefix: 'ap',68 tokenPropertyPermissions: [69 {70 key: 'url',71 permission: {72 tokenOwner: true,73 collectionAdmin: true,74 mutable: true,75 },76 },77 ],78 limits: {sponsorTransferTimeout: 0, sponsorApproveTimeout: 0}, permissions: {mintMode: true},79 });80 81 82 83 await collection.addToAllowList(donor, {Substrate: myAccount.address});84 85 86 87 console.log('collection admin(s)): ', await collection.getAdmins());88 console.log('collection owner(s)): ', await collection.getAllowList());89 90 91 const collectionEthAddress = helper.ethAddress.fromCollectionId(collection.collectionId);92 const collectionContract = helper.ethNativeContract.collection(93 collectionEthAddress,94 'nft',95 );96 const receiverEthAddress = helper.address.substrateToEth(myAccount.address);97 98 console.log('myAccount eth mirror: ', receiverEthAddress);99 console.log('contract eth mirror: ', collectionEthAddress);100101 let subTokenId = await collectionContract.methods.nextTokenId().call();102103 const encodedCall = collectionContract.methods104 .mint(receiverEthAddress, subTokenId)105 .encodeABI();106107 const ethFee = await helper.arrange.calculcateFee(108 {Substrate: donor.address},109 async () => {110 await helper.eth.sendEVM(111 myAccount,112 collectionContract.options.address,113 encodedCall,114 '0',115 );116 },117 );118119 console.log(`\ncollection mint from eth : ${ethFee}\n`);120121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 subTokenId = await collectionContract.methods.nextTokenId().call();140 console.log(subTokenId); 141 142 console.log('All done');143 });144};145 146main()147 .then(() => process.exit(0))148 .catch((e) => {149 console.log(e);150 process.exit(1);151 });152 153 154async function createCollectionForPropertiesBenchmarks(155 helper: EthUniqueHelper,156 privateKey: (seed: string) => IKeyringPair,157 ethSigner: string,158 proxyContract: string,159 permissions: ITokenPropertyPermission[],160) {161 162 const donor = privateKey('//Alice'); 163 164 165 const collection = await helper.nft.mintCollection(donor, {166 name: 'test mintToSubstrate',167 description: 'EVMHelpers',168 tokenPrefix: 'ap',169 tokenPropertyPermissions: [170 {171 key: 'url',172 permission: {173 tokenOwner: true,174 collectionAdmin: true,175 mutable: true,176 },177 },178 ],179 limits: {sponsorTransferTimeout: 0, sponsorApproveTimeout: 0}, permissions: {mintMode: true},180 });181 182 await collection.addToAllowList(donor, {Ethereum: helper.address.substrateToEth(donor.address)});183 await collection.addToAllowList(donor, {Substrate: donor.address});184 await collection.addAdmin(donor, {Ethereum: ethSigner});185 await collection.addAdmin(donor, {Ethereum: helper.address.substrateToEth(donor.address)});186 await collection.addToAllowList(donor, {Ethereum: proxyContract});187 await collection.addAdmin(donor, {Ethereum: proxyContract});188 await collection.setTokenPropertyPermissions(donor, permissions);189 190 return collection;191}