-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b60890
commit 996df24
Showing
1 changed file
with
8 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<number> { | ||
return parseInt(await web3.eth.getGasPrice()); | ||
export async function getGasPrice(): Promise<BN> { | ||
return new BN(await web3.eth.getGasPrice()); | ||
} | ||
|
||
/** | ||
* Returns the gas price + 25%, or max gas | ||
*/ | ||
export async function getAdjustedGasPrice(): Promise<number> { | ||
export async function getAdjustedGasPrice(): Promise<BN> { | ||
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); | ||
} |