Skip to content

Commit

Permalink
feat(minor-ampd): add commands to unbond and claim stake (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcobb23 authored Aug 20, 2024
1 parent ddddd80 commit e2278d2
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 22 deletions.
40 changes: 20 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions ampd/src/commands/claim_stake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use axelar_wasm_std::nonempty;
use cosmrs::cosmwasm::MsgExecuteContract;
use cosmrs::tx::Msg;
use error_stack::Result;
use report::ResultCompatExt;
use service_registry::msg::ExecuteMsg;
use valuable::Valuable;

use crate::commands::{broadcast_tx, verifier_pub_key};
use crate::config::Config;
use crate::{Error, PREFIX};

#[derive(clap::Args, Debug, Valuable)]
pub struct Args {
pub service_name: nonempty::String,
}

pub async fn run(config: Config, args: Args) -> Result<Option<String>, Error> {
let pub_key = verifier_pub_key(config.tofnd_config.clone()).await?;

let msg = serde_json::to_vec(&ExecuteMsg::ClaimStake {
service_name: args.service_name.into(),
})
.expect("claim stake msg should be serializable");

let tx = MsgExecuteContract {
sender: pub_key.account_id(PREFIX).change_context(Error::Tofnd)?,
contract: config.service_registry.cosmwasm_contract.as_ref().clone(),
msg,
funds: vec![],
}
.into_any()
.expect("failed to serialize proto message");

let tx_hash = broadcast_tx(config, tx, pub_key).await?.txhash;

Ok(Some(format!(
"successfully broadcast claim stake transaction, tx hash: {}",
tx_hash
)))
}
6 changes: 6 additions & 0 deletions ampd/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ use crate::types::{PublicKey, TMAddress};
use crate::{broadcaster, tofnd, Error, PREFIX};

pub mod bond_verifier;
pub mod claim_stake;
pub mod daemon;
pub mod deregister_chain_support;
pub mod register_chain_support;
pub mod register_public_key;
pub mod send_tokens;
pub mod unbond_verifier;
pub mod verifier_address;

#[derive(Debug, Subcommand, Valuable)]
Expand All @@ -29,6 +31,10 @@ pub enum SubCommand {
Daemon,
/// Bond the verifier to the service registry contract
BondVerifier(bond_verifier::Args),
/// Unbond the verifier from the service registry contract
UnbondVerifier(unbond_verifier::Args),
/// Claim unbonded stake from the service registry contract
ClaimStake(claim_stake::Args),
/// Register chain support to the service registry contract
RegisterChainSupport(register_chain_support::Args),
/// Deregister chain support to the service registry contract
Expand Down
41 changes: 41 additions & 0 deletions ampd/src/commands/unbond_verifier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use axelar_wasm_std::nonempty;
use cosmrs::cosmwasm::MsgExecuteContract;
use cosmrs::tx::Msg;
use error_stack::Result;
use report::ResultCompatExt;
use service_registry::msg::ExecuteMsg;
use valuable::Valuable;

use crate::commands::{broadcast_tx, verifier_pub_key};
use crate::config::Config;
use crate::{Error, PREFIX};

#[derive(clap::Args, Debug, Valuable)]
pub struct Args {
pub service_name: nonempty::String,
}

pub async fn run(config: Config, args: Args) -> Result<Option<String>, Error> {
let pub_key = verifier_pub_key(config.tofnd_config.clone()).await?;

let msg = serde_json::to_vec(&ExecuteMsg::UnbondVerifier {
service_name: args.service_name.into(),
})
.expect("unbond verifier msg should be serializable");

let tx = MsgExecuteContract {
sender: pub_key.account_id(PREFIX).change_context(Error::Tofnd)?,
contract: config.service_registry.cosmwasm_contract.as_ref().clone(),
msg,
funds: vec![],
}
.into_any()
.expect("failed to serialize proto message");

let tx_hash = broadcast_tx(config, tx, pub_key).await?.txhash;

Ok(Some(format!(
"successfully broadcast unbond verifier transaction, tx hash: {}",
tx_hash
)))
}
6 changes: 4 additions & 2 deletions ampd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::process::ExitCode;

use ::config::{Config as cfg, Environment, File, FileFormat, FileSourceFile};
use ampd::commands::{
bond_verifier, daemon, deregister_chain_support, register_chain_support, register_public_key,
send_tokens, verifier_address, SubCommand,
bond_verifier, claim_stake, daemon, deregister_chain_support, register_chain_support,
register_public_key, send_tokens, unbond_verifier, verifier_address, SubCommand,
};
use ampd::config::Config;
use ampd::Error;
Expand Down Expand Up @@ -64,6 +64,8 @@ async fn main() -> ExitCode {
}
Some(SubCommand::RegisterPublicKey(args)) => register_public_key::run(cfg, args).await,
Some(SubCommand::VerifierAddress) => verifier_address::run(cfg.tofnd_config).await,
Some(SubCommand::UnbondVerifier(args)) => unbond_verifier::run(cfg, args).await,
Some(SubCommand::ClaimStake(args)) => claim_stake::run(cfg, args).await,
Some(SubCommand::SendTokens(args)) => send_tokens::run(cfg, args).await,
};

Expand Down

0 comments on commit e2278d2

Please sign in to comment.