Skip to content

Commit

Permalink
Revert "Fix(Gas estimation): gas price from oracles can be a float (#…
Browse files Browse the repository at this point in the history
…4813)"

This reverts commit 298a7e1.
  • Loading branch information
katspaugh committed Feb 5, 2025
1 parent 2f53b12 commit a5c655e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
16 changes: 8 additions & 8 deletions apps/web/src/hooks/__tests__/useGasPrice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ describe('useGasPrice', () => {
json: () =>
Promise.resolve({
data: {
FastGasPrice: '47.543',
suggestBaseFee: '44.435',
FastGasPrice: '47',
suggestBaseFee: '44',
},
}),
}),
Expand Down Expand Up @@ -104,8 +104,8 @@ describe('useGasPrice', () => {
json: () =>
Promise.resolve({
data: {
FastGasPrice: '30.45435',
suggestBaseFee: '10.5435435',
FastGasPrice: '30',
suggestBaseFee: '10',
},
}),
}),
Expand Down Expand Up @@ -270,8 +270,8 @@ describe('useGasPrice', () => {
json: () =>
Promise.resolve({
data: {
FastGasPrice: '21.5435435',
suggestBaseFee: '19.5435',
FastGasPrice: '21',
suggestBaseFee: '19',
},
}),
}),
Expand All @@ -282,8 +282,8 @@ describe('useGasPrice', () => {
json: () =>
Promise.resolve({
data: {
FastGasPrice: '22.89879',
suggestBaseFee: '19.1243',
FastGasPrice: '22',
suggestBaseFee: '19',
},
}),
}),
Expand Down
15 changes: 4 additions & 11 deletions apps/web/src/hooks/useGasPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ type GasFeeParams = {
// Update gas fees every 20 seconds
const REFRESH_DELAY = 20e3

const DEFAULT_FEE = 1n

type EtherscanResult = {
LastBlock: string
SafeGasPrice: string
Expand All @@ -48,11 +46,6 @@ const isEtherscanResult = (data: any): data is EtherscanResult => {
return 'FastGasPrice' in data && 'suggestBaseFee' in data
}

const stringToBigInt = (value: string): bigint => {
const bigInt = BigInt(value.split('.')[0])
return bigInt <= 0 ? DEFAULT_FEE : bigInt
}

/**
* Parses result from etherscan oracle.
* Since EIP 1559 it returns the `maxFeePerGas` as gas price and the current network baseFee as `suggestedBaseFee`.
Expand All @@ -62,8 +55,8 @@ const stringToBigInt = (value: string): bigint => {
* @see https://docs.etherscan.io/api-endpoints/gas-tracker
*/
const parseEtherscanOracleResult = (result: EtherscanResult, gweiFactor: string): EstimatedGasPrice => {
const maxFeePerGas = stringToBigInt(result.FastGasPrice) * stringToBigInt(gweiFactor)
const baseFee = stringToBigInt(result.suggestBaseFee) * stringToBigInt(gweiFactor)
const maxFeePerGas = BigInt(Number(result.FastGasPrice) * Number(gweiFactor))
const baseFee = BigInt(Number(result.suggestBaseFee) * Number(gweiFactor))

return {
maxFeePerGas,
Expand Down Expand Up @@ -229,8 +222,8 @@ const useGasPrice = (isSpeedUp: boolean = false): AsyncResult<GasFeeParams> => {
return {
maxFeePerGas: gasParameters.maxFeePerGas
? (gasParameters.maxFeePerGas * SPEED_UP_GAS_PRICE_FACTOR) / 100n
: DEFAULT_FEE,
maxPriorityFeePerGas: DEFAULT_FEE,
: undefined,
maxPriorityFeePerGas: undefined,
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down

0 comments on commit a5c655e

Please sign in to comment.