@aztec/aztec.js 0.0.1-commit.3469e52 → 0.0.1-commit.54489865
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 +16 -10
- package/dest/api/contract.d.ts.map +1 -1
- package/dest/api/contract.js +14 -8
- 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 +2 -2
- package/dest/api/wallet.d.ts.map +1 -1
- package/dest/api/wallet.js +1 -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/deploy_method.d.ts +63 -16
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +36 -19
- package/dest/contract/interaction_options.d.ts +42 -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 +1 -14
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts +3 -3
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/contract-class-registry.js +1 -14
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +3 -3
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/contract-instance-registry.js +9 -14
- package/dest/contract/protocol_contracts/fee-juice.d.ts +3 -3
- package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/fee-juice.js +1 -14
- 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 +1 -14
- 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 +1 -14
- 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/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/deploy_account_method.d.ts +19 -5
- package/dest/wallet/deploy_account_method.d.ts.map +1 -1
- package/dest/wallet/wallet.d.ts +63 -18
- package/dest/wallet/wallet.d.ts.map +1 -1
- package/dest/wallet/wallet.js +16 -3
- package/package.json +9 -9
- package/src/api/block.ts +1 -1
- package/src/api/contract.ts +22 -7
- package/src/api/node.ts +7 -3
- package/src/api/tx.ts +2 -0
- package/src/api/wallet.ts +5 -0
- package/src/contract/base_contract_interaction.ts +27 -15
- package/src/contract/deploy_method.ts +115 -23
- package/src/contract/interaction_options.ts +49 -4
- package/src/contract/protocol_contracts/auth-registry.ts +3 -12
- package/src/contract/protocol_contracts/contract-class-registry.ts +3 -12
- package/src/contract/protocol_contracts/contract-instance-registry.ts +5 -12
- package/src/contract/protocol_contracts/fee-juice.ts +3 -12
- package/src/contract/protocol_contracts/multi-call-entrypoint.ts +3 -12
- package/src/contract/protocol_contracts/public-checks.ts +3 -12
- package/src/contract/wait_for_proven.ts +1 -1
- package/src/contract/wait_opts.ts +21 -0
- package/src/utils/authwit.ts +16 -4
- package/src/utils/node.ts +62 -0
- package/src/wallet/deploy_account_method.ts +19 -4
- package/src/wallet/wallet.ts +32 -12
- 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/src/contract/deploy_sent_tx.ts +0 -75
- package/src/contract/sent_tx.ts +0 -129
package/src/api/contract.ts
CHANGED
|
@@ -10,13 +10,21 @@
|
|
|
10
10
|
* or can be queried via `simulate()`.
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
|
-
*
|
|
13
|
+
* // Deploy and get the contract instance directly (default behavior)
|
|
14
|
+
* const contract = await Contract.deploy(wallet, MyContractArtifact, [...constructorArgs]).send({ from: accountAddress });
|
|
14
15
|
* console.log(`Contract deployed at ${contract.address}`);
|
|
16
|
+
*
|
|
17
|
+
* // Or get the full receipt with contract and instance
|
|
18
|
+
* const receipt = await Contract.deploy(wallet, MyContractArtifact, [...constructorArgs]).send({
|
|
19
|
+
* from: accountAddress,
|
|
20
|
+
* wait: { returnReceipt: true }
|
|
21
|
+
* });
|
|
22
|
+
* console.log(`Contract deployed at ${receipt.contract.address}`);
|
|
15
23
|
* ```
|
|
16
24
|
*
|
|
17
25
|
* ```ts
|
|
18
26
|
* const contract = Contract.at(address, MyContractArtifact, wallet);
|
|
19
|
-
* await contract.methods.mint(1000, owner).send()
|
|
27
|
+
* await contract.methods.mint(1000, owner).send({ from: accountAddress });
|
|
20
28
|
* console.log(`Total supply is now ${await contract.methods.totalSupply().simulate()}`);
|
|
21
29
|
* ```
|
|
22
30
|
*
|
|
@@ -25,9 +33,8 @@
|
|
|
25
33
|
* a transaction to the network via the `send` method, but you can also `simulate` it without sending,
|
|
26
34
|
* or obtaining the `request` for aggregating into a {@link BatchCall}.
|
|
27
35
|
*
|
|
28
|
-
* The
|
|
29
|
-
*
|
|
30
|
-
* has synchronized its changes.
|
|
36
|
+
* The `send` method returns a {@link TxReceipt} by default (waits for the transaction to be mined).
|
|
37
|
+
* If you pass `wait: NO_WAIT` in the options, it will return a {@link TxHash} immediately without waiting.
|
|
31
38
|
*
|
|
32
39
|
* @remarks If you are using typescript, consider using the
|
|
33
40
|
* {@link https://docs.aztec.network/developers/aztec-nr/how_to_compile_contract#use-generated-interfaces | autogenerated type-safe interfaces}
|
|
@@ -39,27 +46,35 @@ export { Contract } from '../contract/contract.js';
|
|
|
39
46
|
export { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
40
47
|
|
|
41
48
|
export {
|
|
49
|
+
NO_WAIT,
|
|
50
|
+
type NoWait,
|
|
42
51
|
type RequestInteractionOptions,
|
|
43
52
|
type SendInteractionOptions,
|
|
44
53
|
type ProfileInteractionOptions,
|
|
45
54
|
type SimulateInteractionOptions,
|
|
46
55
|
type InteractionFeeOptions,
|
|
56
|
+
type InteractionWaitOptions,
|
|
47
57
|
type GasSettingsOption,
|
|
58
|
+
type SendReturn,
|
|
59
|
+
type SimulationReturn,
|
|
48
60
|
toProfileOptions,
|
|
49
61
|
toSendOptions,
|
|
50
62
|
toSimulateOptions,
|
|
51
63
|
} from '../contract/interaction_options.js';
|
|
52
64
|
|
|
53
|
-
export { DefaultWaitOpts,
|
|
65
|
+
export { DefaultWaitOpts, type WaitOpts } from '../contract/wait_opts.js';
|
|
54
66
|
export { ContractBase, type ContractMethod, type ContractStorageLayout } from '../contract/contract_base.js';
|
|
55
67
|
export { BatchCall } from '../contract/batch_call.js';
|
|
56
68
|
export {
|
|
57
69
|
type DeployOptions,
|
|
70
|
+
type DeployReturn,
|
|
71
|
+
type DeployTxReceipt,
|
|
72
|
+
type DeployWaitOptions,
|
|
73
|
+
type DeployInteractionWaitOptions,
|
|
58
74
|
DeployMethod,
|
|
59
75
|
type RequestDeployOptions,
|
|
60
76
|
type SimulateDeployOptions,
|
|
61
77
|
} from '../contract/deploy_method.js';
|
|
62
|
-
export { DeploySentTx } from '../contract/deploy_sent_tx.js';
|
|
63
78
|
export { waitForProven, type WaitForProvenOpts, DefaultWaitForProvenOpts } from '../contract/wait_for_proven.js';
|
|
64
79
|
export { getGasLimits } from '../contract/get_gas_limits.js';
|
|
65
80
|
|
package/src/api/node.ts
CHANGED
|
@@ -3,18 +3,22 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The primary function is {@link createAztecNodeClient}, which creates a JSON-RPC client
|
|
5
5
|
* that connects to a running Aztec node instance. Use {@link waitForNode} to wait for
|
|
6
|
-
* the node to be ready before proceeding
|
|
6
|
+
* the node to be ready before proceeding, and {@link waitForTx} to wait for a transaction
|
|
7
|
+
* to be mined.
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
9
10
|
* ```ts
|
|
10
|
-
* import { createAztecNodeClient, waitForNode } from '@aztec/aztec.js/node';
|
|
11
|
+
* import { createAztecNodeClient, waitForNode, waitForTx } from '@aztec/aztec.js/node';
|
|
11
12
|
*
|
|
12
13
|
* const node = createAztecNodeClient('http://localhost:8080');
|
|
13
14
|
* await waitForNode(node);
|
|
14
15
|
* const blockNumber = await node.getBlockNumber();
|
|
16
|
+
*
|
|
17
|
+
* // Wait for a transaction
|
|
18
|
+
* const receipt = await waitForTx(node, txHash);
|
|
15
19
|
* ```
|
|
16
20
|
*
|
|
17
21
|
* @packageDocumentation
|
|
18
22
|
*/
|
|
19
|
-
export { createAztecNodeClient, waitForNode, type AztecNode } from '../utils/node.js';
|
|
23
|
+
export { createAztecNodeClient, waitForNode, waitForTx, type AztecNode } from '../utils/node.js';
|
|
20
24
|
export { type NodeInfo } from '@aztec/stdlib/contract';
|
package/src/api/tx.ts
CHANGED
package/src/api/wallet.ts
CHANGED
|
@@ -11,10 +11,13 @@ export {
|
|
|
11
11
|
type Wallet,
|
|
12
12
|
type PrivateEvent,
|
|
13
13
|
type PrivateEventFilter,
|
|
14
|
+
type ContractMetadata,
|
|
15
|
+
type ContractClassMetadata,
|
|
14
16
|
FunctionCallSchema,
|
|
15
17
|
ExecutionPayloadSchema,
|
|
16
18
|
GasSettingsOptionSchema,
|
|
17
19
|
WalletSimulationFeeOptionSchema,
|
|
20
|
+
WaitOptsSchema,
|
|
18
21
|
SendOptionsSchema,
|
|
19
22
|
SimulateOptionsSchema,
|
|
20
23
|
ProfileOptionsSchema,
|
|
@@ -23,6 +26,8 @@ export {
|
|
|
23
26
|
EventMetadataDefinitionSchema,
|
|
24
27
|
PrivateEventSchema,
|
|
25
28
|
PrivateEventFilterSchema,
|
|
29
|
+
ContractClassMetadataSchema,
|
|
30
|
+
ContractMetadataSchema,
|
|
26
31
|
WalletSchema,
|
|
27
32
|
} from '../wallet/wallet.js';
|
|
28
33
|
|
|
@@ -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
|
}
|
|
@@ -9,27 +9,46 @@ import {
|
|
|
9
9
|
getContractInstanceFromInstantiationParams,
|
|
10
10
|
} from '@aztec/stdlib/contract';
|
|
11
11
|
import type { PublicKeys } from '@aztec/stdlib/keys';
|
|
12
|
-
import { type Capsule, type TxProfileResult, collectOffchainEffects } from '@aztec/stdlib/tx';
|
|
12
|
+
import { type Capsule, TxHash, type TxProfileResult, type TxReceipt, collectOffchainEffects } from '@aztec/stdlib/tx';
|
|
13
13
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
14
14
|
|
|
15
15
|
import { publishContractClass } from '../deployment/publish_class.js';
|
|
16
16
|
import { publishInstance } from '../deployment/publish_instance.js';
|
|
17
|
-
import type { Wallet } from '../wallet/wallet.js';
|
|
17
|
+
import type { SendOptions, Wallet } from '../wallet/wallet.js';
|
|
18
18
|
import { BaseContractInteraction } from './base_contract_interaction.js';
|
|
19
19
|
import type { ContractBase } from './contract_base.js';
|
|
20
20
|
import { ContractFunctionInteraction } from './contract_function_interaction.js';
|
|
21
|
-
import { DeploySentTx } from './deploy_sent_tx.js';
|
|
22
21
|
import { getGasLimits } from './get_gas_limits.js';
|
|
23
22
|
import {
|
|
23
|
+
NO_WAIT,
|
|
24
|
+
type NoWait,
|
|
24
25
|
type ProfileInteractionOptions,
|
|
25
26
|
type RequestInteractionOptions,
|
|
26
|
-
type
|
|
27
|
+
type SendInteractionOptionsWithoutWait,
|
|
27
28
|
type SimulationInteractionFeeOptions,
|
|
28
29
|
type SimulationReturn,
|
|
29
30
|
toProfileOptions,
|
|
30
31
|
toSendOptions,
|
|
31
32
|
toSimulateOptions,
|
|
32
33
|
} from './interaction_options.js';
|
|
34
|
+
import type { WaitOpts } from './wait_opts.js';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Wait options specific to deployment transactions.
|
|
38
|
+
* Extends WaitOpts with a flag to return the full receipt instead of just the contract.
|
|
39
|
+
*/
|
|
40
|
+
export type DeployWaitOptions = WaitOpts & {
|
|
41
|
+
/** If true, return the full DeployTxReceipt instead of just the contract. Defaults to false. */
|
|
42
|
+
returnReceipt?: boolean;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Type for wait options in deployment interactions.
|
|
47
|
+
* - NO_WAIT symbol: Don't wait, return TxHash immediately
|
|
48
|
+
* - DeployWaitOptions: Wait with custom options
|
|
49
|
+
* - undefined: Wait with default options
|
|
50
|
+
*/
|
|
51
|
+
export type DeployInteractionWaitOptions = NoWait | DeployWaitOptions | undefined;
|
|
33
52
|
|
|
34
53
|
/**
|
|
35
54
|
* Options for deploying a contract on the Aztec network.
|
|
@@ -55,21 +74,34 @@ export type RequestDeployOptions = RequestInteractionOptions & {
|
|
|
55
74
|
};
|
|
56
75
|
|
|
57
76
|
/**
|
|
58
|
-
*
|
|
77
|
+
* Base deployment options without wait parameter.
|
|
59
78
|
*/
|
|
60
|
-
export type
|
|
79
|
+
export type DeployOptionsWithoutWait = Omit<RequestDeployOptions, 'deployer'> & {
|
|
61
80
|
/**
|
|
62
81
|
* Set to true to *not* include the sender in the address computation. This option
|
|
63
82
|
* is mutually exclusive with "deployer"
|
|
64
83
|
*/
|
|
65
84
|
universalDeploy?: boolean;
|
|
66
|
-
} & Pick<
|
|
85
|
+
} & Pick<SendInteractionOptionsWithoutWait, 'from' | 'fee'>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Extends the deployment options with the required parameters to send the transaction.
|
|
89
|
+
*/
|
|
90
|
+
export type DeployOptions<W extends DeployInteractionWaitOptions = undefined> = DeployOptionsWithoutWait & {
|
|
91
|
+
/**
|
|
92
|
+
* Options for waiting for the transaction to be mined.
|
|
93
|
+
* - undefined (default): wait with default options and return the contract instance
|
|
94
|
+
* - DeployWaitOptions: wait with custom options and return contract or receipt based on returnReceipt flag
|
|
95
|
+
* - NO_WAIT: return TxHash immediately without waiting
|
|
96
|
+
*/
|
|
97
|
+
wait?: W;
|
|
98
|
+
};
|
|
67
99
|
|
|
68
100
|
/**
|
|
69
101
|
* Options for simulating the deployment of a contract
|
|
70
102
|
* Allows skipping certain validations and computing gas estimations
|
|
71
103
|
*/
|
|
72
|
-
export type SimulateDeployOptions = Omit<
|
|
104
|
+
export type SimulateDeployOptions = Omit<DeployOptionsWithoutWait, 'fee'> & {
|
|
73
105
|
/** The fee options for the transaction. */
|
|
74
106
|
fee?: SimulationInteractionFeeOptions;
|
|
75
107
|
/** Simulate without checking for the validity of the resulting transaction,
|
|
@@ -83,6 +115,29 @@ export type SimulateDeployOptions = Omit<DeployOptions, 'fee'> & {
|
|
|
83
115
|
includeMetadata?: boolean;
|
|
84
116
|
};
|
|
85
117
|
|
|
118
|
+
/** Receipt for a deployment transaction with the deployed contract instance. */
|
|
119
|
+
export type DeployTxReceipt<TContract extends ContractBase = ContractBase> = TxReceipt & {
|
|
120
|
+
/** Type-safe wrapper around the deployed contract instance, linked to the deployment wallet */
|
|
121
|
+
contract: TContract;
|
|
122
|
+
/** The deployed contract instance with address and metadata. */
|
|
123
|
+
instance: ContractInstanceWithAddress;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Represents the result type of deploying a contract.
|
|
128
|
+
* - If wait is NO_WAIT, returns TxHash immediately.
|
|
129
|
+
* - If wait has returnReceipt: true, returns DeployTxReceipt after waiting.
|
|
130
|
+
* - Otherwise (undefined or DeployWaitOptions without returnReceipt), returns TContract after waiting.
|
|
131
|
+
*/
|
|
132
|
+
export type DeployReturn<TContract extends ContractBase, W extends DeployInteractionWaitOptions> = W extends NoWait
|
|
133
|
+
? TxHash
|
|
134
|
+
: W extends {
|
|
135
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
136
|
+
returnReceipt: true;
|
|
137
|
+
}
|
|
138
|
+
? DeployTxReceipt<TContract>
|
|
139
|
+
: TContract;
|
|
140
|
+
|
|
86
141
|
/**
|
|
87
142
|
* Contract interaction for deployment.
|
|
88
143
|
* Handles class publication, instance publication, and initialization of the contract.
|
|
@@ -92,8 +147,6 @@ export type SimulateDeployOptions = Omit<DeployOptions, 'fee'> & {
|
|
|
92
147
|
* then technically the contract has already been "created", and all of the contract's
|
|
93
148
|
* functions (private and utility) can be interacted-with immediately, without any
|
|
94
149
|
* "deployment tx".
|
|
95
|
-
*
|
|
96
|
-
* Extends the BaseContractInteraction class.
|
|
97
150
|
*/
|
|
98
151
|
export class DeployMethod<TContract extends ContractBase = ContractBase> extends BaseContractInteraction {
|
|
99
152
|
/** The contract instance to be deployed. */
|
|
@@ -142,13 +195,30 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
142
195
|
return finalExecutionPayload;
|
|
143
196
|
}
|
|
144
197
|
|
|
145
|
-
convertDeployOptionsToRequestOptions(options:
|
|
198
|
+
convertDeployOptionsToRequestOptions(options: DeployOptionsWithoutWait): RequestDeployOptions {
|
|
146
199
|
return {
|
|
147
200
|
...options,
|
|
148
201
|
deployer: !options?.universalDeploy ? options.from : undefined,
|
|
149
202
|
};
|
|
150
203
|
}
|
|
151
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Converts DeployOptions to SendOptions, stripping out the returnReceipt flag if present.
|
|
207
|
+
* @param options - Deploy options with wait parameter
|
|
208
|
+
* @returns Send options with wait parameter
|
|
209
|
+
*/
|
|
210
|
+
private convertDeployOptionsToSendOptions<W extends DeployInteractionWaitOptions>(
|
|
211
|
+
options: DeployOptions<W>,
|
|
212
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
213
|
+
): SendOptions<W extends { returnReceipt: true } ? WaitOpts : W> {
|
|
214
|
+
return {
|
|
215
|
+
...toSendOptions({
|
|
216
|
+
...options,
|
|
217
|
+
wait: options.wait as any,
|
|
218
|
+
}),
|
|
219
|
+
} as any;
|
|
220
|
+
}
|
|
221
|
+
|
|
152
222
|
/**
|
|
153
223
|
* Adds this contract to the wallet and returns the Contract object.
|
|
154
224
|
* @param options - Deployment options.
|
|
@@ -232,20 +302,42 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
232
302
|
|
|
233
303
|
/**
|
|
234
304
|
* 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.
|
|
305
|
+
* By default, waits for the transaction to be mined and returns the deployed contract instance.
|
|
237
306
|
*
|
|
238
307
|
* @param options - An object containing various deployment options such as contractAddressSalt and from.
|
|
239
|
-
* @returns
|
|
308
|
+
* @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
309
|
*/
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
310
|
+
// Overload for when wait is not specified at all - returns the contract
|
|
311
|
+
public override send(options: DeployOptionsWithoutWait): Promise<TContract>;
|
|
312
|
+
// Generic overload for explicit wait values
|
|
313
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
314
|
+
public override send<W extends DeployInteractionWaitOptions>(
|
|
315
|
+
options: DeployOptions<W>,
|
|
316
|
+
): Promise<DeployReturn<TContract, W>>;
|
|
317
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
318
|
+
public override async send(options: DeployOptions<DeployInteractionWaitOptions>): Promise<any> {
|
|
319
|
+
const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
|
|
320
|
+
const sendOptions = this.convertDeployOptionsToSendOptions(options);
|
|
321
|
+
|
|
322
|
+
if (options.wait === NO_WAIT) {
|
|
323
|
+
const txHash = await this.wallet.sendTx(executionPayload, sendOptions as SendOptions<NoWait>);
|
|
324
|
+
this.log.debug(`Sent deployment tx ${txHash.hash} of ${this.artifact.name} contract`);
|
|
325
|
+
return txHash;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const receipt = await this.wallet.sendTx(executionPayload, sendOptions as SendOptions<WaitOpts | undefined>);
|
|
329
|
+
this.log.debug(`Deployed ${this.artifact.name} contract in tx ${receipt.txHash}`);
|
|
330
|
+
|
|
331
|
+
// Attach contract instance
|
|
332
|
+
const instance = await this.getInstance(options);
|
|
333
|
+
const contract = this.postDeployCtor(instance, this.wallet) as TContract;
|
|
334
|
+
|
|
335
|
+
// Return full receipt if requested, otherwise just the contract
|
|
336
|
+
if (options.wait && typeof options.wait === 'object' && options.wait.returnReceipt) {
|
|
337
|
+
return { ...receipt, contract, instance };
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return contract;
|
|
249
341
|
}
|
|
250
342
|
|
|
251
343
|
/**
|
|
@@ -296,7 +388,7 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
|
|
|
296
388
|
*
|
|
297
389
|
* @returns An object containing the function return value and profile result.
|
|
298
390
|
*/
|
|
299
|
-
public async profile(options:
|
|
391
|
+
public async profile(options: DeployOptionsWithoutWait & ProfileInteractionOptions): Promise<TxProfileResult> {
|
|
300
392
|
const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
|
|
301
393
|
return await this.wallet.profileTx(executionPayload, {
|
|
302
394
|
...toProfileOptions(options),
|
|
@@ -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,15 +56,47 @@ 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;
|
|
65
85
|
};
|
|
66
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Represents options for calling a (constrained) function in a contract.
|
|
89
|
+
*/
|
|
90
|
+
export type SendInteractionOptions<W extends InteractionWaitOptions = undefined> = SendInteractionOptionsWithoutWait & {
|
|
91
|
+
/**
|
|
92
|
+
* Whether to wait for the transaction to be mined.
|
|
93
|
+
* - undefined (default): wait with default options and return TxReceipt
|
|
94
|
+
* - WaitOpts object: wait with custom options and return TxReceipt
|
|
95
|
+
* - NO_WAIT: return txHash immediately without waiting
|
|
96
|
+
*/
|
|
97
|
+
wait?: W;
|
|
98
|
+
};
|
|
99
|
+
|
|
67
100
|
/**
|
|
68
101
|
* Represents the options for simulating a contract function interaction.
|
|
69
102
|
* Allows specifying the address from which the method should be called.
|
|
@@ -110,11 +143,22 @@ export type SimulationReturn<T extends boolean | undefined> = T extends true
|
|
|
110
143
|
}
|
|
111
144
|
: any;
|
|
112
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Represents the result type of sending a transaction.
|
|
148
|
+
* If `wait` is NO_WAIT, returns TxHash immediately without waiting.
|
|
149
|
+
* If `wait` is undefined or WaitOpts, returns TReturn (defaults to TxReceipt) after waiting.
|
|
150
|
+
*/
|
|
151
|
+
export type SendReturn<T extends InteractionWaitOptions, TReturn = TxReceipt> = T extends NoWait ? TxHash : TReturn;
|
|
152
|
+
|
|
113
153
|
/**
|
|
114
154
|
* Transforms and cleans up the higher level SendInteractionOptions defined by the interaction into
|
|
115
155
|
* SendOptions, which are the ones that can be serialized and forwarded to the wallet
|
|
156
|
+
* @param options - The send interaction options with optional wait parameter
|
|
157
|
+
* @returns The send options to forward to the wallet
|
|
116
158
|
*/
|
|
117
|
-
export function toSendOptions
|
|
159
|
+
export function toSendOptions<W extends InteractionWaitOptions = undefined>(
|
|
160
|
+
options: SendInteractionOptions<W>,
|
|
161
|
+
): SendOptions<W> {
|
|
118
162
|
return {
|
|
119
163
|
...options,
|
|
120
164
|
fee: {
|
|
@@ -126,6 +170,7 @@ export function toSendOptions(options: SendInteractionOptions): SendOptions {
|
|
|
126
170
|
...options.fee?.gasSettings,
|
|
127
171
|
},
|
|
128
172
|
},
|
|
173
|
+
wait: options.wait, // Pass through wait option
|
|
129
174
|
};
|
|
130
175
|
}
|
|
131
176
|
|
|
@@ -165,18 +165,9 @@ const AuthRegistryContractArtifact: ContractArtifact = {
|
|
|
165
165
|
error_kind: 'string',
|
|
166
166
|
string: '0 has a square root; you cannot claim it is not square',
|
|
167
167
|
},
|
|
168
|
-
'9885968605480832328': {
|
|
169
|
-
error_kind: 'string',
|
|
170
|
-
string: 'Attempted to read past the length of a CapsuleArray',
|
|
171
|
-
},
|
|
172
168
|
'10135509984888824963': { error_kind: 'fmtstring', length: 58, item_types: [{ kind: 'field' }] },
|
|
173
169
|
'10791800398362570014': { error_kind: 'string', string: 'extend_from_bounded_vec out of bounds' },
|
|
174
|
-
'11021520179822076911': {
|
|
175
|
-
error_kind: 'string',
|
|
176
|
-
string: 'Attempted to delete past the length of a CapsuleArray',
|
|
177
|
-
},
|
|
178
170
|
'11692359521570349358': { error_kind: 'fmtstring', length: 40, item_types: [] },
|
|
179
|
-
'12327971061804302172': { error_kind: 'fmtstring', length: 98, item_types: [] },
|
|
180
171
|
'12469291177396340830': { error_kind: 'string', string: 'call to assert_max_bit_size' },
|
|
181
172
|
'12913276134398371456': { error_kind: 'string', string: 'push out of bounds' },
|
|
182
173
|
'13557316507370296400': {
|
|
@@ -244,7 +235,7 @@ const AuthRegistryContractArtifact: ContractArtifact = {
|
|
|
244
235
|
{
|
|
245
236
|
...{
|
|
246
237
|
functionType: FunctionType.UTILITY,
|
|
247
|
-
name: '
|
|
238
|
+
name: 'sync_state',
|
|
248
239
|
isOnlySelf: false,
|
|
249
240
|
isStatic: false,
|
|
250
241
|
isInitializer: false,
|
|
@@ -544,8 +535,8 @@ export class AuthRegistryContract extends ContractBase {
|
|
|
544
535
|
/** set_reject_all(reject: boolean) */
|
|
545
536
|
set_reject_all: ((reject: boolean) => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
|
|
546
537
|
|
|
547
|
-
/**
|
|
548
|
-
|
|
538
|
+
/** sync_state() */
|
|
539
|
+
sync_state: (() => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
|
|
549
540
|
|
|
550
541
|
/** utility_is_consumable(on_behalf_of: struct, message_hash: field) */
|
|
551
542
|
utility_is_consumable: ((on_behalf_of: AztecAddressLike, message_hash: FieldLike) => ContractFunctionInteraction) &
|
|
@@ -250,18 +250,9 @@ const ContractClassRegistryContractArtifact: ContractArtifact = {
|
|
|
250
250
|
error_kind: 'string',
|
|
251
251
|
string: '0 has a square root; you cannot claim it is not square',
|
|
252
252
|
},
|
|
253
|
-
'9885968605480832328': {
|
|
254
|
-
error_kind: 'string',
|
|
255
|
-
string: 'Attempted to read past the length of a CapsuleArray',
|
|
256
|
-
},
|
|
257
253
|
'10135509984888824963': { error_kind: 'fmtstring', length: 58, item_types: [{ kind: 'field' }] },
|
|
258
254
|
'10791800398362570014': { error_kind: 'string', string: 'extend_from_bounded_vec out of bounds' },
|
|
259
|
-
'11021520179822076911': {
|
|
260
|
-
error_kind: 'string',
|
|
261
|
-
string: 'Attempted to delete past the length of a CapsuleArray',
|
|
262
|
-
},
|
|
263
255
|
'11692359521570349358': { error_kind: 'fmtstring', length: 40, item_types: [] },
|
|
264
|
-
'12327971061804302172': { error_kind: 'fmtstring', length: 98, item_types: [] },
|
|
265
256
|
'12469291177396340830': { error_kind: 'string', string: 'call to assert_max_bit_size' },
|
|
266
257
|
'12913276134398371456': { error_kind: 'string', string: 'push out of bounds' },
|
|
267
258
|
'13557316507370296400': {
|
|
@@ -290,7 +281,7 @@ const ContractClassRegistryContractArtifact: ContractArtifact = {
|
|
|
290
281
|
{
|
|
291
282
|
...{
|
|
292
283
|
functionType: FunctionType.UTILITY,
|
|
293
|
-
name: '
|
|
284
|
+
name: 'sync_state',
|
|
294
285
|
isOnlySelf: false,
|
|
295
286
|
isStatic: false,
|
|
296
287
|
isInitializer: false,
|
|
@@ -436,7 +427,7 @@ export class ContractClassRegistryContract extends ContractBase {
|
|
|
436
427
|
) => ContractFunctionInteraction) &
|
|
437
428
|
Pick<ContractMethod, 'selector'>;
|
|
438
429
|
|
|
439
|
-
/**
|
|
440
|
-
|
|
430
|
+
/** sync_state() */
|
|
431
|
+
sync_state: (() => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
|
|
441
432
|
};
|
|
442
433
|
}
|
|
@@ -228,18 +228,9 @@ const ContractInstanceRegistryContractArtifact: ContractArtifact = {
|
|
|
228
228
|
error_kind: 'string',
|
|
229
229
|
string: '0 has a square root; you cannot claim it is not square',
|
|
230
230
|
},
|
|
231
|
-
'9885968605480832328': {
|
|
232
|
-
error_kind: 'string',
|
|
233
|
-
string: 'Attempted to read past the length of a CapsuleArray',
|
|
234
|
-
},
|
|
235
231
|
'10135509984888824963': { error_kind: 'fmtstring', length: 58, item_types: [{ kind: 'field' }] },
|
|
236
232
|
'10791800398362570014': { error_kind: 'string', string: 'extend_from_bounded_vec out of bounds' },
|
|
237
|
-
'11021520179822076911': {
|
|
238
|
-
error_kind: 'string',
|
|
239
|
-
string: 'Attempted to delete past the length of a CapsuleArray',
|
|
240
|
-
},
|
|
241
233
|
'11692359521570349358': { error_kind: 'fmtstring', length: 40, item_types: [] },
|
|
242
|
-
'12327971061804302172': { error_kind: 'fmtstring', length: 98, item_types: [] },
|
|
243
234
|
'12469291177396340830': { error_kind: 'string', string: 'call to assert_max_bit_size' },
|
|
244
235
|
'12913276134398371456': { error_kind: 'string', string: 'push out of bounds' },
|
|
245
236
|
'13557316507370296400': {
|
|
@@ -300,7 +291,7 @@ const ContractInstanceRegistryContractArtifact: ContractArtifact = {
|
|
|
300
291
|
{
|
|
301
292
|
...{
|
|
302
293
|
functionType: FunctionType.UTILITY,
|
|
303
|
-
name: '
|
|
294
|
+
name: 'sync_state',
|
|
304
295
|
isOnlySelf: false,
|
|
305
296
|
isStatic: false,
|
|
306
297
|
isInitializer: false,
|
|
@@ -401,6 +392,7 @@ const ContractInstanceRegistryContractArtifact: ContractArtifact = {
|
|
|
401
392
|
],
|
|
402
393
|
returnTypes: [],
|
|
403
394
|
errorTypes: {
|
|
395
|
+
'361444214588792908': { error_kind: 'string', string: 'attempt to multiply with overflow' },
|
|
404
396
|
'1998584279744703196': { error_kind: 'string', string: 'attempt to subtract with overflow' },
|
|
405
397
|
'6804164082532189961': { error_kind: 'string', string: 'New update delay is too low' },
|
|
406
398
|
'13455385521185560676': {
|
|
@@ -432,6 +424,7 @@ const ContractInstanceRegistryContractArtifact: ContractArtifact = {
|
|
|
432
424
|
],
|
|
433
425
|
returnTypes: [],
|
|
434
426
|
errorTypes: {
|
|
427
|
+
'361444214588792908': { error_kind: 'string', string: 'attempt to multiply with overflow' },
|
|
435
428
|
'1998584279744703196': { error_kind: 'string', string: 'attempt to subtract with overflow' },
|
|
436
429
|
'12579274401768182412': { error_kind: 'string', string: 'New contract class is not registered' },
|
|
437
430
|
'13455385521185560676': {
|
|
@@ -492,8 +485,8 @@ export class ContractInstanceRegistryContract extends ContractBase {
|
|
|
492
485
|
set_update_delay: ((new_update_delay: bigint | number) => ContractFunctionInteraction) &
|
|
493
486
|
Pick<ContractMethod, 'selector'>;
|
|
494
487
|
|
|
495
|
-
/**
|
|
496
|
-
|
|
488
|
+
/** sync_state() */
|
|
489
|
+
sync_state: (() => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
|
|
497
490
|
|
|
498
491
|
/** update(new_contract_class_id: struct) */
|
|
499
492
|
update: ((new_contract_class_id: WrappedFieldLike) => ContractFunctionInteraction) &
|