cyber_std/
msg.rs

1use cosmwasm_schema::cw_serde;
2use cosmwasm_std::{CosmosMsg, Coin, CustomMsg, Decimal, Uint128};
3use crate::tokenfactory::msg::TokenFactoryMsg;
4use crate::tokenfactory::msg::TokenFactoryMsg::{BurnTokens, ChangeAdmin, CreateDenom, ForceTransfer, MintTokens, SetMetadata};
5use crate::tokenfactory::types::Metadata;
6use crate::types::{Link, Trigger, Load};
7
8impl From<CyberMsg> for CosmosMsg<CyberMsg> {
9    fn from(msg: CyberMsg) -> CosmosMsg<CyberMsg> {
10        CosmosMsg::Custom(msg)
11    }
12}
13
14impl CustomMsg for CyberMsg {}
15
16#[cw_serde]
17pub enum CyberMsg {
18    Cyberlink {
19        neuron: String,
20        links: Vec<Link>,
21    },
22    Investmint {
23        neuron: String,
24        amount: Coin,
25        resource: String,
26        length: u64,
27    },
28    CreateEnergyRoute {
29        source: String,
30        destination: String,
31        name: String,
32    },
33    EditEnergyRoute {
34        source: String,
35        destination: String,
36        value: Coin,
37    },
38    EditEnergyRouteName {
39        source: String,
40        destination: String,
41        name: String,
42    },
43    DeleteEnergyRoute {
44        source: String,
45        destination: String,
46    },
47    CreateThought {
48        program: String,
49        trigger: Trigger,
50        load: Load,
51        name: String,
52        particle: String,
53    },
54    ForgetThought {
55        program: String,
56        name: String,
57    },
58    ChangeThoughtInput {
59        program: String,
60        name: String,
61        input: String,
62    },
63    ChangeThoughtPeriod {
64        program: String,
65        name: String,
66        period: u64,
67    },
68    ChangeThoughtBlock {
69        program: String,
70        name: String,
71        block: u64,
72    },
73    CreatePool {
74        pool_creator_address: String,
75        pool_type_id: u32,
76        deposit_coins: Vec<Coin>,
77    },
78    DepositWithinBatch {
79        depositor_address: String,
80        pool_id: u64,
81        deposit_coins: Vec<Coin>,
82    },
83    WithdrawWithinBatch {
84        withdrawer_address: String,
85        pool_id: u64,
86        pool_coin: Coin,
87    },
88    SwapWithinBatch {
89        swap_requester_address: String,
90        pool_id: u64,
91        swap_type_id: u32,
92        offer_coin: Coin,
93        demand_coin_denom: String,
94        offer_coin_fee: Coin,
95        order_price: Decimal,
96    },
97
98    TokenFactory(TokenFactoryMsg),
99}
100
101impl CyberMsg {
102
103    pub fn create_contract_denom(subdenom: String, metadata: Option<Metadata>) -> Self {
104        Self::TokenFactory(CreateDenom {
105            subdenom,
106            metadata
107        })
108    }
109
110    pub fn change_denom_admin(denom: String, new_admin_address: String) -> Self {
111        Self::TokenFactory(ChangeAdmin {
112            denom,
113            new_admin_address,
114        })
115    }
116
117    pub fn mint_contract_tokens(denom: String, amount: Uint128, mint_to_address: String) -> Self {
118        Self::TokenFactory(MintTokens {
119            denom,
120            amount,
121            mint_to_address,
122        })
123    }
124
125    pub fn burn_contract_tokens(denom: String, amount: Uint128, burn_from_address: String) -> Self {
126        Self::TokenFactory(BurnTokens {
127            denom,
128            amount,
129            burn_from_address,
130        })
131    }
132
133    pub fn force_transfer_tokens(
134        denom: String,
135        amount: Uint128,
136        from_address: String,
137        to_address: String,
138    ) -> Self {
139        Self::TokenFactory(ForceTransfer {
140            denom,
141            amount,
142            from_address,
143            to_address,
144        })
145    }
146
147    pub fn set_metadata(
148        denom: String,
149        metadata: Metadata,
150    ) -> Self {
151        Self::TokenFactory(SetMetadata {
152            denom,
153            metadata
154        })
155    }
156
157    pub fn cyberlink(
158        neuron: String,
159        links: Vec<Link>,
160    ) -> Self {
161        Self::Cyberlink {
162            neuron,
163            links,
164        }
165    }
166
167    pub fn investmint(
168        neuron: String,
169        amount: Coin,
170        resource: String,
171        length: u64,
172    ) -> Self {
173        Self::Investmint {
174            neuron,
175            amount,
176            resource,
177            length,
178        }
179    }
180
181    pub fn create_energy_route(
182        source: String,
183        destination: String,
184        name: String,
185    ) -> Self {
186        Self::CreateEnergyRoute {
187            source,
188            destination,
189            name,
190        }
191    }
192
193    pub fn edit_energy_route(
194        source: String,
195        destination: String,
196        value: Coin,
197    ) -> Self {
198        Self::EditEnergyRoute {
199            source,
200            destination,
201            value,
202        }
203    }
204
205    pub fn edit_energy_route_name(
206        source: String,
207        destination: String,
208        name: String,
209    ) -> Self {
210        Self::EditEnergyRouteName {
211            source,
212            destination,
213            name: name,
214        }
215    }
216
217    pub fn delete_energy_route(
218        source: String,
219        destination: String,
220    ) -> Self {
221        Self::DeleteEnergyRoute {
222            source,
223            destination,
224        }
225    }
226
227    pub fn creat_thought(
228        program: String,
229        trigger: Trigger,
230        load: Load,
231        name: String,
232        particle: String,
233    ) -> Self {
234        Self::CreateThought {
235            program,
236            trigger,
237            load,
238            name,
239            particle,
240        }
241    }
242
243    pub fn forget_thought(
244        program: String,
245        name: String,
246    ) -> Self {
247        Self::ForgetThought {
248            program,
249            name,
250        }
251    }
252
253    pub fn change_thought_input(
254        program: String,
255        name: String,
256        input: String,
257    ) -> Self {
258        Self::ChangeThoughtInput {
259            program,
260            name,
261            input,
262        }
263    }
264
265    pub fn change_thought_period(
266        program: String,
267        name: String,
268        period: u64,
269    ) -> Self {
270        Self::ChangeThoughtPeriod {
271            program,
272            name,
273            period,
274        }
275    }
276
277    pub fn change_thought_block(
278        program: String,
279        name: String,
280        block: u64,
281    ) -> Self {
282        Self::ChangeThoughtBlock {
283            program,
284            name,
285            block,
286        }
287    }
288
289    pub fn create_pool(
290        pool_creator_address: String,
291        pool_type_id: u32,
292        deposit_coins: Vec<Coin>,
293    ) -> Self {
294        Self::CreatePool {
295            pool_creator_address,
296            pool_type_id,
297            deposit_coins,
298        }
299    }
300
301    pub fn deposit_within_batch(
302        depositor_address: String,
303        pool_id: u64,
304        deposit_coins: Vec<Coin>,
305    ) -> Self {
306        Self::DepositWithinBatch {
307            depositor_address,
308            pool_id,
309            deposit_coins,
310        }
311    }
312
313    pub fn withdraw_within_batch(
314        withdrawer_address: String,
315        pool_id: u64,
316        pool_coin: Coin,
317    ) -> Self {
318        Self::WithdrawWithinBatch {
319            withdrawer_address,
320            pool_id,
321            pool_coin,
322        }
323    }
324
325    pub fn swap_within_batch(
326        swap_requester_address: String,
327        pool_id: u64,
328        swap_type_id: u32,
329        offer_coin: Coin,
330        demand_coin_denom: String,
331        offer_coin_fee: Coin,
332        order_price: Decimal,
333    ) -> Self {
334        Self::SwapWithinBatch {
335            swap_requester_address,
336            pool_id,
337            swap_type_id,
338            offer_coin,
339            demand_coin_denom,
340            offer_coin_fee,
341            order_price,
342        }
343    }
344}