@aztec/aztec.js 0.0.1-commit.f295ac2 → 0.0.1-commit.f8ca9b2f3
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/account.d.ts +25 -40
- package/dest/account/account.d.ts.map +1 -1
- package/dest/account/account.js +19 -47
- package/dest/account/account_contract.d.ts +7 -8
- package/dest/account/account_contract.d.ts.map +1 -1
- package/dest/account/account_with_secret_key.d.ts +18 -7
- package/dest/account/account_with_secret_key.d.ts.map +1 -1
- package/dest/account/account_with_secret_key.js +21 -4
- package/dest/account/index.d.ts +3 -2
- package/dest/account/index.d.ts.map +1 -1
- package/dest/account/index.js +2 -0
- package/dest/account/signerless_account.d.ts +5 -6
- package/dest/account/signerless_account.d.ts.map +1 -1
- package/dest/account/signerless_account.js +8 -11
- package/dest/api/account.d.ts +2 -4
- package/dest/api/account.d.ts.map +1 -1
- package/dest/api/account.js +1 -3
- package/dest/api/authorization.d.ts +2 -2
- package/dest/api/authorization.d.ts.map +1 -1
- package/dest/api/authorization.js +1 -1
- 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/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 +6 -6
- 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 +1 -10
- package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/auth-registry.js +97 -467
- 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 +2 -672
- 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 -482
- 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 +14 -412
- 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 +23 -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 +23 -22
- 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 +8 -6
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +5 -9
- 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/account_entrypoint_meta_payment_method.d.ts +5 -8
- package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -1
- package/dest/wallet/account_entrypoint_meta_payment_method.js +28 -43
- package/dest/wallet/account_manager.d.ts +1 -7
- package/dest/wallet/account_manager.d.ts.map +1 -1
- package/dest/wallet/account_manager.js +5 -11
- package/dest/wallet/capabilities.d.ts +444 -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 +34 -6
- package/dest/wallet/deploy_account_method.d.ts.map +1 -1
- package/dest/wallet/deploy_account_method.js +7 -5
- 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 +1493 -94
- package/dest/wallet/wallet.d.ts.map +1 -1
- package/dest/wallet/wallet.js +158 -26
- package/package.json +19 -10
- package/src/account/account.ts +34 -58
- package/src/account/account_contract.ts +6 -7
- package/src/account/account_with_secret_key.ts +33 -8
- package/src/account/index.ts +2 -1
- package/src/account/signerless_account.ts +13 -12
- package/src/api/account.ts +9 -3
- package/src/api/authorization.ts +1 -0
- 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 +47 -1
- package/src/contract/base_contract_interaction.ts +27 -15
- package/src/contract/contract_function_interaction.ts +13 -6
- package/src/contract/deploy_method.ts +115 -23
- package/src/contract/interaction_options.ts +49 -4
- package/src/contract/protocol_contracts/auth-registry.ts +45 -236
- package/src/contract/protocol_contracts/contract-class-registry.ts +1 -347
- package/src/contract/protocol_contracts/contract-instance-registry.ts +34 -233
- package/src/contract/protocol_contracts/fee-juice.ts +4 -202
- package/src/contract/protocol_contracts/multi-call-entrypoint.ts +6 -12
- package/src/contract/protocol_contracts/public-checks.ts +6 -14
- 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 +19 -7
- package/src/utils/node.ts +62 -0
- package/src/wallet/account_entrypoint_meta_payment_method.ts +28 -60
- package/src/wallet/account_manager.ts +5 -13
- package/src/wallet/capabilities.ts +491 -0
- package/src/wallet/deploy_account_method.ts +37 -13
- package/src/wallet/index.ts +1 -0
- package/src/wallet/wallet.ts +214 -48
- package/dest/account/interface.d.ts +0 -19
- package/dest/account/interface.d.ts.map +0 -1
- package/dest/account/interface.js +0 -5
- 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/account/interface.ts +0 -25
- 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/contract.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The `contract` module provides utilities for deploying and interacting with contracts, based on a
|
|
3
3
|
* `Wallet` instance and a compiled artifact. Refer to the {@link account} module for how to obtain a valid
|
|
4
|
-
* `Wallet` instance, and to the {@link https://docs.aztec.network/developers/aztec-nr/
|
|
4
|
+
* `Wallet` instance, and to the {@link https://docs.aztec.network/developers/aztec-nr/compiling_contracts | Compiling contracts}
|
|
5
5
|
* section of the documentation for how to generate an artifact out of your Noir source code.
|
|
6
6
|
*
|
|
7
7
|
* The {@link Contract} class is the main class in this module, and provides static methods for deploying
|
|
@@ -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,12 +33,11 @@
|
|
|
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
|
-
* {@link https://docs.aztec.network/developers/aztec-nr/
|
|
40
|
+
* {@link https://docs.aztec.network/developers/aztec-nr/compiling_contracts#use-generated-interfaces | autogenerated type-safe interfaces}
|
|
34
41
|
* for interacting with your contracts.
|
|
35
42
|
*
|
|
36
43
|
* @packageDocumentation
|
|
@@ -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/deployment.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { publishContractClass } from '../deployment/publish_class.js';
|
|
2
|
-
export { broadcastPrivateFunction, broadcastUtilityFunction } from '../deployment/broadcast_function.js';
|
|
3
2
|
export { publishInstance } from '../deployment/publish_instance.js';
|
|
4
3
|
export { ContractDeployer } from '../deployment/contract_deployer.js';
|
package/src/api/events.ts
CHANGED
|
@@ -1,44 +1,52 @@
|
|
|
1
1
|
import { type EventMetadataDefinition, EventSelector, decodeFromAbi } from '@aztec/stdlib/abi';
|
|
2
2
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
3
3
|
|
|
4
|
+
import type { PublicEvent, PublicEventFilter } from '../wallet/wallet.js';
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Returns decoded public events given search parameters.
|
|
6
8
|
* @param node - The node to request events from
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* @param eventMetadataDef - Metadata of the event. This should be the class generated from the contract. e.g. Contract.events.Event
|
|
10
|
+
* @param filter - Filter options for the event query:
|
|
11
|
+
* - `contractAddress`: The address of the contract that emitted the events.
|
|
12
|
+
* - `txHash`: Transaction in which the events were emitted.
|
|
13
|
+
* - `fromBlock`: The block number from which to start fetching events (inclusive). Defaults to 1.
|
|
14
|
+
* - `toBlock`: The block number until which to fetch events (not inclusive). Defaults to latest + 1.
|
|
15
|
+
* @returns - The decoded events with metadata.
|
|
11
16
|
*/
|
|
12
|
-
export async function
|
|
17
|
+
export async function getPublicEvents<T>(
|
|
13
18
|
node: AztecNode,
|
|
14
19
|
eventMetadataDef: EventMetadataDefinition,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
): Promise<T[]> {
|
|
20
|
+
filter: PublicEventFilter,
|
|
21
|
+
): Promise<PublicEvent<T>[]> {
|
|
18
22
|
const { logs } = await node.getPublicLogs({
|
|
19
|
-
fromBlock:
|
|
20
|
-
toBlock:
|
|
23
|
+
fromBlock: filter.fromBlock ? Number(filter.fromBlock) : undefined,
|
|
24
|
+
toBlock: filter.toBlock ? Number(filter.toBlock) : undefined,
|
|
25
|
+
txHash: filter.txHash,
|
|
26
|
+
contractAddress: filter.contractAddress,
|
|
21
27
|
});
|
|
22
28
|
|
|
23
|
-
const decodedEvents =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
`Something is weird here, we have matching EventSelectors, but the actual payload has mismatched length. Expected ${expectedLength}. Got ${log.log.fields.length}.`,
|
|
30
|
-
);
|
|
31
|
-
}
|
|
29
|
+
const decodedEvents: PublicEvent<T>[] = [];
|
|
30
|
+
|
|
31
|
+
for (const log of logs) {
|
|
32
|
+
const logFields = log.log.getEmittedFields();
|
|
33
|
+
// Event selector is at the last position of the emitted fields
|
|
34
|
+
const logEventSelector = EventSelector.fromField(logFields[logFields.length - 1]);
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
36
|
+
if (!logEventSelector.equals(eventMetadataDef.eventSelector)) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
decodedEvents.push({
|
|
41
|
+
event: decodeFromAbi([eventMetadataDef.abiType], log.log.fields) as T,
|
|
42
|
+
metadata: {
|
|
43
|
+
l2BlockNumber: log.id.blockNumber,
|
|
44
|
+
l2BlockHash: log.id.blockHash,
|
|
45
|
+
txHash: log.id.txHash,
|
|
46
|
+
contractAddress: log.log.contractAddress,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
42
50
|
|
|
43
51
|
return decodedEvents;
|
|
44
52
|
}
|
package/src/api/fields.ts
CHANGED
package/src/api/keys.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { type PublicKey, PublicKeys } from '@aztec/stdlib/keys';
|
|
2
2
|
export {
|
|
3
|
-
|
|
3
|
+
computeAppNullifierHidingKey,
|
|
4
4
|
deriveKeys,
|
|
5
5
|
deriveMasterIncomingViewingSecretKey,
|
|
6
|
-
|
|
6
|
+
deriveMasterNullifierHidingKey,
|
|
7
7
|
} from '@aztec/stdlib/keys';
|
|
8
8
|
export { generatePublicKey } from '../utils/pub_key.js';
|
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,16 @@ export {
|
|
|
11
11
|
type Wallet,
|
|
12
12
|
type PrivateEvent,
|
|
13
13
|
type PrivateEventFilter,
|
|
14
|
-
|
|
14
|
+
type PublicEvent,
|
|
15
|
+
type PublicEventFilter,
|
|
16
|
+
type ContractMetadata,
|
|
17
|
+
type ContractClassMetadata,
|
|
18
|
+
AppCapabilitiesSchema,
|
|
19
|
+
WalletCapabilitiesSchema,
|
|
15
20
|
ExecutionPayloadSchema,
|
|
16
21
|
GasSettingsOptionSchema,
|
|
17
22
|
WalletSimulationFeeOptionSchema,
|
|
23
|
+
WaitOptsSchema,
|
|
18
24
|
SendOptionsSchema,
|
|
19
25
|
SimulateOptionsSchema,
|
|
20
26
|
ProfileOptionsSchema,
|
|
@@ -23,9 +29,49 @@ export {
|
|
|
23
29
|
EventMetadataDefinitionSchema,
|
|
24
30
|
PrivateEventSchema,
|
|
25
31
|
PrivateEventFilterSchema,
|
|
32
|
+
PublicEventSchema,
|
|
33
|
+
PublicEventFilterSchema,
|
|
34
|
+
ContractClassMetadataSchema,
|
|
35
|
+
ContractMetadataSchema,
|
|
26
36
|
WalletSchema,
|
|
37
|
+
ContractFunctionPatternSchema,
|
|
38
|
+
AccountsCapabilitySchema,
|
|
39
|
+
GrantedAccountsCapabilitySchema,
|
|
40
|
+
ContractsCapabilitySchema,
|
|
41
|
+
GrantedContractsCapabilitySchema,
|
|
42
|
+
ContractClassesCapabilitySchema,
|
|
43
|
+
GrantedContractClassesCapabilitySchema,
|
|
44
|
+
SimulationCapabilitySchema,
|
|
45
|
+
GrantedSimulationCapabilitySchema,
|
|
46
|
+
TransactionCapabilitySchema,
|
|
47
|
+
GrantedTransactionCapabilitySchema,
|
|
48
|
+
DataCapabilitySchema,
|
|
49
|
+
GrantedDataCapabilitySchema,
|
|
50
|
+
CapabilitySchema,
|
|
51
|
+
GrantedCapabilitySchema,
|
|
27
52
|
} from '../wallet/wallet.js';
|
|
28
53
|
|
|
54
|
+
export {
|
|
55
|
+
type AppCapabilities,
|
|
56
|
+
type WalletCapabilities,
|
|
57
|
+
CAPABILITY_VERSION,
|
|
58
|
+
type Capability,
|
|
59
|
+
type GrantedCapability,
|
|
60
|
+
type ContractFunctionPattern,
|
|
61
|
+
type AccountsCapability,
|
|
62
|
+
type GrantedAccountsCapability,
|
|
63
|
+
type ContractsCapability,
|
|
64
|
+
type GrantedContractsCapability,
|
|
65
|
+
type ContractClassesCapability,
|
|
66
|
+
type GrantedContractClassesCapability,
|
|
67
|
+
type SimulationCapability,
|
|
68
|
+
type GrantedSimulationCapability,
|
|
69
|
+
type TransactionCapability,
|
|
70
|
+
type GrantedTransactionCapability,
|
|
71
|
+
type DataCapability,
|
|
72
|
+
type GrantedDataCapability,
|
|
73
|
+
} from '../wallet/capabilities.js';
|
|
74
|
+
|
|
29
75
|
export { AccountManager } from '../wallet/account_manager.js';
|
|
30
76
|
|
|
31
77
|
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,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
|
/**
|
|
@@ -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),
|