diff --git a/src/abis/abiBENftMall.ts b/src/abis/abiBENftMall.ts index 041bb52..b99bfaf 100644 --- a/src/abis/abiBENftMall.ts +++ b/src/abis/abiBENftMall.ts @@ -6,19 +6,6 @@ export let abiNftMall: AbiItem[] = [ stateMutability: "nonpayable", type: "constructor", }, - { - anonymous: false, - inputs: [ - { - indexed: false, - internalType: "address", - name: "nftToken", - type: "address", - }, - ], - name: "AddNFTSuppout", - type: "event", - }, { anonymous: false, inputs: [ @@ -28,6 +15,12 @@ export let abiNftMall: AbiItem[] = [ name: "buyer", type: "address", }, + { + indexed: true, + internalType: "uint256", + name: "nonce", + type: "uint256", + }, { indexed: false, internalType: "uint256", @@ -59,6 +52,12 @@ export let abiNftMall: AbiItem[] = [ name: "buyer", type: "address", }, + { + indexed: true, + internalType: "uint256", + name: "nonce", + type: "uint256", + }, { indexed: false, internalType: "address[3]", @@ -106,19 +105,6 @@ export let abiNftMall: AbiItem[] = [ name: "OwnershipTransferred", type: "event", }, - { - anonymous: false, - inputs: [ - { - indexed: false, - internalType: "address", - name: "nftToken", - type: "address", - }, - ], - name: "RemoveNFTSuppout", - type: "event", - }, { inputs: [ { @@ -409,9 +395,9 @@ export let abiNftMall: AbiItem[] = [ { inputs: [ { - internalType: "address[3]", + internalType: "address[4]", name: "addresses", - type: "address[3]", + type: "address[4]", }, { internalType: "uint256[]", @@ -497,6 +483,11 @@ export let abiNftMall: AbiItem[] = [ name: "_tokenAddress", type: "address", }, + { + internalType: "address", + name: "_buyerAddress", + type: "address", + }, { internalType: "uint256[]", name: "_datas", diff --git a/src/abis/abiChipLocker.ts b/src/abis/abiChipLocker.ts new file mode 100644 index 0000000..03d5ed1 --- /dev/null +++ b/src/abis/abiChipLocker.ts @@ -0,0 +1,423 @@ +import { AbiItem } from "web3-utils"; + +export let abiChipLocker: AbiItem[] = [ + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "nft", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "nftId", + type: "uint256", + }, + { + indexed: false, + internalType: "address", + name: "chip", + type: "address", + }, + { + indexed: false, + internalType: "uint256[]", + name: "ids", + type: "uint256[]", + }, + ], + name: "ChipPlugin", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "nft", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "nftId", + type: "uint256", + }, + { + indexed: false, + internalType: "address", + name: "chip", + type: "address", + }, + { + indexed: false, + internalType: "uint256[]", + name: "ids", + type: "uint256[]", + }, + ], + name: "ChipUnplug", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "previousOwner", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "OwnershipTransferred", + type: "event", + }, + { + inputs: [], + name: "MAX_CHIP_NUM", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + constant: true, + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "nftTokenSupported", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + constant: true, + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + { + internalType: "address", + name: "", + type: "address", + }, + { + internalType: "uint256[]", + name: "", + type: "uint256[]", + }, + { + internalType: "uint256[]", + name: "", + type: "uint256[]", + }, + { + internalType: "bytes", + name: "", + type: "bytes", + }, + ], + name: "onERC1155BatchReceived", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + { + internalType: "address", + name: "", + type: "address", + }, + { + internalType: "uint256", + name: "", + type: "uint256", + }, + { + internalType: "uint256", + name: "", + type: "uint256", + }, + { + internalType: "bytes", + name: "", + type: "bytes", + }, + ], + name: "onERC1155Received", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "owner", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + constant: true, + }, + { + inputs: [], + name: "renounceOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "interfaceId", + type: "bytes4", + }, + ], + name: "supportsInterface", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + constant: true, + }, + { + inputs: [ + { + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "nftToken", + type: "address", + }, + ], + name: "addNFTTokenSupport", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "nftToken", + type: "address", + }, + ], + name: "removeNFTTokenSupport", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "nft", + type: "address", + }, + { + internalType: "address", + name: "chip", + type: "address", + }, + { + internalType: "uint256", + name: "nftId", + type: "uint256", + }, + { + internalType: "uint256[]", + name: "chipIds", + type: "uint256[]", + }, + ], + name: "pluginChip", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "nft", + type: "address", + }, + { + internalType: "address", + name: "chip", + type: "address", + }, + { + internalType: "uint256", + name: "nftId", + type: "uint256", + }, + { + internalType: "uint256[]", + name: "chipIds", + type: "uint256[]", + }, + ], + name: "unplugChip", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "nft", + type: "address", + }, + { + internalType: "address", + name: "chip", + type: "address", + }, + { + internalType: "uint256", + name: "chipId", + type: "uint256", + }, + ], + name: "chipOwnerTokenid", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + constant: true, + }, + { + inputs: [ + { + internalType: "address", + name: "nft", + type: "address", + }, + { + internalType: "address", + name: "chip", + type: "address", + }, + { + internalType: "uint256", + name: "tokenId", + type: "uint256", + }, + ], + name: "pluginedChipNum", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + constant: true, + }, + { + inputs: [ + { + internalType: "address", + name: "nft", + type: "address", + }, + { + internalType: "address", + name: "chip", + type: "address", + }, + { + internalType: "uint256", + name: "tokenId", + type: "uint256", + }, + ], + name: "pluginedChips", + outputs: [ + { + internalType: "uint256[]", + name: "", + type: "uint256[]", + }, + ], + stateMutability: "view", + type: "function", + constant: true, + }, +]; diff --git a/src/abis/abiUserEvolveFactory.ts b/src/abis/abiUserEvolveFactory.ts index 907c403..03d9cfe 100644 --- a/src/abis/abiUserEvolveFactory.ts +++ b/src/abis/abiUserEvolveFactory.ts @@ -29,6 +29,12 @@ export let abiEvolveFactory: AbiItem[] = [ name: "to", type: "address", }, + { + indexed: true, + internalType: "uint256", + name: "nonce", + type: "uint256", + }, { indexed: false, internalType: "bytes", @@ -63,6 +69,7 @@ export let abiEvolveFactory: AbiItem[] = [ ], stateMutability: "view", type: "function", + constant: true, }, { inputs: [], diff --git a/src/abis/abiUserMinterFactory.ts b/src/abis/abiUserMinterFactory.ts index 55b0ef0..8ffd194 100644 --- a/src/abis/abiUserMinterFactory.ts +++ b/src/abis/abiUserMinterFactory.ts @@ -29,6 +29,12 @@ export let abiMinterFactory: AbiItem[] = [ name: "to", type: "address", }, + { + indexed: true, + internalType: "uint256", + name: "nonce", + type: "uint256", + }, { indexed: false, internalType: "bytes", diff --git a/src/config/chain_config.ts b/src/config/chain_config.ts index 7c1138e..ac1591c 100644 --- a/src/config/chain_config.ts +++ b/src/config/chain_config.ts @@ -82,13 +82,13 @@ export const DEFALUT_TOKENS = { }, { type: "erc20", - address: "0x4d46f75Be6E98dBA8E8384802a68d550DeB69770", + address: "0x94247cc867ED6277b901AFED817F3b13962814eD", symbol: "CEC", decimal: 18, }, { type: "erc20", - address: "0xb3212b66C337F83D277172D891Daf31776FF9D79", + address: "0x28901774C7C74D3C78a17A18697D7BFFB999d3f7", symbol: "CEG", decimal: 18, }, @@ -170,19 +170,19 @@ export const DEFAULT_NFT_TYPES = { }, 1338: { hero: { - address: "0xCd36bFD6f5c9685A5b1DD953E8279eeC7d41e1E1", + address: "0xF07F3D7c1f64E9bC0005308c24e715D555195D6D", type: "erc721", }, weapon: { - address: "0xf1486cC376555A5035cFa85A761279c9876Daddc", + address: "0xFA58cA95FF52dFF0C57bC0BE54462894003a5394", type: "erc721", }, chip: { - address: "0xc56a7B89639738382abF20E1829d1ff1a4e21e33", + address: "0x615d4BE4Cba8e68efFe6F00e8E42AE07c4f84A7d", type: "erc1155", }, shard: { - address: "0x8BaA4d31B46a272b5a90F192Dcf20348E1845719", + address: "0x0f30db053d360225f43b845Cc8Fb0A456aFD4CA2", type: "erc1155", }, }, @@ -210,8 +210,9 @@ export const JC_CONTRACTS = { minterFactory: "0x5ecEFA2707e3f09B9A169ae696B36Df8dB7410ED", }, 1338: { - nftMall: "0x68731C006E8a7Fa45c6eAb579f8F7507b10f5571", - evolveFactory: "0xa390Fa8d4F032cCfCeC1CFF34f2eb549928DcEad", - minterFactory: "0x0DB24A927FFC3622884B7A3B6f1C694ED8092A01", + nftMall: "0xC04F9c0461DA8C19a60c8d4C95733b12D51e6Eca", + evolveFactory: "0x54B6f621e8c8dD2Cfcd49f2E7aD1dF19E60bf4B9", + minterFactory: "0x4b848789f6994d24cAEfaB187fD6c8bE3E0B97cf", + chipLocker: "0xb288bA87a02d34ec827a15487633D11faB79b718", }, }; diff --git a/src/standards/JCStandard.ts b/src/standards/JCStandard.ts index 51b0198..6c83bc6 100644 --- a/src/standards/JCStandard.ts +++ b/src/standards/JCStandard.ts @@ -1,8 +1,10 @@ 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 { JC_CONTRACTS } from "../config/chain_config"; +import { DEFAULT_NFT_TYPES, JC_CONTRACTS } from "../config/chain_config"; export class JCStandard { private web3: Web3; @@ -232,4 +234,84 @@ export class JCStandard { ) .send({ gas: (gas * 1.1) | 0 }); } + + async pluginChip({ + nftAddress, + chipAddress, + nftId, + chipIds, + }: { + nftAddress: string; + chipAddress: string; + nftId: string; + chipIds: 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.currentAccount(), + }); + let chipInstance = new this.web3.eth.Contract(abiERC1155, chipAddress, { + //@ts-ignore + from: jc.wallet.currentAccount(), + }); + 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(nftAddress, chipAddress, nftId, chipIds) + .estimateGas({ gas: 1000000 }); + //@ts-ignore + if (!jc.wallet.isInternal) { + setTimeout(() => { + // @ts-ignore + jumpToWallet(); + }, 1500); + } + return await contract.methods + .pluginChip(nftAddress, chipAddress, nftId, chipIds) + .send({ gas: (gas0 * 1.1) | 0 }); + } + + async unplugChip({ + nftAddress, + chipAddress, + nftId, + chipIds, + }: { + nftAddress: string; + chipAddress: string; + nftId: string; + chipIds: 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.currentAccount(), + }); + let chipInstance = new this.web3.eth.Contract(abiERC1155, chipAddress, { + //@ts-ignore + from: jc.wallet.currentAccount(), + }); + + let gas0 = await contract.methods + .unplugChip(nftAddress, chipAddress, nftId, chipIds) + .estimateGas({ gas: 1000000 }); + //@ts-ignore + if (!jc.wallet.isInternal) { + setTimeout(() => { + // @ts-ignore + jumpToWallet(); + }, 1500); + } + return await contract.methods + .unplugChip(nftAddress, chipAddress, nftId, chipIds) + .send({ gas: (gas0 * 1.1) | 0 }); + } }