@aztec/wallet-sdk 0.0.1-commit.a89ec08 → 0.0.1-commit.aa0c64f
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 +44 -9
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +157 -60
- 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 +2 -1
- 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 +5 -3
- package/dest/base-wallet/utils.d.ts.map +1 -1
- package/dest/base-wallet/utils.js +8 -4
- 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 +169 -64
- package/src/base-wallet/get_gas_limits.ts +88 -0
- package/src/base-wallet/index.ts +1 -0
- package/src/base-wallet/utils.ts +9 -1
- 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
|
@@ -9,12 +9,14 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
9
9
|
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
10
10
|
import { decodeFromAbi } from '@aztec/stdlib/abi';
|
|
11
11
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
12
|
-
import { computePartialAddress
|
|
12
|
+
import { computePartialAddress } from '@aztec/stdlib/contract';
|
|
13
13
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
14
|
-
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
14
|
+
import { Gas, GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
15
15
|
import { computeSiloedPrivateInitializationNullifier, computeSiloedPublicInitializationNullifier } from '@aztec/stdlib/hash';
|
|
16
|
+
import { deriveKeys, deriveKeysFromMasterSecretKeys } from '@aztec/stdlib/keys';
|
|
16
17
|
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
17
18
|
import { inspect } from 'util';
|
|
19
|
+
import { assertGasLimitsWithinNetworkLimits } from './get_gas_limits.js';
|
|
18
20
|
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
19
21
|
/**
|
|
20
22
|
* A base class for Wallet implementations
|
|
@@ -24,6 +26,9 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
24
26
|
log;
|
|
25
27
|
minFeePadding;
|
|
26
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;
|
|
27
32
|
// A wallet is instantiated for a particular chain, so chain info never changes during its lifetime.
|
|
28
33
|
// We cache it here because getChainInfo is called frequently (every tx simulation, send, auth wit, etc.).
|
|
29
34
|
nodeInfoPromise;
|
|
@@ -35,15 +40,32 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
35
40
|
this.minFeePadding = 0.5;
|
|
36
41
|
this.cancellableTransactions = false;
|
|
37
42
|
}
|
|
38
|
-
scopesFrom(from, additionalScopes
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
scopesFrom(from, additionalScopes, sendMessagesAs) {
|
|
44
|
+
// The sendMessagesAs account must be in scope so that its tagging secrets can be accessed.
|
|
45
|
+
const tagSenderScopes = sendMessagesAs ? [
|
|
46
|
+
sendMessagesAs
|
|
47
|
+
] : [];
|
|
48
|
+
const baseScopes = from === NO_FROM ? [] : [
|
|
49
|
+
from
|
|
50
|
+
];
|
|
51
|
+
const allScopes = [
|
|
52
|
+
...baseScopes,
|
|
53
|
+
...additionalScopes,
|
|
54
|
+
...tagSenderScopes
|
|
42
55
|
];
|
|
43
56
|
const scopeSet = new Set(allScopes.map((address)=>address.toString()));
|
|
44
57
|
return [
|
|
45
58
|
...scopeSet
|
|
46
|
-
].map(AztecAddress.
|
|
59
|
+
].map(AztecAddress.fromStringUnsafe);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Picks the sender address PXE should tag private messages with. Returns `undefined` when there is no signing
|
|
63
|
+
* account (`from === NO_FROM`) and no explicit override; in that case any private log emitted by the tx using
|
|
64
|
+
* the wallet-supplied default sender will fail the "Sender for tags is not set" assertion.
|
|
65
|
+
* @param from - Tx sender, or `NO_FROM`.
|
|
66
|
+
* @param sendMessagesAs - Explicit override.
|
|
67
|
+
*/ senderForTagsFrom(from, sendMessagesAs) {
|
|
68
|
+
return sendMessagesAs ?? (from === NO_FROM ? undefined : from);
|
|
47
69
|
}
|
|
48
70
|
/**
|
|
49
71
|
* Returns the list of aliased contacts associated with the wallet.
|
|
@@ -52,22 +74,44 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
52
74
|
* - Contacts: more general concept akin to a phone's contact list.
|
|
53
75
|
* @returns The aliased collection of AztecAddresses that form this wallet's address book
|
|
54
76
|
*/ async getAddressBook() {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
77
|
+
const sources = await this.pxe.getTaggingSecretSources({
|
|
78
|
+
kind: 'address-derived'
|
|
79
|
+
});
|
|
80
|
+
return sources.map((source)=>({
|
|
81
|
+
item: source.sender,
|
|
58
82
|
alias: ''
|
|
59
83
|
}));
|
|
60
84
|
}
|
|
61
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Fetches and caches the node info for the wallet's lifetime, since a wallet talks to a single network and
|
|
87
|
+
* node info never changes. A rejected fetch clears the cache so the next call retries instead of replaying
|
|
88
|
+
* the cached rejection forever — important because the gas-limit fill-in and validation (run on every send)
|
|
89
|
+
* depend on it.
|
|
90
|
+
*/ getNodeInfo() {
|
|
62
91
|
if (!this.nodeInfoPromise) {
|
|
63
|
-
this.nodeInfoPromise = this.aztecNode.getNodeInfo()
|
|
92
|
+
this.nodeInfoPromise = this.aztecNode.getNodeInfo().catch((err)=>{
|
|
93
|
+
this.nodeInfoPromise = undefined;
|
|
94
|
+
throw err;
|
|
95
|
+
});
|
|
64
96
|
}
|
|
65
|
-
|
|
97
|
+
return this.nodeInfoPromise;
|
|
98
|
+
}
|
|
99
|
+
async getChainInfo() {
|
|
100
|
+
const { l1ChainId, rollupVersion } = await this.getNodeInfo();
|
|
66
101
|
return {
|
|
67
102
|
chainId: new Fr(l1ChainId),
|
|
68
103
|
version: new Fr(rollupVersion)
|
|
69
104
|
};
|
|
70
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Returns the maximum gas limits a single transaction may declare on this wallet's network (the
|
|
108
|
+
* node-advertised `txsLimits.gas`). Internal helper used to fill in default gas limits when sending a
|
|
109
|
+
* transaction without explicit limits, and to validate caller-provided limits before sending. Backed by
|
|
110
|
+
* the cached node info, since a wallet talks to a single network.
|
|
111
|
+
*/ async getMaxTxGasLimits() {
|
|
112
|
+
const { txsLimits } = await this.getNodeInfo();
|
|
113
|
+
return new Gas(txsLimits.gas.daGas, txsLimits.gas.l2Gas);
|
|
114
|
+
}
|
|
71
115
|
async createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions) {
|
|
72
116
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
73
117
|
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
@@ -132,8 +176,8 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
132
176
|
* Completes partial user-provided fee options with wallet defaults.
|
|
133
177
|
* @param config - Fee completion config.
|
|
134
178
|
*/ async completeFeeOptions(config) {
|
|
135
|
-
const { from, feePayer, gasSettings, forEstimation } = config;
|
|
136
|
-
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.
|
|
179
|
+
const { from, feePayer, gasSettings, forEstimation, congestionEstimate } = config;
|
|
180
|
+
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.getMinFees(congestionEstimate)).mul(1 + this.minFeePadding);
|
|
137
181
|
let accountFeePaymentMethodOptions;
|
|
138
182
|
// If from is an address, we need to determine the appropriate fee payment method options for the
|
|
139
183
|
// account contract entrypoint to use
|
|
@@ -155,8 +199,25 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
155
199
|
maxPriorityFeesPerGas: gasSettings?.maxPriorityFeesPerGas ?? GasFees.empty()
|
|
156
200
|
};
|
|
157
201
|
// When estimating gas (simulation), use high limits so the simulation doesn't run out of gas.
|
|
158
|
-
// When sending for real
|
|
159
|
-
|
|
202
|
+
// When sending for real without explicit limits, declare the most a single tx may use on this network
|
|
203
|
+
// (the node's per-tx admission limit), so the proposer does not skip the tx for over-declaring gas.
|
|
204
|
+
let fullGasSettings;
|
|
205
|
+
if (forEstimation) {
|
|
206
|
+
// Estimation deliberately uses very high internal limits and skips tx validation, so we do not
|
|
207
|
+
// validate against the network admission limit here.
|
|
208
|
+
fullGasSettings = GasSettings.forEstimation(gasSettingsOverrides);
|
|
209
|
+
} else {
|
|
210
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
211
|
+
// If the caller declared explicit gas limits, reject them up front when they exceed the network's
|
|
212
|
+
// per-tx admission limit (mirroring the node's GasLimitsValidator). Otherwise fill in the limit.
|
|
213
|
+
if (gasSettingsOverrides.gasLimits) {
|
|
214
|
+
assertGasLimitsWithinNetworkLimits(gasSettingsOverrides.gasLimits, maxTxGasLimits);
|
|
215
|
+
}
|
|
216
|
+
fullGasSettings = GasSettings.fallback({
|
|
217
|
+
...gasSettingsOverrides,
|
|
218
|
+
gasLimits: gasSettingsOverrides.gasLimits ?? maxTxGasLimits
|
|
219
|
+
});
|
|
220
|
+
}
|
|
160
221
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
161
222
|
return {
|
|
162
223
|
gasSettings: fullGasSettings,
|
|
@@ -164,40 +225,57 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
164
225
|
accountFeePaymentMethodOptions
|
|
165
226
|
};
|
|
166
227
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (
|
|
175
|
-
|
|
176
|
-
if (!thisContractClass.id.equals(existingInstance.currentContractClassId)) {
|
|
177
|
-
// wallet holds an outdated version of this contract
|
|
178
|
-
await this.pxe.updateContract(instance.address, artifact);
|
|
179
|
-
instance.currentContractClassId = thisContractClass.id;
|
|
180
|
-
}
|
|
228
|
+
/**
|
|
229
|
+
* Returns the worst-case min fee across predicted future slots.
|
|
230
|
+
* Falls back to getCurrentMinFees if the node doesn't support getPredictedMinFees.
|
|
231
|
+
* @param estimate - The mana usage estimate to use for fee prediction. Defaults to Limit for conservative estimation.
|
|
232
|
+
*/ async getMinFees(estimate = ManaUsageEstimate.Limit) {
|
|
233
|
+
try {
|
|
234
|
+
const predicted = await this.aztecNode.getPredictedMinFees(estimate);
|
|
235
|
+
if (predicted.length === 0) {
|
|
236
|
+
return this.aztecNode.getCurrentMinFees();
|
|
181
237
|
}
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
//
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if (!artifact) {
|
|
189
|
-
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()}`);
|
|
190
|
-
}
|
|
238
|
+
return predicted.reduce((worst, fees)=>fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst);
|
|
239
|
+
} catch (err) {
|
|
240
|
+
// Fallback for old nodes that don't support getPredictedMinFees.
|
|
241
|
+
// Only fall back on method-not-found errors (JSON-RPC code -32601); rethrow others.
|
|
242
|
+
if (err?.cause?.code === -32601 || err?.message?.includes('Method not found')) {
|
|
243
|
+
return this.aztecNode.getCurrentMinFees();
|
|
191
244
|
}
|
|
192
|
-
|
|
193
|
-
artifact,
|
|
194
|
-
instance
|
|
195
|
-
});
|
|
245
|
+
throw err;
|
|
196
246
|
}
|
|
197
|
-
|
|
198
|
-
|
|
247
|
+
}
|
|
248
|
+
async registerSender(address, _alias = '') {
|
|
249
|
+
await this.pxe.registerTaggingSecretSource({
|
|
250
|
+
kind: 'address-derived',
|
|
251
|
+
sender: address
|
|
252
|
+
});
|
|
253
|
+
return address;
|
|
254
|
+
}
|
|
255
|
+
async registerContract(instance, artifact, secretKeyOrKeys) {
|
|
256
|
+
// Classes and instances are registered independently: register the artifact (if provided) then the instance.
|
|
257
|
+
// Neither call validates that the artifact matches the class the instance runs, a missing artifact only surfaces
|
|
258
|
+
// when the contract is later simulated.
|
|
259
|
+
if (artifact) {
|
|
260
|
+
await this.pxe.registerContractClass(artifact);
|
|
261
|
+
}
|
|
262
|
+
const contractAddress = await this.pxe.registerContract(instance);
|
|
263
|
+
if (secretKeyOrKeys) {
|
|
264
|
+
// PXE never receives the account seed (from which the message-signing/fallback secret keys could be re-derived):
|
|
265
|
+
// the wallet derives the keys here. Of these, PXE only reads and stores the four privacy secret keys and the
|
|
266
|
+
// message-signing and fallback *public* keys — it never touches the message-signing or fallback secret keys.
|
|
267
|
+
//
|
|
268
|
+
// Since PXE recomputes the address from those keys, we assert it matches the instance's address: a mismatch means
|
|
269
|
+
// the provided keys don't correspond to this account.
|
|
270
|
+
const derivedKeys = secretKeyOrKeys instanceof Fr ? await deriveKeys(secretKeyOrKeys) : await deriveKeysFromMasterSecretKeys(secretKeyOrKeys);
|
|
271
|
+
const { address } = await this.pxe.registerAccount(derivedKeys, await computePartialAddress(instance));
|
|
272
|
+
if (!address.equals(contractAddress)) {
|
|
273
|
+
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.`);
|
|
274
|
+
}
|
|
199
275
|
}
|
|
200
|
-
|
|
276
|
+
}
|
|
277
|
+
registerContractClass(artifact) {
|
|
278
|
+
return this.pxe.registerContractClass(artifact);
|
|
201
279
|
}
|
|
202
280
|
/**
|
|
203
281
|
* Simulates calls through the standard PXE path (account entrypoint).
|
|
@@ -209,7 +287,9 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
209
287
|
simulatePublic: true,
|
|
210
288
|
skipTxValidation: opts.skipTxValidation,
|
|
211
289
|
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
212
|
-
scopes: this.scopesFrom(opts.from, opts.additionalScopes)
|
|
290
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes ?? [], opts.sendMessagesAs),
|
|
291
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
292
|
+
overrides: opts.overrides
|
|
213
293
|
});
|
|
214
294
|
const appCallOffset = await this.computeAppCallOffset(opts.from, opts.feeOptions);
|
|
215
295
|
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
@@ -238,7 +318,8 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
238
318
|
from: opts.from,
|
|
239
319
|
feePayer: executionPayload.feePayer,
|
|
240
320
|
gasSettings: opts.fee?.gasSettings,
|
|
241
|
-
forEstimation: true
|
|
321
|
+
forEstimation: true,
|
|
322
|
+
congestionEstimate: opts.fee?.congestionEstimate
|
|
242
323
|
});
|
|
243
324
|
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
244
325
|
const remainingPayload = {
|
|
@@ -252,17 +333,19 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
252
333
|
try {
|
|
253
334
|
blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
254
335
|
} catch {
|
|
255
|
-
blockHeader = await this.aztecNode.
|
|
336
|
+
blockHeader = (await this.aztecNode.getBlockData('latest')).header;
|
|
256
337
|
}
|
|
257
338
|
const simulationOrigin = opts.from === NO_FROM ? AztecAddress.ZERO : opts.from;
|
|
258
339
|
const [optimizedResults, normalResult] = await Promise.all([
|
|
259
|
-
optimizableCalls.length > 0 ? simulateViaNode(this.aztecNode, optimizableCalls, simulationOrigin, chainInfo, feeOptions.gasSettings, blockHeader, opts.skipFeeEnforcement ?? true, this.getContractName.bind(this)) : Promise.resolve([]),
|
|
340
|
+
optimizableCalls.length > 0 ? simulateViaNode(this.aztecNode, optimizableCalls, simulationOrigin, chainInfo, feeOptions.gasSettings, blockHeader, opts.skipFeeEnforcement ?? true, this.getContractName.bind(this), opts.overrides) : Promise.resolve([]),
|
|
260
341
|
remainingCalls.length > 0 ? this.simulateViaEntrypoint(remainingPayload, {
|
|
261
342
|
from: opts.from,
|
|
262
343
|
feeOptions,
|
|
263
344
|
additionalScopes: opts.additionalScopes,
|
|
264
345
|
skipTxValidation: opts.skipTxValidation,
|
|
265
|
-
skipFeeEnforcement: opts.skipFeeEnforcement ?? true
|
|
346
|
+
skipFeeEnforcement: opts.skipFeeEnforcement ?? true,
|
|
347
|
+
sendMessagesAs: opts.sendMessagesAs,
|
|
348
|
+
overrides: opts.overrides
|
|
266
349
|
}) : Promise.resolve(null)
|
|
267
350
|
]);
|
|
268
351
|
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
@@ -271,27 +354,33 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
271
354
|
const feeOptions = await this.completeFeeOptions({
|
|
272
355
|
from: opts.from,
|
|
273
356
|
feePayer: executionPayload.feePayer,
|
|
274
|
-
gasSettings: opts.fee?.gasSettings
|
|
357
|
+
gasSettings: opts.fee?.gasSettings,
|
|
358
|
+
congestionEstimate: opts.fee?.congestionEstimate
|
|
275
359
|
});
|
|
276
360
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
277
361
|
return this.pxe.profileTx(txRequest, {
|
|
278
362
|
profileMode: opts.profileMode,
|
|
279
363
|
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
280
|
-
scopes: this.scopesFrom(opts.from, opts.additionalScopes)
|
|
364
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes ?? [], opts.sendMessagesAs),
|
|
365
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs)
|
|
281
366
|
});
|
|
282
367
|
}
|
|
283
368
|
async sendTx(executionPayload, opts) {
|
|
284
369
|
const feeOptions = await this.completeFeeOptions({
|
|
285
370
|
from: opts.from,
|
|
286
371
|
feePayer: executionPayload.feePayer,
|
|
287
|
-
gasSettings: opts.fee?.gasSettings
|
|
372
|
+
gasSettings: opts.fee?.gasSettings,
|
|
373
|
+
congestionEstimate: opts.fee?.congestionEstimate
|
|
288
374
|
});
|
|
289
375
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
290
|
-
const provenTx = await this.pxe.proveTx(txRequest,
|
|
376
|
+
const provenTx = await this.pxe.proveTx(txRequest, {
|
|
377
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes ?? [], opts.sendMessagesAs),
|
|
378
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs)
|
|
379
|
+
});
|
|
291
380
|
const offchainOutput = extractOffchainOutput(provenTx.getOffchainEffects(), provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp);
|
|
292
381
|
const tx = await provenTx.toTx();
|
|
293
382
|
const txHash = tx.getTxHash();
|
|
294
|
-
if (await this.aztecNode.
|
|
383
|
+
if ((await this.aztecNode.getTxReceipt(txHash)).isMined()) {
|
|
295
384
|
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
|
|
296
385
|
}
|
|
297
386
|
this.log.debug(`Sending transaction ${txHash}`);
|
|
@@ -307,10 +396,14 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
307
396
|
};
|
|
308
397
|
}
|
|
309
398
|
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
310
|
-
const
|
|
399
|
+
const callerWaitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
400
|
+
const waitOpts = this.defaultWaitInterval !== undefined && callerWaitOpts?.interval === undefined ? {
|
|
401
|
+
...callerWaitOpts,
|
|
402
|
+
interval: this.defaultWaitInterval
|
|
403
|
+
} : callerWaitOpts;
|
|
311
404
|
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
312
405
|
// Display debug logs from public execution if present (served in test mode only)
|
|
313
|
-
if (receipt.debugLogs?.length) {
|
|
406
|
+
if (receipt.isMined() && receipt.debugLogs?.length) {
|
|
314
407
|
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
315
408
|
}
|
|
316
409
|
return {
|
|
@@ -326,7 +419,11 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
326
419
|
if (!instance) {
|
|
327
420
|
return undefined;
|
|
328
421
|
}
|
|
329
|
-
|
|
422
|
+
// Contract names are class-stable (an upgrade preserves the contract name), so the original class artifact is a
|
|
423
|
+
// sufficient source for the display name without resolving the current class against the node.
|
|
424
|
+
// TODO: if a contract were to be upgraded and its original artifact never registered, then this would fail and we'd
|
|
425
|
+
// want to fallback to the current class.
|
|
426
|
+
const artifact = await this.pxe.getContractArtifact(instance.originalContractClassId);
|
|
330
427
|
return artifact?.name;
|
|
331
428
|
}
|
|
332
429
|
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
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,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"}
|
|
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"}
|
|
@@ -5,7 +5,7 @@ import type { ContractNameResolver } from '@aztec/pxe/client/lazy';
|
|
|
5
5
|
import { type FunctionCall } from '@aztec/stdlib/abi';
|
|
6
6
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
7
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
8
|
-
import { type BlockHeader, type ExecutionPayload, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
8
|
+
import { type BlockHeader, type ExecutionPayload, type SimulationOverrides, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
9
9
|
/**
|
|
10
10
|
* Splits an execution payload into a leading prefix of public static calls
|
|
11
11
|
* (eligible for direct node simulation) and the remaining calls.
|
|
@@ -33,9 +33,11 @@ export declare function extractOptimizablePublicStaticCalls(payload: ExecutionPa
|
|
|
33
33
|
* @param gasSettings - Gas settings for the transaction.
|
|
34
34
|
* @param blockHeader - Block header to use as anchor.
|
|
35
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.
|
|
36
38
|
* @returns Array of TxSimulationResult, one per batch.
|
|
37
39
|
*/
|
|
38
|
-
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[]>;
|
|
39
41
|
/**
|
|
40
42
|
* Merges simulation results from the optimized (public static) and normal paths.
|
|
41
43
|
* Since optimized calls are always a leading prefix, return values are simply
|
|
@@ -47,4 +49,4 @@ export declare function simulateViaNode(node: AztecNode, publicStaticCalls: Func
|
|
|
47
49
|
* @returns A single TxSimulationResult with return values in original call order.
|
|
48
50
|
*/
|
|
49
51
|
export declare function buildMergedSimulationResult(optimizedResults: TxSimulationResult[], normalResult: TxSimulationResultWithAppOffset | null): TxSimulationResultWithAppOffset;
|
|
50
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
52
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUN0RCxPQUFPLEVBQUUsK0JBQStCLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUV6RSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUkvRCxPQUFPLEtBQUssRUFBRSxvQkFBb0IsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBR25FLE9BQU8sRUFBRSxLQUFLLFlBQVksRUFBb0IsTUFBTSxtQkFBbUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQVFyRCxPQUFPLEVBQ0wsS0FBSyxXQUFXLEVBQ2hCLEtBQUssZ0JBQWdCLEVBS3JCLEtBQUssbUJBQW1CLEVBR3hCLGtCQUFrQixFQUNuQixNQUFNLGtCQUFrQixDQUFDO0FBRTFCOzs7Ozs7Ozs7R0FTRztBQUNILHdCQUFnQixtQ0FBbUMsQ0FBQyxPQUFPLEVBQUUsZ0JBQWdCLEdBQUc7SUFDOUUsdUVBQXVFO0lBQ3ZFLGdCQUFnQixFQUFFLFlBQVksRUFBRSxDQUFDO0lBQ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gBAAgB,EAAE,kBAAkB,EAAE,EACtC,YAAY,EAAE,+BAA+B,GAAG,IAAI,GACnD,+BAA+B,CAqBjC"}
|
|
@@ -35,8 +35,10 @@ import { HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx, T
|
|
|
35
35
|
* @param gasSettings - Gas settings for the transaction.
|
|
36
36
|
* @param blockHeader - Block header to use as anchor.
|
|
37
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.
|
|
38
40
|
* @returns TxSimulationResult with public return values.
|
|
39
|
-
*/ async function simulateBatchViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement, getContractName) {
|
|
41
|
+
*/ async function simulateBatchViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement, getContractName, overrides) {
|
|
40
42
|
const txContext = new TxContext(chainInfo.chainId, chainInfo.version, gasSettings);
|
|
41
43
|
const publicFunctionCalldata = [];
|
|
42
44
|
for (const call of publicStaticCalls){
|
|
@@ -75,7 +77,7 @@ import { HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx, T
|
|
|
75
77
|
contractClassLogFields: [],
|
|
76
78
|
publicFunctionCalldata: publicFunctionCalldata
|
|
77
79
|
});
|
|
78
|
-
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement);
|
|
80
|
+
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement, overrides);
|
|
79
81
|
if (publicOutput.revertReason) {
|
|
80
82
|
throw publicOutput.revertReason;
|
|
81
83
|
}
|
|
@@ -94,15 +96,17 @@ import { HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx, T
|
|
|
94
96
|
* @param gasSettings - Gas settings for the transaction.
|
|
95
97
|
* @param blockHeader - Block header to use as anchor.
|
|
96
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.
|
|
97
101
|
* @returns Array of TxSimulationResult, one per batch.
|
|
98
|
-
*/ 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) {
|
|
99
103
|
const batches = [];
|
|
100
104
|
for(let i = 0; i < publicStaticCalls.length; i += MAX_ENQUEUED_CALLS_PER_CALL){
|
|
101
105
|
batches.push(publicStaticCalls.slice(i, i + MAX_ENQUEUED_CALLS_PER_CALL));
|
|
102
106
|
}
|
|
103
107
|
const results = [];
|
|
104
108
|
for (const batch of batches){
|
|
105
|
-
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);
|
|
106
110
|
results.push(result);
|
|
107
111
|
}
|
|
108
112
|
return results;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ChainInfo } from '@aztec/aztec.js/account';
|
|
2
2
|
import { type EncryptedPayload } from '../../crypto.js';
|
|
3
|
-
import { type DiscoveryRequest, type KeyExchangeRequest, type WalletInfo, type WalletMessage, type WalletResponse } from '../../types.js';
|
|
3
|
+
import { type DiscoveryRequest, type KeyExchangeRequest, type WalletInfo, type WalletMessage, type WalletResponse, type WalletSdkLogger } from '../../types.js';
|
|
4
4
|
import { type BackgroundMessage, type MessageSender } from './internal_message_types.js';
|
|
5
5
|
/**
|
|
6
6
|
* Status of a pending discovery request.
|
|
@@ -98,6 +98,8 @@ export interface BackgroundConnectionConfig {
|
|
|
98
98
|
walletVersion: string;
|
|
99
99
|
/** Optional wallet icon URL. */
|
|
100
100
|
walletIcon?: string;
|
|
101
|
+
/** Logger used for diagnostics. */
|
|
102
|
+
logger: WalletSdkLogger;
|
|
101
103
|
}
|
|
102
104
|
/**
|
|
103
105
|
* Handles wallet session flow in the extension background script.
|
|
@@ -115,6 +117,7 @@ export interface BackgroundConnectionConfig {
|
|
|
115
117
|
* walletId: 'my-wallet',
|
|
116
118
|
* walletName: 'My Wallet',
|
|
117
119
|
* walletVersion: '1.0.0',
|
|
120
|
+
* logger: console,
|
|
118
121
|
* },
|
|
119
122
|
* {
|
|
120
123
|
* sendToTab: (tabId, message) => browser.tabs.sendMessage(tabId, message),
|
|
@@ -136,9 +139,16 @@ export declare class BackgroundConnectionHandler {
|
|
|
136
139
|
private callbacks;
|
|
137
140
|
private pendingDiscoveries;
|
|
138
141
|
private activeSessions;
|
|
142
|
+
private log;
|
|
139
143
|
constructor(config: BackgroundConnectionConfig, transport: BackgroundTransport, callbacks?: BackgroundConnectionCallbacks);
|
|
140
144
|
initialize(): void;
|
|
141
145
|
private handleMessage;
|
|
146
|
+
/**
|
|
147
|
+
* Reply to a dApp PING with a PONG. Used as a liveness probe so the dApp can
|
|
148
|
+
* tell the difference between a slow request and a dead extension.
|
|
149
|
+
* @param sessionId - The session that sent the PING.
|
|
150
|
+
*/
|
|
151
|
+
private handlePing;
|
|
142
152
|
getWalletInfo(): WalletInfo;
|
|
143
153
|
handleDiscoveryRequest(request: DiscoveryRequest, tabId: number, origin: string): void;
|
|
144
154
|
approveDiscovery(requestId: string): boolean;
|
|
@@ -155,4 +165,4 @@ export declare class BackgroundConnectionHandler {
|
|
|
155
165
|
getSession(sessionId: string): ActiveSession | undefined;
|
|
156
166
|
getPendingDiscovery(requestId: string): PendingDiscovery | undefined;
|
|
157
167
|
}
|
|
158
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
168
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFja2dyb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