1use cosmwasm_std::{
2 to_json_binary, Addr, Binary, Coin, CosmosMsg, DepsMut, StdError, StdResult, WasmMsg,
3};
4use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7
8#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
9pub enum SendType {
10 Wallet {
11 receiver: Addr,
12 },
13 SteakRewards {
14 steak: Addr,
15 receiver: Addr,
16 },
17 DistributeSteakRewards {
18 steak: Addr,
19 receiver: Addr,
20 },
21 TransferSteakRewards {
22 steak: Addr,
23 receiver: Addr,
24 },
25}
26impl ToString for SendType {
27 fn to_string(&self) -> String {
28 match &self {
29 SendType::Wallet {
30 receiver,
31 } => format!("Wallet -> {}", receiver),
32 SendType::SteakRewards {
33 steak,
34 receiver,
35 } => {
36 format!("Steak:{} -> {} -", steak, receiver)
37 },
38 SendType::DistributeSteakRewards {
39 steak,
40 receiver,
41 } => {
42 format!("Steak:{} -> {} DISTRIBUTE", steak, receiver)
43 },
44 SendType::TransferSteakRewards {
45 steak,
46 receiver,
47 } => {
48 format!("Steak:{} -> {} Transfer", steak, receiver)
49 },
50 }
51 }
52}
53impl SendType {
54 #[deprecated(since = "0.2.9", note = "insufficient checking. use verify_details")]
55 pub fn verify(&self, address: &Addr) -> bool {
56 match &self {
57 SendType::Wallet {
58 receiver,
59 } => receiver != address,
60 SendType::SteakRewards {
61 receiver,
62 ..
63 } => receiver != address,
64 SendType::DistributeSteakRewards {
65 receiver,
66 ..
67 } => receiver != address,
68 SendType::TransferSteakRewards {
69 receiver,
70 ..
71 } => receiver != address,
72 }
73 }
74
75 pub fn verify_details(&self, deps: &DepsMut, address: &Addr) -> Result<(), StdError> {
76 match &self {
77 SendType::Wallet {
78 receiver,
79 } => {
80 if receiver != address {
81 deps.api.addr_validate(receiver.as_str())?;
82 Ok(())
83 } else {
84 Err(StdError::generic_err("address recursion"))
85 }
86 },
87 SendType::SteakRewards {
88 receiver,
89 steak,
90 ..
91 } => {
92 if receiver != address {
93 deps.api.addr_validate(receiver.as_str())?;
94 deps.api.addr_validate(steak.as_str())?;
95 Ok(())
96 } else {
97 Err(StdError::generic_err("address recursion"))
98 }
99 },
100 SendType::DistributeSteakRewards {
101 receiver,
102 steak,
103 } => {
104 if receiver != address {
105 deps.api.addr_validate(receiver.as_str())?;
106 deps.api.addr_validate(steak.as_str())?;
107 Ok(())
108 } else {
109 Err(StdError::generic_err("address recursion"))
110 }
111 },
112 SendType::TransferSteakRewards {
113 receiver,
114 steak,
115 } => {
116 if receiver != address {
117 deps.api.addr_validate(receiver.as_str())?;
118 deps.api.addr_validate(steak.as_str())?;
119 Ok(())
120 } else {
121 Err(StdError::generic_err("address recursion"))
122 }
123 },
124 }
125 }
126}
127
128#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
129pub struct AllocationDetail {
130 pub name: String, pub allocation: u8, pub send_after: Coin, pub send_type: SendType, }
136#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
137pub struct AllocationHolding {
138 pub name: String, pub allocation: u8, pub send_after: Coin, pub send_type: SendType, pub balance: Vec<Coin>,
144}
145#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
146pub struct InstantiateMsg {
147 pub name: String,
148 pub gov_contract: String,
149 pub allocation: Vec<AllocationDetail>,
150 pub init_hook: Option<InitHook>,
152}
153#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
155pub struct InitHook {
156 pub msg: Binary,
157 pub contract_addr: String,
158}
159#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
161pub struct MigrateMsg {}
162
163#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
164#[serde(rename_all = "snake_case")]
165
166pub enum ExecuteMsg {
167 Deposit {
169 flush: bool,
170 },
171
172 AddAllocationDetail {
173 name: String,
174 allocation: u8,
175 send_after: Coin,
176 send_type: SendType,
177 },
178 ModifyAllocationDetail {
180 name: String,
181 allocation: u8,
182 send_after: Coin,
183 send_type: SendType,
184 },
185 RemoveAllocationDetail {
187 name: String,
188 },
189 Reconcile {},
192 TransferGovContract {
194 gov_contract: String,
195 blocks: u64,
196 },
197 AcceptGovContract {},
199 AddToFlushWhitelist {
201 address: String,
202 },
203 RemoveFromFlushWhitelist {
205 address: String,
206 },
207}
208impl ExecuteMsg {
209 pub fn into_binary(self) -> StdResult<Binary> {
211 to_json_binary(&self)
213 }
214
215 pub fn into_cosmos_msg<T: Into<String>, C>(
217 self,
218 contract_addr: T,
219 funds: Vec<Coin>,
220 ) -> StdResult<CosmosMsg<C>>
221 where
222 C: Clone + std::fmt::Debug + PartialEq + JsonSchema,
223 {
224 let msg = self.into_binary()?;
225 let execute = WasmMsg::Execute {
226 contract_addr: contract_addr.into(),
227 msg,
228 funds,
229 };
230 Ok(execute.into())
231 }
232}
233
234#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
235#[serde(rename_all = "snake_case")]
236pub enum QueryMsg {
237 Allocations {
240 start_after: Option<String>,
241 limit: Option<u32>,
242 },
243 Allocation {
246 name: String,
247 },
248 Ownership {},
250 FlushWhitelist {},
252}
253#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
254pub struct OwnershipResponse {
255 pub owner: String,
256 pub new_owner: Option<String>,
257 pub block_height: Option<u64>,
258}
259
260#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
261pub struct WhitelistResponse {
262 pub allowed: Vec<String>,
263}
264
265#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
266pub struct AllocationResponse {
267 pub allocations: Vec<AllocationHolding>,
268}