@@ -10,7 +10,12 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
1010import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract' ;
1111import type { AztecNode } from '@aztec/stdlib/interfaces/client' ;
1212import { deriveSigningKey } from '@aztec/stdlib/keys' ;
13- import { ExecutionPayload , type TxSimulationResult , mergeExecutionPayloads } from '@aztec/stdlib/tx' ;
13+ import {
14+ ExecutionPayload ,
15+ SimulationOverrides ,
16+ type TxSimulationResult ,
17+ mergeExecutionPayloads ,
18+ } from '@aztec/stdlib/tx' ;
1419import { BaseWallet , type FeeOptions } from '@aztec/wallet-sdk/base-wallet' ;
1520
1621import type { AccountContractsProvider } from './account-contract-providers/types.js' ;
@@ -84,10 +89,20 @@ export class EmbeddedWallet extends BaseWallet {
8489 from : AztecAddress ,
8590 feeOptions : FeeOptions ,
8691 scopes : AccessScopes ,
87- _skipTxValidation ?: boolean ,
88- _skipFeeEnforcement ?: boolean ,
92+ skipTxValidation ?: boolean ,
93+ skipFeeEnforcement ?: boolean ,
8994 ) : Promise < TxSimulationResult > {
90- const { account : fromAccount , instance, artifact } = await this . getFakeAccountDataFor ( from ) ;
95+ let overrides : SimulationOverrides | undefined ;
96+ let fromAccount : Account ;
97+ if ( ! from . equals ( AztecAddress . ZERO ) ) {
98+ const { account, instance, artifact } = await this . getFakeAccountDataFor ( from ) ;
99+ fromAccount = account ;
100+ overrides = {
101+ contracts : { [ from . toString ( ) ] : { instance, artifact } } ,
102+ } ;
103+ } else {
104+ fromAccount = await this . getAccountFromAddress ( from ) ;
105+ }
91106
92107 const feeExecutionPayload = await feeOptions . walletFeePaymentMethod ?. getExecutionPayload ( ) ;
93108 const executionOptions : DefaultAccountEntrypointOptions = {
@@ -107,49 +122,33 @@ export class EmbeddedWallet extends BaseWallet {
107122 ) ;
108123 return this . pxe . simulateTx ( txRequest , {
109124 simulatePublic : true ,
110- skipFeeEnforcement : true ,
111- skipTxValidation : true ,
112- overrides : {
113- contracts : { [ from . toString ( ) ] : { instance, artifact } } ,
114- } ,
125+ skipFeeEnforcement,
126+ skipTxValidation,
127+ overrides,
115128 scopes,
116129 } ) ;
117130 }
118131
119132 private async getFakeAccountDataFor ( address : AztecAddress ) {
120- // While we have the convention of "Zero address means no auth", and also
121- // we don't have a way to trigger kernelless simulations without overrides,
122- // we need to explicitly handle the zero address case here by
123- // returning the actual multicall contract instead of trying to create a stub account for it.
124- if ( ! address . equals ( AztecAddress . ZERO ) ) {
125- const originalAccount = await this . getAccountFromAddress ( address ) ;
126- if ( originalAccount instanceof SignerlessAccount ) {
127- throw new Error ( `Cannot create fake account data for SignerlessAccount at address: ${ address } ` ) ;
128- }
129- const originalAddress = ( originalAccount as Account ) . getCompleteAddress ( ) ;
130- const contractInstance = await this . pxe . getContractInstance ( originalAddress . address ) ;
131- if ( ! contractInstance ) {
132- throw new Error ( `No contract instance found for address: ${ originalAddress . address } ` ) ;
133- }
134- const stubAccount = await this . accountContracts . createStubAccount ( originalAddress ) ;
135- const stubArtifact = await this . accountContracts . getStubAccountContractArtifact ( ) ;
136- const instance = await getContractInstanceFromInstantiationParams ( stubArtifact , {
137- salt : Fr . random ( ) ,
138- } ) ;
139- return {
140- account : stubAccount ,
141- instance,
142- artifact : stubArtifact ,
143- } ;
144- } else {
145- const { instance, artifact } = await this . accountContracts . getMulticallContract ( ) ;
146- const account = new SignerlessAccount ( ) ;
147- return {
148- instance,
149- account,
150- artifact,
151- } ;
133+ const originalAccount = await this . getAccountFromAddress ( address ) ;
134+ if ( originalAccount instanceof SignerlessAccount ) {
135+ throw new Error ( `Cannot create fake account data for SignerlessAccount at address: ${ address } ` ) ;
152136 }
137+ const originalAddress = ( originalAccount as Account ) . getCompleteAddress ( ) ;
138+ const contractInstance = await this . pxe . getContractInstance ( originalAddress . address ) ;
139+ if ( ! contractInstance ) {
140+ throw new Error ( `No contract instance found for address: ${ originalAddress . address } ` ) ;
141+ }
142+ const stubAccount = await this . accountContracts . createStubAccount ( originalAddress ) ;
143+ const stubArtifact = await this . accountContracts . getStubAccountContractArtifact ( ) ;
144+ const instance = await getContractInstanceFromInstantiationParams ( stubArtifact , {
145+ salt : Fr . random ( ) ,
146+ } ) ;
147+ return {
148+ account : stubAccount ,
149+ instance,
150+ artifact : stubArtifact ,
151+ } ;
153152 }
154153
155154 protected async createAccountInternal (
0 commit comments