@aztec/cli-wallet 0.0.1-commit.b655e406 → 0.0.1-commit.b9865e97
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 +2 -2
- package/dest/bin/index.d.ts +2 -1
- package/dest/bin/index.js +21 -11
- 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 +5 -3
- 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 +3 -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 +50 -21
- package/dest/cmds/create_account.d.ts +7 -5
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +43 -26
- package/dest/cmds/create_authwit.d.ts +1 -1
- package/dest/cmds/create_authwit.js +1 -1
- package/dest/cmds/deploy.d.ts +5 -4
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +64 -32
- 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 +37 -20
- 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/index.d.ts +1 -1
- package/dest/cmds/index.d.ts.map +1 -1
- package/dest/cmds/index.js +33 -17
- package/dest/cmds/profile.d.ts +1 -1
- package/dest/cmds/profile.js +1 -1
- package/dest/cmds/register_contract.d.ts +1 -1
- package/dest/cmds/register_sender.d.ts +1 -1
- package/dest/cmds/send.d.ts +5 -4
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +33 -17
- package/dest/cmds/simulate.d.ts +1 -1
- package/dest/cmds/simulate.d.ts.map +1 -1
- package/dest/cmds/simulate.js +4 -4
- package/dest/storage/wallet_db.d.ts +10 -5
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +61 -32
- package/dest/utils/authorizations.d.ts +1 -1
- package/dest/utils/cli_wallet_and_node_wrapper.d.ts +1 -1
- package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -1
- package/dest/utils/constants.d.ts +4 -0
- package/dest/utils/constants.d.ts.map +1 -0
- package/dest/utils/constants.js +7 -0
- package/dest/utils/ecdsa.d.ts +1 -1
- package/dest/utils/options/fees.d.ts +5 -3
- package/dest/utils/options/fees.d.ts.map +1 -1
- package/dest/utils/options/fees.js +34 -11
- package/dest/utils/options/index.d.ts +1 -1
- package/dest/utils/options/options.d.ts +1 -1
- package/dest/utils/options/options.js +1 -1
- package/dest/utils/profiling.d.ts +1 -1
- package/dest/utils/profiling.d.ts.map +1 -1
- package/dest/utils/profiling.js +9 -1
- package/dest/utils/wallet.d.ts +21 -12
- package/dest/utils/wallet.d.ts.map +1 -1
- package/dest/utils/wallet.js +135 -65
- package/package.json +19 -15
- package/src/bin/index.ts +19 -13
- package/src/cmds/authorize_action.ts +2 -2
- package/src/cmds/bridge_fee_juice.ts +3 -2
- package/src/cmds/check_tx.ts +55 -25
- package/src/cmds/create_account.ts +47 -26
- package/src/cmds/create_authwit.ts +1 -1
- package/src/cmds/deploy.ts +63 -36
- package/src/cmds/deploy_account.ts +38 -19
- package/src/cmds/get_fee_juice_balance.ts +37 -0
- package/src/cmds/index.ts +63 -9
- package/src/cmds/profile.ts +1 -1
- package/src/cmds/send.ts +33 -13
- package/src/cmds/simulate.ts +5 -8
- package/src/storage/wallet_db.ts +65 -38
- package/src/utils/cli_wallet_and_node_wrapper.ts +1 -1
- package/src/utils/constants.ts +4 -0
- package/src/utils/options/fees.ts +43 -12
- package/src/utils/options/options.ts +1 -1
- package/src/utils/profiling.ts +15 -1
- package/src/utils/wallet.ts +147 -81
package/src/cmds/check_tx.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { ContractArtifact } from '@aztec/aztec.js/abi';
|
|
2
|
-
import
|
|
2
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
3
3
|
import { Fr } from '@aztec/aztec.js/fields';
|
|
4
4
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
5
5
|
import { ProtocolContractAddress } from '@aztec/aztec.js/protocol';
|
|
6
6
|
import type { TxHash } from '@aztec/aztec.js/tx';
|
|
7
7
|
import type { LogFn } from '@aztec/foundation/log';
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import {
|
|
9
|
+
computeSiloedPrivateInitializationNullifier,
|
|
10
|
+
computeSiloedPublicInitializationNullifier,
|
|
11
|
+
siloNullifier,
|
|
12
|
+
} from '@aztec/stdlib/hash';
|
|
13
|
+
import { NoteDao } from '@aztec/stdlib/note';
|
|
10
14
|
|
|
11
15
|
import type { CLIWallet } from '../utils/wallet.js';
|
|
12
16
|
|
|
@@ -29,19 +33,22 @@ export async function checkTx(
|
|
|
29
33
|
// dependency when dropping PXE JSON RPC Server.
|
|
30
34
|
|
|
31
35
|
async function inspectTx(wallet: CLIWallet, aztecNode: AztecNode, txHash: TxHash, log: LogFn) {
|
|
32
|
-
const
|
|
36
|
+
const receipt = await aztecNode.getTxReceipt(txHash, { includeTxEffect: true });
|
|
33
37
|
// Base tx data
|
|
34
38
|
log(`Tx ${txHash.toString()}`);
|
|
35
|
-
log(` Status: ${receipt.status}
|
|
39
|
+
log(` Status: ${receipt.status}`);
|
|
40
|
+
if (receipt.executionResult) {
|
|
41
|
+
log(` Execution result: ${receipt.executionResult}`);
|
|
42
|
+
}
|
|
36
43
|
if (receipt.error) {
|
|
37
44
|
log(` Error: ${receipt.error}`);
|
|
38
45
|
}
|
|
39
46
|
|
|
40
|
-
if (!
|
|
47
|
+
if (!receipt.isMined() || !receipt.txEffect) {
|
|
41
48
|
return;
|
|
42
49
|
}
|
|
43
50
|
|
|
44
|
-
const effects =
|
|
51
|
+
const effects = receipt.txEffect;
|
|
45
52
|
const artifactMap = await getKnownArtifacts(wallet);
|
|
46
53
|
|
|
47
54
|
log(` Block: ${receipt.blockNumber} (${receipt.blockHash?.toString()})`);
|
|
@@ -80,12 +87,13 @@ async function inspectTx(wallet: CLIWallet, aztecNode: AztecNode, txHash: TxHash
|
|
|
80
87
|
// Nullifiers
|
|
81
88
|
const nullifierCount = effects.nullifiers.length;
|
|
82
89
|
const { deployNullifiers, initNullifiers, classNullifiers } = await getKnownNullifiers(wallet, artifactMap);
|
|
90
|
+
const accounts = (await wallet.getAccounts()).map(a => a.item);
|
|
83
91
|
if (nullifierCount > 0) {
|
|
84
92
|
log(' Nullifiers:');
|
|
85
93
|
for (const nullifier of effects.nullifiers) {
|
|
86
94
|
const deployed = deployNullifiers[nullifier.toString()];
|
|
87
95
|
const note = deployed
|
|
88
|
-
? (await wallet.getNotes({ siloedNullifier: nullifier, contractAddress: deployed }))[0]
|
|
96
|
+
? (await wallet.getNotes({ siloedNullifier: nullifier, contractAddress: deployed, scopes: accounts }))[0]
|
|
89
97
|
: undefined;
|
|
90
98
|
const initialized = initNullifiers[nullifier.toString()];
|
|
91
99
|
const registered = classNullifiers[nullifier.toString()];
|
|
@@ -121,11 +129,10 @@ async function inspectTx(wallet: CLIWallet, aztecNode: AztecNode, txHash: TxHash
|
|
|
121
129
|
}
|
|
122
130
|
}
|
|
123
131
|
|
|
124
|
-
function inspectNote(note:
|
|
132
|
+
function inspectNote(note: NoteDao, artifactMap: ArtifactMap, log: LogFn, text = 'Note') {
|
|
125
133
|
const artifact = artifactMap[note.contractAddress.toString()];
|
|
126
134
|
const contract = artifact?.name ?? note.contractAddress.toString();
|
|
127
135
|
log(` ${text} at ${contract}`);
|
|
128
|
-
log(` Recipient: ${toFriendlyAddress(note.recipient, artifactMap)}`);
|
|
129
136
|
for (const field of note.note.items) {
|
|
130
137
|
log(` ${field.toString()}`);
|
|
131
138
|
}
|
|
@@ -142,22 +149,49 @@ function toFriendlyAddress(address: AztecAddress, artifactMap: ArtifactMap) {
|
|
|
142
149
|
|
|
143
150
|
async function getKnownNullifiers(wallet: CLIWallet, artifactMap: ArtifactMap) {
|
|
144
151
|
const knownContracts = await wallet.getContracts();
|
|
145
|
-
|
|
146
|
-
const
|
|
152
|
+
|
|
153
|
+
const [contractResults, classResults] = await Promise.all([
|
|
154
|
+
Promise.all(knownContracts.map(contract => getContractNullifiers(wallet, contract))),
|
|
155
|
+
Promise.all(Object.values(artifactMap).map(artifact => getClassNullifier(artifact))),
|
|
156
|
+
]);
|
|
157
|
+
|
|
147
158
|
const initNullifiers: Record<string, AztecAddress> = {};
|
|
148
159
|
const deployNullifiers: Record<string, AztecAddress> = {};
|
|
149
160
|
const classNullifiers: Record<string, string> = {};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
deployNullifiers[
|
|
161
|
+
|
|
162
|
+
for (const { contract, deployNullifier, privateInitNullifier, publicInitNullifier } of contractResults) {
|
|
163
|
+
deployNullifiers[deployNullifier.toString()] = contract;
|
|
164
|
+
if (privateInitNullifier) {
|
|
165
|
+
initNullifiers[privateInitNullifier.toString()] = contract;
|
|
166
|
+
}
|
|
167
|
+
initNullifiers[publicInitNullifier.toString()] = contract;
|
|
153
168
|
}
|
|
154
|
-
for (const
|
|
155
|
-
classNullifiers[
|
|
156
|
-
`${artifact.name}Class<${artifact.classId}>`;
|
|
169
|
+
for (const { nullifier, label } of classResults) {
|
|
170
|
+
classNullifiers[nullifier.toString()] = label;
|
|
157
171
|
}
|
|
172
|
+
|
|
158
173
|
return { initNullifiers, deployNullifiers, classNullifiers };
|
|
159
174
|
}
|
|
160
175
|
|
|
176
|
+
async function getContractNullifiers(wallet: CLIWallet, contract: AztecAddress) {
|
|
177
|
+
const deployerAddress = ProtocolContractAddress.ContractInstanceRegistry;
|
|
178
|
+
const deployNullifier = await siloNullifier(deployerAddress, contract.toField());
|
|
179
|
+
|
|
180
|
+
const metadata = await wallet.getContractMetadata(contract);
|
|
181
|
+
const privateInitNullifier = metadata.instance
|
|
182
|
+
? await computeSiloedPrivateInitializationNullifier(contract, metadata.instance.initializationHash)
|
|
183
|
+
: undefined;
|
|
184
|
+
const publicInitNullifier = await computeSiloedPublicInitializationNullifier(contract);
|
|
185
|
+
|
|
186
|
+
return { contract, deployNullifier, privateInitNullifier, publicInitNullifier };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async function getClassNullifier(artifact: ContractArtifactWithClassId) {
|
|
190
|
+
const classRegistryAddress = ProtocolContractAddress.ContractClassRegistry;
|
|
191
|
+
const nullifier = await siloNullifier(classRegistryAddress, artifact.classId);
|
|
192
|
+
return { nullifier, label: `${artifact.name}Class<${artifact.classId}>` };
|
|
193
|
+
}
|
|
194
|
+
|
|
161
195
|
type ArtifactMap = Record<string, ContractArtifactWithClassId>;
|
|
162
196
|
type ContractArtifactWithClassId = ContractArtifact & { classId: Fr };
|
|
163
197
|
|
|
@@ -165,15 +199,11 @@ async function getKnownArtifacts(wallet: CLIWallet): Promise<ArtifactMap> {
|
|
|
165
199
|
const knownContractAddresses = await wallet.getContracts();
|
|
166
200
|
const knownContracts = (
|
|
167
201
|
await Promise.all(knownContractAddresses.map(contractAddress => wallet.getContractMetadata(contractAddress)))
|
|
168
|
-
).map(contractMetadata => contractMetadata.
|
|
202
|
+
).map(contractMetadata => contractMetadata.instance);
|
|
169
203
|
const classIds = [...new Set(knownContracts.map(contract => contract?.currentContractClassId))];
|
|
170
204
|
const knownArtifacts = (
|
|
171
|
-
await Promise.all(classIds.map(classId => (classId ? wallet.
|
|
172
|
-
).map(
|
|
173
|
-
contractClassMetadata
|
|
174
|
-
? { ...contractClassMetadata.artifact, classId: contractClassMetadata.contractClass?.id }
|
|
175
|
-
: undefined,
|
|
176
|
-
);
|
|
205
|
+
await Promise.all(classIds.map(classId => (classId ? wallet.getContractArtifact(classId) : undefined)))
|
|
206
|
+
).map((artifact, index) => (artifact ? { ...artifact, classId: classIds[index] } : undefined));
|
|
177
207
|
const map: Record<string, ContractArtifactWithClassId> = {};
|
|
178
208
|
for (const instance of knownContracts) {
|
|
179
209
|
if (instance) {
|
|
@@ -1,20 +1,25 @@
|
|
|
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
|
-
import { Fr } from '@aztec/foundation/
|
|
7
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
8
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
9
|
+
import { type TxHash, type TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
7
10
|
|
|
8
11
|
import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
12
|
+
import type { AccountType } from '../utils/constants.js';
|
|
9
13
|
import { CLIFeeArgs } from '../utils/options/fees.js';
|
|
10
14
|
import { printProfileResult } from '../utils/profiling.js';
|
|
11
|
-
import {
|
|
15
|
+
import { CLIWallet } from '../utils/wallet.js';
|
|
12
16
|
|
|
13
17
|
export async function createAccount(
|
|
14
18
|
wallet: CLIWallet,
|
|
15
19
|
aztecNode: AztecNode,
|
|
16
20
|
accountType: AccountType,
|
|
17
21
|
secretKey: Fr | undefined,
|
|
22
|
+
salt: Fr | undefined,
|
|
18
23
|
publicKey: string | undefined,
|
|
19
24
|
alias: string | undefined,
|
|
20
25
|
deployer: AztecAddress | undefined,
|
|
@@ -24,6 +29,7 @@ export async function createAccount(
|
|
|
24
29
|
registerClass: boolean,
|
|
25
30
|
wait: boolean,
|
|
26
31
|
feeOpts: CLIFeeArgs,
|
|
32
|
+
waitForStatus: TxStatus,
|
|
27
33
|
json: boolean,
|
|
28
34
|
verbose: boolean,
|
|
29
35
|
debugLogger: Logger,
|
|
@@ -35,10 +41,10 @@ export async function createAccount(
|
|
|
35
41
|
undefined /* address, we don't have it yet */,
|
|
36
42
|
secretKey,
|
|
37
43
|
accountType,
|
|
38
|
-
|
|
44
|
+
salt,
|
|
39
45
|
publicKey,
|
|
40
46
|
);
|
|
41
|
-
const
|
|
47
|
+
const instanceSalt = account.getInstance().salt;
|
|
42
48
|
const { address, publicKeys, partialAddress } = await account.getCompleteAddress();
|
|
43
49
|
|
|
44
50
|
const out: Record<string, any> = {};
|
|
@@ -49,7 +55,7 @@ export async function createAccount(
|
|
|
49
55
|
out.secretKey = secretKey;
|
|
50
56
|
}
|
|
51
57
|
out.partialAddress = partialAddress;
|
|
52
|
-
out.salt =
|
|
58
|
+
out.salt = instanceSalt;
|
|
53
59
|
out.initHash = account.getInstance().initializationHash;
|
|
54
60
|
} else {
|
|
55
61
|
log(`\nNew account:\n`);
|
|
@@ -59,17 +65,17 @@ export async function createAccount(
|
|
|
59
65
|
log(`Secret key: ${secretKey.toString()}`);
|
|
60
66
|
}
|
|
61
67
|
log(`Partial address: ${partialAddress.toString()}`);
|
|
62
|
-
log(`Salt: ${
|
|
68
|
+
log(`Salt: ${instanceSalt.toString()}`);
|
|
63
69
|
log(`Init hash: ${account.getInstance().initializationHash.toString()}`);
|
|
64
70
|
}
|
|
65
71
|
|
|
66
|
-
let
|
|
67
|
-
let txReceipt;
|
|
72
|
+
let txHash: TxHash | undefined;
|
|
73
|
+
let txReceipt: TxReceipt | undefined;
|
|
68
74
|
if (!registerOnly) {
|
|
69
75
|
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
|
|
70
76
|
|
|
71
77
|
const delegatedDeployment = deployer && !account.address.equals(deployer);
|
|
72
|
-
const from = delegatedDeployment ? deployer :
|
|
78
|
+
const from = delegatedDeployment ? deployer : NO_FROM;
|
|
73
79
|
|
|
74
80
|
const deployAccountOpts: DeployAccountOptions = {
|
|
75
81
|
skipClassPublication: !registerClass,
|
|
@@ -79,11 +85,15 @@ export async function createAccount(
|
|
|
79
85
|
fee: { paymentMethod, gasSettings },
|
|
80
86
|
};
|
|
81
87
|
|
|
88
|
+
const localStart = performance.now();
|
|
82
89
|
const deployMethod = await account.getDeployMethod();
|
|
83
|
-
const
|
|
90
|
+
const sim = await deployMethod.simulate({
|
|
84
91
|
...deployAccountOpts,
|
|
85
92
|
fee: { ...deployAccountOpts.fee, estimateGas: true },
|
|
86
93
|
});
|
|
94
|
+
// estimateGas: true guarantees these fields are present
|
|
95
|
+
const estimatedGas = sim.estimatedGas!;
|
|
96
|
+
const stats = sim.stats!;
|
|
87
97
|
|
|
88
98
|
if (feeOpts.estimateOnly) {
|
|
89
99
|
if (json) {
|
|
@@ -99,7 +109,14 @@ export async function createAccount(
|
|
|
99
109
|
};
|
|
100
110
|
}
|
|
101
111
|
} else {
|
|
102
|
-
|
|
112
|
+
if (verbose) {
|
|
113
|
+
printProfileResult(stats, log);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (!json) {
|
|
117
|
+
log(`\nWaiting for account contract deployment...`);
|
|
118
|
+
}
|
|
119
|
+
const sendOpts = {
|
|
103
120
|
...deployAccountOpts,
|
|
104
121
|
fee: deployAccountOpts.fee
|
|
105
122
|
? {
|
|
@@ -107,37 +124,41 @@ export async function createAccount(
|
|
|
107
124
|
gasSettings: estimatedGas,
|
|
108
125
|
}
|
|
109
126
|
: undefined,
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
({ txHash } = await deployMethod.send({ ...sendOpts, wait: NO_WAIT }));
|
|
130
|
+
const localTimeMs = performance.now() - localStart;
|
|
114
131
|
|
|
115
|
-
const txHash = await tx.getTxHash();
|
|
116
|
-
debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
|
|
117
|
-
out.txHash = txHash;
|
|
118
132
|
if (wait) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
133
|
+
const nodeStart = performance.now();
|
|
134
|
+
txReceipt = await waitForTx(aztecNode, txHash, { timeout: DEFAULT_TX_TIMEOUT_S, waitForStatus });
|
|
135
|
+
const nodeTimeMs = performance.now() - nodeStart;
|
|
136
|
+
|
|
123
137
|
out.txReceipt = {
|
|
124
138
|
status: txReceipt.status,
|
|
125
139
|
transactionFee: txReceipt.transactionFee,
|
|
126
140
|
};
|
|
141
|
+
|
|
142
|
+
if (!json) {
|
|
143
|
+
log(` Local processing time: ${(localTimeMs / 1000).toFixed(1)}s`);
|
|
144
|
+
log(` Node inclusion time: ${(nodeTimeMs / 1000).toFixed(1)}s`);
|
|
145
|
+
}
|
|
127
146
|
}
|
|
147
|
+
debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
|
|
148
|
+
out.txHash = txHash;
|
|
128
149
|
}
|
|
129
150
|
}
|
|
130
151
|
|
|
131
152
|
if (json) {
|
|
132
153
|
log(prettyPrintJSON(out));
|
|
133
154
|
} else {
|
|
134
|
-
if (
|
|
135
|
-
log(`Deploy tx hash: ${
|
|
155
|
+
if (txHash) {
|
|
156
|
+
log(`Deploy tx hash: ${txHash.toString()}`);
|
|
136
157
|
}
|
|
137
158
|
if (txReceipt) {
|
|
138
159
|
log(`Deploy tx fee: ${txReceipt.transactionFee}`);
|
|
139
160
|
}
|
|
140
161
|
}
|
|
141
162
|
|
|
142
|
-
return { alias, address, secretKey, salt };
|
|
163
|
+
return { alias, address, secretKey, salt: instanceSalt };
|
|
143
164
|
}
|
|
@@ -28,7 +28,7 @@ export async function createAuthwit(
|
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const contract =
|
|
31
|
+
const contract = Contract.at(contractAddress, contractArtifact, wallet);
|
|
32
32
|
const call = await contract.methods[functionName](...functionArgs).getFunctionCall();
|
|
33
33
|
|
|
34
34
|
const witness = await wallet.createAuthWit(from, { caller, call });
|
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
|
fee: { ...deployOpts.fee, estimateGas: true },
|
|
76
79
|
});
|
|
80
|
+
// estimateGas: true guarantees these fields are present
|
|
81
|
+
const estimatedGas = sim.estimatedGas!;
|
|
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,
|
|
@@ -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
|
fee: { ...deployAccountOpts.fee, estimateGas: true },
|
|
67
72
|
});
|
|
73
|
+
// estimateGas: true guarantees these fields are present
|
|
74
|
+
const estimatedGas = sim.estimatedGas!;
|
|
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
|
+
}
|