nym_types/
fees.rs

1use crate::currency::DecCoin;
2use nym_validator_client::nyxd::Fee;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
7#[cfg_attr(
8    feature = "generate-ts",
9    ts(export, export_to = "ts-packages/types/src/types/rust/FeeDetails.ts")
10)]
11pub struct FeeDetails {
12    // expected to be used by the wallet in order to display detailed fee information to the user
13    pub amount: Option<DecCoin>,
14    #[cfg_attr(feature = "generate-ts", ts(as = "ts_type_helpers::Fee"))]
15    pub fee: Fee,
16}
17
18impl FeeDetails {
19    pub fn new(amount: Option<DecCoin>, fee: Fee) -> Self {
20        FeeDetails { amount, fee }
21    }
22}
23
24// this should really be sealed and NEVER EVER used as "normal" types,
25// but due to our typescript requirements, we have to expose it to generate
26// the types...
27#[cfg(feature = "generate-ts")]
28pub mod ts_type_helpers {
29    use nym_validator_client::nyxd::GasAdjustment;
30    use serde::{Deserialize, Serialize};
31
32    #[derive(Debug, Clone, Serialize, Deserialize, ts_rs::TS)]
33    #[ts(export, export_to = "ts-packages/types/src/types/rust/Fee.ts")]
34    pub enum Fee {
35        Manual(CosmosFee),
36        Auto(Option<GasAdjustment>),
37    }
38
39    #[derive(Debug, Clone, Serialize, Deserialize, ts_rs::TS)]
40    #[ts(export, export_to = "ts-packages/types/src/types/rust/CosmosFee.ts")]
41    // this should corresponds to cosmrs::tx::Fee
42    // IMPORTANT NOTE: this should work as of cosmrs 0.7.1 due to their `FromStr` implementations
43    // on the type. The below struct might have to get readjusted if we update cosmrs!!
44    pub struct CosmosFee {
45        amount: Vec<Coin>,
46        gas_limit: u64,
47        payer: Option<String>,
48        granter: Option<String>,
49    }
50
51    // Note: I've got a feeling this one will bite us hard at some point...
52    #[derive(Debug, Clone, Serialize, Deserialize, ts_rs::TS)]
53    #[ts(export, export_to = "ts-packages/types/src/types/rust/Coin.ts")]
54    // this should corresponds to cosmrs::Coin
55    // IMPORTANT NOTE: this should work as of cosmrs 0.7.1 due to their `FromStr` implementations
56    // on the type. The below struct might have to get readjusted if we update cosmrs!!
57    pub struct Coin {
58        denom: String,
59        // this is not entirely true, but for the purposes
60        // of ts_rs, it's sufficient for the time being
61        amount: u64,
62    }
63}