croncat_sdk_agents/types.rs
1use cosmwasm_schema::cw_serde;
2use cosmwasm_std::{Addr, Timestamp};
3use std::fmt;
4
5#[cw_serde]
6pub struct AgentNominationStatus {
7 pub start_height_of_nomination: Option<u64>,
8 pub tasks_created_from_last_nomination: u64,
9}
10
11#[cw_serde]
12pub enum AgentStatus {
13 // Default for any new agent, if tasks ratio allows
14 Active,
15
16 // Default for any new agent, until more tasks come online
17 Pending,
18
19 // More tasks are available, agent must checkin to become active
20 Nominated,
21}
22
23impl fmt::Display for AgentStatus {
24 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25 match self {
26 AgentStatus::Active => write!(f, "active"),
27 AgentStatus::Pending => write!(f, "pending"),
28 AgentStatus::Nominated => write!(f, "nominated"),
29 }
30 }
31}
32
33#[cw_serde]
34pub struct Agent {
35 // Where rewards get transferred
36 pub payable_account_id: Addr,
37
38 // Timestamp of when agent first registered
39 // Useful for rewarding agents for their patience while they are pending and operating service
40 // Agent will be responsible to constantly monitor when it is their turn to join in active agent set (done as part of agent code loops)
41 // Example data: 1633890060000000000 or 0
42 pub register_start: Timestamp,
43}
44
45#[cw_serde]
46#[derive(Default)]
47pub struct AgentStats {
48 pub completed_block_tasks: u64,
49 pub completed_cron_tasks: u64,
50 pub missed_blocked_tasks: u64,
51 pub missed_cron_tasks: u64,
52 // Holds slot number of the last slot when agent called proxy_call.
53 // If agent does a task, this number is set to the current block.
54 pub last_executed_slot: u64,
55}
56/// Contract configuration state
57#[cw_serde]
58pub struct Config {
59 /// Address of the factory contract
60 pub croncat_factory_addr: Addr,
61 /// Name of the key for raw querying Manager address from the factory
62 pub croncat_manager_key: (String, [u8; 2]),
63 /// Name of the key for raw querying Tasks address from the factory
64 pub croncat_tasks_key: (String, [u8; 2]),
65 /// Contract owner address
66 pub owner_addr: Addr,
67 /// A multisig admin whose sole responsibility is to pause the contract in event of emergency.
68 /// Must be a different contract address than DAO, cannot be a regular keypair
69 /// Does not have the ability to unpause, must rely on the DAO to assess the situation and act accordingly
70 pub pause_admin: Addr,
71 /// Agent management
72 /// The minimum number of tasks per agent
73 /// Example: 10
74 /// Explanation: For every 1 agent, 10 tasks per slot are available.
75 /// NOTE: Caveat, when there are odd number of tasks or agents, the overflow will be available to first-come, first-serve. This doesn't negate the possibility of a failed txn from race case choosing winner inside a block.
76 /// NOTE: The overflow will be adjusted to be handled by sweeper in next implementation.
77 pub min_tasks_per_agent: u64,
78 /// The duration a prospective agent has to nominate themselves.
79 /// When a task is created such that a new agent can join,
80 /// The agent at the zeroth index of the pending agent queue has this time to nominate
81 /// The agent at the first index has twice this time to nominate (which would remove the former agent from the pending queue)
82 /// Value is in seconds
83 pub agent_nomination_block_duration: u16,
84 /// Min coins that should be attached to register an agent
85 pub min_coins_for_agent_registration: u64,
86 /// How many slots an agent can miss before being removed from the active queue
87 pub agents_eject_threshold: u64,
88 /// Minimum agent count in active queue to be untouched by bad agent verifier
89 pub min_active_agent_count: u16,
90 /// Whether agent registration is public or restricted to an internal whitelist (allowed_agents)
91 /// Determines whether agent registration is open to the public
92 /// If false, the APPROVED_AGENTS map will determine if an agent is allowed to register
93 /// If true, any address can register and enter the pending queue,
94 /// provided they have the assets required.
95 /// Note that once this becomes true, it's intentionally meant to be true forever,
96 /// since this is an aspect of progressive decentralization
97 pub public_registration: bool,
98}
99
100#[cfg(test)]
101mod test {
102 use crate::types::AgentStatus;
103
104 #[test]
105 fn agent_status_fmt() {
106 let active = AgentStatus::Active;
107 assert_eq!(format!("{active}"), "active");
108
109 let nominated = AgentStatus::Nominated;
110 assert_eq!(format!("{nominated}"), "nominated");
111
112 let pending = AgentStatus::Pending;
113 assert_eq!(format!("{pending}"), "pending");
114 }
115}