1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use cosmwasm_schema::{cw_serde, QueryResponses};
use croncat_sdk_core::internal_messages::tasks::{TasksRemoveTaskByManager, TasksRescheduleTask};

use crate::types::TaskRequest;

#[cw_serde]
pub struct TasksInstantiateMsg {
    /// Chain name to add prefix to the task_hash
    pub chain_name: String,

    /// Assigned by Factory, denotes the version of this contract (CW2 spec) & used as the task verion as well.
    pub version: Option<String>,

    /// Address of the contract owner, defaults to the sender
    pub owner_addr: Option<String>,
    /// Name of the key for raw querying Manager address from the factory
    pub croncat_manager_key: (String, [u8; 2]),
    /// Name of the key for raw querying Agents address from the factory
    pub croncat_agents_key: (String, [u8; 2]),

    /// Time in nanos for each bucket of tasks
    pub slot_granularity_time: Option<u64>,

    /// Gas needed to cover proxy call without any action
    pub gas_base_fee: Option<u64>,
    /// Gas needed to cover single non-wasm task's Action
    pub gas_action_fee: Option<u64>,
    /// Gas needed to cover single query
    pub gas_query_fee: Option<u64>,

    /// Gas limit, to make sure task won't lock contract
    pub gas_limit: Option<u64>,
}

#[cw_serde]
pub struct UpdateConfigMsg {
    pub paused: Option<bool>,
    pub owner_addr: Option<String>,
    pub croncat_factory_addr: Option<String>,
    pub croncat_manager_key: Option<(String, [u8; 2])>,
    pub croncat_agents_key: Option<(String, [u8; 2])>,
    pub slot_granularity_time: Option<u64>,
    pub gas_base_fee: Option<u64>,
    pub gas_action_fee: Option<u64>,
    pub gas_query_fee: Option<u64>,
    pub gas_limit: Option<u64>,
}

#[cw_serde]
pub enum TasksExecuteMsg {
    UpdateConfig(UpdateConfigMsg),
    /// Allows any user or contract to pay for future txns based on a specific schedule
    /// contract, function id & other settings. When the task runs out of balance
    /// the task is no longer executed, any additional funds will be returned to task owner.
    CreateTask {
        task: Box<TaskRequest>,
    },

    /// Deletes a task in its entirety, returning any remaining balance to task owner.
    RemoveTask {
        task_hash: String,
    },
    // Methods for other internal contracts
    /// Remove task, used by the manager if task reached it's stop condition
    RemoveTaskByManager(TasksRemoveTaskByManager),
    /// Try to reschedule a task, if possible, used by the manager
    RescheduleTask(TasksRescheduleTask),
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum TasksQueryMsg {
    #[returns(crate::types::Config)]
    Config {},
    /// Get the total amount of tasks
    #[returns(cosmwasm_std::Uint64)]
    TasksTotal {},
    /// CurrentTaskInfo
    #[returns(crate::types::CurrentTaskInfoResponse)]
    CurrentTaskInfo {},
    /// Get the total amount of tasks with queries
    #[returns(cosmwasm_std::Uint64)]
    TasksWithQueriesTotal {},
    /// Get list of active tasks, without queries
    #[returns(Vec<crate::types::TaskInfo>)]
    Tasks {
        from_index: Option<u64>,
        limit: Option<u64>,
    },
    /// Get list of active tasks, with queries
    #[returns(Vec<crate::types::TaskResponse>)]
    TasksWithQueries {
        from_index: Option<u64>,
        limit: Option<u64>,
    },
    /// Get tasks created by the given address
    #[returns(Vec<crate::types::TaskResponse>)]
    TasksByOwner {
        owner_addr: String,
        from_index: Option<u64>,
        limit: Option<u64>,
    },
    /// Get task by the task hash
    #[returns(crate::types::TaskResponse)]
    Task { task_hash: String },
    /// Simulate task_hash by the given task
    #[returns(String)]
    TaskHash { task: Box<crate::types::Task> },
    /// Get slot hashes by given slot
    #[returns(crate::types::SlotHashesResponse)]
    SlotHashes { slot: Option<u64> },
    /// Get active slots
    #[returns(crate::types::SlotIdsResponse)]
    SlotIds {
        from_index: Option<u64>,
        limit: Option<u64>,
    },
    #[returns(crate::types::SlotTasksTotalResponse)]
    SlotTasksTotal { offset: Option<u64> },
    /// Get next task to be done
    #[returns(crate::types::TaskResponse)]
    CurrentTask {},
    /// Get task with queries if it's ready
    /// To get task when it's not ready query [`TasksQueryMsg::Task`] instead
    #[returns(crate::types::TaskResponse)]
    CurrentTaskWithQueries { task_hash: String },
}