From b3e778d81c8b8229ceeffddc3a4a865fcdfa799a Mon Sep 17 00:00:00 2001 From: Adam Spofford Date: Thu, 2 Mar 2023 11:34:02 -0800 Subject: [PATCH 1/2] More disbursal flags --- CHANGELOG.md | 1 + docs/cli-reference/quill-neuron-manage.md | 2 ++ src/commands/neuron_manage.rs | 26 ++++++++++++++----- src/lib/mod.rs | 12 +++++++++ ...ron-manage-disburse-somewhat-to-someone.sh | 1 + ...on-manage-disburse-somewhat-to-someone.txt | 20 ++++++++++++++ 6 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 tests/commands/neuron-manage-disburse-somewhat-to-someone.sh create mode 100644 tests/outputs/neuron-manage-disburse-somewhat-to-someone.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index d77db490..45821154 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- Added `--disburse-amount` and `--disburse-to` to `quill neuron-manage`. (#171) - Accepts bare principals and ICRC-1 account IDs in `quill account-balance` and `quill transfer`. (#168) - Allowed omitting the account ID in `quill account-balance`. (#167) - Added `--from-subaccount` to `quill transfer` and `quill neuron-stake`. (#166) diff --git a/docs/cli-reference/quill-neuron-manage.md b/docs/cli-reference/quill-neuron-manage.md index 1eae62a0..f45b2420 100644 --- a/docs/cli-reference/quill-neuron-manage.md +++ b/docs/cli-reference/quill-neuron-manage.md @@ -37,6 +37,8 @@ quill neuron-manage [option] | `-a`, `--additional-dissolve-delay-seconds ` | Number of dissolve seconds to add. | | `--add-hot-key ` | Principal to be used as a hot key. | | `--auto-stake-maturity enabled|disabled` | Set whether new maturity should be automatically staked. | +| `--disburse-amount` | Disburse only the selected amount. | +| `--disburse-to` | Disburse to the selected NNS account instead of the controller. | | `--follow-neurons ...` | Defines the neuron ids of a follow rule. | | `--follow-topic ` | Defines the topic of a follow rule as defined [here][follow-rules]. | | `--merge-from-neuron ` | Merge stake, maturity and age from the specified neuron into the managed neuron. | diff --git a/src/commands/neuron_manage.rs b/src/commands/neuron_manage.rs index 640055f2..6a8987b5 100644 --- a/src/commands/neuron_manage.rs +++ b/src/commands/neuron_manage.rs @@ -1,7 +1,8 @@ +use crate::commands::transfer::parse_tokens; use crate::lib::{ governance_canister_id, signing::{sign_ingress_with_request_status_query, IngressWithRequestId}, - AnyhowResult, AuthInfo, ROLE_NNS_GOVERNANCE, + AnyhowResult, AuthInfo, ParsedNnsAccount, ROLE_NNS_GOVERNANCE, }; use anyhow::{anyhow, bail, Context}; use candid::{CandidType, Encode, Principal}; @@ -10,12 +11,13 @@ use ic_base_types::PrincipalId; use ic_nns_common::pb::v1::{NeuronId, ProposalId}; use ic_nns_governance::pb::v1::{ manage_neuron::{ - configure::Operation, AddHotKey, ChangeAutoStakeMaturity, Command, Configure, Disburse, - Follow, IncreaseDissolveDelay, JoinCommunityFund, LeaveCommunityFund, Merge, RegisterVote, - RemoveHotKey, Split, StakeMaturity, StartDissolving, StopDissolving, + configure::Operation, disburse::Amount, AddHotKey, ChangeAutoStakeMaturity, Command, + Configure, Disburse, Follow, IncreaseDissolveDelay, JoinCommunityFund, LeaveCommunityFund, + Merge, RegisterVote, RemoveHotKey, Split, StakeMaturity, StartDissolving, StopDissolving, }, ManageNeuron, }; +use icp_ledger::Tokens; // These constants are copied from src/governance.rs pub const ONE_DAY_SECONDS: u32 = 24 * 60 * 60; @@ -63,6 +65,14 @@ pub struct ManageOpts { #[clap(long)] disburse: bool, + /// Disburse only the selected amount, instead of the entire amount, to the controller's account. + #[clap(long, value_parser = parse_tokens)] + disburse_amount: Option, + + /// Disburse to the selected NNS account instead of the controller. + #[clap(long)] + disburse_to: Option, + /// Spawn rewards to a new neuron under the controller's account. #[clap(long)] spawn: bool, @@ -217,12 +227,14 @@ pub fn exec(auth: &AuthInfo, opts: ManageOpts) -> AnyhowResult) -> fmt::Result { } } +#[derive(Debug, Clone)] pub enum ParsedNnsAccount { Original(AccountIdentifier), Icrc1(Account), @@ -516,6 +517,17 @@ impl FromStr for ParsedNnsAccount { } } +impl ParsedNnsAccount { + pub fn into_identifier(self) -> AccountIdentifier { + match self { + Self::Original(ident) => ident, + Self::Icrc1(account) => { + AccountIdentifier::new(account.owner.into(), account.subaccount.map(Subaccount)) + } + } + } +} + #[cfg(test)] mod tests { use super::{ParsedAccount, ParsedSubaccount}; diff --git a/tests/commands/neuron-manage-disburse-somewhat-to-someone.sh b/tests/commands/neuron-manage-disburse-somewhat-to-someone.sh new file mode 100644 index 00000000..e151d044 --- /dev/null +++ b/tests/commands/neuron-manage-disburse-somewhat-to-someone.sh @@ -0,0 +1 @@ +"$QUILL" neuron-manage 2313380519530470538 --disburse-to pnf55-r7gzn-s3oqn-ah2v7-r6b63-a2ma2-wyzhb-dzbwb-sghid-lzcxh-4ae --disburse-amount 57.31 --pem-file - | "$QUILL" send --dry-run \ No newline at end of file diff --git a/tests/outputs/neuron-manage-disburse-somewhat-to-someone.txt b/tests/outputs/neuron-manage-disburse-somewhat-to-someone.txt new file mode 100644 index 00000000..89fd27da --- /dev/null +++ b/tests/outputs/neuron-manage-disburse-somewhat-to-someone.txt @@ -0,0 +1,20 @@ +Sending message with + + Call type: update + Sender: fdsgv-62ihb-nbiqv-xgic5-iefsv-3cscz-tmbzv-63qd5-vh43v-dqfrt-pae + Canister id: rrkah-fqaaa-aaaaa-aaaaq-cai + Method name: manage_neuron + Arguments: ( + record { + id = opt record { id = 2_313_380_519_530_470_538 : nat64 }; + command = opt variant { + Disburse = record { + to_account = opt record { + hash = blob "\c6H\b8\14\e8\1dyF\e8\ba\ce\a9\92\80\e0|_Q\a0K\a7\a3\80\09\d8\ad\8e\89"; + }; + amount = opt record { e8s = 5_731_000_000 : nat64 }; + } + }; + neuron_id_or_subaccount = null; + }, +) From 6dcfdc42d9acca25f3a45839102c3f4dd5005273 Mon Sep 17 00:00:00 2001 From: Adam Spofford Date: Thu, 2 Mar 2023 11:36:12 -0800 Subject: [PATCH 2/2] clippy --- src/lib/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/mod.rs b/src/lib/mod.rs index d9c64ffd..131ce5b0 100644 --- a/src/lib/mod.rs +++ b/src/lib/mod.rs @@ -522,7 +522,7 @@ impl ParsedNnsAccount { match self { Self::Original(ident) => ident, Self::Icrc1(account) => { - AccountIdentifier::new(account.owner.into(), account.subaccount.map(Subaccount)) + AccountIdentifier::new(account.owner, account.subaccount.map(Subaccount)) } } }