komple_framework_fee_module/
msg.rs

1use crate::state::Config;
2use cosmwasm_schema::{cw_serde, QueryResponses};
3use cosmwasm_std::{Binary, Decimal, Uint128};
4use cw20::Cw20ReceiveMsg;
5use komple_framework_types::modules::fee::Fees;
6use komple_framework_types::shared::execute::SharedExecuteMsg;
7use komple_framework_types::shared::query::ResponseWrapper;
8
9#[cw_serde]
10pub enum ExecuteMsg {
11    /// Admin message.
12    ///
13    /// Creates a new fee configuration.
14    /// Fees are tied to a module with a fee name.
15    SetFee {
16        fee_type: Fees,
17        module_name: String,
18        fee_name: String,
19        data: Binary,
20    },
21    /// Admin message.
22    ///
23    /// Removes a fee configuration.
24    RemoveFee {
25        fee_type: Fees,
26        module_name: String,
27        fee_name: String,
28    },
29    /// Public message.
30    ///
31    /// Distributes the sent funds according to the fee configuration.
32    /// Custom payment addresses can be specified for
33    /// overriding the default payment addresses.
34    Distribute {
35        fee_type: Fees,
36        module_name: String,
37        custom_payment_addresses: Option<Vec<CustomPaymentAddress>>,
38    },
39    /// Admin message.
40    ///
41    /// Update the operators of this contract.
42    UpdateOperators {
43        addrs: Vec<String>,
44    },
45    /// Hub message.
46    ///
47    /// Lock the execute entry point.
48    /// Can only be called by the hub module.
49    LockExecute {},
50    Receive(Cw20ReceiveMsg),
51}
52
53impl From<ExecuteMsg> for SharedExecuteMsg {
54    fn from(msg: ExecuteMsg) -> Self {
55        match msg {
56            ExecuteMsg::LockExecute {} => SharedExecuteMsg::LockExecute {},
57            _ => unreachable!("Cannot convert {:?} to SharedExecuteMessage", msg),
58        }
59    }
60}
61
62#[cw_serde]
63pub enum ReceiveMsg {
64    Distribute {
65        fee_type: Fees,
66        module_name: String,
67        custom_payment_addresses: Option<Vec<CustomPaymentAddress>>,
68    },
69}
70
71#[cw_serde]
72#[derive(QueryResponses)]
73pub enum QueryMsg {
74    /// Gets the contract's config.
75    #[returns(ResponseWrapper<Config>)]
76    Config {},
77    /// Gets the fee configuration for a module and fee name. Used for percentage fees.
78    #[returns(ResponseWrapper<PercentageFeeResponse>)]
79    PercentageFee {
80        module_name: String,
81        fee_name: String,
82    },
83    /// Gets the fee configuration for a module and fee name. Used for fixed fees.
84    #[returns(ResponseWrapper<FixedFeeResponse>)]
85    FixedFee {
86        module_name: String,
87        fee_name: String,
88    },
89    /// Gets the fee configurations for a module with pagination. Used for percentage fees.
90    #[returns(ResponseWrapper<Vec<PercentageFeeResponse>>)]
91    PercentageFees {
92        module_name: String,
93        start_after: Option<String>,
94        limit: Option<u32>,
95    },
96    /// Gets the fee configurations for a module with pagination. Used for fixed fees.
97    #[returns(ResponseWrapper<Vec<FixedFeeResponse>>)]
98    FixedFees {
99        module_name: String,
100        start_after: Option<String>,
101        limit: Option<u32>,
102    },
103    /// Gets the sum of all the percentages for a given module.
104    #[returns(ResponseWrapper<Decimal>)]
105    TotalPercentageFees {
106        module_name: String,
107        start_after: Option<String>,
108        limit: Option<u32>,
109    },
110    /// Gets the sum of all the fixed amounts for a given module.
111    #[returns(ResponseWrapper<Uint128>)]
112    TotalFixedFees {
113        module_name: String,
114        start_after: Option<String>,
115        limit: Option<u32>,
116    },
117    /// Gets all the module names and fee names for a given fee type.
118    #[returns(ResponseWrapper<Vec<String>>)]
119    Keys {
120        fee_type: Fees,
121        start_after: Option<String>,
122        limit: Option<u32>,
123    },
124    /// Get the operators of this contract.
125    #[returns(ResponseWrapper<Vec<String>>)]
126    Operators {},
127}
128
129#[cw_serde]
130pub struct PercentageFeeResponse {
131    pub module_name: String,
132    pub fee_name: String,
133    pub address: Option<String>,
134    pub value: Decimal,
135}
136
137#[cw_serde]
138pub struct FixedFeeResponse {
139    pub module_name: String,
140    pub fee_name: String,
141    pub address: Option<String>,
142    pub value: Uint128,
143}
144
145/// Used for overriding the default payment addresses.
146#[cw_serde]
147pub struct CustomPaymentAddress {
148    pub fee_name: String,
149    pub address: String,
150}