From 3473883411cacf7da374f673cde7f8995f8bdc07 Mon Sep 17 00:00:00 2001 From: Rodrigo <10286502+rodr-r@users.noreply.github.com> Date: Fri, 10 Mar 2023 18:05:06 -0300 Subject: [PATCH] feat/ override bridge provided gas --- .../src/controllers/BridgeController.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/background/src/controllers/BridgeController.ts b/packages/background/src/controllers/BridgeController.ts index 55188a24d..c4e31a8bf 100644 --- a/packages/background/src/controllers/BridgeController.ts +++ b/packages/background/src/controllers/BridgeController.ts @@ -429,6 +429,29 @@ export default class BridgeController extends BaseController< } } + // check gas estimations + const gasEstimation = await this._transactionController.estimateGas({ + chainId: quote.fromChainId, + transactionParams: { + from: quote.transactionRequest.from, + to: quote.transactionRequest.to, + value: BigNumber.from(quote.transactionRequest.value), + data: quote.transactionRequest.data, + }, + } as TransactionMeta); + + // if our estimation is higher, the transaction will use it. + if (gasEstimation.estimationSucceeded) { + if ( + gasEstimation.gasLimit.gt( + BigNumber.from(quote.transactionRequest.gasLimit) + ) + ) { + quote.transactionRequest.gasLimit = + gasEstimation.gasLimit.toString(); + } + } + const methodSignature = await contractSignatureParser.getMethodSignature( quote.transactionRequest.data,