@@ -118,14 +118,21 @@ import {
118
118
TransactionStatus ,
119
119
SimulationErrorCode ,
120
120
} from './types' ;
121
- import { addTransactionBatch , isAtomicBatchSupported } from './utils/batch' ;
121
+ import {
122
+ addTransactionBatch ,
123
+ ERROR_MESSAGE_NO_UPGRADE_CONTRACT ,
124
+ isAtomicBatchSupported ,
125
+ } from './utils/batch' ;
122
126
import {
123
127
DELEGATION_PREFIX ,
128
+ doesChainSupportEIP7702 ,
129
+ ERROR_MESSGE_PUBLIC_KEY ,
124
130
generateEIP7702BatchTransaction ,
125
131
getDelegationAddress ,
126
132
signAuthorizationList ,
127
133
} from './utils/eip7702' ;
128
134
import { validateConfirmedExternalTransaction } from './utils/external-transactions' ;
135
+ import { getEIP7702UpgradeContractAddress } from './utils/feature-flags' ;
129
136
import { addGasBuffer , estimateGas , updateGas } from './utils/gas' ;
130
137
import { updateGasFees } from './utils/gas-fees' ;
131
138
import { getGasFeeFlow } from './utils/gas-flow' ;
@@ -143,6 +150,7 @@ import {
143
150
} from './utils/nonce' ;
144
151
import { prepareTransaction , serializeTransaction } from './utils/prepare' ;
145
152
import { getTransactionParamsWithIncreasedGasFee } from './utils/retry' ;
153
+ import type { GetSimulationDataRequest } from './utils/simulation' ;
146
154
import { getSimulationData } from './utils/simulation' ;
147
155
import {
148
156
updatePostTransactionBalance ,
@@ -3974,20 +3982,8 @@ export class TransactionController extends BaseController<
3974
3982
traceContext ?: TraceContext ;
3975
3983
} = { } ,
3976
3984
) {
3977
- const {
3978
- id : transactionId ,
3979
- chainId,
3980
- txParams,
3981
- simulationData : prevSimulationData ,
3982
- } = transactionMeta ;
3983
-
3984
- const {
3985
- authorizationList : authorizationListRaw ,
3986
- from,
3987
- to,
3988
- value,
3989
- data,
3990
- } = txParams ;
3985
+ const { id : transactionId , simulationData : prevSimulationData } =
3986
+ transactionMeta ;
3991
3987
3992
3988
let simulationData : SimulationData = {
3993
3989
error : {
@@ -4000,39 +3996,11 @@ export class TransactionController extends BaseController<
4000
3996
let gasFeeTokens : GasFeeToken [ ] = [ ] ;
4001
3997
4002
3998
if ( this . #isSimulationEnabled( ) ) {
4003
- const authorizationAddress = txParams ?. authorizationList ?. [ 0 ] ?. address ;
4004
-
4005
- const senderCode =
4006
- authorizationAddress &&
4007
- ( ( DELEGATION_PREFIX + remove0x ( authorizationAddress ) ) as Hex ) ;
4008
-
4009
- const use7702Fees =
4010
- await this . #isEIP7702GasFeeTokensEnabled( transactionMeta ) ;
4011
-
4012
- const authorizationList = authorizationListRaw ?. map ( ( authorization ) => ( {
4013
- address : authorization . address ,
4014
- from : from as Hex ,
4015
- } ) ) ;
4016
-
4017
- const result = await this . #trace(
4018
- { name : 'Simulate' , parentContext : traceContext } ,
4019
- ( ) =>
4020
- getSimulationData (
4021
- {
4022
- authorizationList,
4023
- chainId,
4024
- data : data as Hex ,
4025
- from : from as Hex ,
4026
- to : to as Hex ,
4027
- value : value as Hex ,
4028
- } ,
4029
- {
4030
- blockTime,
4031
- senderCode,
4032
- use7702Fees,
4033
- } ,
4034
- ) ,
4035
- ) ;
3999
+ const result = await this . #getSimulationData( {
4000
+ blockTime,
4001
+ traceContext,
4002
+ transactionMeta,
4003
+ } ) ;
4036
4004
4037
4005
gasFeeTokens = result ?. gasFeeTokens ;
4038
4006
simulationData = result ?. simulationData ;
@@ -4264,4 +4232,89 @@ export class TransactionController extends BaseController<
4264
4232
newTransactionMeta ,
4265
4233
) ;
4266
4234
}
4235
+
4236
+ async #getSimulationData( {
4237
+ blockTime,
4238
+ traceContext,
4239
+ transactionMeta,
4240
+ } : {
4241
+ blockTime ?: number ;
4242
+ traceContext ?: TraceContext ;
4243
+ transactionMeta : TransactionMeta ;
4244
+ } ) {
4245
+ const { chainId, delegationAddress, txParams } = transactionMeta ;
4246
+ const { data, from, to, value } = txParams ;
4247
+ const authorizationAddress = txParams ?. authorizationList ?. [ 0 ] ?. address ;
4248
+
4249
+ const senderCode =
4250
+ authorizationAddress &&
4251
+ ( ( DELEGATION_PREFIX + remove0x ( authorizationAddress ) ) as Hex ) ;
4252
+
4253
+ const is7702GasFeeTokensEnabled =
4254
+ await this . #isEIP7702GasFeeTokensEnabled( transactionMeta ) ;
4255
+
4256
+ const use7702Fees =
4257
+ is7702GasFeeTokensEnabled &&
4258
+ doesChainSupportEIP7702 ( chainId , this . messagingSystem ) ;
4259
+
4260
+ let authorizationList :
4261
+ | GetSimulationDataRequest [ 'authorizationList' ]
4262
+ | undefined ;
4263
+
4264
+ if ( use7702Fees && ! delegationAddress ) {
4265
+ authorizationList = this . #getSimulationAuthorizationList( {
4266
+ chainId,
4267
+ from : from as Hex ,
4268
+ } ) ;
4269
+ }
4270
+
4271
+ return await this . #trace(
4272
+ { name : 'Simulate' , parentContext : traceContext } ,
4273
+ ( ) =>
4274
+ getSimulationData (
4275
+ {
4276
+ authorizationList,
4277
+ chainId,
4278
+ data : data as Hex ,
4279
+ from : from as Hex ,
4280
+ to : to as Hex ,
4281
+ value : value as Hex ,
4282
+ } ,
4283
+ {
4284
+ blockTime,
4285
+ senderCode,
4286
+ use7702Fees,
4287
+ } ,
4288
+ ) ,
4289
+ ) ;
4290
+ }
4291
+
4292
+ #getSimulationAuthorizationList( {
4293
+ chainId,
4294
+ from,
4295
+ } : {
4296
+ chainId : Hex ;
4297
+ from : Hex ;
4298
+ } ) : GetSimulationDataRequest [ 'authorizationList' ] | undefined {
4299
+ if ( ! this . #publicKeyEIP7702) {
4300
+ throw rpcErrors . internal ( ERROR_MESSGE_PUBLIC_KEY ) ;
4301
+ }
4302
+
4303
+ const upgradeAddress = getEIP7702UpgradeContractAddress (
4304
+ chainId ,
4305
+ this . messagingSystem ,
4306
+ this . #publicKeyEIP7702,
4307
+ ) ;
4308
+
4309
+ if ( ! upgradeAddress ) {
4310
+ throw rpcErrors . internal ( ERROR_MESSAGE_NO_UPGRADE_CONTRACT ) ;
4311
+ }
4312
+
4313
+ return [
4314
+ {
4315
+ address : upgradeAddress ,
4316
+ from : from as Hex ,
4317
+ } ,
4318
+ ] ;
4319
+ }
4267
4320
}
0 commit comments