@aztec/aztec.js 0.80.0 → 0.82.0
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/account/{contract.d.ts → account_contract.d.ts} +11 -5
- package/dest/account/account_contract.d.ts.map +1 -0
- package/dest/account/{contract.js → account_contract.js} +5 -1
- package/dest/account/index.d.ts +2 -3
- package/dest/account/index.d.ts.map +1 -1
- package/dest/account/index.js +1 -2
- package/dest/account/interface.d.ts +1 -13
- package/dest/account/interface.d.ts.map +1 -1
- package/dest/account/interface.js +1 -0
- package/dest/account_manager/account_manager.d.ts +105 -0
- package/dest/account_manager/account_manager.d.ts.map +1 -0
- package/dest/account_manager/account_manager.js +165 -0
- package/dest/account_manager/deploy_account_method.d.ts +4 -4
- package/dest/account_manager/deploy_account_method.d.ts.map +1 -1
- package/dest/account_manager/deploy_account_method.js +28 -13
- package/dest/account_manager/deploy_account_sent_tx.d.ts +3 -3
- package/dest/account_manager/deploy_account_sent_tx.d.ts.map +1 -1
- package/dest/account_manager/deploy_account_sent_tx.js +2 -2
- package/dest/account_manager/index.d.ts +1 -104
- package/dest/account_manager/index.d.ts.map +1 -1
- package/dest/account_manager/index.js +1 -157
- package/dest/api/account.d.ts +2 -1
- package/dest/api/account.d.ts.map +1 -1
- package/dest/api/contract.d.ts +4 -1
- package/dest/api/contract.d.ts.map +1 -1
- package/dest/api/contract.js +3 -0
- package/dest/api/fee.d.ts +1 -1
- package/dest/api/fee.d.ts.map +1 -1
- package/dest/api/utils.d.ts +2 -1
- package/dest/api/utils.d.ts.map +1 -1
- package/dest/api/utils.js +2 -1
- package/dest/api/wallet.d.ts +1 -1
- package/dest/api/wallet.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.d.ts +22 -57
- package/dest/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.js +12 -67
- package/dest/contract/batch_call.d.ts +6 -18
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +25 -54
- package/dest/contract/contract.d.ts +1 -1
- package/dest/contract/contract.d.ts.map +1 -1
- package/dest/contract/contract_base.d.ts +2 -2
- package/dest/contract/contract_base.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.d.ts +38 -18
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +34 -41
- package/dest/contract/deploy_method.d.ts +7 -8
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +27 -32
- package/dest/contract/deploy_proven_tx.d.ts +2 -3
- package/dest/contract/deploy_proven_tx.d.ts.map +1 -1
- package/dest/contract/deploy_sent_tx.d.ts +2 -3
- package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
- package/dest/contract/deploy_sent_tx.js +4 -4
- package/dest/contract/protocol_contracts.d.ts +1 -1
- package/dest/contract/protocol_contracts.d.ts.map +1 -1
- package/dest/contract/proven_tx.d.ts +3 -4
- package/dest/contract/proven_tx.d.ts.map +1 -1
- package/dest/contract/sent_tx.d.ts +4 -16
- package/dest/contract/sent_tx.d.ts.map +1 -1
- package/dest/contract/sent_tx.js +6 -37
- package/dest/contract/unsafe_contract.d.ts +1 -1
- package/dest/contract/unsafe_contract.d.ts.map +1 -1
- package/dest/contract/wait_for_proven.d.ts +17 -0
- package/dest/contract/wait_for_proven.d.ts.map +1 -0
- package/dest/contract/wait_for_proven.js +17 -0
- package/dest/deployment/broadcast_function.js +12 -8
- package/dest/deployment/contract_deployer.d.ts +1 -1
- package/dest/deployment/contract_deployer.d.ts.map +1 -1
- package/dest/deployment/register_class.d.ts +1 -1
- package/dest/deployment/register_class.d.ts.map +1 -1
- package/dest/deployment/register_class.js +6 -11
- package/dest/entrypoint/default_multi_call_entrypoint.d.ts +3 -2
- package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +1 -1
- package/dest/entrypoint/default_multi_call_entrypoint.js +12 -8
- package/dest/ethereum/portal_manager.d.ts +20 -11
- package/dest/ethereum/portal_manager.d.ts.map +1 -1
- package/dest/ethereum/portal_manager.js +64 -30
- package/dest/fee/fee_juice_payment_method.d.ts +3 -3
- package/dest/fee/fee_juice_payment_method.d.ts.map +1 -1
- package/dest/fee/fee_juice_payment_method.js +3 -2
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts +4 -4
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -1
- package/dest/fee/fee_juice_payment_method_with_claim.js +6 -5
- package/dest/fee/private_fee_payment_method.d.ts +6 -6
- package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/private_fee_payment_method.js +13 -12
- package/dest/fee/public_fee_payment_method.d.ts +7 -7
- package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/public_fee_payment_method.js +10 -11
- package/dest/fee/utils.d.ts +13 -0
- package/dest/fee/utils.d.ts.map +1 -0
- package/dest/fee/utils.js +32 -0
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/test/aztec_cheat_codes.d.ts +2 -2
- package/dest/test/aztec_cheat_codes.d.ts.map +1 -1
- package/dest/test/aztec_cheat_codes.js +3 -3
- package/dest/utils/authwit.d.ts +16 -9
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +26 -35
- package/dest/wallet/account_wallet.d.ts +6 -6
- package/dest/wallet/account_wallet.d.ts.map +1 -1
- package/dest/wallet/account_wallet.js +15 -17
- package/dest/wallet/base_wallet.d.ts +12 -35
- package/dest/wallet/base_wallet.d.ts.map +1 -1
- package/dest/wallet/base_wallet.js +11 -64
- package/dest/wallet/index.d.ts +2 -2
- package/dest/wallet/index.d.ts.map +1 -1
- package/dest/wallet/index.js +1 -1
- package/dest/wallet/signerless_wallet.d.ts +3 -3
- package/dest/wallet/signerless_wallet.d.ts.map +1 -1
- package/dest/wallet/signerless_wallet.js +3 -6
- package/dest/wallet/wallet.d.ts +11 -0
- package/dest/wallet/wallet.d.ts.map +1 -0
- package/package.json +8 -7
- package/src/account/{contract.ts → account_contract.ts} +17 -4
- package/src/account/index.ts +2 -3
- package/src/account/interface.ts +1 -12
- package/src/account_manager/account_manager.ts +235 -0
- package/src/account_manager/deploy_account_method.ts +35 -15
- package/src/account_manager/deploy_account_sent_tx.ts +4 -4
- package/src/account_manager/index.ts +1 -227
- package/src/api/account.ts +2 -8
- package/src/api/contract.ts +5 -5
- package/src/api/fee.ts +1 -1
- package/src/api/utils.ts +1 -1
- package/src/api/wallet.ts +7 -1
- package/src/contract/base_contract_interaction.ts +32 -88
- package/src/contract/batch_call.ts +40 -43
- package/src/contract/contract.ts +1 -1
- package/src/contract/contract_base.ts +1 -1
- package/src/contract/contract_function_interaction.ts +85 -56
- package/src/contract/deploy_method.ts +24 -26
- package/src/contract/deploy_proven_tx.ts +2 -3
- package/src/contract/deploy_sent_tx.ts +6 -6
- package/src/contract/protocol_contracts.ts +1 -1
- package/src/contract/proven_tx.ts +2 -3
- package/src/contract/sent_tx.ts +6 -47
- package/src/contract/unsafe_contract.ts +1 -1
- package/src/contract/wait_for_proven.ts +38 -0
- package/src/deployment/broadcast_function.ts +40 -40
- package/src/deployment/contract_deployer.ts +1 -1
- package/src/deployment/register_class.ts +9 -22
- package/src/entrypoint/default_multi_call_entrypoint.ts +14 -7
- package/src/ethereum/portal_manager.ts +73 -24
- package/src/fee/fee_juice_payment_method.ts +4 -5
- package/src/fee/fee_juice_payment_method_with_claim.ts +24 -20
- package/src/fee/private_fee_payment_method.ts +29 -28
- package/src/fee/public_fee_payment_method.ts +29 -29
- package/src/fee/utils.ts +39 -0
- package/src/index.ts +1 -1
- package/src/test/aztec_cheat_codes.ts +3 -3
- package/src/utils/authwit.ts +32 -35
- package/src/wallet/account_wallet.ts +18 -17
- package/src/wallet/base_wallet.ts +27 -88
- package/src/wallet/index.ts +2 -2
- package/src/wallet/signerless_wallet.ts +9 -8
- package/src/wallet/wallet.ts +34 -0
- package/dest/account/contract.d.ts.map +0 -1
- package/dest/account/wallet.d.ts +0 -11
- package/dest/account/wallet.d.ts.map +0 -1
- package/dest/api/entrypoint.d.ts +0 -2
- package/dest/api/entrypoint.d.ts.map +0 -1
- package/dest/api/entrypoint.js +0 -1
- package/dest/entrypoint/default_entrypoint.d.ts +0 -12
- package/dest/entrypoint/default_entrypoint.d.ts.map +0 -1
- package/dest/entrypoint/default_entrypoint.js +0 -28
- package/dest/entrypoint/entrypoint.d.ts +0 -39
- package/dest/entrypoint/entrypoint.d.ts.map +0 -1
- package/dest/entrypoint/entrypoint.js +0 -20
- package/dest/entrypoint/payload.d.ts +0 -128
- package/dest/entrypoint/payload.d.ts.map +0 -1
- package/dest/entrypoint/payload.js +0 -143
- package/dest/fee/fee_payment_method.d.ts +0 -22
- package/dest/fee/fee_payment_method.d.ts.map +0 -1
- package/dest/fee/fee_payment_method.js +0 -3
- package/src/account/wallet.ts +0 -13
- package/src/api/entrypoint.ts +0 -1
- package/src/entrypoint/default_entrypoint.ts +0 -39
- package/src/entrypoint/entrypoint.ts +0 -60
- package/src/entrypoint/payload.ts +0 -238
- package/src/fee/fee_payment_method.ts +0 -22
- /package/dest/{account → wallet}/wallet.js +0 -0
package/src/api/contract.ts
CHANGED
|
@@ -36,12 +36,11 @@
|
|
|
36
36
|
* @packageDocumentation
|
|
37
37
|
*/
|
|
38
38
|
export { Contract } from '../contract/contract.js';
|
|
39
|
-
export {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
type SendMethodOptions,
|
|
43
|
-
} from '../contract/contract_function_interaction.js';
|
|
39
|
+
export { ContractFunctionInteraction, type SendMethodOptions } from '../contract/contract_function_interaction.js';
|
|
40
|
+
|
|
41
|
+
export { TxProfileResult } from '@aztec/stdlib/tx';
|
|
44
42
|
export { DefaultWaitOpts, SentTx, type WaitOpts } from '../contract/sent_tx.js';
|
|
43
|
+
export { ProvenTx } from '../contract/proven_tx.js';
|
|
45
44
|
export {
|
|
46
45
|
ContractBase,
|
|
47
46
|
type ContractMethod,
|
|
@@ -51,6 +50,7 @@ export {
|
|
|
51
50
|
export { BatchCall } from '../contract/batch_call.js';
|
|
52
51
|
export { type DeployOptions, DeployMethod } from '../contract/deploy_method.js';
|
|
53
52
|
export { DeploySentTx } from '../contract/deploy_sent_tx.js';
|
|
53
|
+
export { waitForProven, type WaitForProvenOpts, DefaultWaitForProvenOpts } from '../contract/wait_for_proven.js';
|
|
54
54
|
|
|
55
55
|
export {
|
|
56
56
|
type PartialAddress,
|
package/src/api/fee.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { FeePaymentMethod } from '
|
|
1
|
+
export type { FeePaymentMethod } from '@aztec/entrypoints/interfaces';
|
|
2
2
|
export { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js';
|
|
3
3
|
export { PrivateFeePaymentMethod } from '../fee/private_fee_payment_method.js';
|
|
4
4
|
export { PublicFeePaymentMethod } from '../fee/public_fee_payment_method.js';
|
package/src/api/utils.ts
CHANGED
|
@@ -10,11 +10,11 @@ export {
|
|
|
10
10
|
} from '../utils/abi_types.js';
|
|
11
11
|
export {
|
|
12
12
|
computeAuthWitMessageHash,
|
|
13
|
-
computeInnerAuthWitHash,
|
|
14
13
|
computeInnerAuthWitHashFromAction,
|
|
15
14
|
type IntentAction,
|
|
16
15
|
type IntentInnerHash,
|
|
17
16
|
} from '../utils/authwit.js';
|
|
17
|
+
export { computeInnerAuthWitHash } from '@aztec/stdlib/auth-witness';
|
|
18
18
|
export { waitForPXE } from '../utils/pxe.js';
|
|
19
19
|
export { waitForNode, createAztecNodeClient, type AztecNode } from '../utils/node.js';
|
|
20
20
|
export { getFeeJuiceBalance } from '../utils/fee_juice.js';
|
package/src/api/wallet.ts
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
|
+
import type { FeeOptions, TxExecutionOptions, UserFeeOptions } from '@aztec/entrypoints/interfaces';
|
|
2
|
+
import type { ExecutionPayload } from '@aztec/entrypoints/payload';
|
|
1
3
|
import type { Fr } from '@aztec/foundation/fields';
|
|
2
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
5
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
4
6
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
5
|
-
import type { Capsule,
|
|
7
|
+
import type { Capsule, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx';
|
|
6
8
|
|
|
7
|
-
import type { Wallet } from '../account/wallet.js';
|
|
8
|
-
import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js';
|
|
9
|
-
import type { FeeOptions, UserFeeOptions } from '../entrypoint/payload.js';
|
|
10
9
|
import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js';
|
|
10
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
11
11
|
import { getGasLimits } from './get_gas_limits.js';
|
|
12
12
|
import { ProvenTx } from './proven_tx.js';
|
|
13
13
|
import { SentTx } from './sent_tx.js';
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Represents the options to configure a request from a contract interaction.
|
|
17
|
+
* Allows specifying additional auth witnesses and capsules to use during execution
|
|
18
|
+
*/
|
|
19
|
+
export type RequestMethodOptions = {
|
|
20
|
+
/** Extra authwits to use during execution */
|
|
21
|
+
authWitnesses?: AuthWitness[];
|
|
22
|
+
/** Extra capsules to use during execution */
|
|
23
|
+
capsules?: Capsule[];
|
|
24
|
+
};
|
|
25
|
+
|
|
15
26
|
/**
|
|
16
27
|
* Represents options for calling a (constrained) function in a contract.
|
|
17
|
-
* Allows the user to specify the sender address and nonce for a transaction.
|
|
18
28
|
*/
|
|
19
|
-
export type SendMethodOptions = {
|
|
29
|
+
export type SendMethodOptions = RequestMethodOptions & {
|
|
20
30
|
/** Wether to skip the simulation of the public part of the transaction. */
|
|
21
31
|
skipPublicSimulation?: boolean;
|
|
22
32
|
/** The fee options for the transaction. */
|
|
@@ -34,11 +44,11 @@ export type SendMethodOptions = {
|
|
|
34
44
|
export abstract class BaseContractInteraction {
|
|
35
45
|
protected log = createLogger('aztecjs:contract_interaction');
|
|
36
46
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
constructor(
|
|
48
|
+
protected wallet: Wallet,
|
|
49
|
+
protected authWitnesses: AuthWitness[] = [],
|
|
50
|
+
protected capsules: Capsule[] = [],
|
|
51
|
+
) {}
|
|
42
52
|
|
|
43
53
|
/**
|
|
44
54
|
* Create a transaction execution request ready to be simulated.
|
|
@@ -53,7 +63,7 @@ export abstract class BaseContractInteraction {
|
|
|
53
63
|
* @param options - An optional object containing additional configuration for the transaction.
|
|
54
64
|
* @returns An execution request wrapped in promise.
|
|
55
65
|
*/
|
|
56
|
-
public abstract request(options?:
|
|
66
|
+
public abstract request(options?: RequestMethodOptions): Promise<ExecutionPayload>;
|
|
57
67
|
|
|
58
68
|
/**
|
|
59
69
|
* Creates a transaction execution request, simulates and proves it. Differs from .prove in
|
|
@@ -141,23 +151,26 @@ export abstract class BaseContractInteraction {
|
|
|
141
151
|
// docs:start:getFeeOptions
|
|
142
152
|
/**
|
|
143
153
|
* Return fee options based on the user opts, estimating tx gas if needed.
|
|
144
|
-
* @param
|
|
145
|
-
* @param
|
|
154
|
+
* @param executionPayload - Execution payload to get the fee for
|
|
155
|
+
* @param fee - User-provided fee options.
|
|
156
|
+
* @param options - Additional options for the transaction. They must faithfully represent the tx to get accurate fee estimates
|
|
146
157
|
* @returns Fee options for the actual transaction.
|
|
147
158
|
*/
|
|
148
159
|
protected async getFeeOptions(
|
|
149
|
-
|
|
160
|
+
executionPayload: ExecutionPayload,
|
|
161
|
+
fee: UserFeeOptions = {},
|
|
162
|
+
options: TxExecutionOptions,
|
|
150
163
|
): Promise<FeeOptions> {
|
|
151
164
|
// docs:end:getFeeOptions
|
|
152
|
-
const defaultFeeOptions = await this.getDefaultFeeOptions(
|
|
165
|
+
const defaultFeeOptions = await this.getDefaultFeeOptions(fee);
|
|
153
166
|
const paymentMethod = defaultFeeOptions.paymentMethod;
|
|
154
167
|
const maxFeesPerGas = defaultFeeOptions.gasSettings.maxFeesPerGas;
|
|
155
168
|
const maxPriorityFeesPerGas = defaultFeeOptions.gasSettings.maxPriorityFeesPerGas;
|
|
156
169
|
|
|
157
170
|
let gasSettings = defaultFeeOptions.gasSettings;
|
|
158
|
-
if (
|
|
171
|
+
if (fee?.estimateGas) {
|
|
159
172
|
const feeForEstimation: FeeOptions = { paymentMethod, gasSettings };
|
|
160
|
-
const txRequest = await this.wallet.createTxExecutionRequest(
|
|
173
|
+
const txRequest = await this.wallet.createTxExecutionRequest(executionPayload, feeForEstimation, options);
|
|
161
174
|
const simulationResult = await this.wallet.simulateTx(
|
|
162
175
|
txRequest,
|
|
163
176
|
true /*simulatePublic*/,
|
|
@@ -167,7 +180,7 @@ export abstract class BaseContractInteraction {
|
|
|
167
180
|
);
|
|
168
181
|
const { totalGas: gasLimits, teardownGas: teardownGasLimits } = getGasLimits(
|
|
169
182
|
simulationResult,
|
|
170
|
-
|
|
183
|
+
fee?.estimatedGasPadding,
|
|
171
184
|
);
|
|
172
185
|
gasSettings = GasSettings.from({ maxFeesPerGas, maxPriorityFeesPerGas, gasLimits, teardownGasLimits });
|
|
173
186
|
this.log.verbose(
|
|
@@ -177,73 +190,4 @@ export abstract class BaseContractInteraction {
|
|
|
177
190
|
|
|
178
191
|
return { gasSettings, paymentMethod };
|
|
179
192
|
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Add authWitness used in this contract interaction.
|
|
183
|
-
* @param authWitness - authWitness used in the contract interaction.
|
|
184
|
-
*/
|
|
185
|
-
public addAuthWitness(authWitness: AuthWitness) {
|
|
186
|
-
this.authWitnesses.push(authWitness);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Add authWitness used in this contract interaction.
|
|
191
|
-
* @param authWitnesses - authWitnesses used in the contract interaction.
|
|
192
|
-
*/
|
|
193
|
-
public addAuthWitnesses(authWitnesses: AuthWitness[]) {
|
|
194
|
-
this.authWitnesses.push(...authWitnesses);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Return all authWitnesses added for this interaction.
|
|
199
|
-
*/
|
|
200
|
-
public getAuthWitnesses() {
|
|
201
|
-
return this.authWitnesses;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Add hashedArgument used in this contract interaction.
|
|
206
|
-
* @param hashedArgument - hashedArgument used in the contract interaction.
|
|
207
|
-
*/
|
|
208
|
-
public addHashedArgument(hashedArgument: HashedValues) {
|
|
209
|
-
this.hashedArguments.push(hashedArgument);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Add hashedArguments used in this contract interaction.
|
|
214
|
-
* @param hashedArguments - hashedArguments used in the contract interaction.
|
|
215
|
-
*/
|
|
216
|
-
public addHashedArguments(hashedArguments: HashedValues[]) {
|
|
217
|
-
this.hashedArguments.push(...hashedArguments);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Return all hashedArguments added for this interaction.
|
|
222
|
-
*/
|
|
223
|
-
public getHashedArguments() {
|
|
224
|
-
return this.hashedArguments;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Add data passed to the oracle calls during this contract interaction.
|
|
229
|
-
* @param capsule - Data passed to oracle calls.
|
|
230
|
-
*/
|
|
231
|
-
public addCapsule(capsule: Capsule) {
|
|
232
|
-
this.capsules.push(capsule);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Add data passed to the oracle calls during this contract interaction.
|
|
237
|
-
* @param capsules - Data passed to oracle calls.
|
|
238
|
-
*/
|
|
239
|
-
public addCapsules(capsules: Capsule[]) {
|
|
240
|
-
this.capsules.push(...capsules);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Return all capsules added for this contract interaction.
|
|
245
|
-
*/
|
|
246
|
-
public getCapsules() {
|
|
247
|
-
return this.capsules;
|
|
248
|
-
}
|
|
249
193
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/entrypoints/payload';
|
|
1
2
|
import { type FunctionCall, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
|
|
2
3
|
import type { TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
3
4
|
|
|
4
|
-
import type { Wallet } from '../
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
6
|
+
import {
|
|
7
|
+
BaseContractInteraction,
|
|
8
|
+
type RequestMethodOptions,
|
|
9
|
+
type SendMethodOptions,
|
|
10
|
+
} from './base_contract_interaction.js';
|
|
7
11
|
import type { SimulateMethodOptions } from './contract_function_interaction.js';
|
|
8
12
|
|
|
9
13
|
/** A batch of function calls to be sent as a single transaction through a wallet. */
|
|
@@ -21,21 +25,26 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
21
25
|
public async create(options: SendMethodOptions = {}): Promise<TxExecutionRequest> {
|
|
22
26
|
const requestWithoutFee = await this.request(options);
|
|
23
27
|
|
|
24
|
-
const { fee: userFee } = options;
|
|
25
|
-
const fee = await this.getFeeOptions({
|
|
28
|
+
const { fee: userFee, nonce, cancellable } = options;
|
|
29
|
+
const fee = await this.getFeeOptions(requestWithoutFee, userFee, { nonce, cancellable });
|
|
26
30
|
|
|
27
|
-
return await this.wallet.createTxExecutionRequest(
|
|
31
|
+
return await this.wallet.createTxExecutionRequest(requestWithoutFee, fee, { nonce, cancellable });
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
/**
|
|
31
35
|
* Returns an execution request that represents this operation.
|
|
32
|
-
* @param options - An optional object containing additional configuration for the
|
|
33
|
-
* @returns An execution
|
|
36
|
+
* @param options - An optional object containing additional configuration for the request generation.
|
|
37
|
+
* @returns An execution payload wrapped in promise.
|
|
34
38
|
*/
|
|
35
|
-
public async request(options:
|
|
39
|
+
public async request(options: RequestMethodOptions = {}): Promise<ExecutionPayload> {
|
|
36
40
|
const requests = await this.getRequests();
|
|
37
|
-
const
|
|
38
|
-
return
|
|
41
|
+
const combinedPayload = mergeExecutionPayloads(requests);
|
|
42
|
+
return new ExecutionPayload(
|
|
43
|
+
combinedPayload.calls,
|
|
44
|
+
combinedPayload.authWitnesses.concat(options.authWitnesses ?? []),
|
|
45
|
+
combinedPayload.capsules.concat(options.capsules ?? []),
|
|
46
|
+
combinedPayload.extraHashedArgs,
|
|
47
|
+
);
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
/**
|
|
@@ -48,13 +57,13 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
48
57
|
* @returns The result of the transaction as returned by the contract function.
|
|
49
58
|
*/
|
|
50
59
|
public async simulate(options: SimulateMethodOptions = {}): Promise<any> {
|
|
51
|
-
const {
|
|
60
|
+
const { indexedExecutionPayloads, unconstrained } = (await this.getRequests()).reduce<{
|
|
52
61
|
/** Keep track of the number of private calls to retrieve the return values */
|
|
53
62
|
privateIndex: 0;
|
|
54
63
|
/** Keep track of the number of public calls to retrieve the return values */
|
|
55
64
|
publicIndex: 0;
|
|
56
65
|
/** The public and private function execution requests in the batch */
|
|
57
|
-
|
|
66
|
+
indexedExecutionPayloads: [ExecutionPayload, number, number][];
|
|
58
67
|
/** The unconstrained function calls in the batch. */
|
|
59
68
|
unconstrained: [FunctionCall, number][];
|
|
60
69
|
}>(
|
|
@@ -63,7 +72,7 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
63
72
|
if (call.type === FunctionType.UNCONSTRAINED) {
|
|
64
73
|
acc.unconstrained.push([call, index]);
|
|
65
74
|
} else {
|
|
66
|
-
acc.
|
|
75
|
+
acc.indexedExecutionPayloads.push([
|
|
67
76
|
current,
|
|
68
77
|
index,
|
|
69
78
|
call.type === FunctionType.PRIVATE ? acc.privateIndex++ : acc.publicIndex++,
|
|
@@ -71,18 +80,27 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
71
80
|
}
|
|
72
81
|
return acc;
|
|
73
82
|
},
|
|
74
|
-
{
|
|
83
|
+
{ indexedExecutionPayloads: [], unconstrained: [], publicIndex: 0, privateIndex: 0 },
|
|
75
84
|
);
|
|
76
85
|
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
86
|
+
const payloads = indexedExecutionPayloads.map(([request]) => request);
|
|
87
|
+
const combinedPayload = mergeExecutionPayloads(payloads);
|
|
88
|
+
const requestWithoutFee = new ExecutionPayload(
|
|
89
|
+
combinedPayload.calls,
|
|
90
|
+
combinedPayload.authWitnesses.concat(options.authWitnesses ?? []),
|
|
91
|
+
combinedPayload.capsules.concat(options.capsules ?? []),
|
|
92
|
+
combinedPayload.extraHashedArgs,
|
|
93
|
+
);
|
|
94
|
+
const { fee: userFee, nonce, cancellable } = options;
|
|
95
|
+
const fee = await this.getFeeOptions(requestWithoutFee, userFee, {});
|
|
96
|
+
const txRequest = await this.wallet.createTxExecutionRequest(requestWithoutFee, fee, { nonce, cancellable });
|
|
82
97
|
|
|
83
98
|
const unconstrainedCalls = unconstrained.map(
|
|
84
99
|
async ([call, index]) =>
|
|
85
|
-
[
|
|
100
|
+
[
|
|
101
|
+
await this.wallet.simulateUnconstrained(call.name, call.args, call.to, options?.authWitnesses, options?.from),
|
|
102
|
+
index,
|
|
103
|
+
] as const,
|
|
86
104
|
);
|
|
87
105
|
|
|
88
106
|
const [unconstrainedResults, simulatedTx] = await Promise.all([
|
|
@@ -95,7 +113,7 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
95
113
|
unconstrainedResults.forEach(([result, index]) => {
|
|
96
114
|
results[index] = result;
|
|
97
115
|
});
|
|
98
|
-
|
|
116
|
+
indexedExecutionPayloads.forEach(([request, callIndex, resultIndex]) => {
|
|
99
117
|
const call = request.calls[0];
|
|
100
118
|
// As account entrypoints are private, for private functions we retrieve the return values from the first nested call
|
|
101
119
|
// since we're interested in the first set of values AFTER the account entrypoint
|
|
@@ -110,27 +128,6 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
110
128
|
return results;
|
|
111
129
|
}
|
|
112
130
|
|
|
113
|
-
/**
|
|
114
|
-
* Return all authWitnesses added for this interaction.
|
|
115
|
-
*/
|
|
116
|
-
public override getAuthWitnesses() {
|
|
117
|
-
return [this.authWitnesses, ...this.calls.map(c => c.getAuthWitnesses())].flat();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Return all hashedArguments added for this interaction.
|
|
122
|
-
*/
|
|
123
|
-
public override getHashedArguments() {
|
|
124
|
-
return [this.hashedArguments, ...this.calls.map(c => c.getHashedArguments())].flat();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Return all capsules added for this interaction.
|
|
129
|
-
*/
|
|
130
|
-
public override getCapsules() {
|
|
131
|
-
return [this.capsules, ...this.calls.map(c => c.getCapsules())].flat();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
131
|
private async getRequests() {
|
|
135
132
|
return await Promise.all(this.calls.map(c => c.request()));
|
|
136
133
|
}
|
package/src/contract/contract.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
3
3
|
import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
4
4
|
import { PublicKeys } from '@aztec/stdlib/keys';
|
|
5
5
|
|
|
6
|
-
import type { Wallet } from '../
|
|
6
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
7
7
|
import { ContractBase } from './contract_base.js';
|
|
8
8
|
import { DeployMethod } from './deploy_method.js';
|
|
9
9
|
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from '@aztec/stdlib/abi';
|
|
9
9
|
import { type ContractInstanceWithAddress, computePartialAddress } from '@aztec/stdlib/contract';
|
|
10
10
|
|
|
11
|
-
import type { Wallet } from '../
|
|
11
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
12
12
|
import { ContractFunctionInteraction } from './contract_function_interaction.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { ExecutionPayload } from '@aztec/entrypoints/payload';
|
|
1
2
|
import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi, encodeArguments } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
2
4
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
-
import type {
|
|
4
|
-
import type { TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
5
|
+
import type { Capsule, HashedValues, TxExecutionRequest, TxProfileResult } from '@aztec/stdlib/tx';
|
|
5
6
|
|
|
6
|
-
import type { Wallet } from '../
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
8
|
+
import {
|
|
9
|
+
BaseContractInteraction,
|
|
10
|
+
type RequestMethodOptions,
|
|
11
|
+
type SendMethodOptions,
|
|
12
|
+
} from './base_contract_interaction.js';
|
|
10
13
|
|
|
11
14
|
export type { SendMethodOptions };
|
|
12
15
|
|
|
@@ -15,21 +18,31 @@ export type { SendMethodOptions };
|
|
|
15
18
|
* Allows specifying the address from which the view method should be called.
|
|
16
19
|
* Disregarded for simulation of public functions
|
|
17
20
|
*/
|
|
18
|
-
export type
|
|
21
|
+
export type ProfileMethodOptions = Pick<
|
|
22
|
+
SendMethodOptions,
|
|
23
|
+
'authWitnesses' | 'capsules' | 'fee' | 'nonce' | 'cancellable'
|
|
24
|
+
> & {
|
|
25
|
+
/** Whether to return gates information or the bytecode/witnesses. */
|
|
26
|
+
profileMode: 'gates' | 'execution-steps' | 'full';
|
|
19
27
|
/** The sender's Aztec address. */
|
|
20
28
|
from?: AztecAddress;
|
|
21
|
-
/** Simulate without checking for the validity of the resulting transaction, e.g. whether it emits any existing nullifiers. */
|
|
22
|
-
skipTxValidation?: boolean;
|
|
23
|
-
/** Whether to ensure the fee payer is not empty and has enough balance to pay for the fee. */
|
|
24
|
-
skipFeeEnforcement?: boolean;
|
|
25
29
|
};
|
|
26
30
|
|
|
27
31
|
/**
|
|
28
|
-
*
|
|
32
|
+
* Represents the options for simulating a contract function interaction.
|
|
33
|
+
* Allows specifying the address from which the method should be called.
|
|
34
|
+
* Disregarded for simulation of public functions
|
|
29
35
|
*/
|
|
30
|
-
export type
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
export type SimulateMethodOptions = Pick<
|
|
37
|
+
SendMethodOptions,
|
|
38
|
+
'authWitnesses' | 'capsules' | 'fee' | 'nonce' | 'cancellable'
|
|
39
|
+
> & {
|
|
40
|
+
/** The sender's Aztec address. */
|
|
41
|
+
from?: AztecAddress;
|
|
42
|
+
/** Simulate without checking for the validity of the resulting transaction, e.g. whether it emits any existing nullifiers. */
|
|
43
|
+
skipTxValidation?: boolean;
|
|
44
|
+
/** Whether to ensure the fee payer is not empty and has enough balance to pay for the fee. */
|
|
45
|
+
skipFeeEnforcement?: boolean;
|
|
33
46
|
};
|
|
34
47
|
|
|
35
48
|
/**
|
|
@@ -42,8 +55,11 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
42
55
|
protected contractAddress: AztecAddress,
|
|
43
56
|
protected functionDao: FunctionAbi,
|
|
44
57
|
protected args: any[],
|
|
58
|
+
authWitnesses: AuthWitness[] = [],
|
|
59
|
+
capsules: Capsule[] = [],
|
|
60
|
+
private extraHashedArgs: HashedValues[] = [],
|
|
45
61
|
) {
|
|
46
|
-
super(wallet);
|
|
62
|
+
super(wallet, authWitnesses, capsules);
|
|
47
63
|
if (args.some(arg => arg === undefined || arg === null)) {
|
|
48
64
|
throw new Error('All function interaction arguments must be defined and not null. Received: ' + args);
|
|
49
65
|
}
|
|
@@ -63,20 +79,20 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
63
79
|
}
|
|
64
80
|
const requestWithoutFee = await this.request(options);
|
|
65
81
|
|
|
66
|
-
const { fee: userFee } = options;
|
|
67
|
-
const fee = await this.getFeeOptions({
|
|
82
|
+
const { fee: userFee, nonce, cancellable } = options;
|
|
83
|
+
const fee = await this.getFeeOptions(requestWithoutFee, userFee, { nonce, cancellable });
|
|
68
84
|
|
|
69
|
-
return await this.wallet.createTxExecutionRequest(
|
|
85
|
+
return await this.wallet.createTxExecutionRequest(requestWithoutFee, fee, { nonce, cancellable });
|
|
70
86
|
}
|
|
71
87
|
|
|
72
88
|
// docs:start:request
|
|
73
89
|
/**
|
|
74
90
|
* Returns an execution request that represents this operation.
|
|
75
91
|
* Can be used as a building block for constructing batch requests.
|
|
76
|
-
* @param options - An optional object containing additional configuration for the
|
|
77
|
-
* @returns An execution
|
|
92
|
+
* @param options - An optional object containing additional configuration for the request generation.
|
|
93
|
+
* @returns An execution payload wrapped in promise.
|
|
78
94
|
*/
|
|
79
|
-
public async request(options:
|
|
95
|
+
public async request(options: RequestMethodOptions = {}): Promise<ExecutionPayload> {
|
|
80
96
|
// docs:end:request
|
|
81
97
|
const args = encodeArguments(this.functionDao, this.args);
|
|
82
98
|
const calls = [
|
|
@@ -90,18 +106,13 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
90
106
|
returnTypes: this.functionDao.returnTypes,
|
|
91
107
|
},
|
|
92
108
|
];
|
|
93
|
-
const authWitnesses =
|
|
94
|
-
|
|
95
|
-
const capsules = this.getCapsules();
|
|
96
|
-
const { nonce, cancellable } = options;
|
|
97
|
-
return {
|
|
109
|
+
const { authWitnesses, capsules } = options;
|
|
110
|
+
return new ExecutionPayload(
|
|
98
111
|
calls,
|
|
99
|
-
authWitnesses,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
cancellable,
|
|
104
|
-
};
|
|
112
|
+
this.authWitnesses.concat(authWitnesses ?? []),
|
|
113
|
+
this.capsules.concat(capsules ?? []),
|
|
114
|
+
this.extraHashedArgs,
|
|
115
|
+
);
|
|
105
116
|
}
|
|
106
117
|
|
|
107
118
|
// docs:start:simulate
|
|
@@ -117,11 +128,16 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
117
128
|
public async simulate(options: SimulateMethodOptions = {}): Promise<any> {
|
|
118
129
|
// docs:end:simulate
|
|
119
130
|
if (this.functionDao.functionType == FunctionType.UNCONSTRAINED) {
|
|
120
|
-
return this.wallet.simulateUnconstrained(
|
|
131
|
+
return this.wallet.simulateUnconstrained(
|
|
132
|
+
this.functionDao.name,
|
|
133
|
+
this.args,
|
|
134
|
+
this.contractAddress,
|
|
135
|
+
options.authWitnesses ?? [],
|
|
136
|
+
options?.from,
|
|
137
|
+
);
|
|
121
138
|
}
|
|
122
139
|
|
|
123
|
-
const
|
|
124
|
-
const txRequest = await this.create({ fee });
|
|
140
|
+
const txRequest = await this.create(options);
|
|
125
141
|
const simulatedTx = await this.wallet.simulateTx(
|
|
126
142
|
txRequest,
|
|
127
143
|
true /* simulatePublic */,
|
|
@@ -154,30 +170,43 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
154
170
|
*
|
|
155
171
|
* @returns An object containing the function return value and profile result.
|
|
156
172
|
*/
|
|
157
|
-
public async
|
|
173
|
+
public async profile(options: ProfileMethodOptions = { profileMode: 'gates' }): Promise<TxProfileResult> {
|
|
158
174
|
if (this.functionDao.functionType == FunctionType.UNCONSTRAINED) {
|
|
159
175
|
throw new Error("Can't profile an unconstrained function.");
|
|
160
176
|
}
|
|
177
|
+
const { authWitnesses, capsules, fee } = options;
|
|
161
178
|
|
|
162
|
-
const txRequest = await this.create({ fee
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
true,
|
|
166
|
-
options?.from,
|
|
167
|
-
options?.skipTxValidation,
|
|
168
|
-
undefined,
|
|
169
|
-
true,
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
const rawReturnValues =
|
|
173
|
-
this.functionDao.functionType == FunctionType.PRIVATE
|
|
174
|
-
? simulatedTx.getPrivateReturnValues().nested?.[0].values
|
|
175
|
-
: simulatedTx.getPublicReturnValues()?.[0].values;
|
|
176
|
-
const rawReturnValuesDecoded = rawReturnValues ? decodeFromAbi(this.functionDao.returnTypes, rawReturnValues) : [];
|
|
179
|
+
const txRequest = await this.create({ fee, authWitnesses, capsules });
|
|
180
|
+
return await this.wallet.profileTx(txRequest, options.profileMode, options?.from);
|
|
181
|
+
}
|
|
177
182
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Augments this ContractFunctionInteraction with additional metadata, such as authWitnesses, capsules, and extraHashedArgs.
|
|
185
|
+
* This is useful when creating a "batteries included" interaction, such as registering a contract class with its associated
|
|
186
|
+
* capsule instead of having the user provide them externally.
|
|
187
|
+
* @param options - An object containing the metadata to add to the interaction
|
|
188
|
+
* @returns A new ContractFunctionInteraction with the added metadata, but calling the same original function in the same manner
|
|
189
|
+
*/
|
|
190
|
+
public with({
|
|
191
|
+
authWitnesses = [],
|
|
192
|
+
capsules = [],
|
|
193
|
+
extraHashedArgs = [],
|
|
194
|
+
}: {
|
|
195
|
+
/** The authWitnesses to add to the interaction */
|
|
196
|
+
authWitnesses?: AuthWitness[];
|
|
197
|
+
/** The capsules to add to the interaction */
|
|
198
|
+
capsules?: Capsule[];
|
|
199
|
+
/** The extra hashed args to add to the interaction */
|
|
200
|
+
extraHashedArgs?: HashedValues[];
|
|
201
|
+
}): ContractFunctionInteraction {
|
|
202
|
+
return new ContractFunctionInteraction(
|
|
203
|
+
this.wallet,
|
|
204
|
+
this.contractAddress,
|
|
205
|
+
this.functionDao,
|
|
206
|
+
this.args,
|
|
207
|
+
this.authWitnesses.concat(authWitnesses),
|
|
208
|
+
this.capsules.concat(capsules),
|
|
209
|
+
this.extraHashedArgs.concat(extraHashedArgs),
|
|
210
|
+
);
|
|
182
211
|
}
|
|
183
212
|
}
|