Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TAS-728] 🐛 Fix send-nft gas over estimation #49

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
// 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 @@
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 All @@ -87,7 +92,7 @@
try {
const data = await readCsv('list.csv');
if (!MNEMONIC && !PRIVATE_KEY) throw new Error('need MNEMONIC or PRIVATE_KEY');
if (MNEMONIC && PRIVATE_KEY) console.warn('MNEMONIC and PRIVATE_KEY both exist, using MNEMONIC');

Check warning on line 95 in send-nft/index.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected console statement
const signer = MNEMONIC
? await DirectSecp256k1HdWallet.fromMnemonic(MNEMONIC, { prefix: 'like' })
: await DirectSecp256k1Wallet.fromKey(Buffer.from(PRIVATE_KEY, 'hex'), 'like');
Expand Down Expand Up @@ -187,10 +192,10 @@
try {
const txBytes = TxRaw.encode(tx).finish();
const res = await client.broadcastTx(txBytes, 1000, 1000);
console.log(res);

Check warning on line 195 in send-nft/index.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected console statement
} catch (err) {
if (err instanceof TimeoutError) {
console.log(err.txId);

Check warning on line 198 in send-nft/index.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected console statement
} else {
throw err;
}
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
Loading