@aztec/wallet-sdk 0.0.1-commit.64b6bbb → 0.0.1-commit.69c59a8b3
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/dest/base-wallet/base_wallet.d.ts +59 -39
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +195 -75
- package/dest/base-wallet/index.d.ts +2 -2
- package/dest/base-wallet/index.d.ts.map +1 -1
- 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 +10 -5
- package/dest/crypto.d.ts +39 -1
- package/dest/crypto.d.ts.map +1 -1
- package/dest/crypto.js +88 -0
- package/dest/extension/provider/extension_wallet.d.ts +4 -6
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -1
- package/dest/extension/provider/extension_wallet.js +9 -2
- package/dest/extension/provider/index.d.ts +2 -2
- package/dest/extension/provider/index.d.ts.map +1 -1
- package/dest/iframe/handlers/iframe_connection_handler.d.ts +118 -0
- package/dest/iframe/handlers/iframe_connection_handler.d.ts.map +1 -0
- package/dest/iframe/handlers/iframe_connection_handler.js +228 -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 +68 -0
- package/dest/iframe/provider/iframe_wallet.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_wallet.js +200 -0
- package/dest/iframe/provider/index.d.ts +4 -0
- package/dest/iframe/provider/index.d.ts.map +1 -0
- package/dest/iframe/provider/index.js +3 -0
- package/dest/manager/types.d.ts +6 -5
- package/dest/manager/types.d.ts.map +1 -1
- package/dest/manager/wallet_manager.d.ts +1 -1
- package/dest/manager/wallet_manager.d.ts.map +1 -1
- package/dest/manager/wallet_manager.js +48 -18
- package/dest/types.d.ts +14 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +4 -0
- package/package.json +12 -8
- package/src/base-wallet/base_wallet.ts +269 -127
- package/src/base-wallet/index.ts +6 -1
- package/src/base-wallet/utils.ts +15 -4
- package/src/crypto.ts +104 -0
- package/src/extension/provider/extension_wallet.ts +13 -10
- package/src/extension/provider/index.ts +1 -1
- package/src/iframe/handlers/iframe_connection_handler.ts +328 -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 +229 -0
- package/src/iframe/provider/index.ts +3 -0
- package/src/manager/types.ts +5 -4
- package/src/manager/wallet_manager.ts +55 -23
- package/src/types.ts +13 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Account } from '@aztec/aztec.js/account';
|
|
1
|
+
import type { Account, NoFrom } from '@aztec/aztec.js/account';
|
|
2
2
|
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
3
3
|
import { type InteractionWaitOptions, type SendReturn } from '@aztec/aztec.js/contracts';
|
|
4
4
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
5
|
-
import type
|
|
5
|
+
import { type Aliased, type AppCapabilities, type BatchResults, type BatchedMethod, ContractInitializationStatus, type ExecuteUtilityOptions, type PrivateEvent, type PrivateEventFilter, type ProfileOptions, type SendOptions, type SimulateOptions, TxSimulationResultWithAppOffset, type Wallet, type WalletCapabilities } from '@aztec/aztec.js/wallet';
|
|
6
6
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
7
7
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
8
8
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
@@ -10,12 +10,11 @@ import type { FieldsOf } from '@aztec/foundation/types';
|
|
|
10
10
|
import type { PXE } from '@aztec/pxe/server';
|
|
11
11
|
import { type ContractArtifact, type EventMetadataDefinition, type FunctionCall } from '@aztec/stdlib/abi';
|
|
12
12
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
13
|
-
import
|
|
13
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
14
14
|
import { type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
15
|
-
import { GasSettings } from '@aztec/stdlib/gas';
|
|
15
|
+
import { GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
16
16
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
17
|
-
import { type TxExecutionRequest, type TxProfileResult,
|
|
18
|
-
import { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
17
|
+
import { ExecutionPayload, type TxExecutionRequest, type TxProfileResult, type UtilityExecutionResult } from '@aztec/stdlib/tx';
|
|
19
18
|
/**
|
|
20
19
|
* Options to configure fee payment for a transaction
|
|
21
20
|
*/
|
|
@@ -26,10 +25,31 @@ export type FeeOptions = {
|
|
|
26
25
|
*/
|
|
27
26
|
walletFeePaymentMethod?: FeePaymentMethod;
|
|
28
27
|
/** Configuration options for the account to properly handle the selected fee payment method */
|
|
29
|
-
accountFeePaymentMethodOptions
|
|
28
|
+
accountFeePaymentMethodOptions?: AccountFeePaymentMethodOptions;
|
|
30
29
|
/** The gas settings to use for the transaction */
|
|
31
30
|
gasSettings: GasSettings;
|
|
32
31
|
};
|
|
32
|
+
/** Options for `simulateViaEntrypoint`. */
|
|
33
|
+
export type SimulateViaEntrypointOptions = Pick<SimulateOptions, 'from' | 'additionalScopes' | 'skipTxValidation' | 'skipFeeEnforcement'> & {
|
|
34
|
+
/** Fee options for the entrypoint */
|
|
35
|
+
feeOptions: FeeOptions;
|
|
36
|
+
};
|
|
37
|
+
/** Options for `completeFeeOptions`. */
|
|
38
|
+
export type CompleteFeeOptionsConfig = {
|
|
39
|
+
/** The address where the transaction is being sent from. */
|
|
40
|
+
from: AztecAddress | NoFrom;
|
|
41
|
+
/** The address paying for fees (if any fee payment method is embedded in the execution payload). */
|
|
42
|
+
feePayer?: AztecAddress;
|
|
43
|
+
/** User-provided partial gas settings. */
|
|
44
|
+
gasSettings?: Partial<FieldsOf<GasSettings>>;
|
|
45
|
+
/** If true, returns gas settings with high gas limits for estimation. If false, uses fallback limits. */
|
|
46
|
+
forEstimation?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Assumed network congestion level for fee prediction. Controls how aggressively the wallet
|
|
49
|
+
* estimates future fees. Defaults to Limit (worst case) when not specified.
|
|
50
|
+
*/
|
|
51
|
+
congestionEstimate?: ManaUsageEstimate;
|
|
52
|
+
};
|
|
33
53
|
/**
|
|
34
54
|
* A base class for Wallet implementations
|
|
35
55
|
*/
|
|
@@ -39,7 +59,9 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
39
59
|
protected log: import("@aztec/foundation/log").Logger;
|
|
40
60
|
protected minFeePadding: number;
|
|
41
61
|
protected cancellableTransactions: boolean;
|
|
42
|
-
|
|
62
|
+
private nodeInfoPromise;
|
|
63
|
+
protected constructor(pxe: PXE, aztecNode: AztecNode, log?: import("@aztec/foundation/log").Logger);
|
|
64
|
+
protected scopesFrom(from: AztecAddress | NoFrom, additionalScopes?: AztecAddress[]): AztecAddress[];
|
|
43
65
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
44
66
|
abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
45
67
|
/**
|
|
@@ -51,7 +73,7 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
51
73
|
*/
|
|
52
74
|
getAddressBook(): Promise<Aliased<AztecAddress>[]>;
|
|
53
75
|
getChainInfo(): Promise<ChainInfo>;
|
|
54
|
-
protected createTxExecutionRequestFromPayloadAndFee(executionPayload: ExecutionPayload, from: AztecAddress, feeOptions: FeeOptions): Promise<TxExecutionRequest>;
|
|
76
|
+
protected createTxExecutionRequestFromPayloadAndFee(executionPayload: ExecutionPayload, from: AztecAddress | NoFrom, feeOptions: FeeOptions): Promise<TxExecutionRequest>;
|
|
55
77
|
createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
|
|
56
78
|
/**
|
|
57
79
|
* Request capabilities from the wallet.
|
|
@@ -70,41 +92,30 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
70
92
|
batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
|
|
71
93
|
/**
|
|
72
94
|
* Completes partial user-provided fee options with wallet defaults.
|
|
73
|
-
* @param
|
|
74
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
75
|
-
* @param gasSettings - User-provided partial gas settings
|
|
76
|
-
* @returns - Complete fee options that can be used to create a transaction execution request
|
|
95
|
+
* @param config - Fee completion config.
|
|
77
96
|
*/
|
|
78
|
-
protected completeFeeOptions(
|
|
97
|
+
protected completeFeeOptions(config: CompleteFeeOptionsConfig): Promise<FeeOptions>;
|
|
79
98
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* to
|
|
83
|
-
* @param from - The address where the transaction is being sent from
|
|
84
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
85
|
-
* @param gasSettings - User-provided partial gas settings
|
|
99
|
+
* Returns the worst-case min fee across predicted future slots.
|
|
100
|
+
* Falls back to getCurrentMinFees if the node doesn't support getPredictedMinFees.
|
|
101
|
+
* @param estimate - The mana usage estimate to use for fee prediction. Defaults to Limit for conservative estimation.
|
|
86
102
|
*/
|
|
87
|
-
protected
|
|
88
|
-
/**
|
|
89
|
-
* A wallet-provided fallback fee payment method that is used only if the transaction that is being constructed
|
|
90
|
-
* doesn't already include one
|
|
91
|
-
*/
|
|
92
|
-
walletFeePaymentMethod?: FeePaymentMethod | undefined;
|
|
93
|
-
/** Configuration options for the account to properly handle the selected fee payment method */
|
|
94
|
-
accountFeePaymentMethodOptions: AccountFeePaymentMethodOptions;
|
|
95
|
-
gasSettings: GasSettings;
|
|
96
|
-
}>;
|
|
103
|
+
protected getMinFees(estimate?: ManaUsageEstimate): Promise<GasFees>;
|
|
97
104
|
registerSender(address: AztecAddress, _alias?: string): Promise<AztecAddress>;
|
|
98
105
|
registerContract(instance: ContractInstanceWithAddress, artifact?: ContractArtifact, secretKey?: Fr): Promise<ContractInstanceWithAddress>;
|
|
99
106
|
/**
|
|
100
107
|
* Simulates calls through the standard PXE path (account entrypoint).
|
|
101
108
|
* @param executionPayload - The execution payload to simulate.
|
|
102
|
-
* @param
|
|
103
|
-
* @param feeOptions - Fee options for the transaction.
|
|
104
|
-
* @param skipTxValidation - Whether to skip tx validation.
|
|
105
|
-
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
109
|
+
* @param opts - Simulation options.
|
|
106
110
|
*/
|
|
107
|
-
protected simulateViaEntrypoint(executionPayload: ExecutionPayload,
|
|
111
|
+
protected simulateViaEntrypoint(executionPayload: ExecutionPayload, opts: SimulateViaEntrypointOptions): Promise<TxSimulationResultWithAppOffset>;
|
|
112
|
+
/**
|
|
113
|
+
* Computes the index where the app's calls begin in the flattened array of calls (0 = entrypoint/root, 1..N = fee
|
|
114
|
+
* calls, N+1 = app).
|
|
115
|
+
* @param from - The sender address, or NO_FROM for the default entrypoint.
|
|
116
|
+
* @param feeOptions - Fee options containing the wallet fee payment method.
|
|
117
|
+
*/
|
|
118
|
+
protected computeAppCallOffset(from: AztecAddress | NoFrom, feeOptions: FeeOptions): Promise<number>;
|
|
108
119
|
/**
|
|
109
120
|
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
110
121
|
* on the node while sending the remaining calls through the standard PXE path.
|
|
@@ -113,15 +124,24 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
113
124
|
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
114
125
|
* @returns The merged simulation result.
|
|
115
126
|
*/
|
|
116
|
-
simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<
|
|
127
|
+
simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResultWithAppOffset>;
|
|
117
128
|
profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
|
|
118
129
|
sendTx<W extends InteractionWaitOptions = undefined>(executionPayload: ExecutionPayload, opts: SendOptions<W>): Promise<SendReturn<W>>;
|
|
130
|
+
/**
|
|
131
|
+
* Resolves a contract address to a human-readable name via PXE, if available.
|
|
132
|
+
* @param address - The contract address to resolve.
|
|
133
|
+
*/
|
|
134
|
+
protected getContractName(address: AztecAddress): Promise<string | undefined>;
|
|
119
135
|
protected contextualizeError(err: Error, ...context: string[]): Error;
|
|
120
|
-
|
|
136
|
+
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult>;
|
|
121
137
|
getPrivateEvents<T>(eventDef: EventMetadataDefinition, eventFilter: PrivateEventFilter): Promise<PrivateEvent<T>[]>;
|
|
138
|
+
/**
|
|
139
|
+
* Returns metadata about a contract, including whether it has been initialized, published, and updated.
|
|
140
|
+
* @param address - The contract address to query.
|
|
141
|
+
*/
|
|
122
142
|
getContractMetadata(address: AztecAddress): Promise<{
|
|
123
143
|
instance: ContractInstanceWithAddress | undefined;
|
|
124
|
-
|
|
144
|
+
initializationStatus: ContractInitializationStatus;
|
|
125
145
|
isContractPublished: boolean;
|
|
126
146
|
isContractUpdated: boolean;
|
|
127
147
|
updatedContractClassId: Fr | undefined;
|
|
@@ -131,4 +151,4 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
131
151
|
isContractClassPubliclyRegistered: boolean;
|
|
132
152
|
}>;
|
|
133
153
|
}
|
|
134
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
154
|
+
//# sour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sV0FBVyxDQUFDLENBQUMsQ0FBQyxHQUNuQixPQUFPLENBQUMsVUFBVSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBdUN4QjtJQUVEOzs7T0FHRztJQUNILFVBQWdCLGVBQWUsQ0FBQyxPQUFPLEVBQUUsWUFBWSxHQUFHLE9BQU8sQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFDLENBT2xGO0lBRUQsU0FBUyxDQUFDLGtCQUFrQixDQUFDLEdBQUcsRUFBRSxLQUFLLEVBQUUsR0FBRyxPQUFPLEVBQUUsTUFBTSxFQUFFLEdBQUcsS0FBSyxDQVlwRTtJQUVELGNBQWMsQ0FBQyxJQUFJLEVBQUUsWUFBWSxFQUFFLElBQUksRUFBRSxxQkFBcUIsR0FBRyxPQUFPLENBQUMsc0JBQXNCLENBQUMsQ0FFL0Y7SUFFSyxnQkFBZ0IsQ0FBQyxDQUFDLEVBQ3RCLFFBQVEsRUFBRSx1QkFBdUIsRUFDakMsV0FBVyxFQUFFLGtCQUFrQixHQUM5QixPQUFPLENBQUMsWUFBWSxDQUFDLENBQUMsQ0FBQyxFQUFFLENBQUMsQ0FlNUI7SUFFRDs7O09BR0c7SUFDRyxtQkFBbUIsQ0FBQyxPQUFPLEVBQUUsWUFBWTs7Ozs7O09BaUM5QztJQUVLLHdCQUF3QixDQUFDLEVBQUUsRUFBRSxFQUFFOzs7T0FNcEM7Q0FDRiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base_wallet.d.ts","sourceRoot":"","sources":["../../src/base-wallet/base_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"base_wallet.d.ts","sourceRoot":"","sources":["../../src/base-wallet/base_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,KAAK,EAAE,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AEK,wBAAwB,CAAC,EAAE,EAAE,EAAE;;;OAMpC;CACF"}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
2
|
+
import { NO_WAIT, extractOffchainOutput } from '@aztec/aztec.js/contracts';
|
|
2
3
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
3
|
-
import {
|
|
4
|
+
import { ContractInitializationStatus, TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
4
5
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
6
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
5
7
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
8
|
import { createLogger } from '@aztec/foundation/log';
|
|
9
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
7
10
|
import { decodeFromAbi } from '@aztec/stdlib/abi';
|
|
11
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
12
|
import { computePartialAddress, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
9
13
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
10
|
-
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
11
|
-
import {
|
|
14
|
+
import { Gas, GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
15
|
+
import { computeSiloedPrivateInitializationNullifier, computeSiloedPublicInitializationNullifier } from '@aztec/stdlib/hash';
|
|
12
16
|
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
13
17
|
import { inspect } from 'util';
|
|
14
18
|
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
@@ -20,14 +24,27 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
20
24
|
log;
|
|
21
25
|
minFeePadding;
|
|
22
26
|
cancellableTransactions;
|
|
27
|
+
// A wallet is instantiated for a particular chain, so chain info never changes during its lifetime.
|
|
28
|
+
// We cache it here because getChainInfo is called frequently (every tx simulation, send, auth wit, etc.).
|
|
29
|
+
nodeInfoPromise;
|
|
23
30
|
// Protected because we want to force wallets to instantiate their own PXE.
|
|
24
|
-
constructor(pxe, aztecNode){
|
|
31
|
+
constructor(pxe, aztecNode, log = createLogger('wallet-sdk:base_wallet')){
|
|
25
32
|
this.pxe = pxe;
|
|
26
33
|
this.aztecNode = aztecNode;
|
|
27
|
-
this.log =
|
|
34
|
+
this.log = log;
|
|
28
35
|
this.minFeePadding = 0.5;
|
|
29
36
|
this.cancellableTransactions = false;
|
|
30
37
|
}
|
|
38
|
+
scopesFrom(from, additionalScopes = []) {
|
|
39
|
+
const allScopes = from === NO_FROM ? additionalScopes : [
|
|
40
|
+
from,
|
|
41
|
+
...additionalScopes
|
|
42
|
+
];
|
|
43
|
+
const scopeSet = new Set(allScopes.map((address)=>address.toString()));
|
|
44
|
+
return [
|
|
45
|
+
...scopeSet
|
|
46
|
+
].map(AztecAddress.fromString);
|
|
47
|
+
}
|
|
31
48
|
/**
|
|
32
49
|
* Returns the list of aliased contacts associated with the wallet.
|
|
33
50
|
* This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
|
|
@@ -42,7 +59,10 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
42
59
|
}));
|
|
43
60
|
}
|
|
44
61
|
async getChainInfo() {
|
|
45
|
-
|
|
62
|
+
if (!this.nodeInfoPromise) {
|
|
63
|
+
this.nodeInfoPromise = this.aztecNode.getNodeInfo();
|
|
64
|
+
}
|
|
65
|
+
const { l1ChainId, rollupVersion } = await this.nodeInfoPromise;
|
|
46
66
|
return {
|
|
47
67
|
chainId: new Fr(l1ChainId),
|
|
48
68
|
version: new Fr(rollupVersion)
|
|
@@ -50,18 +70,24 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
50
70
|
}
|
|
51
71
|
async createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions) {
|
|
52
72
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
53
|
-
const executionOptions = {
|
|
54
|
-
txNonce: Fr.random(),
|
|
55
|
-
cancellable: this.cancellableTransactions,
|
|
56
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
57
|
-
};
|
|
58
73
|
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
59
74
|
feeExecutionPayload,
|
|
60
75
|
executionPayload
|
|
61
76
|
]) : executionPayload;
|
|
62
|
-
const fromAccount = await this.getAccountFromAddress(from);
|
|
63
77
|
const chainInfo = await this.getChainInfo();
|
|
64
|
-
|
|
78
|
+
if (from === NO_FROM) {
|
|
79
|
+
const entrypoint = new DefaultEntrypoint();
|
|
80
|
+
return entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
81
|
+
} else {
|
|
82
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
83
|
+
const executionOptions = {
|
|
84
|
+
txNonce: Fr.random(),
|
|
85
|
+
cancellable: this.cancellableTransactions,
|
|
86
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
87
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
88
|
+
};
|
|
89
|
+
return fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
90
|
+
}
|
|
65
91
|
}
|
|
66
92
|
async createAuthWit(from, messageHashOrIntent) {
|
|
67
93
|
const account = await this.getAccountFromAddress(from);
|
|
@@ -104,26 +130,33 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
104
130
|
}
|
|
105
131
|
/**
|
|
106
132
|
* Completes partial user-provided fee options with wallet defaults.
|
|
107
|
-
* @param
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
*/ async completeFeeOptions(from, feePayer, gasSettings) {
|
|
112
|
-
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
|
|
133
|
+
* @param config - Fee completion config.
|
|
134
|
+
*/ async completeFeeOptions(config) {
|
|
135
|
+
const { from, feePayer, gasSettings, forEstimation, congestionEstimate } = config;
|
|
136
|
+
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.getMinFees(congestionEstimate)).mul(1 + this.minFeePadding);
|
|
113
137
|
let accountFeePaymentMethodOptions;
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
138
|
+
// If from is an address, we need to determine the appropriate fee payment method options for the
|
|
139
|
+
// account contract entrypoint to use
|
|
140
|
+
if (from !== NO_FROM) {
|
|
141
|
+
if (!feePayer) {
|
|
142
|
+
// The transaction does not include a fee payment method, so we set the flag
|
|
143
|
+
// for the account to use its fee juice balance
|
|
144
|
+
accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
|
|
145
|
+
} else {
|
|
146
|
+
// The transaction includes fee payment method, so we check if we are the fee payer for it
|
|
147
|
+
// (this can only happen if the embedded payment method is FeeJuiceWithClaim)
|
|
148
|
+
accountFeePaymentMethodOptions = from.equals(feePayer) ? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM : AccountFeePaymentMethodOptions.EXTERNAL;
|
|
149
|
+
}
|
|
122
150
|
}
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
151
|
+
const gasSettingsOverrides = {
|
|
152
|
+
gasLimits: gasSettings?.gasLimits ? Gas.from(gasSettings.gasLimits) : undefined,
|
|
153
|
+
teardownGasLimits: gasSettings?.teardownGasLimits ? Gas.from(gasSettings.teardownGasLimits) : undefined,
|
|
154
|
+
maxFeesPerGas,
|
|
155
|
+
maxPriorityFeesPerGas: gasSettings?.maxPriorityFeesPerGas ?? GasFees.empty()
|
|
156
|
+
};
|
|
157
|
+
// When estimating gas (simulation), use high limits so the simulation doesn't run out of gas.
|
|
158
|
+
// When sending for real, use protocol max limits that the network will actually accept.
|
|
159
|
+
const fullGasSettings = forEstimation ? GasSettings.forEstimation(gasSettingsOverrides) : GasSettings.fallback(gasSettingsOverrides);
|
|
127
160
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
128
161
|
return {
|
|
129
162
|
gasSettings: fullGasSettings,
|
|
@@ -132,22 +165,24 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
132
165
|
};
|
|
133
166
|
}
|
|
134
167
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* to
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
168
|
+
* Returns the worst-case min fee across predicted future slots.
|
|
169
|
+
* Falls back to getCurrentMinFees if the node doesn't support getPredictedMinFees.
|
|
170
|
+
* @param estimate - The mana usage estimate to use for fee prediction. Defaults to Limit for conservative estimation.
|
|
171
|
+
*/ async getMinFees(estimate = ManaUsageEstimate.Limit) {
|
|
172
|
+
try {
|
|
173
|
+
const predicted = await this.aztecNode.getPredictedMinFees(estimate);
|
|
174
|
+
if (predicted.length === 0) {
|
|
175
|
+
return this.aztecNode.getCurrentMinFees();
|
|
176
|
+
}
|
|
177
|
+
return predicted.reduce((worst, fees)=>fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst);
|
|
178
|
+
} catch (err) {
|
|
179
|
+
// Fallback for old nodes that don't support getPredictedMinFees.
|
|
180
|
+
// Only fall back on method-not-found errors (JSON-RPC code -32601); rethrow others.
|
|
181
|
+
if (err?.cause?.code === -32601 || err?.message?.includes('Method not found')) {
|
|
182
|
+
return this.aztecNode.getCurrentMinFees();
|
|
183
|
+
}
|
|
184
|
+
throw err;
|
|
185
|
+
}
|
|
151
186
|
}
|
|
152
187
|
registerSender(address, _alias = '') {
|
|
153
188
|
return this.pxe.registerSender(address);
|
|
@@ -187,17 +222,29 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
187
222
|
/**
|
|
188
223
|
* Simulates calls through the standard PXE path (account entrypoint).
|
|
189
224
|
* @param executionPayload - The execution payload to simulate.
|
|
190
|
-
* @param
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
*/ async simulateViaEntrypoint(executionPayload, from, feeOptions, skipTxValidation, skipFeeEnforcement) {
|
|
195
|
-
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions);
|
|
196
|
-
return this.pxe.simulateTx(txRequest, {
|
|
225
|
+
* @param opts - Simulation options.
|
|
226
|
+
*/ async simulateViaEntrypoint(executionPayload, opts) {
|
|
227
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, opts.feeOptions);
|
|
228
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
197
229
|
simulatePublic: true,
|
|
198
|
-
skipTxValidation,
|
|
199
|
-
skipFeeEnforcement
|
|
230
|
+
skipTxValidation: opts.skipTxValidation,
|
|
231
|
+
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
232
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes)
|
|
200
233
|
});
|
|
234
|
+
const appCallOffset = await this.computeAppCallOffset(opts.from, opts.feeOptions);
|
|
235
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Computes the index where the app's calls begin in the flattened array of calls (0 = entrypoint/root, 1..N = fee
|
|
239
|
+
* calls, N+1 = app).
|
|
240
|
+
* @param from - The sender address, or NO_FROM for the default entrypoint.
|
|
241
|
+
* @param feeOptions - Fee options containing the wallet fee payment method.
|
|
242
|
+
*/ async computeAppCallOffset(from, feeOptions) {
|
|
243
|
+
if (from === NO_FROM) {
|
|
244
|
+
return 0;
|
|
245
|
+
}
|
|
246
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
247
|
+
return (feeExecutionPayload?.calls.length ?? 0) + 1; // +1 for entrypoint
|
|
201
248
|
}
|
|
202
249
|
/**
|
|
203
250
|
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
@@ -207,32 +254,64 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
207
254
|
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
208
255
|
* @returns The merged simulation result.
|
|
209
256
|
*/ async simulateTx(executionPayload, opts) {
|
|
210
|
-
const feeOptions =
|
|
257
|
+
const feeOptions = await this.completeFeeOptions({
|
|
258
|
+
from: opts.from,
|
|
259
|
+
feePayer: executionPayload.feePayer,
|
|
260
|
+
gasSettings: opts.fee?.gasSettings,
|
|
261
|
+
forEstimation: true,
|
|
262
|
+
congestionEstimate: opts.fee?.congestionEstimate
|
|
263
|
+
});
|
|
211
264
|
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
212
265
|
const remainingPayload = {
|
|
213
266
|
...executionPayload,
|
|
214
267
|
calls: remainingCalls
|
|
215
268
|
};
|
|
216
269
|
const chainInfo = await this.getChainInfo();
|
|
217
|
-
|
|
270
|
+
let blockHeader;
|
|
271
|
+
// PXE might not be synced yet, so we pull the latest header from the node
|
|
272
|
+
// To keep things consistent, we'll always try with PXE first
|
|
273
|
+
try {
|
|
274
|
+
blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
275
|
+
} catch {
|
|
276
|
+
blockHeader = await this.aztecNode.getBlockHeader();
|
|
277
|
+
}
|
|
278
|
+
const simulationOrigin = opts.from === NO_FROM ? AztecAddress.ZERO : opts.from;
|
|
218
279
|
const [optimizedResults, normalResult] = await Promise.all([
|
|
219
|
-
optimizableCalls.length > 0 ? simulateViaNode(this.aztecNode, optimizableCalls,
|
|
220
|
-
remainingCalls.length > 0 ? this.simulateViaEntrypoint(remainingPayload,
|
|
280
|
+
optimizableCalls.length > 0 ? simulateViaNode(this.aztecNode, optimizableCalls, simulationOrigin, chainInfo, feeOptions.gasSettings, blockHeader, opts.skipFeeEnforcement ?? true, this.getContractName.bind(this)) : Promise.resolve([]),
|
|
281
|
+
remainingCalls.length > 0 ? this.simulateViaEntrypoint(remainingPayload, {
|
|
282
|
+
from: opts.from,
|
|
283
|
+
feeOptions,
|
|
284
|
+
additionalScopes: opts.additionalScopes,
|
|
285
|
+
skipTxValidation: opts.skipTxValidation,
|
|
286
|
+
skipFeeEnforcement: opts.skipFeeEnforcement ?? true
|
|
287
|
+
}) : Promise.resolve(null)
|
|
221
288
|
]);
|
|
222
289
|
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
223
290
|
}
|
|
224
291
|
async profileTx(executionPayload, opts) {
|
|
225
|
-
const feeOptions = await this.completeFeeOptions(
|
|
292
|
+
const feeOptions = await this.completeFeeOptions({
|
|
293
|
+
from: opts.from,
|
|
294
|
+
feePayer: executionPayload.feePayer,
|
|
295
|
+
gasSettings: opts.fee?.gasSettings,
|
|
296
|
+
congestionEstimate: opts.fee?.congestionEstimate
|
|
297
|
+
});
|
|
226
298
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
227
299
|
return this.pxe.profileTx(txRequest, {
|
|
228
300
|
profileMode: opts.profileMode,
|
|
229
|
-
skipProofGeneration: opts.skipProofGeneration ?? true
|
|
301
|
+
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
302
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes)
|
|
230
303
|
});
|
|
231
304
|
}
|
|
232
305
|
async sendTx(executionPayload, opts) {
|
|
233
|
-
const feeOptions = await this.completeFeeOptions(
|
|
306
|
+
const feeOptions = await this.completeFeeOptions({
|
|
307
|
+
from: opts.from,
|
|
308
|
+
feePayer: executionPayload.feePayer,
|
|
309
|
+
gasSettings: opts.fee?.gasSettings,
|
|
310
|
+
congestionEstimate: opts.fee?.congestionEstimate
|
|
311
|
+
});
|
|
234
312
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
235
|
-
const provenTx = await this.pxe.proveTx(txRequest);
|
|
313
|
+
const provenTx = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
|
|
314
|
+
const offchainOutput = extractOffchainOutput(provenTx.getOffchainEffects(), provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp);
|
|
236
315
|
const tx = await provenTx.toTx();
|
|
237
316
|
const txHash = tx.getTxHash();
|
|
238
317
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -245,11 +324,33 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
245
324
|
this.log.info(`Sent transaction ${txHash}`);
|
|
246
325
|
// If wait is NO_WAIT, return txHash immediately
|
|
247
326
|
if (opts.wait === NO_WAIT) {
|
|
248
|
-
return
|
|
327
|
+
return {
|
|
328
|
+
txHash,
|
|
329
|
+
...offchainOutput
|
|
330
|
+
};
|
|
249
331
|
}
|
|
250
332
|
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
251
333
|
const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
252
|
-
|
|
334
|
+
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
335
|
+
// Display debug logs from public execution if present (served in test mode only)
|
|
336
|
+
if (receipt.debugLogs?.length) {
|
|
337
|
+
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
338
|
+
}
|
|
339
|
+
return {
|
|
340
|
+
receipt,
|
|
341
|
+
...offchainOutput
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Resolves a contract address to a human-readable name via PXE, if available.
|
|
346
|
+
* @param address - The contract address to resolve.
|
|
347
|
+
*/ async getContractName(address) {
|
|
348
|
+
const instance = await this.pxe.getContractInstance(address);
|
|
349
|
+
if (!instance) {
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
352
|
+
const artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
353
|
+
return artifact?.name;
|
|
253
354
|
}
|
|
254
355
|
contextualizeError(err, ...context) {
|
|
255
356
|
let contextStr = '';
|
|
@@ -264,9 +365,10 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
264
365
|
}
|
|
265
366
|
return err;
|
|
266
367
|
}
|
|
267
|
-
|
|
268
|
-
return this.pxe.
|
|
269
|
-
authwits
|
|
368
|
+
executeUtility(call, opts) {
|
|
369
|
+
return this.pxe.executeUtility(call, {
|
|
370
|
+
authwits: opts.authWitnesses,
|
|
371
|
+
scopes: opts.scopes
|
|
270
372
|
});
|
|
271
373
|
}
|
|
272
374
|
async getPrivateEvents(eventDef, eventFilter) {
|
|
@@ -285,15 +387,33 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
285
387
|
});
|
|
286
388
|
return decodedEvents;
|
|
287
389
|
}
|
|
288
|
-
|
|
390
|
+
/**
|
|
391
|
+
* Returns metadata about a contract, including whether it has been initialized, published, and updated.
|
|
392
|
+
* @param address - The contract address to query.
|
|
393
|
+
*/ async getContractMetadata(address) {
|
|
289
394
|
const instance = await this.pxe.getContractInstance(address);
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
395
|
+
const publiclyRegisteredContractPromise = this.aztecNode.getContract(address);
|
|
396
|
+
let initializationStatus;
|
|
397
|
+
if (instance) {
|
|
398
|
+
// We have the instance, so we can compute the private initialization nullifier (which includes init_hash and is
|
|
399
|
+
// emitted by both private and public initializers) and get a definitive INITIALIZED/UNINITIALIZED answer.
|
|
400
|
+
const initNullifier = await computeSiloedPrivateInitializationNullifier(address, instance.initializationHash);
|
|
401
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
402
|
+
initializationStatus = witness ? ContractInitializationStatus.INITIALIZED : ContractInitializationStatus.UNINITIALIZED;
|
|
403
|
+
} else {
|
|
404
|
+
// Without the instance we lack the init_hash needed for the private nullifier. We fall back to checking the
|
|
405
|
+
// public initialization nullifier (computed from address alone). Not all contracts emit it (only those with
|
|
406
|
+
// public functions that require initialization checks), so its absence doesn't mean the contract is
|
|
407
|
+
// uninitialized.
|
|
408
|
+
const publicNullifier = await computeSiloedPublicInitializationNullifier(address);
|
|
409
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', publicNullifier);
|
|
410
|
+
initializationStatus = witness ? ContractInitializationStatus.INITIALIZED : ContractInitializationStatus.UNKNOWN;
|
|
411
|
+
}
|
|
412
|
+
const publiclyRegisteredContract = await publiclyRegisteredContractPromise;
|
|
293
413
|
const isContractUpdated = publiclyRegisteredContract && !publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
294
414
|
return {
|
|
295
415
|
instance: instance ?? undefined,
|
|
296
|
-
|
|
416
|
+
initializationStatus,
|
|
297
417
|
isContractPublished: !!publiclyRegisteredContract,
|
|
298
418
|
isContractUpdated: !!isContractUpdated,
|
|
299
419
|
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { BaseWallet, type FeeOptions } from './base_wallet.js';
|
|
1
|
+
export { BaseWallet, type CompleteFeeOptionsConfig, type FeeOptions, type SimulateViaEntrypointOptions, } from './base_wallet.js';
|
|
2
2
|
export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsVUFBVSxFQUNWLEtBQUssd0JBQXdCLEVBQzdCLEtBQUssVUFBVSxFQUNmLEtBQUssNEJBQTRCLEdBQ2xDLE1BQU0sa0JBQWtCLENBQUM7QUFDMUIsT0FBTyxFQUFFLGVBQWUsRUFBRSwyQkFBMkIsRUFBRSxtQ0FBbUMsRUFBRSxNQUFNLFlBQVksQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EACf,KAAK,4BAA4B,GAClC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,mCAAmC,EAAE,MAAM,YAAY,CAAC"}
|