abstract_os/native/
module_factory.rs

1//! # Module Factory
2//!
3//! `abstract_os::module_factory` is a native contract that handles instantiation and migration of os modules.
4//!
5//! ## Description  
6//! This contract is instantiated by Abstract and only used internally. Adding or upgrading modules is done using the [`crate::manager::ExecuteMsg`] endpoint.  
7pub mod state {
8    use crate::{
9        objects::{
10            common_namespace::ADMIN_NAMESPACE,
11            module::{Module, ModuleInfo},
12        },
13        version_control::Core,
14    };
15    use cosmwasm_std::{Addr, Binary};
16    use cw_controllers::Admin;
17    use cw_storage_plus::{Item, Map};
18    use schemars::JsonSchema;
19    use serde::{Deserialize, Serialize};
20
21    #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
22    pub struct Config {
23        pub version_control_address: Addr,
24        pub ans_host_address: Addr,
25    }
26
27    #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
28    pub struct Context {
29        pub core: Option<Core>,
30        pub module: Option<Module>,
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}{7}context");
36    pub const MODULE_INIT_BINARIES: Map<&ModuleInfo, Binary> = Map::new("module_init_binaries");
37}
38
39use crate::{
40    objects::module::{Module, ModuleInfo},
41    version_control::Core,
42};
43use cosmwasm_schema::QueryResponses;
44use cosmwasm_std::Binary;
45
46#[cosmwasm_schema::cw_serde]
47pub struct InstantiateMsg {
48    /// Version control address used to get code-ids and register OS
49    pub version_control_address: String,
50    /// AnsHost address
51    pub ans_host_address: String,
52}
53
54#[cosmwasm_schema::cw_serde]
55#[cfg_attr(feature = "boot", derive(boot_core::ExecuteFns))]
56pub enum ExecuteMsg {
57    /// Update config
58    UpdateConfig {
59        admin: Option<String>,
60        ans_host_address: Option<String>,
61        version_control_address: Option<String>,
62    },
63    /// Installs a module on the OS
64    InstallModule {
65        // Module details
66        module: ModuleInfo,
67        init_msg: Option<Binary>,
68    },
69    UpdateFactoryBinaryMsgs {
70        to_add: Vec<(ModuleInfo, Binary)>,
71        to_remove: Vec<ModuleInfo>,
72    },
73}
74
75#[cosmwasm_schema::cw_serde]
76#[derive(QueryResponses)]
77#[cfg_attr(feature = "boot", derive(boot_core::QueryFns))]
78pub enum QueryMsg {
79    /// Get the configuration for the module factory.
80    /// Returns [`ConfigResponse`]
81    #[returns(ConfigResponse)]
82    Config {},
83    /// Get the installation context of the module factory.
84    /// Returns [`ContextResponse`]
85    #[returns(ContextResponse)]
86    Context {},
87}
88
89// We define a custom struct for each query response
90#[cosmwasm_schema::cw_serde]
91pub struct ConfigResponse {
92    pub owner: String,
93    pub ans_host_address: String,
94    pub version_control_address: String,
95}
96
97#[cosmwasm_schema::cw_serde]
98pub struct ContextResponse {
99    pub core: Option<Core>,
100    pub module: Option<Module>,
101}
102
103/// We currently take no arguments for migrations
104#[cosmwasm_schema::cw_serde]
105pub struct MigrateMsg {}