mars_core/
protocol_rewards_collector.rs1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use thiserror::Error;
4
5use cosmwasm_std::{Addr, Decimal as StdDecimal};
6
7use crate::error::MarsError;
8use crate::helpers::decimal_param_le_one;
9use crate::math::decimal::Decimal;
10
11#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
13pub struct Config {
14 pub owner: Addr,
16 pub address_provider_address: Addr,
18 pub safety_fund_fee_share: Decimal,
20 pub treasury_fee_share: Decimal,
22 pub astroport_factory_address: Addr,
24 pub astroport_max_spread: StdDecimal,
26}
27
28impl Config {
29 pub fn validate(&self) -> Result<(), ConfigError> {
30 decimal_param_le_one(&self.safety_fund_fee_share, "safety_fund_fee_share")?;
31 decimal_param_le_one(&self.treasury_fee_share, "treasury_fee_share")?;
32
33 let combined_fee_share = self.safety_fund_fee_share + self.treasury_fee_share;
34 if combined_fee_share > Decimal::one() {
36 return Err(ConfigError::InvalidFeeShareAmounts {});
37 }
38
39 Ok(())
40 }
41}
42
43#[derive(Error, Debug, PartialEq)]
44pub enum ConfigError {
45 #[error("{0}")]
46 Mars(#[from] MarsError),
47
48 #[error("Invalid fee share amounts. Sum of safety and treasury fee shares exceeds one")]
49 InvalidFeeShareAmounts {},
50}
51
52#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
53pub struct AssetConfig {
54 pub enabled_for_distribution: bool,
55}
56
57#[allow(clippy::derivable_impls)]
58impl Default for AssetConfig {
59 fn default() -> Self {
60 AssetConfig {
61 enabled_for_distribution: false,
62 }
63 }
64}
65
66pub mod msg {
67 use schemars::JsonSchema;
68 use serde::{Deserialize, Serialize};
69
70 use cosmwasm_std::{CosmosMsg, Decimal as StdDecimal, Uint128};
71
72 use astroport::asset::AssetInfo;
73
74 use crate::asset::Asset;
75 use crate::math::decimal::Decimal;
76
77 #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
78 pub struct InstantiateMsg {
79 pub config: CreateOrUpdateConfig,
80 }
81
82 #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
83 pub struct CreateOrUpdateConfig {
84 pub owner: Option<String>,
85 pub address_provider_address: Option<String>,
86 pub safety_fund_fee_share: Option<Decimal>,
87 pub treasury_fee_share: Option<Decimal>,
88 pub astroport_factory_address: Option<String>,
89 pub astroport_max_spread: Option<StdDecimal>,
90 }
91
92 #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
93 #[serde(rename_all = "snake_case")]
94 pub enum ExecuteMsg {
95 UpdateConfig { config: CreateOrUpdateConfig },
97
98 UpdateAssetConfig { asset: Asset, enabled: bool },
100
101 WithdrawFromRedBank {
103 asset: Asset,
104 amount: Option<Uint128>,
105 },
106
107 DistributeProtocolRewards {
111 asset: Asset,
113 amount: Option<Uint128>,
115 },
116
117 SwapAssetToUusd {
119 offer_asset_info: AssetInfo,
120 amount: Option<Uint128>,
121 },
122
123 ExecuteCosmosMsg(CosmosMsg),
125 }
126
127 #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
128 #[serde(rename_all = "snake_case")]
129 pub enum QueryMsg {
130 Config {},
132 AssetConfig { asset: Asset },
134 }
135}