Skip to content

Commit

Permalink
Gas margin 10% (#45)
Browse files Browse the repository at this point in the history
* [defence-for-gas-limit] gas margin 10%

* [defence-for-gas-limit] add comment
  • Loading branch information
Cast0001 authored Dec 11, 2023
1 parent fa50194 commit 5a05b47
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/contracts/vaultMulticall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,25 @@ const vaultMulticall = async <T extends unknown>(values: VaultMulticallInput): P
} as T
}

// Even though ethers tries to find the best price for gas, sometimes it's
// not enough and the transaction breaks down and users lose money for gas.
// Adding 10% to the gas limit

if (isSoloCall) {
const { method, args } = params[0]

// @ts-ignore: no types to describe
return contract[method](...args)
const estimatedGas = await contract[method].estimateGas(...args)
const gasLimit = estimatedGas * 110n / 100n

// @ts-ignore: no types to describe
return contract[method](...args, { gasLimit })
}

return contract.multicall(calls) as T
const estimatedGas = await contract.multicall.estimateGas(calls)
const gasLimit = estimatedGas * 110n / 100n

return contract.multicall(calls, { gasLimit }) as T
}


Expand Down

0 comments on commit 5a05b47

Please sign in to comment.