@aztec/wallet-sdk 0.0.1-commit.ff7989d6c → 0.0.1-commit.fff30aa
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/base-wallet/base_wallet.d.ts +46 -39
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +147 -82
- package/dest/base-wallet/index.d.ts +2 -2
- package/dest/base-wallet/index.d.ts.map +1 -1
- package/dest/base-wallet/utils.d.ts +3 -2
- package/dest/base-wallet/utils.d.ts.map +1 -1
- package/dest/base-wallet/utils.js +3 -1
- package/dest/crypto.d.ts +39 -1
- package/dest/crypto.d.ts.map +1 -1
- package/dest/crypto.js +88 -0
- package/dest/extension/provider/extension_wallet.d.ts +2 -5
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -1
- package/dest/extension/provider/index.d.ts +2 -2
- package/dest/extension/provider/index.d.ts.map +1 -1
- package/dest/iframe/handlers/iframe_connection_handler.d.ts +118 -0
- package/dest/iframe/handlers/iframe_connection_handler.d.ts.map +1 -0
- package/dest/iframe/handlers/iframe_connection_handler.js +228 -0
- package/dest/iframe/handlers/index.d.ts +2 -0
- package/dest/iframe/handlers/index.d.ts.map +1 -0
- package/dest/iframe/handlers/index.js +1 -0
- package/dest/iframe/provider/iframe_discovery.d.ts +25 -0
- package/dest/iframe/provider/iframe_discovery.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_discovery.js +167 -0
- package/dest/iframe/provider/iframe_provider.d.ts +65 -0
- package/dest/iframe/provider/iframe_provider.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_provider.js +257 -0
- package/dest/iframe/provider/iframe_wallet.d.ts +68 -0
- package/dest/iframe/provider/iframe_wallet.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_wallet.js +200 -0
- package/dest/iframe/provider/index.d.ts +4 -0
- package/dest/iframe/provider/index.d.ts.map +1 -0
- package/dest/iframe/provider/index.js +3 -0
- package/dest/manager/types.d.ts +3 -2
- package/dest/manager/types.d.ts.map +1 -1
- package/dest/manager/wallet_manager.d.ts +1 -1
- package/dest/manager/wallet_manager.d.ts.map +1 -1
- package/dest/manager/wallet_manager.js +46 -16
- package/dest/types.d.ts +14 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +4 -0
- package/package.json +12 -8
- package/src/base-wallet/base_wallet.ts +221 -139
- package/src/base-wallet/index.ts +6 -1
- package/src/base-wallet/utils.ts +6 -4
- package/src/crypto.ts +104 -0
- package/src/extension/provider/extension_wallet.ts +1 -6
- package/src/extension/provider/index.ts +1 -1
- package/src/iframe/handlers/iframe_connection_handler.ts +328 -0
- package/src/iframe/handlers/index.ts +7 -0
- package/src/iframe/provider/iframe_discovery.ts +185 -0
- package/src/iframe/provider/iframe_provider.ts +331 -0
- package/src/iframe/provider/iframe_wallet.ts +229 -0
- package/src/iframe/provider/index.ts +3 -0
- package/src/manager/types.ts +2 -1
- package/src/manager/wallet_manager.ts +48 -14
- package/src/types.ts +13 -0
|
@@ -1,34 +1,37 @@
|
|
|
1
|
-
import type { Account } from '@aztec/aztec.js/account';
|
|
1
|
+
import type { Account, NoFrom } from '@aztec/aztec.js/account';
|
|
2
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
2
3
|
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type InteractionWaitOptions,
|
|
6
|
+
NO_WAIT,
|
|
7
|
+
type SendReturn,
|
|
8
|
+
extractOffchainOutput,
|
|
9
|
+
} from '@aztec/aztec.js/contracts';
|
|
4
10
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
5
11
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
6
|
-
import type {
|
|
7
|
-
Aliased,
|
|
8
|
-
AppCapabilities,
|
|
9
|
-
BatchResults,
|
|
10
|
-
BatchedMethod,
|
|
11
|
-
ExecuteUtilityOptions,
|
|
12
|
-
PrivateEvent,
|
|
13
|
-
PrivateEventFilter,
|
|
14
|
-
ProfileOptions,
|
|
15
|
-
SendOptions,
|
|
16
|
-
SimulateOptions,
|
|
17
|
-
Wallet,
|
|
18
|
-
WalletCapabilities,
|
|
19
|
-
} from '@aztec/aztec.js/wallet';
|
|
20
12
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
type Aliased,
|
|
14
|
+
type AppCapabilities,
|
|
15
|
+
type BatchResults,
|
|
16
|
+
type BatchedMethod,
|
|
17
|
+
ContractInitializationStatus,
|
|
18
|
+
type ExecuteUtilityOptions,
|
|
19
|
+
type PrivateEvent,
|
|
20
|
+
type PrivateEventFilter,
|
|
21
|
+
type ProfileOptions,
|
|
22
|
+
type SendOptions,
|
|
23
|
+
type SimulateOptions,
|
|
24
|
+
TxSimulationResultWithAppOffset,
|
|
25
|
+
type Wallet,
|
|
26
|
+
type WalletCapabilities,
|
|
27
|
+
} from '@aztec/aztec.js/wallet';
|
|
26
28
|
import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
29
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
27
30
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
28
31
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
29
32
|
import { createLogger } from '@aztec/foundation/log';
|
|
30
33
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
31
|
-
import
|
|
34
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
32
35
|
import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
|
|
33
36
|
import {
|
|
34
37
|
type ContractArtifact,
|
|
@@ -40,18 +43,21 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
|
40
43
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
41
44
|
import {
|
|
42
45
|
type ContractInstanceWithAddress,
|
|
46
|
+
type NodeInfo,
|
|
43
47
|
computePartialAddress,
|
|
44
48
|
getContractClassFromArtifact,
|
|
45
49
|
} from '@aztec/stdlib/contract';
|
|
46
50
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
47
|
-
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
48
|
-
import {
|
|
51
|
+
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
52
|
+
import {
|
|
53
|
+
computeSiloedPrivateInitializationNullifier,
|
|
54
|
+
computeSiloedPublicInitializationNullifier,
|
|
55
|
+
} from '@aztec/stdlib/hash';
|
|
49
56
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
50
57
|
import {
|
|
51
58
|
BlockHeader,
|
|
52
59
|
type TxExecutionRequest,
|
|
53
60
|
type TxProfileResult,
|
|
54
|
-
TxSimulationResult,
|
|
55
61
|
type UtilityExecutionResult,
|
|
56
62
|
} from '@aztec/stdlib/tx';
|
|
57
63
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
@@ -70,17 +76,41 @@ export type FeeOptions = {
|
|
|
70
76
|
*/
|
|
71
77
|
walletFeePaymentMethod?: FeePaymentMethod;
|
|
72
78
|
/** Configuration options for the account to properly handle the selected fee payment method */
|
|
73
|
-
accountFeePaymentMethodOptions
|
|
79
|
+
accountFeePaymentMethodOptions?: AccountFeePaymentMethodOptions;
|
|
74
80
|
/** The gas settings to use for the transaction */
|
|
75
81
|
gasSettings: GasSettings;
|
|
76
82
|
};
|
|
77
83
|
|
|
84
|
+
/** Options for `simulateViaEntrypoint`. */
|
|
85
|
+
export type SimulateViaEntrypointOptions = Pick<
|
|
86
|
+
SimulateOptions,
|
|
87
|
+
'from' | 'additionalScopes' | 'skipTxValidation' | 'skipFeeEnforcement'
|
|
88
|
+
> & {
|
|
89
|
+
/** Fee options for the entrypoint */
|
|
90
|
+
feeOptions: FeeOptions;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/** Options for `completeFeeOptions`. */
|
|
94
|
+
export type CompleteFeeOptionsConfig = {
|
|
95
|
+
/** The address where the transaction is being sent from. */
|
|
96
|
+
from: AztecAddress | NoFrom;
|
|
97
|
+
/** The address paying for fees (if any fee payment method is embedded in the execution payload). */
|
|
98
|
+
feePayer?: AztecAddress;
|
|
99
|
+
/** User-provided partial gas settings. */
|
|
100
|
+
gasSettings?: Partial<FieldsOf<GasSettings>>;
|
|
101
|
+
/** If true, returns gas settings with high gas limits for estimation. If false, uses fallback limits. */
|
|
102
|
+
forEstimation?: boolean;
|
|
103
|
+
};
|
|
104
|
+
|
|
78
105
|
/**
|
|
79
106
|
* A base class for Wallet implementations
|
|
80
107
|
*/
|
|
81
108
|
export abstract class BaseWallet implements Wallet {
|
|
82
109
|
protected minFeePadding = 0.5;
|
|
83
110
|
protected cancellableTransactions = false;
|
|
111
|
+
// A wallet is instantiated for a particular chain, so chain info never changes during its lifetime.
|
|
112
|
+
// We cache it here because getChainInfo is called frequently (every tx simulation, send, auth wit, etc.).
|
|
113
|
+
private nodeInfoPromise: Promise<NodeInfo> | undefined;
|
|
84
114
|
|
|
85
115
|
// Protected because we want to force wallets to instantiate their own PXE.
|
|
86
116
|
protected constructor(
|
|
@@ -89,8 +119,8 @@ export abstract class BaseWallet implements Wallet {
|
|
|
89
119
|
protected log = createLogger('wallet-sdk:base_wallet'),
|
|
90
120
|
) {}
|
|
91
121
|
|
|
92
|
-
protected scopesFrom(from: AztecAddress, additionalScopes: AztecAddress[] = []): AztecAddress[] {
|
|
93
|
-
const allScopes = from
|
|
122
|
+
protected scopesFrom(from: AztecAddress | NoFrom, additionalScopes: AztecAddress[] = []): AztecAddress[] {
|
|
123
|
+
const allScopes = from === NO_FROM ? additionalScopes : [from, ...additionalScopes];
|
|
94
124
|
const scopeSet = new Set(allScopes.map(address => address.toString()));
|
|
95
125
|
return [...scopeSet].map(AztecAddress.fromString);
|
|
96
126
|
}
|
|
@@ -112,32 +142,42 @@ export abstract class BaseWallet implements Wallet {
|
|
|
112
142
|
}
|
|
113
143
|
|
|
114
144
|
async getChainInfo(): Promise<ChainInfo> {
|
|
115
|
-
|
|
145
|
+
if (!this.nodeInfoPromise) {
|
|
146
|
+
this.nodeInfoPromise = this.aztecNode.getNodeInfo();
|
|
147
|
+
}
|
|
148
|
+
const { l1ChainId, rollupVersion } = await this.nodeInfoPromise;
|
|
116
149
|
return { chainId: new Fr(l1ChainId), version: new Fr(rollupVersion) };
|
|
117
150
|
}
|
|
118
151
|
|
|
119
152
|
protected async createTxExecutionRequestFromPayloadAndFee(
|
|
120
153
|
executionPayload: ExecutionPayload,
|
|
121
|
-
from: AztecAddress,
|
|
154
|
+
from: AztecAddress | NoFrom,
|
|
122
155
|
feeOptions: FeeOptions,
|
|
123
156
|
): Promise<TxExecutionRequest> {
|
|
124
157
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
125
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
126
|
-
txNonce: Fr.random(),
|
|
127
|
-
cancellable: this.cancellableTransactions,
|
|
128
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
129
|
-
};
|
|
130
158
|
const finalExecutionPayload = feeExecutionPayload
|
|
131
159
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
132
160
|
: executionPayload;
|
|
133
|
-
const fromAccount = await this.getAccountFromAddress(from);
|
|
134
161
|
const chainInfo = await this.getChainInfo();
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
chainInfo
|
|
139
|
-
|
|
140
|
-
|
|
162
|
+
|
|
163
|
+
if (from === NO_FROM) {
|
|
164
|
+
const entrypoint = new DefaultEntrypoint();
|
|
165
|
+
return entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
166
|
+
} else {
|
|
167
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
168
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
169
|
+
txNonce: Fr.random(),
|
|
170
|
+
cancellable: this.cancellableTransactions,
|
|
171
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
172
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
173
|
+
};
|
|
174
|
+
return fromAccount.createTxExecutionRequest(
|
|
175
|
+
finalExecutionPayload,
|
|
176
|
+
feeOptions.gasSettings,
|
|
177
|
+
chainInfo,
|
|
178
|
+
executionOptions,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
141
181
|
}
|
|
142
182
|
|
|
143
183
|
public async createAuthWit(
|
|
@@ -186,31 +226,39 @@ export abstract class BaseWallet implements Wallet {
|
|
|
186
226
|
|
|
187
227
|
/**
|
|
188
228
|
* Completes partial user-provided fee options with wallet defaults.
|
|
189
|
-
* @param
|
|
190
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
191
|
-
* @param gasSettings - User-provided partial gas settings
|
|
192
|
-
* @returns - Complete fee options that can be used to create a transaction execution request
|
|
229
|
+
* @param config - Fee completion config.
|
|
193
230
|
*/
|
|
194
|
-
protected async completeFeeOptions(
|
|
195
|
-
from
|
|
196
|
-
feePayer?: AztecAddress,
|
|
197
|
-
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
198
|
-
): Promise<FeeOptions> {
|
|
231
|
+
protected async completeFeeOptions(config: CompleteFeeOptionsConfig): Promise<FeeOptions> {
|
|
232
|
+
const { from, feePayer, gasSettings, forEstimation } = config;
|
|
199
233
|
const maxFeesPerGas =
|
|
200
234
|
gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
|
|
201
235
|
let accountFeePaymentMethodOptions;
|
|
202
|
-
//
|
|
203
|
-
//
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
236
|
+
// If from is an address, we need to determine the appropriate fee payment method options for the
|
|
237
|
+
// account contract entrypoint to use
|
|
238
|
+
if (from !== NO_FROM) {
|
|
239
|
+
if (!feePayer) {
|
|
240
|
+
// The transaction does not include a fee payment method, so we set the flag
|
|
241
|
+
// for the account to use its fee juice balance
|
|
242
|
+
accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
|
|
243
|
+
} else {
|
|
244
|
+
// The transaction includes fee payment method, so we check if we are the fee payer for it
|
|
245
|
+
// (this can only happen if the embedded payment method is FeeJuiceWithClaim)
|
|
246
|
+
accountFeePaymentMethodOptions = from.equals(feePayer)
|
|
247
|
+
? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM
|
|
248
|
+
: AccountFeePaymentMethodOptions.EXTERNAL;
|
|
249
|
+
}
|
|
212
250
|
}
|
|
213
|
-
const
|
|
251
|
+
const gasSettingsOverrides = {
|
|
252
|
+
gasLimits: gasSettings?.gasLimits ? Gas.from(gasSettings.gasLimits) : undefined,
|
|
253
|
+
teardownGasLimits: gasSettings?.teardownGasLimits ? Gas.from(gasSettings.teardownGasLimits) : undefined,
|
|
254
|
+
maxFeesPerGas,
|
|
255
|
+
maxPriorityFeesPerGas: gasSettings?.maxPriorityFeesPerGas ?? GasFees.empty(),
|
|
256
|
+
};
|
|
257
|
+
// When estimating gas (simulation), use high limits so the simulation doesn't run out of gas.
|
|
258
|
+
// When sending for real, use protocol max limits that the network will actually accept.
|
|
259
|
+
const fullGasSettings = forEstimation
|
|
260
|
+
? GasSettings.forEstimation(gasSettingsOverrides)
|
|
261
|
+
: GasSettings.fallback(gasSettingsOverrides);
|
|
214
262
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
215
263
|
return {
|
|
216
264
|
gasSettings: fullGasSettings,
|
|
@@ -219,37 +267,6 @@ export abstract class BaseWallet implements Wallet {
|
|
|
219
267
|
};
|
|
220
268
|
}
|
|
221
269
|
|
|
222
|
-
/**
|
|
223
|
-
* Completes partial user-provided fee options with unreasonably high gas limits
|
|
224
|
-
* for gas estimation. Uses the same logic as completeFeeOptions but sets high limits
|
|
225
|
-
* to avoid running out of gas during estimation.
|
|
226
|
-
* @param from - The address where the transaction is being sent from
|
|
227
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
228
|
-
* @param gasSettings - User-provided partial gas settings
|
|
229
|
-
*/
|
|
230
|
-
protected async completeFeeOptionsForEstimation(
|
|
231
|
-
from: AztecAddress,
|
|
232
|
-
feePayer?: AztecAddress,
|
|
233
|
-
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
234
|
-
) {
|
|
235
|
-
const defaultFeeOptions = await this.completeFeeOptions(from, feePayer, gasSettings);
|
|
236
|
-
const {
|
|
237
|
-
gasSettings: { maxFeesPerGas, maxPriorityFeesPerGas },
|
|
238
|
-
} = defaultFeeOptions;
|
|
239
|
-
// Use unrealistically high gas limits for estimation to avoid running out of gas.
|
|
240
|
-
// They will be tuned down after the simulation.
|
|
241
|
-
const gasSettingsForEstimation = new GasSettings(
|
|
242
|
-
new Gas(GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT),
|
|
243
|
-
new Gas(GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT),
|
|
244
|
-
maxFeesPerGas,
|
|
245
|
-
maxPriorityFeesPerGas,
|
|
246
|
-
);
|
|
247
|
-
return {
|
|
248
|
-
...defaultFeeOptions,
|
|
249
|
-
gasSettings: gasSettingsForEstimation,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
270
|
registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
254
271
|
return this.pxe.registerSender(address);
|
|
255
272
|
}
|
|
@@ -295,22 +312,36 @@ export abstract class BaseWallet implements Wallet {
|
|
|
295
312
|
/**
|
|
296
313
|
* Simulates calls through the standard PXE path (account entrypoint).
|
|
297
314
|
* @param executionPayload - The execution payload to simulate.
|
|
298
|
-
* @param
|
|
299
|
-
* @param feeOptions - Fee options for the transaction.
|
|
300
|
-
* @param skipTxValidation - Whether to skip tx validation.
|
|
301
|
-
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
302
|
-
* @param scopes - The scopes to use for the simulation.
|
|
315
|
+
* @param opts - Simulation options.
|
|
303
316
|
*/
|
|
304
|
-
protected async simulateViaEntrypoint(
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
317
|
+
protected async simulateViaEntrypoint(executionPayload: ExecutionPayload, opts: SimulateViaEntrypointOptions) {
|
|
318
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(
|
|
319
|
+
executionPayload,
|
|
320
|
+
opts.from,
|
|
321
|
+
opts.feeOptions,
|
|
322
|
+
);
|
|
323
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
324
|
+
simulatePublic: true,
|
|
325
|
+
skipTxValidation: opts.skipTxValidation,
|
|
326
|
+
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
327
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
328
|
+
});
|
|
329
|
+
const appCallOffset = await this.computeAppCallOffset(opts.from, opts.feeOptions);
|
|
330
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Computes the index where the app's calls begin in the flattened array of calls (0 = entrypoint/root, 1..N = fee
|
|
335
|
+
* calls, N+1 = app).
|
|
336
|
+
* @param from - The sender address, or NO_FROM for the default entrypoint.
|
|
337
|
+
* @param feeOptions - Fee options containing the wallet fee payment method.
|
|
338
|
+
*/
|
|
339
|
+
protected async computeAppCallOffset(from: AztecAddress | NoFrom, feeOptions: FeeOptions): Promise<number> {
|
|
340
|
+
if (from === NO_FROM) {
|
|
341
|
+
return 0;
|
|
342
|
+
}
|
|
343
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
344
|
+
return (feeExecutionPayload?.calls.length ?? 0) + 1; // +1 for entrypoint
|
|
314
345
|
}
|
|
315
346
|
|
|
316
347
|
/**
|
|
@@ -321,10 +352,16 @@ export abstract class BaseWallet implements Wallet {
|
|
|
321
352
|
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
322
353
|
* @returns The merged simulation result.
|
|
323
354
|
*/
|
|
324
|
-
async simulateTx(
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
355
|
+
async simulateTx(
|
|
356
|
+
executionPayload: ExecutionPayload,
|
|
357
|
+
opts: SimulateOptions,
|
|
358
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
359
|
+
const feeOptions = await this.completeFeeOptions({
|
|
360
|
+
from: opts.from,
|
|
361
|
+
feePayer: executionPayload.feePayer,
|
|
362
|
+
gasSettings: opts.fee?.gasSettings,
|
|
363
|
+
forEstimation: true,
|
|
364
|
+
});
|
|
328
365
|
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
329
366
|
const remainingPayload = { ...executionPayload, calls: remainingCalls };
|
|
330
367
|
|
|
@@ -338,37 +375,28 @@ export abstract class BaseWallet implements Wallet {
|
|
|
338
375
|
blockHeader = (await this.aztecNode.getBlockHeader())!;
|
|
339
376
|
}
|
|
340
377
|
|
|
341
|
-
const
|
|
342
|
-
const instance = await this.pxe.getContractInstance(address);
|
|
343
|
-
if (!instance) {
|
|
344
|
-
return undefined;
|
|
345
|
-
}
|
|
346
|
-
const artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
347
|
-
return artifact?.name;
|
|
348
|
-
};
|
|
349
|
-
|
|
378
|
+
const simulationOrigin = opts.from === NO_FROM ? AztecAddress.ZERO : opts.from;
|
|
350
379
|
const [optimizedResults, normalResult] = await Promise.all([
|
|
351
380
|
optimizableCalls.length > 0
|
|
352
381
|
? simulateViaNode(
|
|
353
382
|
this.aztecNode,
|
|
354
383
|
optimizableCalls,
|
|
355
|
-
|
|
384
|
+
simulationOrigin,
|
|
356
385
|
chainInfo,
|
|
357
386
|
feeOptions.gasSettings,
|
|
358
387
|
blockHeader,
|
|
359
388
|
opts.skipFeeEnforcement ?? true,
|
|
360
|
-
getContractName,
|
|
389
|
+
this.getContractName.bind(this),
|
|
361
390
|
)
|
|
362
391
|
: Promise.resolve([]),
|
|
363
392
|
remainingCalls.length > 0
|
|
364
|
-
? this.simulateViaEntrypoint(
|
|
365
|
-
|
|
366
|
-
opts.from,
|
|
393
|
+
? this.simulateViaEntrypoint(remainingPayload, {
|
|
394
|
+
from: opts.from,
|
|
367
395
|
feeOptions,
|
|
368
|
-
|
|
369
|
-
opts.skipTxValidation,
|
|
370
|
-
opts.skipFeeEnforcement ?? true,
|
|
371
|
-
)
|
|
396
|
+
additionalScopes: opts.additionalScopes,
|
|
397
|
+
skipTxValidation: opts.skipTxValidation,
|
|
398
|
+
skipFeeEnforcement: opts.skipFeeEnforcement ?? true,
|
|
399
|
+
})
|
|
372
400
|
: Promise.resolve(null),
|
|
373
401
|
]);
|
|
374
402
|
|
|
@@ -376,7 +404,11 @@ export abstract class BaseWallet implements Wallet {
|
|
|
376
404
|
}
|
|
377
405
|
|
|
378
406
|
async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
379
|
-
const feeOptions = await this.completeFeeOptions(
|
|
407
|
+
const feeOptions = await this.completeFeeOptions({
|
|
408
|
+
from: opts.from,
|
|
409
|
+
feePayer: executionPayload.feePayer,
|
|
410
|
+
gasSettings: opts.fee?.gasSettings,
|
|
411
|
+
});
|
|
380
412
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
381
413
|
return this.pxe.profileTx(txRequest, {
|
|
382
414
|
profileMode: opts.profileMode,
|
|
@@ -389,9 +421,17 @@ export abstract class BaseWallet implements Wallet {
|
|
|
389
421
|
executionPayload: ExecutionPayload,
|
|
390
422
|
opts: SendOptions<W>,
|
|
391
423
|
): Promise<SendReturn<W>> {
|
|
392
|
-
const feeOptions = await this.completeFeeOptions(
|
|
424
|
+
const feeOptions = await this.completeFeeOptions({
|
|
425
|
+
from: opts.from,
|
|
426
|
+
feePayer: executionPayload.feePayer,
|
|
427
|
+
gasSettings: opts.fee?.gasSettings,
|
|
428
|
+
});
|
|
393
429
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
394
430
|
const provenTx = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
|
|
431
|
+
const offchainOutput = extractOffchainOutput(
|
|
432
|
+
provenTx.getOffchainEffects(),
|
|
433
|
+
provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp,
|
|
434
|
+
);
|
|
395
435
|
const tx = await provenTx.toTx();
|
|
396
436
|
const txHash = tx.getTxHash();
|
|
397
437
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -405,12 +445,32 @@ export abstract class BaseWallet implements Wallet {
|
|
|
405
445
|
|
|
406
446
|
// If wait is NO_WAIT, return txHash immediately
|
|
407
447
|
if (opts.wait === NO_WAIT) {
|
|
408
|
-
return txHash as SendReturn<W>;
|
|
448
|
+
return { txHash, ...offchainOutput } as SendReturn<W>;
|
|
409
449
|
}
|
|
410
450
|
|
|
411
451
|
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
412
452
|
const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
413
|
-
|
|
453
|
+
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
454
|
+
|
|
455
|
+
// Display debug logs from public execution if present (served in test mode only)
|
|
456
|
+
if (receipt.debugLogs?.length) {
|
|
457
|
+
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
return { receipt, ...offchainOutput } as SendReturn<W>;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Resolves a contract address to a human-readable name via PXE, if available.
|
|
465
|
+
* @param address - The contract address to resolve.
|
|
466
|
+
*/
|
|
467
|
+
protected async getContractName(address: AztecAddress): Promise<string | undefined> {
|
|
468
|
+
const instance = await this.pxe.getContractInstance(address);
|
|
469
|
+
if (!instance) {
|
|
470
|
+
return undefined;
|
|
471
|
+
}
|
|
472
|
+
const artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
473
|
+
return artifact?.name;
|
|
414
474
|
}
|
|
415
475
|
|
|
416
476
|
protected contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -428,7 +488,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
428
488
|
}
|
|
429
489
|
|
|
430
490
|
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult> {
|
|
431
|
-
return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes:
|
|
491
|
+
return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes: opts.scopes });
|
|
432
492
|
}
|
|
433
493
|
|
|
434
494
|
async getPrivateEvents<T>(
|
|
@@ -451,17 +511,39 @@ export abstract class BaseWallet implements Wallet {
|
|
|
451
511
|
return decodedEvents;
|
|
452
512
|
}
|
|
453
513
|
|
|
514
|
+
/**
|
|
515
|
+
* Returns metadata about a contract, including whether it has been initialized, published, and updated.
|
|
516
|
+
* @param address - The contract address to query.
|
|
517
|
+
*/
|
|
454
518
|
async getContractMetadata(address: AztecAddress) {
|
|
455
519
|
const instance = await this.pxe.getContractInstance(address);
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
|
|
520
|
+
const publiclyRegisteredContractPromise = this.aztecNode.getContract(address);
|
|
521
|
+
|
|
522
|
+
let initializationStatus: ContractInitializationStatus;
|
|
523
|
+
if (instance) {
|
|
524
|
+
// We have the instance, so we can compute the private initialization nullifier (which includes init_hash and is
|
|
525
|
+
// emitted by both private and public initializers) and get a definitive INITIALIZED/UNINITIALIZED answer.
|
|
526
|
+
const initNullifier = await computeSiloedPrivateInitializationNullifier(address, instance.initializationHash);
|
|
527
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
528
|
+
initializationStatus = witness
|
|
529
|
+
? ContractInitializationStatus.INITIALIZED
|
|
530
|
+
: ContractInitializationStatus.UNINITIALIZED;
|
|
531
|
+
} else {
|
|
532
|
+
// Without the instance we lack the init_hash needed for the private nullifier. We fall back to checking the
|
|
533
|
+
// public initialization nullifier (computed from address alone). Not all contracts emit it (only those with
|
|
534
|
+
// public functions that require initialization checks), so its absence doesn't mean the contract is
|
|
535
|
+
// uninitialized.
|
|
536
|
+
const publicNullifier = await computeSiloedPublicInitializationNullifier(address);
|
|
537
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', publicNullifier);
|
|
538
|
+
initializationStatus = witness ? ContractInitializationStatus.INITIALIZED : ContractInitializationStatus.UNKNOWN;
|
|
539
|
+
}
|
|
540
|
+
const publiclyRegisteredContract = await publiclyRegisteredContractPromise;
|
|
459
541
|
const isContractUpdated =
|
|
460
542
|
publiclyRegisteredContract &&
|
|
461
543
|
!publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
462
544
|
return {
|
|
463
545
|
instance: instance ?? undefined,
|
|
464
|
-
|
|
546
|
+
initializationStatus,
|
|
465
547
|
isContractPublished: !!publiclyRegisteredContract,
|
|
466
548
|
isContractUpdated: !!isContractUpdated,
|
|
467
549
|
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined,
|
package/src/base-wallet/index.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
BaseWallet,
|
|
3
|
+
type CompleteFeeOptionsConfig,
|
|
4
|
+
type FeeOptions,
|
|
5
|
+
type SimulateViaEntrypointOptions,
|
|
6
|
+
} from './base_wallet.js';
|
|
2
7
|
export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
|
package/src/base-wallet/utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
|
+
import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
2
3
|
import { MAX_ENQUEUED_CALLS_PER_CALL } from '@aztec/constants';
|
|
3
4
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
4
5
|
import { makeTuple } from '@aztec/foundation/array';
|
|
@@ -214,13 +215,13 @@ export async function simulateViaNode(
|
|
|
214
215
|
*/
|
|
215
216
|
export function buildMergedSimulationResult(
|
|
216
217
|
optimizedResults: TxSimulationResult[],
|
|
217
|
-
normalResult:
|
|
218
|
-
):
|
|
218
|
+
normalResult: TxSimulationResultWithAppOffset | null,
|
|
219
|
+
): TxSimulationResultWithAppOffset {
|
|
219
220
|
const optimizedReturnValues = optimizedResults.flatMap(r => r.publicOutput?.publicReturnValues ?? []);
|
|
220
221
|
const normalReturnValues = normalResult?.publicOutput?.publicReturnValues ?? [];
|
|
221
222
|
const allReturnValues = [...optimizedReturnValues, ...normalReturnValues];
|
|
222
223
|
|
|
223
|
-
const baseResult = normalResult ?? optimizedResults[0];
|
|
224
|
+
const baseResult: TxSimulationResult = normalResult ?? optimizedResults[0];
|
|
224
225
|
|
|
225
226
|
const mergedPublicOutput: PublicSimulationOutput | undefined = baseResult.publicOutput
|
|
226
227
|
? {
|
|
@@ -229,10 +230,11 @@ export function buildMergedSimulationResult(
|
|
|
229
230
|
}
|
|
230
231
|
: undefined;
|
|
231
232
|
|
|
232
|
-
|
|
233
|
+
const merged = new TxSimulationResult(
|
|
233
234
|
baseResult.privateExecutionResult,
|
|
234
235
|
baseResult.publicInputs,
|
|
235
236
|
mergedPublicOutput,
|
|
236
237
|
normalResult?.stats,
|
|
237
238
|
);
|
|
239
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(merged, normalResult?.appCallOffset ?? 0);
|
|
238
240
|
}
|