1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//! # Os Factory
//!
//! `abstract_os::os_factory` handles OS creation and registration.
//!
//! ## Description
//! 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.  
//! ## Create a new OS
//! Call [`ExecuteMsg::CreateOs`] on this contract along with a [`crate::objects::gov_type`] and name you'd like to display on your OS.
//!
pub mod state {
    use cosmwasm_std::Addr;
    use cw_controllers::Admin;
    use cw_storage_plus::Item;

    use serde::{Deserialize, Serialize};

    use crate::objects::{common_namespace::ADMIN_NAMESPACE, core::OsId};

    #[cosmwasm_schema::cw_serde]
    pub struct Config {
        pub version_control_contract: Addr,
        pub ans_host_contract: Addr,
        pub module_factory_address: Addr,
        pub subscription_address: Option<Addr>,
        pub next_os_id: OsId,
    }

    #[derive(Serialize, Deserialize, Clone, Debug)]
    pub struct Context {
        pub os_manager_address: Addr,
    }

    pub const ADMIN: Admin = Admin::new(ADMIN_NAMESPACE);
    pub const CONFIG: Item<Config> = Item::new("\u{0}{5}config");
    pub const CONTEXT: Item<Context> = Item::new("\u{0}{6}context");
}

use crate::objects::{core::OsId, gov_type::GovernanceDetails};
use cosmwasm_schema::QueryResponses;
use cw20::Cw20ReceiveMsg;

/// Msg used on instantiation
#[cosmwasm_schema::cw_serde]
pub struct InstantiateMsg {
    /// Version control contract used to get code-ids and register OS
    pub version_control_address: String,
    /// AnsHost contract
    pub ans_host_address: String,
    /// AnsHosts of module factory. Used for instantiating manager.
    pub module_factory_address: String,
}

/// Execute function entrypoint.
#[cosmwasm_schema::cw_serde]
#[cfg_attr(feature = "boot", derive(boot_core::ExecuteFns))]
pub enum ExecuteMsg {
    /// Handler called by the CW-20 contract on a send-call
    Receive(Cw20ReceiveMsg),
    /// Update config
    UpdateConfig {
        // New admin
        admin: Option<String>,
        // New ans_host contract
        ans_host_contract: Option<String>,
        // New version control contract
        version_control_contract: Option<String>,
        // New module factory contract
        module_factory_address: Option<String>,
        // New subscription contract
        subscription_address: Option<String>,
    },
    /// Creates the core contracts and sets the permissions.
    /// [`crate::manager`] and [`crate::proxy`]
    CreateOs {
        // Governance details
        // Use [`crate::objects::GovernanceDetails::Monarchy`] to use a custom governance modal.
        // TODO: add support for other types of gov.
        governance: GovernanceDetails,
        name: String,
        description: Option<String>,
        link: Option<String>,
    },
}

#[cosmwasm_schema::cw_serde]
#[derive(QueryResponses)]
#[cfg_attr(feature = "boot", derive(boot_core::QueryFns))]
pub enum QueryMsg {
    #[returns(ConfigResponse)]
    Config {},
}

// We define a custom struct for each query response
#[cosmwasm_schema::cw_serde]
pub struct ConfigResponse {
    pub owner: String,
    pub ans_host_contract: String,
    pub version_control_contract: String,
    pub module_factory_address: String,
    pub subscription_address: Option<String>,
    pub next_os_id: OsId,
}

/// We currently take no arguments for migrations
#[cosmwasm_schema::cw_serde]
pub struct MigrateMsg {}