pfc_fee_split/
fee_split_msg.rs

1use cosmwasm_std::{
2    to_json_binary, Addr, Binary, Coin, CosmosMsg, DepsMut, StdError, StdResult, WasmMsg,
3};
4//use cw20::Cw20ReceiveMsg;
5use 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, // user-friendly name of wallet
131    //   pub contract: String,    // contract/wallet to send too
132    pub allocation: u8,      // what portion should we send
133    pub send_after: Coin,    // only send $ after we have this amount in this coin
134    pub send_type: SendType, // type of contract/wallet this is
135}
136#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
137pub struct AllocationHolding {
138    pub name: String, // user-friendly name of wallet
139    // pub contract: Addr,      // contract/wallet to send too
140    pub allocation: u8,      // what portion should we send
141    pub send_after: Coin,    // only send $ after we have this amount in this coin
142    pub send_type: SendType, // type of contract/wallet this is
143    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    // custom_params
151    pub init_hook: Option<InitHook>,
152}
153/// Hook to be called after token initialization
154#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
155pub struct InitHook {
156    pub msg: Binary,
157    pub contract_addr: String,
158}
159/// We currently take no arguments for migrations
160#[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    /// what other contracts will call to start the fly-wheel or fee distribution
168    Deposit {
169        flush: bool,
170    },
171
172    AddAllocationDetail {
173        name: String,
174        allocation: u8,
175        send_after: Coin,
176        send_type: SendType,
177    },
178    // Modifies the fee, but does not send balance
179    ModifyAllocationDetail {
180        name: String,
181        allocation: u8,
182        send_after: Coin,
183        send_type: SendType,
184    },
185    /// Removes the 'fee', sending whatever balance is there over
186    RemoveAllocationDetail {
187        name: String,
188    },
189    /// Queries tokens held, and then re-assigns them to allocations, wiping out whatever was
190    /// there. This is a ADMIN only function (must be called by current gov_contract)
191    Reconcile {},
192    /// Transfer gov-contract to another account; will not take effect unless the new owner accepts
193    TransferGovContract {
194        gov_contract: String,
195        blocks: u64,
196    },
197    /// Accept an gov-contract transfer
198    AcceptGovContract {},
199    /// allow this address to flush funds
200    AddToFlushWhitelist {
201        address: String,
202    },
203    /// remove this address from flush funds whitelist
204    RemoveFromFlushWhitelist {
205        address: String,
206    },
207}
208impl ExecuteMsg {
209    /// serializes the message
210    pub fn into_binary(self) -> StdResult<Binary> {
211        //  let msg = CollectablesExecuteMsg(self);
212        to_json_binary(&self)
213    }
214
215    /// creates a cosmos_msg sending this struct to the named contract
216    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    /// lists all fees
238    /// Return Type: AllocationResponse
239    Allocations {
240        start_after: Option<String>,
241        limit: Option<u32>,
242    },
243    /// Returns allocation with name 'name'
244    /// Return Type: AllocationHolding
245    Allocation {
246        name: String,
247    },
248    /// returns ownership
249    Ownership {},
250    /// returns list of addresses allowed to flush
251    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}