osmo_bindings/
msg.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use crate::types::SwapAmountWithLimit;
5use crate::{Step, Swap};
6use cosmwasm_std::{CosmosMsg, CustomMsg, Uint128};
7
8#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
9#[serde(rename_all = "snake_case")]
10/// A number of Custom messages that can call into the Osmosis bindings
11pub enum OsmosisMsg {
12    /// Contracts can mint native tokens that have an auto-generated denom
13    /// namespaced under the contract's address. A contract may create any number
14    /// of independent sub-denoms.
15    /// Returns FullDenomResponse in the data field of the Response
16    MintTokens {
17        /// sub_denoms (nonces in Osmosis) are validated as part of the full denomination.
18        /// Can be up to 128 - prefix length (currently 7) - bech32 address length (4 (osmo) + 39) - number of separators (2) =
19        /// 76 "alphanumeric" (https://github.com/cosmos/cosmos-sdk/blob/2646b474c7beb0c93d4fafd395ef345f41afc251/types/coin.go#L677)
20        /// characters long.
21        /// Empty sub-denoms are valid. The token will then be prefix + contract address, i.e. "factory/<bech32 address>/"
22        sub_denom: String,
23        amount: Uint128,
24        recipient: String,
25    },
26    /// Swap over one or more pools
27    /// Returns SwapResponse in the data field of the Response
28    Swap {
29        first: Swap,
30        route: Vec<Step>,
31        amount: SwapAmountWithLimit,
32    },
33}
34
35impl OsmosisMsg {
36    /// Basic helper to define a swap with one pool
37    pub fn simple_swap(
38        pool_id: u64,
39        denom_in: impl Into<String>,
40        denom_out: impl Into<String>,
41        amount: SwapAmountWithLimit,
42    ) -> Self {
43        OsmosisMsg::Swap {
44            first: Swap::new(pool_id, denom_in, denom_out),
45            amount,
46            route: vec![],
47        }
48    }
49}
50
51impl From<OsmosisMsg> for CosmosMsg<OsmosisMsg> {
52    fn from(msg: OsmosisMsg) -> CosmosMsg<OsmosisMsg> {
53        CosmosMsg::Custom(msg)
54    }
55}
56
57impl CustomMsg for OsmosisMsg {}