cw_core/
msg.rs

1use cosmwasm_std::{Binary, CosmosMsg, Empty};
2use cw_utils::Duration;
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use cw_core_macros::voting_query;
7
8use crate::state::Config;
9
10/// Information about the admin of a contract.
11#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
12#[serde(rename_all = "snake_case")]
13pub enum Admin {
14    /// A specific address.
15    Address { addr: String },
16    /// The core contract itself. The contract will fill this in
17    /// while instantiation takes place.
18    CoreContract {},
19    /// No admin.
20    None {},
21}
22
23/// Information needed to instantiate a proposal or voting module.
24#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
25pub struct ModuleInstantiateInfo {
26    /// Code ID of the contract to be instantiated.
27    pub code_id: u64,
28    /// Instantiate message to be used to create the contract.
29    pub msg: Binary,
30    /// Admin of the instantiated contract.
31    pub admin: Admin,
32    /// Label for the instantiated contract.
33    pub label: String,
34}
35
36#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
37pub struct InitialItem {
38    /// The name of the item.
39    pub key: String,
40    /// The value the item will have at instantiation time.
41    pub value: String,
42}
43
44#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
45pub struct InstantiateMsg {
46    /// Optional Admin with the ability to execute DAO messages
47    /// directly. Useful for building SubDAOs controlled by a parent
48    /// DAO. If no admin is specified the contract is set as its own
49    /// admin so that the admin may be updated later by governance.
50    pub admin: Option<String>,
51    /// The name of the core contract.
52    pub name: String,
53    /// A description of the core contract.
54    pub description: String,
55    /// An image URL to describe the core module contract.
56    pub image_url: Option<String>,
57
58    /// If true the contract will automatically add received cw20
59    /// tokens to its treasury.
60    pub automatically_add_cw20s: bool,
61    /// If true the contract will automatically add received cw721
62    /// tokens to its treasury.
63    pub automatically_add_cw721s: bool,
64
65    /// Instantiate information for the core contract's voting
66    /// power module.
67    pub voting_module_instantiate_info: ModuleInstantiateInfo,
68    /// Instantiate information for the core contract's
69    /// proposal modules.
70    pub proposal_modules_instantiate_info: Vec<ModuleInstantiateInfo>,
71
72    /// Initial information for arbitrary contract addresses to be
73    /// added to the items map. The key is the name of the item in the
74    /// items map. The value is an enum that either uses an existing
75    /// address or instantiates a new contract.
76    pub initial_items: Option<Vec<InitialItem>>,
77}
78
79#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
80#[serde(rename_all = "snake_case")]
81pub enum ExecuteMsg {
82    /// Callable by the Admin, if one is configured.
83    /// Executes messages in order.
84    ExecuteAdminMsgs { msgs: Vec<CosmosMsg<Empty>> },
85    /// Callable by proposal modules. The DAO will execute the
86    /// messages in the hook in order.
87    ExecuteProposalHook { msgs: Vec<CosmosMsg<Empty>> },
88    /// Pauses the DAO for a set duration.
89    /// When paused the DAO is unable to execute proposals
90    Pause { duration: Duration },
91    /// Executed when the contract receives a cw20 token. Depending on
92    /// the contract's configuration the contract will automatically
93    /// add the token to its treasury.
94    Receive(cw20::Cw20ReceiveMsg),
95    /// Executed when the contract receives a cw721 token. Depending
96    /// on the contract's configuration the contract will
97    /// automatically add the token to its treasury.
98    ReceiveNft(cw721::Cw721ReceiveMsg),
99    /// Removes an item from the governance contract's item map.
100    RemoveItem { key: String },
101    /// Adds an item to the governance contract's item map. If the
102    /// item already exists the existing value is overriden. If the
103    /// item does not exist a new item is added.
104    SetItem { key: String, addr: String },
105    /// Callable by the admin of the contract. If ADMIN is None the
106    /// admin is set as the contract itself so that it may be updated
107    /// later by vote. If ADMIN is Some a new admin is proposed and
108    /// that new admin may become the admin by executing the
109    /// `AcceptAdminNomination` message.
110    ///
111    /// If there is already a pending admin nomination the
112    /// `WithdrawAdminNomination` message must be executed before a
113    /// new admin may be nominated.
114    NominateAdmin { admin: Option<String> },
115    /// Callable by a nominated admin. Admins are nominated via the
116    /// `NominateAdmin` message. Accepting a nomination will make the
117    /// nominated address the new admin.
118    ///
119    /// Requiring that the new admin accepts the nomination before
120    /// becoming the admin protects against a typo causing the admin
121    /// to change to an invalid address.
122    AcceptAdminNomination {},
123    /// Callable by the current admin. Withdraws the current admin
124    /// nomination.
125    WithdrawAdminNomination {},
126    /// Callable by the core contract. Replaces the current
127    /// governance contract config with the provided config.
128    UpdateConfig { config: Config },
129    /// Updates the list of cw20 tokens this contract has registered.
130    UpdateCw20List {
131        to_add: Vec<String>,
132        to_remove: Vec<String>,
133    },
134    /// Updates the list of cw721 tokens this contract has registered.
135    UpdateCw721List {
136        to_add: Vec<String>,
137        to_remove: Vec<String>,
138    },
139    /// Updates the governance contract's governance modules. Module
140    /// instantiate info in `to_add` is used to create new modules and
141    /// install them.
142    UpdateProposalModules {
143        to_add: Vec<ModuleInstantiateInfo>,
144        to_remove: Vec<String>,
145    },
146    /// Callable by the core contract. Replaces the current
147    /// voting module with a new one instantiated by the governance
148    /// contract.
149    UpdateVotingModule { module: ModuleInstantiateInfo },
150}
151
152#[voting_query]
153#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
154#[serde(rename_all = "snake_case")]
155pub enum QueryMsg {
156    /// Get's the DAO's admin. Returns `Addr`.
157    Admin {},
158    /// Get's the currently nominated admin (if any). Returns
159    /// `AdminNominationResponse`.
160    AdminNomination {},
161    /// Gets the contract's config. Returns Config.
162    Config {},
163    /// Gets the token balance for each cw20 registered with the
164    /// contract.
165    Cw20Balances {
166        start_at: Option<String>,
167        limit: Option<u32>,
168    },
169    /// Lists the addresses of the cw20 tokens in this contract's
170    /// treasury.
171    Cw20TokenList {
172        start_at: Option<String>,
173        limit: Option<u32>,
174    },
175    /// Lists the addresses of the cw721 tokens in this contract's
176    /// treasury.
177    Cw721TokenList {
178        start_at: Option<String>,
179        limit: Option<u32>,
180    },
181    /// Dumps all of the core contract's state in a single
182    /// query. Useful for frontends as performance for queries is more
183    /// limited by network times than compute times. Returns
184    /// `DumpStateResponse`.
185    DumpState {},
186    /// Gets the address associated with an item key.
187    GetItem { key: String },
188    /// Lists all of the items associted with the contract. For
189    /// example, given the items `{ "group": "foo", "subdao": "bar"}`
190    /// this query would return `[("group", "foo"), ("subdao",
191    /// "bar")]`.
192    ListItems {
193        start_at: Option<String>,
194        limit: Option<u32>,
195    },
196    /// Gets the proposal modules assocaited with the
197    /// contract. Returns Vec<Addr>.
198    ProposalModules {
199        start_at: Option<String>,
200        limit: Option<u32>,
201    },
202    /// Returns information about if the contract is currently paused.
203    PauseInfo {},
204    /// Gets the contract's voting module. Returns Addr.
205    VotingModule {},
206}
207
208#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
209pub struct MigrateMsg {}