From 01c4789cbe2279aa9c7db47a7823d6633f38b494 Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Mon, 19 Jun 2023 17:21:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96market=E8=B4=AD=E4=B9=B0gold?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/cfg_421613_dev.js | 2 + src/standards/JCStandard.ts | 312 +++++++++++++++++++---------------- 2 files changed, 170 insertions(+), 144 deletions(-) diff --git a/src/config/cfg_421613_dev.js b/src/config/cfg_421613_dev.js index 8430336..8a8aa1c 100644 --- a/src/config/cfg_421613_dev.js +++ b/src/config/cfg_421613_dev.js @@ -48,5 +48,7 @@ module.exports = { marketCancelOrder: 119027, marketUpdatePrice: 41272, marketBuy: 207735, + gameMallBuy: 119416, + gameMarketBuy: 133251, }, }; diff --git a/src/standards/JCStandard.ts b/src/standards/JCStandard.ts index 5d32651..3f1323c 100644 --- a/src/standards/JCStandard.ts +++ b/src/standards/JCStandard.ts @@ -321,7 +321,175 @@ export class JCStandard { // end of NFT Market + // begin of game item mall + async gameMallBuy({ + orderId, + currency, + price, + startTime, + saltNonce, + signature, + gas, + estimate, + }: { + orderId: string; + currency: string; + price: string; + startTime: string; + saltNonce: string; + signature: string; + gas?: number; + estimate: number; + }) { + const cfg = jc.wallet.currentChainCfg; + estimate = parseInt(estimate + ""); + const addressGameMall = cfg.contracts.gamemall; + console.log("addressGameMall:: ", addressGameMall); + const contract = new this.web3.eth.Contract(abiGameMall, addressGameMall, { + //@ts-ignore + from: jc.wallet.currentAccAddr, + }); + const tokenInstance = new this.web3.eth.Contract(abiERC20, currency, { + //@ts-ignore + from: jc.wallet.currentAccAddr, + }); + let approved = await tokenInstance.methods + .allowance(jc.wallet.currentAccAddr, addressGameMall) + .call(); + console.log("approved:: ", approved); + let gasApprove = 0; + if (approved < price) { + gasApprove = cfg.gasInfo.cecApprove; + } + gasApprove = (gasApprove * GAS_BOOST) | 1; + if (!gas) { + // gas = await contract.methods + // .buy(orderId, currency, price, startTime, saltNonce, signature) + // .estimateGas(); + gas = cfg.gasInfo.gameMallBuy; + } + gas = (gas * GAS_BOOST) | 1; + if (estimate) { + return jc.wallet.generateGasShow(gas + gasApprove); + } + // TOTO:: + let details = [ + { + address: addressGameMall, + from: jc.wallet.currentAccAddr, + to: addressGameMall, + value: 0, + }, + ]; + const logData = { + gas, + title: "game_mall_buy", + details: details, + }; + if (approved < price) { + await tokenInstance.methods + .approve(addressGameMall, price) + .send({ gas: gasApprove }); + } + return universalChainCb( + logData, + contract.methods + .buy(orderId, currency, price, startTime, saltNonce, signature) + .send({ gas }) + ); + } + // end of game item mall + + // begin of game item market + // TODO:: test + async gameMarketBuy({ + orderId, + seller, + currency, + price, + startTime, + saltNonce, + signature, + gas, + estimate, + }: { + orderId: string; + seller: string; + currency: string; + price: string; + startTime: string; + saltNonce: string; + signature: string; + gas?: number; + estimate: number; + }) { + const cfg = jc.wallet.currentChainCfg; + estimate = parseInt(estimate + ""); + const addressGameMarket = cfg.contracts.gamemarket; + console.log("addressGameMarket:: ", addressGameMarket); + const contract = new this.web3.eth.Contract( + abiGameMarket, + addressGameMarket, + { + //@ts-ignore + from: jc.wallet.currentAccAddr, + } + ); + const tokenInstance = new this.web3.eth.Contract(abiERC20, currency, { + //@ts-ignore + from: jc.wallet.currentAccAddr, + }); + let approved = await tokenInstance.methods + .allowance(jc.wallet.currentAccAddr, addressGameMarket) + .call(); + console.log("approved:: ", approved); + let gasApprove = 0; + if (approved < price) { + gasApprove = cfg.gasInfo.cecApprove; + } + gasApprove = (gasApprove * GAS_BOOST) | 1; + console.log("gasApprove: " + gasApprove); + if (!gas) { + // gas = await contract.methods + // .buy(orderId, seller, currency, price, startTime, saltNonce, signature) + // .estimateGas(); + gas = cfg.gasInfo.gameMarketBuy; + } + gas = (gas * GAS_BOOST) | 1; + console.log("gas: " + gas); + + if (estimate) { + return jc.wallet.generateGasShow(gas + gasApprove); + } + + let details = [ + { + address: addressGameMarket, + from: jc.wallet.currentAccAddr, + to: addressGameMarket, + value: 0, + }, + ]; + const logData = { + gas, + title: "game_market_buy", + details: details, + }; + if (approved < price) { + await tokenInstance.methods + .approve(addressGameMarket, price) + .send({ gas: gasApprove }); + } + return universalChainCb( + logData, + contract.methods + .buy(orderId, seller, currency, price, startTime, saltNonce, signature) + .send({ gas }) + ); + } + // end of game item market // begin of NFT Mall + // TODO:: test async mallBuy({ addresses, values, @@ -390,148 +558,4 @@ export class JCStandard { ); } // end of NFT Mall - - // begin of game item market - async gameMarketBuy({ - orderId, - seller, - currency, - price, - startTime, - saltNonce, - signature, - gas, - estimate, - }: { - orderId: string; - seller: string; - currency: string; - price: string; - startTime: string; - saltNonce: string; - signature: string; - gas?: number; - estimate: number; - }) { - const cfg = jc.wallet.currentChainCfg; - estimate = parseInt(estimate + ""); - const addressGameMarket = cfg.contracts.gamemarket; - console.log("addressGameMarket:: ", addressGameMarket); - const contract = new this.web3.eth.Contract( - abiGameMarket, - addressGameMarket, - { - //@ts-ignore - from: jc.wallet.currentAccAddr, - } - ); - if (!gas) { - gas = await contract.methods - .buy(orderId, seller, currency, price, startTime, saltNonce, signature) - .estimateGas(); - } - gas = (gas * GAS_BOOST) | 1; - - const tokenInstance = new this.web3.eth.Contract(abiERC20, currency); - let gasApprove = await tokenInstance.methods - .approve(addressGameMarket, price) - .estimateGas(); - gasApprove = (gasApprove * GAS_BOOST) | 1; - - if (estimate) { - return jc.wallet.generateGasShow(gas + gasApprove); - } - - let details = [ - { - address: addressGameMarket, - from: jc.wallet.currentAccAddr, - to: addressGameMarket, - value: 0, - }, - ]; - const logData = { - gas, - title: "game_market_buy", - details: details, - }; - await tokenInstance.methods - .approve(addressGameMarket, price) - .send({ gas: gasApprove }); - return universalChainCb( - logData, - contract.methods - .buy(orderId, seller, currency, price, startTime, saltNonce, signature) - .send({ gas }) - ); - } - // end of game item market - - // begin of game item mall - async gameMallBuy({ - orderId, - currency, - price, - startTime, - saltNonce, - signature, - gas, - estimate, - }: { - orderId: string; - currency: string; - price: string; - startTime: string; - saltNonce: string; - signature: string; - gas?: number; - estimate: number; - }) { - const cfg = jc.wallet.currentChainCfg; - estimate = parseInt(estimate + ""); - const addressGameMall = cfg.contracts.gamemall; - console.log("addressGameMall:: ", addressGameMall); - const contract = new this.web3.eth.Contract(abiGameMall, addressGameMall, { - //@ts-ignore - from: jc.wallet.currentAccAddr, - }); - if (!gas) { - gas = await contract.methods - .buy(orderId, currency, price, startTime, saltNonce, signature) - .estimateGas(); - } - gas = (gas * GAS_BOOST) | 1; - const tokenInstance = new this.web3.eth.Contract(abiERC20, currency); - let gasApprove = await tokenInstance.methods - .approve(addressGameMall, price) - .estimateGas(); - gasApprove = (gasApprove * GAS_BOOST) | 1; - if (estimate) { - return jc.wallet.generateGasShow(gas + gasApprove); - } - // TOTO:: - let details = [ - { - address: addressGameMall, - from: jc.wallet.currentAccAddr, - to: addressGameMall, - value: 0, - }, - ]; - const logData = { - gas, - title: "game_mall_buy", - details: details, - }; - await tokenInstance.methods - .approve(addressGameMall, price) - .send({ gas: gasApprove }); - return universalChainCb( - logData, - contract.methods - .buy(orderId, currency, price, startTime, saltNonce, signature) - .send({ gas }) - ); - } - // end of game item mall }