@aztec/wallet-sdk 0.0.1-commit.9ef841308 → 0.0.1-commit.a4600f49
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 -35
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +187 -81
- 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/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 -3
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -1
- package/dest/extension/provider/extension_wallet.js +80 -9
- package/dest/iframe/handlers/iframe_connection_handler.d.ts +6 -2
- package/dest/iframe/handlers/iframe_connection_handler.d.ts.map +1 -1
- package/dest/iframe/handlers/iframe_connection_handler.js +18 -7
- package/dest/iframe/provider/iframe_wallet.d.ts +20 -3
- package/dest/iframe/provider/iframe_wallet.d.ts.map +1 -1
- package/dest/iframe/provider/iframe_wallet.js +79 -10
- package/dest/types.d.ts +52 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +25 -0
- package/package.json +8 -8
- package/src/base-wallet/base_wallet.ts +221 -108
- 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/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 -8
- package/src/iframe/handlers/iframe_connection_handler.ts +21 -8
- package/src/iframe/provider/iframe_wallet.ts +103 -9
- package/src/types.ts +59 -0
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
2
2
|
import { NO_WAIT, extractOffchainOutput } from '@aztec/aztec.js/contracts';
|
|
3
3
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
4
|
-
import { ContractInitializationStatus } from '@aztec/aztec.js/wallet';
|
|
5
|
-
import { GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT } from '@aztec/constants';
|
|
4
|
+
import { ContractInitializationStatus, TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
6
5
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
7
6
|
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
8
7
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
@@ -10,12 +9,14 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
10
9
|
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
11
10
|
import { decodeFromAbi } from '@aztec/stdlib/abi';
|
|
12
11
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
|
-
import { computePartialAddress
|
|
12
|
+
import { computePartialAddress } from '@aztec/stdlib/contract';
|
|
14
13
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
15
|
-
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
14
|
+
import { Gas, GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
16
15
|
import { computeSiloedPrivateInitializationNullifier, computeSiloedPublicInitializationNullifier } from '@aztec/stdlib/hash';
|
|
16
|
+
import { deriveKeys, deriveKeysFromMasterSecretKeys } from '@aztec/stdlib/keys';
|
|
17
17
|
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
18
18
|
import { inspect } from 'util';
|
|
19
|
+
import { assertGasLimitsWithinNetworkLimits } from './get_gas_limits.js';
|
|
19
20
|
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
20
21
|
/**
|
|
21
22
|
* A base class for Wallet implementations
|
|
@@ -25,6 +26,12 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
25
26
|
log;
|
|
26
27
|
minFeePadding;
|
|
27
28
|
cancellableTransactions;
|
|
29
|
+
// Poll interval (in seconds) injected into sendTx waits when the caller does not specify one. Left undefined on
|
|
30
|
+
// production wallets so the DefaultWaitOpts 1s cadence stands; test wallets talking to in-process nodes lower it.
|
|
31
|
+
defaultWaitInterval;
|
|
32
|
+
// A wallet is instantiated for a particular chain, so chain info never changes during its lifetime.
|
|
33
|
+
// We cache it here because getChainInfo is called frequently (every tx simulation, send, auth wit, etc.).
|
|
34
|
+
nodeInfoPromise;
|
|
28
35
|
// Protected because we want to force wallets to instantiate their own PXE.
|
|
29
36
|
constructor(pxe, aztecNode, log = createLogger('wallet-sdk:base_wallet')){
|
|
30
37
|
this.pxe = pxe;
|
|
@@ -41,7 +48,16 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
41
48
|
const scopeSet = new Set(allScopes.map((address)=>address.toString()));
|
|
42
49
|
return [
|
|
43
50
|
...scopeSet
|
|
44
|
-
].map(AztecAddress.
|
|
51
|
+
].map(AztecAddress.fromStringUnsafe);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Picks the sender address PXE should tag private messages with. Returns `undefined` when there is no signing
|
|
55
|
+
* account (`from === NO_FROM`) and no explicit override; in that case any private log emitted by the tx using
|
|
56
|
+
* the wallet-supplied default sender will fail the "Sender for tags is not set" assertion.
|
|
57
|
+
* @param from - Tx sender, or `NO_FROM`.
|
|
58
|
+
* @param sendMessagesAs - Explicit override.
|
|
59
|
+
*/ senderForTagsFrom(from, sendMessagesAs) {
|
|
60
|
+
return sendMessagesAs ?? (from === NO_FROM ? undefined : from);
|
|
45
61
|
}
|
|
46
62
|
/**
|
|
47
63
|
* Returns the list of aliased contacts associated with the wallet.
|
|
@@ -50,19 +66,44 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
50
66
|
* - Contacts: more general concept akin to a phone's contact list.
|
|
51
67
|
* @returns The aliased collection of AztecAddresses that form this wallet's address book
|
|
52
68
|
*/ async getAddressBook() {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
69
|
+
const sources = await this.pxe.getTaggingSecretSources({
|
|
70
|
+
kind: 'address-derived'
|
|
71
|
+
});
|
|
72
|
+
return sources.map((source)=>({
|
|
73
|
+
item: source.sender,
|
|
56
74
|
alias: ''
|
|
57
75
|
}));
|
|
58
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Fetches and caches the node info for the wallet's lifetime, since a wallet talks to a single network and
|
|
79
|
+
* node info never changes. A rejected fetch clears the cache so the next call retries instead of replaying
|
|
80
|
+
* the cached rejection forever — important because the gas-limit fill-in and validation (run on every send)
|
|
81
|
+
* depend on it.
|
|
82
|
+
*/ getNodeInfo() {
|
|
83
|
+
if (!this.nodeInfoPromise) {
|
|
84
|
+
this.nodeInfoPromise = this.aztecNode.getNodeInfo().catch((err)=>{
|
|
85
|
+
this.nodeInfoPromise = undefined;
|
|
86
|
+
throw err;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return this.nodeInfoPromise;
|
|
90
|
+
}
|
|
59
91
|
async getChainInfo() {
|
|
60
|
-
const { l1ChainId, rollupVersion } = await this.
|
|
92
|
+
const { l1ChainId, rollupVersion } = await this.getNodeInfo();
|
|
61
93
|
return {
|
|
62
94
|
chainId: new Fr(l1ChainId),
|
|
63
95
|
version: new Fr(rollupVersion)
|
|
64
96
|
};
|
|
65
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Returns the maximum gas limits a single transaction may declare on this wallet's network (the
|
|
100
|
+
* node-advertised `txsLimits.gas`). Internal helper used to fill in default gas limits when sending a
|
|
101
|
+
* transaction without explicit limits, and to validate caller-provided limits before sending. Backed by
|
|
102
|
+
* the cached node info, since a wallet talks to a single network.
|
|
103
|
+
*/ async getMaxTxGasLimits() {
|
|
104
|
+
const { txsLimits } = await this.getNodeInfo();
|
|
105
|
+
return new Gas(txsLimits.gas.daGas, txsLimits.gas.l2Gas);
|
|
106
|
+
}
|
|
66
107
|
async createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions) {
|
|
67
108
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
68
109
|
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
@@ -125,12 +166,10 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
125
166
|
}
|
|
126
167
|
/**
|
|
127
168
|
* Completes partial user-provided fee options with wallet defaults.
|
|
128
|
-
* @param
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
*/ async completeFeeOptions(from, feePayer, gasSettings) {
|
|
133
|
-
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
|
|
169
|
+
* @param config - Fee completion config.
|
|
170
|
+
*/ async completeFeeOptions(config) {
|
|
171
|
+
const { from, feePayer, gasSettings, forEstimation, congestionEstimate } = config;
|
|
172
|
+
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.getMinFees(congestionEstimate)).mul(1 + this.minFeePadding);
|
|
134
173
|
let accountFeePaymentMethodOptions;
|
|
135
174
|
// If from is an address, we need to determine the appropriate fee payment method options for the
|
|
136
175
|
// account contract entrypoint to use
|
|
@@ -145,10 +184,32 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
145
184
|
accountFeePaymentMethodOptions = from.equals(feePayer) ? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM : AccountFeePaymentMethodOptions.EXTERNAL;
|
|
146
185
|
}
|
|
147
186
|
}
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
187
|
+
const gasSettingsOverrides = {
|
|
188
|
+
gasLimits: gasSettings?.gasLimits ? Gas.from(gasSettings.gasLimits) : undefined,
|
|
189
|
+
teardownGasLimits: gasSettings?.teardownGasLimits ? Gas.from(gasSettings.teardownGasLimits) : undefined,
|
|
190
|
+
maxFeesPerGas,
|
|
191
|
+
maxPriorityFeesPerGas: gasSettings?.maxPriorityFeesPerGas ?? GasFees.empty()
|
|
192
|
+
};
|
|
193
|
+
// When estimating gas (simulation), use high limits so the simulation doesn't run out of gas.
|
|
194
|
+
// When sending for real without explicit limits, declare the most a single tx may use on this network
|
|
195
|
+
// (the node's per-tx admission limit), so the proposer does not skip the tx for over-declaring gas.
|
|
196
|
+
let fullGasSettings;
|
|
197
|
+
if (forEstimation) {
|
|
198
|
+
// Estimation deliberately uses very high internal limits and skips tx validation, so we do not
|
|
199
|
+
// validate against the network admission limit here.
|
|
200
|
+
fullGasSettings = GasSettings.forEstimation(gasSettingsOverrides);
|
|
201
|
+
} else {
|
|
202
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
203
|
+
// If the caller declared explicit gas limits, reject them up front when they exceed the network's
|
|
204
|
+
// per-tx admission limit (mirroring the node's GasLimitsValidator). Otherwise fill in the limit.
|
|
205
|
+
if (gasSettingsOverrides.gasLimits) {
|
|
206
|
+
assertGasLimitsWithinNetworkLimits(gasSettingsOverrides.gasLimits, maxTxGasLimits);
|
|
207
|
+
}
|
|
208
|
+
fullGasSettings = GasSettings.fallback({
|
|
209
|
+
...gasSettingsOverrides,
|
|
210
|
+
gasLimits: gasSettingsOverrides.gasLimits ?? maxTxGasLimits
|
|
211
|
+
});
|
|
212
|
+
}
|
|
152
213
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
153
214
|
return {
|
|
154
215
|
gasSettings: fullGasSettings,
|
|
@@ -157,57 +218,56 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
157
218
|
};
|
|
158
219
|
}
|
|
159
220
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* to
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const { gasSettings: { maxFeesPerGas, maxPriorityFeesPerGas } } = defaultFeeOptions;
|
|
169
|
-
// Use unrealistically high gas limits for estimation to avoid running out of gas.
|
|
170
|
-
// They will be tuned down after the simulation.
|
|
171
|
-
const gasSettingsForEstimation = new GasSettings(new Gas(GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT), new Gas(GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT), maxFeesPerGas, maxPriorityFeesPerGas);
|
|
172
|
-
return {
|
|
173
|
-
...defaultFeeOptions,
|
|
174
|
-
gasSettings: gasSettingsForEstimation
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
registerSender(address, _alias = '') {
|
|
178
|
-
return this.pxe.registerSender(address);
|
|
179
|
-
}
|
|
180
|
-
async registerContract(instance, artifact, secretKey) {
|
|
181
|
-
const existingInstance = await this.pxe.getContractInstance(instance.address);
|
|
182
|
-
if (existingInstance) {
|
|
183
|
-
// Instance already registered in the wallet
|
|
184
|
-
if (artifact) {
|
|
185
|
-
const thisContractClass = await getContractClassFromArtifact(artifact);
|
|
186
|
-
if (!thisContractClass.id.equals(existingInstance.currentContractClassId)) {
|
|
187
|
-
// wallet holds an outdated version of this contract
|
|
188
|
-
await this.pxe.updateContract(instance.address, artifact);
|
|
189
|
-
instance.currentContractClassId = thisContractClass.id;
|
|
190
|
-
}
|
|
221
|
+
* Returns the worst-case min fee across predicted future slots.
|
|
222
|
+
* Falls back to getCurrentMinFees if the node doesn't support getPredictedMinFees.
|
|
223
|
+
* @param estimate - The mana usage estimate to use for fee prediction. Defaults to Limit for conservative estimation.
|
|
224
|
+
*/ async getMinFees(estimate = ManaUsageEstimate.Limit) {
|
|
225
|
+
try {
|
|
226
|
+
const predicted = await this.aztecNode.getPredictedMinFees(estimate);
|
|
227
|
+
if (predicted.length === 0) {
|
|
228
|
+
return this.aztecNode.getCurrentMinFees();
|
|
191
229
|
}
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
//
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (!artifact) {
|
|
199
|
-
throw new Error(`Cannot register contract at ${instance.address.toString()}: artifact is required but not provided, and wallet does not have the artifact for contract class ${instance.currentContractClassId.toString()}`);
|
|
200
|
-
}
|
|
230
|
+
return predicted.reduce((worst, fees)=>fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst);
|
|
231
|
+
} catch (err) {
|
|
232
|
+
// Fallback for old nodes that don't support getPredictedMinFees.
|
|
233
|
+
// Only fall back on method-not-found errors (JSON-RPC code -32601); rethrow others.
|
|
234
|
+
if (err?.cause?.code === -32601 || err?.message?.includes('Method not found')) {
|
|
235
|
+
return this.aztecNode.getCurrentMinFees();
|
|
201
236
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
237
|
+
throw err;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
async registerSender(address, _alias = '') {
|
|
241
|
+
await this.pxe.registerTaggingSecretSource({
|
|
242
|
+
kind: 'address-derived',
|
|
243
|
+
sender: address
|
|
244
|
+
});
|
|
245
|
+
return address;
|
|
246
|
+
}
|
|
247
|
+
async registerContract(instance, artifact, secretKeyOrKeys) {
|
|
248
|
+
// Classes and instances are registered independently: register the artifact (if provided) then the instance.
|
|
249
|
+
// Neither call validates that the artifact matches the class the instance runs, a missing artifact only surfaces
|
|
250
|
+
// when the contract is later simulated.
|
|
251
|
+
if (artifact) {
|
|
252
|
+
await this.pxe.registerContractClass(artifact);
|
|
206
253
|
}
|
|
207
|
-
|
|
208
|
-
|
|
254
|
+
const contractAddress = await this.pxe.registerContract(instance);
|
|
255
|
+
if (secretKeyOrKeys) {
|
|
256
|
+
// PXE never receives the account seed (from which the message-signing/fallback secret keys could be re-derived):
|
|
257
|
+
// the wallet derives the keys here. Of these, PXE only reads and stores the four privacy secret keys and the
|
|
258
|
+
// message-signing and fallback *public* keys — it never touches the message-signing or fallback secret keys.
|
|
259
|
+
//
|
|
260
|
+
// Since PXE recomputes the address from those keys, we assert it matches the instance's address: a mismatch means
|
|
261
|
+
// the provided keys don't correspond to this account.
|
|
262
|
+
const derivedKeys = secretKeyOrKeys instanceof Fr ? await deriveKeys(secretKeyOrKeys) : await deriveKeysFromMasterSecretKeys(secretKeyOrKeys);
|
|
263
|
+
const { address } = await this.pxe.registerAccount(derivedKeys, await computePartialAddress(instance));
|
|
264
|
+
if (!address.equals(contractAddress)) {
|
|
265
|
+
throw new Error(`Registered account address ${address.toString()} does not match contract instance address ${contractAddress.toString()}: the provided keys do not correspond to this account.`);
|
|
266
|
+
}
|
|
209
267
|
}
|
|
210
|
-
|
|
268
|
+
}
|
|
269
|
+
registerContractClass(artifact) {
|
|
270
|
+
return this.pxe.registerContractClass(artifact);
|
|
211
271
|
}
|
|
212
272
|
/**
|
|
213
273
|
* Simulates calls through the standard PXE path (account entrypoint).
|
|
@@ -215,12 +275,28 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
215
275
|
* @param opts - Simulation options.
|
|
216
276
|
*/ async simulateViaEntrypoint(executionPayload, opts) {
|
|
217
277
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, opts.feeOptions);
|
|
218
|
-
|
|
278
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
219
279
|
simulatePublic: true,
|
|
220
280
|
skipTxValidation: opts.skipTxValidation,
|
|
221
281
|
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
222
|
-
scopes: opts.
|
|
282
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
283
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
284
|
+
overrides: opts.overrides
|
|
223
285
|
});
|
|
286
|
+
const appCallOffset = await this.computeAppCallOffset(opts.from, opts.feeOptions);
|
|
287
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Computes the index where the app's calls begin in the flattened array of calls (0 = entrypoint/root, 1..N = fee
|
|
291
|
+
* calls, N+1 = app).
|
|
292
|
+
* @param from - The sender address, or NO_FROM for the default entrypoint.
|
|
293
|
+
* @param feeOptions - Fee options containing the wallet fee payment method.
|
|
294
|
+
*/ async computeAppCallOffset(from, feeOptions) {
|
|
295
|
+
if (from === NO_FROM) {
|
|
296
|
+
return 0;
|
|
297
|
+
}
|
|
298
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
299
|
+
return (feeExecutionPayload?.calls.length ?? 0) + 1; // +1 for entrypoint
|
|
224
300
|
}
|
|
225
301
|
/**
|
|
226
302
|
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
@@ -230,7 +306,13 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
230
306
|
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
231
307
|
* @returns The merged simulation result.
|
|
232
308
|
*/ async simulateTx(executionPayload, opts) {
|
|
233
|
-
const feeOptions =
|
|
309
|
+
const feeOptions = await this.completeFeeOptions({
|
|
310
|
+
from: opts.from,
|
|
311
|
+
feePayer: executionPayload.feePayer,
|
|
312
|
+
gasSettings: opts.fee?.gasSettings,
|
|
313
|
+
forEstimation: true,
|
|
314
|
+
congestionEstimate: opts.fee?.congestionEstimate
|
|
315
|
+
});
|
|
234
316
|
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
235
317
|
const remainingPayload = {
|
|
236
318
|
...executionPayload,
|
|
@@ -243,38 +325,54 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
243
325
|
try {
|
|
244
326
|
blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
245
327
|
} catch {
|
|
246
|
-
blockHeader = await this.aztecNode.
|
|
328
|
+
blockHeader = (await this.aztecNode.getBlockData('latest')).header;
|
|
247
329
|
}
|
|
248
330
|
const simulationOrigin = opts.from === NO_FROM ? AztecAddress.ZERO : opts.from;
|
|
249
331
|
const [optimizedResults, normalResult] = await Promise.all([
|
|
250
|
-
optimizableCalls.length > 0 ? simulateViaNode(this.aztecNode, optimizableCalls, simulationOrigin, chainInfo, feeOptions.gasSettings, blockHeader, opts.skipFeeEnforcement ?? true, this.getContractName.bind(this)) : Promise.resolve([]),
|
|
332
|
+
optimizableCalls.length > 0 ? simulateViaNode(this.aztecNode, optimizableCalls, simulationOrigin, chainInfo, feeOptions.gasSettings, blockHeader, opts.skipFeeEnforcement ?? true, this.getContractName.bind(this), opts.overrides) : Promise.resolve([]),
|
|
251
333
|
remainingCalls.length > 0 ? this.simulateViaEntrypoint(remainingPayload, {
|
|
252
334
|
from: opts.from,
|
|
253
335
|
feeOptions,
|
|
254
|
-
|
|
336
|
+
additionalScopes: opts.additionalScopes,
|
|
255
337
|
skipTxValidation: opts.skipTxValidation,
|
|
256
|
-
skipFeeEnforcement: opts.skipFeeEnforcement ?? true
|
|
338
|
+
skipFeeEnforcement: opts.skipFeeEnforcement ?? true,
|
|
339
|
+
sendMessagesAs: opts.sendMessagesAs,
|
|
340
|
+
overrides: opts.overrides
|
|
257
341
|
}) : Promise.resolve(null)
|
|
258
342
|
]);
|
|
259
343
|
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
260
344
|
}
|
|
261
345
|
async profileTx(executionPayload, opts) {
|
|
262
|
-
const feeOptions = await this.completeFeeOptions(
|
|
346
|
+
const feeOptions = await this.completeFeeOptions({
|
|
347
|
+
from: opts.from,
|
|
348
|
+
feePayer: executionPayload.feePayer,
|
|
349
|
+
gasSettings: opts.fee?.gasSettings,
|
|
350
|
+
congestionEstimate: opts.fee?.congestionEstimate
|
|
351
|
+
});
|
|
263
352
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
264
353
|
return this.pxe.profileTx(txRequest, {
|
|
265
354
|
profileMode: opts.profileMode,
|
|
266
355
|
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
267
|
-
scopes: this.scopesFrom(opts.from, opts.additionalScopes)
|
|
356
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
357
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs)
|
|
268
358
|
});
|
|
269
359
|
}
|
|
270
360
|
async sendTx(executionPayload, opts) {
|
|
271
|
-
const feeOptions = await this.completeFeeOptions(
|
|
361
|
+
const feeOptions = await this.completeFeeOptions({
|
|
362
|
+
from: opts.from,
|
|
363
|
+
feePayer: executionPayload.feePayer,
|
|
364
|
+
gasSettings: opts.fee?.gasSettings,
|
|
365
|
+
congestionEstimate: opts.fee?.congestionEstimate
|
|
366
|
+
});
|
|
272
367
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
273
|
-
const provenTx = await this.pxe.proveTx(txRequest,
|
|
368
|
+
const provenTx = await this.pxe.proveTx(txRequest, {
|
|
369
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
370
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs)
|
|
371
|
+
});
|
|
274
372
|
const offchainOutput = extractOffchainOutput(provenTx.getOffchainEffects(), provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp);
|
|
275
373
|
const tx = await provenTx.toTx();
|
|
276
374
|
const txHash = tx.getTxHash();
|
|
277
|
-
if (await this.aztecNode.
|
|
375
|
+
if ((await this.aztecNode.getTxReceipt(txHash)).isMined()) {
|
|
278
376
|
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
|
|
279
377
|
}
|
|
280
378
|
this.log.debug(`Sending transaction ${txHash}`);
|
|
@@ -290,10 +388,14 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
290
388
|
};
|
|
291
389
|
}
|
|
292
390
|
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
293
|
-
const
|
|
391
|
+
const callerWaitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
392
|
+
const waitOpts = this.defaultWaitInterval !== undefined && callerWaitOpts?.interval === undefined ? {
|
|
393
|
+
...callerWaitOpts,
|
|
394
|
+
interval: this.defaultWaitInterval
|
|
395
|
+
} : callerWaitOpts;
|
|
294
396
|
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
295
397
|
// Display debug logs from public execution if present (served in test mode only)
|
|
296
|
-
if (receipt.debugLogs?.length) {
|
|
398
|
+
if (receipt.isMined() && receipt.debugLogs?.length) {
|
|
297
399
|
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
298
400
|
}
|
|
299
401
|
return {
|
|
@@ -309,7 +411,11 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
309
411
|
if (!instance) {
|
|
310
412
|
return undefined;
|
|
311
413
|
}
|
|
312
|
-
|
|
414
|
+
// Contract names are class-stable (an upgrade preserves the contract name), so the original class artifact is a
|
|
415
|
+
// sufficient source for the display name without resolving the current class against the node.
|
|
416
|
+
// TODO: if a contract were to be upgraded and its original artifact never registered, then this would fail and we'd
|
|
417
|
+
// want to fallback to the current class.
|
|
418
|
+
const artifact = await this.pxe.getContractArtifact(instance.originalContractClassId);
|
|
313
419
|
return artifact?.name;
|
|
314
420
|
}
|
|
315
421
|
contextualizeError(err, ...context) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Gas, type GasUsed } from '@aztec/stdlib/gas';
|
|
2
|
+
/**
|
|
3
|
+
* Returns suggested total and teardown gas limits for a simulated tx, clamped to the network's per-tx
|
|
4
|
+
* admission limits.
|
|
5
|
+
*
|
|
6
|
+
* The network only admits transactions that declare up to `maxTxGasLimits` per dimension (the
|
|
7
|
+
* node-advertised `txsLimits.gas`). Wallets pass the value read from their own node info, but since node info
|
|
8
|
+
* is remote input it is defensively clamped here to the per-tx protocol maxima so a value above them is never
|
|
9
|
+
* honored. If the simulated usage already exceeds the resulting admission limits the tx can never be included,
|
|
10
|
+
* so this throws a descriptive error instead of returning a limit the node would reject. Otherwise it pads the
|
|
11
|
+
* usage and clamps each dimension to the admission limit.
|
|
12
|
+
* @param gasUsed - The gas actually consumed during simulation.
|
|
13
|
+
* @param maxTxGasLimits - The maximum gas a single tx may declare on this network (the node-advertised `txsLimits.gas`).
|
|
14
|
+
* @param pad - Fraction to pad the suggested gas limits by (as a decimal, e.g. 0.1 for 10%). The effective
|
|
15
|
+
* padding shrinks to zero as usage approaches the network limit, since the network will not admit a higher
|
|
16
|
+
* declared limit regardless of the buffer.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getGasLimits(gasUsed: GasUsed, maxTxGasLimits: Gas, pad?: number): {
|
|
19
|
+
/**
|
|
20
|
+
* Gas limit for the tx, excluding teardown gas
|
|
21
|
+
*/
|
|
22
|
+
gasLimits: Gas;
|
|
23
|
+
/**
|
|
24
|
+
* Gas limit for the teardown phase
|
|
25
|
+
*/
|
|
26
|
+
teardownGasLimits: Gas;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Validates that caller-declared gas limits do not exceed the network's per-tx admission limits, throwing a
|
|
30
|
+
* descriptive error per dimension when they do. The node's inbound validation checks declared
|
|
31
|
+
* `gasSettings.gasLimits`, so we mirror that here to surface the rejection locally before the tx is sent.
|
|
32
|
+
* @param gasLimits - The gas limits the transaction will declare.
|
|
33
|
+
* @param maxTxGasLimits - The maximum gas a single tx may declare on this network (the node-advertised `txsLimits.gas`).
|
|
34
|
+
*/
|
|
35
|
+
export declare function assertGasLimitsWithinNetworkLimits(gasLimits: Gas, maxTxGasLimits: Gas): void;
|
|
36
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2V0X2dhc19saW1pdHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9nZXRfZ2FzX2xpbWl0cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsR0FBRyxFQUFFLEtBQUssT0FBTyxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFFdEQ7Ozs7Ozs7Ozs7Ozs7OztHQWVHO0FBQ0gsd0JBQWdCLFlBQVksQ0FDMUIsT0FBTyxFQUFFLE9BQU8sRUFDaEIsY0FBYyxFQUFFLEdBQUcsRUFDbkIsR0FBRyxTQUFNLEdBQ1I7SUFDRDs7T0FFRztJQUNILFNBQVMsRUFBRSxHQUFHLENBQUM7SUFDZjs7T0FFRztJQUNILGlCQUFpQixFQUFFLEdBQUcsQ0FBQztDQUN4QixDQTZCQTtBQVFEOzs7Ozs7R0FNRztBQUNILHdCQUFnQixrQ0FBa0MsQ0FBQyxTQUFTLEVBQUUsR0FBRyxFQUFFLGNBQWMsRUFBRSxHQUFHLEdBQUcsSUFBSSxDQVc1RiJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get_gas_limits.d.ts","sourceRoot":"","sources":["../../src/base-wallet/get_gas_limits.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,GAAG,EACnB,GAAG,SAAM,GACR;IACD;;OAEG;IACH,SAAS,EAAE,GAAG,CAAC;IACf;;OAEG;IACH,iBAAiB,EAAE,GAAG,CAAC;CACxB,CA6BA;AAQD;;;;;;GAMG;AACH,wBAAgB,kCAAkC,CAAC,SAAS,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,GAAG,IAAI,CAW5F"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { MAX_PROCESSABLE_L2_GAS, MAX_TX_DA_GAS } from '@aztec/constants';
|
|
2
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
3
|
+
/**
|
|
4
|
+
* Returns suggested total and teardown gas limits for a simulated tx, clamped to the network's per-tx
|
|
5
|
+
* admission limits.
|
|
6
|
+
*
|
|
7
|
+
* The network only admits transactions that declare up to `maxTxGasLimits` per dimension (the
|
|
8
|
+
* node-advertised `txsLimits.gas`). Wallets pass the value read from their own node info, but since node info
|
|
9
|
+
* is remote input it is defensively clamped here to the per-tx protocol maxima so a value above them is never
|
|
10
|
+
* honored. If the simulated usage already exceeds the resulting admission limits the tx can never be included,
|
|
11
|
+
* so this throws a descriptive error instead of returning a limit the node would reject. Otherwise it pads the
|
|
12
|
+
* usage and clamps each dimension to the admission limit.
|
|
13
|
+
* @param gasUsed - The gas actually consumed during simulation.
|
|
14
|
+
* @param maxTxGasLimits - The maximum gas a single tx may declare on this network (the node-advertised `txsLimits.gas`).
|
|
15
|
+
* @param pad - Fraction to pad the suggested gas limits by (as a decimal, e.g. 0.1 for 10%). The effective
|
|
16
|
+
* padding shrinks to zero as usage approaches the network limit, since the network will not admit a higher
|
|
17
|
+
* declared limit regardless of the buffer.
|
|
18
|
+
*/ export function getGasLimits(gasUsed, maxTxGasLimits, pad = 0.1) {
|
|
19
|
+
const { totalGas, teardownGas } = gasUsed;
|
|
20
|
+
// `maxTxGasLimits` is the node-advertised admission limit. Node info is remote input, so we defensively
|
|
21
|
+
// clamp to the per-tx protocol maxima so a value above them can never be honored.
|
|
22
|
+
const maxLimits = new Gas(Math.min(maxTxGasLimits.daGas, MAX_TX_DA_GAS), Math.min(maxTxGasLimits.l2Gas, MAX_PROCESSABLE_L2_GAS));
|
|
23
|
+
// The simulated usage must fit within the admission limits, otherwise the tx can never be included.
|
|
24
|
+
if (totalGas.daGas > maxLimits.daGas) {
|
|
25
|
+
throw new Error(`Transaction consumes ${totalGas.daGas} DA gas but the network only admits transactions declaring up to ${maxLimits.daGas} DA gas`);
|
|
26
|
+
}
|
|
27
|
+
if (totalGas.l2Gas > maxLimits.l2Gas) {
|
|
28
|
+
throw new Error(`Transaction consumes ${totalGas.l2Gas} L2 gas but the network only admits transactions declaring up to ${maxLimits.l2Gas} L2 gas`);
|
|
29
|
+
}
|
|
30
|
+
// Pad the limits by the buffer, then cap each dimension at the admission limit so the buffer cannot push a
|
|
31
|
+
// declared limit past what inbound validation accepts. Teardown is part of the total, so clamping it to the
|
|
32
|
+
// admission limit is safe.
|
|
33
|
+
return {
|
|
34
|
+
gasLimits: padGas(totalGas, pad, maxLimits),
|
|
35
|
+
teardownGasLimits: padGas(teardownGas, pad, maxLimits)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Pads each gas dimension, capping it at the network admission limit. */ function padGas(gas, pad, cap) {
|
|
39
|
+
const padded = gas.mul(1 + pad);
|
|
40
|
+
return new Gas(Math.min(padded.daGas, cap.daGas), Math.min(padded.l2Gas, cap.l2Gas));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validates that caller-declared gas limits do not exceed the network's per-tx admission limits, throwing a
|
|
44
|
+
* descriptive error per dimension when they do. The node's inbound validation checks declared
|
|
45
|
+
* `gasSettings.gasLimits`, so we mirror that here to surface the rejection locally before the tx is sent.
|
|
46
|
+
* @param gasLimits - The gas limits the transaction will declare.
|
|
47
|
+
* @param maxTxGasLimits - The maximum gas a single tx may declare on this network (the node-advertised `txsLimits.gas`).
|
|
48
|
+
*/ export function assertGasLimitsWithinNetworkLimits(gasLimits, maxTxGasLimits) {
|
|
49
|
+
if (gasLimits.daGas > maxTxGasLimits.daGas) {
|
|
50
|
+
throw new Error(`Declared DA gas limit (${gasLimits.daGas}) exceeds the maximum this network allows per tx (${maxTxGasLimits.daGas})`);
|
|
51
|
+
}
|
|
52
|
+
if (gasLimits.l2Gas > maxTxGasLimits.l2Gas) {
|
|
53
|
+
throw new Error(`Declared L2 gas limit (${gasLimits.l2Gas}) exceeds the maximum this network allows per tx (${maxTxGasLimits.l2Gas})`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { BaseWallet, type FeeOptions, type SimulateViaEntrypointOptions } from './base_wallet.js';
|
|
1
|
+
export { BaseWallet, type CompleteFeeOptionsConfig, type FeeOptions, type SimulateViaEntrypointOptions, } from './base_wallet.js';
|
|
2
2
|
export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
|
|
3
|
-
|
|
3
|
+
export { getGasLimits, assertGasLimitsWithinNetworkLimits } from './get_gas_limits.js';
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsVUFBVSxFQUNWLEtBQUssd0JBQXdCLEVBQzdCLEtBQUssVUFBVSxFQUNmLEtBQUssNEJBQTRCLEdBQ2xDLE1BQU0sa0JBQWtCLENBQUM7QUFDMUIsT0FBTyxFQUFFLGVBQWUsRUFBRSwyQkFBMkIsRUFBRSxtQ0FBbUMsRUFBRSxNQUFNLFlBQVksQ0FBQztBQUMvRyxPQUFPLEVBQUUsWUFBWSxFQUFFLGtDQUFrQyxFQUFFLE1BQU0scUJBQXFCLENBQUMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EACf,KAAK,4BAA4B,GAClC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,mCAAmC,EAAE,MAAM,YAAY,CAAC;AAC/G,OAAO,EAAE,YAAY,EAAE,kCAAkC,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
|
+
import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
2
3
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
3
4
|
import type { ContractNameResolver } from '@aztec/pxe/client/lazy';
|
|
4
5
|
import { type FunctionCall } from '@aztec/stdlib/abi';
|
|
5
6
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
7
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
7
|
-
import { type BlockHeader, type ExecutionPayload, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
8
|
+
import { type BlockHeader, type ExecutionPayload, type SimulationOverrides, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
8
9
|
/**
|
|
9
10
|
* Splits an execution payload into a leading prefix of public static calls
|
|
10
11
|
* (eligible for direct node simulation) and the remaining calls.
|
|
@@ -32,9 +33,11 @@ export declare function extractOptimizablePublicStaticCalls(payload: ExecutionPa
|
|
|
32
33
|
* @param gasSettings - Gas settings for the transaction.
|
|
33
34
|
* @param blockHeader - Block header to use as anchor.
|
|
34
35
|
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
36
|
+
* @param getContractName - Resolver for contract names (used for debug log display).
|
|
37
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
35
38
|
* @returns Array of TxSimulationResult, one per batch.
|
|
36
39
|
*/
|
|
37
|
-
export declare function simulateViaNode(node: AztecNode, publicStaticCalls: FunctionCall[], from: AztecAddress, chainInfo: ChainInfo, gasSettings: GasSettings, blockHeader: BlockHeader, skipFeeEnforcement: boolean | undefined, getContractName: ContractNameResolver): Promise<TxSimulationResult[]>;
|
|
40
|
+
export declare function simulateViaNode(node: AztecNode, publicStaticCalls: FunctionCall[], from: AztecAddress, chainInfo: ChainInfo, gasSettings: GasSettings, blockHeader: BlockHeader, skipFeeEnforcement: boolean | undefined, getContractName: ContractNameResolver, overrides?: SimulationOverrides): Promise<TxSimulationResult[]>;
|
|
38
41
|
/**
|
|
39
42
|
* Merges simulation results from the optimized (public static) and normal paths.
|
|
40
43
|
* Since optimized calls are always a leading prefix, return values are simply
|
|
@@ -45,5 +48,5 @@ export declare function simulateViaNode(node: AztecNode, publicStaticCalls: Func
|
|
|
45
48
|
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
46
49
|
* @returns A single TxSimulationResult with return values in original call order.
|
|
47
50
|
*/
|
|
48
|
-
export declare function buildMergedSimulationResult(optimizedResults: TxSimulationResult[], normalResult:
|
|
49
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
51
|
+
export declare function buildMergedSimulationResult(optimizedResults: TxSimulationResult[], normalResult: TxSimulationResultWithAppOffset | null): TxSimulationResultWithAppOffset;
|
|
52
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUN0RCxPQUFPLEVBQUUsK0JBQStCLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUV6RSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUkvRCxPQUFPLEtBQUssRUFBRSxvQkFBb0IsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBR25FLE9BQU8sRUFBRSxLQUFLLFlBQVksRUFBb0IsTUFBTSxtQkFBbUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQVFyRCxPQUFPLEVBQ0wsS0FBSyxXQUFXLEVBQ2hCLEtBQUssZ0JBQWdCLEVBS3JCLEtBQUssbUJBQW1CLEVBR3hCLGtCQUFrQixFQUNuQixNQUFNLGtCQUFrQixDQUFDO0FBRTFCOzs7Ozs7Ozs7R0FTRztBQUNILHdCQUFnQixtQ0FBbUMsQ0FBQyxPQUFPLEVBQUUsZ0JBQWdCLEdBQUc7SUFDOUUsdUVBQXVFO0lBQ3ZFLGdCQUFnQixFQUFFLFlBQVksRUFBRSxDQUFDO0lBQ2pDLDJCQUEyQjtJQUMzQixjQUFjLEVBQUUsWUFBWSxFQUFFLENBQUM7Q0FDaEMsQ0FPQTtBQTBHRDs7Ozs7Ozs7Ozs7Ozs7R0FjRztBQUNILHdCQUFzQixlQUFlLENBQ25DLElBQUksRUFBRSxTQUFTLEVBQ2YsaUJBQWlCLEVBQUUsWUFBWSxFQUFFLEVBQ2pDLElBQUksRUFBRSxZQUFZLEVBQ2xCLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLFdBQVcsRUFBRSxXQUFXLEVBQ3hCLFdBQVcsRUFBRSxXQUFXLEVBQ3hCLGtCQUFrQixxQkFBZ0IsRUFDbEMsZUFBZSxFQUFFLG9CQUFvQixFQUNyQyxTQUFTLENBQUMsRUFBRSxtQkFBbUIsR0FDOUIsT0FBTyxDQUFDLGtCQUFrQixFQUFFLENBQUMsQ0F5Qi9CO0FBRUQ7Ozs7Ozs7OztHQVNHO0FBQ0gsd0JBQWdCLDJCQUEyQixDQUN6QyxnQkFBZ0IsRUFBRSxrQkFBa0IsRUFBRSxFQUN0QyxZQUFZLEVBQUUsK0JBQStCLEdBQUcsSUFBSSxHQUNuRCwrQkFBK0IsQ0FxQmpDIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/base-wallet/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/base-wallet/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AAEzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAI/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAGnE,OAAO,EAAE,KAAK,YAAY,EAAoB,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQrD,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EAKrB,KAAK,mBAAmB,EAGxB,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;GASG;AACH,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,gBAAgB,GAAG;IAC9E,uEAAuE;IACvE,gBAAgB,EAAE,YAAY,EAAE,CAAC;IACjC,2BAA2B;IAC3B,cAAc,EAAE,YAAY,EAAE,CAAC;CAChC,CAOA;AA0GD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,SAAS,EACf,iBAAiB,EAAE,YAAY,EAAE,EACjC,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,kBAAkB,qBAAgB,EAClC,eAAe,EAAE,oBAAoB,EACrC,SAAS,CAAC,EAAE,mBAAmB,GAC9B,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAyB/B;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CACzC,gBAAgB,EAAE,kBAAkB,EAAE,EACtC,YAAY,EAAE,+BAA+B,GAAG,IAAI,GACnD,+BAA+B,CAqBjC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
1
2
|
import { MAX_ENQUEUED_CALLS_PER_CALL } from '@aztec/constants';
|
|
2
3
|
import { makeTuple } from '@aztec/foundation/array';
|
|
3
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
@@ -34,8 +35,10 @@ import { HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx, T
|
|
|
34
35
|
* @param gasSettings - Gas settings for the transaction.
|
|
35
36
|
* @param blockHeader - Block header to use as anchor.
|
|
36
37
|
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
38
|
+
* @param getContractName - Resolver for contract names (used for debug log display).
|
|
39
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
37
40
|
* @returns TxSimulationResult with public return values.
|
|
38
|
-
*/ async function simulateBatchViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement, getContractName) {
|
|
41
|
+
*/ async function simulateBatchViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement, getContractName, overrides) {
|
|
39
42
|
const txContext = new TxContext(chainInfo.chainId, chainInfo.version, gasSettings);
|
|
40
43
|
const publicFunctionCalldata = [];
|
|
41
44
|
for (const call of publicStaticCalls){
|
|
@@ -74,7 +77,7 @@ import { HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx, T
|
|
|
74
77
|
contractClassLogFields: [],
|
|
75
78
|
publicFunctionCalldata: publicFunctionCalldata
|
|
76
79
|
});
|
|
77
|
-
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement);
|
|
80
|
+
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement, overrides);
|
|
78
81
|
if (publicOutput.revertReason) {
|
|
79
82
|
throw publicOutput.revertReason;
|
|
80
83
|
}
|
|
@@ -93,15 +96,17 @@ import { HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx, T
|
|
|
93
96
|
* @param gasSettings - Gas settings for the transaction.
|
|
94
97
|
* @param blockHeader - Block header to use as anchor.
|
|
95
98
|
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
99
|
+
* @param getContractName - Resolver for contract names (used for debug log display).
|
|
100
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
96
101
|
* @returns Array of TxSimulationResult, one per batch.
|
|
97
|
-
*/ export async function simulateViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement = true, getContractName) {
|
|
102
|
+
*/ export async function simulateViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement = true, getContractName, overrides) {
|
|
98
103
|
const batches = [];
|
|
99
104
|
for(let i = 0; i < publicStaticCalls.length; i += MAX_ENQUEUED_CALLS_PER_CALL){
|
|
100
105
|
batches.push(publicStaticCalls.slice(i, i + MAX_ENQUEUED_CALLS_PER_CALL));
|
|
101
106
|
}
|
|
102
107
|
const results = [];
|
|
103
108
|
for (const batch of batches){
|
|
104
|
-
const result = await simulateBatchViaNode(node, batch, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement, getContractName);
|
|
109
|
+
const result = await simulateBatchViaNode(node, batch, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement, getContractName, overrides);
|
|
105
110
|
results.push(result);
|
|
106
111
|
}
|
|
107
112
|
return results;
|
|
@@ -127,5 +132,6 @@ import { HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx, T
|
|
|
127
132
|
...baseResult.publicOutput,
|
|
128
133
|
publicReturnValues: allReturnValues
|
|
129
134
|
} : undefined;
|
|
130
|
-
|
|
135
|
+
const merged = new TxSimulationResult(baseResult.privateExecutionResult, baseResult.publicInputs, mergedPublicOutput, normalResult?.stats);
|
|
136
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(merged, normalResult?.appCallOffset ?? 0);
|
|
131
137
|
}
|