@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,218 @@
|
|
|
1
|
+
import { FunctionCall, FunctionSelector, FunctionType, canBeMappedFromNullOrUndefined, decodeFromAbi, encodeArguments, getFunctionReturnType, isOptionStruct } 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, toProfileOptions, toSimulateOptions } from './interaction_options.js';
|
|
5
|
+
/**
|
|
6
|
+
* This is the class that is returned when calling e.g. `contract.methods.myMethod(arg0, arg1)`.
|
|
7
|
+
* It contains available interactions one can call on a method, including view.
|
|
8
|
+
*/ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
9
|
+
contractAddress;
|
|
10
|
+
functionDao;
|
|
11
|
+
args;
|
|
12
|
+
extraHashedArgs;
|
|
13
|
+
constructor(wallet, contractAddress, functionDao, args, authWitnesses = [], capsules = [], extraHashedArgs = []){
|
|
14
|
+
super(wallet, authWitnesses, capsules), this.contractAddress = contractAddress, this.functionDao = functionDao, this.args = args, this.extraHashedArgs = extraHashedArgs;
|
|
15
|
+
// This may feel a bit ad-hoc here, so it warrants a comment. We accept Noir Option<T> parameters, and it's natural
|
|
16
|
+
// to map JS's null/undefined to Noir Option's None. One possible way to deal with null/undefined arguments at this
|
|
17
|
+
// point in the codebase is to conclude that they are accepted since at least one Noir type (ie: Option) can be
|
|
18
|
+
// encoded from them. Then we would let `encode` deal with potential mismatches. I chose not to do that because of
|
|
19
|
+
// the pervasiveness of null/undefined in JS, and how easy it is to inadvertently pass it around. Having this check
|
|
20
|
+
// here allows us to fail at a point where the boundaries and intent are clear.
|
|
21
|
+
if (this.hasInvalidNullOrUndefinedArguments(args)) {
|
|
22
|
+
const signature = formatFunctionSignature(this.functionDao.name, this.functionDao.parameters);
|
|
23
|
+
const received = args.map(formatArg).join(', ');
|
|
24
|
+
throw new Error(`Null or undefined arguments are only allowed for Option<T> parameters in ${signature}. Received: (${received}).`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
hasInvalidNullOrUndefinedArguments(args) {
|
|
28
|
+
return args.some((arg, index)=>{
|
|
29
|
+
if (arg !== undefined && arg !== null) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const parameterType = this.functionDao.parameters[index]?.type;
|
|
33
|
+
return !parameterType || !canBeMappedFromNullOrUndefined(parameterType);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns the encoded function call wrapped by this interaction
|
|
38
|
+
* Useful when generating authwits
|
|
39
|
+
* @returns An encoded function call
|
|
40
|
+
*/ async getFunctionCall() {
|
|
41
|
+
const args = encodeArguments(this.functionDao, this.args);
|
|
42
|
+
return FunctionCall.from({
|
|
43
|
+
name: this.functionDao.name,
|
|
44
|
+
to: this.contractAddress,
|
|
45
|
+
selector: await FunctionSelector.fromNameAndParameters(this.functionDao.name, this.functionDao.parameters),
|
|
46
|
+
type: this.functionDao.functionType,
|
|
47
|
+
hideMsgSender: false,
|
|
48
|
+
isStatic: this.functionDao.isStatic,
|
|
49
|
+
args,
|
|
50
|
+
returnType: getFunctionReturnType(this.functionDao)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns the execution payload that allows this operation to happen on chain.
|
|
55
|
+
* @param options - Configuration options.
|
|
56
|
+
* @returns The execution payload for this operation
|
|
57
|
+
*/ async request(options = {}) {
|
|
58
|
+
const calls = [
|
|
59
|
+
await this.getFunctionCall()
|
|
60
|
+
];
|
|
61
|
+
const { authWitnesses, capsules } = options;
|
|
62
|
+
const feeExecutionPayload = options.fee?.paymentMethod ? await options.fee.paymentMethod.getExecutionPayload() : undefined;
|
|
63
|
+
const functionExecutionPayload = new ExecutionPayload(calls, this.authWitnesses.concat(authWitnesses ?? []), this.capsules.concat(capsules ?? []), this.extraHashedArgs);
|
|
64
|
+
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
65
|
+
feeExecutionPayload,
|
|
66
|
+
functionExecutionPayload
|
|
67
|
+
]) : functionExecutionPayload;
|
|
68
|
+
return finalExecutionPayload;
|
|
69
|
+
}
|
|
70
|
+
// docs:start:simulate
|
|
71
|
+
/**
|
|
72
|
+
* Simulate a transaction and get information from its execution.
|
|
73
|
+
* Differs from prove in a few important ways:
|
|
74
|
+
* 1. It returns the values of the function execution, plus additional metadata if requested
|
|
75
|
+
* 2. It supports `utility`, `private` and `public` functions
|
|
76
|
+
*
|
|
77
|
+
* @param options - An optional object containing additional configuration for the simulation.
|
|
78
|
+
* @returns Depending on the simulation options, this method directly returns the result value of the executed
|
|
79
|
+
* function or a rich object containing extra metadata, such as estimated gas costs (if requested via options),
|
|
80
|
+
* execution statistics and emitted offchain effects
|
|
81
|
+
*/ async simulate(options = {}) {
|
|
82
|
+
// docs:end:simulate
|
|
83
|
+
if (this.functionDao.functionType == FunctionType.UTILITY) {
|
|
84
|
+
if (options.overrides?.publicStorage?.length || options.overrides?.contracts) {
|
|
85
|
+
throw new Error('overrides are not supported for utility function simulation.');
|
|
86
|
+
}
|
|
87
|
+
const call = await this.getFunctionCall();
|
|
88
|
+
const scopes = [
|
|
89
|
+
...options.additionalScopes ?? []
|
|
90
|
+
];
|
|
91
|
+
const utilityResult = await this.wallet.executeUtility(call, {
|
|
92
|
+
scopes: options.from === NO_FROM ? scopes : [
|
|
93
|
+
options.from,
|
|
94
|
+
...scopes
|
|
95
|
+
],
|
|
96
|
+
authWitnesses: options.authWitnesses
|
|
97
|
+
});
|
|
98
|
+
// Decode the raw field elements to the actual return type
|
|
99
|
+
const returnValue = utilityResult.result ? decodeFromAbi(getFunctionReturnType(this.functionDao), utilityResult.result) : undefined;
|
|
100
|
+
const offchainOutput = extractOffchainOutput(utilityResult.offchainEffects, utilityResult.anchorBlockTimestamp);
|
|
101
|
+
if (options.includeMetadata) {
|
|
102
|
+
return {
|
|
103
|
+
stats: utilityResult.stats,
|
|
104
|
+
...offchainOutput,
|
|
105
|
+
result: returnValue
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
result: returnValue,
|
|
110
|
+
...offchainOutput
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const executionPayload = await this.request(options);
|
|
114
|
+
const simulatedTx = await this.wallet.simulateTx(executionPayload, toSimulateOptions(options));
|
|
115
|
+
let rawReturnValues;
|
|
116
|
+
if (this.functionDao.functionType == FunctionType.PRIVATE) {
|
|
117
|
+
// request() prepends the fee payment method's calls (if any) before this interaction's single call, so the app
|
|
118
|
+
// call is the last call of its type in the payload. Its position among the private return values is the number
|
|
119
|
+
// of private calls that precede it.
|
|
120
|
+
const appCallIndex = executionPayload.calls.filter((c)=>c.type === FunctionType.PRIVATE).length - 1;
|
|
121
|
+
rawReturnValues = simulatedTx.getPrivateReturnValuesOfAppCall(appCallIndex)?.values;
|
|
122
|
+
} else {
|
|
123
|
+
// For public functions we retrieve the values directly from the public output, offset by any public fee calls
|
|
124
|
+
// that request() prepended ahead of the app call.
|
|
125
|
+
const appCallIndex = executionPayload.calls.filter((c)=>c.type === FunctionType.PUBLIC).length - 1;
|
|
126
|
+
rawReturnValues = simulatedTx.getPublicReturnValues()?.[appCallIndex]?.values;
|
|
127
|
+
}
|
|
128
|
+
const returnValue = rawReturnValues ? decodeFromAbi(getFunctionReturnType(this.functionDao), rawReturnValues) : undefined;
|
|
129
|
+
const offchainOutput = extractOffchainOutput(simulatedTx.offchainEffects, simulatedTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp);
|
|
130
|
+
if (options.includeMetadata) {
|
|
131
|
+
return {
|
|
132
|
+
stats: simulatedTx.stats,
|
|
133
|
+
...offchainOutput,
|
|
134
|
+
result: returnValue,
|
|
135
|
+
gasUsed: simulatedTx.gasUsed
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
result: returnValue,
|
|
140
|
+
...offchainOutput
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Simulate a transaction and profile the gate count for each function in the transaction.
|
|
145
|
+
* @param options - Same options as `simulate`, plus profiling method
|
|
146
|
+
*
|
|
147
|
+
* @returns An object containing the function return value and profile result.
|
|
148
|
+
*/ async profile(options) {
|
|
149
|
+
if (this.functionDao.functionType == FunctionType.UTILITY) {
|
|
150
|
+
throw new Error("Can't profile a utility function.");
|
|
151
|
+
}
|
|
152
|
+
const executionPayload = await this.request(options);
|
|
153
|
+
return await this.wallet.profileTx(executionPayload, toProfileOptions(options));
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Augments this ContractFunctionInteraction with additional metadata, such as authWitnesses, capsules, and extraHashedArgs.
|
|
157
|
+
* This is useful when creating a "batteries included" interaction, such as registering a contract class with its associated
|
|
158
|
+
* capsule instead of having the user provide them externally.
|
|
159
|
+
* @param options - An object containing the metadata to add to the interaction
|
|
160
|
+
* @returns A new ContractFunctionInteraction with the added metadata, but calling the same original function in the same manner
|
|
161
|
+
*/ with({ authWitnesses = [], capsules = [], extraHashedArgs = [] }) {
|
|
162
|
+
return new ContractFunctionInteraction(this.wallet, this.contractAddress, this.functionDao, this.args, this.authWitnesses.concat(authWitnesses), this.capsules.concat(capsules), this.extraHashedArgs.concat(extraHashedArgs));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Render an AbiType as a human readable string
|
|
167
|
+
* */ function formatAbiType(abiType) {
|
|
168
|
+
switch(abiType.kind){
|
|
169
|
+
case 'field':
|
|
170
|
+
return 'Field';
|
|
171
|
+
case 'boolean':
|
|
172
|
+
return 'bool';
|
|
173
|
+
case 'integer':
|
|
174
|
+
return `${abiType.sign === 'signed' ? 'i' : 'u'}${abiType.width}`;
|
|
175
|
+
case 'string':
|
|
176
|
+
return `str<${abiType.length}>`;
|
|
177
|
+
case 'array':
|
|
178
|
+
return `[${formatAbiType(abiType.type)}; ${abiType.length}]`;
|
|
179
|
+
case 'struct':
|
|
180
|
+
{
|
|
181
|
+
if (isOptionStruct(abiType)) {
|
|
182
|
+
const innerType = abiType.fields.find((f)=>f.name === '_value').type;
|
|
183
|
+
return `Option<${formatAbiType(innerType)}>`;
|
|
184
|
+
}
|
|
185
|
+
return `(${abiType.fields.map((f)=>`${f.name}: ${formatAbiType(f.type)}`).join(', ')})`;
|
|
186
|
+
}
|
|
187
|
+
case 'tuple':
|
|
188
|
+
return `(${abiType.fields.map(formatAbiType).join(', ')})`;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Pretty print a function signature
|
|
193
|
+
*/ function formatFunctionSignature(name, parameters) {
|
|
194
|
+
const params = parameters.map((p)=>`${p.name}: ${formatAbiType(p.type)}`).join(', ');
|
|
195
|
+
return `${name}(${params})`;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Non-exhaustive pretty print of JS args to display in error messages in this module
|
|
199
|
+
*/ function formatArg(arg) {
|
|
200
|
+
if (arg === undefined) {
|
|
201
|
+
return 'undefined';
|
|
202
|
+
}
|
|
203
|
+
if (arg === null) {
|
|
204
|
+
return 'null';
|
|
205
|
+
}
|
|
206
|
+
if (typeof arg === 'bigint') {
|
|
207
|
+
return `${arg}n`;
|
|
208
|
+
}
|
|
209
|
+
if (Array.isArray(arg)) {
|
|
210
|
+
return `[${arg.map(formatArg).join(', ')}]`;
|
|
211
|
+
}
|
|
212
|
+
if (typeof arg === 'object') {
|
|
213
|
+
const entries = Object.entries(arg).map(([k, v])=>`${k}: ${formatArg(v)}`);
|
|
214
|
+
return `{ ${entries.join(', ')} }`;
|
|
215
|
+
}
|
|
216
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
217
|
+
return String(arg);
|
|
218
|
+
}
|