@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,152 @@
|
|
|
1
|
+
import { FunctionType, decodeFromAbi } from '@aztec-labs/stdlib/abi';
|
|
2
|
+
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec-labs/stdlib/tx';
|
|
3
|
+
import { BaseContractInteraction } from './base_contract_interaction.js';
|
|
4
|
+
import { NO_FROM, extractOffchainOutput, toSimulateOptions } from './interaction_options.js';
|
|
5
|
+
/** A batch of function calls to be sent as a single transaction through a wallet. */ // docs:start:batch_call_class
|
|
6
|
+
export class BatchCall extends BaseContractInteraction {
|
|
7
|
+
interactions;
|
|
8
|
+
extraHashedArgs;
|
|
9
|
+
constructor(wallet, interactions, extraHashedArgs = []){
|
|
10
|
+
super(wallet), this.interactions = interactions, this.extraHashedArgs = extraHashedArgs;
|
|
11
|
+
}
|
|
12
|
+
// docs:end:batch_call_class
|
|
13
|
+
/**
|
|
14
|
+
* Returns an execution request that represents this operation.
|
|
15
|
+
* @param options - An optional object containing additional configuration for the request generation.
|
|
16
|
+
* @returns An execution payload wrapped in promise.
|
|
17
|
+
*/ async request(options = {}) {
|
|
18
|
+
const requests = await this.getExecutionPayloads();
|
|
19
|
+
const feeExecutionPayload = options.fee?.paymentMethod ? await options.fee.paymentMethod.getExecutionPayload() : undefined;
|
|
20
|
+
const { authWitnesses, capsules } = options;
|
|
21
|
+
// Propagates the included authwitnesses, capsules, and extraHashedArgs potentially baked into the interaction
|
|
22
|
+
const initialExecutionPayload = new ExecutionPayload([], this.authWitnesses.concat(authWitnesses ?? []), this.capsules.concat(capsules ?? []), this.extraHashedArgs);
|
|
23
|
+
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
24
|
+
initialExecutionPayload,
|
|
25
|
+
feeExecutionPayload,
|
|
26
|
+
...requests
|
|
27
|
+
]) : mergeExecutionPayloads([
|
|
28
|
+
initialExecutionPayload,
|
|
29
|
+
...requests
|
|
30
|
+
]);
|
|
31
|
+
return finalExecutionPayload;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Simulates/executes the batch, supporting private, public and utility functions. Although this is a single
|
|
35
|
+
* interaction with the wallet, private and public functions will be grouped into a single ExecutionPayload
|
|
36
|
+
* that the wallet will simulate as a single transaction. Utility function calls will be executed
|
|
37
|
+
* one by one.
|
|
38
|
+
* @param options - An optional object containing additional configuration for the interaction.
|
|
39
|
+
* @returns The results of all the interactions that make up the batch
|
|
40
|
+
*/ async simulate(options) {
|
|
41
|
+
const feeExecutionPayload = options.fee?.paymentMethod ? await options.fee.paymentMethod.getExecutionPayload() : undefined;
|
|
42
|
+
// A call-contributing fee payment method prepends its calls in front of the batch (see the merge below). Those
|
|
43
|
+
// calls shift the return-value indices, and the wallet-side app-call offset does not absorb them: it only counts
|
|
44
|
+
// the wallet's own fee payment method, not one supplied through options.fee. We offset each app call's result
|
|
45
|
+
// index by the number of prepended fee calls of the matching type.
|
|
46
|
+
const feePrivateCallCount = feeExecutionPayload?.calls.filter((c)=>c.type === FunctionType.PRIVATE).length ?? 0;
|
|
47
|
+
const feePublicCallCount = feeExecutionPayload?.calls.filter((c)=>c.type === FunctionType.PUBLIC).length ?? 0;
|
|
48
|
+
const { indexedExecutionPayloads, utility } = (await this.getExecutionPayloads()).reduce((acc, current, index)=>{
|
|
49
|
+
const call = current.calls[0];
|
|
50
|
+
if (call.type === FunctionType.UTILITY) {
|
|
51
|
+
acc.utility.push([
|
|
52
|
+
call,
|
|
53
|
+
index
|
|
54
|
+
]);
|
|
55
|
+
} else {
|
|
56
|
+
acc.indexedExecutionPayloads.push([
|
|
57
|
+
current,
|
|
58
|
+
index,
|
|
59
|
+
call.type === FunctionType.PRIVATE ? acc.privateIndex++ : acc.publicIndex++
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
return acc;
|
|
63
|
+
}, {
|
|
64
|
+
indexedExecutionPayloads: [],
|
|
65
|
+
utility: [],
|
|
66
|
+
publicIndex: 0,
|
|
67
|
+
privateIndex: 0
|
|
68
|
+
});
|
|
69
|
+
const batchRequests = [];
|
|
70
|
+
// Add utility calls to batch
|
|
71
|
+
for (const [call] of utility){
|
|
72
|
+
batchRequests.push({
|
|
73
|
+
name: 'executeUtility',
|
|
74
|
+
args: [
|
|
75
|
+
call,
|
|
76
|
+
{
|
|
77
|
+
scopes: options.from === NO_FROM ? [] : [
|
|
78
|
+
options.from
|
|
79
|
+
],
|
|
80
|
+
authWitnesses: options.authWitnesses
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// Add tx simulation to batch if there are any private/public calls
|
|
86
|
+
if (indexedExecutionPayloads.length > 0) {
|
|
87
|
+
const payloads = indexedExecutionPayloads.map(([request])=>request);
|
|
88
|
+
const combinedPayload = mergeExecutionPayloads(feeExecutionPayload ? [
|
|
89
|
+
feeExecutionPayload,
|
|
90
|
+
...payloads
|
|
91
|
+
] : payloads);
|
|
92
|
+
const executionPayload = new ExecutionPayload(combinedPayload.calls, combinedPayload.authWitnesses.concat(options.authWitnesses ?? []), combinedPayload.capsules.concat(options.capsules ?? []), combinedPayload.extraHashedArgs, combinedPayload.feePayer);
|
|
93
|
+
batchRequests.push({
|
|
94
|
+
name: 'simulateTx',
|
|
95
|
+
args: [
|
|
96
|
+
executionPayload,
|
|
97
|
+
toSimulateOptions(options)
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const batchResults = batchRequests.length > 0 ? await this.wallet.batch(batchRequests) : [];
|
|
102
|
+
const results = [];
|
|
103
|
+
// Process utility results (they come first in batch results)
|
|
104
|
+
for(let i = 0; i < utility.length; i++){
|
|
105
|
+
const [call, resultIndex] = utility[i];
|
|
106
|
+
const wrappedResult = batchResults[i];
|
|
107
|
+
if (wrappedResult.name === 'executeUtility') {
|
|
108
|
+
const utilityResult = wrappedResult.result;
|
|
109
|
+
const rawReturnValues = utilityResult.result;
|
|
110
|
+
const offchainOutput = extractOffchainOutput(utilityResult.offchainEffects, utilityResult.anchorBlockTimestamp);
|
|
111
|
+
results[resultIndex] = {
|
|
112
|
+
result: rawReturnValues ? decodeFromAbi(call.returnType, rawReturnValues) : undefined,
|
|
113
|
+
...offchainOutput
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Process tx simulation result (it comes last if present)
|
|
118
|
+
let simulatedTx;
|
|
119
|
+
if (indexedExecutionPayloads.length > 0) {
|
|
120
|
+
const txResultWrapper = batchResults[utility.length];
|
|
121
|
+
if (txResultWrapper.name === 'simulateTx') {
|
|
122
|
+
simulatedTx = txResultWrapper.result;
|
|
123
|
+
indexedExecutionPayloads.forEach(([request, callIndex, resultIndex])=>{
|
|
124
|
+
const call = request.calls[0];
|
|
125
|
+
// For public functions we retrieve the values directly from the public output. Both indices are offset by
|
|
126
|
+
// the fee payment method's own calls, which are prepended ahead of the batch.
|
|
127
|
+
const rawReturnValues = call.type == FunctionType.PRIVATE ? simulatedTx.getPrivateReturnValuesOfAppCall(feePrivateCallCount + resultIndex)?.values : simulatedTx.getPublicReturnValues()?.[feePublicCallCount + resultIndex].values;
|
|
128
|
+
results[callIndex] = {
|
|
129
|
+
result: rawReturnValues ? decodeFromAbi(call.returnType, rawReturnValues) : undefined,
|
|
130
|
+
...extractOffchainOutput(simulatedTx.offchainEffects, simulatedTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp)
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (options.includeMetadata && simulatedTx) {
|
|
136
|
+
return {
|
|
137
|
+
result: results,
|
|
138
|
+
gasUsed: simulatedTx.gasUsed,
|
|
139
|
+
offchainEffects: [],
|
|
140
|
+
offchainMessages: []
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
result: results,
|
|
145
|
+
offchainEffects: [],
|
|
146
|
+
offchainMessages: []
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
async getExecutionPayloads() {
|
|
150
|
+
return await Promise.all(this.interactions.map((i)=>i instanceof ExecutionPayload ? i : i.request()));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ContractArtifact } from '@aztec-labs/stdlib/abi';
|
|
2
|
+
/**
|
|
3
|
+
* Validates the given ContractArtifact object by checking its functions and their parameters.
|
|
4
|
+
* Ensures that the ABI has at least one function, a constructor, valid bytecode, and correct parameter types.
|
|
5
|
+
* Throws an error if any inconsistency is detected during the validation process.
|
|
6
|
+
*
|
|
7
|
+
* @param artifact - The ContractArtifact object to be validated.
|
|
8
|
+
* @returns A boolean value indicating whether the artifact is valid or not.
|
|
9
|
+
*/
|
|
10
|
+
export declare function abiChecker(artifact: ContractArtifact): boolean;
|
|
11
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hlY2tlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbnRyYWN0L2NoZWNrZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUdMLEtBQUssZ0JBQWdCLEVBR3RCLE1BQU0sd0JBQXdCLENBQUM7QUFRaEM7Ozs7Ozs7R0FPRztBQUNILHdCQUFnQixVQUFVLENBQUMsUUFBUSxFQUFFLGdCQUFnQixXQTZCcEQifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../../src/contract/checker.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,gBAAgB,EAGtB,MAAM,wBAAwB,CAAC;AAQhC;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,gBAAgB,WA6BpD"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { getDefaultInitializer } from '@aztec-labs/stdlib/abi';
|
|
2
|
+
/**
|
|
3
|
+
* Validates the given ContractArtifact object by checking its functions and their parameters.
|
|
4
|
+
* Ensures that the ABI has at least one function, a constructor, valid bytecode, and correct parameter types.
|
|
5
|
+
* Throws an error if any inconsistency is detected during the validation process.
|
|
6
|
+
*
|
|
7
|
+
* @param artifact - The ContractArtifact object to be validated.
|
|
8
|
+
* @returns A boolean value indicating whether the artifact is valid or not.
|
|
9
|
+
*/ export function abiChecker(artifact) {
|
|
10
|
+
if (!artifact.functions || artifact.functions.length === 0) {
|
|
11
|
+
throw new Error('artifact has no functions');
|
|
12
|
+
}
|
|
13
|
+
artifact.functions.forEach((func)=>{
|
|
14
|
+
if (!('name' in func && typeof func.name === 'string' && func.name.length > 0)) {
|
|
15
|
+
throw new Error('ABI function has no name');
|
|
16
|
+
}
|
|
17
|
+
// TODO: implement a better check for bytecode (right now only checks if it's > 0)
|
|
18
|
+
if (!('bytecode' in func && func.bytecode.length > 0)) {
|
|
19
|
+
throw new Error('ABI function parameter has incorrect bytecode');
|
|
20
|
+
}
|
|
21
|
+
func.parameters.forEach((param)=>{
|
|
22
|
+
if (!param.type) {
|
|
23
|
+
throw new Error('ABI function parameter has no type');
|
|
24
|
+
}
|
|
25
|
+
abiParameterTypeChecker(param.type);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
if (!getDefaultInitializer(artifact)) {
|
|
29
|
+
throw new Error('ABI has no constructor');
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Validates the ABI function parameter's type by checking its kind and attributes.
|
|
35
|
+
* Throws an error if the type has an unrecognized kind or incorrectly formed attributes.
|
|
36
|
+
* Additionally, checks nested types for array and struct kinds.
|
|
37
|
+
*
|
|
38
|
+
* @param type - The AbiType object representing the type of the ABI function parameter.
|
|
39
|
+
* @returns A boolean value indicating whether the type is valid or not.
|
|
40
|
+
*/ function abiParameterTypeChecker(type) {
|
|
41
|
+
switch(type.kind){
|
|
42
|
+
case 'field':
|
|
43
|
+
case 'boolean':
|
|
44
|
+
return checkAttributes(type, {});
|
|
45
|
+
case 'integer':
|
|
46
|
+
return checkAttributes(type, {
|
|
47
|
+
sign: 'string',
|
|
48
|
+
width: 'number'
|
|
49
|
+
});
|
|
50
|
+
case 'string':
|
|
51
|
+
return checkAttributes(type, {
|
|
52
|
+
length: 'number'
|
|
53
|
+
});
|
|
54
|
+
case 'array':
|
|
55
|
+
return checkAttributes(type, {
|
|
56
|
+
length: 'number',
|
|
57
|
+
type: 'object'
|
|
58
|
+
}) && abiParameterTypeChecker(type.type);
|
|
59
|
+
case 'struct':
|
|
60
|
+
return checkAttributes(type, {
|
|
61
|
+
fields: 'object',
|
|
62
|
+
path: 'string'
|
|
63
|
+
}) && checkStruct(type);
|
|
64
|
+
default:
|
|
65
|
+
throw new Error('ABI function parameter has an unrecognized type');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Check if the structure of the AbiType 'struct' is valid by ensuring field names are strings
|
|
70
|
+
* and their type attribute passes the abiParameterTypeChecker. Returns true on successful validation,
|
|
71
|
+
* otherwise throws an error providing insight into the incorrect formation in the struct.
|
|
72
|
+
*
|
|
73
|
+
* @param type - The StructType object containing an array of fields to validate.
|
|
74
|
+
* @returns A boolean value indicating successful validation of the struct's fields.
|
|
75
|
+
*/ function checkStruct(type) {
|
|
76
|
+
return type.fields.reduce((acc, field)=>{
|
|
77
|
+
if (!('name' in field && typeof field.name === 'string')) {
|
|
78
|
+
throw new Error('ABI function parameter has an incorrectly formed struct');
|
|
79
|
+
}
|
|
80
|
+
return acc && abiParameterTypeChecker(field.type);
|
|
81
|
+
}, true);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Check if a provided ABI type has the correct attributes and their associated types.
|
|
85
|
+
* This function compares the given 'type' object's keys with the expected attribute types
|
|
86
|
+
* specified in 'incompleteAttributes', as well as the required 'kind' property.
|
|
87
|
+
* Throws an error if there are any unrecognized attributes or incorrect attribute types.
|
|
88
|
+
*
|
|
89
|
+
* @param type - The ABI type object to be checked for correct attributes.
|
|
90
|
+
* @param incompleteAttributes - An object representing the expected attribute types without the 'kind' property.
|
|
91
|
+
* @returns Returns true if the provided ABI type has the correct attributes and their associated types, otherwise throws an error.
|
|
92
|
+
*/ function checkAttributes(type, incompleteAttributes) {
|
|
93
|
+
const typeKeys = Object.keys(type);
|
|
94
|
+
const attributes = {
|
|
95
|
+
...incompleteAttributes,
|
|
96
|
+
kind: 'string'
|
|
97
|
+
};
|
|
98
|
+
if (typeKeys.length !== Object.keys(attributes).length) {
|
|
99
|
+
throw new Error(`Unrecognized attribute on type ${type.kind}`);
|
|
100
|
+
}
|
|
101
|
+
typeKeys.forEach((element)=>{
|
|
102
|
+
if (!(element in type && typeof type[element] === attributes[element])) {
|
|
103
|
+
throw new Error(`ABI function parameter has an incorrectly formed ${type.kind}`);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
|
|
2
|
+
import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
3
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
4
|
+
import { ContractBase } from './contract_base.js';
|
|
5
|
+
import { type DeployInstantiationOptions, DeployMethod } from './deploy_method.js';
|
|
6
|
+
/**
|
|
7
|
+
* The Contract class represents a contract and provides utility methods for interacting with it.
|
|
8
|
+
* It enables the creation of ContractFunctionInteraction instances for each function in the contract's ABI,
|
|
9
|
+
* allowing users to call or send transactions to these functions. Additionally, the Contract class can be used
|
|
10
|
+
* to attach the contract instance to a deployed contract onchain through the PXE, which facilitates
|
|
11
|
+
* interaction with Aztec's privacy protocol.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Contract extends ContractBase {
|
|
14
|
+
/**
|
|
15
|
+
* Gets a contract instance.
|
|
16
|
+
* @param address - The address of the contract instance.
|
|
17
|
+
* @param artifact - Build artifact of the contract.
|
|
18
|
+
* @param wallet - The wallet to use when interacting with the contract.
|
|
19
|
+
* @returns A promise that resolves to a new Contract instance.
|
|
20
|
+
*/
|
|
21
|
+
static at(address: AztecAddress, artifact: ContractArtifact, wallet: Wallet): Contract;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a tx to deploy (initialize and/or publish) a new instance of a contract.
|
|
24
|
+
*
|
|
25
|
+
* @param wallet - The wallet for executing the deployment.
|
|
26
|
+
* @param artifact - Build artifact of the contract to deploy
|
|
27
|
+
* @param args - Arguments for the constructor.
|
|
28
|
+
* @param constructorName - The name of the constructor function to call.
|
|
29
|
+
* @param instantiation - Other address-affecting parameters (salt, deployer / universalDeploy, publicKeys).
|
|
30
|
+
*/
|
|
31
|
+
static deploy(wallet: Wallet, artifact: ContractArtifact, args: any[], constructorName?: string, instantiation?: DeployInstantiationOptions): DeployMethod<Contract>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3QuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy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E,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,KAAK,0BAA0B,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEnF;;;;;;GAMG;AACH,qBAAa,QAAS,SAAQ,YAAY;IACxC;;;;;;OAMG;IACH,OAAc,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAE5F;IAED;;;;;;;;OAQG;IACH,OAAc,MAAM,CAClB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,EAAE,GAAG,EAAE,EACX,eAAe,CAAC,EAAE,MAAM,EACxB,aAAa,CAAC,EAAE,0BAA0B,0BAS3C;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ContractBase } from './contract_base.js';
|
|
2
|
+
import { DeployMethod } from './deploy_method.js';
|
|
3
|
+
/**
|
|
4
|
+
* The Contract class represents a contract and provides utility methods for interacting with it.
|
|
5
|
+
* It enables the creation of ContractFunctionInteraction instances for each function in the contract's ABI,
|
|
6
|
+
* allowing users to call or send transactions to these functions. Additionally, the Contract class can be used
|
|
7
|
+
* to attach the contract instance to a deployed contract onchain through the PXE, which facilitates
|
|
8
|
+
* interaction with Aztec's privacy protocol.
|
|
9
|
+
*/ export class Contract extends ContractBase {
|
|
10
|
+
/**
|
|
11
|
+
* Gets a contract instance.
|
|
12
|
+
* @param address - The address of the contract instance.
|
|
13
|
+
* @param artifact - Build artifact of the contract.
|
|
14
|
+
* @param wallet - The wallet to use when interacting with the contract.
|
|
15
|
+
* @returns A promise that resolves to a new Contract instance.
|
|
16
|
+
*/ static at(address, artifact, wallet) {
|
|
17
|
+
return new Contract(address, artifact, wallet);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a tx to deploy (initialize and/or publish) a new instance of a contract.
|
|
21
|
+
*
|
|
22
|
+
* @param wallet - The wallet for executing the deployment.
|
|
23
|
+
* @param artifact - Build artifact of the contract to deploy
|
|
24
|
+
* @param args - Arguments for the constructor.
|
|
25
|
+
* @param constructorName - The name of the constructor function to call.
|
|
26
|
+
* @param instantiation - Other address-affecting parameters (salt, deployer / universalDeploy, publicKeys).
|
|
27
|
+
*/ static deploy(wallet, artifact, args, constructorName, instantiation) {
|
|
28
|
+
const postDeployCtor = (instance, wallet)=>Contract.at(instance.address, artifact, wallet);
|
|
29
|
+
return DeployMethod.create(wallet, {
|
|
30
|
+
artifact,
|
|
31
|
+
postDeployCtor,
|
|
32
|
+
args,
|
|
33
|
+
constructorNameOrArtifact: constructorName
|
|
34
|
+
}, instantiation);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type ContractArtifact, type FieldLayout, FunctionSelector } from '@aztec-labs/stdlib/abi';
|
|
2
|
+
import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
3
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
4
|
+
import { ContractFunctionInteraction } from './contract_function_interaction.js';
|
|
5
|
+
/**
|
|
6
|
+
* Type representing a contract method that returns a ContractFunctionInteraction instance
|
|
7
|
+
* and has a readonly 'selector' property of type Buffer. Takes any number of arguments.
|
|
8
|
+
*/
|
|
9
|
+
export type ContractMethod = ((...args: any[]) => ContractFunctionInteraction) & {
|
|
10
|
+
/**
|
|
11
|
+
* The unique identifier for a contract function in bytecode.
|
|
12
|
+
*/
|
|
13
|
+
selector: () => Promise<FunctionSelector>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Type representing the storage layout of a contract.
|
|
17
|
+
*/
|
|
18
|
+
export type ContractStorageLayout<T extends string> = {
|
|
19
|
+
[K in T]: FieldLayout;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Abstract implementation of a contract extended by the Contract class and generated contract types.
|
|
23
|
+
*/
|
|
24
|
+
export declare class ContractBase {
|
|
25
|
+
/** The contract's address. */
|
|
26
|
+
readonly address: AztecAddress;
|
|
27
|
+
/** The Application Binary Interface for the contract. */
|
|
28
|
+
readonly artifact: ContractArtifact;
|
|
29
|
+
/** The wallet used for interacting with this contract. */
|
|
30
|
+
wallet: Wallet;
|
|
31
|
+
/**
|
|
32
|
+
* An object containing contract methods mapped to their respective names.
|
|
33
|
+
*/
|
|
34
|
+
methods: {
|
|
35
|
+
[name: string]: ContractMethod;
|
|
36
|
+
};
|
|
37
|
+
protected constructor(
|
|
38
|
+
/** The contract's address. */
|
|
39
|
+
address: AztecAddress,
|
|
40
|
+
/** The Application Binary Interface for the contract. */
|
|
41
|
+
artifact: ContractArtifact,
|
|
42
|
+
/** The wallet used for interacting with this contract. */
|
|
43
|
+
wallet: Wallet);
|
|
44
|
+
/**
|
|
45
|
+
* Creates a new instance of the contract wrapper attached to a different wallet.
|
|
46
|
+
* @param wallet - Wallet to use for sending txs.
|
|
47
|
+
* @returns A new contract instance.
|
|
48
|
+
*/
|
|
49
|
+
withWallet(wallet: Wallet): this;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3RfYmFzZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbnRyYWN0L2NvbnRyYWN0X2Jhc2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUNMLEtBQUssZ0JBQWdCLEVBQ3JCLEtBQUssV0FBVyxFQUVoQixnQkFBZ0IsRUFFakIsTUFBTSx3QkFBd0IsQ0FBQztBQUNoQyxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSxrQ0FBa0MsQ0FBQztBQUVyRSxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUNsRCxPQUF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,gBAAgB,EACrB,KAAK,WAAW,EAEhB,gBAAgB,EAEjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAErE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAEjF;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,2BAA2B,CAAC,GAAG;IAC/E;;OAEG;IACH,QAAQ,EAAE,MAAM,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC3C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,MAAM,IAAI;KACnD,CAAC,IAAI,CAAC,GAAG,WAAW;CACtB,CAAC;AAEF;;GAEG;AACH,qBAAa,YAAY;IAOrB,8BAA8B;aACd,OAAO,EAAE,YAAY;IACrC,yDAAyD;aACzC,QAAQ,EAAE,gBAAgB;IAC1C,0DAA0D;IACnD,MAAM,EAAE,MAAM;IAXvB;;OAEG;IACI,OAAO,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAAA;KAAE,CAAM;IAExD,SAAS;IACP,8BAA8B;IACd,OAAO,EAAE,YAAY;IACrC,yDAAyD;IACzC,QAAQ,EAAE,gBAAgB;IAC1C,0DAA0D;IACnD,MAAM,EAAE,MAAM,EAiBtB;IAED;;;;OAIG;IACI,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAEtC;CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { FunctionSelector, getAllFunctionAbis } from '@aztec-labs/stdlib/abi';
|
|
2
|
+
import { ContractFunctionInteraction } from './contract_function_interaction.js';
|
|
3
|
+
/**
|
|
4
|
+
* Abstract implementation of a contract extended by the Contract class and generated contract types.
|
|
5
|
+
*/ export class ContractBase {
|
|
6
|
+
address;
|
|
7
|
+
artifact;
|
|
8
|
+
wallet;
|
|
9
|
+
/**
|
|
10
|
+
* An object containing contract methods mapped to their respective names.
|
|
11
|
+
*/ methods;
|
|
12
|
+
constructor(/** The contract's address. */ address, /** The Application Binary Interface for the contract. */ artifact, /** The wallet used for interacting with this contract. */ wallet){
|
|
13
|
+
this.address = address;
|
|
14
|
+
this.artifact = artifact;
|
|
15
|
+
this.wallet = wallet;
|
|
16
|
+
this.methods = {};
|
|
17
|
+
getAllFunctionAbis(artifact).forEach((f)=>{
|
|
18
|
+
const interactionFunction = (...args)=>{
|
|
19
|
+
return new ContractFunctionInteraction(this.wallet, this.address, f, args);
|
|
20
|
+
};
|
|
21
|
+
this.methods[f.name] = Object.assign(interactionFunction, {
|
|
22
|
+
/**
|
|
23
|
+
* A getter for users to fetch the function selector.
|
|
24
|
+
* @returns Selector of the function.
|
|
25
|
+
*/ selector () {
|
|
26
|
+
return FunctionSelector.fromNameAndParameters(f.name, f.parameters);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new instance of the contract wrapper attached to a different wallet.
|
|
33
|
+
* @param wallet - Wallet to use for sending txs.
|
|
34
|
+
* @returns A new contract instance.
|
|
35
|
+
*/ withWallet(wallet) {
|
|
36
|
+
return new ContractBase(this.address, this.artifact, wallet);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type FunctionAbi, FunctionCall } from '@aztec-labs/stdlib/abi';
|
|
2
|
+
import type { AuthWitness } from '@aztec-labs/stdlib/auth-witness';
|
|
3
|
+
import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
4
|
+
import type { Capsule, HashedValues, TxProfileResult } from '@aztec-labs/stdlib/tx';
|
|
5
|
+
import { ExecutionPayload } from '@aztec-labs/stdlib/tx';
|
|
6
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
7
|
+
import { BaseContractInteraction } from './base_contract_interaction.js';
|
|
8
|
+
import { type ProfileInteractionOptions, type RequestInteractionOptions, type SimulateInteractionOptions, type SimulationResult } from './interaction_options.js';
|
|
9
|
+
/**
|
|
10
|
+
* This is the class that is returned when calling e.g. `contract.methods.myMethod(arg0, arg1)`.
|
|
11
|
+
* It contains available interactions one can call on a method, including view.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ContractFunctionInteraction extends BaseContractInteraction {
|
|
14
|
+
protected contractAddress: AztecAddress;
|
|
15
|
+
protected functionDao: FunctionAbi;
|
|
16
|
+
protected args: any[];
|
|
17
|
+
private extraHashedArgs;
|
|
18
|
+
constructor(wallet: Wallet, contractAddress: AztecAddress, functionDao: FunctionAbi, args: any[], authWitnesses?: AuthWitness[], capsules?: Capsule[], extraHashedArgs?: HashedValues[]);
|
|
19
|
+
private hasInvalidNullOrUndefinedArguments;
|
|
20
|
+
/**
|
|
21
|
+
* Returns the encoded function call wrapped by this interaction
|
|
22
|
+
* Useful when generating authwits
|
|
23
|
+
* @returns An encoded function call
|
|
24
|
+
*/
|
|
25
|
+
getFunctionCall(): Promise<FunctionCall>;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the execution payload that allows this operation to happen on chain.
|
|
28
|
+
* @param options - Configuration options.
|
|
29
|
+
* @returns The execution payload for this operation
|
|
30
|
+
*/
|
|
31
|
+
request(options?: RequestInteractionOptions): Promise<ExecutionPayload>;
|
|
32
|
+
/**
|
|
33
|
+
* Simulate a transaction and get information from its execution.
|
|
34
|
+
* Differs from prove in a few important ways:
|
|
35
|
+
* 1. It returns the values of the function execution, plus additional metadata if requested
|
|
36
|
+
* 2. It supports `utility`, `private` and `public` functions
|
|
37
|
+
*
|
|
38
|
+
* @param options - An optional object containing additional configuration for the simulation.
|
|
39
|
+
* @returns Depending on the simulation options, this method directly returns the result value of the executed
|
|
40
|
+
* function or a rich object containing extra metadata, such as estimated gas costs (if requested via options),
|
|
41
|
+
* execution statistics and emitted offchain effects
|
|
42
|
+
*/
|
|
43
|
+
simulate(options?: SimulateInteractionOptions): Promise<SimulationResult>;
|
|
44
|
+
/**
|
|
45
|
+
* Simulate a transaction and profile the gate count for each function in the transaction.
|
|
46
|
+
* @param options - Same options as `simulate`, plus profiling method
|
|
47
|
+
*
|
|
48
|
+
* @returns An object containing the function return value and profile result.
|
|
49
|
+
*/
|
|
50
|
+
profile(options: ProfileInteractionOptions): Promise<TxProfileResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Augments this ContractFunctionInteraction with additional metadata, such as authWitnesses, capsules, and extraHashedArgs.
|
|
53
|
+
* This is useful when creating a "batteries included" interaction, such as registering a contract class with its associated
|
|
54
|
+
* capsule instead of having the user provide them externally.
|
|
55
|
+
* @param options - An object containing the metadata to add to the interaction
|
|
56
|
+
* @returns A new ContractFunctionInteraction with the added metadata, but calling the same original function in the same manner
|
|
57
|
+
*/
|
|
58
|
+
with({ authWitnesses, capsules, extraHashedArgs }: {
|
|
59
|
+
/** The authWitnesses to add to the interaction */
|
|
60
|
+
authWitnesses?: AuthWitness[];
|
|
61
|
+
/** The capsules to add to the interaction */
|
|
62
|
+
capsules?: Capsule[];
|
|
63
|
+
/** The extra hashed args to add to the interaction */
|
|
64
|
+
extraHashedArgs?: HashedValues[];
|
|
65
|
+
}): ContractFunctionInteraction;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3RfZnVuY3Rpb25faW50ZXJhY3Rpb24uZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb250cmFjdC9jb250cmFjdF9mdW5jdGlvbl9pbnRlcmFjdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBR0wsS0FBSyxXQUFXLEVBQ2hCLFlBQVksRUFRYixNQUFNLHdCQUF3QixDQUFDO0FBQ2hDLE9BQU8sS0FBSy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lLElBQUksT0FBTyxDQUFDLFlBQVksQ0FBQyxDQVlwRDtJQUVEOzs7O09BSUc7SUFDbUIsT0FBTyxDQUFDLE9BQU8sR0FBRSx5QkFBOEIsR0FBRyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0FnQmhHO0lBR0Q7Ozs7Ozs7Ozs7T0FVRztJQUNVLFFBQVEsQ0FDbkIsT0FBTyxHQUFFLDBCQUE2RCxHQUNyRSxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0ErRDNCO0lBRUQ7Ozs7O09BS0c7SUFDVSxPQUFPLENBQUMsT0FBTyxFQUFFLHlCQUF5QixHQUFHLE9BQU8sQ0FBQyxlQUFlLENBQUMsQ0FPakY7SUFFRDs7Ozs7O09BTUc7SUFDSSxJQUFJLENBQUMsRUFDVixhQUFrQixFQUNsQixRQUFhLEVBQ2IsZUFBb0IsRUFDckIsRUFBRTtRQUNELGtEQUFrRDtRQUNsRCxhQUFhLENBQUMsRUFBRSxXQUFXLEVBQUUsQ0FBQztRQUM5Qiw2Q0FBNkM7UUFDN0MsUUFBUSxDQUFDLEVBQUUsT0FBTyxFQUFFLENBQUM7UUFDckIsc0RBQXNEO1FBQ3RELGVBQWUsQ0FBQyxFQUFFLFlBQVksRUFBRSxDQUFDO0tBQ2xDLEdBQUcsMkJBQTJCLENBVTlCO0NBQ0YifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract_function_interaction.d.ts","sourceRoot":"","sources":["../../src/contract/contract_function_interaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,WAAW,EAChB,YAAY,EAQb,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAA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