From 9090d939c118079f1f2bb51b1b1e0aaa24398a5a Mon Sep 17 00:00:00 2001 From: Daniel Somoza Date: Mon, 29 Apr 2024 17:41:04 +0200 Subject: [PATCH] Fix safeTxGas estimation for viem --- packages/protocol-kit/src/utils/transactions/gas.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/protocol-kit/src/utils/transactions/gas.ts b/packages/protocol-kit/src/utils/transactions/gas.ts index 420d673be..dff83c07b 100644 --- a/packages/protocol-kit/src/utils/transactions/gas.ts +++ b/packages/protocol-kit/src/utils/transactions/gas.ts @@ -400,7 +400,11 @@ function decodeSafeTxGas(encodedDataResponse: string): string { type GnosisChainEstimationError = { info: { error: { data: string | { data: string } } } } type EthersEstimationError = { data: string } -type EstimationError = Error & EthersEstimationError & GnosisChainEstimationError +type ViemEstimationError = { info: { error: { message: string } } } +type EstimationError = Error & + EthersEstimationError & + GnosisChainEstimationError & + ViemEstimationError /** * Parses the SafeTxGas estimation response from different providers. @@ -417,6 +421,12 @@ function parseSafeTxGasErrorResponse(error: EstimationError) { return decodeSafeTxGas(ethersData) } + // viem + const viemError = error?.info?.error?.message + if (viemError) { + return decodeSafeTxGas(viemError) + } + // gnosis-chain const gnosisChainProviderData = error?.info?.error?.data