sg_std/
msg.rs

1use crate::route::StargazeRoute;
2use cosmwasm_schema::cw_serde;
3use cosmwasm_std::{Coin, CosmosMsg, CustomMsg};
4static MSG_DATA_VERSION: &str = "1.0.0";
5
6/// StargazeMsg is an override of CosmosMsg::Custom to add support for Stargaze's custom message types
7#[cw_serde]
8pub struct StargazeMsgWrapper {
9    pub route: StargazeRoute,
10    pub msg_data: StargazeMsg,
11    pub version: String,
12}
13
14impl From<StargazeMsgWrapper> for CosmosMsg<StargazeMsgWrapper> {
15    fn from(original: StargazeMsgWrapper) -> Self {
16        CosmosMsg::Custom(original)
17    }
18}
19
20impl CustomMsg for StargazeMsgWrapper {}
21
22#[cw_serde]
23pub enum StargazeMsg {
24    ClaimFor {
25        address: String,
26        action: ClaimAction,
27    },
28    FundCommunityPool {
29        amount: Vec<Coin>,
30    },
31    FundFairburnPool {
32        amount: Vec<Coin>,
33    },
34}
35
36#[cw_serde]
37pub enum ClaimAction {
38    #[serde(rename = "mint_nft")]
39    MintNFT,
40    #[serde(rename = "bid_nft")]
41    BidNFT,
42}
43
44pub fn create_claim_for_msg(address: String, action: ClaimAction) -> CosmosMsg<StargazeMsgWrapper> {
45    StargazeMsgWrapper {
46        route: StargazeRoute::Claim,
47        msg_data: StargazeMsg::ClaimFor { address, action },
48        version: MSG_DATA_VERSION.to_owned(),
49    }
50    .into()
51}
52
53pub fn create_fund_community_pool_msg(amount: Vec<Coin>) -> CosmosMsg<StargazeMsgWrapper> {
54    StargazeMsgWrapper {
55        route: StargazeRoute::Distribution,
56        msg_data: StargazeMsg::FundCommunityPool { amount },
57        version: MSG_DATA_VERSION.to_owned(),
58    }
59    .into()
60}
61
62pub fn create_fund_fairburn_pool_msg(amount: Vec<Coin>) -> CosmosMsg<StargazeMsgWrapper> {
63    StargazeMsgWrapper {
64        route: StargazeRoute::Alloc,
65        msg_data: StargazeMsg::FundFairburnPool { amount },
66        version: MSG_DATA_VERSION.to_owned(),
67    }
68    .into()
69}