Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add redelegation functionality #2173

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/unreleased/SDK/2140-sdk-redelegate.md
Original file line number Diff line number Diff line change
@@ -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))
43 changes: 43 additions & 0 deletions sdk/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,49 @@ impl Redelegate {
}
}

impl<C: NamadaTypes> Redelegate<C> {
/// 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<C: NamadaTypes> TxBuilder<C> for Redelegate<C> {
fn tx<F>(self, func: F) -> Self
where
F: FnOnce(Tx<C>) -> Tx<C>,
{
Redelegate {
tx: func(self.tx),
..self
}
}
}

/// Reveal public key
#[derive(Clone, Debug)]
pub struct RevealPk<C: NamadaTypes = SdkTypes> {
Expand Down
32 changes: 28 additions & 4 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading