warp_controller_pkg/
job.rs

1use crate::account::AssetInfo;
2use cosmwasm_schema::cw_serde;
3use cosmwasm_std::{Addr, Uint128, Uint64};
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6use strum_macros::Display;
7
8// pub enum JobFund {
9//     Cw20(...),
10//     Native(...),
11//     Ibc(...)
12// }
13
14// 1. create_account (can potential embed funds here)
15// 2. cw20_sends, native (native send or within the create_job msg itself), ibc_send (to account)
16// 3. create_job msg
17//      - job.funds -> withdraw_asset_from_account(...), withdraws from account to controller contract
18// ...
19// 4. execute_job msg
20//      - job succceeded -
21
22#[cw_serde]
23pub struct Job {
24    pub id: Uint64,
25    pub owner: Addr,
26    pub last_update_time: Uint64,
27    pub name: String,
28    pub description: String,
29    pub labels: Vec<String>,
30    pub status: JobStatus,
31    pub condition: String,
32    pub terminate_condition: Option<String>,
33    pub msgs: String,
34    pub vars: String,
35    pub recurring: bool,
36    pub requeue_on_evict: bool,
37    pub reward: Uint128,
38    pub assets_to_withdraw: Vec<AssetInfo>,
39}
40
41#[cw_serde]
42pub enum JobVarKind {
43    Query,
44    External,
45}
46
47#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, Display)]
48pub enum JobStatus {
49    Pending,
50    Executed,
51    Failed,
52    Cancelled,
53    Evicted,
54}
55
56#[cw_serde]
57pub struct CreateJobMsg {
58    pub name: String,
59    pub description: String,
60    pub labels: Vec<String>,
61    pub condition: String,
62    pub terminate_condition: Option<String>,
63    pub msgs: String,
64    pub vars: String,
65    pub recurring: bool,
66    pub requeue_on_evict: bool,
67    pub reward: Uint128,
68    pub assets_to_withdraw: Option<Vec<AssetInfo>>,
69}
70
71#[cw_serde]
72pub struct DeleteJobMsg {
73    pub id: Uint64,
74}
75
76#[cw_serde]
77pub struct UpdateJobMsg {
78    pub id: Uint64,
79    pub name: Option<String>,
80    pub description: Option<String>,
81    pub labels: Option<Vec<String>>,
82    pub added_reward: Option<Uint128>,
83}
84
85#[cw_serde]
86pub struct ExecuteJobMsg {
87    pub id: Uint64,
88    pub external_inputs: Option<Vec<ExternalInput>>,
89}
90
91#[cw_serde]
92pub struct EvictJobMsg {
93    pub id: Uint64,
94}
95
96#[cw_serde]
97pub struct ExternalInput {
98    pub name: String,
99    pub input: String,
100}
101
102#[cw_serde]
103pub struct QueryJobMsg {
104    pub id: Uint64,
105}
106
107#[cw_serde]
108pub struct QueryJobsMsg {
109    pub ids: Option<Vec<Uint64>>,
110    pub active: Option<bool>,
111    pub owner: Option<Addr>,
112    pub name: Option<String>,
113    pub job_status: Option<JobStatus>,
114    pub condition_status: Option<bool>,
115    pub start_after: Option<JobIndex>,
116    pub limit: Option<u32>,
117}
118
119#[cw_serde]
120pub struct JobIndex {
121    pub _0: Uint128,
122    pub _1: Uint64,
123}
124
125impl QueryJobsMsg {
126    pub fn valid_query(&self) -> bool {
127        (self.ids.is_some() as u8
128            + (self.owner.is_some()
129                || self.name.is_some()
130                || self.job_status.is_some()
131                || self.condition_status.is_some()) as u8)
132            <= 1
133    }
134}
135
136#[cw_serde]
137pub struct QueryResolveJobConditionMsg {
138    pub id: Uint64,
139}
140
141#[cw_serde]
142pub struct JobResponse {
143    pub job: Job,
144}
145
146#[cw_serde]
147pub struct JobsResponse {
148    pub jobs: Vec<Job>,
149    pub total_count: usize,
150}