Skip to content
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
19 changes: 17 additions & 2 deletions packages/cosmos-bin/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use cosmos::{
proto::{
cosmos::{
base::abci::v1beta1::TxResponse,
tx::v1beta1::{AuthInfo, OrderBy, Tx},
tx::v1beta1::{AuthInfo, OrderBy, Tx, TxBody},
},
traits::Message,
Any,
},
Address, BlockInfo, Cosmos, TxResponseExt,
};
Expand Down Expand Up @@ -180,7 +181,7 @@ pub(crate) async fn go(Opt { sub }: Opt, opt: crate::cli::Opt) -> Result<()> {
let tx = tx.context("Missing tx field")?;
println!("Encoded length: {}", tx.encoded_len());
let Tx {
body: _,
body,
auth_info,
signatures: _,
} = Tx::decode(&*tx.value)?;
Expand All @@ -201,6 +202,20 @@ pub(crate) async fn go(Opt { sub }: Opt, opt: crate::cli::Opt) -> Result<()> {
println!();
println!("Signer count: {}", signer_infos.len());
if complete {
let TxBody {
messages,
memo,
timeout_height: _,
extension_options: _,
non_critical_extension_options: _,
} = body.context("No body provided")?;
println!("Memo: {memo}");
for (idx, Any { type_url, value }) in messages.into_iter().enumerate() {
println!(
"Message #{idx}: {type_url}: {}",
String::from_utf8_lossy(&value)
);
}
println!("Data: {data}");
for (idx, log) in logs.into_iter().enumerate() {
println!("Log #{idx}: {log:?}");
Expand Down
34 changes: 32 additions & 2 deletions packages/cosmos-bin/src/rujira.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use anyhow::Result;
use cosmos::{HasAddress, HasAddressHrp, TxBuilder};

use crate::cli::TxOpt;

#[derive(clap::Parser)]
pub(crate) enum Subcommand {
Expand All @@ -9,20 +12,47 @@ pub(crate) enum Subcommand {
},
/// Print information about all pools
Pools {},
/// Withdraw secured assets
Withdraw {
chain: String,
symbol: String,
amount: u128,
destination: String,
#[clap(flatten)]
tx_opt: TxOpt,
},
}

pub(crate) async fn go(opt: crate::cli::Opt, inner: Subcommand) -> Result<()> {
let cosmos = opt.network_opt.build().await?;
match inner {
Subcommand::Pool { asset } => {
let cosmos = opt.network_opt.build().await?;
let x = cosmos.rujira_pool(asset).await?;
println!("{x:#?}");
}
Subcommand::Pools {} => {
let cosmos = opt.network_opt.build().await?;
let x = cosmos.rujira_pools().await?;
println!("{x:#?}");
}
Subcommand::Withdraw {
chain,
symbol,
amount,
destination,
tx_opt,
} => {
let wallet = tx_opt.get_wallet(cosmos.get_address_hrp())?;
let mut builder = TxBuilder::default();
builder.add_message(cosmos::rujira::MsgDeposit {
chain,
symbol,
amount,
destination,
signer: wallet.get_address(),
});
let res = builder.sign_and_broadcast(&cosmos, &wallet).await?;
println!("txhash: {}", res.txhash);
}
}

Ok(())
Expand Down
3 changes: 2 additions & 1 deletion packages/cosmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ mod ext;
mod gas_multiplier;
mod injective;
mod parsed_coin;
mod rujira;
/// Contains Rujira-specific messages.
pub mod rujira;
mod tokenfactory;
mod txbuilder;
mod wallet;
Expand Down
97 changes: 94 additions & 3 deletions packages/cosmos/src/rujira.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use prost::Message;
use tonic::{async_trait, GrpcMethod};

use crate::{
client::{node::Node, query::GrpcRequest},
error::Action,
Cosmos,
Address, Cosmos, TxMessage,
};

impl Cosmos {
Expand Down Expand Up @@ -117,13 +118,16 @@ impl GrpcRequest for QueryPoolsRequest {
}

#[derive(Clone, PartialEq, ::prost::Message)]
pub struct QueryPoolRequest {
pub(crate) struct QueryPoolRequest {
#[prost(string, tag = "1")]
pub asset: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub height: ::prost::alloc::string::String,
}

/// Response with information on a THORChain pool.
#[derive(Clone, PartialEq, ::prost::Message)]
#[allow(missing_docs)]
pub struct QueryPoolResponse {
#[prost(string, tag = "1")]
pub asset: ::prost::alloc::string::String,
Expand Down Expand Up @@ -188,12 +192,99 @@ pub struct QueryPoolResponse {
pub derived_depth_bps: ::prost::alloc::string::String,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct QueryPoolsRequest {
pub(crate) struct QueryPoolsRequest {
#[prost(string, tag = "1")]
pub height: ::prost::alloc::string::String,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[allow(missing_docs)]
pub struct QueryPoolsResponse {
#[prost(message, repeated, tag = "1")]
pub pools: ::prost::alloc::vec::Vec<QueryPoolResponse>,
}

#[derive(Clone, PartialEq, ::prost::Message)]
struct MsgDepositInner {
#[prost(message, repeated, tag = "1")]
coins: Vec<RujiraCoin>,
#[prost(string, tag = "2")]
memo: String,
#[prost(bytes, tag = "3")]
signer: Vec<u8>,
}

#[derive(Clone, PartialEq, ::prost::Message)]
struct RujiraCoin {
#[prost(message, tag = "1")]
asset: Option<RujiraAsset>,
#[prost(string, tag = "2")]
amount: String,
#[prost(int64, tag = "3")]
decimals: i64,
}

#[derive(Clone, PartialEq, ::prost::Message)]
struct RujiraAsset {
#[prost(string, tag = "1")]
chain: String,
#[prost(string, tag = "2")]
symbol: String,
#[prost(string, tag = "3")]
ticker: String,
#[prost(bool, tag = "4")]
synth: bool,
#[prost(bool, tag = "5")]
trade: bool,
#[prost(bool, tag = "6")]
secured: bool,
}

/// A Rujira `MsgDeposit`, used for withdrawing secured assets.
pub struct MsgDeposit {
/// Chain to withdraw to
pub chain: String,
/// Symbol to withdraw
pub symbol: String,
/// Amount of asset to withdraw, given in 10e-8 units
pub amount: u128,
/// Destination to send the asset to
pub destination: String,
/// Account sending the funds
pub signer: Address,
}

impl From<MsgDeposit> for TxMessage {
fn from(
MsgDeposit {
chain,
symbol,
amount,
destination,
signer,
}: MsgDeposit,
) -> Self {
let description =
format!("Withdraw secured assets: {amount}{chain}-{symbol} to {destination}");
TxMessage::new(
"/types.MsgDeposit",
MsgDepositInner {
coins: vec![RujiraCoin {
asset: Some(RujiraAsset {
chain,
symbol: symbol.clone(),
ticker: symbol,
synth: false,
trade: false,
secured: true,
}),
amount: amount.to_string(),
decimals: 0,
}],
memo: format!("secure-:{destination}"),
signer: signer.raw().as_ref().to_owned(),
}
.encode_to_vec(),
description,
)
}
}
Loading