Skip to content

Commit

Permalink
fix: added alchemy as gas price source
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Nov 27, 2022
1 parent 1efcad6 commit 108df09
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/sdk-ui-ts/src/services/gas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { HttpClient, BigNumber, BigNumberInWei } from '@injectivelabs/utils'
import {
HttpClient,
BigNumber,
BigNumberInWei,
BigNumberInBase,
} from '@injectivelabs/utils'
import { Network } from '@injectivelabs/networks'
import { GWEI_IN_WEI, DEFAULT_GAS_PRICE } from '../constants'
import { HttpRequestException } from '@injectivelabs/exceptions'
Expand Down Expand Up @@ -130,13 +135,25 @@ const fetchGasPriceFromAlchemy = async (key: string): Promise<string> => {
network: AlchemyNetwork.ETH_MAINNET,
}
const alchemy = new Alchemy(settings)
const response = await alchemy.core.getGasPrice()
const response = await alchemy.core.getFeeData()

if (!response) {
throw new HttpRequestException(new Error('No response from Alchemy'))
}

return response.toString()
if (response.maxFeePerGas) {
return response.maxFeePerGas.toString()
}

const gasPrice = await alchemy.core.getGasPrice()

if (!gasPrice) {
throw new HttpRequestException(
new Error('No gas price response from Alchemy'),
)
}

return new BigNumberInBase(gasPrice.toString()).times(1.5).toFixed()
} catch (e: unknown) {
if (e instanceof HttpRequestException) {
throw e
Expand Down

0 comments on commit 108df09

Please sign in to comment.