@aztec/cli-wallet 0.0.1-commit.d431d1c → 0.0.1-commit.d58ff9d0
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/bin/index.js +1 -1
- package/dest/cmds/authorize_action.d.ts +2 -2
- package/dest/cmds/authorize_action.d.ts.map +1 -1
- package/dest/cmds/authorize_action.js +4 -2
- package/dest/cmds/check_tx.d.ts +1 -1
- package/dest/cmds/check_tx.d.ts.map +1 -1
- package/dest/cmds/check_tx.js +54 -22
- package/dest/cmds/create_account.d.ts +6 -3
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +64 -31
- package/dest/cmds/deploy.d.ts +5 -4
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +65 -36
- package/dest/cmds/deploy_account.d.ts +4 -3
- package/dest/cmds/deploy_account.d.ts.map +1 -1
- package/dest/cmds/deploy_account.js +39 -25
- package/dest/cmds/get_fee_juice_balance.d.ts +5 -0
- package/dest/cmds/get_fee_juice_balance.d.ts.map +1 -0
- package/dest/cmds/get_fee_juice_balance.js +27 -0
- package/dest/cmds/import_test_accounts.d.ts +1 -1
- package/dest/cmds/import_test_accounts.d.ts.map +1 -1
- package/dest/cmds/import_test_accounts.js +2 -1
- package/dest/cmds/index.d.ts +1 -1
- package/dest/cmds/index.d.ts.map +1 -1
- package/dest/cmds/index.js +36 -19
- package/dest/cmds/send.d.ts +4 -3
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +33 -20
- package/dest/cmds/simulate.d.ts +1 -1
- package/dest/cmds/simulate.d.ts.map +1 -1
- package/dest/cmds/simulate.js +2 -1
- package/dest/storage/wallet_db.d.ts +12 -4
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +74 -31
- package/dest/utils/constants.d.ts +2 -2
- package/dest/utils/constants.d.ts.map +1 -1
- package/dest/utils/constants.js +1 -0
- package/dest/utils/options/fees.d.ts +3 -2
- package/dest/utils/options/fees.d.ts.map +1 -1
- package/dest/utils/options/fees.js +36 -10
- package/dest/utils/options/options.d.ts +2 -2
- package/dest/utils/options/options.d.ts.map +1 -1
- package/dest/utils/options/options.js +5 -5
- package/dest/utils/wallet.d.ts +37 -8
- package/dest/utils/wallet.d.ts.map +1 -1
- package/dest/utils/wallet.js +178 -97
- package/package.json +16 -15
- package/src/bin/index.ts +1 -1
- package/src/cmds/authorize_action.ts +1 -1
- package/src/cmds/check_tx.ts +61 -25
- package/src/cmds/create_account.ts +67 -35
- package/src/cmds/deploy.ts +64 -37
- package/src/cmds/deploy_account.ts +40 -21
- package/src/cmds/get_fee_juice_balance.ts +37 -0
- package/src/cmds/import_test_accounts.ts +12 -1
- package/src/cmds/index.ts +71 -15
- package/src/cmds/send.ts +33 -13
- package/src/cmds/simulate.ts +3 -2
- package/src/storage/wallet_db.ts +86 -37
- package/src/utils/constants.ts +7 -1
- package/src/utils/options/fees.ts +42 -10
- package/src/utils/options/options.ts +5 -5
- package/src/utils/wallet.ts +224 -130
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { deriveSecretKeyFromSigningKey } from '@aztec/accounts/utils';
|
|
2
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
1
3
|
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
-
import
|
|
4
|
+
import { NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
5
|
+
import { type AztecNode, waitForTx } from '@aztec/aztec.js/node';
|
|
3
6
|
import type { DeployAccountOptions } from '@aztec/aztec.js/wallet';
|
|
4
7
|
import { prettyPrintJSON } from '@aztec/cli/cli-utils';
|
|
5
8
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
9
|
+
import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
6
10
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
11
|
+
import { type TxHash, type TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
7
12
|
|
|
8
13
|
import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
9
14
|
import type { AccountType } from '../utils/constants.js';
|
|
@@ -15,7 +20,8 @@ export async function createAccount(
|
|
|
15
20
|
wallet: CLIWallet,
|
|
16
21
|
aztecNode: AztecNode,
|
|
17
22
|
accountType: AccountType,
|
|
18
|
-
|
|
23
|
+
signingKey: GrumpkinScalar | undefined,
|
|
24
|
+
salt: Fr | undefined,
|
|
19
25
|
publicKey: string | undefined,
|
|
20
26
|
alias: string | undefined,
|
|
21
27
|
deployer: AztecAddress | undefined,
|
|
@@ -25,52 +31,63 @@ export async function createAccount(
|
|
|
25
31
|
registerClass: boolean,
|
|
26
32
|
wait: boolean,
|
|
27
33
|
feeOpts: CLIFeeArgs,
|
|
34
|
+
waitForStatus: TxStatus,
|
|
28
35
|
json: boolean,
|
|
29
36
|
verbose: boolean,
|
|
30
37
|
debugLogger: Logger,
|
|
31
38
|
log: LogFn,
|
|
32
39
|
) {
|
|
33
|
-
secretKey
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
secretKey
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
let secretKey: Fr;
|
|
41
|
+
if (accountType === 'ecdsasecp256r1ssh') {
|
|
42
|
+
// SSH accounts sign with a key held in the agent, and so we cannot derive their privacy secret key from it. Instead
|
|
43
|
+
// we pick a random value.
|
|
44
|
+
secretKey = Fr.random();
|
|
45
|
+
} else {
|
|
46
|
+
signingKey ??= GrumpkinScalar.random();
|
|
47
|
+
secretKey = await deriveSecretKeyFromSigningKey(signingKey);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const account = await wallet.createAccount(accountType, signingKey, secretKey, salt, publicKey);
|
|
51
|
+
const instanceSalt = account.getInstance().salt;
|
|
43
52
|
const { address, publicKeys, partialAddress } = await account.getCompleteAddress();
|
|
44
53
|
|
|
45
54
|
const out: Record<string, any> = {};
|
|
46
55
|
if (json) {
|
|
47
56
|
out.address = address;
|
|
48
57
|
out.publicKey = publicKeys;
|
|
58
|
+
if (signingKey) {
|
|
59
|
+
out.signingKey = signingKey;
|
|
60
|
+
}
|
|
49
61
|
if (secretKey) {
|
|
50
62
|
out.secretKey = secretKey;
|
|
51
63
|
}
|
|
52
64
|
out.partialAddress = partialAddress;
|
|
53
|
-
out.salt =
|
|
65
|
+
out.salt = instanceSalt;
|
|
54
66
|
out.initHash = account.getInstance().initializationHash;
|
|
55
67
|
} else {
|
|
56
68
|
log(`\nNew account:\n`);
|
|
57
69
|
log(`Address: ${address.toString()}`);
|
|
58
70
|
log(`Public key: ${publicKeys.toString()}`);
|
|
71
|
+
if (signingKey) {
|
|
72
|
+
log(`Signing key: ${signingKey.toString()}`);
|
|
73
|
+
}
|
|
59
74
|
if (secretKey) {
|
|
60
75
|
log(`Secret key: ${secretKey.toString()}`);
|
|
61
76
|
}
|
|
62
77
|
log(`Partial address: ${partialAddress.toString()}`);
|
|
63
|
-
log(`Salt: ${
|
|
78
|
+
log(`Salt: ${instanceSalt.toString()}`);
|
|
64
79
|
log(`Init hash: ${account.getInstance().initializationHash.toString()}`);
|
|
65
80
|
}
|
|
66
81
|
|
|
67
|
-
let
|
|
68
|
-
let txReceipt;
|
|
69
|
-
|
|
82
|
+
let txHash: TxHash | undefined;
|
|
83
|
+
let txReceipt: TxReceipt | undefined;
|
|
84
|
+
// Initializerless accounts have no deployment tx — creating one only registers it locally — so there is
|
|
85
|
+
// nothing to deploy on-chain.
|
|
86
|
+
if (!registerOnly && accountType !== 'schnorr_initializerless') {
|
|
70
87
|
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
|
|
71
88
|
|
|
72
89
|
const delegatedDeployment = deployer && !account.address.equals(deployer);
|
|
73
|
-
const from = delegatedDeployment ? deployer :
|
|
90
|
+
const from = delegatedDeployment ? deployer : NO_FROM;
|
|
74
91
|
|
|
75
92
|
const deployAccountOpts: DeployAccountOptions = {
|
|
76
93
|
skipClassPublication: !registerClass,
|
|
@@ -80,11 +97,15 @@ export async function createAccount(
|
|
|
80
97
|
fee: { paymentMethod, gasSettings },
|
|
81
98
|
};
|
|
82
99
|
|
|
100
|
+
const localStart = performance.now();
|
|
83
101
|
const deployMethod = await account.getDeployMethod();
|
|
84
|
-
const
|
|
102
|
+
const sim = await deployMethod.simulate({
|
|
85
103
|
...deployAccountOpts,
|
|
86
|
-
|
|
104
|
+
includeMetadata: true,
|
|
87
105
|
});
|
|
106
|
+
// includeMetadata: true guarantees these fields are present
|
|
107
|
+
const estimatedGas = await wallet.estimateGasLimits(sim.gasUsed!);
|
|
108
|
+
const stats = sim.stats!;
|
|
88
109
|
|
|
89
110
|
if (feeOpts.estimateOnly) {
|
|
90
111
|
if (json) {
|
|
@@ -100,7 +121,14 @@ export async function createAccount(
|
|
|
100
121
|
};
|
|
101
122
|
}
|
|
102
123
|
} else {
|
|
103
|
-
|
|
124
|
+
if (verbose) {
|
|
125
|
+
printProfileResult(stats, log);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!json) {
|
|
129
|
+
log(`\nWaiting for account contract deployment...`);
|
|
130
|
+
}
|
|
131
|
+
const sendOpts = {
|
|
104
132
|
...deployAccountOpts,
|
|
105
133
|
fee: deployAccountOpts.fee
|
|
106
134
|
? {
|
|
@@ -108,37 +136,41 @@ export async function createAccount(
|
|
|
108
136
|
gasSettings: estimatedGas,
|
|
109
137
|
}
|
|
110
138
|
: undefined,
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
({ txHash } = await deployMethod.send({ ...sendOpts, wait: NO_WAIT }));
|
|
142
|
+
const localTimeMs = performance.now() - localStart;
|
|
115
143
|
|
|
116
|
-
const txHash = await tx.getTxHash();
|
|
117
|
-
debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
|
|
118
|
-
out.txHash = txHash;
|
|
119
144
|
if (wait) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
145
|
+
const nodeStart = performance.now();
|
|
146
|
+
txReceipt = await waitForTx(aztecNode, txHash, { timeout: DEFAULT_TX_TIMEOUT_S, waitForStatus });
|
|
147
|
+
const nodeTimeMs = performance.now() - nodeStart;
|
|
148
|
+
|
|
124
149
|
out.txReceipt = {
|
|
125
150
|
status: txReceipt.status,
|
|
126
151
|
transactionFee: txReceipt.transactionFee,
|
|
127
152
|
};
|
|
153
|
+
|
|
154
|
+
if (!json) {
|
|
155
|
+
log(` Local processing time: ${(localTimeMs / 1000).toFixed(1)}s`);
|
|
156
|
+
log(` Node inclusion time: ${(nodeTimeMs / 1000).toFixed(1)}s`);
|
|
157
|
+
}
|
|
128
158
|
}
|
|
159
|
+
debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
|
|
160
|
+
out.txHash = txHash;
|
|
129
161
|
}
|
|
130
162
|
}
|
|
131
163
|
|
|
132
164
|
if (json) {
|
|
133
165
|
log(prettyPrintJSON(out));
|
|
134
166
|
} else {
|
|
135
|
-
if (
|
|
136
|
-
log(`Deploy tx hash: ${
|
|
167
|
+
if (txHash) {
|
|
168
|
+
log(`Deploy tx hash: ${txHash.toString()}`);
|
|
137
169
|
}
|
|
138
170
|
if (txReceipt) {
|
|
139
171
|
log(`Deploy tx fee: ${txReceipt.transactionFee}`);
|
|
140
172
|
}
|
|
141
173
|
}
|
|
142
174
|
|
|
143
|
-
return { alias, address, secretKey, salt };
|
|
175
|
+
return { alias, address, signingKey, secretKey, salt: instanceSalt };
|
|
144
176
|
}
|
package/src/cmds/deploy.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
2
|
+
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
3
|
import type { DeployOptions } from '@aztec/aztec.js/contracts';
|
|
4
|
+
import { NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
3
5
|
import { ContractDeployer } from '@aztec/aztec.js/deployment';
|
|
4
6
|
import { Fr } from '@aztec/aztec.js/fields';
|
|
5
|
-
import type
|
|
7
|
+
import { type AztecNode, waitForTx } from '@aztec/aztec.js/node';
|
|
6
8
|
import { encodeArgs, getContractArtifact, prettyPrintJSON } from '@aztec/cli/utils';
|
|
7
9
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
8
10
|
import { getAllFunctionAbis, getInitializer } from '@aztec/stdlib/abi';
|
|
9
11
|
import { PublicKeys } from '@aztec/stdlib/keys';
|
|
12
|
+
import type { TxStatus } from '@aztec/stdlib/tx';
|
|
10
13
|
|
|
11
14
|
import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
12
15
|
import { CLIFeeArgs } from '../utils/options/fees.js';
|
|
@@ -28,10 +31,12 @@ export async function deploy(
|
|
|
28
31
|
skipInitialization: boolean | undefined,
|
|
29
32
|
wait: boolean,
|
|
30
33
|
feeOpts: CLIFeeArgs,
|
|
34
|
+
waitForStatus: TxStatus,
|
|
31
35
|
verbose: boolean,
|
|
32
36
|
timeout: number = DEFAULT_TX_TIMEOUT_S,
|
|
33
37
|
debugLogger: Logger,
|
|
34
38
|
log: LogFn,
|
|
39
|
+
universal?: boolean,
|
|
35
40
|
) {
|
|
36
41
|
const out: Record<string, any> = {};
|
|
37
42
|
salt ??= Fr.random();
|
|
@@ -41,12 +46,7 @@ export async function deploy(
|
|
|
41
46
|
|
|
42
47
|
// TODO(#12081): Add contractArtifact.noirVersion and check here (via Noir.lock)?
|
|
43
48
|
|
|
44
|
-
const contractDeployer = new ContractDeployer(
|
|
45
|
-
contractArtifact,
|
|
46
|
-
wallet,
|
|
47
|
-
publicKeys ?? PublicKeys.default(),
|
|
48
|
-
initializer,
|
|
49
|
-
);
|
|
49
|
+
const contractDeployer = new ContractDeployer(contractArtifact, wallet, initializer);
|
|
50
50
|
|
|
51
51
|
let args = [];
|
|
52
52
|
if (rawArgs.length > 0) {
|
|
@@ -58,22 +58,28 @@ export async function deploy(
|
|
|
58
58
|
debugLogger.debug(`Encoded arguments: ${args.join(', ')}`);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
const
|
|
61
|
+
const deployInteraction = contractDeployer.deploy(args, {
|
|
62
|
+
salt,
|
|
63
|
+
publicKeys: publicKeys ?? PublicKeys.default(),
|
|
64
|
+
...(universal ? { universalDeploy: true as const } : {}),
|
|
65
|
+
});
|
|
62
66
|
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, deployer);
|
|
63
67
|
const deployOpts: DeployOptions = {
|
|
64
68
|
fee: { gasSettings, paymentMethod },
|
|
65
|
-
from: deployer ??
|
|
66
|
-
contractAddressSalt: salt,
|
|
67
|
-
universalDeploy: !deployer,
|
|
69
|
+
from: deployer ?? NO_FROM,
|
|
68
70
|
skipClassPublication,
|
|
69
71
|
skipInitialization,
|
|
70
72
|
skipInstancePublication,
|
|
71
73
|
};
|
|
72
74
|
|
|
73
|
-
const
|
|
75
|
+
const localStart = performance.now();
|
|
76
|
+
const sim = await deployInteraction.simulate({
|
|
74
77
|
...deployOpts,
|
|
75
|
-
|
|
78
|
+
includeMetadata: true,
|
|
76
79
|
});
|
|
80
|
+
// includeMetadata: true guarantees these fields are present
|
|
81
|
+
const estimatedGas = await wallet.estimateGasLimits(sim.gasUsed!);
|
|
82
|
+
const stats = sim.stats!;
|
|
77
83
|
|
|
78
84
|
if (feeOpts.estimateOnly) {
|
|
79
85
|
if (json) {
|
|
@@ -89,42 +95,63 @@ export async function deploy(
|
|
|
89
95
|
};
|
|
90
96
|
}
|
|
91
97
|
} else {
|
|
92
|
-
const tx = deploy.send(deployOpts);
|
|
93
98
|
if (verbose) {
|
|
94
99
|
printProfileResult(stats, log);
|
|
95
100
|
}
|
|
96
101
|
|
|
97
|
-
const
|
|
102
|
+
const instance = await deployInteraction.getInstance();
|
|
103
|
+
const address = instance.address;
|
|
104
|
+
const partialAddress = await deployInteraction.getPartialAddress();
|
|
105
|
+
|
|
106
|
+
const { txHash } = await deployInteraction.send({ ...deployOpts, wait: NO_WAIT });
|
|
107
|
+
const localTimeMs = performance.now() - localStart;
|
|
98
108
|
debugLogger.debug(`Deploy tx sent with hash ${txHash.toString()}`);
|
|
99
109
|
out.hash = txHash;
|
|
100
|
-
|
|
101
|
-
const instance = await deploy.getInstance();
|
|
102
|
-
if (!json) {
|
|
103
|
-
log(`Contract deployed at ${address?.toString()}`);
|
|
104
|
-
log(`Contract partial address ${(await partialAddress)?.toString()}`);
|
|
105
|
-
log(`Contract init hash ${instance.initializationHash.toString()}`);
|
|
106
|
-
log(`Deployment tx hash: ${txHash.toString()}`);
|
|
107
|
-
log(`Deployment salt: ${salt.toString()}`);
|
|
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
|
-
};
|
|
116
|
-
}
|
|
110
|
+
|
|
117
111
|
if (wait) {
|
|
118
|
-
const
|
|
112
|
+
const nodeStart = performance.now();
|
|
113
|
+
const receipt = await waitForTx(node, txHash, { timeout, waitForStatus });
|
|
114
|
+
const nodeTimeMs = performance.now() - nodeStart;
|
|
115
|
+
|
|
116
|
+
if (!json) {
|
|
117
|
+
log(`Contract deployed at ${address.toString()}`);
|
|
118
|
+
log(`Contract partial address ${partialAddress.toString()}`);
|
|
119
|
+
log(`Contract init hash ${instance.initializationHash.toString()}`);
|
|
120
|
+
log(`Deployment tx hash: ${txHash.toString()}`);
|
|
121
|
+
log(`Deployment salt: ${salt.toString()}`);
|
|
122
|
+
log(`Deployer: ${instance.deployer.toString()}`);
|
|
123
|
+
log(`Transaction fee: ${receipt.transactionFee?.toString()}`);
|
|
124
|
+
log(` Local processing time: ${(localTimeMs / 1000).toFixed(1)}s`);
|
|
125
|
+
log(` Node inclusion time: ${(nodeTimeMs / 1000).toFixed(1)}s`);
|
|
126
|
+
} else {
|
|
127
|
+
out.contract = {
|
|
128
|
+
address: address.toString(),
|
|
129
|
+
partialAddress: partialAddress.toString(),
|
|
130
|
+
initializationHash: instance.initializationHash.toString(),
|
|
131
|
+
salt: salt.toString(),
|
|
132
|
+
transactionFee: receipt.transactionFee?.toString(),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
119
136
|
if (!json) {
|
|
120
|
-
log(`
|
|
137
|
+
log(`Contract deployed at ${address.toString()}`);
|
|
138
|
+
log(`Contract partial address ${partialAddress.toString()}`);
|
|
139
|
+
log(`Contract init hash ${instance.initializationHash.toString()}`);
|
|
140
|
+
log(`Deployment tx hash: ${txHash.toString()}`);
|
|
141
|
+
log(`Deployment salt: ${salt.toString()}`);
|
|
142
|
+
log(`Deployer: ${instance.deployer.toString()}`);
|
|
121
143
|
} else {
|
|
122
|
-
out.contract
|
|
144
|
+
out.contract = {
|
|
145
|
+
address: address.toString(),
|
|
146
|
+
partialAddress: partialAddress.toString(),
|
|
147
|
+
initializationHash: instance.initializationHash.toString(),
|
|
148
|
+
salt: salt.toString(),
|
|
149
|
+
};
|
|
123
150
|
}
|
|
124
151
|
}
|
|
125
152
|
}
|
|
126
153
|
if (json) {
|
|
127
154
|
log(prettyPrintJSON(out));
|
|
128
155
|
}
|
|
129
|
-
return
|
|
156
|
+
return await deployInteraction.getAddress();
|
|
130
157
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
1
2
|
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
-
import
|
|
3
|
+
import { NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
4
|
+
import { type AztecNode, waitForTx } from '@aztec/aztec.js/node';
|
|
3
5
|
import type { DeployAccountOptions } from '@aztec/aztec.js/wallet';
|
|
4
6
|
import { prettyPrintJSON } from '@aztec/cli/cli-utils';
|
|
5
7
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
8
|
+
import type { TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
6
9
|
|
|
7
10
|
import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
8
11
|
import type { CLIFeeArgs } from '../utils/options/fees.js';
|
|
@@ -19,6 +22,7 @@ export async function deployAccount(
|
|
|
19
22
|
publicDeploy: boolean,
|
|
20
23
|
skipInitialization: boolean,
|
|
21
24
|
feeOpts: CLIFeeArgs,
|
|
25
|
+
waitForStatus: TxStatus,
|
|
22
26
|
json: boolean,
|
|
23
27
|
verbose: boolean,
|
|
24
28
|
debugLogger: Logger,
|
|
@@ -26,7 +30,7 @@ export async function deployAccount(
|
|
|
26
30
|
) {
|
|
27
31
|
const out: Record<string, any> = {};
|
|
28
32
|
|
|
29
|
-
const account = await wallet.
|
|
33
|
+
const account = await wallet.retrieveAccount(address);
|
|
30
34
|
const { partialAddress, publicKeys } = await account.getCompleteAddress();
|
|
31
35
|
const { initializationHash, salt } = account.getInstance();
|
|
32
36
|
|
|
@@ -45,12 +49,12 @@ export async function deployAccount(
|
|
|
45
49
|
log(`Init hash: ${initializationHash.toString()}`);
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
let
|
|
49
|
-
let txReceipt;
|
|
52
|
+
let txHash: TxHash | undefined;
|
|
53
|
+
let txReceipt: TxReceipt | undefined;
|
|
50
54
|
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
|
|
51
55
|
|
|
52
56
|
const delegatedDeployment = deployer && !account.address.equals(deployer);
|
|
53
|
-
const from = delegatedDeployment ? deployer :
|
|
57
|
+
const from = delegatedDeployment ? deployer : NO_FROM;
|
|
54
58
|
|
|
55
59
|
const deployAccountOpts: DeployAccountOptions = {
|
|
56
60
|
skipClassPublication: !registerClass,
|
|
@@ -60,11 +64,15 @@ export async function deployAccount(
|
|
|
60
64
|
fee: { paymentMethod, gasSettings },
|
|
61
65
|
};
|
|
62
66
|
|
|
67
|
+
const localStart = performance.now();
|
|
63
68
|
const deployMethod = await account.getDeployMethod();
|
|
64
|
-
const
|
|
69
|
+
const sim = await deployMethod.simulate({
|
|
65
70
|
...deployAccountOpts,
|
|
66
|
-
|
|
71
|
+
includeMetadata: true,
|
|
67
72
|
});
|
|
73
|
+
// includeMetadata: true guarantees these fields are present
|
|
74
|
+
const estimatedGas = await wallet.estimateGasLimits(sim.gasUsed!);
|
|
75
|
+
const stats = sim.stats!;
|
|
68
76
|
|
|
69
77
|
if (feeOpts.estimateOnly) {
|
|
70
78
|
if (json) {
|
|
@@ -80,7 +88,14 @@ export async function deployAccount(
|
|
|
80
88
|
};
|
|
81
89
|
}
|
|
82
90
|
} else {
|
|
83
|
-
|
|
91
|
+
if (verbose) {
|
|
92
|
+
printProfileResult(stats, log);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!json) {
|
|
96
|
+
log(`\nWaiting for account contract deployment...`);
|
|
97
|
+
}
|
|
98
|
+
const sendOpts = {
|
|
84
99
|
...deployAccountOpts,
|
|
85
100
|
fee: deployAccountOpts.fee
|
|
86
101
|
? {
|
|
@@ -88,31 +103,35 @@ export async function deployAccount(
|
|
|
88
103
|
gasSettings: estimatedGas,
|
|
89
104
|
}
|
|
90
105
|
: undefined,
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
({ txHash } = await deployMethod.send({ ...sendOpts, wait: NO_WAIT }));
|
|
109
|
+
const localTimeMs = performance.now() - localStart;
|
|
95
110
|
|
|
96
|
-
const txHash = await tx.getTxHash();
|
|
97
|
-
debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
|
|
98
|
-
out.txHash = txHash;
|
|
99
111
|
if (wait) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
const nodeStart = performance.now();
|
|
113
|
+
txReceipt = await waitForTx(aztecNode, txHash, { timeout: DEFAULT_TX_TIMEOUT_S, waitForStatus });
|
|
114
|
+
const nodeTimeMs = performance.now() - nodeStart;
|
|
115
|
+
|
|
104
116
|
out.txReceipt = {
|
|
105
117
|
status: txReceipt.status,
|
|
106
118
|
transactionFee: txReceipt.transactionFee,
|
|
107
119
|
};
|
|
120
|
+
|
|
121
|
+
if (!json) {
|
|
122
|
+
log(` Local processing time: ${(localTimeMs / 1000).toFixed(1)}s`);
|
|
123
|
+
log(` Node inclusion time: ${(nodeTimeMs / 1000).toFixed(1)}s`);
|
|
124
|
+
}
|
|
108
125
|
}
|
|
126
|
+
debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
|
|
127
|
+
out.txHash = txHash;
|
|
109
128
|
}
|
|
110
129
|
|
|
111
130
|
if (json) {
|
|
112
131
|
log(prettyPrintJSON(out));
|
|
113
132
|
} else {
|
|
114
|
-
if (
|
|
115
|
-
log(`Deploy tx hash: ${
|
|
133
|
+
if (txHash) {
|
|
134
|
+
log(`Deploy tx hash: ${txHash.toString()}`);
|
|
116
135
|
}
|
|
117
136
|
if (txReceipt) {
|
|
118
137
|
log(`Deploy tx fee: ${txReceipt.transactionFee}`);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
3
|
+
import { getFeeJuiceBalance } from '@aztec/aztec.js/utils';
|
|
4
|
+
import { prettyPrintJSON } from '@aztec/cli/cli-utils';
|
|
5
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
6
|
+
|
|
7
|
+
const FEE_JUICE_DECIMALS = 18;
|
|
8
|
+
const FEE_JUICE_UNIT = 10n ** BigInt(FEE_JUICE_DECIMALS);
|
|
9
|
+
|
|
10
|
+
/** Formats a raw FeeJuice balance (18 decimals) for human-readable display. */
|
|
11
|
+
function formatFeeJuice(raw: bigint, exact: boolean): string {
|
|
12
|
+
const whole = raw / FEE_JUICE_UNIT;
|
|
13
|
+
const fractional = raw % FEE_JUICE_UNIT;
|
|
14
|
+
const fracStr = fractional.toString().padStart(FEE_JUICE_DECIMALS, '0');
|
|
15
|
+
if (exact) {
|
|
16
|
+
return `${whole}.${fracStr} FJ`;
|
|
17
|
+
}
|
|
18
|
+
if (fractional === 0n) {
|
|
19
|
+
return `${whole} FJ`;
|
|
20
|
+
}
|
|
21
|
+
return `${whole}.${fracStr.replace(/0+$/, '')} FJ`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function getFeeJuiceBalanceCmd(
|
|
25
|
+
node: AztecNode,
|
|
26
|
+
address: AztecAddress,
|
|
27
|
+
json: boolean,
|
|
28
|
+
exact: boolean,
|
|
29
|
+
log: LogFn,
|
|
30
|
+
) {
|
|
31
|
+
const balance = await getFeeJuiceBalance(address, node);
|
|
32
|
+
if (json) {
|
|
33
|
+
log(prettyPrintJSON({ address: address.toString(), balance: balance.toString() }));
|
|
34
|
+
} else {
|
|
35
|
+
log(`Fee Juice balance for ${address.toString()}: ${formatFeeJuice(balance, exact)}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -16,7 +16,18 @@ export async function importTestAccounts(wallet: CLIWallet, db: WalletDB, json:
|
|
|
16
16
|
const secret = testAccounts[i].secret;
|
|
17
17
|
const salt = new Fr(account.salt);
|
|
18
18
|
const address = account.address;
|
|
19
|
-
await db.storeAccount(
|
|
19
|
+
await db.storeAccount(
|
|
20
|
+
address,
|
|
21
|
+
{
|
|
22
|
+
type: 'schnorr_initializerless',
|
|
23
|
+
signingKey: account.signingKey,
|
|
24
|
+
secretKey: secret,
|
|
25
|
+
salt,
|
|
26
|
+
alias,
|
|
27
|
+
publicKey: undefined,
|
|
28
|
+
},
|
|
29
|
+
log,
|
|
30
|
+
);
|
|
20
31
|
|
|
21
32
|
if (json) {
|
|
22
33
|
out[alias] = {
|