Skip to content

Commit

Permalink
🐛 Fix gas over estimation (#49)
Browse files Browse the repository at this point in the history
* 🐛 Fix send-nft gas over estimation

* 🐛 Fix gas estimation should not be digit based
  • Loading branch information
williamchong committed Nov 17, 2023
1 parent 8756ff0 commit d19f260
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
15 changes: 10 additions & 5 deletions list-and-sell-nft/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); });
Expand Down Expand Up @@ -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),
};
}

Expand Down
16 changes: 13 additions & 3 deletions send-like/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions send-nft/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); });
Expand Down Expand Up @@ -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),
};
}

Expand Down
18 changes: 10 additions & 8 deletions web-ui/utils/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}

Expand Down

0 comments on commit d19f260

Please sign in to comment.