Skip to content

Commit

Permalink
fix(synapse-interface): max gas estimates (#2831)
Browse files Browse the repository at this point in the history
* Increase default buffer

* Fix
  • Loading branch information
bigboydiamonds authored Jul 2, 2024
1 parent a362a16 commit 6d5fdfe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
18 changes: 2 additions & 16 deletions packages/synapse-interface/utils/calculateGasCost.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { formatGwei } from 'viem'

import { OPTIMISM } from '@/constants/chains/master'

/**
* Calculates the estimated gas cost for a transaction.
*
Expand All @@ -17,19 +15,14 @@ export const calculateGasCost = (
rawGasCost: string
parsedGasCost: string
} => {
if (!gasPrice || !gasLimit) {
if (!gasPrice || !gasLimit || !chainId) {
return {
rawGasCost: null,
parsedGasCost: null,
}
}

let upperLimitBuffer = 1.75

if (chainId === OPTIMISM.id) {
upperLimitBuffer = 3
}

const upperLimitBuffer = 3
const gasLimitFloat = parseFloat(gasLimit) ? parseFloat(gasLimit) : 1
const gasPriceFloat = parseFloat(gasPrice) ? parseFloat(gasPrice) : 1

Expand All @@ -42,13 +35,6 @@ export const calculateGasCost = (
? estimatedGasCostInGwei * oneGwei
: null

// console.log('estimatedGasCostInGwei: ', estimatedGasCostInGwei)
// console.log('gasLimit: ', gasLimit)
// console.log('gasPrice: ', gasPrice)
// console.log('gasLimitFloat: ', gasLimitFloat)
// console.log('gasPriceFloat: ', gasPriceFloat)
// console.log('formattedEstimatedGasCost: ', formattedEstimatedGasCost)

return {
rawGasCost: estimatedGasCostInGwei?.toString(),
parsedGasCost: formattedEstimatedGasCost?.toString(),
Expand Down
2 changes: 1 addition & 1 deletion packages/synapse-interface/utils/hooks/useGasEstimator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const useGasEstimator = () => {
const gasData = (await dispatch(
fetchGasData(fromChainId)
)) as PayloadAction<GasDataState>
const { maxFeePerGas } = gasData?.payload?.gasData.formatted
const { maxFeePerGas } = gasData?.payload?.gasData.formatted || {}

const gasLimit = await estimateGasLimit()
const { parsedGasCost } = calculateGasCost(
Expand Down

0 comments on commit 6d5fdfe

Please sign in to comment.