croncat_sdk_factory/msg.rs
1use std::fmt;
2
3use cosmwasm_schema::{cw_serde, QueryResponses};
4use cosmwasm_std::{Addr, Binary, WasmMsg};
5
6#[cw_serde]
7pub struct Config {
8 /// The owner of the Factory, the DAO responsible for all changes & usage
9 /// All Execute methods are restricted to this address, the CronCat DAO
10 pub owner_addr: Addr,
11 /// Default empty, nominated owners must accept the nomination for ownership
12 /// transfer to be safely completed.
13 pub nominated_owner_addr: Option<Addr>,
14}
15
16#[cw_serde]
17pub struct FactoryInstantiateMsg {
18 /// Owner address of the contract,
19 /// CronCat DAO will be the owner since it deploys the factory
20 /// Only owner can execute messages in this contract
21 /// If no owner_addr is passed sender will be used as owner address
22 pub owner_addr: Option<String>,
23}
24
25#[cw_serde]
26pub enum FactoryExecuteMsg {
27 /// Deploys contract and saves metadata of the contract to the factory
28 Deploy {
29 kind: VersionKind,
30 module_instantiate_info: ModuleInstantiateInfo,
31 },
32
33 /// Removes contract metadata from the factory if contract is paused or it is library contract.
34 /// Last version of the contract can't get removed
35 Remove {
36 contract_name: String,
37 version: [u8; 2],
38 },
39
40 /// Update fields of the contract metadata
41 UpdateMetadata {
42 contract_name: String,
43 version: [u8; 2],
44 changelog_url: Option<String>,
45 schema: Option<String>,
46 },
47
48 /// Pass through execution for versioned contract calls
49 Proxy { msg: WasmMsg },
50
51 /// Factory owner (DAO) may submit a new owner to transfer ownership
52 NominateOwner { nominated_owner_addr: String },
53
54 /// The nominated address must accept a nomination to finalize transfer of ownership
55 /// NOTE: This is the only method that can be called, that isn't from current owner_addr
56 AcceptNominateOwner {},
57
58 /// Factory owner (DAO) may revoke any/all ownership nominations at any time.
59 RemoveNominateOwner {},
60}
61
62#[cw_serde]
63#[derive(QueryResponses)]
64pub enum FactoryQueryMsg {
65 /// Gets the factory's config
66 #[returns[Config]]
67 Config {},
68
69 /// Gets latest contract names and metadatas of the contracts
70 #[returns[Vec<EntryResponse>]]
71 LatestContracts {},
72
73 /// Gets latest version metadata of the contract
74 #[returns[ContractMetadataResponse]]
75 LatestContract { contract_name: String },
76
77 /// Gets metadatas of the contract
78 #[returns[Vec<ContractMetadataInfo>]]
79 VersionsByContractName {
80 contract_name: String,
81 from_index: Option<u64>,
82 limit: Option<u64>,
83 },
84
85 /// Gets list of the contract names
86 #[returns[Vec<String>]]
87 ContractNames {
88 from_index: Option<u64>,
89 limit: Option<u64>,
90 },
91
92 /// Gets all contract names and metadatas stored in factory.
93 #[returns[Vec<EntryResponse>]]
94 AllEntries {
95 from_index: Option<u64>,
96 limit: Option<u64>,
97 },
98}
99
100#[cw_serde]
101pub struct EntryResponse {
102 pub contract_name: String,
103 pub metadata: ContractMetadataInfo,
104}
105
106#[cw_serde]
107pub struct ContractMetadata {
108 pub kind: VersionKind,
109 /// Code ID of the contract to be instantiated.
110 pub code_id: u64,
111
112 /// Truncated semver so contracts could programmatically check backward compat
113 pub version: [u8; 2],
114
115 /// git commit hash
116 pub commit_id: String,
117
118 /// proof of deployed code
119 pub checksum: String,
120
121 /// public link to a README about this version
122 pub changelog_url: Option<String>,
123
124 /// types/schema - helps keep UI/clients backward compatible
125 pub schema: Option<String>,
126}
127#[cw_serde]
128pub struct ContractMetadataInfo {
129 pub kind: VersionKind,
130 pub code_id: u64,
131 pub contract_addr: Addr,
132 pub version: [u8; 2],
133 pub commit_id: String,
134 pub checksum: String,
135 pub changelog_url: Option<String>,
136 pub schema: Option<String>,
137}
138#[cw_serde]
139pub struct ContractMetadataResponse {
140 pub metadata: Option<ContractMetadataInfo>,
141}
142
143/// Information needed to instantiate a module.
144#[cw_serde]
145pub struct ModuleInstantiateInfo {
146 /// Code ID of the contract to be instantiated.
147 pub code_id: u64,
148
149 /// Truncated semver so contracts could programmatically check backward compat
150 pub version: [u8; 2],
151
152 /// git commit hash
153 pub commit_id: String,
154
155 /// proof of deployed code
156 pub checksum: String,
157
158 /// public link to a README about this version
159 pub changelog_url: Option<String>,
160
161 /// types/schema - helps keep UI/clients backward compatible
162 pub schema: Option<String>,
163
164 /// Instantiate message to be used to create the contract.
165 pub msg: Binary,
166
167 /// Contract name for the instantiated contract.
168 pub contract_name: String,
169}
170
171#[cw_serde]
172#[derive(Copy)]
173pub enum VersionKind {
174 Library,
175 Manager,
176 Tasks,
177 Agents,
178 // Recipes?
179}
180
181impl fmt::Display for VersionKind {
182 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
183 match self {
184 VersionKind::Library => write!(f, "library"),
185 VersionKind::Manager => write!(f, "manager"),
186 VersionKind::Tasks => write!(f, "tasks"),
187 VersionKind::Agents => write!(f, "agents"),
188 }
189 }
190}
191
192// Reference: https://github.com/DA0-DA0/dao-contracts/blob/fa567797e2f42e70296a2d6f889f341ff80f0695/packages/dao-interface/src/lib.rs#L17
193/// Information about the CosmWasm level admin of a contract. Used in
194/// conjunction with `ModuleInstantiateInfo` to instantiate modules.
195#[cw_serde]
196pub enum Admin {
197 /// Set the admin to a specified address.
198 Address { addr: String },
199 /// Sets the admin as the core module address.
200 CoreModule {},
201}