优化market购买gold流程

This commit is contained in:
CounterFire2023 2023-06-19 17:21:28 +08:00
parent aa8b8bebb6
commit 01c4789cbe
2 changed files with 170 additions and 144 deletions

View File

@ -48,5 +48,7 @@ module.exports = {
marketCancelOrder: 119027, marketCancelOrder: 119027,
marketUpdatePrice: 41272, marketUpdatePrice: 41272,
marketBuy: 207735, marketBuy: 207735,
gameMallBuy: 119416,
gameMarketBuy: 133251,
}, },
}; };

View File

@ -321,7 +321,175 @@ export class JCStandard {
// end of NFT Market // 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 // begin of NFT Mall
// TODO:: test
async mallBuy({ async mallBuy({
addresses, addresses,
values, values,
@ -390,148 +558,4 @@ export class JCStandard {
); );
} }
// end of NFT Mall // 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
} }