croncat_sdk_agents/msg.rs
1use crate::types::AgentStatus;
2use cosmwasm_schema::{cw_serde, QueryResponses};
3use cosmwasm_std::{Addr, Timestamp, Uint128, Uint64};
4use croncat_sdk_core::internal_messages::agents::{AgentOnTaskCompleted, AgentOnTaskCreated};
5
6#[cw_serde]
7pub struct InstantiateMsg {
8 /// A multisig admin whose sole responsibility is to pause the contract in event of emergency.
9 /// Must be a different contract address than DAO, cannot be a regular keypair
10 /// Does not have the ability to unpause, must rely on the DAO to assess the situation and act accordingly
11 pub pause_admin: Addr,
12
13 /// CW2 Version provided by factory
14 pub version: Option<String>,
15
16 /// Name of the key for raw querying Manager address from the factory
17 pub croncat_manager_key: (String, [u8; 2]),
18
19 /// Name of the key for raw querying Tasks address from the factory
20 pub croncat_tasks_key: (String, [u8; 2]),
21
22 /// Sets the amount of time opportunity for a pending agent to become active.
23 /// If there is a pending queue, the longer a pending agent waits,
24 /// the more pending agents can potentially become active based on this nomination window.
25 /// This duration doesn't block the already nominated agent from becoming active,
26 /// it only opens the door for more to become active. If a pending agent is nominated,
27 /// then is lazy and beat by another agent, they get removed from pending queue and must
28 /// register again.
29 pub agent_nomination_duration: Option<u16>,
30
31 /// The ratio used to calculate active agents/tasks. Example: "3", requires there are
32 /// 4 tasks before letting in another agent to become active. (3 tasks for agent 1, 1 task for agent 2)
33 pub min_tasks_per_agent: Option<u64>,
34
35 /// The required amount needed to actually execute a few tasks before withdraw profits.
36 /// This helps make sure agent wont get stuck out the gate
37 pub min_coins_for_agent_registration: Option<u64>,
38
39 /// How many slots an agent can miss before being removed from the active queue
40 pub agents_eject_threshold: Option<u64>,
41
42 /// Minimum agent count in active queue to be untouched by bad agent verifier
43 pub min_active_agent_count: Option<u16>,
44
45 /// Whether agent registration is public or restricted to an internal whitelist
46 pub public_registration: bool,
47
48 /// If public registration is false, this provides initial, approved agent addresses
49 pub allowed_agents: Option<Vec<String>>,
50}
51
52/// Execute messages for agent contract
53#[cw_serde]
54pub enum ExecuteMsg {
55 /// Adds an agent address to the internal whitelist
56 AddAgentToWhitelist { agent_address: String },
57 /// Removes an agent from the whitelist
58 /// Note: this does not kick the agent, but instead means they will not be able to re-register
59 RemoveAgentFromWhitelist { agent_address: String },
60 /// Action registers new agent
61 RegisterAgent { payable_account_id: Option<String> },
62 /// Action for updating agents
63 UpdateAgent { payable_account_id: String },
64 /// Action moves agent from pending to active list
65 CheckInAgent {},
66 /// Actions for removing agent from the system
67 UnregisterAgent { from_behind: Option<bool> },
68 /// Task contract will send message when task is created
69 OnTaskCreated(AgentOnTaskCreated),
70 /// Task contract will send message when task is completed
71 OnTaskCompleted(AgentOnTaskCompleted),
72 /// Action for updating agent contract configuration
73 UpdateConfig { config: UpdateConfig },
74 /// Tick action will remove unactive agents periodically or do and any other internal cron tasks
75 Tick {},
76 /// Pauses all operations for this contract, can only be done by pause_admin
77 PauseContract {},
78 /// unpauses all operations for this contract, can only be unpaused by owner_addr
79 UnpauseContract {},
80}
81
82/// Agent request response
83#[cw_serde]
84#[derive(QueryResponses)]
85pub enum QueryMsg {
86 /// Get an agent by specified account_id, returns AgentInfo if found
87 #[returns[AgentResponse]]
88 GetAgent { account_id: String },
89 /// Gets the id list of agents, pagination is supported
90 #[returns[GetAgentIdsResponse]]
91 GetAgentIds {
92 from_index: Option<u64>,
93 limit: Option<u64>,
94 },
95 /// Gets the approved agents' addresses, pagination is supported
96 /// This only applies when Config's `public_registration` is false
97 #[returns[ApprovedAgentAddresses]]
98 GetApprovedAgentAddresses {
99 from_index: Option<u64>,
100 limit: Option<u64>,
101 },
102 /// Gets the specified agent tasks
103 #[returns[AgentTaskResponse]]
104 GetAgentTasks { account_id: String },
105 /// Gets the agent contract configuration
106 #[returns[crate::types::Config]]
107 Config {},
108
109 /// Helper for query responses on versioned contracts
110 #[returns[bool]]
111 Paused {},
112}
113/// Response containing active/pending agents
114#[cw_serde]
115pub struct GetAgentIdsResponse {
116 /// Active agent list
117 pub active: Vec<Addr>,
118 /// Pending agent list
119 pub pending: Vec<Addr>,
120}
121/// Response containing approved agents' addresses
122#[cw_serde]
123pub struct ApprovedAgentAddresses {
124 /// Active agent list
125 pub approved_addresses: Vec<Addr>,
126}
127/// Agent data
128#[cw_serde]
129pub struct AgentInfo {
130 /// Agent status
131 pub status: AgentStatus,
132 /// Account where agent will move all his rewards
133 pub payable_account_id: Addr,
134 /// Agent reward balance
135 pub balance: Uint128,
136 /// Last executed slot number
137 pub last_executed_slot: u64,
138 /// Registration time
139 pub register_start: Timestamp,
140 /// Execution Totals - helpful for alerting & displays
141 pub completed_block_tasks: Uint64,
142 pub completed_cron_tasks: Uint64,
143 pub missed_blocked_tasks: Uint64,
144 pub missed_cron_tasks: Uint64,
145}
146/// Agent response containing agent information
147#[cw_serde]
148pub struct AgentResponse {
149 /// Agent data
150 pub agent: Option<AgentInfo>,
151}
152/// Agent statistics data
153#[cw_serde]
154pub struct TaskStats {
155 /// Total block tasks for specified agent
156 pub num_block_tasks: Uint64,
157 /// Total cron tasks for specified agent
158 pub num_cron_tasks: Uint64,
159}
160/// Agent task response for getting stats and task information
161#[cw_serde]
162pub struct AgentTaskResponse {
163 /// Agent tasks statistic information
164 pub stats: TaskStats,
165}
166/// Updatable agents contract configuration
167#[cw_serde]
168pub struct UpdateConfig {
169 /// Name of the key for raw querying Manager address from the factory
170 pub croncat_manager_key: Option<(String, [u8; 2])>,
171
172 /// Name of the key for raw querying Tasks address from the factory
173 pub croncat_tasks_key: Option<(String, [u8; 2])>,
174
175 /// Minimum tasks count to be reached by agent before next agent nomination
176 pub min_tasks_per_agent: Option<u64>,
177
178 /// Duration to be passed before next agent nomination
179 pub agent_nomination_duration: Option<u16>,
180
181 /// Minimum funds to be attached for agent registration
182 pub min_coins_for_agent_registration: Option<u64>,
183
184 /// How many slots an agent can miss before being removed from the active queue
185 pub agents_eject_threshold: Option<u64>,
186
187 /// Minimum agent count in active queue to be untouched by bad agent verifier
188 pub min_active_agent_count: Option<u16>,
189
190 /// Determines whether agent registration is public or uses the whitelist (APPROVED_AGENTS Map)
191 pub public_registration: Option<bool>,
192}