From df6b27d73ee4bd092f145c09ea2d60e22b40f5be Mon Sep 17 00:00:00 2001 From: Andrey Kopylov Date: Mon, 11 Dec 2023 15:20:30 +0500 Subject: [PATCH 1/2] [defence-for-gas-limit] gas margin 10% --- src/contracts/vaultMulticall.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/contracts/vaultMulticall.ts b/src/contracts/vaultMulticall.ts index fc681de6..0ce240a1 100644 --- a/src/contracts/vaultMulticall.ts +++ b/src/contracts/vaultMulticall.ts @@ -108,10 +108,17 @@ const vaultMulticall = async (values: VaultMulticallInput): P 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 } From 2045947ea7a6a16527919bd6246a0a492b6b4cdc Mon Sep 17 00:00:00 2001 From: Andrey Kopylov Date: Mon, 11 Dec 2023 15:24:51 +0500 Subject: [PATCH 2/2] [defence-for-gas-limit] add comment --- src/contracts/vaultMulticall.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/contracts/vaultMulticall.ts b/src/contracts/vaultMulticall.ts index 0ce240a1..c2bfff94 100644 --- a/src/contracts/vaultMulticall.ts +++ b/src/contracts/vaultMulticall.ts @@ -104,6 +104,10 @@ const vaultMulticall = async (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]