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 quorum: Decimal,
12 pub threshold: Decimal,
13 pub voting_period: u64,
14 pub timelock_period: u64,
15 pub proposal_deposit: Uint128,
16 pub snapshot_period: u64,
17}
18
19#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
20#[serde(rename_all = "snake_case")]
21pub enum ExecuteMsg {
22 Receive(Cw20ReceiveMsg),
23 ExecutePollMsgs {
24 poll_id: u64,
25 },
26 RegisterContracts {
27 anchor_token: String,
28 },
29 UpdateConfig {
30 owner: Option<String>,
31 quorum: Option<Decimal>,
32 threshold: Option<Decimal>,
33 voting_period: Option<u64>,
34 timelock_period: Option<u64>,
35 proposal_deposit: Option<Uint128>,
36 snapshot_period: Option<u64>,
37 },
38 CastVote {
39 poll_id: u64,
40 vote: VoteOption,
41 amount: Uint128,
42 },
43 WithdrawVotingTokens {
44 amount: Option<Uint128>,
45 },
46 EndPoll {
47 poll_id: u64,
48 },
49 ExecutePoll {
50 poll_id: u64,
51 },
52 SnapshotPoll {
53 poll_id: u64,
54 },
55}
56
57#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
58#[serde(rename_all = "snake_case")]
59pub enum Cw20HookMsg {
60 StakeVotingTokens {},
63 CreatePoll {
65 title: String,
66 description: String,
67 link: Option<String>,
68 execute_msgs: Option<Vec<PollExecuteMsg>>,
69 },
70}
71
72#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
73#[serde(rename_all = "snake_case")]
74pub struct PollExecuteMsg {
75 pub order: u64,
76 pub contract: String,
77 pub msg: Binary,
78}
79
80#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
81#[serde(rename_all = "snake_case")]
82pub enum QueryMsg {
83 Config {},
84 State {},
85 Staker {
86 address: String,
87 },
88 Poll {
89 poll_id: u64,
90 },
91 Polls {
92 filter: Option<PollStatus>,
93 start_after: Option<u64>,
94 limit: Option<u32>,
95 order_by: Option<OrderBy>,
96 },
97 Voters {
98 poll_id: u64,
99 start_after: Option<String>,
100 limit: Option<u32>,
101 order_by: Option<OrderBy>,
102 },
103}
104
105#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema)]
106pub struct ConfigResponse {
107 pub owner: String,
108 pub anchor_token: String,
109 pub quorum: Decimal,
110 pub threshold: Decimal,
111 pub voting_period: u64,
112 pub timelock_period: u64,
113 pub proposal_deposit: Uint128,
114 pub snapshot_period: u64,
115}
116
117#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema)]
118pub struct StateResponse {
119 pub poll_count: u64,
120 pub total_share: Uint128,
121 pub total_deposit: Uint128,
122}
123
124#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
125pub struct PollResponse {
126 pub id: u64,
127 pub creator: String,
128 pub status: PollStatus,
129 pub end_height: u64,
130 pub title: String,
131 pub description: String,
132 pub link: Option<String>,
133 pub deposit_amount: Uint128,
134 pub execute_data: Option<Vec<PollExecuteMsg>>,
135 pub yes_votes: Uint128, pub no_votes: Uint128, pub staked_amount: Option<Uint128>,
138 pub total_balance_at_end_poll: Option<Uint128>,
139}
140
141#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
142pub struct PollsResponse {
143 pub polls: Vec<PollResponse>,
144}
145
146#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema)]
147pub struct PollCountResponse {
148 pub poll_count: u64,
149}
150
151#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
152pub struct StakerResponse {
153 pub balance: Uint128,
154 pub share: Uint128,
155 pub locked_balance: Vec<(u64, VoterInfo)>,
156}
157
158#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
159pub struct VotersResponseItem {
160 pub voter: String,
161 pub vote: VoteOption,
162 pub balance: Uint128,
163}
164
165#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
166pub struct VotersResponse {
167 pub voters: Vec<VotersResponseItem>,
168}
169
170#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
171pub struct VoterInfo {
172 pub vote: VoteOption,
173 pub balance: Uint128,
174}
175
176#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
177#[serde(rename_all = "snake_case")]
178pub enum PollStatus {
179 InProgress,
180 Passed,
181 Rejected,
182 Executed,
183 Expired, Failed,
185}
186
187impl fmt::Display for PollStatus {
188 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
189 write!(f, "{:?}", self)
190 }
191}
192
193#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
194#[serde(rename_all = "snake_case")]
195pub enum VoteOption {
196 Yes,
197 No,
198}
199
200impl fmt::Display for VoteOption {
201 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
202 if *self == VoteOption::Yes {
203 write!(f, "yes")
204 } else {
205 write!(f, "no")
206 }
207 }
208}