Skip to content

Commit

Permalink
Fix gas estimation parsing issue in Ethers v6
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniSomoza committed Oct 11, 2023
1 parent ffd7762 commit 0e389e5
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions packages/protocol-kit/src/utils/transactions/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ async function estimateSafeTxGasWithRequiredTxGas(
// if the call throws an error we try to parse the returned value
} catch (error: any) {
try {
const revertData = JSON.parse(error.error.body).error.data
const revertData = error?.info?.error?.data

if (revertData && revertData.startsWith('Reverted ')) {
const [, safeTxGas] = revertData.split('Reverted ')
Expand Down Expand Up @@ -378,18 +378,13 @@ function decodeSafeTxGas(encodedSafeTxGas: string): string {
}

function parseSafeTxGasErrorResponse(error: any) {
// Ethers
if (error?.error?.body) {
const revertData = JSON.parse(error.error.body).error.data
if (revertData && revertData.startsWith('Reverted ')) {
const [, encodedResponse] = revertData.split('Reverted ')
const safeTxGas = decodeSafeTxGas(encodedResponse)

return safeTxGas
}
// Ethers v6
const Ethersv6RevertData = error?.info?.error?.data
if (Ethersv6RevertData) {
return decodeSafeTxGas(Ethersv6RevertData)
}

// Web3
// Web3 v1
const [, encodedResponse] = error.message.split('return data: ')
const safeTxGas = decodeSafeTxGas(encodedResponse)

Expand Down

0 comments on commit 0e389e5

Please sign in to comment.