|
| 1 | +use prost::Message; |
1 | 2 | use tonic::{async_trait, GrpcMethod}; |
2 | 3 |
|
3 | 4 | use crate::{ |
4 | 5 | client::{node::Node, query::GrpcRequest}, |
5 | 6 | error::Action, |
6 | | - Cosmos, |
| 7 | + Address, Cosmos, TxMessage, |
7 | 8 | }; |
8 | 9 |
|
9 | 10 | impl Cosmos { |
@@ -117,13 +118,16 @@ impl GrpcRequest for QueryPoolsRequest { |
117 | 118 | } |
118 | 119 |
|
119 | 120 | #[derive(Clone, PartialEq, ::prost::Message)] |
120 | | -pub struct QueryPoolRequest { |
| 121 | +pub(crate) struct QueryPoolRequest { |
121 | 122 | #[prost(string, tag = "1")] |
122 | 123 | pub asset: ::prost::alloc::string::String, |
123 | 124 | #[prost(string, tag = "2")] |
124 | 125 | pub height: ::prost::alloc::string::String, |
125 | 126 | } |
| 127 | + |
| 128 | +/// Response with information on a THORChain pool. |
126 | 129 | #[derive(Clone, PartialEq, ::prost::Message)] |
| 130 | +#[allow(missing_docs)] |
127 | 131 | pub struct QueryPoolResponse { |
128 | 132 | #[prost(string, tag = "1")] |
129 | 133 | pub asset: ::prost::alloc::string::String, |
@@ -188,12 +192,99 @@ pub struct QueryPoolResponse { |
188 | 192 | pub derived_depth_bps: ::prost::alloc::string::String, |
189 | 193 | } |
190 | 194 | #[derive(Clone, PartialEq, ::prost::Message)] |
191 | | -pub struct QueryPoolsRequest { |
| 195 | +pub(crate) struct QueryPoolsRequest { |
192 | 196 | #[prost(string, tag = "1")] |
193 | 197 | pub height: ::prost::alloc::string::String, |
194 | 198 | } |
195 | 199 | #[derive(Clone, PartialEq, ::prost::Message)] |
| 200 | +#[allow(missing_docs)] |
196 | 201 | pub struct QueryPoolsResponse { |
197 | 202 | #[prost(message, repeated, tag = "1")] |
198 | 203 | pub pools: ::prost::alloc::vec::Vec<QueryPoolResponse>, |
199 | 204 | } |
| 205 | + |
| 206 | +#[derive(Clone, PartialEq, ::prost::Message)] |
| 207 | +struct MsgDepositInner { |
| 208 | + #[prost(message, repeated, tag = "1")] |
| 209 | + coins: Vec<RujiraCoin>, |
| 210 | + #[prost(string, tag = "2")] |
| 211 | + memo: String, |
| 212 | + #[prost(bytes, tag = "3")] |
| 213 | + signer: Vec<u8>, |
| 214 | +} |
| 215 | + |
| 216 | +#[derive(Clone, PartialEq, ::prost::Message)] |
| 217 | +struct RujiraCoin { |
| 218 | + #[prost(message, tag = "1")] |
| 219 | + asset: Option<RujiraAsset>, |
| 220 | + #[prost(string, tag = "2")] |
| 221 | + amount: String, |
| 222 | + #[prost(int64, tag = "3")] |
| 223 | + decimals: i64, |
| 224 | +} |
| 225 | + |
| 226 | +#[derive(Clone, PartialEq, ::prost::Message)] |
| 227 | +struct RujiraAsset { |
| 228 | + #[prost(string, tag = "1")] |
| 229 | + chain: String, |
| 230 | + #[prost(string, tag = "2")] |
| 231 | + symbol: String, |
| 232 | + #[prost(string, tag = "3")] |
| 233 | + ticker: String, |
| 234 | + #[prost(bool, tag = "4")] |
| 235 | + synth: bool, |
| 236 | + #[prost(bool, tag = "5")] |
| 237 | + trade: bool, |
| 238 | + #[prost(bool, tag = "6")] |
| 239 | + secured: bool, |
| 240 | +} |
| 241 | + |
| 242 | +/// A Rujira `MsgDeposit`, used for withdrawing secured assets. |
| 243 | +pub struct MsgDeposit { |
| 244 | + /// Chain to withdraw to |
| 245 | + pub chain: String, |
| 246 | + /// Symbol to withdraw |
| 247 | + pub symbol: String, |
| 248 | + /// Amount of asset to withdraw, given in 10e-8 units |
| 249 | + pub amount: u128, |
| 250 | + /// Destination to send the asset to |
| 251 | + pub destination: String, |
| 252 | + /// Account sending the funds |
| 253 | + pub signer: Address, |
| 254 | +} |
| 255 | + |
| 256 | +impl From<MsgDeposit> for TxMessage { |
| 257 | + fn from( |
| 258 | + MsgDeposit { |
| 259 | + chain, |
| 260 | + symbol, |
| 261 | + amount, |
| 262 | + destination, |
| 263 | + signer, |
| 264 | + }: MsgDeposit, |
| 265 | + ) -> Self { |
| 266 | + let description = |
| 267 | + format!("Withdraw secured assets: {amount}{chain}-{symbol} to {destination}"); |
| 268 | + TxMessage::new( |
| 269 | + "/types.MsgDeposit", |
| 270 | + MsgDepositInner { |
| 271 | + coins: vec![RujiraCoin { |
| 272 | + asset: Some(RujiraAsset { |
| 273 | + chain, |
| 274 | + symbol: symbol.clone(), |
| 275 | + ticker: symbol, |
| 276 | + synth: false, |
| 277 | + trade: false, |
| 278 | + secured: true, |
| 279 | + }), |
| 280 | + amount: amount.to_string(), |
| 281 | + decimals: 0, |
| 282 | + }], |
| 283 | + memo: format!("secure-:{destination}"), |
| 284 | + signer: signer.raw().as_ref().to_owned(), |
| 285 | + } |
| 286 | + .encode_to_vec(), |
| 287 | + description, |
| 288 | + ) |
| 289 | + } |
| 290 | +} |
0 commit comments