@aztec/cli-wallet 2.1.0-rc.9 → 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/README.md +30 -0
- package/dest/bin/index.js +28 -22
- package/dest/cmds/authorize_action.d.ts +3 -2
- package/dest/cmds/authorize_action.d.ts.map +1 -1
- package/dest/cmds/authorize_action.js +5 -6
- package/dest/cmds/bridge_fee_juice.d.ts +2 -2
- package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
- package/dest/cmds/bridge_fee_juice.js +6 -5
- package/dest/cmds/check_tx.d.ts +4 -2
- package/dest/cmds/check_tx.d.ts.map +1 -1
- package/dest/cmds/check_tx.js +145 -6
- package/dest/cmds/create_account.d.ts +5 -4
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +35 -47
- package/dest/cmds/create_authwit.d.ts +3 -2
- package/dest/cmds/create_authwit.d.ts.map +1 -1
- package/dest/cmds/create_authwit.js +5 -5
- package/dest/cmds/deploy.d.ts +6 -3
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +57 -46
- package/dest/cmds/deploy_account.d.ts +5 -7
- package/dest/cmds/deploy_account.d.ts.map +1 -1
- package/dest/cmds/deploy_account.js +36 -51
- package/dest/cmds/import_test_accounts.d.ts +2 -2
- package/dest/cmds/import_test_accounts.d.ts.map +1 -1
- package/dest/cmds/import_test_accounts.js +6 -9
- package/dest/cmds/index.d.ts +2 -2
- package/dest/cmds/index.d.ts.map +1 -1
- package/dest/cmds/index.js +73 -112
- package/dest/cmds/profile.d.ts +6 -3
- package/dest/cmds/profile.d.ts.map +1 -1
- package/dest/cmds/profile.js +8 -3
- package/dest/cmds/register_contract.d.ts +6 -2
- package/dest/cmds/register_contract.d.ts.map +1 -1
- package/dest/cmds/register_contract.js +5 -6
- package/dest/cmds/register_sender.d.ts +3 -2
- package/dest/cmds/register_sender.d.ts.map +1 -1
- package/dest/cmds/send.d.ts +7 -8
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +26 -23
- package/dest/cmds/simulate.d.ts +6 -3
- package/dest/cmds/simulate.d.ts.map +1 -1
- package/dest/cmds/simulate.js +8 -3
- package/dest/storage/wallet_db.d.ts +2 -12
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +1 -22
- package/dest/utils/authorizations.d.ts +2 -1
- package/dest/utils/authorizations.d.ts.map +1 -1
- package/dest/utils/authorizations.js +1 -1
- package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
- package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
- package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
- package/dest/utils/options/fees.d.ts +20 -27
- package/dest/utils/options/fees.d.ts.map +1 -1
- package/dest/utils/options/fees.js +65 -132
- package/dest/utils/options/options.d.ts +2 -1
- package/dest/utils/options/options.d.ts.map +1 -1
- package/dest/utils/options/options.js +1 -1
- package/dest/utils/wallet.d.ts +35 -0
- package/dest/utils/wallet.d.ts.map +1 -0
- package/dest/utils/wallet.js +193 -0
- package/package.json +12 -12
- package/src/bin/index.ts +30 -29
- package/src/cmds/authorize_action.ts +13 -5
- package/src/cmds/bridge_fee_juice.ts +12 -9
- package/src/cmds/check_tx.ts +182 -5
- package/src/cmds/create_account.ts +42 -52
- package/src/cmds/create_authwit.ts +8 -4
- package/src/cmds/deploy.ts +58 -56
- package/src/cmds/deploy_account.ts +43 -51
- package/src/cmds/import_test_accounts.ts +7 -11
- package/src/cmds/index.ts +120 -206
- package/src/cmds/profile.ts +13 -5
- package/src/cmds/register_contract.ts +9 -11
- package/src/cmds/register_sender.ts +3 -2
- package/src/cmds/send.ts +21 -31
- package/src/cmds/simulate.ts +13 -5
- package/src/storage/wallet_db.ts +2 -30
- package/src/utils/authorizations.ts +3 -1
- package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
- package/src/utils/options/fees.ts +86 -177
- package/src/utils/options/options.ts +3 -2
- package/src/utils/wallet.ts +264 -0
- package/dest/cmds/cancel_tx.d.ts +0 -11
- package/dest/cmds/cancel_tx.d.ts.map +0 -1
- package/dest/cmds/cancel_tx.js +0 -43
- package/dest/utils/accounts.d.ts +0 -9
- package/dest/utils/accounts.d.ts.map +0 -1
- package/dest/utils/accounts.js +0 -61
- package/dest/utils/pxe_wrapper.d.ts +0 -12
- package/dest/utils/pxe_wrapper.d.ts.map +0 -1
- package/dest/utils/pxe_wrapper.js +0 -26
- package/src/cmds/cancel_tx.ts +0 -66
- package/src/utils/accounts.ts +0 -77
- package/src/utils/pxe_wrapper.ts +0 -32
|
@@ -1,24 +1,29 @@
|
|
|
1
|
-
import { AztecAddress
|
|
1
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
3
|
+
import type { DeployAccountOptions } from '@aztec/aztec.js/wallet';
|
|
2
4
|
import { prettyPrintJSON } from '@aztec/cli/cli-utils';
|
|
3
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
6
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
5
7
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
+
import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
9
|
+
import { CLIFeeArgs } from '../utils/options/fees.js';
|
|
8
10
|
import { printProfileResult } from '../utils/profiling.js';
|
|
9
|
-
import {
|
|
11
|
+
import { type AccountType, CLIWallet } from '../utils/wallet.js';
|
|
10
12
|
|
|
11
13
|
export async function createAccount(
|
|
12
|
-
|
|
14
|
+
wallet: CLIWallet,
|
|
15
|
+
aztecNode: AztecNode,
|
|
13
16
|
accountType: AccountType,
|
|
14
17
|
secretKey: Fr | undefined,
|
|
15
18
|
publicKey: string | undefined,
|
|
16
19
|
alias: string | undefined,
|
|
20
|
+
deployer: AztecAddress | undefined,
|
|
17
21
|
registerOnly: boolean,
|
|
18
|
-
publicDeploy: boolean,
|
|
19
22
|
skipInitialization: boolean,
|
|
23
|
+
publicDeploy: boolean,
|
|
24
|
+
registerClass: boolean,
|
|
20
25
|
wait: boolean,
|
|
21
|
-
feeOpts:
|
|
26
|
+
feeOpts: CLIFeeArgs,
|
|
22
27
|
json: boolean,
|
|
23
28
|
verbose: boolean,
|
|
24
29
|
debugLogger: Logger,
|
|
@@ -26,10 +31,8 @@ export async function createAccount(
|
|
|
26
31
|
) {
|
|
27
32
|
secretKey ??= Fr.random();
|
|
28
33
|
|
|
29
|
-
const account = await createOrRetrieveAccount(
|
|
30
|
-
client,
|
|
34
|
+
const account = await wallet.createOrRetrieveAccount(
|
|
31
35
|
undefined /* address, we don't have it yet */,
|
|
32
|
-
undefined /* db, as we want to create from scratch */,
|
|
33
36
|
secretKey,
|
|
34
37
|
accountType,
|
|
35
38
|
Fr.ZERO,
|
|
@@ -48,7 +51,6 @@ export async function createAccount(
|
|
|
48
51
|
out.partialAddress = partialAddress;
|
|
49
52
|
out.salt = salt;
|
|
50
53
|
out.initHash = account.getInstance().initializationHash;
|
|
51
|
-
out.deployer = account.getInstance().deployer;
|
|
52
54
|
} else {
|
|
53
55
|
log(`\nNew account:\n`);
|
|
54
56
|
log(`Address: ${address.toString()}`);
|
|
@@ -59,68 +61,56 @@ export async function createAccount(
|
|
|
59
61
|
log(`Partial address: ${partialAddress.toString()}`);
|
|
60
62
|
log(`Salt: ${salt.toString()}`);
|
|
61
63
|
log(`Init hash: ${account.getInstance().initializationHash.toString()}`);
|
|
62
|
-
log(`Deployer: ${account.getInstance().deployer.toString()}`);
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
let tx;
|
|
66
67
|
let txReceipt;
|
|
67
|
-
if (registerOnly) {
|
|
68
|
-
await
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
68
|
+
if (!registerOnly) {
|
|
69
|
+
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
|
|
70
|
+
|
|
71
|
+
const delegatedDeployment = deployer && !account.address.equals(deployer);
|
|
72
|
+
const from = delegatedDeployment ? deployer : AztecAddress.ZERO;
|
|
73
|
+
|
|
74
|
+
const deployAccountOpts: DeployAccountOptions = {
|
|
75
|
+
skipClassPublication: !registerClass,
|
|
73
76
|
skipInstancePublication: !publicDeploy,
|
|
74
|
-
skipInitialization
|
|
75
|
-
|
|
77
|
+
skipInitialization,
|
|
78
|
+
from,
|
|
79
|
+
fee: { paymentMethod, gasSettings },
|
|
76
80
|
};
|
|
77
|
-
/*
|
|
78
|
-
* This is usually handled by accountManager.create(), but we're accessing the lower
|
|
79
|
-
* level method to get gas and timings. That means we have to replicate some of the logic here.
|
|
80
|
-
* In case we're initializing and/or publishing our own account, we need to hijack the payment method for the fee,
|
|
81
|
-
* wrapping it in the one that will make use of the freshly deployed account's
|
|
82
|
-
* entrypoint. For reference, see aztec.js/src/account_manager.ts:sendAccountContractSetupTx()
|
|
83
|
-
* Also, salt and universalDeploy have to be explicitly provided
|
|
84
|
-
*/
|
|
85
|
-
deployOpts.fee =
|
|
86
|
-
!deployOpts?.deployWallet && deployOpts?.fee
|
|
87
|
-
? { ...deployOpts.fee, paymentMethod: await account.getSelfPaymentMethod(deployOpts.fee.paymentMethod) }
|
|
88
|
-
: deployOpts?.fee;
|
|
89
81
|
|
|
90
|
-
const deployMethod = await account.getDeployMethod(
|
|
82
|
+
const deployMethod = await account.getDeployMethod();
|
|
83
|
+
const { estimatedGas, stats } = await deployMethod.simulate({
|
|
84
|
+
...deployAccountOpts,
|
|
85
|
+
fee: { ...deployAccountOpts.fee, estimateGas: true },
|
|
86
|
+
});
|
|
91
87
|
|
|
92
88
|
if (feeOpts.estimateOnly) {
|
|
93
|
-
const gas = await deployMethod.estimateGas({
|
|
94
|
-
...deployOpts,
|
|
95
|
-
from: AztecAddress.ZERO,
|
|
96
|
-
universalDeploy: true,
|
|
97
|
-
contractAddressSalt: salt,
|
|
98
|
-
});
|
|
99
89
|
if (json) {
|
|
100
90
|
out.fee = {
|
|
101
91
|
gasLimits: {
|
|
102
|
-
da:
|
|
103
|
-
l2:
|
|
92
|
+
da: estimatedGas.gasLimits.daGas,
|
|
93
|
+
l2: estimatedGas.gasLimits.l2Gas,
|
|
104
94
|
},
|
|
105
95
|
teardownGasLimits: {
|
|
106
|
-
da:
|
|
107
|
-
l2:
|
|
96
|
+
da: estimatedGas.teardownGasLimits.daGas,
|
|
97
|
+
l2: estimatedGas.teardownGasLimits,
|
|
108
98
|
},
|
|
109
99
|
};
|
|
110
|
-
} else {
|
|
111
|
-
printGasEstimates(feeOpts, gas, log);
|
|
112
100
|
}
|
|
113
101
|
} else {
|
|
114
|
-
|
|
115
|
-
...
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
102
|
+
tx = deployMethod.send({
|
|
103
|
+
...deployAccountOpts,
|
|
104
|
+
fee: deployAccountOpts.fee
|
|
105
|
+
? {
|
|
106
|
+
...deployAccountOpts.fee,
|
|
107
|
+
gasSettings: estimatedGas,
|
|
108
|
+
}
|
|
109
|
+
: undefined,
|
|
119
110
|
});
|
|
120
111
|
if (verbose) {
|
|
121
|
-
printProfileResult(
|
|
112
|
+
printProfileResult(stats, log);
|
|
122
113
|
}
|
|
123
|
-
tx = provenTx.send();
|
|
124
114
|
|
|
125
115
|
const txHash = await tx.getTxHash();
|
|
126
116
|
debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { Contract } from '@aztec/aztec.js/contracts';
|
|
2
3
|
import { prepTx } from '@aztec/cli/utils';
|
|
3
4
|
import type { LogFn } from '@aztec/foundation/log';
|
|
4
5
|
|
|
6
|
+
import type { CLIWallet } from '../utils/wallet.js';
|
|
7
|
+
|
|
5
8
|
export async function createAuthwit(
|
|
6
|
-
wallet:
|
|
9
|
+
wallet: CLIWallet,
|
|
10
|
+
from: AztecAddress,
|
|
7
11
|
functionName: string,
|
|
8
12
|
caller: AztecAddress,
|
|
9
13
|
functionArgsIn: any[],
|
|
@@ -25,9 +29,9 @@ export async function createAuthwit(
|
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
const contract = await Contract.at(contractAddress, contractArtifact, wallet);
|
|
28
|
-
const
|
|
32
|
+
const call = await contract.methods[functionName](...functionArgs).getFunctionCall();
|
|
29
33
|
|
|
30
|
-
const witness = await wallet.createAuthWit({ caller,
|
|
34
|
+
const witness = await wallet.createAuthWit(from, { caller, call });
|
|
31
35
|
|
|
32
36
|
log(`Created authorization witness for action ${functionName} on contract ${contractAddress} for caller ${caller}`);
|
|
33
37
|
|
package/src/cmds/deploy.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '@aztec/aztec.js';
|
|
8
|
-
import { encodeArgs, getContractArtifact } from '@aztec/cli/utils';
|
|
1
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import type { DeployOptions } from '@aztec/aztec.js/contracts';
|
|
3
|
+
import { ContractDeployer } from '@aztec/aztec.js/deployment';
|
|
4
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
5
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
6
|
+
import { encodeArgs, getContractArtifact, prettyPrintJSON } from '@aztec/cli/utils';
|
|
9
7
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
10
8
|
import { getAllFunctionAbis, getInitializer } from '@aztec/stdlib/abi';
|
|
11
9
|
import { PublicKeys } from '@aztec/stdlib/keys';
|
|
12
10
|
|
|
13
|
-
import {
|
|
11
|
+
import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
12
|
+
import { CLIFeeArgs } from '../utils/options/fees.js';
|
|
14
13
|
import { printProfileResult } from '../utils/profiling.js';
|
|
15
|
-
import {
|
|
14
|
+
import type { CLIWallet } from '../utils/wallet.js';
|
|
16
15
|
|
|
17
16
|
export async function deploy(
|
|
18
|
-
wallet:
|
|
19
|
-
|
|
17
|
+
wallet: CLIWallet,
|
|
18
|
+
node: AztecNode,
|
|
19
|
+
deployer: AztecAddress,
|
|
20
20
|
artifactPath: string,
|
|
21
21
|
json: boolean,
|
|
22
22
|
publicKeys: PublicKeys | undefined,
|
|
@@ -27,13 +27,13 @@ export async function deploy(
|
|
|
27
27
|
skipClassPublication: boolean,
|
|
28
28
|
skipInitialization: boolean | undefined,
|
|
29
29
|
wait: boolean,
|
|
30
|
-
feeOpts:
|
|
30
|
+
feeOpts: CLIFeeArgs,
|
|
31
31
|
verbose: boolean,
|
|
32
32
|
timeout: number = DEFAULT_TX_TIMEOUT_S,
|
|
33
33
|
debugLogger: Logger,
|
|
34
34
|
log: LogFn,
|
|
35
|
-
logJson: (output: any) => void,
|
|
36
35
|
) {
|
|
36
|
+
const out: Record<string, any> = {};
|
|
37
37
|
salt ??= Fr.random();
|
|
38
38
|
const contractArtifact = await getContractArtifact(artifactPath, log);
|
|
39
39
|
const hasInitializer = getAllFunctionAbis(contractArtifact).some(fn => fn.isInitializer);
|
|
@@ -59,8 +59,9 @@ export async function deploy(
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
const deploy = contractDeployer.deploy(...args);
|
|
62
|
+
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, deployer);
|
|
62
63
|
const deployOpts: DeployOptions = {
|
|
63
|
-
|
|
64
|
+
fee: { gasSettings, paymentMethod },
|
|
64
65
|
from: deployer ?? AztecAddress.ZERO,
|
|
65
66
|
contractAddressSalt: salt,
|
|
66
67
|
universalDeploy: !deployer,
|
|
@@ -69,60 +70,61 @@ export async function deploy(
|
|
|
69
70
|
skipInstancePublication,
|
|
70
71
|
};
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const provenTx = await deploy.prove(deployOpts);
|
|
79
|
-
if (verbose) {
|
|
80
|
-
printProfileResult(provenTx.stats!, log);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const tx = provenTx.send();
|
|
73
|
+
const { estimatedGas, stats } = await deploy.simulate({
|
|
74
|
+
...deployOpts,
|
|
75
|
+
fee: { ...deployOpts.fee, estimateGas: true },
|
|
76
|
+
});
|
|
84
77
|
|
|
85
|
-
|
|
86
|
-
debugLogger.debug(`Deploy tx sent with hash ${txHash.toString()}`);
|
|
87
|
-
if (wait) {
|
|
88
|
-
const deployed = await tx.wait({ timeout });
|
|
89
|
-
const { address, partialAddress, instance } = deployed.contract;
|
|
78
|
+
if (feeOpts.estimateOnly) {
|
|
90
79
|
if (json) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
log(`Contract init hash ${instance.initializationHash.toString()}`);
|
|
102
|
-
log(`Deployment tx hash: ${txHash.toString()}`);
|
|
103
|
-
log(`Deployment salt: ${salt.toString()}`);
|
|
104
|
-
log(`Deployment fee: ${deployed.transactionFee}`);
|
|
80
|
+
out.fee = {
|
|
81
|
+
gasLimits: {
|
|
82
|
+
da: estimatedGas.gasLimits.daGas,
|
|
83
|
+
l2: estimatedGas.gasLimits.l2Gas,
|
|
84
|
+
},
|
|
85
|
+
teardownGasLimits: {
|
|
86
|
+
da: estimatedGas.teardownGasLimits.daGas,
|
|
87
|
+
l2: estimatedGas.teardownGasLimits,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
105
90
|
}
|
|
106
91
|
} else {
|
|
92
|
+
const tx = deploy.send(deployOpts);
|
|
93
|
+
if (verbose) {
|
|
94
|
+
printProfileResult(stats, log);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const txHash = await tx.getTxHash();
|
|
98
|
+
debugLogger.debug(`Deploy tx sent with hash ${txHash.toString()}`);
|
|
99
|
+
out.hash = txHash;
|
|
107
100
|
const { address, partialAddress } = deploy;
|
|
108
101
|
const instance = await deploy.getInstance();
|
|
109
|
-
if (json) {
|
|
110
|
-
logJson({
|
|
111
|
-
address: address?.toString() ?? 'N/A',
|
|
112
|
-
partialAddress: (await partialAddress)?.toString() ?? 'N/A',
|
|
113
|
-
txHash: txHash.toString(),
|
|
114
|
-
initializationHash: instance.initializationHash.toString(),
|
|
115
|
-
salt: salt.toString(),
|
|
116
|
-
deployer: instance.deployer.toString(),
|
|
117
|
-
});
|
|
118
|
-
} else {
|
|
102
|
+
if (!json) {
|
|
119
103
|
log(`Contract deployed at ${address?.toString()}`);
|
|
120
104
|
log(`Contract partial address ${(await partialAddress)?.toString()}`);
|
|
121
105
|
log(`Contract init hash ${instance.initializationHash.toString()}`);
|
|
122
106
|
log(`Deployment tx hash: ${txHash.toString()}`);
|
|
123
107
|
log(`Deployment salt: ${salt.toString()}`);
|
|
124
108
|
log(`Deployer: ${instance.deployer.toString()}`);
|
|
109
|
+
} else {
|
|
110
|
+
out.contract = {
|
|
111
|
+
address: address?.toString(),
|
|
112
|
+
partialAddress: (await partialAddress)?.toString(),
|
|
113
|
+
initializationHash: instance.initializationHash.toString(),
|
|
114
|
+
salt: salt.toString(),
|
|
115
|
+
};
|
|
125
116
|
}
|
|
117
|
+
if (wait) {
|
|
118
|
+
const deployed = await tx.wait({ timeout });
|
|
119
|
+
if (!json) {
|
|
120
|
+
log(`Transaction fee: ${deployed.transactionFee?.toString()}`);
|
|
121
|
+
} else {
|
|
122
|
+
out.contract.transactionFee = deployed.transactionFee?.toString();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (json) {
|
|
127
|
+
log(prettyPrintJSON(out));
|
|
126
128
|
}
|
|
127
129
|
return deploy.address;
|
|
128
130
|
}
|
|
@@ -1,27 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
3
|
+
import type { DeployAccountOptions } from '@aztec/aztec.js/wallet';
|
|
2
4
|
import { prettyPrintJSON } from '@aztec/cli/cli-utils';
|
|
3
5
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
4
6
|
|
|
5
|
-
import {
|
|
7
|
+
import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
8
|
+
import type { CLIFeeArgs } from '../utils/options/fees.js';
|
|
6
9
|
import { printProfileResult } from '../utils/profiling.js';
|
|
7
|
-
import {
|
|
10
|
+
import type { CLIWallet } from '../utils/wallet.js';
|
|
8
11
|
|
|
9
12
|
export async function deployAccount(
|
|
10
|
-
|
|
13
|
+
wallet: CLIWallet,
|
|
14
|
+
aztecNode: AztecNode,
|
|
15
|
+
address: AztecAddress,
|
|
11
16
|
wait: boolean,
|
|
17
|
+
deployer: AztecAddress | undefined,
|
|
12
18
|
registerClass: boolean,
|
|
13
19
|
publicDeploy: boolean,
|
|
14
|
-
|
|
20
|
+
skipInitialization: boolean,
|
|
21
|
+
feeOpts: CLIFeeArgs,
|
|
15
22
|
json: boolean,
|
|
16
23
|
verbose: boolean,
|
|
17
24
|
debugLogger: Logger,
|
|
18
25
|
log: LogFn,
|
|
19
26
|
) {
|
|
20
27
|
const out: Record<string, any> = {};
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
28
|
+
|
|
29
|
+
const account = await wallet.createOrRetrieveAccount(address);
|
|
30
|
+
const { partialAddress, publicKeys } = await account.getCompleteAddress();
|
|
31
|
+
const { initializationHash, salt } = account.getInstance();
|
|
25
32
|
|
|
26
33
|
if (json) {
|
|
27
34
|
out.address = address;
|
|
@@ -33,71 +40,58 @@ export async function deployAccount(
|
|
|
33
40
|
log(`\nNew account:\n`);
|
|
34
41
|
log(`Address: ${address.toString()}`);
|
|
35
42
|
log(`Public key: ${publicKeys.toString()}`);
|
|
36
|
-
if (secretKey) {
|
|
37
|
-
log(`Secret key: ${secretKey.toString()}`);
|
|
38
|
-
}
|
|
39
43
|
log(`Partial address: ${partialAddress.toString()}`);
|
|
40
44
|
log(`Salt: ${salt.toString()}`);
|
|
41
45
|
log(`Init hash: ${initializationHash.toString()}`);
|
|
42
|
-
log(`Deployer: ${deployer.toString()}`);
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
let tx;
|
|
46
49
|
let txReceipt;
|
|
50
|
+
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
|
|
47
51
|
|
|
48
|
-
const
|
|
49
|
-
|
|
52
|
+
const delegatedDeployment = deployer && !account.address.equals(deployer);
|
|
53
|
+
const from = delegatedDeployment ? deployer : AztecAddress.ZERO;
|
|
54
|
+
|
|
55
|
+
const deployAccountOpts: DeployAccountOptions = {
|
|
50
56
|
skipClassPublication: !registerClass,
|
|
51
|
-
|
|
57
|
+
skipInstancePublication: !publicDeploy,
|
|
58
|
+
skipInitialization,
|
|
59
|
+
from,
|
|
60
|
+
fee: { paymentMethod, gasSettings },
|
|
52
61
|
};
|
|
53
62
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* entrypoint. For reference, see aztec.js/src/account_manager.ts:deploy()
|
|
60
|
-
* Also, salt and universalDeploy have to be explicitly provided
|
|
61
|
-
*/
|
|
62
|
-
deployOpts.fee =
|
|
63
|
-
!deployOpts?.deployWallet && deployOpts?.fee
|
|
64
|
-
? { ...deployOpts.fee, paymentMethod: await account.getSelfPaymentMethod(deployOpts.fee.paymentMethod) }
|
|
65
|
-
: deployOpts?.fee;
|
|
66
|
-
|
|
67
|
-
const deployMethod = await account.getDeployMethod(deployOpts.deployWallet);
|
|
63
|
+
const deployMethod = await account.getDeployMethod();
|
|
64
|
+
const { estimatedGas, stats } = await deployMethod.simulate({
|
|
65
|
+
...deployAccountOpts,
|
|
66
|
+
fee: { ...deployAccountOpts.fee, estimateGas: true },
|
|
67
|
+
});
|
|
68
68
|
|
|
69
69
|
if (feeOpts.estimateOnly) {
|
|
70
|
-
const gas = await deployMethod.estimateGas({
|
|
71
|
-
...deployOpts,
|
|
72
|
-
from: AztecAddress.ZERO,
|
|
73
|
-
universalDeploy: true,
|
|
74
|
-
contractAddressSalt: salt,
|
|
75
|
-
});
|
|
76
70
|
if (json) {
|
|
77
71
|
out.fee = {
|
|
78
72
|
gasLimits: {
|
|
79
|
-
da:
|
|
80
|
-
l2:
|
|
73
|
+
da: estimatedGas.gasLimits.daGas,
|
|
74
|
+
l2: estimatedGas.gasLimits.l2Gas,
|
|
81
75
|
},
|
|
82
76
|
teardownGasLimits: {
|
|
83
|
-
da:
|
|
84
|
-
l2:
|
|
77
|
+
da: estimatedGas.teardownGasLimits.daGas,
|
|
78
|
+
l2: estimatedGas.teardownGasLimits,
|
|
85
79
|
},
|
|
86
80
|
};
|
|
87
|
-
} else {
|
|
88
|
-
printGasEstimates(feeOpts, gas, log);
|
|
89
81
|
}
|
|
90
82
|
} else {
|
|
91
|
-
|
|
92
|
-
...
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
83
|
+
tx = deployMethod.send({
|
|
84
|
+
...deployAccountOpts,
|
|
85
|
+
fee: deployAccountOpts.fee
|
|
86
|
+
? {
|
|
87
|
+
...deployAccountOpts.fee,
|
|
88
|
+
gasSettings: estimatedGas,
|
|
89
|
+
}
|
|
90
|
+
: undefined,
|
|
96
91
|
});
|
|
97
92
|
if (verbose) {
|
|
98
|
-
printProfileResult(
|
|
93
|
+
printProfileResult(stats, log);
|
|
99
94
|
}
|
|
100
|
-
tx = provenTx.send();
|
|
101
95
|
|
|
102
96
|
const txHash = await tx.getTxHash();
|
|
103
97
|
debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
|
|
@@ -124,6 +118,4 @@ export async function deployAccount(
|
|
|
124
118
|
log(`Deploy tx fee: ${txReceipt.transactionFee}`);
|
|
125
119
|
}
|
|
126
120
|
}
|
|
127
|
-
|
|
128
|
-
return { address, secretKey, salt };
|
|
129
121
|
}
|
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Fr, type PXE } from '@aztec/aztec.js';
|
|
1
|
+
import { getInitialTestAccountsData } from '@aztec/accounts/testing';
|
|
2
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
4
3
|
import { prettyPrintJSON } from '@aztec/cli/cli-utils';
|
|
5
4
|
import type { LogFn } from '@aztec/foundation/log';
|
|
6
5
|
|
|
7
6
|
import type { WalletDB } from '../storage/wallet_db.js';
|
|
7
|
+
import type { CLIWallet } from '../utils/wallet.js';
|
|
8
8
|
|
|
9
|
-
export async function importTestAccounts(
|
|
10
|
-
const testAccounts = await
|
|
11
|
-
const accounts = await Promise.all(
|
|
12
|
-
testAccounts.map(({ secret, signingKey, salt }) => getSchnorrAccount(client, secret, signingKey, salt)),
|
|
13
|
-
);
|
|
9
|
+
export async function importTestAccounts(wallet: CLIWallet, db: WalletDB, json: boolean, log: LogFn) {
|
|
10
|
+
const testAccounts = await getInitialTestAccountsData();
|
|
14
11
|
|
|
15
12
|
const out: Record<string, any> = {};
|
|
16
13
|
await Promise.all(
|
|
17
|
-
|
|
14
|
+
testAccounts.map(async (account, i) => {
|
|
18
15
|
const alias = `test${i}`;
|
|
19
16
|
const secret = testAccounts[i].secret;
|
|
20
17
|
const salt = new Fr(account.salt);
|
|
21
|
-
const address = account.
|
|
22
|
-
await account.register();
|
|
18
|
+
const address = account.address;
|
|
23
19
|
await db.storeAccount(address, { type: 'schnorr', secretKey: secret, salt, alias, publicKey: undefined }, log);
|
|
24
20
|
|
|
25
21
|
if (json) {
|