import Web3 from "web3"; import { abiNftMall } from "../abis/abiBENftMall"; import { abiChipLocker } from "../abis/abiChipLocker"; import { abiERC1155 } from "../abis/abiERC1155"; import { abiEvolveFactory } from "../abis/abiUserEvolveFactory"; import { abiMinterFactory } from "../abis/abiUserMinterFactory"; import { DEFAULT_NFT_TYPES, JC_CONTRACTS } from "../config/chain_config"; export class JCStandard { private web3: Web3; constructor(web3: Web3) { this.web3 = web3; } async buyNft721({ addresses, values, signature, }: { addresses: string[]; values: string[]; signature: string; }) { let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].nftMall; const contract = new this.web3.eth.Contract(abiNftMall, address, { //@ts-ignore from: jc.wallet.currentAccAddr, }); //TODO:: increaseAllowance before call let gas = await contract.methods .buy721NFT(addresses, values, signature) .estimateGas({ gas: 1000000 }); //@ts-ignore if (!jc.wallet.isInternal) { setTimeout(() => { // @ts-ignore jumpToWallet(); }, 1500); } return contract.methods .buy721NFT(addresses, values, signature) .send({ gas: (gas * 1.1) | 0 }); } async buyNft1155({ addresses, values, ids, amounts, signature, }: { addresses: string[]; values: string[]; ids: string[]; amounts: string[]; signature: string; }) { let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].nftMall; const contract = new this.web3.eth.Contract(abiNftMall, address, { //@ts-ignore from: jc.wallet.currentAccAddr, }); let gas = await contract.methods .buy1155NFT(addresses, values, ids, amounts, signature) .estimateGas({ gas: 1000000 }); //@ts-ignore if (!jc.wallet.isInternal) { setTimeout(() => { // @ts-ignore jumpToWallet(); }, 1500); } return contract.methods .buy1155NFT(addresses, values, ids, amounts, signature) .send({ gas: (gas * 1.1) | 0 }); } async evolve721NFT({ nftAddress, tokenIds, startTime, nonce, signature, }: { nftAddress: string; tokenIds: string[]; startTime: number; nonce: string; signature: string; }) { let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].evolveFactory; const contract = new this.web3.eth.Contract(abiEvolveFactory, address, { //@ts-ignore from: jc.wallet.currentAccAddr, }); let gas = await contract.methods .evolve721NFT(nftAddress, tokenIds, startTime, nonce, signature) .estimateGas({ gas: 1000000 }); //@ts-ignore if (!jc.wallet.isInternal) { setTimeout(() => { // @ts-ignore jumpToWallet(); }, 1500); } return contract.methods .evolve721NFT(nftAddress, tokenIds, startTime, nonce, signature) .send({ gas: (gas * 1.1) | 0 }); } async evolveChip({ tokenIds, startTime, nonce, signature, }: { tokenIds: string[]; startTime: number; nonce: string; signature: string; }) { let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].evolveFactory; const contract = new this.web3.eth.Contract(abiEvolveFactory, address, { //@ts-ignore from: jc.wallet.currentAccAddr, }); let gas = await contract.methods .evolveChip(tokenIds, startTime, nonce, signature) .estimateGas({ gas: 1000000 }); //@ts-ignore if (!jc.wallet.isInternal) { setTimeout(() => { // @ts-ignore jumpToWallet(); }, 1500); } return contract.methods .evolveChip(tokenIds, startTime, nonce, signature) .send({ gas: (gas * 1.1) | 0 }); } async mintShardBatchUser({ tokenIds, amounts, startTime, nonce, signature, }: { tokenIds: string[]; amounts: number[]; startTime: number; nonce: string; signature: string; }) { let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].minterFactory; const contract = new this.web3.eth.Contract(abiMinterFactory, address, { //@ts-ignore from: jc.wallet.currentAccAddr, }); let gas = await contract.methods .mintShardBatchUser(tokenIds, amounts, startTime, nonce, signature) .estimateGas({ gas: 1000000 }); //@ts-ignore if (!jc.wallet.isInternal) { setTimeout(() => { // @ts-ignore jumpToWallet(); }, 1500); } return contract.methods .mintShardBatchUser(tokenIds, amounts, startTime, nonce, signature) .send({ gas: (gas * 1.1) | 0 }); } async shardMixByUser({ tokenId, nftType, payToken, payAmount, ids, amounts, startTime, nonce, signature, }: { tokenId: string; nftType: number; payToken: string; payAmount: number; ids: string[]; amounts: number[]; startTime: number; nonce: string; signature: string; }) { let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].minterFactory; const contract = new this.web3.eth.Contract(abiMinterFactory, address, { //@ts-ignore from: jc.wallet.currentAccAddr, }); let gas = await contract.methods .shardMixByUser( tokenId, nftType, payToken, payAmount, ids, amounts, startTime, nonce, signature ) .estimateGas({ gas: 1000000 }); //@ts-ignore if (!jc.wallet.isInternal) { setTimeout(() => { // @ts-ignore jumpToWallet(); }, 1500); } return contract.methods .shardMixByUser( tokenId, nftType, payToken, payAmount, ids, amounts, startTime, nonce, signature ) .send({ gas: (gas * 1.1) | 0 }); } async pluginChip({ addresses, values, chipIds, slots, signature, }: { addresses: string[]; values: string[]; chipIds: string[]; slots: string[]; signature: string; }) { let lockerAddress = JC_CONTRACTS[window.jc.wallet.currentChain.id].chipLocker; const contract = new this.web3.eth.Contract(abiChipLocker, lockerAddress, { //@ts-ignore from: jc.wallet.currentAccAddr, }); let chipInstance = new this.web3.eth.Contract(abiERC1155, addresses[1], { //@ts-ignore from: jc.wallet.currentAccAddr, }); //@ts-ignore if (!jc.wallet.isInternal) { setTimeout(() => { // @ts-ignore jumpToWallet(); }, 1500); } let gas1 = await chipInstance.methods .setApprovalForAll(lockerAddress, true) .estimateGas({ gas: 1000000 }); await chipInstance.methods .setApprovalForAll(lockerAddress, true) .send({ gas: (gas1 * 1.1) | 0 }); let gas0 = await contract.methods .pluginChip(addresses, values, chipIds, slots, signature) .estimateGas({ gas: 1000000 }); //@ts-ignore if (!jc.wallet.isInternal) { setTimeout(() => { // @ts-ignore jumpToWallet(); }, 1500); } return await contract.methods .pluginChip(addresses, values, chipIds, slots, signature) .send({ gas: (gas0 * 1.1) | 0 }); } async unplugChip({ addresses, values, chipIds, slots, signature, }: { addresses: string[]; values: string[]; chipIds: string[]; slots: string[]; signature: string; }) { let lockerAddress = JC_CONTRACTS[window.jc.wallet.currentChain.id].chipLocker; const contract = new this.web3.eth.Contract(abiChipLocker, lockerAddress, { //@ts-ignore from: jc.wallet.currentAccAddr, }); let gas0 = await contract.methods .unplugChip(addresses, values, chipIds, slots, signature) .estimateGas({ gas: 1000000 }); //@ts-ignore if (!jc.wallet.isInternal) { setTimeout(() => { // @ts-ignore jumpToWallet(); }, 1500); } return await contract.methods .unplugChip(addresses, values, chipIds, slots, signature) .send({ gas: (gas0 * 1.1) | 0 }); } }