From 0f03727177c06e2b7b1e9605219fd9a248382f7c Mon Sep 17 00:00:00 2001 From: William Chong Date: Fri, 17 Nov 2023 15:51:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20send-nft=20gas=20over?= =?UTF-8?q?=20estimation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- send-nft/index.js | 13 +++++++++---- web-ui/utils/cosmos.ts | 18 ++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/send-nft/index.js b/send-nft/index.js index 22f4018..3f1f193 100644 --- a/send-nft/index.js +++ b/send-nft/index.js @@ -14,8 +14,8 @@ import { // eslint-disable-next-line import/extensions } from './config/config.js'; -const gasNeedDigits = 5; -const amountNeedDigits = 6; +const DEFAULT_GAS_AMOUNT = 200000; +const DEFAULT_GAS_PRICE = 10000; function sleep(ms) { return new Promise((resolve) => { setTimeout(resolve, ms); }); @@ -76,10 +76,15 @@ function getGasFee(count) { amount: [ { denom: DENOM, - amount: `${new BigNumber(count).shiftedBy(amountNeedDigits).toFixed(0)}`, + amount: new BigNumber(count) + .multipliedBy(DEFAULT_GAS_AMOUNT) + .multipliedBy(DEFAULT_GAS_PRICE) + .toFixed(0), }, ], - gas: `${new BigNumber(count).shiftedBy(gasNeedDigits).toFixed(0)}`, + gas: new BigNumber(count) + .multipliedBy(DEFAULT_GAS_AMOUNT) + .toFixed(0), }; } diff --git a/web-ui/utils/cosmos.ts b/web-ui/utils/cosmos.ts index ff38b5e..cc7feae 100644 --- a/web-ui/utils/cosmos.ts +++ b/web-ui/utils/cosmos.ts @@ -8,6 +8,9 @@ import { addParamToUrl } from '.' import { RPC_URL, LIKER_NFT_FEE_WALLET } from '~/constant' import network from '~/constant/network' +const DEFAULT_GAS_AMOUNT = 200000 +const DEFAULT_GAS_PRICE = 10000 + export const royaltyRateBasisPoints = 1000 // 10% as in current chain config export const royaltyFeeAmount = 25000 // 2.5% export const royaltyUserAmount = 1000000 - royaltyFeeAmount // 1000000 - fee @@ -34,16 +37,15 @@ export function getGasFee (count: number) { amount: [ { denom: network.feeCurrencies[0].coinMinimalDenom, - amount: `${new BigNumber(count) - .shiftedBy(network.feeCurrencies[0].coinDecimals) - .shiftedBy(-4) // *10000 - .toFixed(0)}` + amount: new BigNumber(count) + .multipliedBy(DEFAULT_GAS_AMOUNT) + .multipliedBy(DEFAULT_GAS_PRICE) + .toFixed(0) } ], - gas: `${new BigNumber(count) - .shiftedBy(network.feeCurrencies[0].coinDecimals) - .shiftedBy(-3) // * 1000 - .toFixed(0)}` + gas: new BigNumber(count) + .multipliedBy(DEFAULT_GAS_AMOUNT) + .toFixed(0) } } From 1e26f9977cd2325e68961cdd7d8f2bb0d04124fb Mon Sep 17 00:00:00 2001 From: William Chong Date: Fri, 17 Nov 2023 16:00:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20gas=20estimation=20sho?= =?UTF-8?q?uld=20not=20be=20digit=20based?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list-and-sell-nft/index.js | 15 ++++++++++----- send-like/index.js | 16 +++++++++++++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/list-and-sell-nft/index.js b/list-and-sell-nft/index.js index b6eeed8..9a15eda 100644 --- a/list-and-sell-nft/index.js +++ b/list-and-sell-nft/index.js @@ -11,9 +11,9 @@ import { // eslint-disable-next-line import/extensions } from './config/config.js'; -const defaultExpirationInMs = Date.now() + 15552000000 -const gasNeedDigits = 5; -const amountNeedDigits = 6; +const defaultExpirationInMs = Date.now() + 15552000000; +const DEFAULT_GAS_AMOUNT = 200000; +const DEFAULT_GAS_PRICE = 10000; function sleep(ms) { return new Promise((resolve) => { setTimeout(resolve, ms); }); @@ -52,10 +52,15 @@ function getGasFee(count) { amount: [ { denom: DENOM, - amount: `${new BigNumber(count).shiftedBy(amountNeedDigits).toFixed(0)}`, + amount: new BigNumber(count) + .multipliedBy(DEFAULT_GAS_AMOUNT) + .multipliedBy(DEFAULT_GAS_PRICE) + .toFixed(0), }, ], - gas: `${new BigNumber(count).shiftedBy(gasNeedDigits).toFixed(0)}`, + gas: new BigNumber(count) + .multipliedBy(DEFAULT_GAS_AMOUNT) + .toFixed(0), }; } diff --git a/send-like/index.js b/send-like/index.js index 616eab9..e29e0d5 100644 --- a/send-like/index.js +++ b/send-like/index.js @@ -12,10 +12,15 @@ const memo = process.env.MEMO || ''; ////////////// adjust delay ////////////// const waitTime = Number(10000) +const DEFAULT_GAS_AMOUNT = 200000; +const DEFAULT_GAS_PRICE = 10000; + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix: 'like' }); const [firstAccount] = await wallet.getAccounts(); + const rpcEndpoint = process.env.IS_TESTNET ? 'https://node.testnet.like.co/rpc/' : 'https://mainnet-node.like.co/rpc/'; const denom = process.env.IS_TESTNET ? "nanoekil" : "nanolike" + const client = await SigningStargateClient.connectWithSigner( rpcEndpoint, wallet, @@ -55,11 +60,16 @@ async function run() { const fee = { amount: [ { - denom: denom, - amount: `${new BigNumber(msgAnyArray.length).shiftedBy(6).toFixed(0)}`, + denom, + amount: new BigNumber(msgAnyArray.length) + .multipliedBy(DEFAULT_GAS_AMOUNT) + .multipliedBy(DEFAULT_GAS_PRICE) + .toFixed(0), }, ], - gas: `${new BigNumber(msgAnyArray.length).shiftedBy(5).toFixed(0)}`, + gas: new BigNumber(msgAnyArray.length) + .multipliedBy(DEFAULT_GAS_AMOUNT) + .toFixed(0), }; console.log('total:', total)