更新market的地址, 完善出售购买流程
This commit is contained in:
parent
97b7edbe2d
commit
aa8b8bebb6
@ -36,9 +36,17 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
contracts: {
|
contracts: {
|
||||||
minterFactory: "0x1A27515c35a92Fb276c2670fa27C85ffAd75D094",
|
minterFactory: "0x1A27515c35a92Fb276c2670fa27C85ffAd75D094",
|
||||||
nftmarket: "0x1d33b4E045ce595B6346C3D0e334814dd4Af5418",
|
nftmarket: "0x28cd862Baa826e65a0c0F1179B9A3423dF4d366A",
|
||||||
nftmall: "0x38Bf9f3C29D8384B6A79435745AE796cd2465545",
|
nftmall: "0x38Bf9f3C29D8384B6A79435745AE796cd2465545",
|
||||||
gamemarket: "0x46e2C612756b702b3d68d89F97c88FFa725F6fab",
|
gamemarket: "0x46e2C612756b702b3d68d89F97c88FFa725F6fab",
|
||||||
gamemall: "0x1D058c7c7451c34BbfF9c0dF1C16b95C5d171d64",
|
gamemall: "0x1D058c7c7451c34BbfF9c0dF1C16b95C5d171d64",
|
||||||
},
|
},
|
||||||
|
gasInfo: {
|
||||||
|
nftApprove: 49340,
|
||||||
|
cecApprove: 46962,
|
||||||
|
marketSellNFT: 270740,
|
||||||
|
marketCancelOrder: 119027,
|
||||||
|
marketUpdatePrice: 41272,
|
||||||
|
marketBuy: 207735,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
@ -17,3 +17,5 @@ export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|||||||
export const AVAILABLE_CHAINS = [80001, 421613, 137, 42161];
|
export const AVAILABLE_CHAINS = [80001, 421613, 137, 42161];
|
||||||
|
|
||||||
export const BASE_TOKEN_URI = "https://market.cebg.games/api/nft/info/";
|
export const BASE_TOKEN_URI = "https://market.cebg.games/api/nft/info/";
|
||||||
|
|
||||||
|
export const GAS_BOOST = 1.2;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
import Web3 from "web3";
|
import Web3 from "web3";
|
||||||
import { abiMinterFactory } from "../abis/abiUserMinterFactory";
|
import { abiMinterFactory } from "../abis/abiUserMinterFactory";
|
||||||
import { ZERO_ADDRESS } from "../config/constants";
|
import { GAS_BOOST, ZERO_ADDRESS } from "../config/constants";
|
||||||
import { getAddressByName, universalChainCb } from "../util/chain.util";
|
import { getAddressByName, universalChainCb } from "../util/chain.util";
|
||||||
import { SAMPLE_GAS } from "./ChainCommon";
|
import { SAMPLE_GAS } from "./ChainCommon";
|
||||||
import { abiMarket } from "../abis/abiMarket";
|
import { abiMarket } from "../abis/abiMarket";
|
||||||
@ -10,6 +10,7 @@ import { abiGameMarket } from "../abis/abiGameMarket";
|
|||||||
import { abiGameMall } from "../abis/abiGameMall";
|
import { abiGameMall } from "../abis/abiGameMall";
|
||||||
import { ZError } from "../common/ZError";
|
import { ZError } from "../common/ZError";
|
||||||
import { abiERC20 } from "../abis/abiERC20";
|
import { abiERC20 } from "../abis/abiERC20";
|
||||||
|
import { abiERC721 } from "../abis/abiERC721";
|
||||||
|
|
||||||
export class JCStandard {
|
export class JCStandard {
|
||||||
private web3: Web3;
|
private web3: Web3;
|
||||||
@ -51,7 +52,7 @@ export class JCStandard {
|
|||||||
.mintNft(address, tokenIds, startTime, saltNonce, signature)
|
.mintNft(address, tokenIds, startTime, saltNonce, signature)
|
||||||
.estimateGas();
|
.estimateGas();
|
||||||
}
|
}
|
||||||
gas = (gas * 1.1) | 1;
|
gas = (gas * GAS_BOOST) | 1;
|
||||||
if (estimate) {
|
if (estimate) {
|
||||||
return jc.wallet.generateGasShow(gas);
|
return jc.wallet.generateGasShow(gas);
|
||||||
}
|
}
|
||||||
@ -96,20 +97,34 @@ export class JCStandard {
|
|||||||
estimate: number;
|
estimate: number;
|
||||||
}) {
|
}) {
|
||||||
const cfg = jc.wallet.currentChainCfg;
|
const cfg = jc.wallet.currentChainCfg;
|
||||||
|
estimate = parseInt(estimate + "");
|
||||||
const addressMarket = cfg.contracts.nftmarket;
|
const addressMarket = cfg.contracts.nftmarket;
|
||||||
console.log("addressMarket:: ", addressMarket);
|
console.log("addressMarket:: ", addressMarket);
|
||||||
const contract = new this.web3.eth.Contract(abiMarket, addressMarket, {
|
const contract = new this.web3.eth.Contract(abiMarket, addressMarket, {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
from: jc.wallet.currentAccAddr,
|
from: jc.wallet.currentAccAddr,
|
||||||
});
|
});
|
||||||
if (!gas) {
|
const tokenInstance = new this.web3.eth.Contract(abiERC721, nftToken, {
|
||||||
gas = await contract.methods
|
//@ts-ignore
|
||||||
.sell(nftToken, currency, tokenId, price, amount)
|
from: jc.wallet.currentAccAddr,
|
||||||
.estimateGas();
|
});
|
||||||
|
let approved = await tokenInstance.methods.getApproved(tokenId);
|
||||||
|
let gasApprove = 0;
|
||||||
|
if (approved != addressMarket) {
|
||||||
|
gasApprove = cfg.gasInfo.nftApprove;
|
||||||
|
gasApprove = (gasApprove * GAS_BOOST) | 1;
|
||||||
}
|
}
|
||||||
gas = (gas * 1.1) | 1;
|
|
||||||
|
if (!gas) {
|
||||||
|
gas = cfg.gasInfo.marketSellNFT;
|
||||||
|
// gas = await contract.methods
|
||||||
|
// .sell(nftToken, currency, tokenId, price, amount)
|
||||||
|
// .estimateGas();
|
||||||
|
}
|
||||||
|
gas = (gas * GAS_BOOST) | 1;
|
||||||
|
|
||||||
if (estimate) {
|
if (estimate) {
|
||||||
return jc.wallet.generateGasShow(gas);
|
return jc.wallet.generateGasShow(gas + gasApprove);
|
||||||
}
|
}
|
||||||
|
|
||||||
let details = [
|
let details = [
|
||||||
@ -125,6 +140,12 @@ export class JCStandard {
|
|||||||
title: "market_sell",
|
title: "market_sell",
|
||||||
details: details,
|
details: details,
|
||||||
};
|
};
|
||||||
|
if (approved != addressMarket) {
|
||||||
|
await tokenInstance.methods
|
||||||
|
.approve(addressMarket, tokenId)
|
||||||
|
.send({ gas: gasApprove });
|
||||||
|
console.log("approve done");
|
||||||
|
}
|
||||||
return universalChainCb(
|
return universalChainCb(
|
||||||
logData,
|
logData,
|
||||||
contract.methods
|
contract.methods
|
||||||
@ -145,6 +166,7 @@ export class JCStandard {
|
|||||||
estimate: number;
|
estimate: number;
|
||||||
}) {
|
}) {
|
||||||
const cfg = jc.wallet.currentChainCfg;
|
const cfg = jc.wallet.currentChainCfg;
|
||||||
|
estimate = parseInt(estimate + "");
|
||||||
const addressMarket = cfg.contracts.nftmarket;
|
const addressMarket = cfg.contracts.nftmarket;
|
||||||
console.log("addressMarket:: ", addressMarket);
|
console.log("addressMarket:: ", addressMarket);
|
||||||
const contract = new this.web3.eth.Contract(abiMarket, addressMarket, {
|
const contract = new this.web3.eth.Contract(abiMarket, addressMarket, {
|
||||||
@ -152,9 +174,10 @@ export class JCStandard {
|
|||||||
from: jc.wallet.currentAccAddr,
|
from: jc.wallet.currentAccAddr,
|
||||||
});
|
});
|
||||||
if (!gas) {
|
if (!gas) {
|
||||||
gas = await contract.methods.updatePrice(orderId, price).estimateGas();
|
// gas = await contract.methods.updatePrice(orderId, price).estimateGas();
|
||||||
|
gas = cfg.gasInfo.marketUpdatePrice;
|
||||||
}
|
}
|
||||||
gas = (gas * 1.1) | 1;
|
gas = (gas * GAS_BOOST) | 1;
|
||||||
if (estimate) {
|
if (estimate) {
|
||||||
return jc.wallet.generateGasShow(gas);
|
return jc.wallet.generateGasShow(gas);
|
||||||
}
|
}
|
||||||
@ -188,6 +211,7 @@ export class JCStandard {
|
|||||||
estimate: number;
|
estimate: number;
|
||||||
}) {
|
}) {
|
||||||
const cfg = jc.wallet.currentChainCfg;
|
const cfg = jc.wallet.currentChainCfg;
|
||||||
|
estimate = parseInt(estimate + "");
|
||||||
const addressMarket = cfg.contracts.nftmarket;
|
const addressMarket = cfg.contracts.nftmarket;
|
||||||
console.log("addressMarket:: ", addressMarket);
|
console.log("addressMarket:: ", addressMarket);
|
||||||
const contract = new this.web3.eth.Contract(abiMarket, addressMarket, {
|
const contract = new this.web3.eth.Contract(abiMarket, addressMarket, {
|
||||||
@ -196,8 +220,9 @@ export class JCStandard {
|
|||||||
});
|
});
|
||||||
if (!gas) {
|
if (!gas) {
|
||||||
gas = await contract.methods.cancelOrder(orderId).estimateGas();
|
gas = await contract.methods.cancelOrder(orderId).estimateGas();
|
||||||
|
// gas = cfg.gasInfo.marketCancelOrder;
|
||||||
}
|
}
|
||||||
gas = (gas * 1.1) | 1;
|
gas = (gas * GAS_BOOST) | 1;
|
||||||
if (estimate) {
|
if (estimate) {
|
||||||
return jc.wallet.generateGasShow(gas);
|
return jc.wallet.generateGasShow(gas);
|
||||||
}
|
}
|
||||||
@ -231,37 +256,45 @@ export class JCStandard {
|
|||||||
estimate: number;
|
estimate: number;
|
||||||
}) {
|
}) {
|
||||||
const cfg = jc.wallet.currentChainCfg;
|
const cfg = jc.wallet.currentChainCfg;
|
||||||
|
estimate = parseInt(estimate + "");
|
||||||
const addressMarket = cfg.contracts.nftmarket;
|
const addressMarket = cfg.contracts.nftmarket;
|
||||||
console.log("addressMarket:: ", addressMarket);
|
console.log("addressMarket:: ", addressMarket);
|
||||||
const contract = new this.web3.eth.Contract(abiMarket, addressMarket, {
|
const contract = new this.web3.eth.Contract(abiMarket, addressMarket, {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
from: jc.wallet.currentAccAddr,
|
from: jc.wallet.currentAccAddr,
|
||||||
});
|
});
|
||||||
if (!gas) {
|
|
||||||
gas = await contract.methods.buy(orderId).estimateGas();
|
|
||||||
}
|
|
||||||
gas = (gas * 1.1) | 1;
|
|
||||||
// begin of increase allowance
|
|
||||||
let orderInfo = await contract.methods.orderInfos(orderId).call();
|
let orderInfo = await contract.methods.orderInfos(orderId).call();
|
||||||
if (!orderInfo.orderId) {
|
if (!orderInfo.orderId) {
|
||||||
throw new ZError(100, `order info with id: ${orderId} not found`);
|
throw new ZError(100, `order info with id: ${orderId} not found`);
|
||||||
}
|
}
|
||||||
const tokenInstance = new this.web3.eth.Contract(
|
const tokenInstance = new this.web3.eth.Contract(
|
||||||
abiERC20,
|
abiERC20,
|
||||||
orderInfo.currency
|
orderInfo.currency,
|
||||||
|
{
|
||||||
|
//@ts-ignore
|
||||||
|
from: jc.wallet.currentAccAddr,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
let gasApprove = await tokenInstance.methods
|
let approved = await tokenInstance.methods
|
||||||
.approve(addressMarket, orderInfo.price)
|
.allowance(jc.wallet.currentAccAddr, addressMarket)
|
||||||
.estimateGas();
|
.call();
|
||||||
gasApprove = (gasApprove * 1.1) | 1;
|
console.log("approved:: ", approved);
|
||||||
|
let gasApprove = 0;
|
||||||
|
if (approved < orderInfo.price) {
|
||||||
|
gasApprove = cfg.gasInfo.cecApprove;
|
||||||
|
}
|
||||||
|
gasApprove = (gasApprove * GAS_BOOST) | 1;
|
||||||
|
if (!gas) {
|
||||||
|
// gas = await contract.methods.buy(orderId).estimateGas();
|
||||||
|
gas = cfg.gasInfo.marketBuy;
|
||||||
|
}
|
||||||
|
gas = (gas * GAS_BOOST) | 1;
|
||||||
|
// begin of increase allowance
|
||||||
|
|
||||||
if (estimate) {
|
if (estimate) {
|
||||||
return jc.wallet.generateGasShow(gas + gasApprove);
|
return jc.wallet.generateGasShow(gas + gasApprove);
|
||||||
}
|
}
|
||||||
|
|
||||||
await tokenInstance.methods
|
|
||||||
.approve(addressMarket, orderInfo.price)
|
|
||||||
.send({ gas: gasApprove });
|
|
||||||
|
|
||||||
let details = [
|
let details = [
|
||||||
{
|
{
|
||||||
address: addressMarket,
|
address: addressMarket,
|
||||||
@ -275,6 +308,11 @@ export class JCStandard {
|
|||||||
title: "market_buy",
|
title: "market_buy",
|
||||||
details: details,
|
details: details,
|
||||||
};
|
};
|
||||||
|
if (approved < orderInfo.price) {
|
||||||
|
await tokenInstance.methods
|
||||||
|
.approve(addressMarket, orderInfo.price)
|
||||||
|
.send({ gas: gasApprove });
|
||||||
|
}
|
||||||
return universalChainCb(
|
return universalChainCb(
|
||||||
logData,
|
logData,
|
||||||
contract.methods.buy(orderId).send({ gas })
|
contract.methods.buy(orderId).send({ gas })
|
||||||
@ -296,6 +334,7 @@ export class JCStandard {
|
|||||||
estimate: number;
|
estimate: number;
|
||||||
}) {
|
}) {
|
||||||
const cfg = jc.wallet.currentChainCfg;
|
const cfg = jc.wallet.currentChainCfg;
|
||||||
|
estimate = parseInt(estimate + "");
|
||||||
const addressMall = cfg.contracts.nftmall;
|
const addressMall = cfg.contracts.nftmall;
|
||||||
console.log("addressMall:: ", addressMall);
|
console.log("addressMall:: ", addressMall);
|
||||||
const contract = new this.web3.eth.Contract(abiMall, addressMall, {
|
const contract = new this.web3.eth.Contract(abiMall, addressMall, {
|
||||||
@ -305,13 +344,13 @@ export class JCStandard {
|
|||||||
if (!gas) {
|
if (!gas) {
|
||||||
gas = await contract.methods.buyNFT(addresses, values).estimateGas();
|
gas = await contract.methods.buyNFT(addresses, values).estimateGas();
|
||||||
}
|
}
|
||||||
gas = (gas * 1.1) | 1;
|
gas = (gas * GAS_BOOST) | 1;
|
||||||
|
|
||||||
const tokenInstance = new this.web3.eth.Contract(abiERC20, addresses[2]);
|
const tokenInstance = new this.web3.eth.Contract(abiERC20, addresses[2]);
|
||||||
let gasApprove = await tokenInstance.methods
|
let gasApprove = await tokenInstance.methods
|
||||||
.approve(addressMall, values[1])
|
.approve(addressMall, values[1])
|
||||||
.estimateGas();
|
.estimateGas();
|
||||||
gasApprove = (gasApprove * 1.1) | 1;
|
gasApprove = (gasApprove * GAS_BOOST) | 1;
|
||||||
|
|
||||||
if (estimate) {
|
if (estimate) {
|
||||||
return jc.wallet.generateGasShow(gas + gasApprove);
|
return jc.wallet.generateGasShow(gas + gasApprove);
|
||||||
@ -375,6 +414,7 @@ export class JCStandard {
|
|||||||
estimate: number;
|
estimate: number;
|
||||||
}) {
|
}) {
|
||||||
const cfg = jc.wallet.currentChainCfg;
|
const cfg = jc.wallet.currentChainCfg;
|
||||||
|
estimate = parseInt(estimate + "");
|
||||||
const addressGameMarket = cfg.contracts.gamemarket;
|
const addressGameMarket = cfg.contracts.gamemarket;
|
||||||
console.log("addressGameMarket:: ", addressGameMarket);
|
console.log("addressGameMarket:: ", addressGameMarket);
|
||||||
const contract = new this.web3.eth.Contract(
|
const contract = new this.web3.eth.Contract(
|
||||||
@ -390,13 +430,13 @@ export class JCStandard {
|
|||||||
.buy(orderId, seller, currency, price, startTime, saltNonce, signature)
|
.buy(orderId, seller, currency, price, startTime, saltNonce, signature)
|
||||||
.estimateGas();
|
.estimateGas();
|
||||||
}
|
}
|
||||||
gas = (gas * 1.1) | 1;
|
gas = (gas * GAS_BOOST) | 1;
|
||||||
|
|
||||||
const tokenInstance = new this.web3.eth.Contract(abiERC20, currency);
|
const tokenInstance = new this.web3.eth.Contract(abiERC20, currency);
|
||||||
let gasApprove = await tokenInstance.methods
|
let gasApprove = await tokenInstance.methods
|
||||||
.approve(addressGameMarket, price)
|
.approve(addressGameMarket, price)
|
||||||
.estimateGas();
|
.estimateGas();
|
||||||
gasApprove = (gasApprove * 1.1) | 1;
|
gasApprove = (gasApprove * GAS_BOOST) | 1;
|
||||||
|
|
||||||
if (estimate) {
|
if (estimate) {
|
||||||
return jc.wallet.generateGasShow(gas + gasApprove);
|
return jc.wallet.generateGasShow(gas + gasApprove);
|
||||||
@ -448,6 +488,7 @@ export class JCStandard {
|
|||||||
estimate: number;
|
estimate: number;
|
||||||
}) {
|
}) {
|
||||||
const cfg = jc.wallet.currentChainCfg;
|
const cfg = jc.wallet.currentChainCfg;
|
||||||
|
estimate = parseInt(estimate + "");
|
||||||
const addressGameMall = cfg.contracts.gamemall;
|
const addressGameMall = cfg.contracts.gamemall;
|
||||||
console.log("addressGameMall:: ", addressGameMall);
|
console.log("addressGameMall:: ", addressGameMall);
|
||||||
const contract = new this.web3.eth.Contract(abiGameMall, addressGameMall, {
|
const contract = new this.web3.eth.Contract(abiGameMall, addressGameMall, {
|
||||||
@ -459,12 +500,12 @@ export class JCStandard {
|
|||||||
.buy(orderId, currency, price, startTime, saltNonce, signature)
|
.buy(orderId, currency, price, startTime, saltNonce, signature)
|
||||||
.estimateGas();
|
.estimateGas();
|
||||||
}
|
}
|
||||||
gas = (gas * 1.1) | 1;
|
gas = (gas * GAS_BOOST) | 1;
|
||||||
const tokenInstance = new this.web3.eth.Contract(abiERC20, currency);
|
const tokenInstance = new this.web3.eth.Contract(abiERC20, currency);
|
||||||
let gasApprove = await tokenInstance.methods
|
let gasApprove = await tokenInstance.methods
|
||||||
.approve(addressGameMall, price)
|
.approve(addressGameMall, price)
|
||||||
.estimateGas();
|
.estimateGas();
|
||||||
gasApprove = (gasApprove * 1.1) | 1;
|
gasApprove = (gasApprove * GAS_BOOST) | 1;
|
||||||
if (estimate) {
|
if (estimate) {
|
||||||
return jc.wallet.generateGasShow(gas + gasApprove);
|
return jc.wallet.generateGasShow(gas + gasApprove);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user