@aztec/wallet-sdk 5.0.0-private.20260319 → 5.0.0-rc.2
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/README.md +125 -0
- package/dest/base-wallet/base_wallet.d.ts +65 -40
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +196 -80
- package/dest/base-wallet/get_gas_limits.d.ts +36 -0
- package/dest/base-wallet/get_gas_limits.d.ts.map +1 -0
- package/dest/base-wallet/get_gas_limits.js +55 -0
- package/dest/base-wallet/index.d.ts +3 -2
- package/dest/base-wallet/index.d.ts.map +1 -1
- package/dest/base-wallet/index.js +1 -0
- package/dest/base-wallet/utils.d.ts +7 -4
- package/dest/base-wallet/utils.d.ts.map +1 -1
- package/dest/base-wallet/utils.js +11 -5
- package/dest/crypto.d.ts +39 -1
- package/dest/crypto.d.ts.map +1 -1
- package/dest/crypto.js +88 -0
- package/dest/extension/handlers/background_connection_handler.d.ts +12 -2
- package/dest/extension/handlers/background_connection_handler.d.ts.map +1 -1
- package/dest/extension/handlers/background_connection_handler.js +44 -8
- package/dest/extension/handlers/content_script_connection_handler.d.ts +2 -1
- package/dest/extension/handlers/content_script_connection_handler.d.ts.map +1 -1
- package/dest/extension/handlers/content_script_connection_handler.js +19 -0
- package/dest/extension/handlers/internal_message_types.d.ts +3 -1
- package/dest/extension/handlers/internal_message_types.d.ts.map +1 -1
- package/dest/extension/handlers/internal_message_types.js +3 -1
- package/dest/extension/provider/extension_wallet.d.ts +26 -6
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -1
- package/dest/extension/provider/extension_wallet.js +80 -9
- 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 +122 -0
- package/dest/iframe/handlers/iframe_connection_handler.d.ts.map +1 -0
- package/dest/iframe/handlers/iframe_connection_handler.js +239 -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 +85 -0
- package/dest/iframe/provider/iframe_wallet.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_wallet.js +269 -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 +64 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +29 -0
- package/package.json +12 -8
- package/src/base-wallet/base_wallet.ts +257 -125
- package/src/base-wallet/get_gas_limits.ts +88 -0
- package/src/base-wallet/index.ts +7 -1
- package/src/base-wallet/utils.ts +15 -5
- package/src/crypto.ts +104 -0
- package/src/extension/handlers/background_connection_handler.ts +42 -9
- package/src/extension/handlers/content_script_connection_handler.ts +18 -0
- package/src/extension/handlers/internal_message_types.ts +2 -0
- package/src/extension/provider/extension_wallet.ts +94 -13
- package/src/extension/provider/index.ts +1 -1
- package/src/iframe/handlers/iframe_connection_handler.ts +341 -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 +323 -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 +72 -0
|
@@ -1,4 +1,5 @@
|
|
|
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
4
|
import {
|
|
4
5
|
type InteractionWaitOptions,
|
|
@@ -8,32 +9,29 @@ import {
|
|
|
8
9
|
} from '@aztec/aztec.js/contracts';
|
|
9
10
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
10
11
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
11
|
-
import type {
|
|
12
|
-
Aliased,
|
|
13
|
-
AppCapabilities,
|
|
14
|
-
BatchResults,
|
|
15
|
-
BatchedMethod,
|
|
16
|
-
ExecuteUtilityOptions,
|
|
17
|
-
PrivateEvent,
|
|
18
|
-
PrivateEventFilter,
|
|
19
|
-
ProfileOptions,
|
|
20
|
-
SendOptions,
|
|
21
|
-
SimulateOptions,
|
|
22
|
-
Wallet,
|
|
23
|
-
WalletCapabilities,
|
|
24
|
-
} from '@aztec/aztec.js/wallet';
|
|
25
12
|
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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';
|
|
31
28
|
import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
29
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
32
30
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
33
31
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
34
32
|
import { createLogger } from '@aztec/foundation/log';
|
|
35
33
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
36
|
-
import {
|
|
34
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
37
35
|
import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
|
|
38
36
|
import {
|
|
39
37
|
type ContractArtifact,
|
|
@@ -45,24 +43,29 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
|
45
43
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
46
44
|
import {
|
|
47
45
|
type ContractInstanceWithAddress,
|
|
46
|
+
type NodeInfo,
|
|
48
47
|
computePartialAddress,
|
|
49
48
|
getContractClassFromArtifact,
|
|
50
49
|
} from '@aztec/stdlib/contract';
|
|
51
50
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
52
|
-
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
53
|
-
import {
|
|
51
|
+
import { Gas, GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
52
|
+
import {
|
|
53
|
+
computeSiloedPrivateInitializationNullifier,
|
|
54
|
+
computeSiloedPublicInitializationNullifier,
|
|
55
|
+
} from '@aztec/stdlib/hash';
|
|
54
56
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
55
57
|
import {
|
|
56
58
|
BlockHeader,
|
|
59
|
+
ExecutionPayload,
|
|
57
60
|
type TxExecutionRequest,
|
|
58
61
|
type TxProfileResult,
|
|
59
|
-
TxSimulationResult,
|
|
60
62
|
type UtilityExecutionResult,
|
|
63
|
+
mergeExecutionPayloads,
|
|
61
64
|
} from '@aztec/stdlib/tx';
|
|
62
|
-
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
63
65
|
|
|
64
66
|
import { inspect } from 'util';
|
|
65
67
|
|
|
68
|
+
import { assertGasLimitsWithinNetworkLimits } from './get_gas_limits.js';
|
|
66
69
|
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
67
70
|
|
|
68
71
|
/**
|
|
@@ -75,7 +78,7 @@ export type FeeOptions = {
|
|
|
75
78
|
*/
|
|
76
79
|
walletFeePaymentMethod?: FeePaymentMethod;
|
|
77
80
|
/** Configuration options for the account to properly handle the selected fee payment method */
|
|
78
|
-
accountFeePaymentMethodOptions
|
|
81
|
+
accountFeePaymentMethodOptions?: AccountFeePaymentMethodOptions;
|
|
79
82
|
/** The gas settings to use for the transaction */
|
|
80
83
|
gasSettings: GasSettings;
|
|
81
84
|
};
|
|
@@ -83,19 +86,38 @@ export type FeeOptions = {
|
|
|
83
86
|
/** Options for `simulateViaEntrypoint`. */
|
|
84
87
|
export type SimulateViaEntrypointOptions = Pick<
|
|
85
88
|
SimulateOptions,
|
|
86
|
-
'from' | 'additionalScopes' | 'skipTxValidation' | 'skipFeeEnforcement'
|
|
89
|
+
'from' | 'additionalScopes' | 'skipTxValidation' | 'skipFeeEnforcement' | 'sendMessagesAs' | 'overrides'
|
|
87
90
|
> & {
|
|
88
91
|
/** Fee options for the entrypoint */
|
|
89
92
|
feeOptions: FeeOptions;
|
|
90
|
-
/** Scopes to use for the simulation */
|
|
91
|
-
scopes: AccessScopes;
|
|
92
93
|
};
|
|
94
|
+
|
|
95
|
+
/** Options for `completeFeeOptions`. */
|
|
96
|
+
export type CompleteFeeOptionsConfig = {
|
|
97
|
+
/** The address where the transaction is being sent from. */
|
|
98
|
+
from: AztecAddress | NoFrom;
|
|
99
|
+
/** The address paying for fees (if any fee payment method is embedded in the execution payload). */
|
|
100
|
+
feePayer?: AztecAddress;
|
|
101
|
+
/** User-provided partial gas settings. */
|
|
102
|
+
gasSettings?: Partial<FieldsOf<GasSettings>>;
|
|
103
|
+
/** If true, returns gas settings with high gas limits for estimation. If false, uses fallback limits. */
|
|
104
|
+
forEstimation?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Assumed network congestion level for fee prediction. Controls how aggressively the wallet
|
|
107
|
+
* estimates future fees. Defaults to Limit (worst case) when not specified.
|
|
108
|
+
*/
|
|
109
|
+
congestionEstimate?: ManaUsageEstimate;
|
|
110
|
+
};
|
|
111
|
+
|
|
93
112
|
/**
|
|
94
113
|
* A base class for Wallet implementations
|
|
95
114
|
*/
|
|
96
115
|
export abstract class BaseWallet implements Wallet {
|
|
97
116
|
protected minFeePadding = 0.5;
|
|
98
117
|
protected cancellableTransactions = false;
|
|
118
|
+
// A wallet is instantiated for a particular chain, so chain info never changes during its lifetime.
|
|
119
|
+
// We cache it here because getChainInfo is called frequently (every tx simulation, send, auth wit, etc.).
|
|
120
|
+
private nodeInfoPromise: Promise<NodeInfo> | undefined;
|
|
99
121
|
|
|
100
122
|
// Protected because we want to force wallets to instantiate their own PXE.
|
|
101
123
|
protected constructor(
|
|
@@ -104,10 +126,21 @@ export abstract class BaseWallet implements Wallet {
|
|
|
104
126
|
protected log = createLogger('wallet-sdk:base_wallet'),
|
|
105
127
|
) {}
|
|
106
128
|
|
|
107
|
-
protected scopesFrom(from: AztecAddress, additionalScopes: AztecAddress[] = []): AztecAddress[] {
|
|
108
|
-
const allScopes = from
|
|
129
|
+
protected scopesFrom(from: AztecAddress | NoFrom, additionalScopes: AztecAddress[] = []): AztecAddress[] {
|
|
130
|
+
const allScopes = from === NO_FROM ? additionalScopes : [from, ...additionalScopes];
|
|
109
131
|
const scopeSet = new Set(allScopes.map(address => address.toString()));
|
|
110
|
-
return [...scopeSet].map(AztecAddress.
|
|
132
|
+
return [...scopeSet].map(AztecAddress.fromStringUnsafe);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Picks the sender address PXE should tag private messages with. Returns `undefined` when there is no signing
|
|
137
|
+
* account (`from === NO_FROM`) and no explicit override; in that case any private log emitted by the tx using
|
|
138
|
+
* the wallet-supplied default sender will fail the "Sender for tags is not set" assertion.
|
|
139
|
+
* @param from - Tx sender, or `NO_FROM`.
|
|
140
|
+
* @param sendMessagesAs - Explicit override.
|
|
141
|
+
*/
|
|
142
|
+
protected senderForTagsFrom(from: AztecAddress | NoFrom, sendMessagesAs?: AztecAddress): AztecAddress | undefined {
|
|
143
|
+
return sendMessagesAs ?? (from === NO_FROM ? undefined : from);
|
|
111
144
|
}
|
|
112
145
|
|
|
113
146
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
@@ -122,37 +155,71 @@ export abstract class BaseWallet implements Wallet {
|
|
|
122
155
|
* @returns The aliased collection of AztecAddresses that form this wallet's address book
|
|
123
156
|
*/
|
|
124
157
|
async getAddressBook(): Promise<Aliased<AztecAddress>[]> {
|
|
125
|
-
const
|
|
126
|
-
return
|
|
158
|
+
const sources = await this.pxe.getTaggingSecretSources({ kind: 'address-derived' });
|
|
159
|
+
return sources.map(source => ({ item: source.sender, alias: '' }));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Fetches and caches the node info for the wallet's lifetime, since a wallet talks to a single network and
|
|
164
|
+
* node info never changes. A rejected fetch clears the cache so the next call retries instead of replaying
|
|
165
|
+
* the cached rejection forever — important because the gas-limit fill-in and validation (run on every send)
|
|
166
|
+
* depend on it.
|
|
167
|
+
*/
|
|
168
|
+
private getNodeInfo(): Promise<NodeInfo> {
|
|
169
|
+
if (!this.nodeInfoPromise) {
|
|
170
|
+
this.nodeInfoPromise = this.aztecNode.getNodeInfo().catch(err => {
|
|
171
|
+
this.nodeInfoPromise = undefined;
|
|
172
|
+
throw err;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return this.nodeInfoPromise;
|
|
127
176
|
}
|
|
128
177
|
|
|
129
178
|
async getChainInfo(): Promise<ChainInfo> {
|
|
130
|
-
const { l1ChainId, rollupVersion } = await this.
|
|
179
|
+
const { l1ChainId, rollupVersion } = await this.getNodeInfo();
|
|
131
180
|
return { chainId: new Fr(l1ChainId), version: new Fr(rollupVersion) };
|
|
132
181
|
}
|
|
133
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Returns the maximum gas limits a single transaction may declare on this wallet's network (the
|
|
185
|
+
* node-advertised `txsLimits.gas`). Internal helper used to fill in default gas limits when sending a
|
|
186
|
+
* transaction without explicit limits, and to validate caller-provided limits before sending. Backed by
|
|
187
|
+
* the cached node info, since a wallet talks to a single network.
|
|
188
|
+
*/
|
|
189
|
+
protected async getMaxTxGasLimits(): Promise<Gas> {
|
|
190
|
+
const { txsLimits } = await this.getNodeInfo();
|
|
191
|
+
return new Gas(txsLimits.gas.daGas, txsLimits.gas.l2Gas);
|
|
192
|
+
}
|
|
193
|
+
|
|
134
194
|
protected async createTxExecutionRequestFromPayloadAndFee(
|
|
135
195
|
executionPayload: ExecutionPayload,
|
|
136
|
-
from: AztecAddress,
|
|
196
|
+
from: AztecAddress | NoFrom,
|
|
137
197
|
feeOptions: FeeOptions,
|
|
138
198
|
): Promise<TxExecutionRequest> {
|
|
139
199
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
140
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
141
|
-
txNonce: Fr.random(),
|
|
142
|
-
cancellable: this.cancellableTransactions,
|
|
143
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
144
|
-
};
|
|
145
200
|
const finalExecutionPayload = feeExecutionPayload
|
|
146
201
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
147
202
|
: executionPayload;
|
|
148
|
-
const fromAccount = await this.getAccountFromAddress(from);
|
|
149
203
|
const chainInfo = await this.getChainInfo();
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
chainInfo
|
|
154
|
-
|
|
155
|
-
|
|
204
|
+
|
|
205
|
+
if (from === NO_FROM) {
|
|
206
|
+
const entrypoint = new DefaultEntrypoint();
|
|
207
|
+
return entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
208
|
+
} else {
|
|
209
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
210
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
211
|
+
txNonce: Fr.random(),
|
|
212
|
+
cancellable: this.cancellableTransactions,
|
|
213
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
214
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
215
|
+
};
|
|
216
|
+
return fromAccount.createTxExecutionRequest(
|
|
217
|
+
finalExecutionPayload,
|
|
218
|
+
feeOptions.gasSettings,
|
|
219
|
+
chainInfo,
|
|
220
|
+
executionOptions,
|
|
221
|
+
);
|
|
222
|
+
}
|
|
156
223
|
}
|
|
157
224
|
|
|
158
225
|
public async createAuthWit(
|
|
@@ -201,31 +268,54 @@ export abstract class BaseWallet implements Wallet {
|
|
|
201
268
|
|
|
202
269
|
/**
|
|
203
270
|
* Completes partial user-provided fee options with wallet defaults.
|
|
204
|
-
* @param
|
|
205
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
206
|
-
* @param gasSettings - User-provided partial gas settings
|
|
207
|
-
* @returns - Complete fee options that can be used to create a transaction execution request
|
|
271
|
+
* @param config - Fee completion config.
|
|
208
272
|
*/
|
|
209
|
-
protected async completeFeeOptions(
|
|
210
|
-
from
|
|
211
|
-
feePayer?: AztecAddress,
|
|
212
|
-
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
213
|
-
): Promise<FeeOptions> {
|
|
273
|
+
protected async completeFeeOptions(config: CompleteFeeOptionsConfig): Promise<FeeOptions> {
|
|
274
|
+
const { from, feePayer, gasSettings, forEstimation, congestionEstimate } = config;
|
|
214
275
|
const maxFeesPerGas =
|
|
215
|
-
gasSettings?.maxFeesPerGas ?? (await this.
|
|
276
|
+
gasSettings?.maxFeesPerGas ?? (await this.getMinFees(congestionEstimate)).mul(1 + this.minFeePadding);
|
|
216
277
|
let accountFeePaymentMethodOptions;
|
|
217
|
-
//
|
|
218
|
-
//
|
|
219
|
-
if (
|
|
220
|
-
|
|
278
|
+
// If from is an address, we need to determine the appropriate fee payment method options for the
|
|
279
|
+
// account contract entrypoint to use
|
|
280
|
+
if (from !== NO_FROM) {
|
|
281
|
+
if (!feePayer) {
|
|
282
|
+
// The transaction does not include a fee payment method, so we set the flag
|
|
283
|
+
// for the account to use its fee juice balance
|
|
284
|
+
accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
|
|
285
|
+
} else {
|
|
286
|
+
// The transaction includes fee payment method, so we check if we are the fee payer for it
|
|
287
|
+
// (this can only happen if the embedded payment method is FeeJuiceWithClaim)
|
|
288
|
+
accountFeePaymentMethodOptions = from.equals(feePayer)
|
|
289
|
+
? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM
|
|
290
|
+
: AccountFeePaymentMethodOptions.EXTERNAL;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const gasSettingsOverrides = {
|
|
294
|
+
gasLimits: gasSettings?.gasLimits ? Gas.from(gasSettings.gasLimits) : undefined,
|
|
295
|
+
teardownGasLimits: gasSettings?.teardownGasLimits ? Gas.from(gasSettings.teardownGasLimits) : undefined,
|
|
296
|
+
maxFeesPerGas,
|
|
297
|
+
maxPriorityFeesPerGas: gasSettings?.maxPriorityFeesPerGas ?? GasFees.empty(),
|
|
298
|
+
};
|
|
299
|
+
// When estimating gas (simulation), use high limits so the simulation doesn't run out of gas.
|
|
300
|
+
// When sending for real without explicit limits, declare the most a single tx may use on this network
|
|
301
|
+
// (the node's per-tx admission limit), so the proposer does not skip the tx for over-declaring gas.
|
|
302
|
+
let fullGasSettings;
|
|
303
|
+
if (forEstimation) {
|
|
304
|
+
// Estimation deliberately uses very high internal limits and skips tx validation, so we do not
|
|
305
|
+
// validate against the network admission limit here.
|
|
306
|
+
fullGasSettings = GasSettings.forEstimation(gasSettingsOverrides);
|
|
221
307
|
} else {
|
|
222
|
-
|
|
223
|
-
//
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
308
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
309
|
+
// If the caller declared explicit gas limits, reject them up front when they exceed the network's
|
|
310
|
+
// per-tx admission limit (mirroring the node's GasLimitsValidator). Otherwise fill in the limit.
|
|
311
|
+
if (gasSettingsOverrides.gasLimits) {
|
|
312
|
+
assertGasLimitsWithinNetworkLimits(gasSettingsOverrides.gasLimits, maxTxGasLimits);
|
|
313
|
+
}
|
|
314
|
+
fullGasSettings = GasSettings.fallback({
|
|
315
|
+
...gasSettingsOverrides,
|
|
316
|
+
gasLimits: gasSettingsOverrides.gasLimits ?? maxTxGasLimits,
|
|
317
|
+
});
|
|
227
318
|
}
|
|
228
|
-
const fullGasSettings: GasSettings = GasSettings.default({ ...gasSettings, maxFeesPerGas });
|
|
229
319
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
230
320
|
return {
|
|
231
321
|
gasSettings: fullGasSettings,
|
|
@@ -235,38 +325,30 @@ export abstract class BaseWallet implements Wallet {
|
|
|
235
325
|
}
|
|
236
326
|
|
|
237
327
|
/**
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* to
|
|
241
|
-
* @param from - The address where the transaction is being sent from
|
|
242
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
243
|
-
* @param gasSettings - User-provided partial gas settings
|
|
328
|
+
* Returns the worst-case min fee across predicted future slots.
|
|
329
|
+
* Falls back to getCurrentMinFees if the node doesn't support getPredictedMinFees.
|
|
330
|
+
* @param estimate - The mana usage estimate to use for fee prediction. Defaults to Limit for conservative estimation.
|
|
244
331
|
*/
|
|
245
|
-
protected async
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
maxPriorityFeesPerGas,
|
|
261
|
-
);
|
|
262
|
-
return {
|
|
263
|
-
...defaultFeeOptions,
|
|
264
|
-
gasSettings: gasSettingsForEstimation,
|
|
265
|
-
};
|
|
332
|
+
protected async getMinFees(estimate: ManaUsageEstimate = ManaUsageEstimate.Limit): Promise<GasFees> {
|
|
333
|
+
try {
|
|
334
|
+
const predicted = await this.aztecNode.getPredictedMinFees(estimate);
|
|
335
|
+
if (predicted.length === 0) {
|
|
336
|
+
return this.aztecNode.getCurrentMinFees();
|
|
337
|
+
}
|
|
338
|
+
return predicted.reduce((worst, fees) => (fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst));
|
|
339
|
+
} catch (err: any) {
|
|
340
|
+
// Fallback for old nodes that don't support getPredictedMinFees.
|
|
341
|
+
// Only fall back on method-not-found errors (JSON-RPC code -32601); rethrow others.
|
|
342
|
+
if (err?.cause?.code === -32601 || err?.message?.includes('Method not found')) {
|
|
343
|
+
return this.aztecNode.getCurrentMinFees();
|
|
344
|
+
}
|
|
345
|
+
throw err;
|
|
346
|
+
}
|
|
266
347
|
}
|
|
267
348
|
|
|
268
|
-
registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
269
|
-
|
|
349
|
+
async registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
350
|
+
await this.pxe.registerTaggingSecretSource({ kind: 'address-derived', sender: address });
|
|
351
|
+
return address;
|
|
270
352
|
}
|
|
271
353
|
|
|
272
354
|
async registerContract(
|
|
@@ -307,6 +389,10 @@ export abstract class BaseWallet implements Wallet {
|
|
|
307
389
|
return instance;
|
|
308
390
|
}
|
|
309
391
|
|
|
392
|
+
registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
393
|
+
return this.pxe.registerContractClass(artifact);
|
|
394
|
+
}
|
|
395
|
+
|
|
310
396
|
/**
|
|
311
397
|
* Simulates calls through the standard PXE path (account entrypoint).
|
|
312
398
|
* @param executionPayload - The execution payload to simulate.
|
|
@@ -318,12 +404,30 @@ export abstract class BaseWallet implements Wallet {
|
|
|
318
404
|
opts.from,
|
|
319
405
|
opts.feeOptions,
|
|
320
406
|
);
|
|
321
|
-
|
|
407
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
322
408
|
simulatePublic: true,
|
|
323
409
|
skipTxValidation: opts.skipTxValidation,
|
|
324
410
|
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
325
|
-
scopes: opts.
|
|
411
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
412
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
413
|
+
overrides: opts.overrides,
|
|
326
414
|
});
|
|
415
|
+
const appCallOffset = await this.computeAppCallOffset(opts.from, opts.feeOptions);
|
|
416
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Computes the index where the app's calls begin in the flattened array of calls (0 = entrypoint/root, 1..N = fee
|
|
421
|
+
* calls, N+1 = app).
|
|
422
|
+
* @param from - The sender address, or NO_FROM for the default entrypoint.
|
|
423
|
+
* @param feeOptions - Fee options containing the wallet fee payment method.
|
|
424
|
+
*/
|
|
425
|
+
protected async computeAppCallOffset(from: AztecAddress | NoFrom, feeOptions: FeeOptions): Promise<number> {
|
|
426
|
+
if (from === NO_FROM) {
|
|
427
|
+
return 0;
|
|
428
|
+
}
|
|
429
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
430
|
+
return (feeExecutionPayload?.calls.length ?? 0) + 1; // +1 for entrypoint
|
|
327
431
|
}
|
|
328
432
|
|
|
329
433
|
/**
|
|
@@ -334,10 +438,17 @@ export abstract class BaseWallet implements Wallet {
|
|
|
334
438
|
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
335
439
|
* @returns The merged simulation result.
|
|
336
440
|
*/
|
|
337
|
-
async simulateTx(
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
441
|
+
async simulateTx(
|
|
442
|
+
executionPayload: ExecutionPayload,
|
|
443
|
+
opts: SimulateOptions,
|
|
444
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
445
|
+
const feeOptions = await this.completeFeeOptions({
|
|
446
|
+
from: opts.from,
|
|
447
|
+
feePayer: executionPayload.feePayer,
|
|
448
|
+
gasSettings: opts.fee?.gasSettings,
|
|
449
|
+
forEstimation: true,
|
|
450
|
+
congestionEstimate: opts.fee?.congestionEstimate,
|
|
451
|
+
});
|
|
341
452
|
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
342
453
|
const remainingPayload = { ...executionPayload, calls: remainingCalls };
|
|
343
454
|
|
|
@@ -348,29 +459,33 @@ export abstract class BaseWallet implements Wallet {
|
|
|
348
459
|
try {
|
|
349
460
|
blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
350
461
|
} catch {
|
|
351
|
-
blockHeader = (await this.aztecNode.
|
|
462
|
+
blockHeader = (await this.aztecNode.getBlockData('latest'))!.header;
|
|
352
463
|
}
|
|
353
464
|
|
|
465
|
+
const simulationOrigin = opts.from === NO_FROM ? AztecAddress.ZERO : opts.from;
|
|
354
466
|
const [optimizedResults, normalResult] = await Promise.all([
|
|
355
467
|
optimizableCalls.length > 0
|
|
356
468
|
? simulateViaNode(
|
|
357
469
|
this.aztecNode,
|
|
358
470
|
optimizableCalls,
|
|
359
|
-
|
|
471
|
+
simulationOrigin,
|
|
360
472
|
chainInfo,
|
|
361
473
|
feeOptions.gasSettings,
|
|
362
474
|
blockHeader,
|
|
363
475
|
opts.skipFeeEnforcement ?? true,
|
|
364
476
|
this.getContractName.bind(this),
|
|
477
|
+
opts.overrides,
|
|
365
478
|
)
|
|
366
479
|
: Promise.resolve([]),
|
|
367
480
|
remainingCalls.length > 0
|
|
368
481
|
? this.simulateViaEntrypoint(remainingPayload, {
|
|
369
482
|
from: opts.from,
|
|
370
483
|
feeOptions,
|
|
371
|
-
|
|
484
|
+
additionalScopes: opts.additionalScopes,
|
|
372
485
|
skipTxValidation: opts.skipTxValidation,
|
|
373
486
|
skipFeeEnforcement: opts.skipFeeEnforcement ?? true,
|
|
487
|
+
sendMessagesAs: opts.sendMessagesAs,
|
|
488
|
+
overrides: opts.overrides,
|
|
374
489
|
})
|
|
375
490
|
: Promise.resolve(null),
|
|
376
491
|
]);
|
|
@@ -379,12 +494,18 @@ export abstract class BaseWallet implements Wallet {
|
|
|
379
494
|
}
|
|
380
495
|
|
|
381
496
|
async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
382
|
-
const feeOptions = await this.completeFeeOptions(
|
|
497
|
+
const feeOptions = await this.completeFeeOptions({
|
|
498
|
+
from: opts.from,
|
|
499
|
+
feePayer: executionPayload.feePayer,
|
|
500
|
+
gasSettings: opts.fee?.gasSettings,
|
|
501
|
+
congestionEstimate: opts.fee?.congestionEstimate,
|
|
502
|
+
});
|
|
383
503
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
384
504
|
return this.pxe.profileTx(txRequest, {
|
|
385
505
|
profileMode: opts.profileMode,
|
|
386
506
|
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
387
507
|
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
508
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
388
509
|
});
|
|
389
510
|
}
|
|
390
511
|
|
|
@@ -392,16 +513,24 @@ export abstract class BaseWallet implements Wallet {
|
|
|
392
513
|
executionPayload: ExecutionPayload,
|
|
393
514
|
opts: SendOptions<W>,
|
|
394
515
|
): Promise<SendReturn<W>> {
|
|
395
|
-
const feeOptions = await this.completeFeeOptions(
|
|
516
|
+
const feeOptions = await this.completeFeeOptions({
|
|
517
|
+
from: opts.from,
|
|
518
|
+
feePayer: executionPayload.feePayer,
|
|
519
|
+
gasSettings: opts.fee?.gasSettings,
|
|
520
|
+
congestionEstimate: opts.fee?.congestionEstimate,
|
|
521
|
+
});
|
|
396
522
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
397
|
-
const provenTx = await this.pxe.proveTx(txRequest,
|
|
523
|
+
const provenTx = await this.pxe.proveTx(txRequest, {
|
|
524
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
525
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
526
|
+
});
|
|
398
527
|
const offchainOutput = extractOffchainOutput(
|
|
399
528
|
provenTx.getOffchainEffects(),
|
|
400
529
|
provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp,
|
|
401
530
|
);
|
|
402
531
|
const tx = await provenTx.toTx();
|
|
403
532
|
const txHash = tx.getTxHash();
|
|
404
|
-
if (await this.aztecNode.
|
|
533
|
+
if ((await this.aztecNode.getTxReceipt(txHash)).isMined()) {
|
|
405
534
|
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
|
|
406
535
|
}
|
|
407
536
|
this.log.debug(`Sending transaction ${txHash}`);
|
|
@@ -420,7 +549,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
420
549
|
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
421
550
|
|
|
422
551
|
// Display debug logs from public execution if present (served in test mode only)
|
|
423
|
-
if (receipt.debugLogs?.length) {
|
|
552
|
+
if (receipt.isMined() && receipt.debugLogs?.length) {
|
|
424
553
|
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
425
554
|
}
|
|
426
555
|
|
|
@@ -455,7 +584,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
455
584
|
}
|
|
456
585
|
|
|
457
586
|
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult> {
|
|
458
|
-
return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes:
|
|
587
|
+
return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes: opts.scopes });
|
|
459
588
|
}
|
|
460
589
|
|
|
461
590
|
async getPrivateEvents<T>(
|
|
@@ -480,26 +609,29 @@ export abstract class BaseWallet implements Wallet {
|
|
|
480
609
|
|
|
481
610
|
/**
|
|
482
611
|
* Returns metadata about a contract, including whether it has been initialized, published, and updated.
|
|
483
|
-
*
|
|
484
|
-
* `isContractInitialized` requires the contract instance to be registered in the PXE (for `init_hash`). When the
|
|
485
|
-
* instance is not available, `isContractInitialized` is `undefined` since it cannot be determined.
|
|
486
612
|
* @param address - The contract address to query.
|
|
487
613
|
*/
|
|
488
614
|
async getContractMetadata(address: AztecAddress) {
|
|
489
615
|
const instance = await this.pxe.getContractInstance(address);
|
|
490
616
|
const publiclyRegisteredContractPromise = this.aztecNode.getContract(address);
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
// the instance (and thus init_hash), we can't compute it, so we return undefined.
|
|
494
|
-
//
|
|
495
|
-
// We skip the public initialization nullifier because it's not always emitted (contracts without public external
|
|
496
|
-
// functions that require initialization checks won't emit it). If the private one exists, the public one was
|
|
497
|
-
// created in the same tx and will also be present.
|
|
498
|
-
let isContractInitialized: boolean | undefined = undefined;
|
|
617
|
+
|
|
618
|
+
let initializationStatus: ContractInitializationStatus;
|
|
499
619
|
if (instance) {
|
|
620
|
+
// We have the instance, so we can compute the private initialization nullifier (which includes init_hash and is
|
|
621
|
+
// emitted by both private and public initializers) and get a definitive INITIALIZED/UNINITIALIZED answer.
|
|
500
622
|
const initNullifier = await computeSiloedPrivateInitializationNullifier(address, instance.initializationHash);
|
|
501
623
|
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
502
|
-
|
|
624
|
+
initializationStatus = witness
|
|
625
|
+
? ContractInitializationStatus.INITIALIZED
|
|
626
|
+
: ContractInitializationStatus.UNINITIALIZED;
|
|
627
|
+
} else {
|
|
628
|
+
// Without the instance we lack the init_hash needed for the private nullifier. We fall back to checking the
|
|
629
|
+
// public initialization nullifier (computed from address alone). Not all contracts emit it (only those with
|
|
630
|
+
// public functions that require initialization checks), so its absence doesn't mean the contract is
|
|
631
|
+
// uninitialized.
|
|
632
|
+
const publicNullifier = await computeSiloedPublicInitializationNullifier(address);
|
|
633
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', publicNullifier);
|
|
634
|
+
initializationStatus = witness ? ContractInitializationStatus.INITIALIZED : ContractInitializationStatus.UNKNOWN;
|
|
503
635
|
}
|
|
504
636
|
const publiclyRegisteredContract = await publiclyRegisteredContractPromise;
|
|
505
637
|
const isContractUpdated =
|
|
@@ -507,7 +639,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
507
639
|
!publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
508
640
|
return {
|
|
509
641
|
instance: instance ?? undefined,
|
|
510
|
-
|
|
642
|
+
initializationStatus,
|
|
511
643
|
isContractPublished: !!publiclyRegisteredContract,
|
|
512
644
|
isContractUpdated: !!isContractUpdated,
|
|
513
645
|
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined,
|