mars_core/incentives.rs
1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use cosmwasm_std::{Addr, Uint128};
5
6use crate::math::decimal::Decimal;
7
8/// Global configuration
9#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
10pub struct Config {
11 /// Contract owner
12 pub owner: Addr,
13 /// Address provider returns addresses for all protocol contracts
14 pub address_provider_address: Addr,
15}
16
17/// Incentive Metadata for a given incentive
18#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
19pub struct AssetIncentive {
20 /// How much MARS per second is emitted to be then distributed to all maToken holders
21 pub emission_per_second: Uint128,
22 /// Total MARS assigned for distribution since the start of the incentive
23 pub index: Decimal,
24 /// Last time (in seconds) index was updated
25 pub last_updated: u64,
26}
27
28/// Response to AssetIncentive query
29#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
30pub struct AssetIncentiveResponse {
31 /// Existing asset incentive for a given address. Will return None if it doesn't exist
32 pub asset_incentive: Option<AssetIncentive>,
33}
34
35pub mod msg {
36 use cosmwasm_std::{Addr, CosmosMsg, Uint128};
37 use schemars::JsonSchema;
38 use serde::{Deserialize, Serialize};
39
40 #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
41 pub struct InstantiateMsg {
42 /// Contract owner
43 pub owner: String,
44 /// Address provider returns addresses for all protocol contracts
45 pub address_provider_address: String,
46 }
47
48 #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
49 #[serde(rename_all = "snake_case")]
50 pub enum ExecuteMsg {
51 /// Set emission per second for an asset to holders of its maToken
52 SetAssetIncentive {
53 /// maToken address associated with the incentives
54 ma_token_address: String,
55 /// How many MARS will be assigned per second to be distributed among all maToken
56 /// holders
57 emission_per_second: Uint128,
58 },
59
60 /// Handle balance change updating user and asset rewards.
61 /// Sent from an external contract, triggered on user balance changes.
62 /// Will return an empty response if no incentive is applied for the asset
63 BalanceChange {
64 /// User address. Address is trusted as it must be validated by the maToken
65 /// contract before calling this method
66 user_address: Addr,
67 /// User maToken balance up to the instant before the change
68 user_balance_before: Uint128,
69 /// Total maToken supply up to the instant before the change
70 total_supply_before: Uint128,
71 },
72
73 /// Claim rewards. MARS rewards accrued by the user will be staked into xMARS before
74 /// being sent.
75 ClaimRewards {},
76
77 /// Update contract config (only callable by owner)
78 UpdateConfig {
79 owner: Option<String>,
80 address_provider_address: Option<String>,
81 },
82
83 /// Execute Cosmos msg (only callable by owner)
84 ExecuteCosmosMsg(CosmosMsg),
85 }
86
87 #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
88 #[serde(rename_all = "snake_case")]
89 pub enum QueryMsg {
90 /// Query contract config
91 Config {},
92
93 /// Query info about asset incentive for a given maToken
94 AssetIncentive { ma_token_address: String },
95
96 /// Query user current unclaimed rewards
97 UserUnclaimedRewards { user_address: String },
98 }
99}