Skip to content

Commit 76475bc

Browse files
authored
Merge pull request #1395 from AmbireTech/fix/declaring-estimation-errors
Declare estimation errors only if the account types say they are fatal
2 parents d93fa62 + 03a67f6 commit 76475bc

7 files changed

+18
-60
lines changed

src/libs/account/BaseAccount.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export abstract class BaseAccount {
2626

2727
// each implementation should declare when an estimation failure is critical
2828
// and we should display it to the user
29-
abstract getEstimationCriticalError(estimation: FullEstimation): Error | null
29+
abstract getEstimationCriticalError(estimation: FullEstimation, op: AccountOp): Error | null
3030

3131
abstract supportsBundlerEstimation(): boolean
3232

src/libs/account/EOA.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ export class EOA extends BaseAccount {
2121

2222
ambireEstimation?: AmbireEstimation | Error
2323

24-
getEstimationCriticalError(estimation: FullEstimation): Error | null {
25-
if (estimation.provider instanceof Error) return estimation.provider
24+
getEstimationCriticalError(estimation: FullEstimation, op: AccountOp): Error | null {
25+
const numberOfCalls = op.calls.length
26+
if (numberOfCalls === 1) {
27+
if (estimation.provider instanceof Error) return estimation.provider
28+
}
29+
if (numberOfCalls > 1) {
30+
if (estimation.ambire instanceof Error) return estimation.ambire
31+
}
2632
return null
2733
}
2834

src/libs/estimate/callGasUsedEstimation.ts

-50
This file was deleted.

src/libs/estimate/estimate.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { BundlerSwitcher } from '../../services/bundlers/bundlerSwitcher'
77
import { AccountOp } from '../accountOp/accountOp'
88
import { TokenResult } from '../portfolio'
99
import { ambireEstimateGas } from './ambireEstimation'
10-
import { estimateEachCallSeparately } from './callGasUsedEstimation'
1110
import { bundlerEstimate } from './estimateBundler'
1211
import { estimateWithRetries } from './estimateWithRetries'
1312
import { FullEstimation, FullEstimationSummary } from './interfaces'
@@ -60,12 +59,11 @@ export async function getEstimation(
6059
network,
6160
feeTokens
6261
)
63-
const perCallEstimation = estimateEachCallSeparately(baseAcc, op, network, provider)
6462

6563
const estimations = await estimateWithRetries<
6664
[FullEstimation['ambire'], FullEstimation['bundler'], FullEstimation['provider']]
6765
>(
68-
() => [ambireEstimation, bundlerEstimation, providerEstimation, perCallEstimation],
66+
() => [ambireEstimation, bundlerEstimation, providerEstimation],
6967
'estimation-deployless',
7068
errorCallback,
7169
12000
@@ -83,7 +81,7 @@ export async function getEstimation(
8381
flags: {}
8482
}
8583

86-
const criticalError = baseAcc.getEstimationCriticalError(fullEstimation)
84+
const criticalError = baseAcc.getEstimationCriticalError(fullEstimation, op)
8785
if (criticalError) return criticalError
8886

8987
// TODO: if the bundler is the preferred method of estimation, re-estimate

src/libs/estimate/estimateBundler.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,12 @@ async function estimate(
9898
'estimation-bundler',
9999
errorCallback
100100
)
101+
const foundError = Array.isArray(estimation)
102+
? estimation.find((res) => res instanceof Error)
103+
: null
101104
return {
102105
gasPrice,
103-
estimation,
106+
estimation: foundError ?? estimation,
104107
nonFatalErrors
105108
}
106109
}

src/libs/estimate/estimateEOA.ts

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ export async function estimateEOA(
104104
}
105105
]
106106
if (result instanceof Error) return estimationErrorFormatted(result, { feePaymentOptions })
107+
const foundError = Array.isArray(result) ? result.find((res) => res instanceof Error) : null
108+
if (foundError instanceof Error)
109+
return estimationErrorFormatted(foundError, { feePaymentOptions })
107110

108111
let gasUsed = 0n
109112
if (!network.rpcNoStateOverride) {

src/libs/estimate/estimateWithRetries.ts

-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ export async function estimateWithRetries<T>(
8787
counter + 1
8888
)
8989
}
90-
91-
return error
9290
}
9391

9492
return result as T

0 commit comments

Comments
 (0)