-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: cli wallet with fee opts + private transfer flow (#7856)
Further improvements to `aztec-wallet`, supporting new commands: - **bridge-fee-juice**: Same as old version, but supports alias for the recipient ```bash aztec-wallet bridge-fee-juice 100000000000000000 accounts:main --mint ``` - **add-secret** : generates aliased secrets (and their hashes) that can be later used as `secrets:my_secret(:hash)` - **add-note**: Adds notes to PXE, reading from the contract interface so no "magic numbers" are required ```bash aztec-wallet add-secret -a shield aztec-wallet send mint_private -ca contracts:last --args 42 secrets:shield:hash -f main # Note that the contract interface doesn't have to be specified since the wallet nows about the last contract that # was deployed. Also transactions now store the `txHash` in `transactions:last` # (and the `send` method supports a `-a` param for custom aliases) aztec-wallet add-note TransparentNote pending_shields -ca contracts:last -h transactions:last -a accounts:main -b 42 secrets:shield:hash ``` Also, fee options now accept aliases for the things that make sense: `--payment method=fpc-public,fpc=contracts:my_fpc` It is also possible to claim bridged fee juice without passing secrets around, using a stack: ```bash # Pushes the claim to the stack, with sender, amount and secret aztec-wallet bridge-fee-juice 100000000000000000 accounts:main --mint # Retrieves the last one on the stack, only the claim keyword is needed aztec-wallet deploy-account -f main --payment method=native,claim ``` ## Testing In order not to break things constantly, the most interesting flows should be added as e2e tests (using a sandbox as target) inside `./test/flows`. A few examples are provided showcasing old and new features.  ## Breaking changes - `-ac, --account` param has been renamed to `-f, --from` for improved readability
- Loading branch information
Showing
33 changed files
with
671 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// deploy-protocol-contracts // |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { type AccountWalletWithSecretKey, type AztecAddress } from '@aztec/aztec.js'; | ||
import { ExtendedNote, Note, type TxHash } from '@aztec/circuit-types'; | ||
import { getContractArtifact, parseFields } from '@aztec/cli/utils'; | ||
import { type LogFn } from '@aztec/foundation/log'; | ||
|
||
export async function addNote( | ||
wallet: AccountWalletWithSecretKey, | ||
address: AztecAddress, | ||
contractAddress: AztecAddress, | ||
noteName: string, | ||
storageFieldName: string, | ||
artifactPath: string, | ||
txHash: TxHash, | ||
noteFields: string[], | ||
log: LogFn, | ||
) { | ||
const fields = parseFields(noteFields); | ||
const note = new Note(fields); | ||
const contractArtifact = await getContractArtifact(artifactPath, log); | ||
|
||
const contractNote = contractArtifact.notes[noteName]; | ||
const storageField = contractArtifact.storageLayout[storageFieldName]; | ||
|
||
if (!contractNote) { | ||
throw new Error(`Note ${noteName} not found in contract ${contractArtifact.name}`); | ||
} | ||
|
||
const extendedNote = new ExtendedNote(note, address, contractAddress, storageField.slot, contractNote.id, txHash); | ||
await wallet.addNote(extendedNote); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { type AccountManager, type DeployAccountOptions } from '@aztec/aztec.js'; | ||
import { prettyPrintJSON } from '@aztec/cli/cli-utils'; | ||
import { type DebugLogger, type LogFn } from '@aztec/foundation/log'; | ||
|
||
import { type IFeeOpts, printGasEstimates } from '../utils/options/fees.js'; | ||
|
||
export async function deployAccount( | ||
account: AccountManager, | ||
wait: boolean, | ||
feeOpts: IFeeOpts, | ||
json: boolean, | ||
debugLogger: DebugLogger, | ||
log: LogFn, | ||
) { | ||
const out: Record<string, any> = {}; | ||
const { address, partialAddress, publicKeys } = account.getCompleteAddress(); | ||
const { initializationHash, deployer, salt } = account.getInstance(); | ||
const wallet = await account.getWallet(); | ||
const secretKey = wallet.getSecretKey(); | ||
|
||
if (json) { | ||
out.address = address; | ||
out.partialAddress = partialAddress; | ||
out.salt = salt; | ||
out.initHash = initializationHash; | ||
out.deployer = deployer; | ||
} else { | ||
log(`\nNew account:\n`); | ||
log(`Address: ${address.toString()}`); | ||
log(`Public key: 0x${publicKeys.toString()}`); | ||
if (secretKey) { | ||
log(`Secret key: ${secretKey.toString()}`); | ||
} | ||
log(`Partial address: ${partialAddress.toString()}`); | ||
log(`Salt: ${salt.toString()}`); | ||
log(`Init hash: ${initializationHash.toString()}`); | ||
log(`Deployer: ${deployer.toString()}`); | ||
} | ||
|
||
let tx; | ||
let txReceipt; | ||
|
||
const sendOpts: DeployAccountOptions = { | ||
...feeOpts.toSendOpts(wallet), | ||
skipInitialization: false, | ||
}; | ||
if (feeOpts.estimateOnly) { | ||
const gas = await (await account.getDeployMethod()).estimateGas({ ...sendOpts }); | ||
if (json) { | ||
out.fee = { | ||
gasLimits: { | ||
da: gas.gasLimits.daGas, | ||
l2: gas.gasLimits.l2Gas, | ||
}, | ||
teardownGasLimits: { | ||
da: gas.teardownGasLimits.daGas, | ||
l2: gas.teardownGasLimits, | ||
}, | ||
}; | ||
} else { | ||
printGasEstimates(feeOpts, gas, log); | ||
} | ||
} else { | ||
tx = account.deploy({ ...sendOpts }); | ||
const txHash = await tx.getTxHash(); | ||
debugLogger.debug(`Account contract tx sent with hash ${txHash}`); | ||
out.txHash = txHash; | ||
if (wait) { | ||
if (!json) { | ||
log(`\nWaiting for account contract deployment...`); | ||
} | ||
txReceipt = await tx.wait(); | ||
out.txReceipt = { | ||
status: txReceipt.status, | ||
transactionFee: txReceipt.transactionFee, | ||
}; | ||
} | ||
} | ||
|
||
if (json) { | ||
log(prettyPrintJSON(out)); | ||
} else { | ||
if (tx) { | ||
log(`Deploy tx hash: ${await tx.getTxHash()}`); | ||
} | ||
if (txReceipt) { | ||
log(`Deploy tx fee: ${txReceipt.transactionFee}`); | ||
} | ||
} | ||
|
||
return { address, secretKey, salt }; | ||
} |
Oops, something went wrong.