@aztec/cli-wallet 0.0.0-test.1 → 0.0.1-commit.b655e406

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.
Files changed (105) hide show
  1. package/README.md +30 -0
  2. package/dest/bin/index.js +48 -26
  3. package/dest/cmds/authorize_action.d.ts +3 -2
  4. package/dest/cmds/authorize_action.d.ts.map +1 -1
  5. package/dest/cmds/authorize_action.js +8 -4
  6. package/dest/cmds/bridge_fee_juice.d.ts +2 -2
  7. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
  8. package/dest/cmds/bridge_fee_juice.js +8 -7
  9. package/dest/cmds/check_tx.d.ts +4 -2
  10. package/dest/cmds/check_tx.d.ts.map +1 -1
  11. package/dest/cmds/check_tx.js +145 -6
  12. package/dest/cmds/create_account.d.ts +6 -5
  13. package/dest/cmds/create_account.d.ts.map +1 -1
  14. package/dest/cmds/create_account.js +46 -27
  15. package/dest/cmds/create_authwit.d.ts +3 -2
  16. package/dest/cmds/create_authwit.d.ts.map +1 -1
  17. package/dest/cmds/create_authwit.js +5 -5
  18. package/dest/cmds/deploy.d.ts +6 -3
  19. package/dest/cmds/deploy.d.ts.map +1 -1
  20. package/dest/cmds/deploy.js +71 -54
  21. package/dest/cmds/deploy_account.d.ts +5 -7
  22. package/dest/cmds/deploy_account.d.ts.map +1 -1
  23. package/dest/cmds/deploy_account.js +46 -29
  24. package/dest/cmds/import_test_accounts.d.ts +2 -2
  25. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  26. package/dest/cmds/import_test_accounts.js +6 -9
  27. package/dest/cmds/index.d.ts +2 -2
  28. package/dest/cmds/index.d.ts.map +1 -1
  29. package/dest/cmds/index.js +83 -115
  30. package/dest/cmds/profile.d.ts +8 -0
  31. package/dest/cmds/profile.d.ts.map +1 -0
  32. package/dest/cmds/profile.js +28 -0
  33. package/dest/cmds/register_contract.d.ts +6 -2
  34. package/dest/cmds/register_contract.d.ts.map +1 -1
  35. package/dest/cmds/register_contract.js +20 -7
  36. package/dest/cmds/register_sender.d.ts +3 -2
  37. package/dest/cmds/register_sender.d.ts.map +1 -1
  38. package/dest/cmds/send.d.ts +7 -8
  39. package/dest/cmds/send.d.ts.map +1 -1
  40. package/dest/cmds/send.js +31 -20
  41. package/dest/cmds/simulate.d.ts +6 -2
  42. package/dest/cmds/simulate.d.ts.map +1 -1
  43. package/dest/cmds/simulate.js +25 -19
  44. package/dest/storage/wallet_db.d.ts +4 -16
  45. package/dest/storage/wallet_db.d.ts.map +1 -1
  46. package/dest/storage/wallet_db.js +2 -23
  47. package/dest/utils/authorizations.d.ts +6 -0
  48. package/dest/utils/authorizations.d.ts.map +1 -0
  49. package/dest/utils/authorizations.js +28 -0
  50. package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
  51. package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
  52. package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
  53. package/dest/utils/ecdsa.d.ts +0 -2
  54. package/dest/utils/ecdsa.d.ts.map +1 -1
  55. package/dest/utils/options/fees.d.ts +20 -27
  56. package/dest/utils/options/fees.d.ts.map +1 -1
  57. package/dest/utils/options/fees.js +85 -144
  58. package/dest/utils/options/options.d.ts +8 -4
  59. package/dest/utils/options/options.d.ts.map +1 -1
  60. package/dest/utils/options/options.js +26 -14
  61. package/dest/utils/profiling.d.ts +5 -0
  62. package/dest/utils/profiling.d.ts.map +1 -0
  63. package/dest/utils/profiling.js +60 -0
  64. package/dest/utils/wallet.d.ts +35 -0
  65. package/dest/utils/wallet.d.ts.map +1 -0
  66. package/dest/utils/wallet.js +193 -0
  67. package/package.json +24 -20
  68. package/src/bin/index.ts +56 -32
  69. package/src/cmds/authorize_action.ts +15 -4
  70. package/src/cmds/bridge_fee_juice.ts +14 -11
  71. package/src/cmds/check_tx.ts +182 -5
  72. package/src/cmds/create_account.ts +55 -32
  73. package/src/cmds/create_authwit.ts +8 -4
  74. package/src/cmds/deploy.ts +79 -62
  75. package/src/cmds/deploy_account.ts +57 -28
  76. package/src/cmds/import_test_accounts.ts +7 -11
  77. package/src/cmds/index.ts +256 -220
  78. package/src/cmds/profile.ts +48 -0
  79. package/src/cmds/register_contract.ts +28 -5
  80. package/src/cmds/register_sender.ts +3 -2
  81. package/src/cmds/send.ts +31 -17
  82. package/src/cmds/simulate.ts +39 -23
  83. package/src/storage/wallet_db.ts +3 -31
  84. package/src/utils/authorizations.ts +51 -0
  85. package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
  86. package/src/utils/options/fees.ts +134 -206
  87. package/src/utils/options/options.ts +41 -19
  88. package/src/utils/profiling.ts +158 -0
  89. package/src/utils/wallet.ts +264 -0
  90. package/dest/cmds/add_authwit.d.ts +0 -4
  91. package/dest/cmds/add_authwit.d.ts.map +0 -1
  92. package/dest/cmds/add_authwit.js +0 -4
  93. package/dest/cmds/cancel_tx.d.ts +0 -11
  94. package/dest/cmds/cancel_tx.d.ts.map +0 -1
  95. package/dest/cmds/cancel_tx.js +0 -38
  96. package/dest/utils/accounts.d.ts +0 -11
  97. package/dest/utils/accounts.d.ts.map +0 -1
  98. package/dest/utils/accounts.js +0 -87
  99. package/dest/utils/pxe_wrapper.d.ts +0 -10
  100. package/dest/utils/pxe_wrapper.d.ts.map +0 -1
  101. package/dest/utils/pxe_wrapper.js +0 -21
  102. package/src/cmds/add_authwit.ts +0 -13
  103. package/src/cmds/cancel_tx.ts +0 -62
  104. package/src/utils/accounts.ts +0 -102
  105. package/src/utils/pxe_wrapper.ts +0 -26
@@ -1,31 +1,25 @@
1
1
  import { getIdentities } from '@aztec/accounts/utils';
2
- import { createCompatibleClient } from '@aztec/aztec.js/rpc';
3
- import { TxHash } from '@aztec/aztec.js/tx_hash';
4
- import { ETHEREUM_HOSTS, PRIVATE_KEY, addOptions, createSecretKeyOption, l1ChainIdOption, logJson, parseBigint, parseFieldFromHexString, parsePublicKey, pxeOption } from '@aztec/cli/utils';
5
- import { GasFees } from '@aztec/stdlib/gas';
6
- import { createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
2
+ import { TxHash } from '@aztec/aztec.js/tx';
3
+ import { ETHEREUM_HOSTS, PRIVATE_KEY, addOptions, createSecretKeyOption, l1ChainIdOption, parseBigint, parseFieldFromHexString, parsePublicKey } from '@aztec/cli/utils';
4
+ import { randomBytes } from '@aztec/foundation/crypto';
7
5
  import { Option } from 'commander';
8
6
  import inquirer from 'inquirer';
9
- import { addScopeToWallet, createOrRetrieveAccount, getWalletWithScopes } from '../utils/accounts.js';
10
- import { FeeOpts, FeeOptsWithFeePayer } from '../utils/options/fees.js';
11
- import { ARTIFACT_DESCRIPTION, aliasedAddressParser, aliasedAuthWitParser, aliasedSecretKeyParser, aliasedTxHashParser, artifactPathFromPromiseOrAlias, artifactPathParser, createAccountOption, createAliasOption, createArgsOption, createArtifactOption, createContractAddressOption, createProfileOption, createTypeOption, integerArgParser, parseGasFees, parsePaymentMethod } from '../utils/options/index.js';
12
- export function injectCommands(program, log, debugLogger, db, pxeWrapper) {
13
- program.command('import-test-accounts').description('Import test accounts from pxe.').addOption(pxeOption).option('--json', 'Emit output as json').action(async (options)=>{
14
- if (!db) {
15
- throw new Error(`A db is required to store the imported test accounts.`);
16
- }
7
+ import { ARTIFACT_DESCRIPTION, CLIFeeArgs, aliasedAddressParser, aliasedSecretKeyParser, aliasedTxHashParser, artifactPathFromPromiseOrAlias, artifactPathParser, cleanupAuthWitnesses, createAccountOption, createAliasOption, createArgsOption, createArtifactOption, createAuthwitnessOption, createContractAddressOption, createDebugExecutionStepsDirOption, createTypeOption, createVerboseOption, integerArgParser } from '../utils/options/index.js';
8
+ // TODO: This function is only used in 1 place so we could just inline this
9
+ export function injectCommands(program, log, debugLogger, walletAndNodeWrapper, db) {
10
+ program.command('import-test-accounts').description('Import test accounts from pxe.').option('--json', 'Emit output as json').action(async (options)=>{
11
+ const { json } = options;
12
+ const wallet = walletAndNodeWrapper.wallet;
17
13
  const { importTestAccounts } = await import('./import_test_accounts.js');
18
- const { rpcUrl, json } = options;
19
- const client = pxeWrapper?.getPXE() ?? await createCompatibleClient(rpcUrl, debugLogger);
20
- await importTestAccounts(client, db, json, log);
14
+ await importTestAccounts(wallet, db, json, log);
21
15
  });
22
- const createAccountCommand = program.command('create-account').description('Creates an aztec account that can be used for sending transactions. Registers the account on the PXE and deploys an account contract. Uses a Schnorr single-key account which uses the same key for encryption and authentication (not secure for production usage).').summary('Creates an aztec account that can be used for sending transactions.').option('--skip-initialization', 'Skip initializing the account contract. Useful for publicly deploying an existing account.').option('--public-deploy', 'Publicly deploys the account and registers the class if needed.').option('-p, --public-key <string>', 'Public key that identifies a private signing key stored outside of the wallet. Used for ECDSA SSH accounts over the secp256r1 curve.').addOption(pxeOption).addOption(createSecretKeyOption('Secret key for account. Uses random by default.', false, (sk)=>aliasedSecretKeyParser(sk, db)).conflicts('public-key')).addOption(createAliasOption('Alias for the account. Used for easy reference in subsequent commands.', !db)).addOption(createTypeOption(true)).option('--register-only', 'Just register the account on the PXE. Do not deploy or initialize the account contract.').option('--json', 'Emit output as json')// `options.wait` is default true. Passing `--no-wait` will set it to false.
16
+ const createAccountCommand = program.command('create-account').description('Creates an aztec account that can be used for sending transactions. Registers the account on the PXE and deploys an account contract. Uses a Schnorr single-key account which uses the same key for encryption and authentication (not secure for production usage).').summary('Creates an aztec account that can be used for sending transactions.').addOption(createAccountOption('Alias or address of the account performing the deployment', !db, db)).option('--skip-initialization', 'Skip initializing the account contract. Useful for publicly deploying an existing account.').option('--public-deploy', 'Publishes the account contract instance (and the class, if needed). Needed if the contract contains public functions.').option('--register-class', 'Register the contract class (useful for when the contract class has not been deployed yet).').option('-p, --public-key <string>', 'Public key that identifies a private signing key stored outside of the wallet. Used for ECDSA SSH accounts over the secp256r1 curve.').addOption(createSecretKeyOption('Secret key for account. Uses random by default.', false, (sk)=>aliasedSecretKeyParser(sk, db)).conflicts('public-key')).addOption(createAliasOption('Alias for the account. Used for easy reference in subsequent commands.', !db)).addOption(createTypeOption(true)).option('--register-only', 'Just register the account on the Wallet. Do not deploy or initialize the account contract.').option('--json', 'Emit output as json')// `options.wait` is default true. Passing `--no-wait` will set it to false.
23
17
  // https://github.com/tj/commander.js#other-option-types-negatable-boolean-and-booleanvalue
24
- .option('--no-wait', 'Skip waiting for the contract to be deployed. Print the hash of deployment transaction');
25
- addOptions(createAccountCommand, FeeOptsWithFeePayer.getOptions()).action(async (_options, command)=>{
18
+ .option('--no-wait', 'Skip waiting for the contract to be deployed. Print the hash of deployment transaction').addOption(createVerboseOption());
19
+ addOptions(createAccountCommand, CLIFeeArgs.getOptions()).action(async (_options, command)=>{
26
20
  const { createAccount } = await import('./create_account.js');
27
21
  const options = command.optsWithGlobals();
28
- const { type, secretKey, wait, registerOnly, skipInitialization, publicDeploy, rpcUrl, alias, json } = options;
22
+ const { type, from: parsedFromAddress, secretKey, wait, registerOnly, skipInitialization, publicDeploy, registerClass, alias, json, verbose } = options;
29
23
  let { publicKey } = options;
30
24
  if (type === 'ecdsasecp256r1ssh' && !publicKey) {
31
25
  const identities = await getIdentities();
@@ -39,8 +33,8 @@ export function injectCommands(program, log, debugLogger, db, pxeWrapper) {
39
33
  ]);
40
34
  publicKey = answers.identity.split(' ')[1];
41
35
  }
42
- const client = pxeWrapper?.getPXE() ?? await createCompatibleClient(rpcUrl, debugLogger);
43
- const accountCreationResult = await createAccount(client, type, secretKey, publicKey, alias, registerOnly, skipInitialization, publicDeploy, wait, await FeeOptsWithFeePayer.fromCli(options, client, log, db), json, debugLogger, log);
36
+ const { wallet, node } = walletAndNodeWrapper;
37
+ const accountCreationResult = await createAccount(wallet, node, type, secretKey, publicKey, alias, parsedFromAddress, registerOnly, skipInitialization, publicDeploy, registerClass, wait, CLIFeeArgs.parse(options, log, db), json, verbose, debugLogger, log);
44
38
  if (db) {
45
39
  const { address, alias, secretKey, salt } = accountCreationResult;
46
40
  await db.storeAccount(address, {
@@ -52,113 +46,105 @@ export function injectCommands(program, log, debugLogger, db, pxeWrapper) {
52
46
  }, log);
53
47
  }
54
48
  });
55
- const deployAccountCommand = program.command('deploy-account').description('Deploys an already registered aztec account that can be used for sending transactions.').addOption(createAccountOption('Alias or address of the account to deploy', !db, db)).addOption(pxeOption).option('--json', 'Emit output as json')// `options.wait` is default true. Passing `--no-wait` will set it to false.
49
+ const deployAccountCommand = program.command('deploy-account').description('Deploys an already registered aztec account that can be used for sending transactions.').argument('<address>', 'The address of the contract to register', (address)=>aliasedAddressParser('accounts', address, db)).addOption(createAccountOption('Alias or address of the account performing the deployment', !db, db)).option('--json', 'Emit output as json')// `options.wait` is default true. Passing `--no-wait` will set it to false.
56
50
  // https://github.com/tj/commander.js#other-option-types-negatable-boolean-and-booleanvalue
57
- .option('--no-wait', 'Skip waiting for the contract to be deployed. Print the hash of deployment transaction');
58
- addOptions(deployAccountCommand, FeeOptsWithFeePayer.getOptions()).action(async (_options, command)=>{
51
+ .option('--no-wait', 'Skip waiting for the contract to be deployed. Print the hash of deployment transaction').option('--register-class', 'Register the contract class (useful for when the contract class has not been deployed yet).').option('--public-deploy', 'Publishes the account contract instance (and the class, if needed). Needed if the contract contains public functions.').option('--skip-initialization', 'Skip initializing the account contract. Useful for publicly deploying an existing account.').addOption(createVerboseOption());
52
+ addOptions(deployAccountCommand, CLIFeeArgs.getOptions()).action(async (parsedAccount, _options, command)=>{
59
53
  const { deployAccount } = await import('./deploy_account.js');
60
54
  const options = command.optsWithGlobals();
61
- const { rpcUrl, wait, from: parsedFromAddress, json } = options;
62
- const client = pxeWrapper?.getPXE() ?? await createCompatibleClient(rpcUrl, debugLogger);
63
- const account = await createOrRetrieveAccount(client, parsedFromAddress, db);
64
- await deployAccount(account, wait, await FeeOptsWithFeePayer.fromCli(options, client, log, db), json, debugLogger, log);
55
+ const { wait, from: parsedFromAddress, json, registerClass, skipInitialization, publicDeploy, verbose } = options;
56
+ const { wallet, node } = walletAndNodeWrapper;
57
+ await deployAccount(wallet, node, parsedAccount, wait, parsedFromAddress, registerClass, publicDeploy, skipInitialization, CLIFeeArgs.parse(options, log, db), json, verbose, debugLogger, log);
65
58
  });
66
- const deployCommand = program.command('deploy').description('Deploys a compiled Aztec.nr contract to Aztec.').argument('[artifact]', ARTIFACT_DESCRIPTION, artifactPathParser).option('--init <string>', 'The contract initializer function to call', 'constructor').option('--no-init', 'Leave the contract uninitialized').option('-k, --public-key <string>', 'Optional encryption public key for this address. Set this value only if this contract is expected to receive private notes, which will be encrypted using this public key.', parsePublicKey).option('-s, --salt <hex string>', 'Optional deployment salt as a hex string for generating the deployment address.', parseFieldFromHexString).option('--universal', 'Do not mix the sender address into the deployment.').addOption(pxeOption).addOption(createArgsOption(true, db)).addOption(createSecretKeyOption("The sender's secret key", !db, (sk)=>aliasedSecretKeyParser(sk, db)).conflicts('account')).addOption(createAccountOption('Alias or address of the account to deploy from', !db, db)).addOption(createAliasOption('Alias for the contract. Used for easy reference subsequent commands.', !db)).option('--json', 'Emit output as json')// `options.wait` is default true. Passing `--no-wait` will set it to false.
59
+ const deployCommand = program.command('deploy').description('Deploys a compiled Aztec.nr contract to Aztec.').argument('[artifact]', ARTIFACT_DESCRIPTION, artifactPathParser).option('--init <string>', 'The contract initializer function to call', 'constructor').option('--no-init', 'Leave the contract uninitialized').option('-k, --public-key <string>', 'Optional encryption public key for this address. Set this value only if this contract is expected to receive private notes, which will be encrypted using this public key.', parsePublicKey).option('-s, --salt <hex string>', 'Optional deployment salt as a hex string for generating the deployment address.', parseFieldFromHexString).option('--universal', 'Do not mix the sender address into the deployment.').addOption(createArgsOption(true, db)).addOption(createAccountOption('Alias or address of the account to deploy from', !db, db)).addOption(createAliasOption('Alias for the contract. Used for easy reference subsequent commands.', !db)).option('--json', 'Emit output as json')// `options.wait` is default true. Passing `--no-wait` will set it to false.
67
60
  // https://github.com/tj/commander.js#other-option-types-negatable-boolean-and-booleanvalue
68
- .option('--no-wait', 'Skip waiting for the contract to be deployed. Print the hash of deployment transaction').option('--no-class-registration', "Don't register this contract class").option('--no-public-deployment', "Don't emit this contract's public bytecode");
69
- addOptions(deployCommand, FeeOpts.getOptions()).action(async (artifactPathPromise, _options, command)=>{
61
+ .option('--no-wait', 'Skip waiting for the contract to be deployed. Print the hash of deployment transaction').option('--no-class-registration', "Don't register this contract class").option('--no-public-deployment', "Don't emit this contract's public bytecode").addOption(new Option('--timeout <number>', 'The amount of time in seconds to wait for the deployment to post to L2').conflicts('wait')).addOption(createVerboseOption());
62
+ addOptions(deployCommand, CLIFeeArgs.getOptions()).action(async (artifactPathPromise, _options, command)=>{
70
63
  const { deploy } = await import('./deploy.js');
71
64
  const options = command.optsWithGlobals();
72
- const { json, publicKey, args, salt, wait, secretKey, classRegistration, init, publicDeployment, universal, rpcUrl, from: parsedFromAddress, alias } = options;
73
- const client = pxeWrapper?.getPXE() ?? await createCompatibleClient(rpcUrl, debugLogger);
74
- const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
75
- const wallet = await getWalletWithScopes(account, db);
65
+ const { json, publicKey, args, salt, wait, classRegistration, init, publicDeployment, universal, from: parsedFromAddress, alias, timeout, verbose } = options;
66
+ const { wallet, node } = walletAndNodeWrapper;
76
67
  const artifactPath = await artifactPathPromise;
77
- debugLogger.info(`Using wallet with address ${wallet.getCompleteAddress().address.toString()}`);
78
- const address = await deploy(client, wallet, artifactPath, json, publicKey, args, salt, typeof init === 'string' ? init : undefined, !publicDeployment, !classRegistration, typeof init === 'string' ? false : init, universal, wait, await FeeOpts.fromCli(options, client, log, db), debugLogger, log, logJson(log));
68
+ debugLogger.info(`Using wallet with address ${parsedFromAddress.toString()}`);
69
+ const address = await deploy(wallet, node, universal ? undefined : parsedFromAddress, artifactPath, json, publicKey, args, salt, typeof init === 'string' ? init : undefined, !publicDeployment, !classRegistration, typeof init === 'string' ? false : init, wait, CLIFeeArgs.parse(options, log, db), timeout, verbose, debugLogger, log);
79
70
  if (db && address) {
80
71
  await db.storeContract(address, artifactPath, log, alias);
81
72
  }
82
73
  });
83
- const sendCommand = program.command('send').description('Calls a function on an Aztec contract.').argument('<functionName>', 'Name of function to execute').addOption(pxeOption).addOption(createArgsOption(false, db)).addOption(createArtifactOption(db)).addOption(createContractAddressOption(db)).addOption(createAliasOption('Alias for the transaction hash. Used for easy reference in subsequent commands.', !db)).addOption(createSecretKeyOption("The sender's secret key", !db, (sk)=>aliasedSecretKeyParser(sk, db)).conflicts('account')).addOption(createAccountOption('Alias or address of the account to send the transaction from', !db, db)).option('--no-wait', 'Print transaction hash without waiting for it to be mined').option('--no-cancel', 'Do not allow the transaction to be cancelled. This makes for cheaper transactions.');
84
- addOptions(sendCommand, FeeOpts.getOptions()).action(async (functionName, _options, command)=>{
74
+ const sendCommand = program.command('send').description('Calls a function on an Aztec contract.').argument('<functionName>', 'Name of function to execute').addOption(createArgsOption(false, db)).addOption(createArtifactOption(db)).addOption(createContractAddressOption(db)).addOption(createAliasOption('Alias for the transaction hash. Used for easy reference in subsequent commands.', !db)).addOption(createAuthwitnessOption('Authorization witness to use for the transaction. If using multiple, pass a comma separated string', !db, db)).addOption(createAccountOption('Alias or address of the account to send the transaction from', !db, db)).option('--no-wait', 'Print transaction hash without waiting for it to be mined').addOption(createVerboseOption());
75
+ addOptions(sendCommand, CLIFeeArgs.getOptions()).action(async (functionName, _options, command)=>{
85
76
  const { send } = await import('./send.js');
86
77
  const options = command.optsWithGlobals();
87
- const { args, contractArtifact: artifactPathPromise, contractAddress, from: parsedFromAddress, wait, rpcUrl, secretKey, alias, cancel } = options;
88
- const client = pxeWrapper?.getPXE() ?? await createCompatibleClient(rpcUrl, debugLogger);
89
- const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
90
- const wallet = await getWalletWithScopes(account, db);
78
+ const { args, contractArtifact: artifactPathPromise, contractAddress, from: parsedFromAddress, wait, alias, authWitness: authWitnessArray, verbose } = options;
79
+ const { wallet, node } = walletAndNodeWrapper;
91
80
  const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db);
92
- debugLogger.info(`Using wallet with address ${wallet.getCompleteAddress().address.toString()}`);
93
- const sentTx = await send(wallet, functionName, args, artifactPath, contractAddress, wait, cancel, await FeeOpts.fromCli(options, client, log, db), log);
81
+ debugLogger.info(`Using wallet with address ${parsedFromAddress.toString()}`);
82
+ const authWitnesses = cleanupAuthWitnesses(authWitnessArray);
83
+ const sentTx = await send(wallet, node, parsedFromAddress, functionName, args, artifactPath, contractAddress, wait, alias, CLIFeeArgs.parse(options, log, db), authWitnesses, verbose, log);
94
84
  if (db && sentTx) {
95
- const txAlias = alias ? alias : `${functionName}-${sentTx.nonce.toString().slice(-4)}`;
85
+ const txAlias = alias ? alias : `${functionName}-${randomBytes(16).toString()}`;
96
86
  await db.storeTx(sentTx, log, txAlias);
97
87
  }
98
88
  });
99
- program.command('simulate').description('Simulates the execution of a function on an Aztec contract.').argument('<functionName>', 'Name of function to simulate').addOption(pxeOption).addOption(createArgsOption(false, db)).addOption(createContractAddressOption(db)).addOption(createArtifactOption(db)).addOption(createSecretKeyOption("The sender's secret key", !db, (sk)=>aliasedSecretKeyParser(sk, db)).conflicts('account')).addOption(createAccountOption('Alias or address of the account to simulate from', !db, db)).addOption(createProfileOption()).action(async (functionName, _options, command)=>{
89
+ const simulateCommand = program.command('simulate').description('Simulates the execution of a function on an Aztec contract.').argument('<functionName>', 'Name of function to simulate').addOption(createArgsOption(false, db)).addOption(createContractAddressOption(db)).addOption(createArtifactOption(db)).addOption(createSecretKeyOption("The sender's secret key", !db, (sk)=>aliasedSecretKeyParser(sk, db)).conflicts('account')).addOption(createAuthwitnessOption('Authorization witness to use for the simulation', !db, db)).addOption(createAccountOption('Alias or address of the account to simulate from', !db, db)).addOption(createVerboseOption());
90
+ addOptions(simulateCommand, CLIFeeArgs.getOptions()).action(async (functionName, _options, command)=>{
100
91
  const { simulate } = await import('./simulate.js');
101
92
  const options = command.optsWithGlobals();
102
- const { args, contractArtifact: artifactPathPromise, contractAddress, from: parsedFromAddress, rpcUrl, secretKey, profile } = options;
103
- const client = pxeWrapper?.getPXE() ?? await createCompatibleClient(rpcUrl, debugLogger);
104
- const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
105
- const wallet = await getWalletWithScopes(account, db);
93
+ const { args, contractArtifact: artifactPathPromise, contractAddress, from: parsedFromAddress, verbose, authWitness } = options;
94
+ const { wallet, node } = walletAndNodeWrapper;
95
+ const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db);
96
+ const authWitnesses = cleanupAuthWitnesses(authWitness);
97
+ await simulate(wallet, node, parsedFromAddress, functionName, args, artifactPath, contractAddress, CLIFeeArgs.parse(options, log, db), authWitnesses, verbose, log);
98
+ });
99
+ const profileCommand = program.command('profile').description('Profiles a private function by counting the unconditional operations in its execution steps').argument('<functionName>', 'Name of function to simulate').addOption(createArgsOption(false, db)).addOption(createContractAddressOption(db)).addOption(createArtifactOption(db)).addOption(createDebugExecutionStepsDirOption()).addOption(createAuthwitnessOption('Authorization witness to use for the simulation', !db, db)).addOption(createAccountOption('Alias or address of the account to simulate from', !db, db));
100
+ addOptions(profileCommand, CLIFeeArgs.getOptions()).action(async (functionName, _options, command)=>{
101
+ const { profile } = await import('./profile.js');
102
+ const options = command.optsWithGlobals();
103
+ const { args, contractArtifact: artifactPathPromise, contractAddress, from: parsedFromAddress, debugExecutionStepsDir, authWitness } = options;
104
+ const { wallet, node } = walletAndNodeWrapper;
106
105
  const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db);
107
- await simulate(wallet, functionName, args, artifactPath, contractAddress, profile, log);
106
+ const authWitnesses = cleanupAuthWitnesses(authWitness);
107
+ await profile(wallet, node, parsedFromAddress, functionName, args, artifactPath, contractAddress, debugExecutionStepsDir, CLIFeeArgs.parse(options, log, db), authWitnesses, log);
108
108
  });
109
109
  program.command('bridge-fee-juice').description('Mints L1 Fee Juice and pushes them to L2.').argument('<amount>', 'The amount of Fee Juice to mint and bridge.', parseBigint).argument('<recipient>', 'Aztec address of the recipient.', (address)=>aliasedAddressParser('accounts', address, db)).requiredOption('--l1-rpc-urls <string>', 'List of Ethereum host URLs. Chain identifiers localhost and testnet can be used (comma separated)', (arg)=>arg.split(','), [
110
110
  ETHEREUM_HOSTS
111
- ]).option('-m, --mnemonic <string>', 'The mnemonic to use for deriving the Ethereum address that will mint and bridge', 'test test test test test test test test test test test junk').option('--mint', 'Mint the tokens on L1', false).option('--l1-private-key <string>', 'The private key to the eth account bridging', PRIVATE_KEY).addOption(pxeOption).addOption(l1ChainIdOption).option('--json', 'Output the claim in JSON format')// `options.wait` is default true. Passing `--no-wait` will set it to false.
111
+ ]).option('-m, --mnemonic <string>', 'The mnemonic to use for deriving the Ethereum address that will mint and bridge', 'test test test test test test test test test test test junk').option('--mint', 'Mint the tokens on L1', false).option('--l1-private-key <string>', 'The private key to the eth account bridging', PRIVATE_KEY).addOption(l1ChainIdOption).option('--json', 'Output the claim in JSON format')// `options.wait` is default true. Passing `--no-wait` will set it to false.
112
112
  // https://github.com/tj/commander.js#other-option-types-negatable-boolean-and-booleanvalue
113
- .option('--no-wait', 'Wait for the brigded funds to be available in L2, polling every 60 seconds').addOption(new Option('--interval <number>', 'The polling interval in seconds for the bridged funds').default('60').conflicts('wait')).action(async (amount, recipient, options)=>{
113
+ .option('--no-wait', 'Wait for the bridged funds to be available in L2, polling every 60 seconds').addOption(new Option('--interval <number>', 'The polling interval in seconds for the bridged funds').default('60').conflicts('wait')).action(async (amount, recipient, options)=>{
114
114
  const { bridgeL1FeeJuice } = await import('./bridge_fee_juice.js');
115
- const { rpcUrl, l1ChainId, l1RpcUrls, l1PrivateKey, mnemonic, mint, json, wait, interval: intervalS } = options;
116
- const client = pxeWrapper?.getPXE() ?? await createCompatibleClient(rpcUrl, debugLogger);
117
- const [secret, messageLeafIndex] = await bridgeL1FeeJuice(amount, recipient, client, l1RpcUrls, l1ChainId, l1PrivateKey, mnemonic, mint, json, wait, intervalS * 1000, log, debugLogger);
115
+ const { l1ChainId, l1RpcUrls, l1PrivateKey, mnemonic, mint, json, wait, interval: intervalS } = options;
116
+ const [secret, messageLeafIndex] = await bridgeL1FeeJuice(amount, recipient, walletAndNodeWrapper.node, l1RpcUrls, l1ChainId, l1PrivateKey, mnemonic, mint, json, wait, intervalS * 1000, log, debugLogger);
118
117
  if (db) {
119
118
  await db.pushBridgedFeeJuice(recipient, secret, amount, messageLeafIndex, log);
120
119
  }
121
120
  });
122
- program.command('create-authwit').description('Creates an authorization witness that can be privately sent to a caller so they can perform an action on behalf of the provided account').argument('<functionName>', 'Name of function to authorize').argument('<caller>', 'Account to be authorized to perform the action', (address)=>aliasedAddressParser('accounts', address, db)).addOption(pxeOption).addOption(createArgsOption(false, db)).addOption(createContractAddressOption(db)).addOption(createArtifactOption(db)).addOption(createSecretKeyOption("The sender's secret key", !db, (sk)=>aliasedSecretKeyParser(sk, db)).conflicts('account')).addOption(createAccountOption('Alias or address of the account to simulate from', !db, db)).addOption(createAliasOption('Alias for the authorization witness. Used for easy reference in subsequent commands.', !db)).action(async (functionName, caller, _options, command)=>{
121
+ program.command('create-authwit').description('Creates an authorization witness that can be privately sent to a caller so they can perform an action on behalf of the provided account').argument('<functionName>', 'Name of function to authorize').argument('<caller>', 'Account to be authorized to perform the action', (address)=>aliasedAddressParser('accounts', address, db)).addOption(createArgsOption(false, db)).addOption(createContractAddressOption(db)).addOption(createArtifactOption(db)).addOption(createAccountOption('Alias or address of the account to simulate from', !db, db)).addOption(createAliasOption('Alias for the authorization witness. Used for easy reference in subsequent commands.', !db)).action(async (functionName, caller, _options, command)=>{
123
122
  const { createAuthwit } = await import('./create_authwit.js');
124
123
  const options = command.optsWithGlobals();
125
- const { args, contractArtifact: artifactPathPromise, contractAddress, from: parsedFromAddress, rpcUrl, secretKey, alias } = options;
126
- const client = pxeWrapper?.getPXE() ?? await createCompatibleClient(rpcUrl, debugLogger);
127
- const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
128
- const wallet = await getWalletWithScopes(account, db);
124
+ const { args, contractArtifact: artifactPathPromise, contractAddress, from: parsedFromAddress, alias } = options;
125
+ const wallet = walletAndNodeWrapper.wallet;
129
126
  const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db);
130
- const witness = await createAuthwit(wallet, functionName, caller, args, artifactPath, contractAddress, log);
127
+ const witness = await createAuthwit(wallet, parsedFromAddress, functionName, caller, args, artifactPath, contractAddress, log);
131
128
  if (db) {
132
129
  await db.storeAuthwitness(witness, log, alias);
133
130
  }
134
131
  });
135
- program.command('authorize-action').description('Authorizes a public call on the caller, so they can perform an action on behalf of the provided account').argument('<functionName>', 'Name of function to authorize').argument('<caller>', 'Account to be authorized to perform the action', (address)=>aliasedAddressParser('accounts', address, db)).addOption(pxeOption).addOption(createArgsOption(false, db)).addOption(createContractAddressOption(db)).addOption(createArtifactOption(db)).addOption(createSecretKeyOption("The sender's secret key", !db, (sk)=>aliasedSecretKeyParser(sk, db)).conflicts('account')).addOption(createAccountOption('Alias or address of the account to simulate from', !db, db)).action(async (functionName, caller, _options, command)=>{
132
+ program.command('authorize-action').description('Authorizes a public call on the caller, so they can perform an action on behalf of the provided account').argument('<functionName>', 'Name of function to authorize').argument('<caller>', 'Account to be authorized to perform the action', (address)=>aliasedAddressParser('accounts', address, db)).addOption(createArgsOption(false, db)).addOption(createContractAddressOption(db)).addOption(createArtifactOption(db)).addOption(createAccountOption('Alias or address of the account to simulate from', !db, db)).action(async (functionName, caller, _options, command)=>{
136
133
  const { authorizeAction } = await import('./authorize_action.js');
137
134
  const options = command.optsWithGlobals();
138
- const { args, contractArtifact: artifactPathPromise, contractAddress, from: parsedFromAddress, rpcUrl, secretKey } = options;
139
- const client = pxeWrapper?.getPXE() ?? await createCompatibleClient(rpcUrl, debugLogger);
140
- const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
141
- const wallet = await getWalletWithScopes(account, db);
135
+ const { args, contractArtifact: artifactPathPromise, contractAddress, from: parsedFromAddress } = options;
136
+ const wallet = walletAndNodeWrapper.wallet;
142
137
  const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db);
143
- await authorizeAction(wallet, functionName, caller, args, artifactPath, contractAddress, log);
138
+ await authorizeAction(wallet, parsedFromAddress, functionName, caller, args, artifactPath, contractAddress, log);
144
139
  });
145
- program.command('add-authwit').description('Adds an authorization witness to the provided account, granting PXE access to the notes of the authorizer so that it can be verified').argument('<authwit>', 'Authorization witness to add to the account', (witness)=>aliasedAuthWitParser(witness, db)).argument('<authorizer>', 'Account that provides the authorization to perform the action', (address)=>aliasedAddressParser('accounts', address, db)).addOption(pxeOption).addOption(createSecretKeyOption("The sender's secret key", !db, (sk)=>aliasedSecretKeyParser(sk, db)).conflicts('account')).addOption(createAccountOption('Alias or address of the account to simulate from', !db, db)).addOption(createAliasOption('Alias for the authorization witness. Used for easy reference in subsequent commands.', !db)).action(async (authwit, authorizer, _options, command)=>{
146
- const { addAuthwit } = await import('./add_authwit.js');
147
- const options = command.optsWithGlobals();
148
- const { from: parsedFromAddress, rpcUrl, secretKey } = options;
149
- const client = pxeWrapper?.getPXE() ?? await createCompatibleClient(rpcUrl, debugLogger);
150
- const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
151
- const wallet = await getWalletWithScopes(account, db);
152
- await addAuthwit(wallet, authwit, authorizer, log);
153
- await addScopeToWallet(wallet, authorizer, db);
154
- });
155
- program.command('get-tx').description('Gets the status of the recent txs, or a detailed view if a specific transaction hash is provided').argument('[txHash]', 'A transaction hash to get the receipt for.', (txHash)=>aliasedTxHashParser(txHash, db)).addOption(pxeOption).option('-p, --page <number>', 'The page number to display', (value)=>integerArgParser(value, '--page', 1), 1).option('-s, --page-size <number>', 'The number of transactions to display per page', (value)=>integerArgParser(value, '--page-size', 1), 10).action(async (txHash, options)=>{
140
+ program.command('get-tx').description('Gets the status of the recent txs, or a detailed view if a specific transaction hash is provided').argument('[txHash]', 'A transaction hash to get the receipt for.', (txHash)=>aliasedTxHashParser(txHash, db)).option('-p, --page <number>', 'The page number to display', (value)=>integerArgParser(value, '--page', 1), 1).option('-s, --page-size <number>', 'The number of transactions to display per page', (value)=>integerArgParser(value, '--page-size', 1), 10).action(async (txHash, options)=>{
156
141
  const { checkTx } = await import('./check_tx.js');
157
- const { rpcUrl, pageSize } = options;
142
+ const { pageSize } = options;
158
143
  let { page } = options;
159
- const client = pxeWrapper?.getPXE() ?? await createCompatibleClient(rpcUrl, debugLogger);
144
+ const wallet = walletAndNodeWrapper.wallet;
145
+ const node = walletAndNodeWrapper.node;
160
146
  if (txHash) {
161
- await checkTx(client, txHash, false, log);
147
+ await checkTx(wallet, node, txHash, false, log);
162
148
  } else if (db) {
163
149
  const aliases = await db.listAliases('transactions');
164
150
  const totalPages = Math.ceil(aliases.length / pageSize);
@@ -166,55 +152,37 @@ export function injectCommands(program, log, debugLogger, db, pxeWrapper) {
166
152
  const dataRows = await Promise.all(aliases.slice(page * pageSize, pageSize * (1 + page)).map(async ({ key, value })=>({
167
153
  alias: key,
168
154
  txHash: value,
169
- cancellable: (await db.retrieveTxData(TxHash.fromString(value))).cancellable,
170
- status: await checkTx(client, TxHash.fromString(value), true, log)
155
+ status: await checkTx(wallet, node, TxHash.fromString(value), true, log)
171
156
  })));
172
157
  log(`Recent transactions:`);
173
158
  log('');
174
159
  log(`${'Alias'.padEnd(32, ' ')} | ${'TxHash'.padEnd(64, ' ')} | ${'Cancellable'.padEnd(12, ' ')} | Status`);
175
- log(''.padEnd(32 + 64 + 12 + 20, '-'));
176
- for (const { alias, txHash, status, cancellable } of dataRows){
177
- log(`${alias.padEnd(32, ' ')} | ${txHash} | ${cancellable.toString()?.padEnd(12, ' ')} | ${status}`);
178
- log(''.padEnd(32 + 64 + 12 + 20, '-'));
160
+ log(''.padEnd(32 + 64 + 20, '-'));
161
+ for (const { alias, txHash, status } of dataRows){
162
+ log(`${alias.padEnd(32, ' ')} | ${txHash} | ${status}`);
163
+ log(''.padEnd(32 + 64 + 20, '-'));
179
164
  }
180
165
  log(`Displaying ${Math.min(pageSize, aliases.length)} rows, page ${page + 1}/${totalPages}`);
181
166
  } else {
182
167
  log('Recent transactions are not available, please provide a specific transaction hash');
183
168
  }
184
169
  });
185
- program.command('cancel-tx').description('Cancels a pending tx by reusing its nonce with a higher fee and an empty payload').argument('<txHash>', 'A transaction hash to cancel.', (txHash)=>aliasedTxHashParser(txHash, db)).addOption(pxeOption).addOption(createSecretKeyOption("The sender's secret key", !db, (sk)=>aliasedSecretKeyParser(sk, db)).conflicts('account')).addOption(createAccountOption('Alias or address of the account to simulate from', !db, db)).addOption(FeeOpts.paymentMethodOption().default('method=fee_juice')).option('-i --increased-fees <da=1,l2=1>', 'The amounts by which the fees are increased', (value)=>parseGasFees(value), new GasFees(1, 1)).option('--max-fees-per-gas <da=100,l2=100>', 'Maximum fees per gas unit for DA and L2 computation.', (value)=>parseGasFees(value)).action(async (txHash, options)=>{
186
- const { cancelTx } = await import('./cancel_tx.js');
187
- const { from: parsedFromAddress, rpcUrl, secretKey, payment, increasedFees, maxFeesPerGas } = options;
188
- const client = pxeWrapper?.getPXE() ?? await createCompatibleClient(rpcUrl, debugLogger);
189
- const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
190
- const wallet = await getWalletWithScopes(account, db);
191
- const txData = await db?.retrieveTxData(txHash);
192
- if (!txData) {
193
- throw new Error('Transaction data not found in the database, cannot reuse nonce');
194
- }
195
- const paymentMethod = await parsePaymentMethod(payment, false, log, db)(wallet);
196
- await cancelTx(wallet, txData, paymentMethod, increasedFees, maxFeesPerGas, log);
197
- });
198
- program.command('register-sender').description("Registers a sender's address in the wallet, so the note synching process will look for notes sent by them").argument('[address]', 'The address of the sender to register', (address)=>aliasedAddressParser('accounts', address, db)).addOption(pxeOption).addOption(createAccountOption('Alias or address of the account to simulate from', !db, db)).addOption(createAliasOption('Alias for the sender. Used for easy reference in subsequent commands.', !db)).action(async (address, options)=>{
170
+ program.command('register-sender').description("Registers a sender's address in the wallet, so the note synching process will look for notes sent by them").argument('[address]', 'The address of the sender to register', (address)=>aliasedAddressParser('accounts', address, db)).addOption(createAliasOption('Alias for the sender. Used for easy reference in subsequent commands.', !db)).action(async (address, options)=>{
199
171
  const { registerSender } = await import('./register_sender.js');
200
- const { from: parsedFromAddress, rpcUrl, secretKey, alias } = options;
201
- const client = pxeWrapper?.getPXE() ?? await createCompatibleClient(rpcUrl, debugLogger);
202
- const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
203
- const wallet = await getWalletWithScopes(account, db);
172
+ const { alias } = options;
173
+ const wallet = walletAndNodeWrapper.wallet;
204
174
  await registerSender(wallet, address, log);
205
175
  if (db && alias) {
206
176
  await db.storeSender(address, alias, log);
207
177
  }
208
178
  });
209
- program.command('register-contract').description("Registers a contract in this wallet's PXE").argument('[address]', 'The address of the contract to register', (address)=>aliasedAddressParser('accounts', address, db)).argument('[artifact]', ARTIFACT_DESCRIPTION, artifactPathParser).addOption(createArgsOption(true, db)).addOption(pxeOption).addOption(createAccountOption('Alias or address of the account to simulate from', !db, db)).addOption(createAliasOption('Alias for the contact. Used for easy reference in subsequent commands.', !db)).action(async (address, artifactPathPromise, _options, command)=>{
179
+ program.command('register-contract').description("Registers a contract in this wallet's PXE").argument('[address]', 'The address of the contract to register', (address)=>aliasedAddressParser('accounts', address, db)).argument('[artifact]', ARTIFACT_DESCRIPTION, artifactPathParser).option('--init <string>', 'The contract initializer function to call', 'constructor').option('-k, --public-key <string>', 'Optional encryption public key for this address. Set this value only if this contract is expected to receive private notes, which will be encrypted using this public key.', parsePublicKey).option('-s, --salt <hex string>', 'Optional deployment salt as a hex string for generating the deployment address.', parseFieldFromHexString).option('--deployer <string>', 'The address of the account that deployed the contract', (address)=>aliasedAddressParser('accounts', address, db)).addOption(createArgsOption(true, db)).addOption(createAliasOption('Alias for the contact. Used for easy reference in subsequent commands.', !db)).action(async (address, artifactPathPromise, _options, command)=>{
210
180
  const { registerContract } = await import('./register_contract.js');
211
- const { from: parsedFromAddress, rpcUrl, nodeUrl, secretKey, alias } = command.optsWithGlobals();
212
- const client = pxeWrapper?.getPXE() ?? await createCompatibleClient(rpcUrl, debugLogger);
213
- const node = pxeWrapper?.getNode() ?? createAztecNodeClient(nodeUrl);
214
- const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey);
215
- const wallet = await getWalletWithScopes(account, db);
181
+ const { alias, init, publicKey, salt, deployer, args } = command.optsWithGlobals();
182
+ const wallet = walletAndNodeWrapper.wallet;
183
+ const node = walletAndNodeWrapper.node;
216
184
  const artifactPath = await artifactPathPromise;
217
- const instance = await registerContract(wallet, node, address, artifactPath, log);
185
+ const instance = await registerContract(wallet, node, address, artifactPath, log, init, publicKey, args, salt, deployer);
218
186
  if (db && alias) {
219
187
  await db.storeContract(instance.address, artifactPath, log, alias);
220
188
  }
@@ -0,0 +1,8 @@
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { AuthWitness } from '@aztec/aztec.js/authorization';
3
+ import type { AztecNode } from '@aztec/aztec.js/node';
4
+ import type { LogFn } from '@aztec/foundation/log';
5
+ import type { CLIFeeArgs } from '../utils/options/fees.js';
6
+ import type { CLIWallet } from '../utils/wallet.js';
7
+ export declare function profile(wallet: CLIWallet, node: AztecNode, from: AztecAddress, functionName: string, functionArgsIn: any[], contractArtifactPath: string, contractAddress: AztecAddress, debugOutputPath: string | undefined, feeOpts: CLIFeeArgs, authWitnesses: AuthWitness[], log: LogFn): Promise<void>;
8
+ //# sourceMappingURL=profile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../src/cmds/profile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAMnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,wBAAsB,OAAO,CAC3B,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,YAAY,EAClB,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,GAAG,EAAE,EACrB,oBAAoB,EAAE,MAAM,EAC5B,eAAe,EAAE,YAAY,EAC7B,eAAe,EAAE,MAAM,GAAG,SAAS,EACnC,OAAO,EAAE,UAAU,EACnB,aAAa,EAAE,WAAW,EAAE,EAC5B,GAAG,EAAE,KAAK,iBAqBX"}
@@ -0,0 +1,28 @@
1
+ import { Contract } from '@aztec/aztec.js/contracts';
2
+ import { prepTx } from '@aztec/cli/utils';
3
+ import { serializePrivateExecutionSteps } from '@aztec/stdlib/kernel';
4
+ import { promises as fs } from 'fs';
5
+ import path from 'path';
6
+ import { printProfileResult } from '../utils/profiling.js';
7
+ export async function profile(wallet, node, from, functionName, functionArgsIn, contractArtifactPath, contractAddress, debugOutputPath, feeOpts, authWitnesses, log) {
8
+ const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
9
+ const contract = await Contract.at(contractAddress, contractArtifact, wallet);
10
+ const call = contract.methods[functionName](...functionArgs);
11
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
12
+ const result = await call.profile({
13
+ fee: {
14
+ gasSettings,
15
+ paymentMethod
16
+ },
17
+ from,
18
+ profileMode: 'full',
19
+ authWitnesses,
20
+ skipProofGeneration: false
21
+ });
22
+ printProfileResult(result.stats, log, true, result.executionSteps);
23
+ if (debugOutputPath) {
24
+ const ivcInputsPath = path.join(debugOutputPath, 'ivc-inputs.msgpack');
25
+ log(`Debug output written to ${ivcInputsPath}.`);
26
+ await fs.writeFile(ivcInputsPath, serializePrivateExecutionSteps(result.executionSteps));
27
+ }
28
+ }
@@ -1,4 +1,8 @@
1
- import type { AccountWalletWithSecretKey, AztecAddress, AztecNode } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { Fr } from '@aztec/aztec.js/fields';
3
+ import { PublicKeys } from '@aztec/aztec.js/keys';
4
+ import type { AztecNode } from '@aztec/aztec.js/node';
5
+ import type { Wallet } from '@aztec/aztec.js/wallet';
2
6
  import type { LogFn } from '@aztec/foundation/log';
3
- export declare function registerContract(wallet: AccountWalletWithSecretKey, node: AztecNode, address: AztecAddress, artifactPath: string, log: LogFn): Promise<import("@aztec/aztec.js").ContractInstanceWithAddress>;
7
+ export declare function registerContract(wallet: Wallet, node: AztecNode, address: AztecAddress, artifactPath: string, log: LogFn, initializer?: string, publicKeys?: PublicKeys, rawArgs?: any[], salt?: Fr, deployer?: AztecAddress): Promise<import("@aztec/aztec.js/contracts").ContractInstanceWithAddress>;
4
8
  //# sourceMappingURL=register_contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"register_contract.d.ts","sourceRoot":"","sources":["../../src/cmds/register_contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE3F,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,0BAA0B,EAClC,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,YAAY,EACrB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,KAAK,kEAUX"}
1
+ {"version":3,"file":"register_contract.d.ts","sourceRoot":"","sources":["../../src/cmds/register_contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAGnD,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,YAAY,EACrB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,KAAK,EACV,WAAW,CAAC,EAAE,MAAM,EACpB,UAAU,CAAC,EAAE,UAAU,EACvB,OAAO,CAAC,EAAE,GAAG,EAAE,EACf,IAAI,CAAC,EAAE,EAAE,EACT,QAAQ,CAAC,EAAE,YAAY,4EAsBxB"}
@@ -1,14 +1,27 @@
1
+ import { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
2
+ import { Fr } from '@aztec/aztec.js/fields';
3
+ import { PublicKeys } from '@aztec/aztec.js/keys';
1
4
  import { getContractArtifact } from '@aztec/cli/cli-utils';
2
- export async function registerContract(wallet, node, address, artifactPath, log) {
5
+ import { getAllFunctionAbis, getInitializer } from '@aztec/stdlib/abi';
6
+ export async function registerContract(wallet, node, address, artifactPath, log, initializer, publicKeys, rawArgs, salt, deployer) {
3
7
  const contractArtifact = await getContractArtifact(artifactPath, log);
4
- const contractInstance = await node.getContract(address);
8
+ const hasInitializer = getAllFunctionAbis(contractArtifact).some((fn)=>fn.isInitializer);
9
+ const constructorArtifact = hasInitializer ? getInitializer(contractArtifact, initializer) : undefined;
10
+ let contractInstance = await node.getContract(address);
5
11
  if (!contractInstance) {
6
- throw new Error(`Contract not found at address: ${address}`);
12
+ log(`Contract not found in the node at ${address}. Computing instance locally...`);
13
+ contractInstance = await getContractInstanceFromInstantiationParams(contractArtifact, {
14
+ constructorArtifact,
15
+ publicKeys: publicKeys ?? PublicKeys.default(),
16
+ constructorArgs: rawArgs,
17
+ salt: salt ?? Fr.ZERO,
18
+ deployer
19
+ });
7
20
  }
8
- await wallet.registerContract({
9
- instance: contractInstance,
10
- artifact: contractArtifact
11
- });
21
+ if (!contractInstance.address.equals(address)) {
22
+ throw new Error(`Contract address mismatch: expected ${address}, got ${contractInstance.address}`);
23
+ }
24
+ await wallet.registerContract(contractInstance, contractArtifact);
12
25
  log(`Contract registered: at ${contractInstance.address}`);
13
26
  return contractInstance;
14
27
  }
@@ -1,4 +1,5 @@
1
- import type { AccountWalletWithSecretKey, AztecAddress } from '@aztec/aztec.js';
1
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import type { Wallet } from '@aztec/aztec.js/wallet';
2
3
  import type { LogFn } from '@aztec/foundation/log';
3
- export declare function registerSender(wallet: AccountWalletWithSecretKey, address: AztecAddress, log: LogFn): Promise<void>;
4
+ export declare function registerSender(wallet: Wallet, address: AztecAddress, log: LogFn): Promise<void>;
4
5
  //# sourceMappingURL=register_sender.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"register_sender.d.ts","sourceRoot":"","sources":["../../src/cmds/register_sender.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,wBAAsB,cAAc,CAAC,MAAM,EAAE,0BAA0B,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,KAAK,iBAGzG"}
1
+ {"version":3,"file":"register_sender.d.ts","sourceRoot":"","sources":["../../src/cmds/register_sender.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,KAAK,iBAGrF"}
@@ -1,11 +1,10 @@
1
- import { type AccountWalletWithSecretKey, type AztecAddress, Fr } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { AuthWitness } from '@aztec/aztec.js/authorization';
3
+ import type { AztecNode } from '@aztec/aztec.js/node';
2
4
  import type { LogFn } from '@aztec/foundation/log';
3
- import { GasSettings } from '@aztec/stdlib/gas';
4
- import { type IFeeOpts } from '../utils/options/fees.js';
5
- export declare function send(wallet: AccountWalletWithSecretKey, functionName: string, functionArgsIn: any[], contractArtifactPath: string, contractAddress: AztecAddress, wait: boolean, cancellable: boolean, feeOpts: IFeeOpts, log: LogFn): Promise<{
6
- txHash: import("@aztec/aztec.js").TxHash;
7
- nonce: Fr;
8
- cancellable: boolean;
9
- gasSettings: GasSettings;
5
+ import { CLIFeeArgs } from '../utils/options/fees.js';
6
+ import type { CLIWallet } from '../utils/wallet.js';
7
+ export declare function send(wallet: CLIWallet, node: AztecNode, from: AztecAddress, functionName: string, functionArgsIn: any[], contractArtifactPath: string, contractAddress: AztecAddress, wait: boolean, cancellable: boolean, feeOpts: CLIFeeArgs, authWitnesses: AuthWitness[], verbose: boolean, log: LogFn): Promise<{
8
+ txHash: import("@aztec/aztec.js/tx").TxHash;
10
9
  } | undefined>;
11
10
  //# sourceMappingURL=send.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../src/cmds/send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,KAAK,YAAY,EAAY,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAEnG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,KAAK,QAAQ,EAAqB,MAAM,0BAA0B,CAAC;AAE5E,wBAAsB,IAAI,CACxB,MAAM,EAAE,0BAA0B,EAClC,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,GAAG,EAAE,EACrB,oBAAoB,EAAE,MAAM,EAC5B,eAAe,EAAE,YAAY,EAC7B,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,OAAO,EACpB,OAAO,EAAE,QAAQ,EACjB,GAAG,EAAE,KAAK;;;;;eA6CX"}
1
+ {"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../src/cmds/send.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,wBAAsB,IAAI,CACxB,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,YAAY,EAClB,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,GAAG,EAAE,EACrB,oBAAoB,EAAE,MAAM,EAC5B,eAAe,EAAE,YAAY,EAC7B,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,OAAO,EACpB,OAAO,EAAE,UAAU,EACnB,aAAa,EAAE,WAAW,EAAE,EAC5B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,KAAK;;eAkDX"}
package/dest/cmds/send.js CHANGED
@@ -1,29 +1,47 @@
1
- import { Contract, Fr } from '@aztec/aztec.js';
1
+ import { Contract } from '@aztec/aztec.js/contracts';
2
2
  import { prepTx } from '@aztec/cli/utils';
3
- import { GasSettings } from '@aztec/stdlib/gas';
4
- import { printGasEstimates } from '../utils/options/fees.js';
5
- export async function send(wallet, functionName, functionArgsIn, contractArtifactPath, contractAddress, wait, cancellable, feeOpts, log) {
3
+ import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
4
+ import { printProfileResult } from '../utils/profiling.js';
5
+ export async function send(wallet, node, from, functionName, functionArgsIn, contractArtifactPath, contractAddress, wait, cancellable, feeOpts, authWitnesses, verbose, log) {
6
6
  const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
7
7
  const contract = await Contract.at(contractAddress, contractArtifact, wallet);
8
8
  const call = contract.methods[functionName](...functionArgs);
9
- const gasLimits = await call.estimateGas({
10
- ...await feeOpts.toSendOpts(wallet)
9
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
10
+ const sendOptions = {
11
+ fee: {
12
+ paymentMethod,
13
+ gasSettings
14
+ },
15
+ from,
16
+ authWitnesses
17
+ };
18
+ const { estimatedGas, stats } = await call.simulate({
19
+ ...sendOptions,
20
+ fee: {
21
+ ...sendOptions.fee,
22
+ estimateGas: true
23
+ }
11
24
  });
12
- printGasEstimates(feeOpts, gasLimits, log);
13
25
  if (feeOpts.estimateOnly) {
14
26
  return;
15
27
  }
16
- const nonce = Fr.random();
17
28
  const tx = call.send({
18
- ...await feeOpts.toSendOpts(wallet),
19
- nonce,
20
- cancellable
29
+ ...sendOptions,
30
+ fee: {
31
+ ...sendOptions.fee,
32
+ gasSettings: estimatedGas
33
+ }
21
34
  });
35
+ if (verbose) {
36
+ printProfileResult(stats, log);
37
+ }
22
38
  const txHash = await tx.getTxHash();
23
39
  log(`\nTransaction hash: ${txHash.toString()}`);
24
40
  if (wait) {
25
41
  try {
26
- await tx.wait();
42
+ await tx.wait({
43
+ timeout: DEFAULT_TX_TIMEOUT_S
44
+ });
27
45
  log('Transaction has been mined');
28
46
  const receipt = await tx.getReceipt();
29
47
  log(` Tx fee: ${receipt.transactionFee}`);
@@ -36,14 +54,7 @@ export async function send(wallet, functionName, functionArgsIn, contractArtifac
36
54
  } else {
37
55
  log('Transaction pending. Check status with check-tx');
38
56
  }
39
- const gasSettings = GasSettings.from({
40
- ...feeOpts.gasSettings,
41
- ...gasLimits
42
- });
43
57
  return {
44
- txHash,
45
- nonce,
46
- cancellable,
47
- gasSettings
58
+ txHash
48
59
  };
49
60
  }
@@ -1,4 +1,8 @@
1
- import { type AccountWalletWithSecretKey, type AztecAddress } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { AuthWitness } from '@aztec/aztec.js/authorization';
3
+ import type { AztecNode } from '@aztec/aztec.js/node';
2
4
  import type { LogFn } from '@aztec/foundation/log';
3
- export declare function simulate(wallet: AccountWalletWithSecretKey, functionName: string, functionArgsIn: any[], contractArtifactPath: string, contractAddress: AztecAddress, profile: boolean, log: LogFn): Promise<void>;
5
+ import type { CLIFeeArgs } from '../utils/options/fees.js';
6
+ import type { CLIWallet } from '../utils/wallet.js';
7
+ export declare function simulate(wallet: CLIWallet, node: AztecNode, from: AztecAddress, functionName: string, functionArgsIn: any[], contractArtifactPath: string, contractAddress: AztecAddress, feeOpts: CLIFeeArgs, authWitnesses: AuthWitness[], verbose: boolean, log: LogFn): Promise<void>;
4
8
  //# sourceMappingURL=simulate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"simulate.d.ts","sourceRoot":"","sources":["../../src/cmds/simulate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,KAAK,YAAY,EAAgC,MAAM,iBAAiB,CAAC;AAEnH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAkBnD,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,0BAA0B,EAClC,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,GAAG,EAAE,EACrB,oBAAoB,EAAE,MAAM,EAC5B,eAAe,EAAE,YAAY,EAC7B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,KAAK,iBAcX"}
1
+ {"version":3,"file":"simulate.d.ts","sourceRoot":"","sources":["../../src/cmds/simulate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAKnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,YAAY,EAClB,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,GAAG,EAAE,EACrB,oBAAoB,EAAE,MAAM,EAC5B,eAAe,EAAE,YAAY,EAC7B,OAAO,EAAE,UAAU,EACnB,aAAa,EAAE,WAAW,EAAE,EAC5B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,KAAK,iBAgCX"}