From 996df2417b2d516864f36e601adad9d0d8ad597f Mon Sep 17 00:00:00 2001 From: Emre Kanatli Date: Mon, 20 Sep 2021 21:43:36 +0300 Subject: [PATCH] use BN for gas prices in helper --- src/helpers/gas_helper.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/helpers/gas_helper.ts b/src/helpers/gas_helper.ts index b7b975f5..75927255 100644 --- a/src/helpers/gas_helper.ts +++ b/src/helpers/gas_helper.ts @@ -1,19 +1,21 @@ import { web3 } from '@/Network/network'; +import { BN } from 'avalanche'; -const MAX_GAS = 235000000000; +const MAX_GAS = new BN(235000000000); /** * Returns the current gas price in WEI from the network */ -export async function getGasPrice(): Promise { - return parseInt(await web3.eth.getGasPrice()); +export async function getGasPrice(): Promise { + return new BN(await web3.eth.getGasPrice()); } /** * Returns the gas price + 25%, or max gas */ -export async function getAdjustedGasPrice(): Promise { +export async function getAdjustedGasPrice(): Promise { let gasPrice = await getGasPrice(); - let adjustedGas = Math.floor(gasPrice * 1.25); - return Math.min(adjustedGas, MAX_GAS); + let additionalGas = gasPrice.div(new BN(100)).mul(new BN(25)); + let adjustedGas = gasPrice.add(additionalGas); + return BN.min(adjustedGas, MAX_GAS); }