@aztec/aztec.js 0.0.1-commit.d431d1c → 0.0.1-commit.dbf9cec
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/api/block.d.ts +2 -2
- package/dest/api/block.d.ts.map +1 -1
- package/dest/api/block.js +1 -1
- package/dest/api/contract.d.ts +18 -12
- package/dest/api/contract.d.ts.map +1 -1
- package/dest/api/contract.js +16 -10
- package/dest/api/deployment.d.ts +1 -2
- package/dest/api/deployment.d.ts.map +1 -1
- package/dest/api/deployment.js +0 -1
- package/dest/api/events.d.ts +10 -6
- package/dest/api/events.d.ts.map +1 -1
- package/dest/api/events.js +30 -20
- package/dest/api/fields.d.ts +2 -1
- package/dest/api/fields.d.ts.map +1 -1
- package/dest/api/fields.js +1 -0
- package/dest/api/keys.d.ts +1 -1
- package/dest/api/keys.js +1 -1
- package/dest/api/node.d.ts +8 -4
- package/dest/api/node.d.ts.map +1 -1
- package/dest/api/node.js +7 -3
- package/dest/api/tx.d.ts +2 -2
- package/dest/api/tx.d.ts.map +1 -1
- package/dest/api/tx.js +1 -1
- package/dest/api/wallet.d.ts +3 -2
- package/dest/api/wallet.d.ts.map +1 -1
- package/dest/api/wallet.js +2 -1
- package/dest/contract/base_contract_interaction.d.ts +8 -10
- package/dest/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.js +5 -17
- package/dest/contract/batch_call.d.ts +3 -3
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +8 -5
- package/dest/contract/contract_function_interaction.d.ts +3 -12
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +10 -7
- package/dest/contract/deploy_method.d.ts +78 -18
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +61 -29
- package/dest/contract/get_gas_limits.js +3 -3
- package/dest/contract/interaction_options.d.ts +49 -5
- package/dest/contract/interaction_options.d.ts.map +1 -1
- package/dest/contract/interaction_options.js +8 -1
- package/dest/contract/protocol_contracts/auth-registry.d.ts +3 -3
- package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/auth-registry.js +41 -20
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts +2 -22
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/contract-class-registry.js +13 -671
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +2 -11
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/contract-instance-registry.js +80 -486
- package/dest/contract/protocol_contracts/fee-juice.d.ts +1 -10
- package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/fee-juice.js +0 -414
- package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts +3 -3
- package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/multi-call-entrypoint.js +32 -15
- package/dest/contract/protocol_contracts/public-checks.d.ts +3 -3
- package/dest/contract/protocol_contracts/public-checks.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/public-checks.js +32 -23
- package/dest/contract/wait_for_proven.js +1 -1
- package/dest/contract/wait_opts.d.ts +16 -0
- package/dest/contract/wait_opts.d.ts.map +1 -0
- package/dest/contract/wait_opts.js +5 -0
- package/dest/fee/fee_juice_payment_method_with_claim.js +6 -6
- package/dest/fee/private_fee_payment_method.js +10 -10
- package/dest/fee/public_fee_payment_method.js +10 -10
- package/dest/fee/sponsored_fee_payment.js +3 -3
- package/dest/utils/authwit.d.ts +6 -6
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +2 -6
- package/dest/utils/node.d.ts +12 -1
- package/dest/utils/node.d.ts.map +1 -1
- package/dest/utils/node.js +46 -0
- package/dest/wallet/capabilities.d.ts +452 -0
- package/dest/wallet/capabilities.d.ts.map +1 -0
- package/dest/wallet/capabilities.js +3 -0
- package/dest/wallet/deploy_account_method.d.ts +31 -6
- package/dest/wallet/deploy_account_method.d.ts.map +1 -1
- package/dest/wallet/deploy_account_method.js +26 -0
- package/dest/wallet/index.d.ts +2 -1
- package/dest/wallet/index.d.ts.map +1 -1
- package/dest/wallet/index.js +1 -0
- package/dest/wallet/wallet.d.ts +1639 -93
- package/dest/wallet/wallet.d.ts.map +1 -1
- package/dest/wallet/wallet.js +169 -27
- package/package.json +20 -11
- package/src/api/block.ts +1 -1
- package/src/api/contract.ts +24 -9
- package/src/api/deployment.ts +0 -1
- package/src/api/events.ts +35 -27
- package/src/api/fields.ts +1 -0
- package/src/api/keys.ts +2 -2
- package/src/api/node.ts +7 -3
- package/src/api/tx.ts +2 -0
- package/src/api/wallet.ts +48 -1
- package/src/contract/base_contract_interaction.ts +27 -15
- package/src/contract/batch_call.ts +7 -12
- package/src/contract/contract_function_interaction.ts +17 -7
- package/src/contract/deploy_method.ts +158 -32
- package/src/contract/get_gas_limits.ts +3 -3
- package/src/contract/interaction_options.ts +56 -4
- package/src/contract/protocol_contracts/auth-registry.ts +11 -14
- package/src/contract/protocol_contracts/contract-class-registry.ts +4 -347
- package/src/contract/protocol_contracts/contract-instance-registry.ts +34 -234
- package/src/contract/protocol_contracts/fee-juice.ts +0 -202
- package/src/contract/protocol_contracts/multi-call-entrypoint.ts +9 -13
- package/src/contract/protocol_contracts/public-checks.ts +9 -15
- package/src/contract/wait_for_proven.ts +1 -1
- package/src/contract/wait_opts.ts +21 -0
- package/src/fee/fee_juice_payment_method_with_claim.ts +5 -5
- package/src/fee/private_fee_payment_method.ts +7 -7
- package/src/fee/public_fee_payment_method.ts +8 -8
- package/src/fee/sponsored_fee_payment.ts +3 -3
- package/src/utils/authwit.ts +16 -4
- package/src/utils/node.ts +62 -0
- package/src/wallet/capabilities.ts +500 -0
- package/src/wallet/deploy_account_method.ts +56 -4
- package/src/wallet/index.ts +1 -0
- package/src/wallet/wallet.ts +236 -50
- package/dest/contract/deploy_sent_tx.d.ts +0 -48
- package/dest/contract/deploy_sent_tx.d.ts.map +0 -1
- package/dest/contract/deploy_sent_tx.js +0 -46
- package/dest/contract/sent_tx.d.ts +0 -50
- package/dest/contract/sent_tx.d.ts.map +0 -1
- package/dest/contract/sent_tx.js +0 -90
- package/dest/deployment/broadcast_function.d.ts +0 -24
- package/dest/deployment/broadcast_function.d.ts.map +0 -1
- package/dest/deployment/broadcast_function.js +0 -74
- package/src/contract/deploy_sent_tx.ts +0 -75
- package/src/contract/sent_tx.ts +0 -129
- package/src/deployment/broadcast_function.ts +0 -148
package/src/api/wallet.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export {
|
|
2
2
|
type Aliased,
|
|
3
3
|
type SimulateOptions,
|
|
4
|
+
type ExecuteUtilityOptions,
|
|
4
5
|
type ProfileOptions,
|
|
5
6
|
type SendOptions,
|
|
6
7
|
type BatchableMethods,
|
|
@@ -11,10 +12,16 @@ export {
|
|
|
11
12
|
type Wallet,
|
|
12
13
|
type PrivateEvent,
|
|
13
14
|
type PrivateEventFilter,
|
|
14
|
-
|
|
15
|
+
type PublicEvent,
|
|
16
|
+
type PublicEventFilter,
|
|
17
|
+
type ContractMetadata,
|
|
18
|
+
type ContractClassMetadata,
|
|
19
|
+
AppCapabilitiesSchema,
|
|
20
|
+
WalletCapabilitiesSchema,
|
|
15
21
|
ExecutionPayloadSchema,
|
|
16
22
|
GasSettingsOptionSchema,
|
|
17
23
|
WalletSimulationFeeOptionSchema,
|
|
24
|
+
WaitOptsSchema,
|
|
18
25
|
SendOptionsSchema,
|
|
19
26
|
SimulateOptionsSchema,
|
|
20
27
|
ProfileOptionsSchema,
|
|
@@ -23,9 +30,49 @@ export {
|
|
|
23
30
|
EventMetadataDefinitionSchema,
|
|
24
31
|
PrivateEventSchema,
|
|
25
32
|
PrivateEventFilterSchema,
|
|
33
|
+
PublicEventSchema,
|
|
34
|
+
PublicEventFilterSchema,
|
|
35
|
+
ContractClassMetadataSchema,
|
|
36
|
+
ContractMetadataSchema,
|
|
26
37
|
WalletSchema,
|
|
38
|
+
ContractFunctionPatternSchema,
|
|
39
|
+
AccountsCapabilitySchema,
|
|
40
|
+
GrantedAccountsCapabilitySchema,
|
|
41
|
+
ContractsCapabilitySchema,
|
|
42
|
+
GrantedContractsCapabilitySchema,
|
|
43
|
+
ContractClassesCapabilitySchema,
|
|
44
|
+
GrantedContractClassesCapabilitySchema,
|
|
45
|
+
SimulationCapabilitySchema,
|
|
46
|
+
GrantedSimulationCapabilitySchema,
|
|
47
|
+
TransactionCapabilitySchema,
|
|
48
|
+
GrantedTransactionCapabilitySchema,
|
|
49
|
+
DataCapabilitySchema,
|
|
50
|
+
GrantedDataCapabilitySchema,
|
|
51
|
+
CapabilitySchema,
|
|
52
|
+
GrantedCapabilitySchema,
|
|
27
53
|
} from '../wallet/wallet.js';
|
|
28
54
|
|
|
55
|
+
export {
|
|
56
|
+
type AppCapabilities,
|
|
57
|
+
type WalletCapabilities,
|
|
58
|
+
CAPABILITY_VERSION,
|
|
59
|
+
type Capability,
|
|
60
|
+
type GrantedCapability,
|
|
61
|
+
type ContractFunctionPattern,
|
|
62
|
+
type AccountsCapability,
|
|
63
|
+
type GrantedAccountsCapability,
|
|
64
|
+
type ContractsCapability,
|
|
65
|
+
type GrantedContractsCapability,
|
|
66
|
+
type ContractClassesCapability,
|
|
67
|
+
type GrantedContractClassesCapability,
|
|
68
|
+
type SimulationCapability,
|
|
69
|
+
type GrantedSimulationCapability,
|
|
70
|
+
type TransactionCapability,
|
|
71
|
+
type GrantedTransactionCapability,
|
|
72
|
+
type DataCapability,
|
|
73
|
+
type GrantedDataCapability,
|
|
74
|
+
} from '../wallet/capabilities.js';
|
|
75
|
+
|
|
29
76
|
export { AccountManager } from '../wallet/account_manager.js';
|
|
30
77
|
|
|
31
78
|
export { type DeployAccountOptions, DeployAccountMethod } from '../wallet/deploy_account_method.js';
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
3
|
-
import type { Capsule, ExecutionPayload } from '@aztec/stdlib/tx';
|
|
3
|
+
import type { Capsule, ExecutionPayload, TxReceipt } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
5
5
|
import type { Wallet } from '../wallet/wallet.js';
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
type InteractionWaitOptions,
|
|
8
|
+
type RequestInteractionOptions,
|
|
9
|
+
type SendInteractionOptions,
|
|
10
|
+
type SendInteractionOptionsWithoutWait,
|
|
11
|
+
type SendReturn,
|
|
12
|
+
toSendOptions,
|
|
13
|
+
} from './interaction_options.js';
|
|
8
14
|
|
|
9
15
|
/**
|
|
10
16
|
* Base class for an interaction with a contract, be it a deployment, a function call, or a batch.
|
|
@@ -30,20 +36,26 @@ export abstract class BaseContractInteraction {
|
|
|
30
36
|
// docs:start:send
|
|
31
37
|
/**
|
|
32
38
|
* Sends a transaction to the contract function with the specified options.
|
|
33
|
-
*
|
|
34
|
-
* It creates and signs the transaction if necessary, and returns a SentTx instance,
|
|
35
|
-
* which can be used to track the transaction status, receipt, and events.
|
|
39
|
+
* By default, waits for the transaction to be mined and returns the receipt (or custom type).
|
|
36
40
|
* @param options - An object containing 'from' property representing
|
|
37
|
-
* the AztecAddress of the sender and optional
|
|
38
|
-
* @returns
|
|
41
|
+
* the AztecAddress of the sender, optional fee configuration, and optional wait settings
|
|
42
|
+
* @returns TReturn (if wait is undefined/WaitOpts) or TxHash (if wait is NO_WAIT)
|
|
39
43
|
*/
|
|
40
|
-
|
|
44
|
+
// Overload for when wait is not specified at all - returns TReturn
|
|
45
|
+
public send<TReturn = TxReceipt>(options: SendInteractionOptionsWithoutWait): Promise<TReturn>;
|
|
46
|
+
// Generic overload for explicit wait values
|
|
47
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
48
|
+
public send<TReturn = TxReceipt, W extends InteractionWaitOptions = undefined>(
|
|
49
|
+
options: SendInteractionOptions<W>,
|
|
50
|
+
): Promise<SendReturn<W, TReturn>>;
|
|
51
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
52
|
+
public async send<TReturn = TxReceipt>(
|
|
53
|
+
options: SendInteractionOptions<InteractionWaitOptions>,
|
|
54
|
+
): Promise<SendReturn<typeof options.wait, TReturn>> {
|
|
41
55
|
// docs:end:send
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
return new SentTx(this.wallet, sendTx);
|
|
56
|
+
const executionPayload = await this.request(options);
|
|
57
|
+
const sendOptions = toSendOptions(options);
|
|
58
|
+
|
|
59
|
+
return (await this.wallet.sendTx(executionPayload, sendOptions as any)) as SendReturn<typeof options.wait, TReturn>;
|
|
48
60
|
}
|
|
49
61
|
}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { type FunctionCall, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
|
|
2
|
-
import {
|
|
3
|
-
ExecutionPayload,
|
|
4
|
-
TxSimulationResult,
|
|
5
|
-
UtilitySimulationResult,
|
|
6
|
-
mergeExecutionPayloads,
|
|
7
|
-
} from '@aztec/stdlib/tx';
|
|
2
|
+
import { ExecutionPayload, TxSimulationResult, UtilityExecutionResult, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
8
3
|
|
|
9
4
|
import type { BatchedMethod, Wallet } from '../wallet/wallet.js';
|
|
10
5
|
import { BaseContractInteraction } from './base_contract_interaction.js';
|
|
@@ -42,9 +37,9 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
42
37
|
}
|
|
43
38
|
|
|
44
39
|
/**
|
|
45
|
-
* Simulates the batch, supporting private, public and utility functions. Although this is a single
|
|
40
|
+
* Simulates/executes the batch, supporting private, public and utility functions. Although this is a single
|
|
46
41
|
* interaction with the wallet, private and public functions will be grouped into a single ExecutionPayload
|
|
47
|
-
* that the wallet will simulate as a single transaction. Utility function calls will
|
|
42
|
+
* that the wallet will simulate as a single transaction. Utility function calls will be executed
|
|
48
43
|
* one by one.
|
|
49
44
|
* @param options - An optional object containing additional configuration for the interaction.
|
|
50
45
|
* @returns The results of all the interactions that make up the batch
|
|
@@ -81,8 +76,8 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
81
76
|
// Add utility calls to batch
|
|
82
77
|
for (const [call] of utility) {
|
|
83
78
|
batchRequests.push({
|
|
84
|
-
name: '
|
|
85
|
-
args: [call, options
|
|
79
|
+
name: 'executeUtility' as const,
|
|
80
|
+
args: [call, { scope: options.from, authWitnesses: options.authWitnesses }],
|
|
86
81
|
});
|
|
87
82
|
}
|
|
88
83
|
|
|
@@ -111,8 +106,8 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
111
106
|
for (let i = 0; i < utility.length; i++) {
|
|
112
107
|
const [call, resultIndex] = utility[i];
|
|
113
108
|
const wrappedResult = batchResults[i];
|
|
114
|
-
if (wrappedResult.name === '
|
|
115
|
-
const rawReturnValues = (wrappedResult.result as
|
|
109
|
+
if (wrappedResult.name === 'executeUtility') {
|
|
110
|
+
const rawReturnValues = (wrappedResult.result as UtilityExecutionResult).result;
|
|
116
111
|
results[resultIndex] = rawReturnValues ? decodeFromAbi(call.returnTypes, rawReturnValues) : [];
|
|
117
112
|
}
|
|
118
113
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type FunctionAbi,
|
|
3
|
+
FunctionCall,
|
|
4
|
+
FunctionSelector,
|
|
5
|
+
FunctionType,
|
|
6
|
+
decodeFromAbi,
|
|
7
|
+
encodeArguments,
|
|
8
|
+
} from '@aztec/stdlib/abi';
|
|
2
9
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
3
10
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
11
|
import { type Capsule, type HashedValues, type TxProfileResult, collectOffchainEffects } from '@aztec/stdlib/tx';
|
|
@@ -43,16 +50,16 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
43
50
|
*/
|
|
44
51
|
public async getFunctionCall() {
|
|
45
52
|
const args = encodeArguments(this.functionDao, this.args);
|
|
46
|
-
return {
|
|
53
|
+
return FunctionCall.from({
|
|
47
54
|
name: this.functionDao.name,
|
|
48
|
-
|
|
55
|
+
to: this.contractAddress,
|
|
49
56
|
selector: await FunctionSelector.fromNameAndParameters(this.functionDao.name, this.functionDao.parameters),
|
|
50
57
|
type: this.functionDao.functionType,
|
|
51
|
-
to: this.contractAddress,
|
|
52
|
-
isStatic: this.functionDao.isStatic,
|
|
53
58
|
hideMsgSender: false /** Only set to `true` for enqueued public function calls */,
|
|
59
|
+
isStatic: this.functionDao.isStatic,
|
|
60
|
+
args,
|
|
54
61
|
returnTypes: this.functionDao.returnTypes,
|
|
55
|
-
};
|
|
62
|
+
});
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
/**
|
|
@@ -104,7 +111,10 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
104
111
|
// docs:end:simulate
|
|
105
112
|
if (this.functionDao.functionType == FunctionType.UTILITY) {
|
|
106
113
|
const call = await this.getFunctionCall();
|
|
107
|
-
const utilityResult = await this.wallet.
|
|
114
|
+
const utilityResult = await this.wallet.executeUtility(call, {
|
|
115
|
+
scope: options.from,
|
|
116
|
+
authWitnesses: options.authWitnesses,
|
|
117
|
+
});
|
|
108
118
|
|
|
109
119
|
// Decode the raw field elements to the actual return type
|
|
110
120
|
const returnValue = utilityResult.result ? decodeFromAbi(this.functionDao.returnTypes, utilityResult.result) : [];
|
|
@@ -9,27 +9,53 @@ import {
|
|
|
9
9
|
getContractInstanceFromInstantiationParams,
|
|
10
10
|
} from '@aztec/stdlib/contract';
|
|
11
11
|
import type { PublicKeys } from '@aztec/stdlib/keys';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
type Capsule,
|
|
14
|
+
HashedValues,
|
|
15
|
+
TxHash,
|
|
16
|
+
type TxProfileResult,
|
|
17
|
+
type TxReceipt,
|
|
18
|
+
collectOffchainEffects,
|
|
19
|
+
} from '@aztec/stdlib/tx';
|
|
13
20
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
14
21
|
|
|
15
22
|
import { publishContractClass } from '../deployment/publish_class.js';
|
|
16
23
|
import { publishInstance } from '../deployment/publish_instance.js';
|
|
17
|
-
import type { Wallet } from '../wallet/wallet.js';
|
|
24
|
+
import type { ProfileOptions, SendOptions, SimulateOptions, Wallet } from '../wallet/wallet.js';
|
|
18
25
|
import { BaseContractInteraction } from './base_contract_interaction.js';
|
|
19
26
|
import type { ContractBase } from './contract_base.js';
|
|
20
27
|
import { ContractFunctionInteraction } from './contract_function_interaction.js';
|
|
21
|
-
import { DeploySentTx } from './deploy_sent_tx.js';
|
|
22
28
|
import { getGasLimits } from './get_gas_limits.js';
|
|
23
29
|
import {
|
|
30
|
+
NO_WAIT,
|
|
31
|
+
type NoWait,
|
|
24
32
|
type ProfileInteractionOptions,
|
|
25
33
|
type RequestInteractionOptions,
|
|
26
|
-
type
|
|
34
|
+
type SendInteractionOptionsWithoutWait,
|
|
27
35
|
type SimulationInteractionFeeOptions,
|
|
28
36
|
type SimulationReturn,
|
|
29
37
|
toProfileOptions,
|
|
30
38
|
toSendOptions,
|
|
31
39
|
toSimulateOptions,
|
|
32
40
|
} from './interaction_options.js';
|
|
41
|
+
import type { WaitOpts } from './wait_opts.js';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Wait options specific to deployment transactions.
|
|
45
|
+
* Extends WaitOpts with a flag to return the full receipt instead of just the contract.
|
|
46
|
+
*/
|
|
47
|
+
export type DeployWaitOptions = WaitOpts & {
|
|
48
|
+
/** If true, return the full DeployTxReceipt instead of just the contract. Defaults to false. */
|
|
49
|
+
returnReceipt?: boolean;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Type for wait options in deployment interactions.
|
|
54
|
+
* - NO_WAIT symbol: Don't wait, return TxHash immediately
|
|
55
|
+
* - DeployWaitOptions: Wait with custom options
|
|
56
|
+
* - undefined: Wait with default options
|
|
57
|
+
*/
|
|
58
|
+
export type DeployInteractionWaitOptions = NoWait | DeployWaitOptions | undefined;
|
|
33
59
|
|
|
34
60
|
/**
|
|
35
61
|
* Options for deploying a contract on the Aztec network.
|
|
@@ -55,21 +81,34 @@ export type RequestDeployOptions = RequestInteractionOptions & {
|
|
|
55
81
|
};
|
|
56
82
|
|
|
57
83
|
/**
|
|
58
|
-
*
|
|
84
|
+
* Base deployment options without wait parameter.
|
|
59
85
|
*/
|
|
60
|
-
export type
|
|
86
|
+
export type DeployOptionsWithoutWait = Omit<RequestDeployOptions, 'deployer'> & {
|
|
61
87
|
/**
|
|
62
88
|
* Set to true to *not* include the sender in the address computation. This option
|
|
63
89
|
* is mutually exclusive with "deployer"
|
|
64
90
|
*/
|
|
65
91
|
universalDeploy?: boolean;
|
|
66
|
-
} & Pick<
|
|
92
|
+
} & Pick<SendInteractionOptionsWithoutWait, 'from' | 'fee' | 'additionalScopes'>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Extends the deployment options with the required parameters to send the transaction.
|
|
96
|
+
*/
|
|
97
|
+
export type DeployOptions<W extends DeployInteractionWaitOptions = undefined> = DeployOptionsWithoutWait & {
|
|
98
|
+
/**
|
|
99
|
+
* Options for waiting for the transaction to be mined.
|
|
100
|
+
* - undefined (default): wait with default options and return the contract instance
|
|
101
|
+
* - DeployWaitOptions: wait with custom options and return contract or receipt based on returnReceipt flag
|
|
102
|
+
* - NO_WAIT: return TxHash immediately without waiting
|
|
103
|
+
*/
|
|
104
|
+
wait?: W;
|
|
105
|
+
};
|
|
67
106
|
|
|
68
107
|
/**
|
|
69
108
|
* Options for simulating the deployment of a contract
|
|
70
109
|
* Allows skipping certain validations and computing gas estimations
|
|
71
110
|
*/
|
|
72
|
-
export type SimulateDeployOptions = Omit<
|
|
111
|
+
export type SimulateDeployOptions = Omit<DeployOptionsWithoutWait, 'fee'> & {
|
|
73
112
|
/** The fee options for the transaction. */
|
|
74
113
|
fee?: SimulationInteractionFeeOptions;
|
|
75
114
|
/** Simulate without checking for the validity of the resulting transaction,
|
|
@@ -83,6 +122,29 @@ export type SimulateDeployOptions = Omit<DeployOptions, 'fee'> & {
|
|
|
83
122
|
includeMetadata?: boolean;
|
|
84
123
|
};
|
|
85
124
|
|
|
125
|
+
/** Receipt for a deployment transaction with the deployed contract instance. */
|
|
126
|
+
export type DeployTxReceipt<TContract extends ContractBase = ContractBase> = TxReceipt & {
|
|
127
|
+
/** Type-safe wrapper around the deployed contract instance, linked to the deployment wallet */
|
|
128
|
+
contract: TContract;
|
|
129
|
+
/** The deployed contract instance with address and metadata. */
|
|
130
|
+
instance: ContractInstanceWithAddress;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Represents the result type of deploying a contract.
|
|
135
|
+
* - If wait is NO_WAIT, returns TxHash immediately.
|
|
136
|
+
* - If wait has returnReceipt: true, returns DeployTxReceipt after waiting.
|
|
137
|
+
* - Otherwise (undefined or DeployWaitOptions without returnReceipt), returns TContract after waiting.
|
|
138
|
+
*/
|
|
139
|
+
export type DeployReturn<TContract extends ContractBase, W extends DeployInteractionWaitOptions> = W extends NoWait
|
|
140
|
+
? TxHash
|
|
141
|
+
: W extends {
|
|
142
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
143
|
+
returnReceipt: true;
|
|
144
|
+
}
|
|
145
|
+
? DeployTxReceipt<TContract>
|
|
146
|
+
: TContract;
|
|
147
|
+
|
|
86
148
|
/**
|
|
87
149
|
* Contract interaction for deployment.
|
|
88
150
|
* Handles class publication, instance publication, and initialization of the contract.
|
|
@@ -92,8 +154,6 @@ export type SimulateDeployOptions = Omit<DeployOptions, 'fee'> & {
|
|
|
92
154
|
* then technically the contract has already been "created", and all of the contract's
|
|
93
155
|
* functions (private and utility) can be interacted-with immediately, without any
|
|
94
156
|
* "deployment tx".
|
|
95
|
-
*
|
|
96
|
-
* Extends the BaseContractInteraction class.
|
|
97
157
|
*/
|
|
98
158
|
export class DeployMethod<TContract extends ContractBase = ContractBase> extends BaseContractInteraction {
|
|
99
159
|
/** The contract instance to be deployed. */
|
|
@@ -111,6 +171,7 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
111
171
|
constructorNameOrArtifact?: string | FunctionArtifact,
|
|
112
172
|
authWitnesses: AuthWitness[] = [],
|
|
113
173
|
capsules: Capsule[] = [],
|
|
174
|
+
private extraHashedArgs: HashedValues[] = [],
|
|
114
175
|
) {
|
|
115
176
|
super(wallet, authWitnesses, capsules);
|
|
116
177
|
this.constructorArtifact = getInitializer(artifact, constructorNameOrArtifact);
|
|
@@ -121,20 +182,29 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
121
182
|
* @param options - Configuration options.
|
|
122
183
|
* @returns The execution payload for this operation
|
|
123
184
|
*/
|
|
124
|
-
public async request(options
|
|
185
|
+
public async request(options: RequestDeployOptions = {}): Promise<ExecutionPayload> {
|
|
125
186
|
const publication = await this.getPublicationExecutionPayload(options);
|
|
126
187
|
|
|
127
188
|
if (!options?.skipRegistration) {
|
|
128
189
|
await this.wallet.registerContract(await this.getInstance(options), this.artifact);
|
|
129
190
|
}
|
|
191
|
+
const { authWitnesses, capsules } = options;
|
|
130
192
|
|
|
193
|
+
// Propagates the included authwitnesses, capsules, and extraHashedArgs
|
|
194
|
+
// potentially baked into the interaction
|
|
195
|
+
const initialExecutionPayload = new ExecutionPayload(
|
|
196
|
+
[],
|
|
197
|
+
this.authWitnesses.concat(authWitnesses ?? []),
|
|
198
|
+
this.capsules.concat(capsules ?? []),
|
|
199
|
+
this.extraHashedArgs,
|
|
200
|
+
);
|
|
131
201
|
const initialization = await this.getInitializationExecutionPayload(options);
|
|
132
202
|
const feeExecutionPayload = options?.fee?.paymentMethod
|
|
133
203
|
? await options.fee.paymentMethod.getExecutionPayload()
|
|
134
204
|
: undefined;
|
|
135
205
|
const finalExecutionPayload = feeExecutionPayload
|
|
136
|
-
? mergeExecutionPayloads([feeExecutionPayload, publication, initialization])
|
|
137
|
-
: mergeExecutionPayloads([publication, initialization]);
|
|
206
|
+
? mergeExecutionPayloads([initialExecutionPayload, feeExecutionPayload, publication, initialization])
|
|
207
|
+
: mergeExecutionPayloads([initialExecutionPayload, publication, initialization]);
|
|
138
208
|
if (!finalExecutionPayload.calls.length) {
|
|
139
209
|
throw new Error(`No transactions are needed to publish or initialize contract ${this.artifact.name}`);
|
|
140
210
|
}
|
|
@@ -142,13 +212,48 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
142
212
|
return finalExecutionPayload;
|
|
143
213
|
}
|
|
144
214
|
|
|
145
|
-
convertDeployOptionsToRequestOptions(options:
|
|
215
|
+
convertDeployOptionsToRequestOptions(options: DeployOptionsWithoutWait): RequestDeployOptions {
|
|
146
216
|
return {
|
|
147
217
|
...options,
|
|
148
218
|
deployer: !options?.universalDeploy ? options.from : undefined,
|
|
149
219
|
};
|
|
150
220
|
}
|
|
151
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Converts DeployOptions to SendOptions, stripping out the returnReceipt flag if present.
|
|
224
|
+
* @param options - Deploy options with wait parameter
|
|
225
|
+
* @returns Send options with wait parameter
|
|
226
|
+
*/
|
|
227
|
+
protected convertDeployOptionsToSendOptions<W extends DeployInteractionWaitOptions>(
|
|
228
|
+
options: DeployOptions<W>,
|
|
229
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
230
|
+
): SendOptions<W extends { returnReceipt: true } ? WaitOpts : W> {
|
|
231
|
+
return {
|
|
232
|
+
...toSendOptions({
|
|
233
|
+
...options,
|
|
234
|
+
wait: options.wait as any,
|
|
235
|
+
}),
|
|
236
|
+
} as any;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Converts deploy simulation options into wallet-level simulate options.
|
|
241
|
+
* @param options - The deploy simulation options to convert.
|
|
242
|
+
*/
|
|
243
|
+
protected convertDeployOptionsToSimulateOptions(options: SimulateDeployOptions): SimulateOptions {
|
|
244
|
+
return toSimulateOptions(options);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Converts deploy profile options into wallet-level profile options.
|
|
249
|
+
* @param options - The deploy profile options to convert.
|
|
250
|
+
*/
|
|
251
|
+
protected convertDeployOptionsToProfileOptions(
|
|
252
|
+
options: DeployOptionsWithoutWait & ProfileInteractionOptions,
|
|
253
|
+
): ProfileOptions {
|
|
254
|
+
return toProfileOptions(options);
|
|
255
|
+
}
|
|
256
|
+
|
|
152
257
|
/**
|
|
153
258
|
* Adds this contract to the wallet and returns the Contract object.
|
|
154
259
|
* @param options - Deployment options.
|
|
@@ -232,20 +337,42 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
232
337
|
|
|
233
338
|
/**
|
|
234
339
|
* Send a contract deployment transaction (initialize and/or publish) using the provided options.
|
|
235
|
-
*
|
|
236
|
-
* allowing us to send a transaction specifically for contract deployment.
|
|
340
|
+
* By default, waits for the transaction to be mined and returns the deployed contract instance.
|
|
237
341
|
*
|
|
238
342
|
* @param options - An object containing various deployment options such as contractAddressSalt and from.
|
|
239
|
-
* @returns
|
|
343
|
+
* @returns TxHash (if wait is NO_WAIT), TContract (if wait is undefined or doesn't have returnReceipt), or DeployTxReceipt (if wait.returnReceipt is true)
|
|
240
344
|
*/
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
345
|
+
// Overload for when wait is not specified at all - returns the contract
|
|
346
|
+
public override send(options: DeployOptionsWithoutWait): Promise<TContract>;
|
|
347
|
+
// Generic overload for explicit wait values
|
|
348
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
349
|
+
public override send<W extends DeployInteractionWaitOptions>(
|
|
350
|
+
options: DeployOptions<W>,
|
|
351
|
+
): Promise<DeployReturn<TContract, W>>;
|
|
352
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
353
|
+
public override async send(options: DeployOptions<DeployInteractionWaitOptions>): Promise<any> {
|
|
354
|
+
const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
|
|
355
|
+
const sendOptions = this.convertDeployOptionsToSendOptions(options);
|
|
356
|
+
|
|
357
|
+
if (options.wait === NO_WAIT) {
|
|
358
|
+
const txHash = await this.wallet.sendTx(executionPayload, sendOptions as SendOptions<NoWait>);
|
|
359
|
+
this.log.debug(`Sent deployment tx ${txHash.hash} of ${this.artifact.name} contract`);
|
|
360
|
+
return txHash;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const receipt = await this.wallet.sendTx(executionPayload, sendOptions as SendOptions<WaitOpts | undefined>);
|
|
364
|
+
this.log.debug(`Deployed ${this.artifact.name} contract in tx ${receipt.txHash}`);
|
|
365
|
+
|
|
366
|
+
// Attach contract instance
|
|
367
|
+
const instance = await this.getInstance(options);
|
|
368
|
+
const contract = this.postDeployCtor(instance, this.wallet) as TContract;
|
|
369
|
+
|
|
370
|
+
// Return full receipt if requested, otherwise just the contract
|
|
371
|
+
if (options.wait && typeof options.wait === 'object' && options.wait.returnReceipt) {
|
|
372
|
+
return { ...receipt, contract, instance };
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return contract;
|
|
249
376
|
}
|
|
250
377
|
|
|
251
378
|
/**
|
|
@@ -276,7 +403,10 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
276
403
|
*/
|
|
277
404
|
public async simulate(options: SimulateDeployOptions): Promise<SimulationReturn<true>> {
|
|
278
405
|
const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
|
|
279
|
-
const simulatedTx = await this.wallet.simulateTx(
|
|
406
|
+
const simulatedTx = await this.wallet.simulateTx(
|
|
407
|
+
executionPayload,
|
|
408
|
+
this.convertDeployOptionsToSimulateOptions(options),
|
|
409
|
+
);
|
|
280
410
|
|
|
281
411
|
const { gasLimits, teardownGasLimits } = getGasLimits(simulatedTx, options.fee?.estimatedGasPadding);
|
|
282
412
|
this.log.verbose(
|
|
@@ -296,13 +426,9 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
296
426
|
*
|
|
297
427
|
* @returns An object containing the function return value and profile result.
|
|
298
428
|
*/
|
|
299
|
-
public async profile(options:
|
|
429
|
+
public async profile(options: DeployOptionsWithoutWait & ProfileInteractionOptions): Promise<TxProfileResult> {
|
|
300
430
|
const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
|
|
301
|
-
return await this.wallet.profileTx(executionPayload,
|
|
302
|
-
...toProfileOptions(options),
|
|
303
|
-
profileMode: options.profileMode,
|
|
304
|
-
skipProofGeneration: options.skipProofGeneration,
|
|
305
|
-
});
|
|
431
|
+
return await this.wallet.profileTx(executionPayload, this.convertDeployOptionsToProfileOptions(options));
|
|
306
432
|
}
|
|
307
433
|
|
|
308
434
|
/** Return this deployment address. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
|
|
2
2
|
import { Gas } from '@aztec/stdlib/gas';
|
|
3
3
|
import type { TxSimulationResult } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
@@ -23,8 +23,8 @@ export function getGasLimits(
|
|
|
23
23
|
const gasLimits = simulationResult.gasUsed.totalGas.mul(1 + pad);
|
|
24
24
|
const teardownGasLimits = simulationResult.gasUsed.teardownGas.mul(1 + pad);
|
|
25
25
|
|
|
26
|
-
if (gasLimits.l2Gas >
|
|
27
|
-
throw new Error('Transaction consumes more gas than the
|
|
26
|
+
if (gasLimits.l2Gas > MAX_PROCESSABLE_L2_GAS) {
|
|
27
|
+
throw new Error('Transaction consumes more l2 gas than the maximum processable gas');
|
|
28
28
|
}
|
|
29
29
|
return {
|
|
30
30
|
gasLimits,
|
|
@@ -2,10 +2,11 @@ import type { FieldsOf } from '@aztec/foundation/types';
|
|
|
2
2
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
5
|
-
import type { Capsule, OffchainEffect, SimulationStats } from '@aztec/stdlib/tx';
|
|
5
|
+
import type { Capsule, OffchainEffect, SimulationStats, TxHash, TxReceipt } from '@aztec/stdlib/tx';
|
|
6
6
|
|
|
7
7
|
import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
|
|
8
8
|
import type { ProfileOptions, SendOptions, SimulateOptions } from '../wallet/index.js';
|
|
9
|
+
import type { WaitOpts } from './wait_opts.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Options used to tweak the simulation and add gas estimation capabilities
|
|
@@ -55,13 +56,52 @@ export type RequestInteractionOptions = {
|
|
|
55
56
|
};
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
|
-
*
|
|
59
|
+
* Constant for explicitly not waiting for transaction confirmation.
|
|
60
|
+
* We use this instead of false to avoid confusion with falsy checks.
|
|
61
|
+
*/
|
|
62
|
+
export const NO_WAIT = 'NO_WAIT' as const;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Type for the NO_WAIT constant.
|
|
66
|
+
*/
|
|
67
|
+
export type NoWait = typeof NO_WAIT;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Type for wait options in interactions.
|
|
71
|
+
* - NO_WAIT symbol: Don't wait for confirmation, return TxHash immediately
|
|
72
|
+
* - WaitOpts object: Wait with custom options and return receipt/result
|
|
73
|
+
* - undefined: Wait with default options and return receipt/result
|
|
74
|
+
*/
|
|
75
|
+
export type InteractionWaitOptions = NoWait | WaitOpts | undefined;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Base options for calling a (constrained) function in a contract, without wait parameter.
|
|
59
79
|
*/
|
|
60
|
-
export type
|
|
80
|
+
export type SendInteractionOptionsWithoutWait = RequestInteractionOptions & {
|
|
61
81
|
/** The sender's Aztec address. */
|
|
62
82
|
from: AztecAddress;
|
|
63
83
|
/** The fee options for the transaction. */
|
|
64
84
|
fee?: InteractionFeeOptions;
|
|
85
|
+
/**
|
|
86
|
+
* Additional addresses whose private state and keys should be accessible during execution,
|
|
87
|
+
* beyond the sender's. Required when the transaction needs to access private state or keys
|
|
88
|
+
* belonging to an address other than `from`, e.g. withdrawing from an escrow that holds
|
|
89
|
+
* its own private notes.
|
|
90
|
+
*/
|
|
91
|
+
additionalScopes?: AztecAddress[];
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Represents options for calling a (constrained) function in a contract.
|
|
96
|
+
*/
|
|
97
|
+
export type SendInteractionOptions<W extends InteractionWaitOptions = undefined> = SendInteractionOptionsWithoutWait & {
|
|
98
|
+
/**
|
|
99
|
+
* Whether to wait for the transaction to be mined.
|
|
100
|
+
* - undefined (default): wait with default options and return TxReceipt
|
|
101
|
+
* - WaitOpts object: wait with custom options and return TxReceipt
|
|
102
|
+
* - NO_WAIT: return txHash immediately without waiting
|
|
103
|
+
*/
|
|
104
|
+
wait?: W;
|
|
65
105
|
};
|
|
66
106
|
|
|
67
107
|
/**
|
|
@@ -110,11 +150,22 @@ export type SimulationReturn<T extends boolean | undefined> = T extends true
|
|
|
110
150
|
}
|
|
111
151
|
: any;
|
|
112
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Represents the result type of sending a transaction.
|
|
155
|
+
* If `wait` is NO_WAIT, returns TxHash immediately without waiting.
|
|
156
|
+
* If `wait` is undefined or WaitOpts, returns TReturn (defaults to TxReceipt) after waiting.
|
|
157
|
+
*/
|
|
158
|
+
export type SendReturn<T extends InteractionWaitOptions, TReturn = TxReceipt> = T extends NoWait ? TxHash : TReturn;
|
|
159
|
+
|
|
113
160
|
/**
|
|
114
161
|
* Transforms and cleans up the higher level SendInteractionOptions defined by the interaction into
|
|
115
162
|
* SendOptions, which are the ones that can be serialized and forwarded to the wallet
|
|
163
|
+
* @param options - The send interaction options with optional wait parameter
|
|
164
|
+
* @returns The send options to forward to the wallet
|
|
116
165
|
*/
|
|
117
|
-
export function toSendOptions
|
|
166
|
+
export function toSendOptions<W extends InteractionWaitOptions = undefined>(
|
|
167
|
+
options: SendInteractionOptions<W>,
|
|
168
|
+
): SendOptions<W> {
|
|
118
169
|
return {
|
|
119
170
|
...options,
|
|
120
171
|
fee: {
|
|
@@ -126,6 +177,7 @@ export function toSendOptions(options: SendInteractionOptions): SendOptions {
|
|
|
126
177
|
...options.fee?.gasSettings,
|
|
127
178
|
},
|
|
128
179
|
},
|
|
180
|
+
wait: options.wait, // Pass through wait option
|
|
129
181
|
};
|
|
130
182
|
}
|
|
131
183
|
|