@aztec/cli-wallet 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108
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.d.ts +1 -1
- package/dest/bin/index.js +38 -23
- package/dest/cmds/authorize_action.d.ts +4 -3
- package/dest/cmds/authorize_action.d.ts.map +1 -1
- package/dest/cmds/authorize_action.js +6 -7
- package/dest/cmds/bridge_fee_juice.d.ts +4 -4
- package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
- package/dest/cmds/bridge_fee_juice.js +9 -7
- package/dest/cmds/check_tx.d.ts +5 -3
- package/dest/cmds/check_tx.d.ts.map +1 -1
- package/dest/cmds/check_tx.js +144 -6
- package/dest/cmds/create_account.d.ts +7 -6
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +36 -48
- package/dest/cmds/create_authwit.d.ts +4 -3
- package/dest/cmds/create_authwit.d.ts.map +1 -1
- package/dest/cmds/create_authwit.js +6 -6
- package/dest/cmds/deploy.d.ts +7 -4
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +57 -46
- package/dest/cmds/deploy_account.d.ts +6 -8
- 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 +3 -3
- 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 +3 -3
- package/dest/cmds/index.d.ts.map +1 -1
- package/dest/cmds/index.js +73 -112
- package/dest/cmds/profile.d.ts +7 -4
- package/dest/cmds/profile.d.ts.map +1 -1
- package/dest/cmds/profile.js +9 -4
- package/dest/cmds/register_contract.d.ts +7 -3
- 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 +4 -3
- package/dest/cmds/register_sender.d.ts.map +1 -1
- package/dest/cmds/send.d.ts +8 -9
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +27 -24
- package/dest/cmds/simulate.d.ts +7 -4
- package/dest/cmds/simulate.d.ts.map +1 -1
- package/dest/cmds/simulate.js +9 -4
- package/dest/storage/wallet_db.d.ts +6 -16
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +2 -23
- package/dest/utils/authorizations.d.ts +3 -2
- 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/ecdsa.d.ts +1 -1
- package/dest/utils/options/fees.d.ts +22 -28
- package/dest/utils/options/fees.d.ts.map +1 -1
- package/dest/utils/options/fees.js +66 -133
- package/dest/utils/options/index.d.ts +1 -1
- package/dest/utils/options/options.d.ts +4 -3
- package/dest/utils/options/options.d.ts.map +1 -1
- package/dest/utils/options/options.js +1 -1
- package/dest/utils/profiling.d.ts +1 -1
- package/dest/utils/wallet.d.ts +36 -0
- package/dest/utils/wallet.d.ts.map +1 -0
- package/dest/utils/wallet.js +195 -0
- package/package.json +17 -14
- package/src/bin/index.ts +38 -31
- package/src/cmds/authorize_action.ts +14 -6
- package/src/cmds/bridge_fee_juice.ts +15 -11
- package/src/cmds/check_tx.ts +181 -5
- package/src/cmds/create_account.ts +43 -53
- package/src/cmds/create_authwit.ts +9 -5
- 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 +14 -6
- package/src/cmds/register_contract.ts +9 -11
- package/src/cmds/register_sender.ts +3 -2
- package/src/cmds/send.ts +22 -32
- package/src/cmds/simulate.ts +14 -6
- package/src/storage/wallet_db.ts +3 -31
- package/src/utils/authorizations.ts +3 -1
- package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
- package/src/utils/options/fees.ts +88 -178
- package/src/utils/options/options.ts +3 -2
- package/src/utils/wallet.ts +266 -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
package/src/cmds/check_tx.ts
CHANGED
|
@@ -1,12 +1,188 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { ContractArtifact } from '@aztec/aztec.js/abi';
|
|
2
|
+
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
3
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
4
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
5
|
+
import { ProtocolContractAddress } from '@aztec/aztec.js/protocol';
|
|
6
|
+
import type { TxHash } from '@aztec/aztec.js/tx';
|
|
3
7
|
import type { LogFn } from '@aztec/foundation/log';
|
|
8
|
+
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
9
|
+
import { NoteDao } from '@aztec/stdlib/note';
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
import type { CLIWallet } from '../utils/wallet.js';
|
|
12
|
+
|
|
13
|
+
export async function checkTx(
|
|
14
|
+
wallet: CLIWallet,
|
|
15
|
+
aztecNode: AztecNode,
|
|
16
|
+
txHash: TxHash,
|
|
17
|
+
statusOnly: boolean,
|
|
18
|
+
log: LogFn,
|
|
19
|
+
) {
|
|
6
20
|
if (statusOnly) {
|
|
7
|
-
const receipt = await
|
|
21
|
+
const receipt = await aztecNode.getTxReceipt(txHash);
|
|
8
22
|
return receipt.status;
|
|
9
23
|
} else {
|
|
10
|
-
await inspectTx(
|
|
24
|
+
await inspectTx(wallet, aztecNode, txHash, log);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// The rest of the code here was copied over here from CLI because in CLI I needed to prune the inspect function of the PXE
|
|
29
|
+
// dependency when dropping PXE JSON RPC Server.
|
|
30
|
+
|
|
31
|
+
async function inspectTx(wallet: CLIWallet, aztecNode: AztecNode, txHash: TxHash, log: LogFn) {
|
|
32
|
+
const [receipt, effectsInBlock] = await Promise.all([aztecNode.getTxReceipt(txHash), aztecNode.getTxEffect(txHash)]);
|
|
33
|
+
// Base tx data
|
|
34
|
+
log(`Tx ${txHash.toString()}`);
|
|
35
|
+
log(` Status: ${receipt.status} ${effectsInBlock ? `(${effectsInBlock.data.revertCode.getDescription()})` : ''}`);
|
|
36
|
+
if (receipt.error) {
|
|
37
|
+
log(` Error: ${receipt.error}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!effectsInBlock) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const effects = effectsInBlock.data;
|
|
45
|
+
const artifactMap = await getKnownArtifacts(wallet);
|
|
46
|
+
|
|
47
|
+
log(` Block: ${receipt.blockNumber} (${receipt.blockHash?.toString()})`);
|
|
48
|
+
if (receipt.transactionFee) {
|
|
49
|
+
log(` Fee: ${receipt.transactionFee.toString()}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Public logs
|
|
53
|
+
const publicLogs = effects.publicLogs;
|
|
54
|
+
if (publicLogs.length > 0) {
|
|
55
|
+
log(' Logs:');
|
|
56
|
+
for (const publicLog of publicLogs) {
|
|
57
|
+
log(` ${publicLog.toHumanReadable()}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Public data writes
|
|
62
|
+
const writes = effects.publicDataWrites;
|
|
63
|
+
if (writes.length > 0) {
|
|
64
|
+
log(' Public data writes:');
|
|
65
|
+
for (const write of writes) {
|
|
66
|
+
log(` Leaf ${write.leafSlot.toString()} = ${write.value.toString()}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Created notes
|
|
71
|
+
const notes = effects.noteHashes;
|
|
72
|
+
if (notes.length > 0) {
|
|
73
|
+
log(' Created notes:');
|
|
74
|
+
log(` Total: ${notes.length}`);
|
|
75
|
+
for (const note of notes) {
|
|
76
|
+
log(` Note hash: ${note.toShortString()}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Nullifiers
|
|
81
|
+
const nullifierCount = effects.nullifiers.length;
|
|
82
|
+
const { deployNullifiers, initNullifiers, classNullifiers } = await getKnownNullifiers(wallet, artifactMap);
|
|
83
|
+
if (nullifierCount > 0) {
|
|
84
|
+
log(' Nullifiers:');
|
|
85
|
+
for (const nullifier of effects.nullifiers) {
|
|
86
|
+
const deployed = deployNullifiers[nullifier.toString()];
|
|
87
|
+
const note = deployed
|
|
88
|
+
? (await wallet.getNotes({ siloedNullifier: nullifier, contractAddress: deployed }))[0]
|
|
89
|
+
: undefined;
|
|
90
|
+
const initialized = initNullifiers[nullifier.toString()];
|
|
91
|
+
const registered = classNullifiers[nullifier.toString()];
|
|
92
|
+
if (nullifier.toBuffer().equals(txHash.toBuffer())) {
|
|
93
|
+
log(` Transaction hash nullifier ${nullifier.toShortString()}`);
|
|
94
|
+
} else if (note) {
|
|
95
|
+
inspectNote(note, artifactMap, log, `Nullifier ${nullifier.toShortString()} for note`);
|
|
96
|
+
} else if (deployed) {
|
|
97
|
+
log(
|
|
98
|
+
` Contract ${toFriendlyAddress(deployed, artifactMap)} deployed via nullifier ${nullifier.toShortString()}`,
|
|
99
|
+
);
|
|
100
|
+
} else if (initialized) {
|
|
101
|
+
log(
|
|
102
|
+
` Contract ${toFriendlyAddress(
|
|
103
|
+
initialized,
|
|
104
|
+
artifactMap,
|
|
105
|
+
)} initialized via nullifier ${nullifier.toShortString()}`,
|
|
106
|
+
);
|
|
107
|
+
} else if (registered) {
|
|
108
|
+
log(` Class ${registered} registered via nullifier ${nullifier.toShortString()}`);
|
|
109
|
+
} else {
|
|
110
|
+
log(` Unknown nullifier ${nullifier.toString()}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// L2 to L1 messages
|
|
116
|
+
if (effects.l2ToL1Msgs.length > 0) {
|
|
117
|
+
log(` L2 to L1 messages:`);
|
|
118
|
+
for (const msg of effects.l2ToL1Msgs) {
|
|
119
|
+
log(` ${msg.toString()}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function inspectNote(note: NoteDao, artifactMap: ArtifactMap, log: LogFn, text = 'Note') {
|
|
125
|
+
const artifact = artifactMap[note.contractAddress.toString()];
|
|
126
|
+
const contract = artifact?.name ?? note.contractAddress.toString();
|
|
127
|
+
log(` ${text} at ${contract}`);
|
|
128
|
+
for (const field of note.note.items) {
|
|
129
|
+
log(` ${field.toString()}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function toFriendlyAddress(address: AztecAddress, artifactMap: ArtifactMap) {
|
|
134
|
+
const artifact = artifactMap[address.toString()];
|
|
135
|
+
if (!artifact) {
|
|
136
|
+
return address.toString();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return `${artifact.name}<${address.toString()}>`;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function getKnownNullifiers(wallet: CLIWallet, artifactMap: ArtifactMap) {
|
|
143
|
+
const knownContracts = await wallet.getContracts();
|
|
144
|
+
const deployerAddress = ProtocolContractAddress.ContractInstanceRegistry;
|
|
145
|
+
const classRegistryAddress = ProtocolContractAddress.ContractClassRegistry;
|
|
146
|
+
const initNullifiers: Record<string, AztecAddress> = {};
|
|
147
|
+
const deployNullifiers: Record<string, AztecAddress> = {};
|
|
148
|
+
const classNullifiers: Record<string, string> = {};
|
|
149
|
+
for (const contract of knownContracts) {
|
|
150
|
+
initNullifiers[(await siloNullifier(contract, contract.toField())).toString()] = contract;
|
|
151
|
+
deployNullifiers[(await siloNullifier(deployerAddress, contract.toField())).toString()] = contract;
|
|
152
|
+
}
|
|
153
|
+
for (const artifact of Object.values(artifactMap)) {
|
|
154
|
+
classNullifiers[(await siloNullifier(classRegistryAddress, artifact.classId)).toString()] =
|
|
155
|
+
`${artifact.name}Class<${artifact.classId}>`;
|
|
156
|
+
}
|
|
157
|
+
return { initNullifiers, deployNullifiers, classNullifiers };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
type ArtifactMap = Record<string, ContractArtifactWithClassId>;
|
|
161
|
+
type ContractArtifactWithClassId = ContractArtifact & { classId: Fr };
|
|
162
|
+
|
|
163
|
+
async function getKnownArtifacts(wallet: CLIWallet): Promise<ArtifactMap> {
|
|
164
|
+
const knownContractAddresses = await wallet.getContracts();
|
|
165
|
+
const knownContracts = (
|
|
166
|
+
await Promise.all(knownContractAddresses.map(contractAddress => wallet.getContractMetadata(contractAddress)))
|
|
167
|
+
).map(contractMetadata => contractMetadata.contractInstance);
|
|
168
|
+
const classIds = [...new Set(knownContracts.map(contract => contract?.currentContractClassId))];
|
|
169
|
+
const knownArtifacts = (
|
|
170
|
+
await Promise.all(classIds.map(classId => (classId ? wallet.getContractClassMetadata(classId) : undefined)))
|
|
171
|
+
).map(contractClassMetadata =>
|
|
172
|
+
contractClassMetadata
|
|
173
|
+
? { ...contractClassMetadata.artifact, classId: contractClassMetadata.contractClass?.id }
|
|
174
|
+
: undefined,
|
|
175
|
+
);
|
|
176
|
+
const map: Record<string, ContractArtifactWithClassId> = {};
|
|
177
|
+
for (const instance of knownContracts) {
|
|
178
|
+
if (instance) {
|
|
179
|
+
const artifact = knownArtifacts.find(a =>
|
|
180
|
+
a?.classId?.equals(instance.currentContractClassId),
|
|
181
|
+
) as ContractArtifactWithClassId;
|
|
182
|
+
if (artifact) {
|
|
183
|
+
map[instance.address.toString()] = artifact;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
11
186
|
}
|
|
187
|
+
return map;
|
|
12
188
|
}
|
|
@@ -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
|
-
import { Fr } from '@aztec/foundation/
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
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[],
|
|
@@ -24,10 +28,10 @@ export async function createAuthwit(
|
|
|
24
28
|
);
|
|
25
29
|
}
|
|
26
30
|
|
|
27
|
-
const contract =
|
|
28
|
-
const
|
|
31
|
+
const contract = Contract.at(contractAddress, contractArtifact, wallet);
|
|
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
|
}
|