@aztec/aztec.js 0.0.0-test.0 → 0.0.1-commit.24de95ac
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 +1 -1
- package/dest/account/account.d.ts +60 -0
- package/dest/account/account.d.ts.map +1 -0
- package/dest/account/account.js +59 -0
- package/dest/account/{contract.d.ts → account_contract.d.ts} +16 -10
- package/dest/account/account_contract.d.ts.map +1 -0
- package/dest/account/{contract.js → account_contract.js} +7 -4
- package/dest/{wallet/account_wallet_with_private_key.d.ts → account/account_with_secret_key.d.ts} +7 -8
- package/dest/account/account_with_secret_key.d.ts.map +1 -0
- package/dest/{wallet/account_wallet_with_private_key.js → account/account_with_secret_key.js} +5 -5
- package/dest/account/index.d.ts +3 -7
- package/dest/account/index.d.ts.map +1 -1
- package/dest/account/index.js +2 -6
- package/dest/account/interface.d.ts +1 -13
- package/dest/account/interface.d.ts.map +1 -1
- package/dest/account/interface.js +1 -0
- package/dest/account/signerless_account.d.ts +24 -0
- package/dest/account/signerless_account.d.ts.map +1 -0
- package/dest/account/signerless_account.js +27 -0
- package/dest/api/abi.d.ts +2 -1
- package/dest/api/abi.d.ts.map +1 -1
- package/dest/api/abi.js +1 -1
- package/dest/api/account.d.ts +5 -2
- package/dest/api/account.d.ts.map +1 -1
- package/dest/api/account.js +3 -1
- package/dest/api/addresses.d.ts +1 -0
- package/dest/api/addresses.d.ts.map +1 -1
- package/dest/api/addresses.js +1 -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/{contract/index.d.ts → api/contract.d.ts} +15 -11
- package/dest/api/contract.d.ts.map +1 -0
- package/dest/{contract/index.js → api/contract.js} +14 -10
- 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 -3
- package/dest/api/deployment.d.ts.map +1 -1
- package/dest/api/deployment.js +4 -3
- 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/events.d.ts +12 -0
- package/dest/api/events.d.ts.map +1 -0
- package/dest/api/events.js +30 -0
- package/dest/api/fee.d.ts +1 -1
- package/dest/api/fee.d.ts.map +1 -1
- package/dest/api/fee.js +1 -1
- 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/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 +1 -0
- package/dest/api/log.d.ts.map +1 -1
- package/dest/api/log.js +1 -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 +21 -0
- package/dest/api/node.d.ts.map +1 -0
- package/dest/api/node.js +18 -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 +3 -0
- package/dest/api/protocol.d.ts.map +1 -0
- package/dest/api/protocol.js +2 -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 +2 -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 +4 -1
- package/dest/api/wallet.d.ts.map +1 -1
- package/dest/api/wallet.js +4 -1
- package/dest/authorization/call_authorization_request.d.ts +67 -0
- package/dest/authorization/call_authorization_request.d.ts.map +1 -0
- package/dest/authorization/call_authorization_request.js +49 -0
- package/dest/contract/base_contract_interaction.d.ts +16 -79
- package/dest/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.js +15 -128
- package/dest/contract/batch_call.d.ts +13 -14
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +60 -60
- package/dest/contract/checker.d.ts +1 -1
- package/dest/contract/checker.d.ts.map +1 -1
- package/dest/contract/checker.js +2 -2
- package/dest/contract/contract.d.ts +7 -6
- package/dest/contract/contract.d.ts.map +1 -1
- package/dest/contract/contract.js +7 -16
- package/dest/contract/contract_base.d.ts +3 -9
- package/dest/contract/contract_base.d.ts.map +1 -1
- package/dest/contract/contract_base.js +2 -2
- package/dest/contract/contract_function_interaction.d.ts +52 -44
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +75 -74
- package/dest/contract/deploy_method.d.ts +102 -57
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +122 -132
- package/dest/contract/deploy_sent_tx.d.ts +3 -5
- package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
- package/dest/contract/deploy_sent_tx.js +10 -13
- package/dest/contract/get_gas_limits.d.ts +5 -6
- package/dest/contract/get_gas_limits.d.ts.map +1 -1
- package/dest/contract/get_gas_limits.js +9 -3
- package/dest/contract/interaction_options.d.ts +114 -0
- package/dest/contract/interaction_options.d.ts.map +1 -0
- package/dest/contract/interaction_options.js +52 -0
- package/dest/contract/protocol_contracts.d.ts +6 -6
- package/dest/contract/protocol_contracts.d.ts.map +1 -1
- package/dest/contract/protocol_contracts.js +7 -7
- package/dest/contract/sent_tx.d.ts +8 -18
- package/dest/contract/sent_tx.d.ts.map +1 -1
- package/dest/contract/sent_tx.js +30 -42
- package/dest/contract/unsafe_contract.d.ts +1 -1
- package/dest/contract/unsafe_contract.d.ts.map +1 -1
- package/dest/contract/wait_for_proven.d.ts +17 -0
- package/dest/contract/wait_for_proven.d.ts.map +1 -0
- package/dest/contract/wait_for_proven.js +17 -0
- package/dest/deployment/broadcast_function.d.ts +3 -3
- package/dest/deployment/broadcast_function.d.ts.map +1 -1
- package/dest/deployment/broadcast_function.js +27 -23
- package/dest/deployment/contract_deployer.d.ts +1 -1
- package/dest/deployment/contract_deployer.d.ts.map +1 -1
- 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/{api/ethereum → ethereum}/portal_manager.d.ts +29 -25
- package/dest/ethereum/portal_manager.d.ts.map +1 -0
- package/dest/{api/ethereum → ethereum}/portal_manager.js +106 -73
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts +16 -11
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -1
- package/dest/fee/fee_juice_payment_method_with_claim.js +26 -16
- package/dest/fee/fee_payment_method.d.ts +11 -7
- package/dest/fee/fee_payment_method.d.ts.map +1 -1
- package/dest/fee/private_fee_payment_method.d.ts +25 -8
- package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/private_fee_payment_method.js +43 -21
- package/dest/fee/public_fee_payment_method.d.ts +26 -9
- package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/public_fee_payment_method.js +45 -23
- 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 +34 -0
- package/dest/utils/abi_types.d.ts +0 -2
- package/dest/utils/abi_types.d.ts.map +1 -1
- package/dest/utils/authwit.d.ts +81 -24
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +226 -40
- package/dest/utils/cross_chain.d.ts +24 -0
- package/dest/utils/cross_chain.d.ts.map +1 -0
- package/dest/utils/cross_chain.js +30 -0
- package/dest/utils/fee_juice.d.ts +3 -2
- package/dest/utils/fee_juice.d.ts.map +1 -1
- package/dest/utils/fee_juice.js +3 -2
- package/dest/utils/field_compressed_string.d.ts.map +1 -1
- package/dest/utils/node.d.ts.map +1 -1
- package/dest/utils/node.js +1 -1
- package/dest/utils/pub_key.d.ts.map +1 -1
- package/dest/utils/pub_key.js +1 -2
- package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +34 -0
- package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -0
- package/dest/wallet/account_entrypoint_meta_payment_method.js +76 -0
- package/dest/wallet/account_manager.d.ts +69 -0
- package/dest/wallet/account_manager.d.ts.map +1 -0
- package/dest/wallet/account_manager.js +113 -0
- package/dest/wallet/base_wallet.d.ts +81 -63
- package/dest/wallet/base_wallet.d.ts.map +1 -1
- package/dest/wallet/base_wallet.js +221 -106
- package/dest/wallet/deploy_account_method.d.ts +52 -0
- package/dest/wallet/deploy_account_method.d.ts.map +1 -0
- package/dest/wallet/deploy_account_method.js +77 -0
- package/dest/wallet/index.d.ts +3 -16
- package/dest/wallet/index.d.ts.map +1 -1
- package/dest/wallet/index.js +3 -20
- package/dest/wallet/wallet.d.ts +2478 -0
- package/dest/wallet/wallet.d.ts.map +1 -0
- package/dest/wallet/wallet.js +202 -0
- package/package.json +40 -32
- package/src/account/account.ts +97 -0
- package/src/account/{contract.ts → account_contract.ts} +24 -13
- package/src/{wallet/account_wallet_with_private_key.ts → account/account_with_secret_key.ts} +6 -8
- package/src/account/index.ts +3 -7
- package/src/account/interface.ts +1 -12
- package/src/account/signerless_account.ts +46 -0
- package/src/api/abi.ts +26 -0
- package/src/api/account.ts +5 -9
- package/src/api/addresses.ts +1 -0
- package/src/api/authorization.ts +14 -0
- package/src/api/block.ts +2 -0
- package/src/{contract/index.ts → api/contract.ts} +37 -13
- package/src/api/crypto.ts +1 -0
- package/src/api/deployment.ts +4 -3
- package/src/api/ethereum.ts +10 -0
- package/src/api/events.ts +44 -0
- package/src/api/fee.ts +1 -1
- package/src/api/fee_testing.ts +1 -0
- package/src/api/keys.ts +8 -0
- package/src/api/log.ts +1 -0
- package/src/api/messaging.ts +2 -0
- package/src/api/node.ts +20 -0
- package/src/api/note.ts +1 -0
- package/src/api/protocol.ts +2 -0
- package/src/api/trees.ts +2 -0
- package/src/api/tx.ts +11 -0
- package/src/api/utils.ts +14 -0
- package/src/api/wallet.ts +33 -5
- package/src/authorization/call_authorization_request.ts +63 -0
- package/src/contract/base_contract_interaction.ts +24 -166
- package/src/contract/batch_call.ts +81 -49
- package/src/contract/checker.ts +8 -3
- package/src/contract/contract.ts +8 -17
- package/src/contract/contract_base.ts +4 -11
- package/src/contract/contract_function_interaction.ts +136 -106
- package/src/contract/deploy_method.ts +199 -129
- package/src/contract/deploy_sent_tx.ts +9 -15
- package/src/contract/get_gas_limits.ts +15 -8
- package/src/contract/interaction_options.ts +169 -0
- package/src/contract/protocol_contracts.ts +10 -10
- package/src/contract/sent_tx.ts +40 -51
- package/src/contract/unsafe_contract.ts +1 -1
- package/src/contract/wait_for_proven.ts +38 -0
- package/src/deployment/broadcast_function.ts +57 -57
- package/src/deployment/contract_deployer.ts +1 -1
- package/src/deployment/publish_class.ts +34 -0
- package/src/deployment/publish_instance.ts +26 -0
- package/src/{api/ethereum → ethereum}/portal_manager.ts +120 -74
- package/src/fee/fee_juice_payment_method_with_claim.ts +46 -33
- package/src/fee/fee_payment_method.ts +11 -7
- package/src/fee/private_fee_payment_method.ts +77 -57
- package/src/fee/public_fee_payment_method.ts +91 -67
- package/src/fee/sponsored_fee_payment.ts +44 -0
- package/src/utils/authwit.ts +255 -53
- package/src/utils/cross_chain.ts +53 -0
- package/src/utils/fee_juice.ts +4 -4
- package/src/utils/node.ts +1 -1
- package/src/utils/pub_key.ts +1 -2
- package/src/wallet/account_entrypoint_meta_payment_method.ts +105 -0
- package/src/wallet/account_manager.ts +154 -0
- package/src/wallet/base_wallet.ts +295 -143
- package/src/wallet/deploy_account_method.ts +125 -0
- package/src/wallet/index.ts +3 -33
- package/src/wallet/wallet.ts +362 -0
- package/dest/account/contract.d.ts.map +0 -1
- package/dest/account/wallet.d.ts +0 -11
- package/dest/account/wallet.d.ts.map +0 -1
- package/dest/account/wallet.js +0 -3
- package/dest/account_manager/deploy_account_method.d.ts +0 -15
- package/dest/account_manager/deploy_account_method.d.ts.map +0 -1
- package/dest/account_manager/deploy_account_method.js +0 -43
- package/dest/account_manager/deploy_account_sent_tx.d.ts +0 -30
- package/dest/account_manager/deploy_account_sent_tx.d.ts.map +0 -1
- package/dest/account_manager/deploy_account_sent_tx.js +0 -29
- package/dest/account_manager/index.d.ts +0 -108
- package/dest/account_manager/index.d.ts.map +0 -1
- package/dest/account_manager/index.js +0 -159
- package/dest/api/cheat_codes.d.ts +0 -26
- package/dest/api/cheat_codes.d.ts.map +0 -1
- package/dest/api/cheat_codes.js +0 -25
- package/dest/api/entrypoint.d.ts +0 -2
- package/dest/api/entrypoint.d.ts.map +0 -1
- package/dest/api/entrypoint.js +0 -1
- package/dest/api/ethereum/anvil_test_watcher.d.ts +0 -32
- package/dest/api/ethereum/anvil_test_watcher.d.ts.map +0 -1
- package/dest/api/ethereum/anvil_test_watcher.js +0 -133
- package/dest/api/ethereum/chain_monitor.d.ts +0 -25
- package/dest/api/ethereum/chain_monitor.d.ts.map +0 -1
- package/dest/api/ethereum/chain_monitor.js +0 -74
- package/dest/api/ethereum/cheat_codes.d.ts +0 -63
- package/dest/api/ethereum/cheat_codes.d.ts.map +0 -1
- package/dest/api/ethereum/cheat_codes.js +0 -162
- package/dest/api/ethereum/index.d.ts +0 -7
- package/dest/api/ethereum/index.d.ts.map +0 -1
- package/dest/api/ethereum/index.js +0 -6
- package/dest/api/ethereum/l1_contracts.d.ts +0 -3
- package/dest/api/ethereum/l1_contracts.d.ts.map +0 -1
- package/dest/api/ethereum/l1_contracts.js +0 -13
- package/dest/api/ethereum/portal_manager.d.ts.map +0 -1
- package/dest/api/interfaces/pxe.d.ts +0 -2
- package/dest/api/interfaces/pxe.d.ts.map +0 -1
- package/dest/api/interfaces/pxe.js +0 -1
- package/dest/api/log_id.d.ts +0 -2
- package/dest/api/log_id.d.ts.map +0 -1
- package/dest/api/log_id.js +0 -1
- package/dest/api/tx_hash.d.ts +0 -2
- package/dest/api/tx_hash.d.ts.map +0 -1
- package/dest/api/tx_hash.js +0 -1
- package/dest/contract/deploy_proven_tx.d.ts +0 -21
- package/dest/contract/deploy_proven_tx.d.ts.map +0 -1
- package/dest/contract/deploy_proven_tx.js +0 -19
- package/dest/contract/index.d.ts.map +0 -1
- package/dest/contract/proven_tx.d.ts +0 -17
- package/dest/contract/proven_tx.d.ts.map +0 -1
- package/dest/contract/proven_tx.js +0 -22
- package/dest/deployment/deploy_instance.d.ts +0 -10
- package/dest/deployment/deploy_instance.d.ts.map +0 -1
- package/dest/deployment/deploy_instance.js +0 -14
- package/dest/deployment/index.d.ts +0 -2
- package/dest/deployment/index.d.ts.map +0 -1
- package/dest/deployment/index.js +0 -1
- package/dest/deployment/register_class.d.ts +0 -6
- package/dest/deployment/register_class.d.ts.map +0 -1
- package/dest/deployment/register_class.js +0 -22
- package/dest/entrypoint/default_entrypoint.d.ts +0 -12
- package/dest/entrypoint/default_entrypoint.d.ts.map +0 -1
- package/dest/entrypoint/default_entrypoint.js +0 -28
- package/dest/entrypoint/default_multi_call_entrypoint.d.ts +0 -15
- package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +0 -1
- package/dest/entrypoint/default_multi_call_entrypoint.js +0 -130
- package/dest/entrypoint/entrypoint.d.ts +0 -35
- package/dest/entrypoint/entrypoint.d.ts.map +0 -1
- package/dest/entrypoint/entrypoint.js +0 -4
- package/dest/entrypoint/payload.d.ts +0 -128
- package/dest/entrypoint/payload.d.ts.map +0 -1
- package/dest/entrypoint/payload.js +0 -143
- package/dest/fee/fee_juice_payment_method.d.ts +0 -14
- package/dest/fee/fee_juice_payment_method.d.ts.map +0 -1
- package/dest/fee/fee_juice_payment_method.js +0 -20
- package/dest/index.d.ts +0 -66
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -69
- package/dest/rpc_clients/index.d.ts +0 -3
- package/dest/rpc_clients/index.d.ts.map +0 -1
- package/dest/rpc_clients/index.js +0 -2
- package/dest/rpc_clients/node/index.d.ts +0 -12
- package/dest/rpc_clients/node/index.d.ts.map +0 -1
- package/dest/rpc_clients/node/index.js +0 -78
- package/dest/rpc_clients/pxe_client.d.ts +0 -10
- package/dest/rpc_clients/pxe_client.d.ts.map +0 -1
- package/dest/rpc_clients/pxe_client.js +0 -23
- package/dest/utils/aztec_cheatcodes.d.ts +0 -59
- package/dest/utils/aztec_cheatcodes.d.ts.map +0 -1
- package/dest/utils/aztec_cheatcodes.js +0 -62
- package/dest/utils/index.d.ts +0 -8
- package/dest/utils/index.d.ts.map +0 -1
- package/dest/utils/index.js +0 -6
- package/dest/utils/pxe.d.ts +0 -4
- package/dest/utils/pxe.d.ts.map +0 -1
- package/dest/utils/pxe.js +0 -14
- package/dest/wallet/account_wallet.d.ts +0 -76
- package/dest/wallet/account_wallet.d.ts.map +0 -1
- package/dest/wallet/account_wallet.js +0 -231
- package/dest/wallet/account_wallet_with_private_key.d.ts.map +0 -1
- package/dest/wallet/signerless_wallet.d.ts +0 -25
- package/dest/wallet/signerless_wallet.d.ts.map +0 -1
- package/dest/wallet/signerless_wallet.js +0 -36
- package/src/account/wallet.ts +0 -13
- package/src/account_manager/deploy_account_method.ts +0 -86
- package/src/account_manager/deploy_account_sent_tx.ts +0 -42
- package/src/account_manager/index.ts +0 -229
- package/src/api/cheat_codes.ts +0 -35
- package/src/api/entrypoint.ts +0 -1
- package/src/api/ethereum/anvil_test_watcher.ts +0 -158
- package/src/api/ethereum/chain_monitor.ts +0 -88
- package/src/api/ethereum/cheat_codes.ts +0 -184
- package/src/api/ethereum/index.ts +0 -19
- package/src/api/ethereum/l1_contracts.ts +0 -21
- package/src/api/interfaces/pxe.ts +0 -1
- package/src/api/log_id.ts +0 -1
- package/src/api/tx_hash.ts +0 -1
- package/src/contract/deploy_proven_tx.ts +0 -34
- package/src/contract/proven_tx.ts +0 -42
- package/src/deployment/deploy_instance.ts +0 -31
- package/src/deployment/index.ts +0 -1
- package/src/deployment/register_class.ts +0 -44
- package/src/entrypoint/default_entrypoint.ts +0 -39
- package/src/entrypoint/default_multi_call_entrypoint.ts +0 -93
- package/src/entrypoint/entrypoint.ts +0 -39
- package/src/entrypoint/payload.ts +0 -238
- package/src/fee/fee_juice_payment_method.ts +0 -26
- package/src/index.ts +0 -106
- package/src/rpc_clients/index.ts +0 -2
- package/src/rpc_clients/node/index.ts +0 -77
- package/src/rpc_clients/pxe_client.ts +0 -25
- package/src/utils/aztec_cheatcodes.ts +0 -77
- package/src/utils/index.ts +0 -21
- package/src/utils/pxe.ts +0 -17
- package/src/wallet/account_wallet.ts +0 -242
- package/src/wallet/signerless_wallet.ts +0 -52
|
@@ -1,95 +1,127 @@
|
|
|
1
|
+
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/entrypoints/payload';
|
|
1
2
|
import { type FunctionCall, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
|
|
2
|
-
import type { TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
3
3
|
|
|
4
|
-
import type { Wallet } from '../
|
|
5
|
-
import { BaseContractInteraction
|
|
6
|
-
import
|
|
4
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
5
|
+
import { BaseContractInteraction } from './base_contract_interaction.js';
|
|
6
|
+
import {
|
|
7
|
+
type RequestInteractionOptions,
|
|
8
|
+
type SimulateInteractionOptions,
|
|
9
|
+
toSimulateOptions,
|
|
10
|
+
} from './interaction_options.js';
|
|
7
11
|
|
|
8
12
|
/** A batch of function calls to be sent as a single transaction through a wallet. */
|
|
9
13
|
export class BatchCall extends BaseContractInteraction {
|
|
10
|
-
constructor(
|
|
14
|
+
constructor(
|
|
15
|
+
wallet: Wallet,
|
|
16
|
+
protected interactions: (BaseContractInteraction | ExecutionPayload)[],
|
|
17
|
+
) {
|
|
11
18
|
super(wallet);
|
|
12
19
|
}
|
|
13
20
|
|
|
14
21
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @
|
|
18
|
-
* @returns A Promise that resolves to a transaction instance.
|
|
22
|
+
* Returns an execution request that represents this operation.
|
|
23
|
+
* @param options - An optional object containing additional configuration for the request generation.
|
|
24
|
+
* @returns An execution payload wrapped in promise.
|
|
19
25
|
*/
|
|
20
|
-
public async
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
public async request(options: RequestInteractionOptions = {}): Promise<ExecutionPayload> {
|
|
27
|
+
const requests = await this.getExecutionPayloads();
|
|
28
|
+
const feeExecutionPayload = options.fee?.paymentMethod
|
|
29
|
+
? await options.fee.paymentMethod.getExecutionPayload()
|
|
30
|
+
: undefined;
|
|
31
|
+
const finalExecutionPayload = feeExecutionPayload
|
|
32
|
+
? mergeExecutionPayloads([feeExecutionPayload, ...requests])
|
|
33
|
+
: mergeExecutionPayloads([...requests]);
|
|
34
|
+
return finalExecutionPayload;
|
|
25
35
|
}
|
|
26
36
|
|
|
27
37
|
/**
|
|
28
38
|
* Simulate a transaction and get its return values
|
|
29
39
|
* Differs from prove in a few important ways:
|
|
30
40
|
* 1. It returns the values of the function execution
|
|
31
|
-
* 2. It supports `
|
|
41
|
+
* 2. It supports `utility`, `private` and `public` functions
|
|
32
42
|
*
|
|
33
43
|
* @param options - An optional object containing additional configuration for the transaction.
|
|
34
44
|
* @returns The result of the transaction as returned by the contract function.
|
|
35
45
|
*/
|
|
36
|
-
public async simulate(options:
|
|
37
|
-
const {
|
|
46
|
+
public async simulate(options: SimulateInteractionOptions): Promise<any> {
|
|
47
|
+
const { indexedExecutionPayloads, utility } = (await this.getExecutionPayloads()).reduce<{
|
|
38
48
|
/** Keep track of the number of private calls to retrieve the return values */
|
|
39
49
|
privateIndex: 0;
|
|
40
50
|
/** Keep track of the number of public calls to retrieve the return values */
|
|
41
51
|
publicIndex: 0;
|
|
42
|
-
/** The public and private function
|
|
43
|
-
|
|
44
|
-
/** The
|
|
45
|
-
|
|
52
|
+
/** The public and private function execution requests in the batch */
|
|
53
|
+
indexedExecutionPayloads: [ExecutionPayload, number, number][];
|
|
54
|
+
/** The utility function calls in the batch. */
|
|
55
|
+
utility: [FunctionCall, number][];
|
|
46
56
|
}>(
|
|
47
57
|
(acc, current, index) => {
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
const call = current.calls[0];
|
|
59
|
+
if (call.type === FunctionType.UTILITY) {
|
|
60
|
+
acc.utility.push([call, index]);
|
|
50
61
|
} else {
|
|
51
|
-
acc.
|
|
62
|
+
acc.indexedExecutionPayloads.push([
|
|
52
63
|
current,
|
|
53
64
|
index,
|
|
54
|
-
|
|
65
|
+
call.type === FunctionType.PRIVATE ? acc.privateIndex++ : acc.publicIndex++,
|
|
55
66
|
]);
|
|
56
67
|
}
|
|
57
68
|
return acc;
|
|
58
69
|
},
|
|
59
|
-
{
|
|
70
|
+
{ indexedExecutionPayloads: [], utility: [], publicIndex: 0, privateIndex: 0 },
|
|
60
71
|
);
|
|
61
72
|
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
[await this.wallet.simulateUnconstrained(call.name, call.args, call.to, options?.from), index] as const,
|
|
73
|
+
const payloads = indexedExecutionPayloads.map(([request]) => request);
|
|
74
|
+
const combinedPayload = mergeExecutionPayloads(payloads);
|
|
75
|
+
const executionPayload = new ExecutionPayload(
|
|
76
|
+
combinedPayload.calls,
|
|
77
|
+
combinedPayload.authWitnesses.concat(options.authWitnesses ?? []),
|
|
78
|
+
combinedPayload.capsules.concat(options.capsules ?? []),
|
|
79
|
+
combinedPayload.extraHashedArgs,
|
|
70
80
|
);
|
|
71
81
|
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
const utilityBatchPromise =
|
|
83
|
+
utility.length > 0
|
|
84
|
+
? this.wallet.batch(
|
|
85
|
+
utility.map(([call]) => ({
|
|
86
|
+
name: 'simulateUtility' as const,
|
|
87
|
+
args: [call.name, call.args, call.to, options?.authWitnesses] as const,
|
|
88
|
+
})),
|
|
89
|
+
)
|
|
90
|
+
: Promise.resolve([]);
|
|
91
|
+
|
|
92
|
+
const [utilityBatchResults, simulatedTx] = await Promise.all([
|
|
93
|
+
utilityBatchPromise,
|
|
94
|
+
indexedExecutionPayloads.length > 0
|
|
95
|
+
? this.wallet.simulateTx(executionPayload, await toSimulateOptions(options))
|
|
96
|
+
: Promise.resolve(),
|
|
75
97
|
]);
|
|
76
98
|
|
|
77
99
|
const results: any[] = [];
|
|
78
100
|
|
|
79
|
-
|
|
80
|
-
|
|
101
|
+
utilityBatchResults.forEach((wrappedResult, utilityIndex) => {
|
|
102
|
+
const [, originalIndex] = utility[utilityIndex];
|
|
103
|
+
results[originalIndex] = wrappedResult.result.result;
|
|
81
104
|
});
|
|
82
|
-
indexedCalls.forEach(([call, callIndex, resultIndex]) => {
|
|
83
|
-
// As account entrypoints are private, for private functions we retrieve the return values from the first nested call
|
|
84
|
-
// since we're interested in the first set of values AFTER the account entrypoint
|
|
85
|
-
// For public functions we retrieve the first values directly from the public output.
|
|
86
|
-
const rawReturnValues =
|
|
87
|
-
call.type == FunctionType.PRIVATE
|
|
88
|
-
? simulatedTx.getPrivateReturnValues()?.nested?.[resultIndex].values
|
|
89
|
-
: simulatedTx.getPublicReturnValues()?.[resultIndex].values;
|
|
90
105
|
|
|
91
|
-
|
|
92
|
-
|
|
106
|
+
if (simulatedTx) {
|
|
107
|
+
indexedExecutionPayloads.forEach(([request, callIndex, resultIndex]) => {
|
|
108
|
+
const call = request.calls[0];
|
|
109
|
+
// As account entrypoints are private, for private functions we retrieve the return values from the first nested call
|
|
110
|
+
// since we're interested in the first set of values AFTER the account entrypoint
|
|
111
|
+
// For public functions we retrieve the first values directly from the public output.
|
|
112
|
+
const rawReturnValues =
|
|
113
|
+
call.type == FunctionType.PRIVATE
|
|
114
|
+
? simulatedTx.getPrivateReturnValues()?.nested?.[resultIndex].values
|
|
115
|
+
: simulatedTx.getPublicReturnValues()?.[resultIndex].values;
|
|
116
|
+
|
|
117
|
+
results[callIndex] = rawReturnValues ? decodeFromAbi(call.returnTypes, rawReturnValues) : [];
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
93
121
|
return results;
|
|
94
122
|
}
|
|
123
|
+
|
|
124
|
+
protected async getExecutionPayloads(): Promise<ExecutionPayload[]> {
|
|
125
|
+
return await Promise.all(this.interactions.map(i => (i instanceof ExecutionPayload ? i : i.request())));
|
|
126
|
+
}
|
|
95
127
|
}
|
package/src/contract/checker.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
type AbiType,
|
|
3
|
+
type BasicType,
|
|
4
|
+
type ContractArtifact,
|
|
5
|
+
type StructType,
|
|
6
|
+
getDefaultInitializer,
|
|
7
|
+
} from '@aztec/stdlib/abi';
|
|
2
8
|
|
|
3
9
|
/**
|
|
4
10
|
* Represents a type derived from input type T with the 'kind' property removed.
|
|
@@ -38,8 +44,7 @@ export function abiChecker(artifact: ContractArtifact) {
|
|
|
38
44
|
});
|
|
39
45
|
});
|
|
40
46
|
|
|
41
|
-
|
|
42
|
-
if (!artifact.functions.find(func => func.name === 'constructor')) {
|
|
47
|
+
if (!getDefaultInitializer(artifact)) {
|
|
43
48
|
throw new Error('ABI has no constructor');
|
|
44
49
|
}
|
|
45
50
|
|
package/src/contract/contract.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
-
import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
4
3
|
import { PublicKeys } from '@aztec/stdlib/keys';
|
|
5
4
|
|
|
6
|
-
import type { Wallet } from '../
|
|
5
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
7
6
|
import { ContractBase } from './contract_base.js';
|
|
8
7
|
import { DeployMethod } from './deploy_method.js';
|
|
9
8
|
|
|
@@ -11,33 +10,24 @@ import { DeployMethod } from './deploy_method.js';
|
|
|
11
10
|
* The Contract class represents a contract and provides utility methods for interacting with it.
|
|
12
11
|
* It enables the creation of ContractFunctionInteraction instances for each function in the contract's ABI,
|
|
13
12
|
* allowing users to call or send transactions to these functions. Additionally, the Contract class can be used
|
|
14
|
-
* to attach the contract instance to a deployed contract
|
|
13
|
+
* to attach the contract instance to a deployed contract onchain through the PXE, which facilitates
|
|
15
14
|
* interaction with Aztec's privacy protocol.
|
|
16
15
|
*/
|
|
17
16
|
export class Contract extends ContractBase {
|
|
18
17
|
/**
|
|
19
|
-
*
|
|
20
|
-
* @param address - The
|
|
18
|
+
* Gets a contract instance.
|
|
19
|
+
* @param address - The address of the contract instance.
|
|
21
20
|
* @param artifact - Build artifact of the contract.
|
|
22
21
|
* @param wallet - The wallet to use when interacting with the contract.
|
|
23
22
|
* @returns A promise that resolves to a new Contract instance.
|
|
24
23
|
*/
|
|
25
24
|
public static async at(address: AztecAddress, artifact: ContractArtifact, wallet: Wallet): Promise<Contract> {
|
|
26
|
-
const instance =
|
|
27
|
-
if (instance === undefined) {
|
|
28
|
-
throw new Error(`Contract instance at ${address.toString()} has not been registered in the wallet's PXE`);
|
|
29
|
-
}
|
|
30
|
-
const thisContractClass = await getContractClassFromArtifact(artifact);
|
|
31
|
-
if (!thisContractClass.id.equals(instance.currentContractClassId)) {
|
|
32
|
-
// wallet holds an outdated version of this contract
|
|
33
|
-
await wallet.updateContract(address, artifact);
|
|
34
|
-
instance.currentContractClassId = thisContractClass.id;
|
|
35
|
-
}
|
|
25
|
+
const instance = await wallet.registerContract(address, artifact);
|
|
36
26
|
return new Contract(instance, artifact, wallet);
|
|
37
27
|
}
|
|
38
28
|
|
|
39
29
|
/**
|
|
40
|
-
* Creates a tx to deploy a new instance of a contract.
|
|
30
|
+
* Creates a tx to deploy (initialize and/or publish) a new instance of a contract.
|
|
41
31
|
* @param wallet - The wallet for executing the deployment.
|
|
42
32
|
* @param artifact - Build artifact of the contract to deploy
|
|
43
33
|
* @param args - Arguments for the constructor.
|
|
@@ -49,7 +39,8 @@ export class Contract extends ContractBase {
|
|
|
49
39
|
}
|
|
50
40
|
|
|
51
41
|
/**
|
|
52
|
-
* Creates a tx to deploy a new instance of a contract
|
|
42
|
+
* Creates a tx to deploy (initialize and/or publish) a new instance of a contract
|
|
43
|
+
* using the specified public keys hash to derive the address.
|
|
53
44
|
* @param publicKeys - Hash of public keys to use for deriving the address.
|
|
54
45
|
* @param wallet - The wallet for executing the deployment.
|
|
55
46
|
* @param artifact - Build artifact of the contract.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type ContractArtifact,
|
|
3
|
-
type ContractNote,
|
|
4
3
|
type FieldLayout,
|
|
5
|
-
type
|
|
4
|
+
type FunctionAbi,
|
|
6
5
|
FunctionSelector,
|
|
6
|
+
getAllFunctionAbis,
|
|
7
7
|
} from '@aztec/stdlib/abi';
|
|
8
8
|
import { type ContractInstanceWithAddress, computePartialAddress } from '@aztec/stdlib/contract';
|
|
9
9
|
|
|
10
|
-
import type { Wallet } from '../
|
|
10
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
11
11
|
import { ContractFunctionInteraction } from './contract_function_interaction.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -28,13 +28,6 @@ export type ContractStorageLayout<T extends string> = {
|
|
|
28
28
|
[K in T]: FieldLayout;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
/**
|
|
32
|
-
* Type representing the notes used in a contract.
|
|
33
|
-
*/
|
|
34
|
-
export type ContractNotes<T extends string> = {
|
|
35
|
-
[K in T]: ContractNote;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
31
|
/**
|
|
39
32
|
* Abstract implementation of a contract extended by the Contract class and generated contract types.
|
|
40
33
|
*/
|
|
@@ -52,7 +45,7 @@ export class ContractBase {
|
|
|
52
45
|
/** The wallet used for interacting with this contract. */
|
|
53
46
|
public wallet: Wallet,
|
|
54
47
|
) {
|
|
55
|
-
artifact.
|
|
48
|
+
getAllFunctionAbis(artifact).forEach((f: FunctionAbi) => {
|
|
56
49
|
const interactionFunction = (...args: any[]) => {
|
|
57
50
|
return new ContractFunctionInteraction(this.wallet, this.instance.address, f, args);
|
|
58
51
|
};
|
|
@@ -1,42 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
FunctionSelector,
|
|
5
|
-
FunctionType,
|
|
6
|
-
decodeFromAbi,
|
|
7
|
-
encodeArguments,
|
|
8
|
-
} from '@aztec/stdlib/abi';
|
|
1
|
+
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/entrypoints/payload';
|
|
2
|
+
import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi, encodeArguments } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
9
4
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
|
-
import type
|
|
11
|
-
import type { TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
12
|
-
|
|
13
|
-
import type { Wallet } from '../account/wallet.js';
|
|
14
|
-
import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js';
|
|
15
|
-
import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js';
|
|
16
|
-
|
|
17
|
-
export type { SendMethodOptions };
|
|
5
|
+
import { type Capsule, type HashedValues, type TxProfileResult, collectOffchainEffects } from '@aztec/stdlib/tx';
|
|
18
6
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
skipFeeEnforcement?: boolean;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The result of a profile() call.
|
|
35
|
-
*/
|
|
36
|
-
export type ProfileResult = PrivateKernelProverProfileResult & {
|
|
37
|
-
/** The result of the transaction as returned by the contract function. */
|
|
38
|
-
returnValues: any;
|
|
39
|
-
};
|
|
7
|
+
import type { Wallet } from '../wallet/wallet.js';
|
|
8
|
+
import { BaseContractInteraction } from './base_contract_interaction.js';
|
|
9
|
+
import { getGasLimits } from './get_gas_limits.js';
|
|
10
|
+
import {
|
|
11
|
+
type ProfileInteractionOptions,
|
|
12
|
+
type RequestInteractionOptions,
|
|
13
|
+
type SimulateInteractionOptions,
|
|
14
|
+
type SimulationReturn,
|
|
15
|
+
toProfileOptions,
|
|
16
|
+
toSimulateOptions,
|
|
17
|
+
} from './interaction_options.js';
|
|
40
18
|
|
|
41
19
|
/**
|
|
42
20
|
* This is the class that is returned when calling e.g. `contract.methods.myMethod(arg0, arg1)`.
|
|
@@ -48,40 +26,22 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
48
26
|
protected contractAddress: AztecAddress,
|
|
49
27
|
protected functionDao: FunctionAbi,
|
|
50
28
|
protected args: any[],
|
|
29
|
+
authWitnesses: AuthWitness[] = [],
|
|
30
|
+
capsules: Capsule[] = [],
|
|
31
|
+
private extraHashedArgs: HashedValues[] = [],
|
|
51
32
|
) {
|
|
52
|
-
super(wallet);
|
|
33
|
+
super(wallet, authWitnesses, capsules);
|
|
53
34
|
if (args.some(arg => arg === undefined || arg === null)) {
|
|
54
|
-
throw new Error(
|
|
35
|
+
throw new Error(`All function interaction arguments must be defined and not null. Received: ${args}`);
|
|
55
36
|
}
|
|
56
37
|
}
|
|
57
38
|
|
|
58
|
-
// docs:start:create
|
|
59
39
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* @
|
|
63
|
-
* @returns A Promise that resolves to a transaction instance.
|
|
40
|
+
* Returns the encoded function call wrapped by this interaction
|
|
41
|
+
* Useful when generating authwits
|
|
42
|
+
* @returns An encoded function call
|
|
64
43
|
*/
|
|
65
|
-
public async
|
|
66
|
-
// docs:end:create
|
|
67
|
-
if (this.functionDao.functionType === FunctionType.UNCONSTRAINED) {
|
|
68
|
-
throw new Error("Can't call `create` on an unconstrained function.");
|
|
69
|
-
}
|
|
70
|
-
const calls = [await this.request()];
|
|
71
|
-
const capsules = this.getCapsules();
|
|
72
|
-
const fee = await this.getFeeOptions({ calls, capsules, ...opts });
|
|
73
|
-
const { nonce, cancellable } = opts;
|
|
74
|
-
return await this.wallet.createTxExecutionRequest({ calls, fee, nonce, cancellable, capsules });
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// docs:start:request
|
|
78
|
-
/**
|
|
79
|
-
* Returns an execution request that represents this operation. Useful as a building
|
|
80
|
-
* block for constructing batch requests.
|
|
81
|
-
* @returns An execution request wrapped in promise.
|
|
82
|
-
*/
|
|
83
|
-
public async request(): Promise<FunctionCall> {
|
|
84
|
-
// docs:end:request
|
|
44
|
+
public async getFunctionCall() {
|
|
85
45
|
const args = encodeArguments(this.functionDao, this.args);
|
|
86
46
|
return {
|
|
87
47
|
name: this.functionDao.name,
|
|
@@ -90,35 +50,78 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
90
50
|
type: this.functionDao.functionType,
|
|
91
51
|
to: this.contractAddress,
|
|
92
52
|
isStatic: this.functionDao.isStatic,
|
|
53
|
+
hideMsgSender: false /** Only set to `true` for enqueued public function calls */,
|
|
93
54
|
returnTypes: this.functionDao.returnTypes,
|
|
94
55
|
};
|
|
95
56
|
}
|
|
96
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Returns the execution payload that allows this operation to happen on chain.
|
|
60
|
+
* @param options - Configuration options.
|
|
61
|
+
* @returns The execution payload for this operation
|
|
62
|
+
*/
|
|
63
|
+
public override async request(options: RequestInteractionOptions = {}): Promise<ExecutionPayload> {
|
|
64
|
+
const calls = [await this.getFunctionCall()];
|
|
65
|
+
const { authWitnesses, capsules } = options;
|
|
66
|
+
const feeExecutionPayload = options.fee?.paymentMethod
|
|
67
|
+
? await options.fee.paymentMethod.getExecutionPayload()
|
|
68
|
+
: undefined;
|
|
69
|
+
const functionExecutionPayload = new ExecutionPayload(
|
|
70
|
+
calls,
|
|
71
|
+
this.authWitnesses.concat(authWitnesses ?? []),
|
|
72
|
+
this.capsules.concat(capsules ?? []),
|
|
73
|
+
this.extraHashedArgs,
|
|
74
|
+
);
|
|
75
|
+
const finalExecutionPayload = feeExecutionPayload
|
|
76
|
+
? mergeExecutionPayloads([feeExecutionPayload, functionExecutionPayload])
|
|
77
|
+
: functionExecutionPayload;
|
|
78
|
+
return finalExecutionPayload;
|
|
79
|
+
}
|
|
80
|
+
|
|
97
81
|
// docs:start:simulate
|
|
98
82
|
/**
|
|
99
|
-
* Simulate a transaction and get its
|
|
83
|
+
* Simulate a transaction and get information from its execution.
|
|
100
84
|
* Differs from prove in a few important ways:
|
|
101
|
-
* 1. It returns the values of the function execution
|
|
102
|
-
* 2. It supports `
|
|
85
|
+
* 1. It returns the values of the function execution, plus additional metadata if requested
|
|
86
|
+
* 2. It supports `utility`, `private` and `public` functions
|
|
103
87
|
*
|
|
104
|
-
* @param options - An optional object containing additional configuration for the
|
|
105
|
-
* @returns
|
|
88
|
+
* @param options - An optional object containing additional configuration for the simulation.
|
|
89
|
+
* @returns Depending on the simulation options, this method directly returns the result value of the executed
|
|
90
|
+
* function or a rich object containing extra metadata, such as estimated gas costs (if requested via options),
|
|
91
|
+
* execution statistics and emitted offchain effects
|
|
106
92
|
*/
|
|
107
|
-
public async simulate
|
|
93
|
+
public async simulate<T extends SimulateInteractionOptions>(
|
|
94
|
+
options: T,
|
|
95
|
+
): Promise<SimulationReturn<Exclude<T['fee'], undefined>['estimateGas']>>;
|
|
96
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
97
|
+
public async simulate<T extends SimulateInteractionOptions>(
|
|
98
|
+
options: T,
|
|
99
|
+
): Promise<SimulationReturn<T['includeMetadata']>>;
|
|
100
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
101
|
+
public async simulate(
|
|
102
|
+
options: SimulateInteractionOptions,
|
|
103
|
+
): Promise<SimulationReturn<typeof options.includeMetadata>> {
|
|
108
104
|
// docs:end:simulate
|
|
109
|
-
if (this.functionDao.functionType == FunctionType.
|
|
110
|
-
|
|
105
|
+
if (this.functionDao.functionType == FunctionType.UTILITY) {
|
|
106
|
+
const utilityResult = await this.wallet.simulateUtility(
|
|
107
|
+
this.functionDao.name,
|
|
108
|
+
this.args,
|
|
109
|
+
this.contractAddress,
|
|
110
|
+
options.authWitnesses ?? [],
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
if (options.includeMetadata) {
|
|
114
|
+
return {
|
|
115
|
+
stats: utilityResult.stats,
|
|
116
|
+
result: utilityResult.result,
|
|
117
|
+
};
|
|
118
|
+
} else {
|
|
119
|
+
return utilityResult.result;
|
|
120
|
+
}
|
|
111
121
|
}
|
|
112
122
|
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
const simulatedTx = await this.wallet.simulateTx(
|
|
116
|
-
txRequest,
|
|
117
|
-
true /* simulatePublic */,
|
|
118
|
-
options.from,
|
|
119
|
-
options.skipTxValidation,
|
|
120
|
-
options.skipFeeEnforcement ?? true,
|
|
121
|
-
);
|
|
123
|
+
const executionPayload = await this.request(options);
|
|
124
|
+
const simulatedTx = await this.wallet.simulateTx(executionPayload, await toSimulateOptions(options));
|
|
122
125
|
|
|
123
126
|
let rawReturnValues;
|
|
124
127
|
if (this.functionDao.functionType == FunctionType.PRIVATE) {
|
|
@@ -132,42 +135,69 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
132
135
|
}
|
|
133
136
|
} else {
|
|
134
137
|
// For public functions we retrieve the first values directly from the public output.
|
|
135
|
-
rawReturnValues = simulatedTx.getPublicReturnValues()?.[0]
|
|
138
|
+
rawReturnValues = simulatedTx.getPublicReturnValues()?.[0]?.values;
|
|
136
139
|
}
|
|
137
140
|
|
|
138
|
-
|
|
141
|
+
const returnValue = rawReturnValues ? decodeFromAbi(this.functionDao.returnTypes, rawReturnValues) : [];
|
|
142
|
+
|
|
143
|
+
if (options.includeMetadata || options.fee?.estimateGas) {
|
|
144
|
+
const { gasLimits, teardownGasLimits } = getGasLimits(simulatedTx, options.fee?.estimatedGasPadding);
|
|
145
|
+
this.log.verbose(
|
|
146
|
+
`Estimated gas limits for tx: DA=${gasLimits.daGas} L2=${gasLimits.l2Gas} teardownDA=${teardownGasLimits.daGas} teardownL2=${teardownGasLimits.l2Gas}`,
|
|
147
|
+
);
|
|
148
|
+
return {
|
|
149
|
+
stats: simulatedTx.stats,
|
|
150
|
+
offchainEffects: collectOffchainEffects(simulatedTx.privateExecutionResult),
|
|
151
|
+
result: returnValue,
|
|
152
|
+
estimatedGas: { gasLimits, teardownGasLimits },
|
|
153
|
+
};
|
|
154
|
+
} else {
|
|
155
|
+
return returnValue;
|
|
156
|
+
}
|
|
139
157
|
}
|
|
140
158
|
|
|
141
159
|
/**
|
|
142
160
|
* Simulate a transaction and profile the gate count for each function in the transaction.
|
|
143
|
-
* @param options - Same options as `simulate
|
|
161
|
+
* @param options - Same options as `simulate`, plus profiling method
|
|
144
162
|
*
|
|
145
163
|
* @returns An object containing the function return value and profile result.
|
|
146
164
|
*/
|
|
147
|
-
public async
|
|
148
|
-
if (this.functionDao.functionType == FunctionType.
|
|
149
|
-
throw new Error("Can't profile
|
|
165
|
+
public async profile(options: ProfileInteractionOptions): Promise<TxProfileResult> {
|
|
166
|
+
if (this.functionDao.functionType == FunctionType.UTILITY) {
|
|
167
|
+
throw new Error("Can't profile a utility function.");
|
|
150
168
|
}
|
|
151
169
|
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
true,
|
|
156
|
-
options?.from,
|
|
157
|
-
options?.skipTxValidation,
|
|
158
|
-
undefined,
|
|
159
|
-
true,
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
const rawReturnValues =
|
|
163
|
-
this.functionDao.functionType == FunctionType.PRIVATE
|
|
164
|
-
? simulatedTx.getPrivateReturnValues().nested?.[0].values
|
|
165
|
-
: simulatedTx.getPublicReturnValues()?.[0].values;
|
|
166
|
-
const rawReturnValuesDecoded = rawReturnValues ? decodeFromAbi(this.functionDao.returnTypes, rawReturnValues) : [];
|
|
170
|
+
const executionPayload = await this.request(options);
|
|
171
|
+
return await this.wallet.profileTx(executionPayload, await toProfileOptions(options));
|
|
172
|
+
}
|
|
167
173
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Augments this ContractFunctionInteraction with additional metadata, such as authWitnesses, capsules, and extraHashedArgs.
|
|
176
|
+
* This is useful when creating a "batteries included" interaction, such as registering a contract class with its associated
|
|
177
|
+
* capsule instead of having the user provide them externally.
|
|
178
|
+
* @param options - An object containing the metadata to add to the interaction
|
|
179
|
+
* @returns A new ContractFunctionInteraction with the added metadata, but calling the same original function in the same manner
|
|
180
|
+
*/
|
|
181
|
+
public with({
|
|
182
|
+
authWitnesses = [],
|
|
183
|
+
capsules = [],
|
|
184
|
+
extraHashedArgs = [],
|
|
185
|
+
}: {
|
|
186
|
+
/** The authWitnesses to add to the interaction */
|
|
187
|
+
authWitnesses?: AuthWitness[];
|
|
188
|
+
/** The capsules to add to the interaction */
|
|
189
|
+
capsules?: Capsule[];
|
|
190
|
+
/** The extra hashed args to add to the interaction */
|
|
191
|
+
extraHashedArgs?: HashedValues[];
|
|
192
|
+
}): ContractFunctionInteraction {
|
|
193
|
+
return new ContractFunctionInteraction(
|
|
194
|
+
this.wallet,
|
|
195
|
+
this.contractAddress,
|
|
196
|
+
this.functionDao,
|
|
197
|
+
this.args,
|
|
198
|
+
this.authWitnesses.concat(authWitnesses),
|
|
199
|
+
this.capsules.concat(capsules),
|
|
200
|
+
this.extraHashedArgs.concat(extraHashedArgs),
|
|
201
|
+
);
|
|
172
202
|
}
|
|
173
203
|
}
|