@aztec-labs/aztec.js 6.0.0-nightly.20260829
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/README.md +44 -0
- package/dest/account/account.d.ts +44 -0
- package/dest/account/account.d.ts.map +1 -0
- package/dest/account/account.js +31 -0
- package/dest/account/account_contract.d.ts +49 -0
- package/dest/account/account_contract.d.ts.map +1 -0
- package/dest/account/account_contract.js +20 -0
- package/dest/account/index.d.ts +11 -0
- package/dest/account/index.d.ts.map +1 -0
- package/dest/account/index.js +6 -0
- package/dest/api/abi.d.ts +4 -0
- package/dest/api/abi.d.ts.map +1 -0
- package/dest/api/abi.js +1 -0
- package/dest/api/account.d.ts +5 -0
- package/dest/api/account.d.ts.map +1 -0
- package/dest/api/account.js +3 -0
- package/dest/api/addresses.d.ts +4 -0
- package/dest/api/addresses.d.ts.map +1 -0
- package/dest/api/addresses.js +3 -0
- package/dest/api/authorization.d.ts +5 -0
- package/dest/api/authorization.d.ts.map +1 -0
- package/dest/api/authorization.js +4 -0
- package/dest/api/block.d.ts +3 -0
- package/dest/api/block.d.ts.map +1 -0
- package/dest/api/block.js +2 -0
- package/dest/api/contract.d.ts +48 -0
- package/dest/api/contract.d.ts.map +1 -0
- package/dest/api/contract.js +46 -0
- package/dest/api/crypto.d.ts +2 -0
- package/dest/api/crypto.d.ts.map +1 -0
- package/dest/api/crypto.js +1 -0
- package/dest/api/deployment.d.ts +4 -0
- package/dest/api/deployment.d.ts.map +1 -0
- package/dest/api/deployment.js +3 -0
- package/dest/api/eth_address.d.ts +2 -0
- package/dest/api/eth_address.d.ts.map +1 -0
- package/dest/api/eth_address.js +1 -0
- package/dest/api/ethereum.d.ts +2 -0
- package/dest/api/ethereum.d.ts.map +1 -0
- package/dest/api/ethereum.js +1 -0
- package/dest/api/event_cursor.d.ts +44 -0
- package/dest/api/event_cursor.d.ts.map +1 -0
- package/dest/api/event_cursor.js +42 -0
- package/dest/api/events.d.ts +36 -0
- package/dest/api/events.d.ts.map +1 -0
- package/dest/api/events.js +59 -0
- package/dest/api/fee.d.ts +6 -0
- package/dest/api/fee.d.ts.map +1 -0
- package/dest/api/fee.js +4 -0
- package/dest/api/fee_testing.d.ts +2 -0
- package/dest/api/fee_testing.d.ts.map +1 -0
- package/dest/api/fee_testing.js +1 -0
- package/dest/api/fields.d.ts +4 -0
- package/dest/api/fields.d.ts.map +1 -0
- package/dest/api/fields.js +3 -0
- package/dest/api/keys.d.ts +4 -0
- package/dest/api/keys.d.ts.map +1 -0
- package/dest/api/keys.js +3 -0
- package/dest/api/log.d.ts +3 -0
- package/dest/api/log.d.ts.map +1 -0
- package/dest/api/log.js +2 -0
- package/dest/api/messaging.d.ts +3 -0
- package/dest/api/messaging.d.ts.map +1 -0
- package/dest/api/messaging.js +2 -0
- package/dest/api/node.d.ts +25 -0
- package/dest/api/node.d.ts.map +1 -0
- package/dest/api/node.js +22 -0
- package/dest/api/note.d.ts +2 -0
- package/dest/api/note.d.ts.map +1 -0
- package/dest/api/note.js +1 -0
- package/dest/api/protocol.d.ts +6 -0
- package/dest/api/protocol.d.ts.map +1 -0
- package/dest/api/protocol.js +5 -0
- package/dest/api/trees.d.ts +3 -0
- package/dest/api/trees.d.ts.map +1 -0
- package/dest/api/trees.js +2 -0
- package/dest/api/tx.d.ts +3 -0
- package/dest/api/tx.d.ts.map +1 -0
- package/dest/api/tx.js +1 -0
- package/dest/api/utils.d.ts +13 -0
- package/dest/api/utils.d.ts.map +1 -0
- package/dest/api/utils.js +12 -0
- package/dest/api/wallet.d.ts +8 -0
- package/dest/api/wallet.d.ts.map +1 -0
- package/dest/api/wallet.js +7 -0
- package/dest/authorization/call_authorization_request.d.ts +46 -0
- package/dest/authorization/call_authorization_request.d.ts.map +1 -0
- package/dest/authorization/call_authorization_request.js +72 -0
- package/dest/contract/base_contract_interaction.d.ts +32 -0
- package/dest/contract/base_contract_interaction.d.ts.map +1 -0
- package/dest/contract/base_contract_interaction.js +24 -0
- package/dest/contract/batch_call.d.ts +27 -0
- package/dest/contract/batch_call.d.ts.map +1 -0
- package/dest/contract/batch_call.js +152 -0
- package/dest/contract/checker.d.ts +11 -0
- package/dest/contract/checker.d.ts.map +1 -0
- package/dest/contract/checker.js +107 -0
- package/dest/contract/contract.d.ts +33 -0
- package/dest/contract/contract.d.ts.map +1 -0
- package/dest/contract/contract.js +36 -0
- package/dest/contract/contract_base.d.ts +51 -0
- package/dest/contract/contract_base.d.ts.map +1 -0
- package/dest/contract/contract_base.js +38 -0
- package/dest/contract/contract_function_interaction.d.ts +67 -0
- package/dest/contract/contract_function_interaction.d.ts.map +1 -0
- package/dest/contract/contract_function_interaction.js +218 -0
- package/dest/contract/deploy_method.d.ts +433 -0
- package/dest/contract/deploy_method.d.ts.map +1 -0
- package/dest/contract/deploy_method.js +471 -0
- package/dest/contract/fastforward_contract_update.d.ts +25 -0
- package/dest/contract/fastforward_contract_update.d.ts.map +1 -0
- package/dest/contract/fastforward_contract_update.js +57 -0
- package/dest/contract/interaction_options.d.ts +213 -0
- package/dest/contract/interaction_options.d.ts.map +1 -0
- package/dest/contract/interaction_options.js +87 -0
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts +18 -0
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/contract-class-registry.js +137 -0
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +25 -0
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/contract-instance-registry.js +366 -0
- package/dest/contract/protocol_contracts/fee-juice.d.ts +24 -0
- package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/fee-juice.js +383 -0
- package/dest/contract/wait_for_proven.d.ts +18 -0
- package/dest/contract/wait_for_proven.d.ts.map +1 -0
- package/dest/contract/wait_for_proven.js +17 -0
- package/dest/contract/wait_opts.d.ts +21 -0
- package/dest/contract/wait_opts.d.ts.map +1 -0
- package/dest/contract/wait_opts.js +5 -0
- package/dest/deployment/contract_deployer.d.ts +28 -0
- package/dest/deployment/contract_deployer.d.ts.map +1 -0
- package/dest/deployment/contract_deployer.js +35 -0
- package/dest/deployment/publish_class.d.ts +6 -0
- package/dest/deployment/publish_class.d.ts.map +1 -0
- package/dest/deployment/publish_class.js +17 -0
- package/dest/deployment/publish_instance.d.ts +10 -0
- package/dest/deployment/publish_instance.d.ts.map +1 -0
- package/dest/deployment/publish_instance.js +11 -0
- package/dest/ethereum/portal_manager.d.ts +146 -0
- package/dest/ethereum/portal_manager.d.ts.map +1 -0
- package/dest/ethereum/portal_manager.js +415 -0
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts +23 -0
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -0
- package/dest/fee/fee_juice_payment_method_with_claim.js +46 -0
- package/dest/fee/fee_payment_method.d.ts +26 -0
- package/dest/fee/fee_payment_method.d.ts.map +1 -0
- package/dest/fee/fee_payment_method.js +3 -0
- package/dest/fee/private_fee_payment_method.d.ts +69 -0
- package/dest/fee/private_fee_payment_method.d.ts.map +1 -0
- package/dest/fee/private_fee_payment_method.js +122 -0
- package/dest/fee/public_fee_payment_method.d.ts +59 -0
- package/dest/fee/public_fee_payment_method.d.ts.map +1 -0
- package/dest/fee/public_fee_payment_method.js +116 -0
- package/dest/fee/sponsored_fee_payment.d.ts +17 -0
- package/dest/fee/sponsored_fee_payment.d.ts.map +1 -0
- package/dest/fee/sponsored_fee_payment.js +33 -0
- package/dest/scripts/generate_protocol_contract_types.d.ts +2 -0
- package/dest/scripts/generate_protocol_contract_types.d.ts.map +1 -0
- package/dest/scripts/generate_protocol_contract_types.js +128 -0
- package/dest/test/fixtures.d.ts +13 -0
- package/dest/test/fixtures.d.ts.map +1 -0
- package/dest/test/fixtures.js +185 -0
- package/dest/utils/abi_types.d.ts +32 -0
- package/dest/utils/abi_types.d.ts.map +1 -0
- package/dest/utils/abi_types.js +1 -0
- package/dest/utils/authwit.d.ts +119 -0
- package/dest/utils/authwit.d.ts.map +1 -0
- package/dest/utils/authwit.js +266 -0
- package/dest/utils/cross_chain.d.ts +28 -0
- package/dest/utils/cross_chain.d.ts.map +1 -0
- package/dest/utils/cross_chain.js +26 -0
- package/dest/utils/fee_juice.d.ts +8 -0
- package/dest/utils/fee_juice.d.ts.map +1 -0
- package/dest/utils/fee_juice.js +10 -0
- package/dest/utils/field_compressed_string.d.ts +17 -0
- package/dest/utils/field_compressed_string.d.ts.map +1 -0
- package/dest/utils/field_compressed_string.js +15 -0
- package/dest/utils/node.d.ts +24 -0
- package/dest/utils/node.d.ts.map +1 -0
- package/dest/utils/node.js +80 -0
- package/dest/utils/pub_key.d.ts +9 -0
- package/dest/utils/pub_key.d.ts.map +1 -0
- package/dest/utils/pub_key.js +8 -0
- package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +33 -0
- package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -0
- package/dest/wallet/account_entrypoint_meta_payment_method.js +63 -0
- package/dest/wallet/account_manager.d.ts +73 -0
- package/dest/wallet/account_manager.d.ts.map +1 -0
- package/dest/wallet/account_manager.js +102 -0
- package/dest/wallet/capabilities.d.ts +456 -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 +97 -0
- package/dest/wallet/deploy_account_method.d.ts.map +1 -0
- package/dest/wallet/deploy_account_method.js +127 -0
- package/dest/wallet/index.d.ts +5 -0
- package/dest/wallet/index.d.ts.map +1 -0
- package/dest/wallet/index.js +4 -0
- package/dest/wallet/tx_simulation_result_with_app_offset.d.ts +40 -0
- package/dest/wallet/tx_simulation_result_with_app_offset.d.ts.map +1 -0
- package/dest/wallet/tx_simulation_result_with_app_offset.js +65 -0
- package/dest/wallet/wallet.d.ts +1451 -0
- package/dest/wallet/wallet.d.ts.map +1 -0
- package/dest/wallet/wallet.js +430 -0
- package/package.json +138 -0
- package/src/account/account.ts +72 -0
- package/src/account/account_contract.ts +80 -0
- package/src/account/index.ts +12 -0
- package/src/api/README.md +7 -0
- package/src/api/abi.ts +42 -0
- package/src/api/account.ts +12 -0
- package/src/api/addresses.ts +3 -0
- package/src/api/authorization.ts +15 -0
- package/src/api/block.ts +2 -0
- package/src/api/contract.ts +86 -0
- package/src/api/crypto.ts +1 -0
- package/src/api/deployment.ts +3 -0
- package/src/api/eth_address.ts +1 -0
- package/src/api/ethereum.ts +10 -0
- package/src/api/event_cursor.ts +60 -0
- package/src/api/events.ts +79 -0
- package/src/api/fee.ts +5 -0
- package/src/api/fee_testing.ts +1 -0
- package/src/api/fields.ts +3 -0
- package/src/api/keys.ts +8 -0
- package/src/api/log.ts +2 -0
- package/src/api/messaging.ts +2 -0
- package/src/api/node.ts +30 -0
- package/src/api/note.ts +1 -0
- package/src/api/protocol.ts +6 -0
- package/src/api/trees.ts +2 -0
- package/src/api/tx.ts +20 -0
- package/src/api/utils.ts +14 -0
- package/src/api/wallet.ts +83 -0
- package/src/authorization/call_authorization_request.ts +93 -0
- package/src/contract/base_contract_interaction.ts +62 -0
- package/src/contract/batch_call.ts +188 -0
- package/src/contract/checker.ts +122 -0
- package/src/contract/contract.ts +52 -0
- package/src/contract/contract_base.ts +73 -0
- package/src/contract/contract_function_interaction.ts +297 -0
- package/src/contract/deploy_method.ts +877 -0
- package/src/contract/fastforward_contract_update.ts +71 -0
- package/src/contract/interaction_options.ts +301 -0
- package/src/contract/protocol_contracts/contract-class-registry.ts +104 -0
- package/src/contract/protocol_contracts/contract-instance-registry.ts +241 -0
- package/src/contract/protocol_contracts/fee-juice.ts +257 -0
- package/src/contract/wait_for_proven.ts +43 -0
- package/src/contract/wait_opts.ts +26 -0
- package/src/deployment/contract_deployer.ts +40 -0
- package/src/deployment/publish_class.ts +34 -0
- package/src/deployment/publish_instance.ts +24 -0
- package/src/ethereum/portal_manager.ts +539 -0
- package/src/fee/fee_juice_payment_method_with_claim.ts +63 -0
- package/src/fee/fee_payment_method.ts +26 -0
- package/src/fee/private_fee_payment_method.ts +145 -0
- package/src/fee/public_fee_payment_method.ts +145 -0
- package/src/fee/sponsored_fee_payment.ts +45 -0
- package/src/scripts/generate_protocol_contract_types.ts +160 -0
- package/src/test/fixtures.ts +126 -0
- package/src/utils/abi_types.ts +32 -0
- package/src/utils/authwit.ts +327 -0
- package/src/utils/cross_chain.ts +55 -0
- package/src/utils/fee_juice.ts +14 -0
- package/src/utils/field_compressed_string.ts +27 -0
- package/src/utils/node.ts +110 -0
- package/src/utils/pub_key.ts +12 -0
- package/src/wallet/account_entrypoint_meta_payment_method.ts +76 -0
- package/src/wallet/account_manager.ts +164 -0
- package/src/wallet/capabilities.ts +505 -0
- package/src/wallet/deploy_account_method.ts +234 -0
- package/src/wallet/index.ts +4 -0
- package/src/wallet/tx_simulation_result_with_app_offset.ts +100 -0
- package/src/wallet/wallet.ts +668 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
2
|
+
import { FieldReader } from '@aztec-labs/foundation/serialize';
|
|
3
|
+
import { AuthorizationSelector, FunctionSelector } from '@aztec-labs/stdlib/abi';
|
|
4
|
+
import { computeInnerAuthWitHash } from '@aztec-labs/stdlib/auth-witness';
|
|
5
|
+
import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
6
|
+
import { computeVarArgsHash } from '@aztec-labs/stdlib/hash';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* An authwit request for a function call. Includes the preimage of the data
|
|
10
|
+
* to be signed, as opposed of just the inner hash.
|
|
11
|
+
*/
|
|
12
|
+
export class CallAuthorizationRequest {
|
|
13
|
+
private constructor(
|
|
14
|
+
/**
|
|
15
|
+
* The selector of the authwit type, used to identify it
|
|
16
|
+
* when emitted from `emit_offchain_effect`oracle.
|
|
17
|
+
* Computed as poseidon2("CallAuthwit((Field),(u32),Field)".to_bytes())
|
|
18
|
+
*/
|
|
19
|
+
public selector: AuthorizationSelector,
|
|
20
|
+
/**
|
|
21
|
+
* The inner hash of the authwit, computed as
|
|
22
|
+
* poseidon2([msg_sender, selector, args_hash])
|
|
23
|
+
*/
|
|
24
|
+
public innerHash: Fr,
|
|
25
|
+
/**
|
|
26
|
+
* The address on whose behalf the auth witness should be created.
|
|
27
|
+
* This is the account that must sign the authorization.
|
|
28
|
+
*/
|
|
29
|
+
public onBehalfOf: AztecAddress,
|
|
30
|
+
/**
|
|
31
|
+
* The address performing the call
|
|
32
|
+
*/
|
|
33
|
+
public msgSender: AztecAddress,
|
|
34
|
+
/**
|
|
35
|
+
* The selector of the function that is to be authorized
|
|
36
|
+
* */
|
|
37
|
+
public functionSelector: FunctionSelector,
|
|
38
|
+
/**
|
|
39
|
+
* The hash of the arguments to the function call,
|
|
40
|
+
*/
|
|
41
|
+
public argsHash: Fr,
|
|
42
|
+
/**
|
|
43
|
+
* The arguments to the function call.
|
|
44
|
+
*/
|
|
45
|
+
public args: Fr[],
|
|
46
|
+
) {}
|
|
47
|
+
|
|
48
|
+
/** Validates that innerHash and argsHash are consistent with the provided preimage fields. */
|
|
49
|
+
private async validate(): Promise<void> {
|
|
50
|
+
const expectedArgsHash = await computeVarArgsHash(this.args);
|
|
51
|
+
if (!expectedArgsHash.equals(this.argsHash)) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`CallAuthorizationRequest argsHash mismatch: expected ${expectedArgsHash.toString()}, got ${this.argsHash.toString()}`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
const expectedInnerHash = await computeInnerAuthWitHash([
|
|
57
|
+
this.msgSender.toField(),
|
|
58
|
+
this.functionSelector.toField(),
|
|
59
|
+
this.argsHash,
|
|
60
|
+
]);
|
|
61
|
+
if (!expectedInnerHash.equals(this.innerHash)) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`CallAuthorizationRequest innerHash mismatch: expected ${expectedInnerHash.toString()}, got ${this.innerHash.toString()}`,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static getSelector(): Promise<AuthorizationSelector> {
|
|
69
|
+
return AuthorizationSelector.fromSignature('CallAuthorization((Field),(u32),Field)');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static async fromFields(fields: Fr[]): Promise<CallAuthorizationRequest> {
|
|
73
|
+
const expectedSelector = await CallAuthorizationRequest.getSelector();
|
|
74
|
+
const reader = FieldReader.asReader(fields);
|
|
75
|
+
const selector = AuthorizationSelector.fromField(reader.readField());
|
|
76
|
+
if (!selector.equals(expectedSelector)) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`Invalid authorization selector for CallAuthwit: expected ${expectedSelector.toString()}, got ${selector.toString()}`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
const request = new CallAuthorizationRequest(
|
|
82
|
+
selector,
|
|
83
|
+
reader.readField(), // inner_hash
|
|
84
|
+
AztecAddress.fromFieldUnsafe(reader.readField()), // on_behalf_of
|
|
85
|
+
AztecAddress.fromFieldUnsafe(reader.readField()), // msg_sender
|
|
86
|
+
FunctionSelector.fromField(reader.readField()), // fn_selector
|
|
87
|
+
reader.readField(), // args_hash
|
|
88
|
+
reader.readFieldArray(reader.remainingFields()), // args
|
|
89
|
+
);
|
|
90
|
+
await request.validate();
|
|
91
|
+
return request;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createLogger } from '@aztec-labs/foundation/log';
|
|
2
|
+
import type { AuthWitness } from '@aztec-labs/stdlib/auth-witness';
|
|
3
|
+
import type { Capsule, ExecutionPayload, TxReceipt } from '@aztec-labs/stdlib/tx';
|
|
4
|
+
|
|
5
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
6
|
+
import {
|
|
7
|
+
type InteractionWaitOptions,
|
|
8
|
+
type RequestInteractionOptions,
|
|
9
|
+
type SendInteractionOptions,
|
|
10
|
+
type SendInteractionOptionsWithoutWait,
|
|
11
|
+
type SendReturn,
|
|
12
|
+
type TxSendResultMined,
|
|
13
|
+
toSendOptions,
|
|
14
|
+
} from './interaction_options.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Base class for an interaction with a contract, be it a deployment, a function call, or a batch.
|
|
18
|
+
* Implements the sequence create/simulate/send.
|
|
19
|
+
*/
|
|
20
|
+
export abstract class BaseContractInteraction {
|
|
21
|
+
protected log = createLogger('aztecjs:contract_interaction');
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
protected wallet: Wallet,
|
|
25
|
+
protected authWitnesses: AuthWitness[] = [],
|
|
26
|
+
protected capsules: Capsule[] = [],
|
|
27
|
+
) {}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns an execution request that represents this operation.
|
|
31
|
+
* Can be used as a building block for constructing batch requests.
|
|
32
|
+
* @param options - An optional object containing additional configuration for the transaction.
|
|
33
|
+
* @returns An execution request wrapped in promise.
|
|
34
|
+
*/
|
|
35
|
+
public abstract request(options?: RequestInteractionOptions): Promise<ExecutionPayload>;
|
|
36
|
+
|
|
37
|
+
// docs:start:send
|
|
38
|
+
/**
|
|
39
|
+
* Sends a transaction to the contract function with the specified options.
|
|
40
|
+
* By default, waits for the transaction to be mined and returns the receipt (or custom type).
|
|
41
|
+
* @param options - An object containing 'from' property representing
|
|
42
|
+
* the AztecAddress of the sender, optional fee configuration, and optional wait settings
|
|
43
|
+
* @returns TReturn (if wait is undefined/WaitOpts) or TxHash (if wait is NO_WAIT)
|
|
44
|
+
*/
|
|
45
|
+
// Overload for when wait is not specified at all - returns { receipt: TReturn, offchainEffects }
|
|
46
|
+
public send<TReturn = TxReceipt>(options: SendInteractionOptionsWithoutWait): Promise<TxSendResultMined<TReturn>>;
|
|
47
|
+
// Generic overload for explicit wait values
|
|
48
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
49
|
+
public send<TReturn = TxReceipt, W extends InteractionWaitOptions = undefined>(
|
|
50
|
+
options: SendInteractionOptions<W>,
|
|
51
|
+
): Promise<SendReturn<W, TReturn>>;
|
|
52
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
53
|
+
public async send<TReturn = TxReceipt>(
|
|
54
|
+
options: SendInteractionOptions<InteractionWaitOptions>,
|
|
55
|
+
): Promise<SendReturn<typeof options.wait, TReturn>> {
|
|
56
|
+
// docs:end:send
|
|
57
|
+
const executionPayload = await this.request(options);
|
|
58
|
+
const sendOptions = toSendOptions(options);
|
|
59
|
+
|
|
60
|
+
return (await this.wallet.sendTx(executionPayload, sendOptions as any)) as SendReturn<typeof options.wait, TReturn>;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { type FunctionCall, FunctionType, decodeFromAbi } from '@aztec-labs/stdlib/abi';
|
|
2
|
+
import { ExecutionPayload, HashedValues, UtilityExecutionResult, mergeExecutionPayloads } from '@aztec-labs/stdlib/tx';
|
|
3
|
+
|
|
4
|
+
import type { TxSimulationResultWithAppOffset } from '../wallet/tx_simulation_result_with_app_offset.js';
|
|
5
|
+
import type { BatchedMethod, Wallet } from '../wallet/wallet.js';
|
|
6
|
+
import { BaseContractInteraction } from './base_contract_interaction.js';
|
|
7
|
+
import {
|
|
8
|
+
NO_FROM,
|
|
9
|
+
type RequestInteractionOptions,
|
|
10
|
+
type SimulateInteractionOptions,
|
|
11
|
+
type SimulationResult,
|
|
12
|
+
extractOffchainOutput,
|
|
13
|
+
toSimulateOptions,
|
|
14
|
+
} from './interaction_options.js';
|
|
15
|
+
|
|
16
|
+
/** A batch of function calls to be sent as a single transaction through a wallet. */
|
|
17
|
+
// docs:start:batch_call_class
|
|
18
|
+
export class BatchCall extends BaseContractInteraction {
|
|
19
|
+
constructor(
|
|
20
|
+
wallet: Wallet,
|
|
21
|
+
protected interactions: (BaseContractInteraction | ExecutionPayload)[],
|
|
22
|
+
private extraHashedArgs: HashedValues[] = [],
|
|
23
|
+
) {
|
|
24
|
+
super(wallet);
|
|
25
|
+
}
|
|
26
|
+
// docs:end:batch_call_class
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns an execution request that represents this operation.
|
|
30
|
+
* @param options - An optional object containing additional configuration for the request generation.
|
|
31
|
+
* @returns An execution payload wrapped in promise.
|
|
32
|
+
*/
|
|
33
|
+
public async request(options: RequestInteractionOptions = {}): Promise<ExecutionPayload> {
|
|
34
|
+
const requests = await this.getExecutionPayloads();
|
|
35
|
+
const feeExecutionPayload = options.fee?.paymentMethod
|
|
36
|
+
? await options.fee.paymentMethod.getExecutionPayload()
|
|
37
|
+
: undefined;
|
|
38
|
+
const { authWitnesses, capsules } = options;
|
|
39
|
+
|
|
40
|
+
// Propagates the included authwitnesses, capsules, and extraHashedArgs potentially baked into the interaction
|
|
41
|
+
const initialExecutionPayload = new ExecutionPayload(
|
|
42
|
+
[],
|
|
43
|
+
this.authWitnesses.concat(authWitnesses ?? []),
|
|
44
|
+
this.capsules.concat(capsules ?? []),
|
|
45
|
+
this.extraHashedArgs,
|
|
46
|
+
);
|
|
47
|
+
const finalExecutionPayload = feeExecutionPayload
|
|
48
|
+
? mergeExecutionPayloads([initialExecutionPayload, feeExecutionPayload, ...requests])
|
|
49
|
+
: mergeExecutionPayloads([initialExecutionPayload, ...requests]);
|
|
50
|
+
return finalExecutionPayload;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Simulates/executes the batch, supporting private, public and utility functions. Although this is a single
|
|
55
|
+
* interaction with the wallet, private and public functions will be grouped into a single ExecutionPayload
|
|
56
|
+
* that the wallet will simulate as a single transaction. Utility function calls will be executed
|
|
57
|
+
* one by one.
|
|
58
|
+
* @param options - An optional object containing additional configuration for the interaction.
|
|
59
|
+
* @returns The results of all the interactions that make up the batch
|
|
60
|
+
*/
|
|
61
|
+
public async simulate(options: SimulateInteractionOptions): Promise<SimulationResult> {
|
|
62
|
+
const feeExecutionPayload = options.fee?.paymentMethod
|
|
63
|
+
? await options.fee.paymentMethod.getExecutionPayload()
|
|
64
|
+
: undefined;
|
|
65
|
+
// A call-contributing fee payment method prepends its calls in front of the batch (see the merge below). Those
|
|
66
|
+
// calls shift the return-value indices, and the wallet-side app-call offset does not absorb them: it only counts
|
|
67
|
+
// the wallet's own fee payment method, not one supplied through options.fee. We offset each app call's result
|
|
68
|
+
// index by the number of prepended fee calls of the matching type.
|
|
69
|
+
const feePrivateCallCount = feeExecutionPayload?.calls.filter(c => c.type === FunctionType.PRIVATE).length ?? 0;
|
|
70
|
+
const feePublicCallCount = feeExecutionPayload?.calls.filter(c => c.type === FunctionType.PUBLIC).length ?? 0;
|
|
71
|
+
|
|
72
|
+
const { indexedExecutionPayloads, utility } = (await this.getExecutionPayloads()).reduce<{
|
|
73
|
+
/** Keep track of the number of private calls to retrieve the return values */
|
|
74
|
+
privateIndex: 0;
|
|
75
|
+
/** Keep track of the number of public calls to retrieve the return values */
|
|
76
|
+
publicIndex: 0;
|
|
77
|
+
/** The public and private function execution requests in the batch */
|
|
78
|
+
indexedExecutionPayloads: [ExecutionPayload, number, number][];
|
|
79
|
+
/** The utility function calls in the batch. */
|
|
80
|
+
utility: [FunctionCall, number][];
|
|
81
|
+
}>(
|
|
82
|
+
(acc, current, index) => {
|
|
83
|
+
const call = current.calls[0];
|
|
84
|
+
if (call.type === FunctionType.UTILITY) {
|
|
85
|
+
acc.utility.push([call, index]);
|
|
86
|
+
} else {
|
|
87
|
+
acc.indexedExecutionPayloads.push([
|
|
88
|
+
current,
|
|
89
|
+
index,
|
|
90
|
+
call.type === FunctionType.PRIVATE ? acc.privateIndex++ : acc.publicIndex++,
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
return acc;
|
|
94
|
+
},
|
|
95
|
+
{ indexedExecutionPayloads: [], utility: [], publicIndex: 0, privateIndex: 0 },
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const batchRequests: BatchedMethod[] = [];
|
|
99
|
+
|
|
100
|
+
// Add utility calls to batch
|
|
101
|
+
for (const [call] of utility) {
|
|
102
|
+
batchRequests.push({
|
|
103
|
+
name: 'executeUtility' as const,
|
|
104
|
+
args: [call, { scopes: options.from === NO_FROM ? [] : [options.from], authWitnesses: options.authWitnesses }],
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Add tx simulation to batch if there are any private/public calls
|
|
109
|
+
if (indexedExecutionPayloads.length > 0) {
|
|
110
|
+
const payloads = indexedExecutionPayloads.map(([request]) => request);
|
|
111
|
+
const combinedPayload = mergeExecutionPayloads(
|
|
112
|
+
feeExecutionPayload ? [feeExecutionPayload, ...payloads] : payloads,
|
|
113
|
+
);
|
|
114
|
+
const executionPayload = new ExecutionPayload(
|
|
115
|
+
combinedPayload.calls,
|
|
116
|
+
combinedPayload.authWitnesses.concat(options.authWitnesses ?? []),
|
|
117
|
+
combinedPayload.capsules.concat(options.capsules ?? []),
|
|
118
|
+
combinedPayload.extraHashedArgs,
|
|
119
|
+
combinedPayload.feePayer,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
batchRequests.push({
|
|
123
|
+
name: 'simulateTx' as const,
|
|
124
|
+
args: [executionPayload, toSimulateOptions(options)],
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const batchResults = batchRequests.length > 0 ? await this.wallet.batch(batchRequests) : [];
|
|
129
|
+
|
|
130
|
+
const results: any[] = [];
|
|
131
|
+
|
|
132
|
+
// Process utility results (they come first in batch results)
|
|
133
|
+
for (let i = 0; i < utility.length; i++) {
|
|
134
|
+
const [call, resultIndex] = utility[i];
|
|
135
|
+
const wrappedResult = batchResults[i];
|
|
136
|
+
if (wrappedResult.name === 'executeUtility') {
|
|
137
|
+
const utilityResult = wrappedResult.result as UtilityExecutionResult;
|
|
138
|
+
const rawReturnValues = utilityResult.result;
|
|
139
|
+
const offchainOutput = extractOffchainOutput(utilityResult.offchainEffects, utilityResult.anchorBlockTimestamp);
|
|
140
|
+
results[resultIndex] = {
|
|
141
|
+
result: rawReturnValues ? decodeFromAbi(call.returnType, rawReturnValues) : undefined,
|
|
142
|
+
...offchainOutput,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Process tx simulation result (it comes last if present)
|
|
148
|
+
let simulatedTx: TxSimulationResultWithAppOffset | undefined;
|
|
149
|
+
if (indexedExecutionPayloads.length > 0) {
|
|
150
|
+
const txResultWrapper = batchResults[utility.length];
|
|
151
|
+
if (txResultWrapper.name === 'simulateTx') {
|
|
152
|
+
simulatedTx = txResultWrapper.result as TxSimulationResultWithAppOffset;
|
|
153
|
+
indexedExecutionPayloads.forEach(([request, callIndex, resultIndex]) => {
|
|
154
|
+
const call = request.calls[0];
|
|
155
|
+
// For public functions we retrieve the values directly from the public output. Both indices are offset by
|
|
156
|
+
// the fee payment method's own calls, which are prepended ahead of the batch.
|
|
157
|
+
const rawReturnValues =
|
|
158
|
+
call.type == FunctionType.PRIVATE
|
|
159
|
+
? simulatedTx!.getPrivateReturnValuesOfAppCall(feePrivateCallCount + resultIndex)?.values
|
|
160
|
+
: simulatedTx!.getPublicReturnValues()?.[feePublicCallCount + resultIndex].values;
|
|
161
|
+
|
|
162
|
+
results[callIndex] = {
|
|
163
|
+
result: rawReturnValues ? decodeFromAbi(call.returnType, rawReturnValues) : undefined,
|
|
164
|
+
...extractOffchainOutput(
|
|
165
|
+
simulatedTx!.offchainEffects,
|
|
166
|
+
simulatedTx!.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp,
|
|
167
|
+
),
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (options.includeMetadata && simulatedTx) {
|
|
174
|
+
return {
|
|
175
|
+
result: results,
|
|
176
|
+
gasUsed: simulatedTx.gasUsed,
|
|
177
|
+
offchainEffects: [],
|
|
178
|
+
offchainMessages: [],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return { result: results, offchainEffects: [], offchainMessages: [] };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
protected async getExecutionPayloads(): Promise<ExecutionPayload[]> {
|
|
186
|
+
return await Promise.all(this.interactions.map(i => (i instanceof ExecutionPayload ? i : i.request())));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AbiType,
|
|
3
|
+
type BasicType,
|
|
4
|
+
type ContractArtifact,
|
|
5
|
+
type StructType,
|
|
6
|
+
getDefaultInitializer,
|
|
7
|
+
} from '@aztec-labs/stdlib/abi';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Represents a type derived from input type T with the 'kind' property removed.
|
|
11
|
+
* Useful when checking attributes of a specific kind and validating their types.
|
|
12
|
+
*/
|
|
13
|
+
type TypeWithoutKind<T> = Omit<{ [key in keyof T]: any }, 'kind'>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Validates the given ContractArtifact object by checking its functions and their parameters.
|
|
17
|
+
* Ensures that the ABI has at least one function, a constructor, valid bytecode, and correct parameter types.
|
|
18
|
+
* Throws an error if any inconsistency is detected during the validation process.
|
|
19
|
+
*
|
|
20
|
+
* @param artifact - The ContractArtifact object to be validated.
|
|
21
|
+
* @returns A boolean value indicating whether the artifact is valid or not.
|
|
22
|
+
*/
|
|
23
|
+
export function abiChecker(artifact: ContractArtifact) {
|
|
24
|
+
if (!artifact.functions || artifact.functions.length === 0) {
|
|
25
|
+
throw new Error('artifact has no functions');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
artifact.functions.forEach(func => {
|
|
29
|
+
if (!('name' in func && typeof func.name === 'string' && func.name.length > 0)) {
|
|
30
|
+
throw new Error('ABI function has no name');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// TODO: implement a better check for bytecode (right now only checks if it's > 0)
|
|
34
|
+
if (!('bytecode' in func && func.bytecode.length > 0)) {
|
|
35
|
+
throw new Error('ABI function parameter has incorrect bytecode');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func.parameters.forEach(param => {
|
|
39
|
+
if (!param.type) {
|
|
40
|
+
throw new Error('ABI function parameter has no type');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
abiParameterTypeChecker(param.type);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (!getDefaultInitializer(artifact)) {
|
|
48
|
+
throw new Error('ABI has no constructor');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Validates the ABI function parameter's type by checking its kind and attributes.
|
|
56
|
+
* Throws an error if the type has an unrecognized kind or incorrectly formed attributes.
|
|
57
|
+
* Additionally, checks nested types for array and struct kinds.
|
|
58
|
+
*
|
|
59
|
+
* @param type - The AbiType object representing the type of the ABI function parameter.
|
|
60
|
+
* @returns A boolean value indicating whether the type is valid or not.
|
|
61
|
+
*/
|
|
62
|
+
function abiParameterTypeChecker(type: AbiType): boolean {
|
|
63
|
+
switch (type.kind) {
|
|
64
|
+
case 'field':
|
|
65
|
+
case 'boolean':
|
|
66
|
+
return checkAttributes(type, {});
|
|
67
|
+
case 'integer':
|
|
68
|
+
return checkAttributes(type, { sign: 'string', width: 'number' });
|
|
69
|
+
case 'string':
|
|
70
|
+
return checkAttributes(type, { length: 'number' });
|
|
71
|
+
case 'array':
|
|
72
|
+
return checkAttributes(type, { length: 'number', type: 'object' }) && abiParameterTypeChecker(type.type);
|
|
73
|
+
case 'struct':
|
|
74
|
+
return checkAttributes(type, { fields: 'object', path: 'string' }) && checkStruct(type);
|
|
75
|
+
default:
|
|
76
|
+
throw new Error('ABI function parameter has an unrecognized type');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Check if the structure of the AbiType 'struct' is valid by ensuring field names are strings
|
|
82
|
+
* and their type attribute passes the abiParameterTypeChecker. Returns true on successful validation,
|
|
83
|
+
* otherwise throws an error providing insight into the incorrect formation in the struct.
|
|
84
|
+
*
|
|
85
|
+
* @param type - The StructType object containing an array of fields to validate.
|
|
86
|
+
* @returns A boolean value indicating successful validation of the struct's fields.
|
|
87
|
+
*/
|
|
88
|
+
function checkStruct(type: StructType) {
|
|
89
|
+
return type.fields.reduce((acc, field) => {
|
|
90
|
+
if (!('name' in field && typeof field.name === 'string')) {
|
|
91
|
+
throw new Error('ABI function parameter has an incorrectly formed struct');
|
|
92
|
+
}
|
|
93
|
+
return acc && abiParameterTypeChecker(field.type);
|
|
94
|
+
}, true);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Check if a provided ABI type has the correct attributes and their associated types.
|
|
99
|
+
* This function compares the given 'type' object's keys with the expected attribute types
|
|
100
|
+
* specified in 'incompleteAttributes', as well as the required 'kind' property.
|
|
101
|
+
* Throws an error if there are any unrecognized attributes or incorrect attribute types.
|
|
102
|
+
*
|
|
103
|
+
* @param type - The ABI type object to be checked for correct attributes.
|
|
104
|
+
* @param incompleteAttributes - An object representing the expected attribute types without the 'kind' property.
|
|
105
|
+
* @returns Returns true if the provided ABI type has the correct attributes and their associated types, otherwise throws an error.
|
|
106
|
+
*/
|
|
107
|
+
function checkAttributes<T extends BasicType<string>>(type: T, incompleteAttributes: TypeWithoutKind<T>) {
|
|
108
|
+
const typeKeys = Object.keys(type);
|
|
109
|
+
const attributes = { ...incompleteAttributes, kind: 'string' };
|
|
110
|
+
|
|
111
|
+
if (typeKeys.length !== Object.keys(attributes).length) {
|
|
112
|
+
throw new Error(`Unrecognized attribute on type ${type.kind}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
typeKeys.forEach(element => {
|
|
116
|
+
if (!(element in type && typeof (type as any)[element] === (attributes as any)[element])) {
|
|
117
|
+
throw new Error(`ABI function parameter has an incorrectly formed ${type.kind}`);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
|
|
2
|
+
import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
3
|
+
import type { ContractInstanceWithAddress } from '@aztec-labs/stdlib/contract';
|
|
4
|
+
|
|
5
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
6
|
+
import { ContractBase } from './contract_base.js';
|
|
7
|
+
import { type DeployInstantiationOptions, DeployMethod } from './deploy_method.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The Contract class represents a contract and provides utility methods for interacting with it.
|
|
11
|
+
* It enables the creation of ContractFunctionInteraction instances for each function in the contract's ABI,
|
|
12
|
+
* allowing users to call or send transactions to these functions. Additionally, the Contract class can be used
|
|
13
|
+
* to attach the contract instance to a deployed contract onchain through the PXE, which facilitates
|
|
14
|
+
* interaction with Aztec's privacy protocol.
|
|
15
|
+
*/
|
|
16
|
+
export class Contract extends ContractBase {
|
|
17
|
+
/**
|
|
18
|
+
* Gets a contract instance.
|
|
19
|
+
* @param address - The address of the contract instance.
|
|
20
|
+
* @param artifact - Build artifact of the contract.
|
|
21
|
+
* @param wallet - The wallet to use when interacting with the contract.
|
|
22
|
+
* @returns A promise that resolves to a new Contract instance.
|
|
23
|
+
*/
|
|
24
|
+
public static at(address: AztecAddress, artifact: ContractArtifact, wallet: Wallet): Contract {
|
|
25
|
+
return new Contract(address, artifact, wallet);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates a tx to deploy (initialize and/or publish) a new instance of a contract.
|
|
30
|
+
*
|
|
31
|
+
* @param wallet - The wallet for executing the deployment.
|
|
32
|
+
* @param artifact - Build artifact of the contract to deploy
|
|
33
|
+
* @param args - Arguments for the constructor.
|
|
34
|
+
* @param constructorName - The name of the constructor function to call.
|
|
35
|
+
* @param instantiation - Other address-affecting parameters (salt, deployer / universalDeploy, publicKeys).
|
|
36
|
+
*/
|
|
37
|
+
public static deploy(
|
|
38
|
+
wallet: Wallet,
|
|
39
|
+
artifact: ContractArtifact,
|
|
40
|
+
args: any[],
|
|
41
|
+
constructorName?: string,
|
|
42
|
+
instantiation?: DeployInstantiationOptions,
|
|
43
|
+
) {
|
|
44
|
+
const postDeployCtor = (instance: ContractInstanceWithAddress, wallet: Wallet) =>
|
|
45
|
+
Contract.at(instance.address, artifact, wallet);
|
|
46
|
+
return DeployMethod.create(
|
|
47
|
+
wallet,
|
|
48
|
+
{ artifact, postDeployCtor, args, constructorNameOrArtifact: constructorName },
|
|
49
|
+
instantiation,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ContractArtifact,
|
|
3
|
+
type FieldLayout,
|
|
4
|
+
type FunctionAbi,
|
|
5
|
+
FunctionSelector,
|
|
6
|
+
getAllFunctionAbis,
|
|
7
|
+
} from '@aztec-labs/stdlib/abi';
|
|
8
|
+
import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
9
|
+
|
|
10
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
11
|
+
import { ContractFunctionInteraction } from './contract_function_interaction.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Type representing a contract method that returns a ContractFunctionInteraction instance
|
|
15
|
+
* and has a readonly 'selector' property of type Buffer. Takes any number of arguments.
|
|
16
|
+
*/
|
|
17
|
+
export type ContractMethod = ((...args: any[]) => ContractFunctionInteraction) & {
|
|
18
|
+
/**
|
|
19
|
+
* The unique identifier for a contract function in bytecode.
|
|
20
|
+
*/
|
|
21
|
+
selector: () => Promise<FunctionSelector>;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Type representing the storage layout of a contract.
|
|
26
|
+
*/
|
|
27
|
+
export type ContractStorageLayout<T extends string> = {
|
|
28
|
+
[K in T]: FieldLayout;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Abstract implementation of a contract extended by the Contract class and generated contract types.
|
|
33
|
+
*/
|
|
34
|
+
export class ContractBase {
|
|
35
|
+
/**
|
|
36
|
+
* An object containing contract methods mapped to their respective names.
|
|
37
|
+
*/
|
|
38
|
+
public methods: { [name: string]: ContractMethod } = {};
|
|
39
|
+
|
|
40
|
+
protected constructor(
|
|
41
|
+
/** The contract's address. */
|
|
42
|
+
public readonly address: AztecAddress,
|
|
43
|
+
/** The Application Binary Interface for the contract. */
|
|
44
|
+
public readonly artifact: ContractArtifact,
|
|
45
|
+
/** The wallet used for interacting with this contract. */
|
|
46
|
+
public wallet: Wallet,
|
|
47
|
+
) {
|
|
48
|
+
getAllFunctionAbis(artifact).forEach((f: FunctionAbi) => {
|
|
49
|
+
const interactionFunction = (...args: any[]) => {
|
|
50
|
+
return new ContractFunctionInteraction(this.wallet, this.address, f, args);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
this.methods[f.name] = Object.assign(interactionFunction, {
|
|
54
|
+
/**
|
|
55
|
+
* A getter for users to fetch the function selector.
|
|
56
|
+
* @returns Selector of the function.
|
|
57
|
+
*/
|
|
58
|
+
selector() {
|
|
59
|
+
return FunctionSelector.fromNameAndParameters(f.name, f.parameters);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Creates a new instance of the contract wrapper attached to a different wallet.
|
|
67
|
+
* @param wallet - Wallet to use for sending txs.
|
|
68
|
+
* @returns A new contract instance.
|
|
69
|
+
*/
|
|
70
|
+
public withWallet(wallet: Wallet): this {
|
|
71
|
+
return new ContractBase(this.address, this.artifact, wallet) as this;
|
|
72
|
+
}
|
|
73
|
+
}
|