mirror_protocol/
gov.rs

1use cosmwasm_std::{Binary, Decimal, Uint128};
2use cw20::Cw20ReceiveMsg;
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5use std::fmt;
6
7use crate::common::OrderBy;
8
9#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
10pub struct InstantiateMsg {
11    pub mirror_token: String,
12    pub quorum: Decimal,
13    pub threshold: Decimal,
14    pub voting_period: u64,
15    pub effective_delay: u64,
16    pub proposal_deposit: Uint128,
17    pub voter_weight: Decimal,
18    pub snapshot_period: u64,
19}
20
21#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
22#[serde(rename_all = "snake_case")]
23pub enum ExecuteMsg {
24    Receive(Cw20ReceiveMsg),
25    UpdateConfig {
26        owner: Option<String>,
27        quorum: Option<Decimal>,
28        threshold: Option<Decimal>,
29        voting_period: Option<u64>,
30        effective_delay: Option<u64>,
31        proposal_deposit: Option<Uint128>,
32        voter_weight: Option<Decimal>,
33        snapshot_period: Option<u64>,
34    },
35    CastVote {
36        poll_id: u64,
37        vote: VoteOption,
38        amount: Uint128,
39    },
40    WithdrawVotingTokens {
41        amount: Option<Uint128>,
42    },
43    WithdrawVotingRewards {
44        poll_id: Option<u64>,
45    },
46    StakeVotingRewards {
47        poll_id: Option<u64>,
48    },
49    EndPoll {
50        poll_id: u64,
51    },
52    ExecutePoll {
53        poll_id: u64,
54    },
55    SnapshotPoll {
56        poll_id: u64,
57    },
58}
59
60#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
61#[serde(rename_all = "snake_case")]
62pub enum Cw20HookMsg {
63    /// StakeVotingTokens a user can stake their mirror token to receive rewards
64    /// or do vote on polls
65    StakeVotingTokens {},
66    /// CreatePoll need to receive deposit from a proposer
67    CreatePoll {
68        title: String,
69        description: String,
70        link: Option<String>,
71        execute_msg: Option<PollExecuteMsg>,
72    },
73    /// Deposit rewards to be distributed among stakers and voters
74    DepositReward {},
75}
76
77#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
78#[serde(rename_all = "snake_case")]
79pub struct PollExecuteMsg {
80    pub contract: String,
81    pub msg: Binary,
82}
83
84#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
85#[serde(rename_all = "snake_case")]
86pub enum QueryMsg {
87    Config {},
88    State {},
89    Staker {
90        address: String,
91    },
92    Poll {
93        poll_id: u64,
94    },
95    Polls {
96        filter: Option<PollStatus>,
97        start_after: Option<u64>,
98        limit: Option<u32>,
99        order_by: Option<OrderBy>,
100    },
101    Voter {
102        poll_id: u64,
103        address: String,
104    },
105    Voters {
106        poll_id: u64,
107        start_after: Option<String>,
108        limit: Option<u32>,
109        order_by: Option<OrderBy>,
110    },
111    Shares {
112        start_after: Option<String>,
113        limit: Option<u32>,
114        order_by: Option<OrderBy>,
115    },
116}
117
118#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema)]
119pub struct ConfigResponse {
120    pub owner: String,
121    pub mirror_token: String,
122    pub quorum: Decimal,
123    pub threshold: Decimal,
124    pub voting_period: u64,
125    pub effective_delay: u64,
126    pub proposal_deposit: Uint128,
127    pub voter_weight: Decimal,
128    pub snapshot_period: u64,
129}
130
131#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema)]
132pub struct StateResponse {
133    pub poll_count: u64,
134    pub total_share: Uint128,
135    pub total_deposit: Uint128,
136    pub pending_voting_rewards: Uint128,
137}
138
139#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
140pub struct PollResponse {
141    pub id: u64,
142    pub creator: String,
143    pub status: PollStatus,
144    pub end_time: u64,
145    pub title: String,
146    pub description: String,
147    pub link: Option<String>,
148    pub deposit_amount: Uint128,
149    pub execute_data: Option<PollExecuteMsg>,
150    pub yes_votes: Uint128,     // balance
151    pub no_votes: Uint128,      // balance
152    pub abstain_votes: Uint128, // balance
153    pub total_balance_at_end_poll: Option<Uint128>,
154    pub voters_reward: Uint128,
155    pub staked_amount: Option<Uint128>,
156}
157
158#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
159pub struct PollsResponse {
160    pub polls: Vec<PollResponse>,
161}
162
163#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema)]
164pub struct PollCountResponse {
165    pub poll_count: u64,
166}
167
168#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
169pub struct StakerResponse {
170    pub balance: Uint128,
171    pub share: Uint128,
172    pub locked_balance: Vec<(u64, VoterInfo)>,
173    pub withdrawable_polls: Vec<(u64, Uint128)>,
174    pub pending_voting_rewards: Uint128,
175}
176
177#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
178pub struct SharesResponseItem {
179    pub staker: String,
180    pub share: Uint128,
181}
182
183#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
184pub struct SharesResponse {
185    pub stakers: Vec<SharesResponseItem>,
186}
187
188#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
189pub struct VotersResponseItem {
190    pub voter: String,
191    pub vote: VoteOption,
192    pub balance: Uint128,
193}
194
195#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
196pub struct VotersResponse {
197    pub voters: Vec<VotersResponseItem>,
198}
199
200#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
201pub struct MigrateMsg {}
202
203#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
204pub struct VoterInfo {
205    pub vote: VoteOption,
206    pub balance: Uint128,
207}
208
209#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
210#[serde(rename_all = "snake_case")]
211pub enum PollStatus {
212    InProgress,
213    Passed,
214    Rejected,
215    Executed,
216    Expired,
217    Failed,
218}
219
220impl fmt::Display for PollStatus {
221    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
222        write!(f, "{:?}", self)
223    }
224}
225
226#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
227#[serde(rename_all = "snake_case")]
228pub enum VoteOption {
229    Yes,
230    No,
231    Abstain,
232}
233
234impl fmt::Display for VoteOption {
235    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
236        match *self {
237            VoteOption::Yes => write!(f, "yes"),
238            VoteOption::No => write!(f, "no"),
239            VoteOption::Abstain => write!(f, "abstain"),
240        }
241    }
242}