@aztec/aztec.js 3.0.0-canary.a9708bd → 3.0.0-devnet.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/account/account.d.ts +60 -0
- package/dest/account/account.d.ts.map +1 -0
- package/dest/account/account.js +59 -0
- package/dest/account/account_contract.d.ts +5 -5
- package/dest/account/account_contract.d.ts.map +1 -1
- package/dest/account/account_contract.js +0 -1
- 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 +1 -4
- package/dest/account/index.d.ts.map +1 -1
- package/dest/account/index.js +1 -4
- 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 +1 -0
- package/dest/api/abi.d.ts.map +1 -1
- package/dest/api/account.d.ts +4 -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 +2 -0
- package/dest/api/authorization.d.ts.map +1 -1
- package/dest/api/authorization.js +2 -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 +4 -5
- package/dest/api/contract.d.ts.map +1 -1
- package/dest/api/contract.js +3 -3
- 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/ethereum.d.ts +0 -1
- package/dest/api/ethereum.d.ts.map +1 -1
- package/dest/api/ethereum.js +0 -1
- 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 -2
- package/dest/api/fee.d.ts.map +1 -1
- package/dest/api/fee.js +0 -1
- 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 +10 -6
- package/dest/api/utils.d.ts.map +1 -1
- package/dest/api/utils.js +10 -5
- 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/contract/base_contract_interaction.d.ts +6 -48
- package/dest/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.js +6 -106
- package/dest/contract/batch_call.d.ts +6 -14
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +42 -52
- package/dest/contract/contract.d.ts +1 -1
- package/dest/contract/contract.d.ts.map +1 -1
- package/dest/contract/contract.js +2 -12
- package/dest/contract/contract_base.d.ts +1 -1
- package/dest/contract/contract_base.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.d.ts +29 -40
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +41 -53
- package/dest/contract/deploy_method.d.ts +63 -56
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +68 -86
- package/dest/contract/deploy_sent_tx.d.ts +0 -1
- package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
- package/dest/contract/deploy_sent_tx.js +7 -10
- package/dest/contract/interaction_options.d.ts +74 -19
- package/dest/contract/interaction_options.d.ts.map +1 -1
- package/dest/contract/interaction_options.js +51 -3
- package/dest/contract/sent_tx.d.ts +3 -3
- package/dest/contract/sent_tx.d.ts.map +1 -1
- package/dest/contract/sent_tx.js +5 -5
- package/dest/contract/wait_for_proven.d.ts +3 -3
- package/dest/contract/wait_for_proven.d.ts.map +1 -1
- package/dest/contract/wait_for_proven.js +2 -2
- package/dest/deployment/publish_instance.d.ts +1 -1
- package/dest/deployment/publish_instance.d.ts.map +1 -1
- package/dest/deployment/publish_instance.js +2 -5
- package/dest/ethereum/portal_manager.d.ts +3 -4
- package/dest/ethereum/portal_manager.d.ts.map +1 -1
- package/dest/ethereum/portal_manager.js +3 -5
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts +12 -7
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -1
- package/dest/fee/fee_juice_payment_method_with_claim.js +21 -12
- 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 +22 -5
- package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/private_fee_payment_method.js +34 -13
- package/dest/fee/public_fee_payment_method.d.ts +22 -5
- package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/public_fee_payment_method.js +37 -14
- package/dest/fee/sponsored_fee_payment.d.ts +2 -0
- package/dest/fee/sponsored_fee_payment.d.ts.map +1 -1
- package/dest/fee/sponsored_fee_payment.js +4 -0
- package/dest/utils/authwit.d.ts +77 -25
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +219 -24
- 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/{fee → wallet}/account_entrypoint_meta_payment_method.d.ts +13 -10
- 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 +78 -35
- package/dest/wallet/base_wallet.d.ts.map +1 -1
- package/dest/wallet/base_wallet.js +216 -48
- 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 +2 -15
- package/dest/wallet/index.d.ts.map +1 -1
- package/dest/wallet/index.js +2 -19
- package/dest/wallet/wallet.d.ts +2473 -6
- package/dest/wallet/wallet.d.ts.map +1 -1
- package/dest/wallet/wallet.js +202 -3
- package/package.json +25 -21
- package/src/account/account.ts +97 -0
- package/src/account/account_contract.ts +4 -6
- package/src/{wallet/account_wallet_with_private_key.ts → account/account_with_secret_key.ts} +6 -8
- package/src/account/index.ts +1 -4
- package/src/account/signerless_account.ts +46 -0
- package/src/api/abi.ts +11 -0
- package/src/api/account.ts +4 -2
- package/src/api/addresses.ts +1 -0
- package/src/api/authorization.ts +11 -0
- package/src/api/block.ts +2 -0
- package/src/api/contract.ts +16 -8
- package/src/api/crypto.ts +1 -0
- package/src/api/ethereum.ts +0 -1
- package/src/api/events.ts +44 -0
- package/src/api/fee.ts +1 -2
- 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 +12 -19
- package/src/api/wallet.ts +33 -5
- package/src/contract/base_contract_interaction.ts +9 -138
- package/src/contract/batch_call.ts +52 -61
- package/src/contract/contract.ts +2 -12
- package/src/contract/contract_function_interaction.ts +65 -97
- package/src/contract/deploy_method.ts +117 -99
- package/src/contract/deploy_sent_tx.ts +4 -10
- package/src/contract/interaction_options.ts +126 -24
- package/src/contract/sent_tx.ts +4 -4
- package/src/contract/wait_for_proven.ts +4 -4
- package/src/deployment/publish_instance.ts +3 -8
- package/src/ethereum/portal_manager.ts +4 -12
- package/src/fee/fee_juice_payment_method_with_claim.ts +26 -17
- package/src/fee/fee_payment_method.ts +26 -0
- package/src/fee/private_fee_payment_method.ts +60 -41
- package/src/fee/public_fee_payment_method.ts +73 -49
- package/src/fee/sponsored_fee_payment.ts +6 -0
- package/src/utils/authwit.ts +250 -38
- package/src/utils/cross_chain.ts +53 -0
- package/src/utils/fee_juice.ts +4 -3
- 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 +287 -78
- package/src/wallet/deploy_account_method.ts +125 -0
- package/src/wallet/index.ts +2 -32
- package/src/wallet/wallet.ts +357 -29
- package/dest/account_manager/account_manager.d.ts +0 -119
- package/dest/account_manager/account_manager.d.ts.map +0 -1
- package/dest/account_manager/account_manager.js +0 -202
- 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 -3
- package/dest/account_manager/index.d.ts.map +0 -1
- package/dest/account_manager/index.js +0 -2
- package/dest/api/interfaces.d.ts +0 -2
- package/dest/api/interfaces.d.ts.map +0 -1
- package/dest/api/interfaces.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/rpc.d.ts +0 -3
- package/dest/api/rpc.d.ts.map +0 -1
- package/dest/api/rpc.js +0 -2
- 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 -21
- package/dest/contract/proven_tx.d.ts +0 -21
- package/dest/contract/proven_tx.d.ts.map +0 -1
- package/dest/contract/proven_tx.js +0 -23
- package/dest/ethereum/l1_contracts.d.ts +0 -3
- package/dest/ethereum/l1_contracts.d.ts.map +0 -1
- package/dest/ethereum/l1_contracts.js +0 -13
- package/dest/fee/account_entrypoint_meta_payment_method.d.ts.map +0 -1
- package/dest/fee/account_entrypoint_meta_payment_method.js +0 -64
- 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 -21
- package/dest/fee/utils.d.ts +0 -13
- package/dest/fee/utils.d.ts.map +0 -1
- package/dest/fee/utils.js +0 -32
- package/dest/index.d.ts +0 -59
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -62
- 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 -72
- 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/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 -74
- package/dest/wallet/account_wallet.d.ts.map +0 -1
- package/dest/wallet/account_wallet.js +0 -232
- package/dest/wallet/account_wallet_with_private_key.d.ts.map +0 -1
- package/dest/wallet/signerless_wallet.d.ts +0 -23
- package/dest/wallet/signerless_wallet.d.ts.map +0 -1
- package/dest/wallet/signerless_wallet.js +0 -33
- package/src/account_manager/account_manager.ts +0 -276
- package/src/account_manager/deploy_account_sent_tx.ts +0 -46
- package/src/account_manager/index.ts +0 -2
- package/src/api/interfaces.ts +0 -1
- package/src/api/log_id.ts +0 -1
- package/src/api/rpc.ts +0 -2
- package/src/api/tx_hash.ts +0 -1
- package/src/contract/deploy_proven_tx.ts +0 -45
- package/src/contract/proven_tx.ts +0 -36
- package/src/ethereum/l1_contracts.ts +0 -21
- package/src/fee/account_entrypoint_meta_payment_method.ts +0 -89
- package/src/fee/fee_juice_payment_method.ts +0 -25
- package/src/fee/utils.ts +0 -39
- package/src/index.ts +0 -85
- package/src/rpc_clients/node/index.ts +0 -77
- package/src/rpc_clients/pxe_client.ts +0 -25
- package/src/utils/pxe.ts +0 -17
- package/src/wallet/account_wallet.ts +0 -246
- package/src/wallet/signerless_wallet.ts +0 -56
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
2
|
+
import { EncodedAppEntrypointCalls } from '@aztec/entrypoints/encoding';
|
|
3
|
+
import { ExecutionPayload } from '@aztec/entrypoints/payload';
|
|
4
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
5
|
+
import {
|
|
6
|
+
type ContractArtifact,
|
|
7
|
+
type FunctionArtifact,
|
|
8
|
+
FunctionCall,
|
|
9
|
+
FunctionSelector,
|
|
10
|
+
encodeArguments,
|
|
11
|
+
getFunctionArtifactByName,
|
|
12
|
+
} from '@aztec/stdlib/abi';
|
|
13
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
14
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
15
|
+
|
|
16
|
+
import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
|
|
17
|
+
import type { Wallet } from './index.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Fee payment method that allows an account contract to pay for its own deployment
|
|
21
|
+
* It works by rerouting the provided fee payment method through the account's entrypoint,
|
|
22
|
+
* which sets itself as fee payer. If no payment method is provided, it is assumed the
|
|
23
|
+
* account will pay with its own fee juice balance.
|
|
24
|
+
*
|
|
25
|
+
* Usually, in order to pay fees it is necessary to obtain an ExecutionPayload that encodes the necessary information
|
|
26
|
+
* that is sent to the user's account entrypoint, that has plumbing to handle it.
|
|
27
|
+
* If there's no account contract yet (it's being deployed) a MultiCallContract is used, which doesn't have a concept of fees or
|
|
28
|
+
* how to handle this payload.
|
|
29
|
+
* HOWEVER, the account contract's entrypoint does, so this method reshapes that fee payload into a call to the account contract entrypoint
|
|
30
|
+
* being deployed with the original fee payload.
|
|
31
|
+
*
|
|
32
|
+
* This class can be seen in action in DeployAccountMethod.ts#getSelfPaymentMethod
|
|
33
|
+
*/
|
|
34
|
+
export class AccountEntrypointMetaPaymentMethod implements FeePaymentMethod {
|
|
35
|
+
constructor(
|
|
36
|
+
private wallet: Wallet,
|
|
37
|
+
private artifact: ContractArtifact,
|
|
38
|
+
private feePaymentNameOrArtifact: string | FunctionArtifact,
|
|
39
|
+
private accountAddress: AztecAddress,
|
|
40
|
+
private paymentMethod?: FeePaymentMethod,
|
|
41
|
+
) {}
|
|
42
|
+
|
|
43
|
+
getAsset(): Promise<AztecAddress> {
|
|
44
|
+
return this.paymentMethod?.getAsset() ?? Promise.resolve(ProtocolContractAddress.FeeJuice);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async getExecutionPayload(): Promise<ExecutionPayload> {
|
|
48
|
+
// Get the execution payload for the fee, it includes the calls and potentially authWitnesses
|
|
49
|
+
// It can be empty because the account might attempt to pay for the tx fee using its own
|
|
50
|
+
// FeeJuice balance
|
|
51
|
+
const { calls: feeCalls, authWitnesses: feeAuthwitnesses } =
|
|
52
|
+
(await this.paymentMethod?.getExecutionPayload()) ?? ExecutionPayload.empty();
|
|
53
|
+
// Encode the calls for the fee
|
|
54
|
+
const feePayer = (await this.paymentMethod?.getFeePayer()) ?? this.accountAddress;
|
|
55
|
+
const isFeePayer = feePayer.equals(this.accountAddress);
|
|
56
|
+
let accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.EXTERNAL;
|
|
57
|
+
if (isFeePayer) {
|
|
58
|
+
// If the account is the fee payer, and the incoming fee payload has calls
|
|
59
|
+
// it can only be FeeJuicePaymentMethodWithClaim
|
|
60
|
+
// If the payload has no calls, it's paying using
|
|
61
|
+
// its own fee juice balance
|
|
62
|
+
accountFeePaymentMethodOptions =
|
|
63
|
+
feeCalls.length === 0
|
|
64
|
+
? AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE
|
|
65
|
+
: AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM;
|
|
66
|
+
}
|
|
67
|
+
const feeEncodedCalls = await EncodedAppEntrypointCalls.create(feeCalls);
|
|
68
|
+
|
|
69
|
+
// Get the entrypoint args
|
|
70
|
+
const args = [feeEncodedCalls, accountFeePaymentMethodOptions, false];
|
|
71
|
+
const feePaymentArtifact =
|
|
72
|
+
typeof this.feePaymentNameOrArtifact === 'string'
|
|
73
|
+
? getFunctionArtifactByName(this.artifact, this.feePaymentNameOrArtifact)
|
|
74
|
+
: this.feePaymentNameOrArtifact;
|
|
75
|
+
|
|
76
|
+
const entrypointCall = new FunctionCall(
|
|
77
|
+
feePaymentArtifact.name,
|
|
78
|
+
this.accountAddress,
|
|
79
|
+
await FunctionSelector.fromNameAndParameters(feePaymentArtifact.name, feePaymentArtifact.parameters),
|
|
80
|
+
feePaymentArtifact.functionType,
|
|
81
|
+
false /** hideMsgSender -- set to `false`, because it's not applicable for an entrypoint function (only for enqueued public calls) */,
|
|
82
|
+
feePaymentArtifact.isStatic,
|
|
83
|
+
encodeArguments(feePaymentArtifact, args),
|
|
84
|
+
feePaymentArtifact.returnTypes,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
// Compute the authwitness required to verify the combined payload
|
|
88
|
+
const payloadAuthWitness = await this.wallet.createAuthWit(this.accountAddress, await feeEncodedCalls.hash());
|
|
89
|
+
|
|
90
|
+
return new ExecutionPayload(
|
|
91
|
+
[entrypointCall],
|
|
92
|
+
[payloadAuthWitness, ...feeAuthwitnesses],
|
|
93
|
+
[],
|
|
94
|
+
feeEncodedCalls.hashedArguments,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getFeePayer(): Promise<AztecAddress> {
|
|
99
|
+
return this.paymentMethod?.getFeePayer() ?? Promise.resolve(this.accountAddress);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
getGasSettings(): GasSettings | undefined {
|
|
103
|
+
return this.paymentMethod?.getGasSettings();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import {
|
|
3
|
+
CompleteAddress,
|
|
4
|
+
type ContractInstanceWithAddress,
|
|
5
|
+
getContractInstanceFromInstantiationParams,
|
|
6
|
+
} from '@aztec/stdlib/contract';
|
|
7
|
+
import { deriveKeys } from '@aztec/stdlib/keys';
|
|
8
|
+
|
|
9
|
+
import type { AccountContract } from '../account/account_contract.js';
|
|
10
|
+
import { AccountWithSecretKey } from '../account/account_with_secret_key.js';
|
|
11
|
+
import type { Salt } from '../account/index.js';
|
|
12
|
+
import type { AccountInterface } from '../account/interface.js';
|
|
13
|
+
import { Contract } from '../contract/contract.js';
|
|
14
|
+
import { DeployAccountMethod } from './deploy_account_method.js';
|
|
15
|
+
import type { Wallet } from './wallet.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Manages a user account. Provides methods for calculating the account's address and other related data,
|
|
19
|
+
* plus a helper to return a preconfigured deploy method.
|
|
20
|
+
*/
|
|
21
|
+
export class AccountManager {
|
|
22
|
+
private constructor(
|
|
23
|
+
private wallet: Wallet,
|
|
24
|
+
private secretKey: Fr,
|
|
25
|
+
private accountContract: AccountContract,
|
|
26
|
+
private instance: ContractInstanceWithAddress,
|
|
27
|
+
/**
|
|
28
|
+
* Contract instantiation salt for the account contract
|
|
29
|
+
*/
|
|
30
|
+
public readonly salt: Salt,
|
|
31
|
+
) {}
|
|
32
|
+
|
|
33
|
+
static async create(wallet: Wallet, secretKey: Fr, accountContract: AccountContract, salt?: Salt) {
|
|
34
|
+
const { publicKeys } = await deriveKeys(secretKey);
|
|
35
|
+
salt = salt !== undefined ? new Fr(salt) : Fr.random();
|
|
36
|
+
|
|
37
|
+
const { constructorName, constructorArgs } = (await accountContract.getInitializationFunctionAndArgs()) ?? {
|
|
38
|
+
constructorName: undefined,
|
|
39
|
+
constructorArgs: undefined,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const artifact = await accountContract.getContractArtifact();
|
|
43
|
+
const instance = await getContractInstanceFromInstantiationParams(artifact, {
|
|
44
|
+
constructorArtifact: constructorName,
|
|
45
|
+
constructorArgs,
|
|
46
|
+
salt: salt,
|
|
47
|
+
publicKeys,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return new AccountManager(wallet, secretKey, accountContract, instance, salt);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected getPublicKeys() {
|
|
54
|
+
return this.instance.publicKeys;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
protected getPublicKeysHash() {
|
|
58
|
+
return this.getPublicKeys().hash();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Returns the entrypoint for this account as defined by its account contract.
|
|
63
|
+
* @returns An entrypoint.
|
|
64
|
+
*/
|
|
65
|
+
public async getAccountInterface(): Promise<AccountInterface> {
|
|
66
|
+
const chainInfo = await this.wallet.getChainInfo();
|
|
67
|
+
const completeAddress = await this.getCompleteAddress();
|
|
68
|
+
return this.accountContract.getInterface(completeAddress, chainInfo);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Gets the calculated complete address associated with this account.
|
|
73
|
+
* Does not require the account to have been published for public execution.
|
|
74
|
+
* @returns The address, partial address, and encryption public key.
|
|
75
|
+
*/
|
|
76
|
+
public getCompleteAddress(): Promise<CompleteAddress> {
|
|
77
|
+
return CompleteAddress.fromSecretKeyAndInstance(this.secretKey, this.instance);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Returns the secret key used to derive the rest of the privacy keys for this contract
|
|
82
|
+
*/
|
|
83
|
+
public getSecretKey() {
|
|
84
|
+
return this.secretKey;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get address() {
|
|
88
|
+
return this.instance.address;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Returns the contract instance definition associated with this account.
|
|
93
|
+
* Does not require the account to have been published for public execution.
|
|
94
|
+
* @returns ContractInstance instance.
|
|
95
|
+
*/
|
|
96
|
+
public getInstance(): ContractInstanceWithAddress {
|
|
97
|
+
return this.instance;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Returns a Wallet instance associated with this account. Use it to create Contract
|
|
102
|
+
* instances to be interacted with from this account.
|
|
103
|
+
* @returns A Wallet instance.
|
|
104
|
+
*/
|
|
105
|
+
public async getAccount(): Promise<AccountWithSecretKey> {
|
|
106
|
+
const accountInterface = await this.getAccountInterface();
|
|
107
|
+
return new AccountWithSecretKey(accountInterface, this.secretKey, this.salt);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Returns the account contract that backs this account.
|
|
112
|
+
* @returns The account contract
|
|
113
|
+
*/
|
|
114
|
+
getAccountContract(): AccountContract {
|
|
115
|
+
return this.accountContract;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Returns a preconfigured deploy method that contains all the necessary function
|
|
120
|
+
* calls to deploy the account contract.
|
|
121
|
+
*/
|
|
122
|
+
public async getDeployMethod(): Promise<DeployAccountMethod> {
|
|
123
|
+
const artifact = await this.accountContract.getContractArtifact();
|
|
124
|
+
|
|
125
|
+
if (!(await this.hasInitializer())) {
|
|
126
|
+
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/15576):
|
|
127
|
+
// there should be a path which enables an account contract's class & instance to be published,
|
|
128
|
+
// even if the account contract doesn't have an initializer function. This should not throw.
|
|
129
|
+
throw new Error(`Account contract ${artifact.name} does not have an initializer function to call.`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const { constructorName, constructorArgs } = (await this.accountContract.getInitializationFunctionAndArgs()) ?? {
|
|
133
|
+
constructorName: undefined,
|
|
134
|
+
constructorArgs: undefined,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
return new DeployAccountMethod(
|
|
138
|
+
this.getPublicKeys(),
|
|
139
|
+
this.wallet,
|
|
140
|
+
artifact,
|
|
141
|
+
address => Contract.at(address, artifact, this.wallet),
|
|
142
|
+
new Fr(this.salt),
|
|
143
|
+
constructorArgs,
|
|
144
|
+
constructorName,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Returns whether this account contract has an initializer function.
|
|
150
|
+
*/
|
|
151
|
+
public async hasInitializer() {
|
|
152
|
+
return (await this.accountContract.getInitializationFunctionAndArgs()) !== undefined;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -1,105 +1,322 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
GAS_ESTIMATION_DA_GAS_LIMIT,
|
|
3
|
+
GAS_ESTIMATION_L2_GAS_LIMIT,
|
|
4
|
+
GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT,
|
|
5
|
+
GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT,
|
|
6
|
+
} from '@aztec/constants';
|
|
7
|
+
import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
8
|
+
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
9
|
+
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/entrypoints/payload';
|
|
10
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
11
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
12
|
+
import type { ContractArtifact, EventMetadataDefinition } from '@aztec/stdlib/abi';
|
|
5
13
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
6
14
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
-
import
|
|
8
|
-
|
|
15
|
+
import {
|
|
16
|
+
type ContractClassMetadata,
|
|
17
|
+
type ContractInstanceWithAddress,
|
|
18
|
+
type ContractInstantiationData,
|
|
19
|
+
type ContractMetadata,
|
|
20
|
+
computePartialAddress,
|
|
21
|
+
getContractClassFromArtifact,
|
|
22
|
+
getContractInstanceFromInstantiationParams,
|
|
23
|
+
} from '@aztec/stdlib/contract';
|
|
24
|
+
import { SimulationError } from '@aztec/stdlib/errors';
|
|
25
|
+
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
26
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
9
27
|
import type {
|
|
10
|
-
ContractClassMetadata,
|
|
11
|
-
ContractMetadata,
|
|
12
|
-
EventMetadataDefinition,
|
|
13
|
-
PXE,
|
|
14
|
-
PXEInfo,
|
|
15
|
-
} from '@aztec/stdlib/interfaces/client';
|
|
16
|
-
import type {
|
|
17
|
-
PrivateExecutionResult,
|
|
18
|
-
SimulationOverrides,
|
|
19
|
-
Tx,
|
|
20
28
|
TxExecutionRequest,
|
|
21
29
|
TxHash,
|
|
22
30
|
TxProfileResult,
|
|
23
|
-
TxProvingResult,
|
|
24
31
|
TxReceipt,
|
|
25
32
|
TxSimulationResult,
|
|
26
33
|
UtilitySimulationResult,
|
|
27
34
|
} from '@aztec/stdlib/tx';
|
|
28
35
|
|
|
29
|
-
import
|
|
30
|
-
|
|
36
|
+
import { inspect } from 'util';
|
|
37
|
+
|
|
38
|
+
import type { Account } from '../account/account.js';
|
|
39
|
+
import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
|
|
40
|
+
import type { CallIntent, IntentInnerHash } from '../utils/authwit.js';
|
|
41
|
+
import type {
|
|
42
|
+
Aliased,
|
|
43
|
+
BatchResults,
|
|
44
|
+
BatchableMethods,
|
|
45
|
+
BatchedMethod,
|
|
46
|
+
ContractInstanceAndArtifact,
|
|
47
|
+
ProfileOptions,
|
|
48
|
+
SendOptions,
|
|
49
|
+
SimulateOptions,
|
|
50
|
+
UserFeeOptions,
|
|
51
|
+
Wallet,
|
|
52
|
+
} from './wallet.js';
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Options to configure fee payment for a transaction
|
|
56
|
+
*/
|
|
57
|
+
export type FeeOptions = {
|
|
58
|
+
/**
|
|
59
|
+
* A wallet-provided fallback fee payment method that is used only if the transaction that is being constructed
|
|
60
|
+
* doesn't already include one
|
|
61
|
+
*/
|
|
62
|
+
walletFeePaymentMethod?: FeePaymentMethod;
|
|
63
|
+
/** Configuration options for the account to properly handle the selected fee payment method */
|
|
64
|
+
accountFeePaymentMethodOptions: AccountFeePaymentMethodOptions;
|
|
65
|
+
/** The gas settings to use for the transaction */
|
|
66
|
+
gasSettings: GasSettings;
|
|
67
|
+
};
|
|
31
68
|
|
|
32
69
|
/**
|
|
33
70
|
* A base class for Wallet implementations
|
|
34
71
|
*/
|
|
35
72
|
export abstract class BaseWallet implements Wallet {
|
|
36
|
-
|
|
73
|
+
protected log = createLogger('aztecjs:base_wallet');
|
|
37
74
|
|
|
38
|
-
|
|
75
|
+
protected baseFeePadding = 0.5;
|
|
76
|
+
protected cancellableTransactions = false;
|
|
39
77
|
|
|
40
|
-
|
|
78
|
+
// Protected because we want to force wallets to instantiate their own PXE.
|
|
79
|
+
protected constructor(
|
|
80
|
+
// TODO: We cannot type here pxe because we cannot import that package as that would result in a circular
|
|
81
|
+
// dependency. This will eventually get resolved by the introduction of @aztec/wallet-sdk package.
|
|
82
|
+
protected readonly pxe: any,
|
|
83
|
+
protected readonly aztecNode: AztecNode,
|
|
84
|
+
) {}
|
|
41
85
|
|
|
42
|
-
abstract
|
|
86
|
+
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
43
87
|
|
|
44
|
-
abstract
|
|
45
|
-
exec: ExecutionPayload,
|
|
46
|
-
fee: FeeOptions,
|
|
47
|
-
options: TxExecutionOptions,
|
|
48
|
-
): Promise<TxExecutionRequest>;
|
|
88
|
+
abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
49
89
|
|
|
50
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Returns the list of aliased contacts associated with the wallet.
|
|
92
|
+
* This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
|
|
93
|
+
* - Senders: Addresses we check during synching in case they sent us notes,
|
|
94
|
+
* - Contacts: more general concept akin to a phone's contact list.
|
|
95
|
+
* @returns The aliased collection of AztecAddresses that form this wallet's address book
|
|
96
|
+
*/
|
|
97
|
+
async getAddressBook(): Promise<Aliased<AztecAddress>[]> {
|
|
98
|
+
const senders: AztecAddress[] = await this.pxe.getSenders();
|
|
99
|
+
return senders.map(sender => ({ item: sender, alias: '' }));
|
|
100
|
+
}
|
|
51
101
|
|
|
52
|
-
|
|
53
|
-
|
|
102
|
+
async getChainInfo(): Promise<ChainInfo> {
|
|
103
|
+
const { l1ChainId, rollupVersion } = await this.aztecNode.getNodeInfo();
|
|
104
|
+
return { chainId: new Fr(l1ChainId), version: new Fr(rollupVersion) };
|
|
54
105
|
}
|
|
55
106
|
|
|
56
|
-
|
|
57
|
-
|
|
107
|
+
protected async createTxExecutionRequestFromPayloadAndFee(
|
|
108
|
+
executionPayload: ExecutionPayload,
|
|
109
|
+
from: AztecAddress,
|
|
110
|
+
feeOptions: FeeOptions,
|
|
111
|
+
): Promise<TxExecutionRequest> {
|
|
112
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
113
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
114
|
+
txNonce: Fr.random(),
|
|
115
|
+
cancellable: this.cancellableTransactions,
|
|
116
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
117
|
+
};
|
|
118
|
+
const finalExecutionPayload = feeExecutionPayload
|
|
119
|
+
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
120
|
+
: executionPayload;
|
|
121
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
122
|
+
return fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, executionOptions);
|
|
58
123
|
}
|
|
59
|
-
|
|
60
|
-
|
|
124
|
+
|
|
125
|
+
public async createAuthWit(
|
|
126
|
+
from: AztecAddress,
|
|
127
|
+
messageHashOrIntent: Fr | Buffer | IntentInnerHash | CallIntent,
|
|
128
|
+
): Promise<AuthWitness> {
|
|
129
|
+
const account = await this.getAccountFromAddress(from);
|
|
130
|
+
return account.createAuthWit(messageHashOrIntent);
|
|
61
131
|
}
|
|
62
|
-
|
|
63
|
-
|
|
132
|
+
|
|
133
|
+
public async batch<const T extends readonly BatchedMethod<keyof BatchableMethods>[]>(
|
|
134
|
+
methods: T,
|
|
135
|
+
): Promise<BatchResults<T>> {
|
|
136
|
+
const results: any[] = [];
|
|
137
|
+
for (const method of methods) {
|
|
138
|
+
const { name, args } = method;
|
|
139
|
+
// Type safety is guaranteed by the BatchedMethod type, which ensures that:
|
|
140
|
+
// 1. `name` is a valid batchable method name
|
|
141
|
+
// 2. `args` matches the parameter types of that specific method
|
|
142
|
+
// 3. The return type is correctly mapped in BatchResults<T>
|
|
143
|
+
// We use dynamic dispatch here for simplicity, but the types are enforced at the call site.
|
|
144
|
+
|
|
145
|
+
const fn = this[name] as (...args: any[]) => Promise<any>;
|
|
146
|
+
const result = await fn.apply(this, args);
|
|
147
|
+
// Wrap result with method name for discriminated union deserialization
|
|
148
|
+
results.push({ name, result });
|
|
149
|
+
}
|
|
150
|
+
return results as BatchResults<T>;
|
|
64
151
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Returns default values for the transaction fee options
|
|
155
|
+
* if they were omitted by the user.
|
|
156
|
+
* @param from - The address where the transaction is being sent from
|
|
157
|
+
* @param userFeeOptions - User-provided fee options, which might be incomplete
|
|
158
|
+
* @returns - Populated fee options that can be used to create a transaction execution request
|
|
159
|
+
*/
|
|
160
|
+
protected async getDefaultFeeOptions(from: AztecAddress, userFeeOptions?: UserFeeOptions): Promise<FeeOptions> {
|
|
161
|
+
const maxFeesPerGas =
|
|
162
|
+
userFeeOptions?.gasSettings?.maxFeesPerGas ??
|
|
163
|
+
(await this.aztecNode.getCurrentBaseFees()).mul(1 + this.baseFeePadding);
|
|
164
|
+
let accountFeePaymentMethodOptions;
|
|
165
|
+
// The transaction does not include a fee payment method, so we set the flag
|
|
166
|
+
// for the account to use its fee juice balance
|
|
167
|
+
if (!userFeeOptions?.embeddedPaymentMethodFeePayer) {
|
|
168
|
+
accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
|
|
169
|
+
} else {
|
|
170
|
+
// The transaction includes fee payment method, so we check if we are the fee payer for it
|
|
171
|
+
// (this can only happen if the embedded payment method is FeeJuiceWithClaim)
|
|
172
|
+
accountFeePaymentMethodOptions = from.equals(userFeeOptions.embeddedPaymentMethodFeePayer)
|
|
173
|
+
? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM
|
|
174
|
+
: AccountFeePaymentMethodOptions.EXTERNAL;
|
|
175
|
+
}
|
|
176
|
+
const gasSettings: GasSettings = GasSettings.default({ ...userFeeOptions?.gasSettings, maxFeesPerGas });
|
|
177
|
+
this.log.debug(`Using L2 gas settings`, gasSettings);
|
|
178
|
+
return {
|
|
179
|
+
gasSettings,
|
|
180
|
+
walletFeePaymentMethod: undefined,
|
|
181
|
+
accountFeePaymentMethodOptions,
|
|
182
|
+
};
|
|
70
183
|
}
|
|
71
|
-
|
|
72
|
-
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Returns unreasonably high gas limits in order to execute a simulation
|
|
187
|
+
* with the goal of estimating its gas cost. It will otherwise try to respect
|
|
188
|
+
* the user-specified fee options, filling the gaps with default values as needed.
|
|
189
|
+
* @param from - The address where the transaction is being sent from
|
|
190
|
+
* @param userFeeOptions - User-provided fee options to use as a basis for the fully populated `FeeOptions` type.
|
|
191
|
+
*/
|
|
192
|
+
protected async getFeeOptionsForGasEstimation(from: AztecAddress, userFeeOptions?: UserFeeOptions) {
|
|
193
|
+
const defaultFeeOptions = await this.getDefaultFeeOptions(from, userFeeOptions);
|
|
194
|
+
const {
|
|
195
|
+
gasSettings: { maxFeesPerGas, maxPriorityFeesPerGas },
|
|
196
|
+
} = defaultFeeOptions;
|
|
197
|
+
// Use unrealistically high gas limits for estimation to avoid running out of gas.
|
|
198
|
+
// They will be tuned down after the simulation.
|
|
199
|
+
const gasSettingsForEstimation = new GasSettings(
|
|
200
|
+
new Gas(GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT),
|
|
201
|
+
new Gas(GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT),
|
|
202
|
+
maxFeesPerGas,
|
|
203
|
+
maxPriorityFeesPerGas,
|
|
204
|
+
);
|
|
205
|
+
return {
|
|
206
|
+
...defaultFeeOptions,
|
|
207
|
+
gasSettings: gasSettingsForEstimation,
|
|
208
|
+
};
|
|
73
209
|
}
|
|
74
|
-
|
|
75
|
-
|
|
210
|
+
|
|
211
|
+
registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
212
|
+
return this.pxe.registerSender(address);
|
|
76
213
|
}
|
|
77
|
-
|
|
78
|
-
|
|
214
|
+
|
|
215
|
+
async registerContract(
|
|
216
|
+
instanceData: AztecAddress | ContractInstanceWithAddress | ContractInstantiationData | ContractInstanceAndArtifact,
|
|
217
|
+
artifact?: ContractArtifact,
|
|
218
|
+
secretKey?: Fr,
|
|
219
|
+
): Promise<ContractInstanceWithAddress> {
|
|
220
|
+
/** Determines if the provided instance data is already a contract instance with an address. */
|
|
221
|
+
function isInstanceWithAddress(instanceData: any): instanceData is ContractInstanceWithAddress {
|
|
222
|
+
return (instanceData as ContractInstanceWithAddress).address !== undefined;
|
|
223
|
+
}
|
|
224
|
+
/** Determines if the provided instance data is contract instantiation data */
|
|
225
|
+
function isContractInstantiationData(instanceData: any): instanceData is ContractInstantiationData {
|
|
226
|
+
return (instanceData as ContractInstantiationData).salt !== undefined;
|
|
227
|
+
}
|
|
228
|
+
/** Determines if the provided instance data is already a contract */
|
|
229
|
+
function isContractInstanceAndArtifact(instanceData: any): instanceData is ContractInstanceAndArtifact {
|
|
230
|
+
return (
|
|
231
|
+
(instanceData as ContractInstanceAndArtifact).instance !== undefined &&
|
|
232
|
+
(instanceData as ContractInstanceAndArtifact).artifact !== undefined
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
let instance: ContractInstanceWithAddress;
|
|
236
|
+
if (isContractInstanceAndArtifact(instanceData)) {
|
|
237
|
+
instance = instanceData.instance;
|
|
238
|
+
await this.pxe.registerContract(instanceData);
|
|
239
|
+
} else if (isInstanceWithAddress(instanceData)) {
|
|
240
|
+
instance = instanceData;
|
|
241
|
+
await this.pxe.registerContract({ artifact, instance });
|
|
242
|
+
} else if (isContractInstantiationData(instanceData)) {
|
|
243
|
+
if (!artifact) {
|
|
244
|
+
throw new Error(`Contract artifact must be provided when registering a contract using instantiation data`);
|
|
245
|
+
}
|
|
246
|
+
instance = await getContractInstanceFromInstantiationParams(artifact, instanceData);
|
|
247
|
+
await this.pxe.registerContract({ artifact, instance });
|
|
248
|
+
} else {
|
|
249
|
+
if (!artifact) {
|
|
250
|
+
throw new Error(`Contract artifact must be provided when registering a contract using an address`);
|
|
251
|
+
}
|
|
252
|
+
const { contractInstance: maybeContractInstance } = await this.pxe.getContractMetadata(instanceData);
|
|
253
|
+
if (!maybeContractInstance) {
|
|
254
|
+
throw new Error(`Contract instance at ${instanceData.toString()} has not been registered in the wallet's PXE`);
|
|
255
|
+
}
|
|
256
|
+
instance = maybeContractInstance;
|
|
257
|
+
const thisContractClass = await getContractClassFromArtifact(artifact);
|
|
258
|
+
if (!thisContractClass.id.equals(instance.currentContractClassId)) {
|
|
259
|
+
// wallet holds an outdated version of this contract
|
|
260
|
+
await this.pxe.updateContract(instance.address, artifact);
|
|
261
|
+
instance.currentContractClassId = thisContractClass.id;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (secretKey) {
|
|
265
|
+
await this.pxe.registerAccount(secretKey, await computePartialAddress(instance));
|
|
266
|
+
}
|
|
267
|
+
return instance;
|
|
79
268
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return this.pxe.
|
|
269
|
+
|
|
270
|
+
async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
|
|
271
|
+
const feeOptions = opts.fee?.estimateGas
|
|
272
|
+
? await this.getFeeOptionsForGasEstimation(opts.from, opts.fee)
|
|
273
|
+
: await this.getDefaultFeeOptions(opts.from, opts.fee);
|
|
274
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
275
|
+
return this.pxe.simulateTx(
|
|
276
|
+
txRequest,
|
|
277
|
+
true /* simulatePublic */,
|
|
278
|
+
opts?.skipTxValidation,
|
|
279
|
+
opts?.skipFeeEnforcement ?? true,
|
|
280
|
+
);
|
|
87
281
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
overrides?: SimulationOverrides,
|
|
94
|
-
): Promise<TxSimulationResult> {
|
|
95
|
-
return this.pxe.simulateTx(txRequest, simulatePublic, skipTxValidation, skipFeeEnforcement, overrides);
|
|
282
|
+
|
|
283
|
+
async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
284
|
+
const fee = await this.getDefaultFeeOptions(opts.from, opts.fee);
|
|
285
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, fee);
|
|
286
|
+
return this.pxe.profileTx(txRequest, opts.profileMode, opts.skipProofGeneration ?? true);
|
|
96
287
|
}
|
|
97
|
-
|
|
98
|
-
|
|
288
|
+
|
|
289
|
+
async sendTx(executionPayload: ExecutionPayload, opts: SendOptions): Promise<TxHash> {
|
|
290
|
+
const fee = await this.getDefaultFeeOptions(opts.from, opts.fee);
|
|
291
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, fee);
|
|
292
|
+
const provenTx = await this.pxe.proveTx(txRequest);
|
|
293
|
+
const tx = await provenTx.toTx();
|
|
294
|
+
const txHash = tx.getTxHash();
|
|
295
|
+
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
296
|
+
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
|
|
297
|
+
}
|
|
298
|
+
this.log.debug(`Sending transaction ${txHash}`);
|
|
299
|
+
await this.aztecNode.sendTx(tx).catch(err => {
|
|
300
|
+
throw this.contextualizeError(err, inspect(tx));
|
|
301
|
+
});
|
|
302
|
+
this.log.info(`Sent transaction ${txHash}`);
|
|
303
|
+
return txHash;
|
|
99
304
|
}
|
|
100
|
-
|
|
101
|
-
|
|
305
|
+
|
|
306
|
+
protected contextualizeError(err: Error, ...context: string[]): Error {
|
|
307
|
+
let contextStr = '';
|
|
308
|
+
if (context.length > 0) {
|
|
309
|
+
contextStr = `\nContext:\n${context.join('\n')}`;
|
|
310
|
+
}
|
|
311
|
+
if (err instanceof SimulationError) {
|
|
312
|
+
err.setAztecContext(contextStr);
|
|
313
|
+
} else {
|
|
314
|
+
this.log.error(err.name, err);
|
|
315
|
+
this.log.debug(contextStr);
|
|
316
|
+
}
|
|
317
|
+
return err;
|
|
102
318
|
}
|
|
319
|
+
|
|
103
320
|
simulateUtility(
|
|
104
321
|
functionName: string,
|
|
105
322
|
args: any[],
|
|
@@ -109,12 +326,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
109
326
|
): Promise<UtilitySimulationResult> {
|
|
110
327
|
return this.pxe.simulateUtility(functionName, args, to, authwits, from);
|
|
111
328
|
}
|
|
112
|
-
|
|
113
|
-
return this.pxe.getNodeInfo();
|
|
114
|
-
}
|
|
115
|
-
getPXEInfo(): Promise<PXEInfo> {
|
|
116
|
-
return this.pxe.getPXEInfo();
|
|
117
|
-
}
|
|
329
|
+
|
|
118
330
|
getContractClassMetadata(id: Fr, includeArtifact: boolean = false): Promise<ContractClassMetadata> {
|
|
119
331
|
return this.pxe.getContractClassMetadata(id, includeArtifact);
|
|
120
332
|
}
|
|
@@ -123,7 +335,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
123
335
|
}
|
|
124
336
|
|
|
125
337
|
getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
126
|
-
return this.
|
|
338
|
+
return this.aztecNode.getTxReceipt(txHash);
|
|
127
339
|
}
|
|
128
340
|
|
|
129
341
|
getPrivateEvents<T>(
|
|
@@ -131,11 +343,8 @@ export abstract class BaseWallet implements Wallet {
|
|
|
131
343
|
event: EventMetadataDefinition,
|
|
132
344
|
from: number,
|
|
133
345
|
limit: number,
|
|
134
|
-
recipients: AztecAddress[] = [
|
|
346
|
+
recipients: AztecAddress[] = [],
|
|
135
347
|
): Promise<T[]> {
|
|
136
348
|
return this.pxe.getPrivateEvents(contractAddress, event, from, limit, recipients);
|
|
137
349
|
}
|
|
138
|
-
getPublicEvents<T>(event: EventMetadataDefinition, from: number, limit: number): Promise<T[]> {
|
|
139
|
-
return this.pxe.getPublicEvents(event, from, limit);
|
|
140
|
-
}
|
|
141
350
|
}
|