Skip to content

Commit

Permalink
feat(minor-ampd): add command to set rewards proxy (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcobb23 authored Sep 19, 2024
1 parent 62273a3 commit 84f27eb
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions ampd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ prost = "0.11.9"
prost-types = "0.11.9"
report = { workspace = true }
reqwest = { version = "0.11.24", default-features = false }
rewards = { workspace = true }
router-api = { workspace = true }
serde = { version = "1.0.147", features = ["derive"] }
serde_json = { workspace = true }
Expand Down
16 changes: 16 additions & 0 deletions ampd/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub mod deregister_chain_support;
pub mod register_chain_support;
pub mod register_public_key;
pub mod send_tokens;
pub mod set_rewards_proxy;
pub mod unbond_verifier;
pub mod verifier_address;

Expand All @@ -49,6 +50,8 @@ pub enum SubCommand {
VerifierAddress,
/// Send tokens from the verifier account to a specified address
SendTokens(send_tokens::Args),
/// Set a proxy address to receive rewards, instead of receiving rewards at the verifier address
SetRewardsProxy(set_rewards_proxy::Args),
}

#[derive(Debug, Deserialize, Serialize, PartialEq)]
Expand All @@ -64,6 +67,19 @@ impl Default for ServiceRegistryConfig {
}
}

#[derive(Debug, Deserialize, Serialize, PartialEq)]
pub struct RewardsConfig {
pub cosmwasm_contract: TMAddress,
}

impl Default for RewardsConfig {
fn default() -> Self {
Self {
cosmwasm_contract: AccountId::new(PREFIX, &[0; 32]).unwrap().into(),
}
}
}

async fn verifier_pub_key(config: tofnd::Config) -> Result<PublicKey, Error> {
MultisigClient::new(config.party_uid, config.url.clone())
.await
Expand Down
41 changes: 41 additions & 0 deletions ampd/src/commands/set_rewards_proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use cosmrs::cosmwasm::MsgExecuteContract;
use cosmrs::tx::Msg;
use error_stack::Result;
use report::ResultCompatExt;
use rewards::msg::ExecuteMsg;
use router_api::Address;
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 proxy_address: Address,
}

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::SetVerifierProxy {
proxy_address: args.proxy_address,
})
.expect("register chain support msg should serialize");

let tx = MsgExecuteContract {
sender: pub_key.account_id(PREFIX).change_context(Error::Tofnd)?,
contract: config.rewards.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 set verifier proxy transaction, tx hash: {}",
tx_hash
)))
}
4 changes: 3 additions & 1 deletion ampd/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::net::{Ipv4Addr, SocketAddrV4};

use serde::{Deserialize, Serialize};

use crate::commands::ServiceRegistryConfig;
use crate::commands::{RewardsConfig, ServiceRegistryConfig};
use crate::handlers::config::deserialize_handler_configs;
use crate::handlers::{self};
use crate::tofnd::Config as TofndConfig;
Expand All @@ -21,6 +21,7 @@ pub struct Config {
pub handlers: Vec<handlers::config::Config>,
pub tofnd_config: TofndConfig,
pub service_registry: ServiceRegistryConfig,
pub rewards: RewardsConfig,
}

impl Default for Config {
Expand All @@ -33,6 +34,7 @@ impl Default for Config {
tofnd_config: TofndConfig::default(),
event_processor: event_processor::Config::default(),
service_registry: ServiceRegistryConfig::default(),
rewards: RewardsConfig::default(),
health_check_bind_addr: SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 3000),
}
}
Expand Down
1 change: 1 addition & 0 deletions ampd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ async fn prepare_app(cfg: Config) -> Result<App<impl Broadcaster>, Error> {
tofnd_config,
event_processor,
service_registry: _service_registry,
rewards: _rewards,
health_check_bind_addr,
} = cfg;

Expand Down
4 changes: 3 additions & 1 deletion ampd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use std::process::ExitCode;
use ::config::{Config as cfg, Environment, File, FileFormat, FileSourceFile};
use ampd::commands::{
bond_verifier, claim_stake, daemon, deregister_chain_support, register_chain_support,
register_public_key, send_tokens, unbond_verifier, verifier_address, SubCommand,
register_public_key, send_tokens, set_rewards_proxy, unbond_verifier, verifier_address,
SubCommand,
};
use ampd::config::Config;
use ampd::Error;
Expand Down Expand Up @@ -67,6 +68,7 @@ async fn main() -> ExitCode {
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,
Some(SubCommand::SetRewardsProxy(args)) => set_rewards_proxy::run(cfg, args).await,
};

match result {
Expand Down
3 changes: 3 additions & 0 deletions ampd/src/tests/config_template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ key_uid = 'axelar'

[service_registry]
cosmwasm_contract = 'axelar1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqecnww6'

[rewards]
cosmwasm_contract = 'axelar1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqecnww6'
2 changes: 1 addition & 1 deletion packages/router-api/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl From<Message> for Vec<Attribute> {

#[cw_serde]
#[serde(try_from = "String")]
#[derive(Eq, Hash)]
#[derive(Eq, Hash, Valuable)]
pub struct Address(nonempty::String);

impl Deref for Address {
Expand Down

0 comments on commit 84f27eb

Please sign in to comment.