Commit cfe590d8 authored by Moody Salem's avatar Moody Salem

refactor(devx): show a warning when a call fails due to insufficient gas allowed

parent 2ee9b16c
...@@ -12,6 +12,8 @@ import { useAppDispatch, useAppSelector } from 'state/hooks' ...@@ -12,6 +12,8 @@ import { useAppDispatch, useAppSelector } from 'state/hooks'
import { Call, parseCallKey } from './utils' import { Call, parseCallKey } from './utils'
import { UniswapInterfaceMulticall } from 'types/v3' import { UniswapInterfaceMulticall } from 'types/v3'
const DEFAULT_GAS_REQUIRED = 1_000_000
/** /**
* Fetches a chunk of calls, enforcing a minimum block number constraint * Fetches a chunk of calls, enforcing a minimum block number constraint
* @param multicall multicall contract to fetch against * @param multicall multicall contract to fetch against
...@@ -31,11 +33,32 @@ async function fetchChunk( ...@@ -31,11 +33,32 @@ async function fetchChunk(
let results: { success: boolean; returnData: string }[] let results: { success: boolean; returnData: string }[]
try { try {
const { blockNumber, returnData } = await multicall.callStatic.multicall( const { blockNumber, returnData } = await multicall.callStatic.multicall(
chunk.map((obj) => ({ target: obj.address, callData: obj.callData, gasLimit: obj.gasRequired ?? 1_000_000 })), chunk.map((obj) => ({
target: obj.address,
callData: obj.callData,
gasLimit: obj.gasRequired ?? DEFAULT_GAS_REQUIRED,
})),
{ blockTag: minBlockNumber } { blockTag: minBlockNumber }
) )
resultsBlockNumber = blockNumber.toNumber() resultsBlockNumber = blockNumber.toNumber()
results = returnData results = returnData
if (process.env.NODE_ENV === 'development') {
returnData.forEach(({ gasUsed, returnData, success }, i) => {
if (
!success &&
returnData.length === 2 &&
gasUsed.gte(Math.floor((chunk[i].gasRequired ?? DEFAULT_GAS_REQUIRED) * 0.95))
) {
console.warn(
`A call failed due to requiring ${gasUsed.toString()} vs. allowed ${
chunk[i].gasRequired ?? DEFAULT_GAS_REQUIRED
}`,
chunk[i]
)
}
})
}
} catch (error) { } catch (error) {
console.debug('Failed to fetch chunk', error) console.debug('Failed to fetch chunk', error)
throw error throw error
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment