desmos_bindings/tokenfactory/
msg.rs

1//! Contains the messages that can be sent to the chain to interact with the x/tokenfactory module.
2
3use cosmwasm_std::{Addr, Coin};
4
5use crate::cosmos_types::Metadata;
6use crate::tokenfactory::types::*;
7
8/// TokenfactoryMsg is the builder to generate Desmos x/tokenfactory messages.
9pub struct TokenfactoryMsg {}
10
11impl TokenfactoryMsg {
12    /// Creates a new instance of [`MsgCreateDenom`].
13    ///
14    /// * `subspace_id` - Id of the subspace which creates the denom.
15    /// * `sender` - Address of user having the permission to manage subspace denoms.
16    /// * `subdenom` - Subdenom name of the creating denom.
17    pub fn create_denom(subspace_id: u64, sender: Addr, subdenom: &str) -> MsgCreateDenom {
18        MsgCreateDenom {
19            subspace_id,
20            sender: sender.into(),
21            subdenom: subdenom.into(),
22        }
23    }
24
25    /// Creates a new instance of [`MsgMint`].
26    ///
27    /// * `subspace_id` - Id of the subspace which manages the denom.
28    /// * `sender` - Address of user having the permission to manage subspace denoms.
29    /// * `amount` - Amount of the minting subspace tokens.
30    pub fn mint(subspace_id: u64, sender: Addr, amount: Coin) -> MsgMint {
31        MsgMint {
32            subspace_id,
33            sender: sender.into(),
34            amount: Some(amount.into()),
35        }
36    }
37
38    /// Creates a new instance of [`MsgBurn`].
39    ///
40    /// * `subspace_id` - Id of the subspace which manages the denom.
41    /// * `sender` - Address of user having the permission to manage subspace denoms.
42    /// * `amount` - Amount of the burning subspace tokens.
43    pub fn burn(subspace_id: u64, sender: Addr, amount: Coin) -> MsgBurn {
44        MsgBurn {
45            subspace_id,
46            sender: sender.into(),
47            amount: Some(amount.into()),
48        }
49    }
50
51    /// Creates a new instance of [`MsgSetDenomMetadata`].
52    ///
53    /// * `subspace_id` - Id of the subspace which manages the denom.
54    /// * `sender` - Address of user having the permission to manage subspace denoms.
55    /// * `metadata` - Metadata of the denom.
56    pub fn set_denom_metadata(
57        subspace_id: u64,
58        sender: Addr,
59        metadata: Metadata,
60    ) -> MsgSetDenomMetadata {
61        MsgSetDenomMetadata {
62            subspace_id,
63            sender: sender.into(),
64            metadata: Some(metadata),
65        }
66    }
67}
68
69#[cfg(test)]
70mod test {
71    use super::*;
72
73    #[test]
74    fn test_create_denom() {
75        let msg = TokenfactoryMsg::create_denom(1, Addr::unchecked("sender"), "subdenom");
76
77        let expected = MsgCreateDenom {
78            subspace_id: 1,
79            sender: "sender".into(),
80            subdenom: "subdenom".into(),
81        };
82
83        assert_eq!(expected, msg)
84    }
85
86    #[test]
87    fn test_mint() {
88        let msg = TokenfactoryMsg::mint(1, Addr::unchecked("sender"), Coin::new(100, "denom"));
89
90        let expected = MsgMint {
91            subspace_id: 1,
92            sender: "sender".into(),
93            amount: Some(Coin::new(100, "denom").into()),
94        };
95
96        assert_eq!(expected, msg)
97    }
98
99    #[test]
100    fn test_burn() {
101        let msg = TokenfactoryMsg::burn(1, Addr::unchecked("sender"), Coin::new(100, "denom"));
102
103        let expected = MsgBurn {
104            subspace_id: 1,
105            sender: "sender".into(),
106            amount: Some(Coin::new(100, "denom").into()),
107        };
108
109        assert_eq!(expected, msg)
110    }
111
112    #[test]
113    fn test_set_denom_metadata() {
114        let msg = TokenfactoryMsg::set_denom_metadata(
115            1,
116            Addr::unchecked("sender"),
117            Metadata {
118                description: "metadata".into(),
119                denom_units: [].into(),
120                base: "denom".into(),
121                display: "metadata".into(),
122                name: "metadata".into(),
123                symbol: "metadata".into(),
124                uri: "https://metadata".into(),
125                uri_hash: "metadata hash".into(),
126            },
127        );
128
129        let expected = MsgSetDenomMetadata {
130            subspace_id: 1,
131            sender: "sender".into(),
132            metadata: Some(Metadata {
133                description: "metadata".into(),
134                denom_units: [].into(),
135                base: "denom".into(),
136                display: "metadata".into(),
137                name: "metadata".into(),
138                symbol: "metadata".into(),
139                uri: "https://metadata".into(),
140                uri_hash: "metadata hash".into(),
141            }),
142        };
143
144        assert_eq!(expected, msg)
145    }
146}