Skip to content

Commit 439820d

Browse files
authored
Merge pull request #2196 from AmbireTech/fix/v1-accounts-broadcast-options
add: limit v1 accounts to EOA broadcast only
2 parents e61e30c + 4ef5f37 commit 439820d

3 files changed

Lines changed: 59 additions & 27 deletions

File tree

src/consts/signAccountOp/errorHandling.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ const WARNINGS: { [key: string]: Warning } = {
3333
text: 'The transaction you are about to sign will override the existing EIP-7702 delegation on your account. Are you sure you want to proceed?',
3434
promptBefore: ['one-click-sign', 'sign'],
3535
type: 'info3'
36+
},
37+
v1Acc: {
38+
id: 'v1Acc',
39+
title: 'You can only broadcast transactions for Ambire v1 accounts from an EOA'
3640
}
3741
}
3842

src/controllers/signAccountOp/signAccountOp.ts

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -826,30 +826,41 @@ export class SignAccountOpController extends EventEmitter implements ISignAccoun
826826
}
827827
)
828828
if (isUnableToCoverWithAllOtherTokens) {
829-
let skippedTokensCount = 0
830-
const gasTokenNames = gasTankFeeTokens
831-
.filter(({ chainId, hiddenOnError }) => {
832-
if (chainId !== this.accountOp.chainId) return false
833-
834-
if (hiddenOnError) {
835-
skippedTokensCount++
836-
return false
837-
}
838-
839-
return true
829+
// v1 acc handle
830+
const state =
831+
this.#accounts.accountStates[this.account.addr]?.[this.#network.chainId.toString()]
832+
const isV1 = this.account.creation && !state?.isV2
833+
if (isV1) {
834+
errors.push({
835+
title:
836+
'Broadcasting Ambire v1 transactions is possible only by using an ЕОА. Import or create one to broadcast your transactions.'
840837
})
841-
.map(({ symbol }) => symbol.toUpperCase())
842-
.join(', ')
838+
} else {
839+
let skippedTokensCount = 0
840+
const gasTokenNames = gasTankFeeTokens
841+
.filter(({ chainId, hiddenOnError }) => {
842+
if (chainId !== this.accountOp.chainId) return false
843+
844+
if (hiddenOnError) {
845+
skippedTokensCount++
846+
return false
847+
}
843848

844-
errors.push({
845-
title: `${ERRORS.eoaInsufficientFunds}${
846-
isSA
847-
? ` Available fee options: USDC in Gas Tank, ${gasTokenNames}${
848-
skippedTokensCount ? ' and others' : ''
849-
}`
850-
: ''
851-
}`
852-
})
849+
return true
850+
})
851+
.map(({ symbol }) => symbol.toUpperCase())
852+
.join(', ')
853+
854+
errors.push({
855+
title: `${ERRORS.eoaInsufficientFunds}${
856+
isSA
857+
? ` Available fee options: USDC in Gas Tank, ${gasTokenNames}${
858+
skippedTokensCount ? ' and others' : ''
859+
}`
860+
: ''
861+
}`
862+
})
863+
}
853864
} else {
854865
errors.push({
855866
title: isSA
@@ -954,6 +965,11 @@ export class SignAccountOpController extends EventEmitter implements ISignAccoun
954965
warnings.push(WARNINGS.delegationDetected)
955966
}
956967

968+
const accountState =
969+
this.#accounts.accountStates[this.account.addr]?.[this.#network.chainId.toString()]
970+
if (this.account.creation && !accountState?.isV2 && WARNINGS.v1Acc)
971+
warnings.push(WARNINGS.v1Acc)
972+
957973
const estimationWarnings = this.estimation.calculateWarnings()
958974

959975
this.warnings = warnings.concat(estimationWarnings)

src/libs/account/V1.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable class-methods-use-this */
22
/* eslint-disable @typescript-eslint/no-unused-vars */
3-
import { Interface } from 'ethers'
3+
import { Interface, ZeroAddress } from 'ethers'
4+
45
import AmbireAccount from '../../../contracts/compiled/AmbireAccount.json'
56
import AmbireFactory from '../../../contracts/compiled/AmbireFactory.json'
67
import { ARBITRUM_CHAIN_ID } from '../../consts/networks'
@@ -13,9 +14,8 @@ import { BROADCAST_OPTIONS } from '../broadcast/broadcast'
1314
import { FeePaymentOption, FullEstimation, FullEstimationSummary } from '../estimate/interfaces'
1415
import { getBroadcastGas } from '../gasPrice/gasPrice'
1516
import { TokenResult } from '../portfolio'
16-
import { isNative } from '../portfolio/helpers'
17-
import { BaseAccount } from './BaseAccount'
1817
import { getSpoof } from './account'
18+
import { BaseAccount } from './BaseAccount'
1919

2020
// this class describes a plain EOA that cannot transition
2121
// to 7702 either because the network or the hardware wallet doesnt' support it
@@ -33,9 +33,21 @@ export class V1 extends BaseAccount {
3333
estimation: FullEstimationSummary,
3434
feePaymentOptions: FeePaymentOption[]
3535
): FeePaymentOption[] {
36-
return feePaymentOptions.filter(
37-
(opt) => (isNative(opt.token) && opt.paidBy === this.account.addr) || opt.availableAmount > 0n
36+
const options = feePaymentOptions.filter(
37+
(opt) => opt.paidBy !== this.account.addr && opt.availableAmount > 0n
38+
)
39+
if (options.length) return options
40+
41+
// return the native only to display errors
42+
const native = feePaymentOptions.find(
43+
(opt) =>
44+
opt.paidBy === this.account.addr &&
45+
opt.token.address === ZeroAddress &&
46+
!opt.token.flags.onGasTank
3847
)
48+
if (!native) throw new Error('no native fee payment option, it should not happen')
49+
native.availableAmount = 0n
50+
return [native]
3951
}
4052

4153
getGasUsed(

0 commit comments

Comments
 (0)