abstract_os/native/
os_factory.rs

1//! # Os Factory
2//!
3//! `abstract_os::os_factory` handles OS creation and registration.
4//!
5//! ## Description
6//! The OS factory instantiates a new OS instance and registeres it with the [`crate::version_control`] contract. It then forwards the payment to the main os's subscription module.  
7//! ## Create a new OS
8//! Call [`ExecuteMsg::CreateOs`] on this contract along with a [`crate::objects::gov_type`] and name you'd like to display on your OS.
9//!
10pub mod state {
11    use cosmwasm_std::Addr;
12    use cw_controllers::Admin;
13    use cw_storage_plus::Item;
14
15    use serde::{Deserialize, Serialize};
16
17    use crate::objects::{common_namespace::ADMIN_NAMESPACE, core::OsId};
18
19    #[cosmwasm_schema::cw_serde]
20    pub struct Config {
21        pub version_control_contract: Addr,
22        pub ans_host_contract: Addr,
23        pub module_factory_address: Addr,
24        pub subscription_address: Option<Addr>,
25        pub next_os_id: OsId,
26    }
27
28    #[derive(Serialize, Deserialize, Clone, Debug)]
29    pub struct Context {
30        pub os_manager_address: Addr,
31    }
32
33    pub const ADMIN: Admin = Admin::new(ADMIN_NAMESPACE);
34    pub const CONFIG: Item<Config> = Item::new("\u{0}{5}config");
35    pub const CONTEXT: Item<Context> = Item::new("\u{0}{6}context");
36}
37
38use crate::objects::{core::OsId, gov_type::GovernanceDetails};
39use cosmwasm_schema::QueryResponses;
40use cw20::Cw20ReceiveMsg;
41
42/// Msg used on instantiation
43#[cosmwasm_schema::cw_serde]
44pub struct InstantiateMsg {
45    /// Version control contract used to get code-ids and register OS
46    pub version_control_address: String,
47    /// AnsHost contract
48    pub ans_host_address: String,
49    /// AnsHosts of module factory. Used for instantiating manager.
50    pub module_factory_address: String,
51}
52
53/// Execute function entrypoint.
54#[cosmwasm_schema::cw_serde]
55#[cfg_attr(feature = "boot", derive(boot_core::ExecuteFns))]
56pub enum ExecuteMsg {
57    /// Handler called by the CW-20 contract on a send-call
58    Receive(Cw20ReceiveMsg),
59    /// Update config
60    UpdateConfig {
61        // New admin
62        admin: Option<String>,
63        // New ans_host contract
64        ans_host_contract: Option<String>,
65        // New version control contract
66        version_control_contract: Option<String>,
67        // New module factory contract
68        module_factory_address: Option<String>,
69        // New subscription contract
70        subscription_address: Option<String>,
71    },
72    /// Creates the core contracts and sets the permissions.
73    /// [`crate::manager`] and [`crate::proxy`]
74    CreateOs {
75        // Governance details
76        // Use [`crate::objects::GovernanceDetails::Monarchy`] to use a custom governance modal.
77        // TODO: add support for other types of gov.
78        governance: GovernanceDetails,
79        name: String,
80        description: Option<String>,
81        link: Option<String>,
82    },
83}
84
85#[cosmwasm_schema::cw_serde]
86#[derive(QueryResponses)]
87#[cfg_attr(feature = "boot", derive(boot_core::QueryFns))]
88pub enum QueryMsg {
89    #[returns(ConfigResponse)]
90    Config {},
91}
92
93// We define a custom struct for each query response
94#[cosmwasm_schema::cw_serde]
95pub struct ConfigResponse {
96    pub owner: String,
97    pub ans_host_contract: String,
98    pub version_control_contract: String,
99    pub module_factory_address: String,
100    pub subscription_address: Option<String>,
101    pub next_os_id: OsId,
102}
103
104/// We currently take no arguments for migrations
105#[cosmwasm_schema::cw_serde]
106pub struct MigrateMsg {}