@aztec/wallet-sdk 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0
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 +321 -299
- package/dest/base-wallet/base_wallet.d.ts +129 -44
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +388 -110
- 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 +4 -2
- package/dest/base-wallet/index.d.ts.map +1 -1
- package/dest/base-wallet/index.js +2 -0
- package/dest/base-wallet/utils.d.ts +52 -0
- package/dest/base-wallet/utils.d.ts.map +1 -0
- package/dest/base-wallet/utils.js +137 -0
- package/dest/crypto.d.ts +230 -0
- package/dest/crypto.d.ts.map +1 -0
- package/dest/crypto.js +482 -0
- package/dest/emoji_alphabet.d.ts +35 -0
- package/dest/emoji_alphabet.d.ts.map +1 -0
- package/dest/emoji_alphabet.js +299 -0
- package/dest/extension/handlers/background_connection_handler.d.ts +168 -0
- package/dest/extension/handlers/background_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/background_connection_handler.js +294 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts +57 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/content_script_connection_handler.js +193 -0
- package/dest/extension/handlers/index.d.ts +12 -0
- package/dest/extension/handlers/index.d.ts.map +1 -0
- package/dest/extension/handlers/index.js +10 -0
- package/dest/extension/handlers/internal_message_types.d.ts +65 -0
- package/dest/extension/handlers/internal_message_types.d.ts.map +1 -0
- package/dest/extension/handlers/internal_message_types.js +24 -0
- package/dest/extension/provider/extension_provider.d.ts +107 -0
- package/dest/extension/provider/extension_provider.d.ts.map +1 -0
- package/dest/extension/provider/extension_provider.js +160 -0
- package/dest/extension/provider/extension_wallet.d.ts +152 -0
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -0
- package/dest/extension/provider/extension_wallet.js +349 -0
- package/dest/extension/provider/index.d.ts +3 -0
- package/dest/extension/provider/index.d.ts.map +1 -0
- 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/index.d.ts +2 -7
- package/dest/manager/index.d.ts.map +1 -1
- package/dest/manager/index.js +0 -4
- package/dest/manager/types.d.ts +109 -5
- package/dest/manager/types.d.ts.map +1 -1
- package/dest/manager/types.js +17 -1
- package/dest/manager/wallet_manager.d.ts +50 -7
- package/dest/manager/wallet_manager.d.ts.map +1 -1
- package/dest/manager/wallet_manager.js +208 -29
- package/dest/types.d.ts +185 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +40 -0
- package/package.json +24 -11
- package/src/base-wallet/base_wallet.ts +499 -176
- package/src/base-wallet/get_gas_limits.ts +88 -0
- package/src/base-wallet/index.ts +8 -1
- package/src/base-wallet/utils.ts +248 -0
- package/src/crypto.ts +603 -0
- package/src/emoji_alphabet.ts +317 -0
- package/src/extension/handlers/background_connection_handler.ts +456 -0
- package/src/extension/handlers/content_script_connection_handler.ts +264 -0
- package/src/extension/handlers/index.ts +25 -0
- package/src/extension/handlers/internal_message_types.ts +71 -0
- package/src/extension/provider/extension_provider.ts +233 -0
- package/src/extension/provider/extension_wallet.ts +410 -0
- package/src/extension/provider/index.ts +7 -0
- 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/index.ts +3 -15
- package/src/manager/types.ts +113 -4
- package/src/manager/wallet_manager.ts +235 -30
- package/src/types.ts +204 -0
- package/dest/providers/extension/extension_provider.d.ts +0 -17
- package/dest/providers/extension/extension_provider.d.ts.map +0 -1
- package/dest/providers/extension/extension_provider.js +0 -56
- package/dest/providers/extension/extension_wallet.d.ts +0 -23
- package/dest/providers/extension/extension_wallet.d.ts.map +0 -1
- package/dest/providers/extension/extension_wallet.js +0 -96
- package/dest/providers/extension/index.d.ts +0 -4
- package/dest/providers/extension/index.d.ts.map +0 -1
- package/dest/providers/types.d.ts +0 -67
- package/dest/providers/types.d.ts.map +0 -1
- package/dest/providers/types.js +0 -3
- package/src/providers/extension/extension_provider.ts +0 -72
- package/src/providers/extension/extension_wallet.ts +0 -124
- package/src/providers/extension/index.ts +0 -3
- package/src/providers/types.ts +0 -71
- /package/dest/{providers/extension → extension/provider}/index.js +0 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { MAX_PROCESSABLE_L2_GAS, MAX_TX_DA_GAS } from '@aztec/constants';
|
|
2
|
+
import { Gas, type GasUsed } from '@aztec/stdlib/gas';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns suggested total and teardown gas limits for a simulated tx, clamped to the network's per-tx
|
|
6
|
+
* admission limits.
|
|
7
|
+
*
|
|
8
|
+
* The network only admits transactions that declare up to `maxTxGasLimits` per dimension (the
|
|
9
|
+
* node-advertised `txsLimits.gas`). Wallets pass the value read from their own node info, but since node info
|
|
10
|
+
* is remote input it is defensively clamped here to the per-tx protocol maxima so a value above them is never
|
|
11
|
+
* honored. If the simulated usage already exceeds the resulting admission limits the tx can never be included,
|
|
12
|
+
* so this throws a descriptive error instead of returning a limit the node would reject. Otherwise it pads the
|
|
13
|
+
* usage and clamps each dimension to the admission limit.
|
|
14
|
+
* @param gasUsed - The gas actually consumed during simulation.
|
|
15
|
+
* @param maxTxGasLimits - The maximum gas a single tx may declare on this network (the node-advertised `txsLimits.gas`).
|
|
16
|
+
* @param pad - Fraction to pad the suggested gas limits by (as a decimal, e.g. 0.1 for 10%). The effective
|
|
17
|
+
* padding shrinks to zero as usage approaches the network limit, since the network will not admit a higher
|
|
18
|
+
* declared limit regardless of the buffer.
|
|
19
|
+
*/
|
|
20
|
+
export function getGasLimits(
|
|
21
|
+
gasUsed: GasUsed,
|
|
22
|
+
maxTxGasLimits: Gas,
|
|
23
|
+
pad = 0.1,
|
|
24
|
+
): {
|
|
25
|
+
/**
|
|
26
|
+
* Gas limit for the tx, excluding teardown gas
|
|
27
|
+
*/
|
|
28
|
+
gasLimits: Gas;
|
|
29
|
+
/**
|
|
30
|
+
* Gas limit for the teardown phase
|
|
31
|
+
*/
|
|
32
|
+
teardownGasLimits: Gas;
|
|
33
|
+
} {
|
|
34
|
+
const { totalGas, teardownGas } = gasUsed;
|
|
35
|
+
|
|
36
|
+
// `maxTxGasLimits` is the node-advertised admission limit. Node info is remote input, so we defensively
|
|
37
|
+
// clamp to the per-tx protocol maxima so a value above them can never be honored.
|
|
38
|
+
const maxLimits = new Gas(
|
|
39
|
+
Math.min(maxTxGasLimits.daGas, MAX_TX_DA_GAS),
|
|
40
|
+
Math.min(maxTxGasLimits.l2Gas, MAX_PROCESSABLE_L2_GAS),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// The simulated usage must fit within the admission limits, otherwise the tx can never be included.
|
|
44
|
+
if (totalGas.daGas > maxLimits.daGas) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Transaction consumes ${totalGas.daGas} DA gas but the network only admits transactions declaring up to ${maxLimits.daGas} DA gas`,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (totalGas.l2Gas > maxLimits.l2Gas) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Transaction consumes ${totalGas.l2Gas} L2 gas but the network only admits transactions declaring up to ${maxLimits.l2Gas} L2 gas`,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Pad the limits by the buffer, then cap each dimension at the admission limit so the buffer cannot push a
|
|
56
|
+
// declared limit past what inbound validation accepts. Teardown is part of the total, so clamping it to the
|
|
57
|
+
// admission limit is safe.
|
|
58
|
+
return {
|
|
59
|
+
gasLimits: padGas(totalGas, pad, maxLimits),
|
|
60
|
+
teardownGasLimits: padGas(teardownGas, pad, maxLimits),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Pads each gas dimension, capping it at the network admission limit. */
|
|
65
|
+
function padGas(gas: Gas, pad: number, cap: Gas): Gas {
|
|
66
|
+
const padded = gas.mul(1 + pad);
|
|
67
|
+
return new Gas(Math.min(padded.daGas, cap.daGas), Math.min(padded.l2Gas, cap.l2Gas));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Validates that caller-declared gas limits do not exceed the network's per-tx admission limits, throwing a
|
|
72
|
+
* descriptive error per dimension when they do. The node's inbound validation checks declared
|
|
73
|
+
* `gasSettings.gasLimits`, so we mirror that here to surface the rejection locally before the tx is sent.
|
|
74
|
+
* @param gasLimits - The gas limits the transaction will declare.
|
|
75
|
+
* @param maxTxGasLimits - The maximum gas a single tx may declare on this network (the node-advertised `txsLimits.gas`).
|
|
76
|
+
*/
|
|
77
|
+
export function assertGasLimitsWithinNetworkLimits(gasLimits: Gas, maxTxGasLimits: Gas): void {
|
|
78
|
+
if (gasLimits.daGas > maxTxGasLimits.daGas) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Declared DA gas limit (${gasLimits.daGas}) exceeds the maximum this network allows per tx (${maxTxGasLimits.daGas})`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (gasLimits.l2Gas > maxTxGasLimits.l2Gas) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`Declared L2 gas limit (${gasLimits.l2Gas}) exceeds the maximum this network allows per tx (${maxTxGasLimits.l2Gas})`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
package/src/base-wallet/index.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
BaseWallet,
|
|
3
|
+
type CompleteFeeOptionsConfig,
|
|
4
|
+
type FeeOptions,
|
|
5
|
+
type SimulateViaEntrypointOptions,
|
|
6
|
+
} from './base_wallet.js';
|
|
7
|
+
export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
|
|
8
|
+
export { getGasLimits, assertGasLimitsWithinNetworkLimits } from './get_gas_limits.js';
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
|
+
import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
3
|
+
import { MAX_ENQUEUED_CALLS_PER_CALL } from '@aztec/constants';
|
|
4
|
+
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
5
|
+
import { makeTuple } from '@aztec/foundation/array';
|
|
6
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
7
|
+
import type { Tuple } from '@aztec/foundation/serialize';
|
|
8
|
+
import type { ContractNameResolver } from '@aztec/pxe/client/lazy';
|
|
9
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
10
|
+
import { generateSimulatedProvingResult } from '@aztec/pxe/simulator';
|
|
11
|
+
import { type FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
|
|
12
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
14
|
+
import {
|
|
15
|
+
ClaimedLengthArray,
|
|
16
|
+
CountedPublicCallRequest,
|
|
17
|
+
PrivateCircuitPublicInputs,
|
|
18
|
+
PublicCallRequest,
|
|
19
|
+
} from '@aztec/stdlib/kernel';
|
|
20
|
+
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
21
|
+
import {
|
|
22
|
+
type BlockHeader,
|
|
23
|
+
type ExecutionPayload,
|
|
24
|
+
HashedValues,
|
|
25
|
+
PrivateCallExecutionResult,
|
|
26
|
+
PrivateExecutionResult,
|
|
27
|
+
PublicSimulationOutput,
|
|
28
|
+
type SimulationOverrides,
|
|
29
|
+
Tx,
|
|
30
|
+
TxContext,
|
|
31
|
+
TxSimulationResult,
|
|
32
|
+
} from '@aztec/stdlib/tx';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Splits an execution payload into a leading prefix of public static calls
|
|
36
|
+
* (eligible for direct node simulation) and the remaining calls.
|
|
37
|
+
*
|
|
38
|
+
* Only a leading run of public static calls is eligible for optimization.
|
|
39
|
+
* Any non-public-static call may enqueue public state mutations
|
|
40
|
+
* (e.g. private calls can enqueue public calls), so all calls that follow
|
|
41
|
+
* must go through the normal simulation path to see the correct state.
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
export function extractOptimizablePublicStaticCalls(payload: ExecutionPayload): {
|
|
45
|
+
/** Leading public static calls eligible for direct node simulation. */
|
|
46
|
+
optimizableCalls: FunctionCall[];
|
|
47
|
+
/** All remaining calls. */
|
|
48
|
+
remainingCalls: FunctionCall[];
|
|
49
|
+
} {
|
|
50
|
+
const splitIndex = payload.calls.findIndex(call => !call.isPublicStatic());
|
|
51
|
+
const boundary = splitIndex === -1 ? payload.calls.length : splitIndex;
|
|
52
|
+
return {
|
|
53
|
+
optimizableCalls: payload.calls.slice(0, boundary),
|
|
54
|
+
remainingCalls: payload.calls.slice(boundary),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Simulates a batch of public static calls by bypassing account entrypoint and private execution,
|
|
60
|
+
* directly constructing a minimal Tx and calling node.simulatePublicCalls.
|
|
61
|
+
*
|
|
62
|
+
* @param node - The Aztec node to simulate on.
|
|
63
|
+
* @param publicStaticCalls - Array of public static function calls (max MAX_ENQUEUED_CALLS_PER_CALL).
|
|
64
|
+
* @param from - The account address making the calls.
|
|
65
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
66
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
67
|
+
* @param blockHeader - Block header to use as anchor.
|
|
68
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
69
|
+
* @param getContractName - Resolver for contract names (used for debug log display).
|
|
70
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
71
|
+
* @returns TxSimulationResult with public return values.
|
|
72
|
+
*/
|
|
73
|
+
async function simulateBatchViaNode(
|
|
74
|
+
node: AztecNode,
|
|
75
|
+
publicStaticCalls: FunctionCall[],
|
|
76
|
+
from: AztecAddress,
|
|
77
|
+
chainInfo: ChainInfo,
|
|
78
|
+
gasSettings: GasSettings,
|
|
79
|
+
blockHeader: BlockHeader,
|
|
80
|
+
skipFeeEnforcement: boolean,
|
|
81
|
+
getContractName: ContractNameResolver,
|
|
82
|
+
overrides?: SimulationOverrides,
|
|
83
|
+
): Promise<TxSimulationResult> {
|
|
84
|
+
const txContext = new TxContext(chainInfo.chainId, chainInfo.version, gasSettings);
|
|
85
|
+
|
|
86
|
+
const publicFunctionCalldata: HashedValues[] = [];
|
|
87
|
+
for (const call of publicStaticCalls) {
|
|
88
|
+
const calldata = await HashedValues.fromCalldata([call.selector.toField(), ...call.args]);
|
|
89
|
+
publicFunctionCalldata.push(calldata);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const publicCallRequests = makeTuple(MAX_ENQUEUED_CALLS_PER_CALL, i => {
|
|
93
|
+
const call = publicStaticCalls[i];
|
|
94
|
+
if (!call) {
|
|
95
|
+
return CountedPublicCallRequest.empty();
|
|
96
|
+
}
|
|
97
|
+
const publicCallRequest = new PublicCallRequest(from, call.to, call.isStatic, publicFunctionCalldata[i]!.hash);
|
|
98
|
+
// Counter starts at 1 (minRevertibleSideEffectCounter) so all calls are revertible
|
|
99
|
+
return new CountedPublicCallRequest(publicCallRequest, i + 1);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const publicCallRequestsArray: ClaimedLengthArray<CountedPublicCallRequest, typeof MAX_ENQUEUED_CALLS_PER_CALL> =
|
|
103
|
+
new ClaimedLengthArray(
|
|
104
|
+
publicCallRequests as Tuple<CountedPublicCallRequest, typeof MAX_ENQUEUED_CALLS_PER_CALL>,
|
|
105
|
+
publicStaticCalls.length,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const publicInputs = PrivateCircuitPublicInputs.from({
|
|
109
|
+
...PrivateCircuitPublicInputs.empty(),
|
|
110
|
+
anchorBlockHeader: blockHeader,
|
|
111
|
+
txContext: txContext,
|
|
112
|
+
publicCallRequests: publicCallRequestsArray,
|
|
113
|
+
startSideEffectCounter: new Fr(0),
|
|
114
|
+
endSideEffectCounter: new Fr(publicStaticCalls.length + 1),
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Minimal entrypoint structure — no real private execution, just public call requests
|
|
118
|
+
const emptyEntrypoint = new PrivateCallExecutionResult(
|
|
119
|
+
Buffer.alloc(0),
|
|
120
|
+
Buffer.alloc(0),
|
|
121
|
+
new Map(),
|
|
122
|
+
publicInputs,
|
|
123
|
+
[],
|
|
124
|
+
new Map(),
|
|
125
|
+
[],
|
|
126
|
+
[],
|
|
127
|
+
[],
|
|
128
|
+
[],
|
|
129
|
+
[],
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const privateResult = new PrivateExecutionResult(emptyEntrypoint, Fr.random(), publicFunctionCalldata);
|
|
133
|
+
|
|
134
|
+
const provingResult = await generateSimulatedProvingResult(
|
|
135
|
+
privateResult,
|
|
136
|
+
(_contractAddress: AztecAddress, _functionSelector: FunctionSelector) => Promise.resolve(''),
|
|
137
|
+
node,
|
|
138
|
+
1, // minRevertibleSideEffectCounter
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
provingResult.publicInputs.feePayer = from;
|
|
142
|
+
|
|
143
|
+
const tx = await Tx.create({
|
|
144
|
+
data: provingResult.publicInputs,
|
|
145
|
+
chonkProof: ChonkProof.empty(),
|
|
146
|
+
contractClassLogFields: [],
|
|
147
|
+
publicFunctionCalldata: publicFunctionCalldata,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement, overrides);
|
|
151
|
+
|
|
152
|
+
if (publicOutput.revertReason) {
|
|
153
|
+
throw publicOutput.revertReason;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Display debug logs from the public simulation.
|
|
157
|
+
await displayDebugLogs(publicOutput.debugLogs, getContractName);
|
|
158
|
+
|
|
159
|
+
return new TxSimulationResult(privateResult, provingResult.publicInputs, publicOutput, undefined);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Simulates public static calls by splitting them into batches of MAX_ENQUEUED_CALLS_PER_CALL
|
|
164
|
+
* and sending each batch directly to the node.
|
|
165
|
+
*
|
|
166
|
+
* @param node - The Aztec node to simulate on.
|
|
167
|
+
* @param publicStaticCalls - Array of public static function calls to optimize.
|
|
168
|
+
* @param from - The account address making the calls.
|
|
169
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
170
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
171
|
+
* @param blockHeader - Block header to use as anchor.
|
|
172
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
173
|
+
* @param getContractName - Resolver for contract names (used for debug log display).
|
|
174
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
175
|
+
* @returns Array of TxSimulationResult, one per batch.
|
|
176
|
+
*/
|
|
177
|
+
export async function simulateViaNode(
|
|
178
|
+
node: AztecNode,
|
|
179
|
+
publicStaticCalls: FunctionCall[],
|
|
180
|
+
from: AztecAddress,
|
|
181
|
+
chainInfo: ChainInfo,
|
|
182
|
+
gasSettings: GasSettings,
|
|
183
|
+
blockHeader: BlockHeader,
|
|
184
|
+
skipFeeEnforcement: boolean = true,
|
|
185
|
+
getContractName: ContractNameResolver,
|
|
186
|
+
overrides?: SimulationOverrides,
|
|
187
|
+
): Promise<TxSimulationResult[]> {
|
|
188
|
+
const batches: FunctionCall[][] = [];
|
|
189
|
+
|
|
190
|
+
for (let i = 0; i < publicStaticCalls.length; i += MAX_ENQUEUED_CALLS_PER_CALL) {
|
|
191
|
+
batches.push(publicStaticCalls.slice(i, i + MAX_ENQUEUED_CALLS_PER_CALL));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const results: TxSimulationResult[] = [];
|
|
195
|
+
|
|
196
|
+
for (const batch of batches) {
|
|
197
|
+
const result = await simulateBatchViaNode(
|
|
198
|
+
node,
|
|
199
|
+
batch,
|
|
200
|
+
from,
|
|
201
|
+
chainInfo,
|
|
202
|
+
gasSettings,
|
|
203
|
+
blockHeader,
|
|
204
|
+
skipFeeEnforcement,
|
|
205
|
+
getContractName,
|
|
206
|
+
overrides,
|
|
207
|
+
);
|
|
208
|
+
results.push(result);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return results;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Merges simulation results from the optimized (public static) and normal paths.
|
|
216
|
+
* Since optimized calls are always a leading prefix, return values are simply
|
|
217
|
+
* concatenated: optimized first, then normal.
|
|
218
|
+
* Stats are taken from the normal result only (the optimized path doesn't produce them).
|
|
219
|
+
*
|
|
220
|
+
* @param optimizedResults - Results from optimized public static call batches.
|
|
221
|
+
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
222
|
+
* @returns A single TxSimulationResult with return values in original call order.
|
|
223
|
+
*/
|
|
224
|
+
export function buildMergedSimulationResult(
|
|
225
|
+
optimizedResults: TxSimulationResult[],
|
|
226
|
+
normalResult: TxSimulationResultWithAppOffset | null,
|
|
227
|
+
): TxSimulationResultWithAppOffset {
|
|
228
|
+
const optimizedReturnValues = optimizedResults.flatMap(r => r.publicOutput?.publicReturnValues ?? []);
|
|
229
|
+
const normalReturnValues = normalResult?.publicOutput?.publicReturnValues ?? [];
|
|
230
|
+
const allReturnValues = [...optimizedReturnValues, ...normalReturnValues];
|
|
231
|
+
|
|
232
|
+
const baseResult: TxSimulationResult = normalResult ?? optimizedResults[0];
|
|
233
|
+
|
|
234
|
+
const mergedPublicOutput: PublicSimulationOutput | undefined = baseResult.publicOutput
|
|
235
|
+
? {
|
|
236
|
+
...baseResult.publicOutput,
|
|
237
|
+
publicReturnValues: allReturnValues,
|
|
238
|
+
}
|
|
239
|
+
: undefined;
|
|
240
|
+
|
|
241
|
+
const merged = new TxSimulationResult(
|
|
242
|
+
baseResult.privateExecutionResult,
|
|
243
|
+
baseResult.publicInputs,
|
|
244
|
+
mergedPublicOutput,
|
|
245
|
+
normalResult?.stats,
|
|
246
|
+
);
|
|
247
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(merged, normalResult?.appCallOffset ?? 0);
|
|
248
|
+
}
|