1use std::str::FromStr;
2
3use cosmwasm_std::{
4 to_json_binary, Addr, Binary, Coin, CosmosMsg, Decimal, Empty, StdResult, Uint128, WasmMsg,
5};
6use cw20::Cw20ReceiveMsg;
7use cw20_base::msg::InstantiateMarketingInfo as Cw20InstantiateMarketingInfo;
8use schemars::JsonSchema;
9use serde::{Deserialize, Serialize};
10
11#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
12pub enum Cw20HookMsg {
13 Distribute {},
14 Transfer {},
15}
16
17#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
18pub enum EnterpriseCw20HookMsg {
19 Distribute {},
20}
21
22#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
23pub struct InstantiateMsg {
24 pub cw20_code_id: u64,
26 pub owner: String,
28 pub name: String,
30 pub symbol: String,
32 pub decimals: u8,
34 pub epoch_period: u64,
36 pub unbond_period: u64,
38 pub validators: Vec<String>,
40 pub denom: String,
42 pub fee_account_type: String,
44 pub fee_account: String,
46 pub fee_amount: Decimal,
48 pub max_fee_amount: Decimal,
50 pub label: Option<String>,
52 pub marketing: Option<Cw20InstantiateMarketingInfo>,
54 pub dust_collector: Option<String>,
55}
56
57#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
58#[serde(rename_all = "snake_case")]
59pub enum ExecuteMsg {
60 Receive(Cw20ReceiveMsg),
62 Bond {
64 receiver: Option<String>,
65 exec_msg: Option<Binary>,
66 },
67 BondEx {
69 receiver: Option<String>,
70 },
71 WithdrawUnbonded {
73 receiver: Option<String>,
74 },
75 WithdrawUnbondedAdmin {
77 address: String,
78 },
79 AddValidator {
81 validator: String,
82 },
83 RemoveValidator {
85 validator: String,
86 },
87 RemoveValidatorEx {
90 validator: String,
91 },
92
93 PauseValidator {
95 validator: String,
96 },
97 UnPauseValidator {
99 validator: String,
100 },
101
102 TransferOwnership {
104 new_owner: String,
105 },
106 AcceptOwnership {},
108 Harvest {},
110 Rebalance {
112 minimum: Uint128,
113 },
114 Redelegate {
116 validator_from: String,
117 validator_to: String,
118 },
119 Reconcile {},
121 SubmitBatch {},
123 SetUnbondPeriod {
125 unbond_period: u64,
126 },
127
128 TransferFeeAccount {
130 fee_account_type: String,
131 new_fee_account: String,
132 },
133 UpdateFee {
135 new_fee: Decimal,
136 },
137 Callback(CallbackMsg),
139 SetDustCollector {
141 dust_collector: Option<String>,
142 },
143 CollectDust {
145 max_tokens: u32,
146 },
147 ReturnDenom {},
149}
150
151#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
152#[serde(rename_all = "snake_case")]
153pub enum ReceiveMsg {
154 QueueUnbond {
157 receiver: Option<String>,
158 },
159}
160
161#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
162#[serde(rename_all = "snake_case")]
163pub enum CallbackMsg {
164 Reinvest {},
166}
167
168impl CallbackMsg {
169 pub fn into_cosmos_msg(&self, contract_addr: &Addr) -> StdResult<CosmosMsg> {
170 Ok(CosmosMsg::Wasm(WasmMsg::Execute {
171 contract_addr: contract_addr.to_string(),
172 msg: to_json_binary(&ExecuteMsg::Callback(self.clone()))?,
173 funds: vec![],
174 }))
175 }
176}
177
178#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
179#[serde(rename_all = "snake_case")]
180pub enum QueryMsg {
181 Config {},
183 State {},
185 PendingBatch {},
187 PreviousBatch(u64),
190 PreviousBatches {
193 start_after: Option<u64>,
194 limit: Option<u32>,
195 },
196 UnbondRequestsByBatch {
199 id: u64,
200 start_after: Option<String>,
201 limit: Option<u32>,
202 },
203 UnbondRequestsByUser {
206 user: String,
207 start_after: Option<u64>,
208 limit: Option<u32>,
209 },
210}
211
212#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
213pub struct ConfigResponse {
214 pub owner: String,
216 pub new_owner: Option<String>,
218 pub steak_token: String,
220 pub epoch_period: u64,
222 pub unbond_period: u64,
224 pub denom: String,
226 pub fee_type: String,
228 pub fee_account: String,
230 pub fee_rate: Decimal,
232 pub max_fee_rate: Decimal,
234 pub validators: Vec<String>,
236 pub paused_validators: Vec<String>,
237 pub dust_collector: Option<String>,
238 pub token_factory: Option<String>,
239}
240
241#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
242pub struct StateResponse {
243 pub total_usteak: Uint128,
245 pub total_native: Uint128,
247 pub exchange_rate: Decimal,
249 pub unlocked_coins: Vec<Coin>,
251}
252
253#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
254pub struct PendingBatch {
255 pub id: u64,
257 pub usteak_to_burn: Uint128,
259 pub est_unbond_start_time: u64,
261}
262
263#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
264pub struct Batch {
265 pub id: u64,
267 pub reconciled: bool,
269 pub total_shares: Uint128,
271 pub amount_unclaimed: Uint128,
273 pub est_unbond_end_time: u64,
275}
276
277#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
278pub struct UnbondRequest {
279 pub id: u64,
281 pub user: Addr,
283 pub shares: Uint128,
285}
286
287#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
288pub struct UnbondRequestsByBatchResponseItem {
289 pub user: String,
291 pub shares: Uint128,
293}
294
295impl From<UnbondRequest> for UnbondRequestsByBatchResponseItem {
296 fn from(s: UnbondRequest) -> Self {
297 Self {
298 user: s.user.into(),
299 shares: s.shares,
300 }
301 }
302}
303
304#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
305pub struct UnbondRequestsByUserResponseItem {
306 pub id: u64,
308 pub shares: Uint128,
310}
311
312impl From<UnbondRequest> for UnbondRequestsByUserResponseItem {
313 fn from(s: UnbondRequest) -> Self {
314 Self {
315 id: s.id,
316 shares: s.shares,
317 }
318 }
319}
320
321pub type MigrateMsg = Empty;
322
323#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Copy, JsonSchema)]
324pub enum FeeType {
325 Wallet,
326 FeeSplit,
327}
328
329impl FromStr for FeeType {
330 type Err = ();
331
332 fn from_str(s: &str) -> Result<Self, Self::Err> {
333 match s {
334 "Wallet" => Ok(FeeType::Wallet),
335 "FeeSplit" => Ok(FeeType::FeeSplit),
336 _ => Err(()),
337 }
338 }
339}
340
341impl ToString for FeeType {
342 fn to_string(&self) -> String {
343 match &self {
344 FeeType::Wallet => String::from("Wallet"),
345 FeeType::FeeSplit => String::from("FeeSplit"),
346 }
347 }
348}