@aztec/wallet-sdk 0.0.1-commit.fcb71a6 → 0.0.1-commit.ff7989d6c
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 +229 -332
- package/dest/base-wallet/base_wallet.d.ts +57 -14
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +135 -28
- 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 +49 -0
- package/dest/base-wallet/utils.d.ts.map +1 -0
- package/dest/base-wallet/utils.js +131 -0
- package/dest/crypto.d.ts +192 -0
- package/dest/crypto.d.ts.map +1 -0
- package/dest/crypto.js +394 -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 +158 -0
- package/dest/extension/handlers/background_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/background_connection_handler.js +258 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts +56 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/content_script_connection_handler.js +174 -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 +63 -0
- package/dest/extension/handlers/internal_message_types.d.ts.map +1 -0
- package/dest/extension/handlers/internal_message_types.js +22 -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 +132 -0
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -0
- package/dest/extension/provider/extension_wallet.js +278 -0
- package/dest/extension/provider/index.d.ts +3 -0
- package/dest/extension/provider/index.d.ts.map +1 -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 +108 -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 +178 -29
- package/dest/types.d.ts +123 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +11 -0
- package/package.json +20 -11
- package/src/base-wallet/base_wallet.ts +178 -48
- package/src/base-wallet/index.ts +1 -0
- package/src/base-wallet/utils.ts +238 -0
- package/src/crypto.ts +499 -0
- package/src/emoji_alphabet.ts +317 -0
- package/src/extension/handlers/background_connection_handler.ts +423 -0
- package/src/extension/handlers/content_script_connection_handler.ts +246 -0
- package/src/extension/handlers/index.ts +25 -0
- package/src/extension/handlers/internal_message_types.ts +69 -0
- package/src/extension/provider/extension_provider.ts +233 -0
- package/src/extension/provider/extension_wallet.ts +329 -0
- package/src/extension/provider/index.ts +7 -0
- package/src/manager/index.ts +3 -15
- package/src/manager/types.ts +112 -4
- package/src/manager/wallet_manager.ts +202 -31
- package/src/types.ts +132 -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
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import type { Account } from '@aztec/aztec.js/account';
|
|
2
2
|
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { type InteractionWaitOptions, type SendReturn } from '@aztec/aztec.js/contracts';
|
|
3
4
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
4
|
-
import type { Aliased,
|
|
5
|
+
import type { Aliased, AppCapabilities, BatchResults, BatchedMethod, ExecuteUtilityOptions, PrivateEvent, PrivateEventFilter, ProfileOptions, SendOptions, SimulateOptions, Wallet, WalletCapabilities } from '@aztec/aztec.js/wallet';
|
|
5
6
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
6
7
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
7
8
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
8
9
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
10
|
+
import type { AccessScopes } from '@aztec/pxe/client/lazy';
|
|
9
11
|
import type { PXE } from '@aztec/pxe/server';
|
|
10
12
|
import { type ContractArtifact, type EventMetadataDefinition, type FunctionCall } from '@aztec/stdlib/abi';
|
|
11
13
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
12
|
-
import
|
|
13
|
-
import { type
|
|
14
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
|
+
import { type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
14
16
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
15
17
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
16
|
-
import type
|
|
18
|
+
import { type TxExecutionRequest, type TxProfileResult, TxSimulationResult, type UtilityExecutionResult } from '@aztec/stdlib/tx';
|
|
17
19
|
import { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
18
20
|
/**
|
|
19
21
|
* Options to configure fee payment for a transaction
|
|
@@ -36,9 +38,10 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
36
38
|
protected readonly pxe: PXE;
|
|
37
39
|
protected readonly aztecNode: AztecNode;
|
|
38
40
|
protected log: import("@aztec/foundation/log").Logger;
|
|
39
|
-
protected
|
|
41
|
+
protected minFeePadding: number;
|
|
40
42
|
protected cancellableTransactions: boolean;
|
|
41
|
-
protected constructor(pxe: PXE, aztecNode: AztecNode);
|
|
43
|
+
protected constructor(pxe: PXE, aztecNode: AztecNode, log?: import("@aztec/foundation/log").Logger);
|
|
44
|
+
protected scopesFrom(from: AztecAddress, additionalScopes?: AztecAddress[]): AztecAddress[];
|
|
42
45
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
43
46
|
abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
44
47
|
/**
|
|
@@ -51,8 +54,22 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
51
54
|
getAddressBook(): Promise<Aliased<AztecAddress>[]>;
|
|
52
55
|
getChainInfo(): Promise<ChainInfo>;
|
|
53
56
|
protected createTxExecutionRequestFromPayloadAndFee(executionPayload: ExecutionPayload, from: AztecAddress, feeOptions: FeeOptions): Promise<TxExecutionRequest>;
|
|
54
|
-
createAuthWit(from: AztecAddress, messageHashOrIntent:
|
|
55
|
-
|
|
57
|
+
createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
|
|
58
|
+
/**
|
|
59
|
+
* Request capabilities from the wallet.
|
|
60
|
+
*
|
|
61
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
62
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
63
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
64
|
+
* friction by allowing apps to request permissions upfront.
|
|
65
|
+
*
|
|
66
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
67
|
+
* while the feature stabilizes.
|
|
68
|
+
*
|
|
69
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
70
|
+
*/
|
|
71
|
+
requestCapabilities(_manifest: AppCapabilities): Promise<WalletCapabilities>;
|
|
72
|
+
batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
|
|
56
73
|
/**
|
|
57
74
|
* Completes partial user-provided fee options with wallet defaults.
|
|
58
75
|
* @param from - The address where the transaction is being sent from
|
|
@@ -81,14 +98,40 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
81
98
|
}>;
|
|
82
99
|
registerSender(address: AztecAddress, _alias?: string): Promise<AztecAddress>;
|
|
83
100
|
registerContract(instance: ContractInstanceWithAddress, artifact?: ContractArtifact, secretKey?: Fr): Promise<ContractInstanceWithAddress>;
|
|
101
|
+
/**
|
|
102
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
103
|
+
* @param executionPayload - The execution payload to simulate.
|
|
104
|
+
* @param from - The sender address.
|
|
105
|
+
* @param feeOptions - Fee options for the transaction.
|
|
106
|
+
* @param skipTxValidation - Whether to skip tx validation.
|
|
107
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
108
|
+
* @param scopes - The scopes to use for the simulation.
|
|
109
|
+
*/
|
|
110
|
+
protected simulateViaEntrypoint(executionPayload: ExecutionPayload, from: AztecAddress, feeOptions: FeeOptions, scopes: AccessScopes, skipTxValidation?: boolean, skipFeeEnforcement?: boolean): Promise<TxSimulationResult>;
|
|
111
|
+
/**
|
|
112
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
113
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
114
|
+
* Return values from both paths are merged back in original call order.
|
|
115
|
+
* @param executionPayload - The execution payload to simulate.
|
|
116
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
117
|
+
* @returns The merged simulation result.
|
|
118
|
+
*/
|
|
84
119
|
simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
|
|
85
120
|
profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
|
|
86
|
-
sendTx(executionPayload: ExecutionPayload, opts: SendOptions): Promise<
|
|
121
|
+
sendTx<W extends InteractionWaitOptions = undefined>(executionPayload: ExecutionPayload, opts: SendOptions<W>): Promise<SendReturn<W>>;
|
|
87
122
|
protected contextualizeError(err: Error, ...context: string[]): Error;
|
|
88
|
-
|
|
89
|
-
getContractClassMetadata(id: Fr, includeArtifact?: boolean): Promise<ContractClassMetadata>;
|
|
90
|
-
getContractMetadata(address: AztecAddress): Promise<ContractMetadata>;
|
|
91
|
-
getTxReceipt(txHash: TxHash): Promise<TxReceipt>;
|
|
123
|
+
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult>;
|
|
92
124
|
getPrivateEvents<T>(eventDef: EventMetadataDefinition, eventFilter: PrivateEventFilter): Promise<PrivateEvent<T>[]>;
|
|
125
|
+
getContractMetadata(address: AztecAddress): Promise<{
|
|
126
|
+
instance: ContractInstanceWithAddress | undefined;
|
|
127
|
+
isContractInitialized: boolean;
|
|
128
|
+
isContractPublished: boolean;
|
|
129
|
+
isContractUpdated: boolean;
|
|
130
|
+
updatedContractClassId: Fr | undefined;
|
|
131
|
+
}>;
|
|
132
|
+
getContractClassMetadata(id: Fr): Promise<{
|
|
133
|
+
isArtifactRegistered: boolean;
|
|
134
|
+
isContractClassPubliclyRegistered: boolean;
|
|
135
|
+
}>;
|
|
93
136
|
}
|
|
94
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
137
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFzZV93YWxsZXQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9iYXNlX3dhbGxldC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLE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ESTIMATION_L2_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT } from '@aztec/constants';
|
|
2
4
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
3
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
7
|
import { decodeFromAbi } from '@aztec/stdlib/abi';
|
|
8
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
9
|
import { computePartialAddress, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
7
10
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
8
11
|
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
12
|
+
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
9
13
|
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
10
14
|
import { inspect } from 'util';
|
|
15
|
+
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
11
16
|
/**
|
|
12
17
|
* A base class for Wallet implementations
|
|
13
18
|
*/ export class BaseWallet {
|
|
14
19
|
pxe;
|
|
15
20
|
aztecNode;
|
|
16
21
|
log;
|
|
17
|
-
|
|
22
|
+
minFeePadding;
|
|
18
23
|
cancellableTransactions;
|
|
19
24
|
// Protected because we want to force wallets to instantiate their own PXE.
|
|
20
|
-
constructor(pxe, aztecNode){
|
|
25
|
+
constructor(pxe, aztecNode, log = createLogger('wallet-sdk:base_wallet')){
|
|
21
26
|
this.pxe = pxe;
|
|
22
27
|
this.aztecNode = aztecNode;
|
|
23
|
-
this.log =
|
|
24
|
-
this.
|
|
28
|
+
this.log = log;
|
|
29
|
+
this.minFeePadding = 0.5;
|
|
25
30
|
this.cancellableTransactions = false;
|
|
26
31
|
}
|
|
32
|
+
scopesFrom(from, additionalScopes = []) {
|
|
33
|
+
const allScopes = from.isZero() ? additionalScopes : [
|
|
34
|
+
from,
|
|
35
|
+
...additionalScopes
|
|
36
|
+
];
|
|
37
|
+
const scopeSet = new Set(allScopes.map((address)=>address.toString()));
|
|
38
|
+
return [
|
|
39
|
+
...scopeSet
|
|
40
|
+
].map(AztecAddress.fromString);
|
|
41
|
+
}
|
|
27
42
|
/**
|
|
28
43
|
* Returns the list of aliased contacts associated with the wallet.
|
|
29
44
|
* This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
|
|
@@ -56,11 +71,28 @@ import { inspect } from 'util';
|
|
|
56
71
|
executionPayload
|
|
57
72
|
]) : executionPayload;
|
|
58
73
|
const fromAccount = await this.getAccountFromAddress(from);
|
|
59
|
-
|
|
74
|
+
const chainInfo = await this.getChainInfo();
|
|
75
|
+
return fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
60
76
|
}
|
|
61
77
|
async createAuthWit(from, messageHashOrIntent) {
|
|
62
78
|
const account = await this.getAccountFromAddress(from);
|
|
63
|
-
|
|
79
|
+
const chainInfo = await this.getChainInfo();
|
|
80
|
+
return account.createAuthWit(messageHashOrIntent, chainInfo);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Request capabilities from the wallet.
|
|
84
|
+
*
|
|
85
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
86
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
87
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
88
|
+
* friction by allowing apps to request permissions upfront.
|
|
89
|
+
*
|
|
90
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
91
|
+
* while the feature stabilizes.
|
|
92
|
+
*
|
|
93
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
94
|
+
*/ requestCapabilities(_manifest) {
|
|
95
|
+
throw new Error('Not implemented');
|
|
64
96
|
}
|
|
65
97
|
async batch(methods) {
|
|
66
98
|
const results = [];
|
|
@@ -88,7 +120,7 @@ import { inspect } from 'util';
|
|
|
88
120
|
* @param gasSettings - User-provided partial gas settings
|
|
89
121
|
* @returns - Complete fee options that can be used to create a transaction execution request
|
|
90
122
|
*/ async completeFeeOptions(from, feePayer, gasSettings) {
|
|
91
|
-
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.aztecNode.
|
|
123
|
+
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
|
|
92
124
|
let accountFeePaymentMethodOptions;
|
|
93
125
|
// The transaction does not include a fee payment method, so we set the flag
|
|
94
126
|
// for the account to use its fee juice balance
|
|
@@ -132,7 +164,7 @@ import { inspect } from 'util';
|
|
|
132
164
|
return this.pxe.registerSender(address);
|
|
133
165
|
}
|
|
134
166
|
async registerContract(instance, artifact, secretKey) {
|
|
135
|
-
const
|
|
167
|
+
const existingInstance = await this.pxe.getContractInstance(instance.address);
|
|
136
168
|
if (existingInstance) {
|
|
137
169
|
// Instance already registered in the wallet
|
|
138
170
|
if (artifact) {
|
|
@@ -148,11 +180,10 @@ import { inspect } from 'util';
|
|
|
148
180
|
// Instance not registered yet
|
|
149
181
|
if (!artifact) {
|
|
150
182
|
// Try to get the artifact from the wallet's contract class storage
|
|
151
|
-
|
|
152
|
-
if (!
|
|
183
|
+
artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
184
|
+
if (!artifact) {
|
|
153
185
|
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()}`);
|
|
154
186
|
}
|
|
155
|
-
artifact = classMetadata.artifact;
|
|
156
187
|
}
|
|
157
188
|
await this.pxe.registerContract({
|
|
158
189
|
artifact,
|
|
@@ -164,20 +195,73 @@ import { inspect } from 'util';
|
|
|
164
195
|
}
|
|
165
196
|
return instance;
|
|
166
197
|
}
|
|
167
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
200
|
+
* @param executionPayload - The execution payload to simulate.
|
|
201
|
+
* @param from - The sender address.
|
|
202
|
+
* @param feeOptions - Fee options for the transaction.
|
|
203
|
+
* @param skipTxValidation - Whether to skip tx validation.
|
|
204
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
205
|
+
* @param scopes - The scopes to use for the simulation.
|
|
206
|
+
*/ async simulateViaEntrypoint(executionPayload, from, feeOptions, scopes, skipTxValidation, skipFeeEnforcement) {
|
|
207
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions);
|
|
208
|
+
return this.pxe.simulateTx(txRequest, {
|
|
209
|
+
simulatePublic: true,
|
|
210
|
+
skipTxValidation,
|
|
211
|
+
skipFeeEnforcement,
|
|
212
|
+
scopes
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
217
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
218
|
+
* Return values from both paths are merged back in original call order.
|
|
219
|
+
* @param executionPayload - The execution payload to simulate.
|
|
220
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
221
|
+
* @returns The merged simulation result.
|
|
222
|
+
*/ async simulateTx(executionPayload, opts) {
|
|
168
223
|
const feeOptions = opts.fee?.estimateGas ? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings) : await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
169
|
-
const
|
|
170
|
-
|
|
224
|
+
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
225
|
+
const remainingPayload = {
|
|
226
|
+
...executionPayload,
|
|
227
|
+
calls: remainingCalls
|
|
228
|
+
};
|
|
229
|
+
const chainInfo = await this.getChainInfo();
|
|
230
|
+
let blockHeader;
|
|
231
|
+
// PXE might not be synced yet, so we pull the latest header from the node
|
|
232
|
+
// To keep things consistent, we'll always try with PXE first
|
|
233
|
+
try {
|
|
234
|
+
blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
235
|
+
} catch {
|
|
236
|
+
blockHeader = await this.aztecNode.getBlockHeader();
|
|
237
|
+
}
|
|
238
|
+
const getContractName = async (address)=>{
|
|
239
|
+
const instance = await this.pxe.getContractInstance(address);
|
|
240
|
+
if (!instance) {
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
const artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
244
|
+
return artifact?.name;
|
|
245
|
+
};
|
|
246
|
+
const [optimizedResults, normalResult] = await Promise.all([
|
|
247
|
+
optimizableCalls.length > 0 ? simulateViaNode(this.aztecNode, optimizableCalls, opts.from, chainInfo, feeOptions.gasSettings, blockHeader, opts.skipFeeEnforcement ?? true, getContractName) : Promise.resolve([]),
|
|
248
|
+
remainingCalls.length > 0 ? this.simulateViaEntrypoint(remainingPayload, opts.from, feeOptions, this.scopesFrom(opts.from, opts.additionalScopes), opts.skipTxValidation, opts.skipFeeEnforcement ?? true) : Promise.resolve(null)
|
|
249
|
+
]);
|
|
250
|
+
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
171
251
|
}
|
|
172
252
|
async profileTx(executionPayload, opts) {
|
|
173
253
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
174
254
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
175
|
-
return this.pxe.profileTx(txRequest,
|
|
255
|
+
return this.pxe.profileTx(txRequest, {
|
|
256
|
+
profileMode: opts.profileMode,
|
|
257
|
+
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
258
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes)
|
|
259
|
+
});
|
|
176
260
|
}
|
|
177
261
|
async sendTx(executionPayload, opts) {
|
|
178
262
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
179
263
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
180
|
-
const provenTx = await this.pxe.proveTx(txRequest);
|
|
264
|
+
const provenTx = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
|
|
181
265
|
const tx = await provenTx.toTx();
|
|
182
266
|
const txHash = tx.getTxHash();
|
|
183
267
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -188,7 +272,13 @@ import { inspect } from 'util';
|
|
|
188
272
|
throw this.contextualizeError(err, inspect(tx));
|
|
189
273
|
});
|
|
190
274
|
this.log.info(`Sent transaction ${txHash}`);
|
|
191
|
-
return txHash
|
|
275
|
+
// If wait is NO_WAIT, return txHash immediately
|
|
276
|
+
if (opts.wait === NO_WAIT) {
|
|
277
|
+
return txHash;
|
|
278
|
+
}
|
|
279
|
+
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
280
|
+
const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
281
|
+
return await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
192
282
|
}
|
|
193
283
|
contextualizeError(err, ...context) {
|
|
194
284
|
let contextStr = '';
|
|
@@ -203,17 +293,13 @@ import { inspect } from 'util';
|
|
|
203
293
|
}
|
|
204
294
|
return err;
|
|
205
295
|
}
|
|
206
|
-
|
|
207
|
-
return this.pxe.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return this.pxe.getContractMetadata(address);
|
|
214
|
-
}
|
|
215
|
-
getTxReceipt(txHash) {
|
|
216
|
-
return this.aztecNode.getTxReceipt(txHash);
|
|
296
|
+
executeUtility(call, opts) {
|
|
297
|
+
return this.pxe.executeUtility(call, {
|
|
298
|
+
authwits: opts.authWitnesses,
|
|
299
|
+
scopes: [
|
|
300
|
+
opts.scope
|
|
301
|
+
]
|
|
302
|
+
});
|
|
217
303
|
}
|
|
218
304
|
async getPrivateEvents(eventDef, eventFilter) {
|
|
219
305
|
const pxeEvents = await this.pxe.getPrivateEvents(eventDef.eventSelector, eventFilter);
|
|
@@ -231,4 +317,25 @@ import { inspect } from 'util';
|
|
|
231
317
|
});
|
|
232
318
|
return decodedEvents;
|
|
233
319
|
}
|
|
320
|
+
async getContractMetadata(address) {
|
|
321
|
+
const instance = await this.pxe.getContractInstance(address);
|
|
322
|
+
const initNullifier = await siloNullifier(address, address.toField());
|
|
323
|
+
const publiclyRegisteredContract = await this.aztecNode.getContract(address);
|
|
324
|
+
const initNullifierMembershipWitness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
325
|
+
const isContractUpdated = publiclyRegisteredContract && !publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
326
|
+
return {
|
|
327
|
+
instance: instance ?? undefined,
|
|
328
|
+
isContractInitialized: !!initNullifierMembershipWitness,
|
|
329
|
+
isContractPublished: !!publiclyRegisteredContract,
|
|
330
|
+
isContractUpdated: !!isContractUpdated,
|
|
331
|
+
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
async getContractClassMetadata(id) {
|
|
335
|
+
const publiclyRegisteredContractClass = await this.aztecNode.getContractClass(id);
|
|
336
|
+
return {
|
|
337
|
+
isArtifactRegistered: !!await this.pxe.getContractArtifact(id),
|
|
338
|
+
isContractClassPubliclyRegistered: !!publiclyRegisteredContractClass
|
|
339
|
+
};
|
|
340
|
+
}
|
|
234
341
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { BaseWallet, type FeeOptions } from './base_wallet.js';
|
|
2
|
-
|
|
2
|
+
export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLEtBQUssVUFBVSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFDL0QsT0FBTyxFQUFFLGVBQWUsRUFBRSwyQkFBMkIsRUFBRSxtQ0FBbUMsRUFBRSxNQUFNLFlBQVksQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,mCAAmC,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
|
+
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
3
|
+
import type { ContractNameResolver } from '@aztec/pxe/client/lazy';
|
|
4
|
+
import { type FunctionCall } from '@aztec/stdlib/abi';
|
|
5
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
7
|
+
import { type BlockHeader, type ExecutionPayload, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
8
|
+
/**
|
|
9
|
+
* Splits an execution payload into a leading prefix of public static calls
|
|
10
|
+
* (eligible for direct node simulation) and the remaining calls.
|
|
11
|
+
*
|
|
12
|
+
* Only a leading run of public static calls is eligible for optimization.
|
|
13
|
+
* Any non-public-static call may enqueue public state mutations
|
|
14
|
+
* (e.g. private calls can enqueue public calls), so all calls that follow
|
|
15
|
+
* must go through the normal simulation path to see the correct state.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractOptimizablePublicStaticCalls(payload: ExecutionPayload): {
|
|
19
|
+
/** Leading public static calls eligible for direct node simulation. */
|
|
20
|
+
optimizableCalls: FunctionCall[];
|
|
21
|
+
/** All remaining calls. */
|
|
22
|
+
remainingCalls: FunctionCall[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Simulates public static calls by splitting them into batches of MAX_ENQUEUED_CALLS_PER_CALL
|
|
26
|
+
* and sending each batch directly to the node.
|
|
27
|
+
*
|
|
28
|
+
* @param node - The Aztec node to simulate on.
|
|
29
|
+
* @param publicStaticCalls - Array of public static function calls to optimize.
|
|
30
|
+
* @param from - The account address making the calls.
|
|
31
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
32
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
33
|
+
* @param blockHeader - Block header to use as anchor.
|
|
34
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
35
|
+
* @returns Array of TxSimulationResult, one per batch.
|
|
36
|
+
*/
|
|
37
|
+
export declare function simulateViaNode(node: AztecNode, publicStaticCalls: FunctionCall[], from: AztecAddress, chainInfo: ChainInfo, gasSettings: GasSettings, blockHeader: BlockHeader, skipFeeEnforcement: boolean | undefined, getContractName: ContractNameResolver): Promise<TxSimulationResult[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Merges simulation results from the optimized (public static) and normal paths.
|
|
40
|
+
* Since optimized calls are always a leading prefix, return values are simply
|
|
41
|
+
* concatenated: optimized first, then normal.
|
|
42
|
+
* Stats are taken from the normal result only (the optimized path doesn't produce them).
|
|
43
|
+
*
|
|
44
|
+
* @param optimizedResults - Results from optimized public static call batches.
|
|
45
|
+
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
46
|
+
* @returns A single TxSimulationResult with return values in original call order.
|
|
47
|
+
*/
|
|
48
|
+
export declare function buildMergedSimulationResult(optimizedResults: TxSimulationResult[], normalResult: TxSimulationResult | null): TxSimulationResult;
|
|
49
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUV0RCxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUkvRCxPQUFPLEtBQUssRUFBRSxvQkFBb0IsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBR25FLE9BQU8sRUFBRSxLQUFLLFlBQVksRUFBb0IsTUFBTSxtQkFBbUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQVFyRCxPQUFPLEVBQ0wsS0FBSyxXQUFXLEVBQ2hCLEtBQUssZ0JBQWdCLEVBT3JCLGtCQUFrQixFQUNuQixNQUFNLGtCQUFrQixDQUFDO0FBRTFCOzs7Ozs7Ozs7R0FTRztBQUNILHdCQUFnQixtQ0FBbUMsQ0FBQyxPQUFPLEVBQUUsZ0JBQWdCLEdBQUc7SUFDOUUsdUVBQXVFO0lBQ3ZFLGdCQUFnQixFQUFFLFlBQVksRUFBRSxDQUFDO0lBQ2pDLDJCQUEyQjtJQUMzQixjQUFjLEVBQUUsWUFBWSxFQUFFLENBQUM7Q0FDa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B,GAAG;IAC9E,uEAAuE;IACvE,gBAAgB,EAAE,YAAY,EAAE,CAAC;IACjC,2BAA2B;IAC3B,cAAc,EAAE,YAAY,EAAE,CAAC;CAChC,CAOA;AAuGD;;;;;;;;;;;;GAYG;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,GACpC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAwB/B;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CACzC,gBAAgB,EAAE,kBAAkB,EAAE,EACtC,YAAY,EAAE,kBAAkB,GAAG,IAAI,GACtC,kBAAkB,CAoBpB"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { MAX_ENQUEUED_CALLS_PER_CALL } from '@aztec/constants';
|
|
2
|
+
import { makeTuple } from '@aztec/foundation/array';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
5
|
+
import { generateSimulatedProvingResult } from '@aztec/pxe/simulator';
|
|
6
|
+
import { ClaimedLengthArray, CountedPublicCallRequest, PrivateCircuitPublicInputs, PublicCallRequest } from '@aztec/stdlib/kernel';
|
|
7
|
+
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
8
|
+
import { HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx, TxContext, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
9
|
+
/**
|
|
10
|
+
* Splits an execution payload into a leading prefix of public static calls
|
|
11
|
+
* (eligible for direct node simulation) and the remaining calls.
|
|
12
|
+
*
|
|
13
|
+
* Only a leading run of public static calls is eligible for optimization.
|
|
14
|
+
* Any non-public-static call may enqueue public state mutations
|
|
15
|
+
* (e.g. private calls can enqueue public calls), so all calls that follow
|
|
16
|
+
* must go through the normal simulation path to see the correct state.
|
|
17
|
+
*
|
|
18
|
+
*/ export function extractOptimizablePublicStaticCalls(payload) {
|
|
19
|
+
const splitIndex = payload.calls.findIndex((call)=>!call.isPublicStatic());
|
|
20
|
+
const boundary = splitIndex === -1 ? payload.calls.length : splitIndex;
|
|
21
|
+
return {
|
|
22
|
+
optimizableCalls: payload.calls.slice(0, boundary),
|
|
23
|
+
remainingCalls: payload.calls.slice(boundary)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Simulates a batch of public static calls by bypassing account entrypoint and private execution,
|
|
28
|
+
* directly constructing a minimal Tx and calling node.simulatePublicCalls.
|
|
29
|
+
*
|
|
30
|
+
* @param node - The Aztec node to simulate on.
|
|
31
|
+
* @param publicStaticCalls - Array of public static function calls (max MAX_ENQUEUED_CALLS_PER_CALL).
|
|
32
|
+
* @param from - The account address making the calls.
|
|
33
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
34
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
35
|
+
* @param blockHeader - Block header to use as anchor.
|
|
36
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
37
|
+
* @returns TxSimulationResult with public return values.
|
|
38
|
+
*/ async function simulateBatchViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement, getContractName) {
|
|
39
|
+
const txContext = new TxContext(chainInfo.chainId, chainInfo.version, gasSettings);
|
|
40
|
+
const publicFunctionCalldata = [];
|
|
41
|
+
for (const call of publicStaticCalls){
|
|
42
|
+
const calldata = await HashedValues.fromCalldata([
|
|
43
|
+
call.selector.toField(),
|
|
44
|
+
...call.args
|
|
45
|
+
]);
|
|
46
|
+
publicFunctionCalldata.push(calldata);
|
|
47
|
+
}
|
|
48
|
+
const publicCallRequests = makeTuple(MAX_ENQUEUED_CALLS_PER_CALL, (i)=>{
|
|
49
|
+
const call = publicStaticCalls[i];
|
|
50
|
+
if (!call) {
|
|
51
|
+
return CountedPublicCallRequest.empty();
|
|
52
|
+
}
|
|
53
|
+
const publicCallRequest = new PublicCallRequest(from, call.to, call.isStatic, publicFunctionCalldata[i].hash);
|
|
54
|
+
// Counter starts at 1 (minRevertibleSideEffectCounter) so all calls are revertible
|
|
55
|
+
return new CountedPublicCallRequest(publicCallRequest, i + 1);
|
|
56
|
+
});
|
|
57
|
+
const publicCallRequestsArray = new ClaimedLengthArray(publicCallRequests, publicStaticCalls.length);
|
|
58
|
+
const publicInputs = PrivateCircuitPublicInputs.from({
|
|
59
|
+
...PrivateCircuitPublicInputs.empty(),
|
|
60
|
+
anchorBlockHeader: blockHeader,
|
|
61
|
+
txContext: txContext,
|
|
62
|
+
publicCallRequests: publicCallRequestsArray,
|
|
63
|
+
startSideEffectCounter: new Fr(0),
|
|
64
|
+
endSideEffectCounter: new Fr(publicStaticCalls.length + 1)
|
|
65
|
+
});
|
|
66
|
+
// Minimal entrypoint structure — no real private execution, just public call requests
|
|
67
|
+
const emptyEntrypoint = new PrivateCallExecutionResult(Buffer.alloc(0), Buffer.alloc(0), new Map(), publicInputs, [], new Map(), [], [], [], [], []);
|
|
68
|
+
const privateResult = new PrivateExecutionResult(emptyEntrypoint, Fr.random(), publicFunctionCalldata);
|
|
69
|
+
const provingResult = await generateSimulatedProvingResult(privateResult, (_contractAddress, _functionSelector)=>Promise.resolve(''), node, 1);
|
|
70
|
+
provingResult.publicInputs.feePayer = from;
|
|
71
|
+
const tx = await Tx.create({
|
|
72
|
+
data: provingResult.publicInputs,
|
|
73
|
+
chonkProof: ChonkProof.empty(),
|
|
74
|
+
contractClassLogFields: [],
|
|
75
|
+
publicFunctionCalldata: publicFunctionCalldata
|
|
76
|
+
});
|
|
77
|
+
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement);
|
|
78
|
+
if (publicOutput.revertReason) {
|
|
79
|
+
throw publicOutput.revertReason;
|
|
80
|
+
}
|
|
81
|
+
// Display debug logs from the public simulation.
|
|
82
|
+
await displayDebugLogs(publicOutput.debugLogs, getContractName);
|
|
83
|
+
return new TxSimulationResult(privateResult, provingResult.publicInputs, publicOutput, undefined);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Simulates public static calls by splitting them into batches of MAX_ENQUEUED_CALLS_PER_CALL
|
|
87
|
+
* and sending each batch directly to the node.
|
|
88
|
+
*
|
|
89
|
+
* @param node - The Aztec node to simulate on.
|
|
90
|
+
* @param publicStaticCalls - Array of public static function calls to optimize.
|
|
91
|
+
* @param from - The account address making the calls.
|
|
92
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
93
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
94
|
+
* @param blockHeader - Block header to use as anchor.
|
|
95
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
96
|
+
* @returns Array of TxSimulationResult, one per batch.
|
|
97
|
+
*/ export async function simulateViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement = true, getContractName) {
|
|
98
|
+
const batches = [];
|
|
99
|
+
for(let i = 0; i < publicStaticCalls.length; i += MAX_ENQUEUED_CALLS_PER_CALL){
|
|
100
|
+
batches.push(publicStaticCalls.slice(i, i + MAX_ENQUEUED_CALLS_PER_CALL));
|
|
101
|
+
}
|
|
102
|
+
const results = [];
|
|
103
|
+
for (const batch of batches){
|
|
104
|
+
const result = await simulateBatchViaNode(node, batch, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement, getContractName);
|
|
105
|
+
results.push(result);
|
|
106
|
+
}
|
|
107
|
+
return results;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Merges simulation results from the optimized (public static) and normal paths.
|
|
111
|
+
* Since optimized calls are always a leading prefix, return values are simply
|
|
112
|
+
* concatenated: optimized first, then normal.
|
|
113
|
+
* Stats are taken from the normal result only (the optimized path doesn't produce them).
|
|
114
|
+
*
|
|
115
|
+
* @param optimizedResults - Results from optimized public static call batches.
|
|
116
|
+
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
117
|
+
* @returns A single TxSimulationResult with return values in original call order.
|
|
118
|
+
*/ export function buildMergedSimulationResult(optimizedResults, normalResult) {
|
|
119
|
+
const optimizedReturnValues = optimizedResults.flatMap((r)=>r.publicOutput?.publicReturnValues ?? []);
|
|
120
|
+
const normalReturnValues = normalResult?.publicOutput?.publicReturnValues ?? [];
|
|
121
|
+
const allReturnValues = [
|
|
122
|
+
...optimizedReturnValues,
|
|
123
|
+
...normalReturnValues
|
|
124
|
+
];
|
|
125
|
+
const baseResult = normalResult ?? optimizedResults[0];
|
|
126
|
+
const mergedPublicOutput = baseResult.publicOutput ? {
|
|
127
|
+
...baseResult.publicOutput,
|
|
128
|
+
publicReturnValues: allReturnValues
|
|
129
|
+
} : undefined;
|
|
130
|
+
return new TxSimulationResult(baseResult.privateExecutionResult, baseResult.publicInputs, mergedPublicOutput, normalResult?.stats);
|
|
131
|
+
}
|