diff --git a/completions/README.md b/completions/README.md index d274774c..b12f1823 100644 --- a/completions/README.md +++ b/completions/README.md @@ -93,6 +93,12 @@ Only `Public/2gJJjtG9UivBGEhA1Jz6waZQx1cwfYupC5yvKEweHaeH` is used for completio exec zsh ``` +> **Note:** After updating the completion script, re-run step 1 to copy the new file, then rebuild the cache: +> ```sh +> cp _wallet ~/.oh-my-zsh/custom/plugins/wallet/ +> rm -rf ~/.zcompdump* && exec zsh +> ``` + ### Requirements The completion script calls `wallet account list` to dynamically fetch account IDs. Ensure the `wallet` command is in your `$PATH`. @@ -197,8 +203,7 @@ wallet account get --account-id 2. Rebuild the completion cache: ```sh - rm -f ~/.zcompdump* - exec zsh + rm -rf ~/.zcompdump* && exec zsh ``` ### Account IDs not completing diff --git a/completions/bash/wallet b/completions/bash/wallet index b01e5607..a4d390f6 100644 --- a/completions/bash/wallet +++ b/completions/bash/wallet @@ -46,7 +46,7 @@ _wallet() { cword=$COMP_CWORD } - local commands="auth-transfer chain-info account pinata token amm check-health config restore-keys deploy-program help" + local commands="auth-transfer chain-info account pinata token amm ata check-health config restore-keys deploy-program help" # Find the main command and subcommand by scanning words before the cursor. # Global options that take a value are skipped along with their argument. @@ -127,10 +127,10 @@ _wallet() { --to-label) _wallet_complete_account_label "$cur" ;; - --to-npk | --to-vpk | --amount) + --to-npk | --to-vpk | --to-identifier | --amount) ;; # no specific completion *) - COMPREPLY=($(compgen -W "--from --from-label --to --to-label --to-npk --to-vpk --amount" -- "$cur")) + COMPREPLY=($(compgen -W "--from --from-label --to --to-label --to-npk --to-vpk --to-identifier --amount" -- "$cur")) ;; esac ;; @@ -187,11 +187,11 @@ _wallet() { sync-private) ;; # no options new) - # `account new` is itself a subcommand: public | private + # `account new` is itself a subcommand: public | private-accounts-key local new_subcmd="" for ((i = subcmd_idx + 1; i < cword; i++)); do case "${words[$i]}" in - public | private) + public | private-accounts-key) new_subcmd="${words[$i]}" break ;; @@ -199,13 +199,26 @@ _wallet() { done if [[ -z "$new_subcmd" ]]; then - COMPREPLY=($(compgen -W "public private" -- "$cur")) + COMPREPLY=($(compgen -W "public private-accounts-key" -- "$cur")) else - case "$prev" in - --cci | -l | --label) - ;; # no specific completion - *) - COMPREPLY=($(compgen -W "--cci -l --label" -- "$cur")) + case "$new_subcmd" in + public) + case "$prev" in + --cci | -l | --label) + ;; # no specific completion + *) + COMPREPLY=($(compgen -W "--cci -l --label" -- "$cur")) + ;; + esac + ;; + private-accounts-key) + case "$prev" in + --cci) + ;; # no specific completion + *) + COMPREPLY=($(compgen -W "--cci" -- "$cur")) + ;; + esac ;; esac fi @@ -289,10 +302,10 @@ _wallet() { --to-label) _wallet_complete_account_label "$cur" ;; - --to-npk | --to-vpk | --amount) + --to-npk | --to-vpk | --to-identifier | --amount) ;; # no specific completion *) - COMPREPLY=($(compgen -W "--from --from-label --to --to-label --to-npk --to-vpk --amount" -- "$cur")) + COMPREPLY=($(compgen -W "--from --from-label --to --to-label --to-npk --to-vpk --to-identifier --amount" -- "$cur")) ;; esac ;; @@ -331,10 +344,10 @@ _wallet() { --holder-label) _wallet_complete_account_label "$cur" ;; - --holder-npk | --holder-vpk | --amount) + --holder-npk | --holder-vpk | --holder-identifier | --amount) ;; # no specific completion *) - COMPREPLY=($(compgen -W "--definition --definition-label --holder --holder-label --holder-npk --holder-vpk --amount" -- "$cur")) + COMPREPLY=($(compgen -W "--definition --definition-label --holder --holder-label --holder-npk --holder-vpk --holder-identifier --amount" -- "$cur")) ;; esac ;; @@ -344,7 +357,7 @@ _wallet() { amm) case "$subcmd" in "") - COMPREPLY=($(compgen -W "new swap add-liquidity remove-liquidity help" -- "$cur")) + COMPREPLY=($(compgen -W "new swap-exact-input swap-exact-output add-liquidity remove-liquidity help" -- "$cur")) ;; new) case "$prev" in @@ -373,7 +386,7 @@ _wallet() { ;; esac ;; - swap) + swap-exact-input) case "$prev" in --user-holding-a) _wallet_complete_account_id "$cur" @@ -394,6 +407,15 @@ _wallet() { ;; esac ;; + swap-exact-output) + case "$prev" in + --user-holding-a | --user-holding-b | --exact-amount-out | --max-amount-in | --token-definition) + ;; # no specific completion + *) + COMPREPLY=($(compgen -W "--user-holding-a --user-holding-b --exact-amount-out --max-amount-in --token-definition" -- "$cur")) + ;; + esac + ;; add-liquidity) case "$prev" in --user-holding-a) @@ -451,6 +473,68 @@ _wallet() { esac ;; + ata) + case "$subcmd" in + "") + COMPREPLY=($(compgen -W "address create send burn list help" -- "$cur")) + ;; + address) + case "$prev" in + --owner | --token-definition) + ;; # no specific completion + *) + COMPREPLY=($(compgen -W "--owner --token-definition" -- "$cur")) + ;; + esac + ;; + create) + case "$prev" in + --owner) + _wallet_complete_account_id "$cur" + ;; + --token-definition) + ;; # no specific completion + *) + COMPREPLY=($(compgen -W "--owner --token-definition" -- "$cur")) + ;; + esac + ;; + send) + case "$prev" in + --from) + _wallet_complete_account_id "$cur" + ;; + --to | --token-definition | --amount) + ;; # no specific completion + *) + COMPREPLY=($(compgen -W "--from --token-definition --to --amount" -- "$cur")) + ;; + esac + ;; + burn) + case "$prev" in + --holder) + _wallet_complete_account_id "$cur" + ;; + --token-definition | --amount) + ;; # no specific completion + *) + COMPREPLY=($(compgen -W "--holder --token-definition --amount" -- "$cur")) + ;; + esac + ;; + list) + case "$prev" in + --owner | --token-definition) + ;; # no specific completion + *) + COMPREPLY=($(compgen -W "--owner --token-definition" -- "$cur")) + ;; + esac + ;; + esac + ;; + config) case "$subcmd" in "") diff --git a/completions/zsh/_wallet b/completions/zsh/_wallet index 2d4fe26b..8f573ab0 100644 --- a/completions/zsh/_wallet +++ b/completions/zsh/_wallet @@ -24,6 +24,7 @@ _wallet() { 'pinata:Pinata program interaction subcommand' 'token:Token program interaction subcommand' 'amm:AMM program interaction subcommand' + 'ata:Associated Token Account program interaction subcommand' 'check-health:Check the wallet can connect to the node and builtin local programs match the remote versions' 'config:Command to setup config, get and set config fields' 'restore-keys:Restoring keys from given password at given depth' @@ -52,6 +53,9 @@ _wallet() { amm) _wallet_amm ;; + ata) + _wallet_ata + ;; config) _wallet_config ;; @@ -72,7 +76,7 @@ _wallet() { # auth-transfer subcommand _wallet_auth_transfer() { local -a subcommands - + _arguments -C \ '1: :->subcommand' \ '*:: :->args' @@ -91,16 +95,17 @@ _wallet_auth_transfer() { init) _arguments \ '--account-id[Account ID to initialize]:account_id:_wallet_account_ids' \ - '--account-label[Account label (alternative to --account-id)]:label:_wallet_account_labels' + '--account-label[Account label (alternative to --account-id)]:label:' ;; send) _arguments \ '--from[Source account ID]:from_account:_wallet_account_ids' \ - '--from-label[Source account label (alternative to --from)]:label:_wallet_account_labels' \ + '--from-label[From account label (alternative to --from)]:label:' \ '--to[Destination account ID (for owned accounts)]:to_account:_wallet_account_ids' \ - '--to-label[Destination account label (alternative to --to)]:label:_wallet_account_labels' \ + '--to-label[To account label (alternative to --to)]:label:' \ '--to-npk[Destination nullifier public key (for foreign private accounts)]:npk:' \ '--to-vpk[Destination viewing public key (for foreign private accounts)]:vpk:' \ + '--to-identifier[Identifier for the recipient private account]:identifier:' \ '--amount[Amount of native tokens to send]:amount:' ;; esac @@ -111,7 +116,7 @@ _wallet_auth_transfer() { # chain-info subcommand _wallet_chain_info() { local -a subcommands - + _arguments -C \ '1: :->subcommand' \ '*:: :->args' @@ -144,7 +149,7 @@ _wallet_chain_info() { # account subcommand _wallet_account() { local -a subcommands - + _arguments -C \ '1: :->subcommand' \ '*:: :->args' @@ -169,7 +174,7 @@ _wallet_account() { '(-r --raw)'{-r,--raw}'[Get raw account data]' \ '(-k --keys)'{-k,--keys}'[Display keys (pk for public accounts, npk/vpk for private accounts)]' \ '(-a --account-id)'{-a,--account-id}'[Account ID to query]:account_id:_wallet_account_ids' \ - '--account-label[Account label (alternative to --account-id)]:label:_wallet_account_labels' + '--account-label[Account label (alternative to --account-id)]:label:' ;; list|ls) _arguments \ @@ -181,19 +186,27 @@ _wallet_account() { '*:: :->new_args' case $state in account_type) - compadd public private + compadd public private-accounts-key ;; new_args) - _arguments \ - '--cci[Chain index of a parent node]:chain_index:' \ - '(-l --label)'{-l,--label}'[Label to assign to the new account]:label:' + case $line[1] in + public) + _arguments \ + '--cci[Chain index of a parent node]:chain_index:' \ + '(-l --label)'{-l,--label}'[Label to assign to the new account]:label:' + ;; + private-accounts-key) + _arguments \ + '--cci[Chain index of a parent node]:chain_index:' + ;; + esac ;; esac ;; label) _arguments \ '(-a --account-id)'{-a,--account-id}'[Account ID to label]:account_id:_wallet_account_ids' \ - '--account-label[Account label (alternative to --account-id)]:label:_wallet_account_labels' \ + '--account-label[Account label (alternative to --account-id)]:label:' \ '(-l --label)'{-l,--label}'[The label to assign to the account]:label:' ;; esac @@ -204,7 +217,7 @@ _wallet_account() { # pinata subcommand _wallet_pinata() { local -a subcommands - + _arguments -C \ '1: :->subcommand' \ '*:: :->args' @@ -222,7 +235,7 @@ _wallet_pinata() { claim) _arguments \ '--to[Destination account ID to receive claimed tokens]:to_account:_wallet_account_ids' \ - '--to-label[Destination account label (alternative to --to)]:label:_wallet_account_labels' + '--to-label[To account label (alternative to --to)]:label:' ;; esac ;; @@ -255,36 +268,38 @@ _wallet_token() { '--name[Token name]:name:' \ '--total-supply[Total supply of tokens to mint]:total_supply:' \ '--definition-account-id[Account ID for token definition]:definition_account:_wallet_account_ids' \ - '--definition-account-label[Definition account label (alternative to --definition-account-id)]:label:_wallet_account_labels' \ + '--definition-account-label[Definition account label (alternative to --definition-account-id)]:label:' \ '--supply-account-id[Account ID to receive initial supply]:supply_account:_wallet_account_ids' \ - '--supply-account-label[Supply account label (alternative to --supply-account-id)]:label:_wallet_account_labels' + '--supply-account-label[Supply account label (alternative to --supply-account-id)]:label:' ;; send) _arguments \ '--from[Source holding account ID]:from_account:_wallet_account_ids' \ - '--from-label[Source account label (alternative to --from)]:label:_wallet_account_labels' \ + '--from-label[From account label (alternative to --from)]:label:' \ '--to[Destination holding account ID (for owned accounts)]:to_account:_wallet_account_ids' \ - '--to-label[Destination account label (alternative to --to)]:label:_wallet_account_labels' \ + '--to-label[To account label (alternative to --to)]:label:' \ '--to-npk[Destination nullifier public key (for foreign private accounts)]:npk:' \ '--to-vpk[Destination viewing public key (for foreign private accounts)]:vpk:' \ + '--to-identifier[Identifier for the recipient private account]:identifier:' \ '--amount[Amount of tokens to send]:amount:' ;; burn) _arguments \ '--definition[Definition account ID]:definition_account:_wallet_account_ids' \ - '--definition-label[Definition account label (alternative to --definition)]:label:_wallet_account_labels' \ + '--definition-label[Definition account label (alternative to --definition)]:label:' \ '--holder[Holder account ID]:holder_account:_wallet_account_ids' \ - '--holder-label[Holder account label (alternative to --holder)]:label:_wallet_account_labels' \ + '--holder-label[Holder account label (alternative to --holder)]:label:' \ '--amount[Amount of tokens to burn]:amount:' ;; mint) _arguments \ '--definition[Definition account ID]:definition_account:_wallet_account_ids' \ - '--definition-label[Definition account label (alternative to --definition)]:label:_wallet_account_labels' \ + '--definition-label[Definition account label (alternative to --definition)]:label:' \ '--holder[Holder account ID (for owned accounts)]:holder_account:_wallet_account_ids' \ - '--holder-label[Holder account label (alternative to --holder)]:label:_wallet_account_labels' \ + '--holder-label[Holder account label (alternative to --holder)]:label:' \ '--holder-npk[Holder nullifier public key (for foreign private accounts)]:npk:' \ '--holder-vpk[Holder viewing public key (for foreign private accounts)]:vpk:' \ + '--holder-identifier[Identifier for the holder private account]:identifier:' \ '--amount[Amount of tokens to mint]:amount:' ;; esac @@ -295,7 +310,7 @@ _wallet_token() { # amm subcommand _wallet_amm() { local -a subcommands - + _arguments -C \ '1: :->subcommand' \ '*:: :->args' @@ -304,7 +319,8 @@ _wallet_amm() { subcommand) subcommands=( 'new:Create a new liquidity pool' - 'swap:Swap tokens using the AMM' + 'swap-exact-input:Swap specifying exact input amount' + 'swap-exact-output:Swap specifying exact output amount' 'add-liquidity:Add liquidity to an existing pool' 'remove-liquidity:Remove liquidity from a pool' 'help:Print this message or the help of the given subcommand(s)' @@ -316,32 +332,40 @@ _wallet_amm() { new) _arguments \ '--user-holding-a[User token A holding account ID]:holding_a:_wallet_account_ids' \ - '--user-holding-a-label[User holding A account label (alternative to --user-holding-a)]:label:_wallet_account_labels' \ + '--user-holding-a-label[User holding A label (alternative to --user-holding-a)]:label:' \ '--user-holding-b[User token B holding account ID]:holding_b:_wallet_account_ids' \ - '--user-holding-b-label[User holding B account label (alternative to --user-holding-b)]:label:_wallet_account_labels' \ + '--user-holding-b-label[User holding B label (alternative to --user-holding-b)]:label:' \ '--user-holding-lp[User LP token holding account ID]:holding_lp:_wallet_account_ids' \ - '--user-holding-lp-label[User holding LP account label (alternative to --user-holding-lp)]:label:_wallet_account_labels' \ + '--user-holding-lp-label[User holding LP label (alternative to --user-holding-lp)]:label:' \ '--balance-a[Amount of token A to deposit]:balance_a:' \ '--balance-b[Amount of token B to deposit]:balance_b:' ;; - swap) + swap-exact-input) _arguments \ '--user-holding-a[User token A holding account ID]:holding_a:_wallet_account_ids' \ - '--user-holding-a-label[User holding A account label (alternative to --user-holding-a)]:label:_wallet_account_labels' \ + '--user-holding-a-label[User holding A label (alternative to --user-holding-a)]:label:' \ '--user-holding-b[User token B holding account ID]:holding_b:_wallet_account_ids' \ - '--user-holding-b-label[User holding B account label (alternative to --user-holding-b)]:label:_wallet_account_labels' \ + '--user-holding-b-label[User holding B label (alternative to --user-holding-b)]:label:' \ '--amount-in[Amount of tokens to swap]:amount_in:' \ '--min-amount-out[Minimum tokens expected in return]:min_amount_out:' \ '--token-definition[Definition ID of the token being provided]:token_def:' ;; + swap-exact-output) + _arguments \ + '--user-holding-a[User token A holding account ID]:holding_a:' \ + '--user-holding-b[User token B holding account ID]:holding_b:' \ + '--exact-amount-out[Exact amount of tokens expected out]:exact_amount_out:' \ + '--max-amount-in[Maximum tokens to spend]:max_amount_in:' \ + '--token-definition[Definition ID of the token being provided]:token_def:' + ;; add-liquidity) _arguments \ '--user-holding-a[User token A holding account ID]:holding_a:_wallet_account_ids' \ - '--user-holding-a-label[User holding A account label (alternative to --user-holding-a)]:label:_wallet_account_labels' \ + '--user-holding-a-label[User holding A label (alternative to --user-holding-a)]:label:' \ '--user-holding-b[User token B holding account ID]:holding_b:_wallet_account_ids' \ - '--user-holding-b-label[User holding B account label (alternative to --user-holding-b)]:label:_wallet_account_labels' \ + '--user-holding-b-label[User holding B label (alternative to --user-holding-b)]:label:' \ '--user-holding-lp[User LP token holding account ID]:holding_lp:_wallet_account_ids' \ - '--user-holding-lp-label[User holding LP account label (alternative to --user-holding-lp)]:label:_wallet_account_labels' \ + '--user-holding-lp-label[User holding LP label (alternative to --user-holding-lp)]:label:' \ '--max-amount-a[Maximum amount of token A to deposit]:max_amount_a:' \ '--max-amount-b[Maximum amount of token B to deposit]:max_amount_b:' \ '--min-amount-lp[Minimum LP tokens to receive]:min_amount_lp:' @@ -349,11 +373,11 @@ _wallet_amm() { remove-liquidity) _arguments \ '--user-holding-a[User token A holding account ID]:holding_a:_wallet_account_ids' \ - '--user-holding-a-label[User holding A account label (alternative to --user-holding-a)]:label:_wallet_account_labels' \ + '--user-holding-a-label[User holding A label (alternative to --user-holding-a)]:label:' \ '--user-holding-b[User token B holding account ID]:holding_b:_wallet_account_ids' \ - '--user-holding-b-label[User holding B account label (alternative to --user-holding-b)]:label:_wallet_account_labels' \ + '--user-holding-b-label[User holding B label (alternative to --user-holding-b)]:label:' \ '--user-holding-lp[User LP token holding account ID]:holding_lp:_wallet_account_ids' \ - '--user-holding-lp-label[User holding LP account label (alternative to --user-holding-lp)]:label:_wallet_account_labels' \ + '--user-holding-lp-label[User holding LP label (alternative to --user-holding-lp)]:label:' \ '--balance-lp[Amount of LP tokens to burn]:balance_lp:' \ '--min-amount-a[Minimum token A to receive]:min_amount_a:' \ '--min-amount-b[Minimum token B to receive]:min_amount_b:' @@ -363,6 +387,61 @@ _wallet_amm() { esac } +# ata subcommand +_wallet_ata() { + local -a subcommands + + _arguments -C \ + '1: :->subcommand' \ + '*:: :->args' + + case $state in + subcommand) + subcommands=( + 'address:Derive and print the Associated Token Account address (local only)' + 'create:Create (or idempotently no-op) the Associated Token Account' + 'send:Send tokens from owner ATA to a recipient token holding account' + 'burn:Burn tokens from holder ATA' + 'list:List all ATAs for a given owner across multiple token definitions' + 'help:Print this message or the help of the given subcommand(s)' + ) + _describe -t subcommands 'ata subcommands' subcommands + ;; + args) + case $line[1] in + address) + _arguments \ + '--owner[Owner account (no privacy prefix)]:owner:' \ + '--token-definition[Token definition account (no privacy prefix)]:token_def:' + ;; + create) + _arguments \ + '--owner[Owner account with privacy prefix]:owner:_wallet_account_ids' \ + '--token-definition[Token definition account (no privacy prefix)]:token_def:' + ;; + send) + _arguments \ + '--from[Sender account with privacy prefix]:from:_wallet_account_ids' \ + '--token-definition[Token definition account (no privacy prefix)]:token_def:' \ + '--to[Recipient account (no privacy prefix)]:to:' \ + '--amount[Amount of tokens to send]:amount:' + ;; + burn) + _arguments \ + '--holder[Holder account with privacy prefix]:holder:_wallet_account_ids' \ + '--token-definition[Token definition account (no privacy prefix)]:token_def:' \ + '--amount[Amount of tokens to burn]:amount:' + ;; + list) + _arguments \ + '--owner[Owner account (no privacy prefix)]:owner:' \ + '--token-definition[Token definition accounts (no privacy prefix)]:token_def:' + ;; + esac + ;; + esac +} + # config subcommand _wallet_config() { local -a subcommands @@ -435,6 +514,7 @@ _wallet_help() { 'pinata:Pinata program interaction subcommand' 'token:Token program interaction subcommand' 'amm:AMM program interaction subcommand' + 'ata:Associated Token Account program interaction subcommand' 'check-health:Check the wallet can connect to the node' 'config:Command to setup config, get and set config fields' 'restore-keys:Restoring keys from given password at given depth' @@ -468,25 +548,4 @@ _wallet_account_ids() { _multi_parts / accounts } -# Helper function to complete account labels -# Uses `wallet account list` to get available labels -_wallet_account_labels() { - local -a labels - local line - - if command -v wallet &>/dev/null; then - while IFS= read -r line; do - local label - # Extract label from [...] at end of line - label="${line##*\[}" - label="${label%\]}" - [[ -n "$label" && "$label" != "$line" ]] && labels+=("$label") - done < <(wallet account list 2>/dev/null) - fi - - if (( ${#labels} > 0 )); then - compadd -a labels - fi -} - _wallet "$@"