From 7caa524931c52812172622a0f8be6d79c398327a Mon Sep 17 00:00:00 2001 From: bengtlofgren Date: Thu, 9 Nov 2023 15:48:42 +0100 Subject: [PATCH] Add redelegation functionality --- .../unreleased/SDK/2140-sdk-redelegate.md | 3 ++ sdk/src/args.rs | 43 +++++++++++++++++++ sdk/src/lib.rs | 32 ++++++++++++-- sdk/src/tx.rs | 2 + 4 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 .changelog/unreleased/SDK/2140-sdk-redelegate.md diff --git a/.changelog/unreleased/SDK/2140-sdk-redelegate.md b/.changelog/unreleased/SDK/2140-sdk-redelegate.md new file mode 100644 index 0000000000..66b1b3d4b8 --- /dev/null +++ b/.changelog/unreleased/SDK/2140-sdk-redelegate.md @@ -0,0 +1,3 @@ +- A high level function new_redelegate is added to the sdk to allow developers + to make and submit redelegation functions from the minimum number of arguments + required ([\#2140](https://github.com/anoma/namada/pull/2140)) \ No newline at end of file diff --git a/sdk/src/args.rs b/sdk/src/args.rs index 138828007d..540ee43617 100644 --- a/sdk/src/args.rs +++ b/sdk/src/args.rs @@ -1018,6 +1018,49 @@ impl Redelegate { } } +impl Redelegate { + /// Src validator address + pub fn src_validator(self, src_validator: C::Address) -> Self { + Self { + src_validator, + ..self + } + } + + /// Dest validator address + pub fn dest_validator(self, dest_validator: C::Address) -> Self { + Self { + dest_validator, + ..self + } + } + + /// Owner (or delegator or source) of the redelegation + pub fn owner(self, owner: C::Address) -> Self { + Self { owner, ..self } + } + + /// Path to the TX WASM code file + pub fn tx_code_path(self, tx_code_path: PathBuf) -> Self { + Self { + tx_code_path, + ..self + } + } +} + +impl TxBuilder for Redelegate { + fn tx(self, func: F) -> Self + where + F: FnOnce(Tx) -> Tx, + { + Redelegate { + tx: func(self.tx), + ..self + } + } +} + /// Reveal public key #[derive(Clone, Debug)] pub struct RevealPk { diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index c82c8a063f..b6bb157905 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -55,10 +55,11 @@ use crate::tx::{ ProcessTxResponse, TX_BOND_WASM, TX_BRIDGE_POOL_WASM, TX_CHANGE_COMMISSION_WASM, TX_CHANGE_METADATA_WASM, TX_CLAIM_REWARDS_WASM, TX_DEACTIVATE_VALIDATOR_WASM, TX_IBC_WASM, TX_INIT_PROPOSAL, - TX_INIT_VALIDATOR_WASM, TX_REACTIVATE_VALIDATOR_WASM, TX_RESIGN_STEWARD, - TX_REVEAL_PK, TX_TRANSFER_WASM, TX_UNBOND_WASM, TX_UNJAIL_VALIDATOR_WASM, - TX_UPDATE_ACCOUNT_WASM, TX_UPDATE_STEWARD_COMMISSION, TX_VOTE_PROPOSAL, - TX_WITHDRAW_WASM, VP_USER_WASM, + TX_INIT_VALIDATOR_WASM, TX_REACTIVATE_VALIDATOR_WASM, TX_REDELEGATE_WASM, + TX_RESIGN_STEWARD, TX_REVEAL_PK, TX_TRANSFER_WASM, TX_UNBOND_WASM, + TX_UNJAIL_VALIDATOR_WASM, TX_UPDATE_ACCOUNT_WASM, + TX_UPDATE_STEWARD_COMMISSION, TX_VOTE_PROPOSAL, TX_WITHDRAW_WASM, + VP_USER_WASM, }; use crate::wallet::{Wallet, WalletIo, WalletStorage}; @@ -206,6 +207,29 @@ pub trait Namada<'a>: Sized { } } + // Make a Redelegation builder for the given minimum set of arguments + fn new_redelegation( + &self, + source: Address, + src_validator: Address, + dest_validator: Address, + amount: token::Amount, + ) -> args::Redelegate { + args::Redelegate { + tx: self.tx_builder(), + /// Source validator address + src_validator, + /// Destination validator address + dest_validator, + /// Owner of the bonds that are being redelegated + owner: source, + /// The amount of tokens to redelegate + amount, + /// Path to the TX WASM code file + tx_code_path: PathBuf::from(TX_REDELEGATE_WASM), + } + } + /// Make a TxIbcTransfer builder from the given minimum set of arguments fn new_ibc_transfer( &self, diff --git a/sdk/src/tx.rs b/sdk/src/tx.rs index 2e1a786d12..05b61cdf0e 100644 --- a/sdk/src/tx.rs +++ b/sdk/src/tx.rs @@ -114,6 +114,8 @@ pub const TX_RESIGN_STEWARD: &str = "tx_resign_steward.wasm"; /// Update steward commission WASM path pub const TX_UPDATE_STEWARD_COMMISSION: &str = "tx_update_steward_commission.wasm"; +/// Redelegat WASM path +pub const TX_REDELEGATE_WASM: &str = "tx_redelegate.wasm"; /// Default timeout in seconds for requests to the `/accepted` /// and `/applied` ABCI query endpoints.