mirror_protocol/
staking.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use cosmwasm_std::{Decimal, Uint128};
5use cw20::Cw20ReceiveMsg;
6use terraswap::asset::Asset;
7
8#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
9pub struct InstantiateMsg {
10    pub owner: String,
11    pub mirror_token: String,
12    pub mint_contract: String,
13    pub oracle_contract: String,
14    pub terraswap_factory: String,
15    pub base_denom: String,
16    pub premium_min_update_interval: u64,
17    pub short_reward_contract: String,
18}
19
20#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
21#[serde(rename_all = "snake_case")]
22pub enum ExecuteMsg {
23    Receive(Cw20ReceiveMsg),
24
25    ////////////////////////
26    /// Owner operations ///
27    ////////////////////////
28    UpdateConfig {
29        owner: Option<String>,
30        premium_min_update_interval: Option<u64>,
31        short_reward_contract: Option<String>,
32    },
33    RegisterAsset {
34        asset_token: String,
35        staking_token: String,
36    },
37
38    ////////////////////////
39    /// User operations ///
40    ////////////////////////
41    Unbond {
42        asset_token: String,
43        amount: Uint128,
44    },
45    /// Withdraw pending rewards
46    Withdraw {
47        // If the asset token is not given, then all rewards are withdrawn
48        asset_token: Option<String>,
49    },
50    /// Provides liquidity and automatically stakes the LP tokens
51    AutoStake {
52        assets: [Asset; 2],
53        slippage_tolerance: Option<Decimal>,
54    },
55    /// Hook to stake the minted LP tokens
56    AutoStakeHook {
57        asset_token: String,
58        staking_token: String,
59        staker_addr: String,
60        prev_staking_token_amount: Uint128,
61    },
62
63    //////////////////////////////////
64    /// Permission-less operations ///
65    //////////////////////////////////
66    AdjustPremium {
67        asset_tokens: Vec<String>,
68    },
69
70    ////////////////////////////////
71    /// Mint contract operations ///
72    ////////////////////////////////
73    IncreaseShortToken {
74        asset_token: String,
75        staker_addr: String,
76        amount: Uint128,
77    },
78    DecreaseShortToken {
79        asset_token: String,
80        staker_addr: String,
81        amount: Uint128,
82    },
83}
84
85#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
86#[serde(rename_all = "snake_case")]
87pub enum Cw20HookMsg {
88    Bond { asset_token: String },
89    DepositReward { rewards: Vec<(String, Uint128)> },
90}
91
92/// We currently take no arguments for migrations
93#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
94pub struct MigrateMsg {
95    pub mint_contract: String,
96    pub oracle_contract: String,
97    pub terraswap_factory: String,
98    pub base_denom: String,
99    pub premium_min_update_interval: u64,
100}
101
102#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
103#[serde(rename_all = "snake_case")]
104pub enum QueryMsg {
105    Config {},
106    PoolInfo {
107        asset_token: String,
108    },
109    RewardInfo {
110        staker_addr: String,
111        asset_token: Option<String>,
112    },
113}
114
115// We define a custom struct for each query response
116#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
117pub struct ConfigResponse {
118    pub owner: String,
119    pub mirror_token: String,
120    pub mint_contract: String,
121    pub oracle_contract: String,
122    pub terraswap_factory: String,
123    pub base_denom: String,
124    pub premium_min_update_interval: u64,
125    pub short_reward_contract: String,
126}
127
128// We define a custom struct for each query response
129#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
130pub struct PoolInfoResponse {
131    pub asset_token: String,
132    pub staking_token: String,
133    pub total_bond_amount: Uint128,
134    pub total_short_amount: Uint128,
135    pub reward_index: Decimal,
136    pub short_reward_index: Decimal,
137    pub pending_reward: Uint128,
138    pub short_pending_reward: Uint128,
139    pub premium_rate: Decimal,
140    pub short_reward_weight: Decimal,
141    pub premium_updated_time: u64,
142}
143
144// We define a custom struct for each query response
145#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
146pub struct RewardInfoResponse {
147    pub staker_addr: String,
148    pub reward_infos: Vec<RewardInfoResponseItem>,
149}
150
151#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
152pub struct RewardInfoResponseItem {
153    pub asset_token: String,
154    pub bond_amount: Uint128,
155    pub pending_reward: Uint128,
156    pub is_short: bool,
157}