abstract_os/core/
manager.rs

1//! # OS Manager
2//!
3//! `abstract_os::manager` implements the contract interface and state lay-out.
4//!
5//! ## Description
6//!
7//! The OS-manager is part of the Core OS contracts along with the `abstract_os::proxy` contract.
8//! This contract is responsible for:
9//! - Managing modules instantiation and migrations.
10//! - Managing permissions.
11//! - Upgrading the OS and its modules.
12//! - Providing module name to address resolution.
13//!
14//! **The manager should be set as the contract/CosmWasm admin by default on your modules.**
15//! ## Migration
16//! Migrating this contract is done by calling `ExecuteMsg::Upgrade` with `abstract::manager` as module.
17pub mod state {
18    use std::collections::HashSet;
19
20    pub use crate::objects::core::OS_ID;
21    use crate::objects::module::ModuleId;
22    use cosmwasm_std::Addr;
23    use cw_controllers::Admin;
24    use cw_storage_plus::{Item, Map};
25
26    pub type Subscribed = bool;
27
28    /// Manager configuration
29    #[cosmwasm_schema::cw_serde]
30    pub struct Config {
31        pub version_control_address: Addr,
32        pub module_factory_address: Addr,
33        pub subscription_address: Option<Addr>,
34    }
35    #[cosmwasm_schema::cw_serde]
36    pub struct OsInfo {
37        pub name: String,
38        pub governance_type: String,
39        pub chain_id: String,
40        pub description: Option<String>,
41        pub link: Option<String>,
42    }
43
44    /// Subscription status
45    pub const STATUS: Item<Subscribed> = Item::new("\u{0}{6}status");
46    /// Configuration
47    pub const CONFIG: Item<Config> = Item::new("\u{0}{6}config");
48    /// Info about the OS
49    pub const INFO: Item<OsInfo> = Item::new("\u{0}{4}info");
50    /// Contract Admin
51    pub const OS_FACTORY: Admin = Admin::new("\u{0}{7}factory");
52    /// Root user
53    pub const ROOT: Admin = Admin::new("root");
54    /// Enabled Abstract modules
55    pub const OS_MODULES: Map<ModuleId, Addr> = Map::new("os_modules");
56    /// Stores the dependency relationship between modules
57    /// map module -> modules that depend on module.
58    pub const DEPENDENTS: Map<ModuleId, HashSet<String>> = Map::new("dependents");
59}
60
61use self::state::OsInfo;
62use crate::objects::{
63    core::OsId,
64    module::{Module, ModuleInfo},
65};
66use cosmwasm_schema::QueryResponses;
67use cosmwasm_std::{Binary, Uint64};
68use cw2::ContractVersion;
69
70#[cosmwasm_schema::cw_serde]
71pub struct MigrateMsg {}
72
73#[cosmwasm_schema::cw_serde]
74pub struct InstantiateMsg {
75    pub os_id: OsId,
76    pub root_user: String,
77    pub version_control_address: String,
78    pub module_factory_address: String,
79    pub subscription_address: Option<String>,
80    pub governance_type: String,
81    pub name: String,
82    pub description: Option<String>,
83    pub link: Option<String>,
84}
85
86#[cosmwasm_schema::cw_serde]
87pub struct CallbackMsg {}
88
89/// Execute messages
90#[cosmwasm_schema::cw_serde]
91#[cfg_attr(feature = "boot", derive(boot_core::ExecuteFns))]
92pub enum ExecuteMsg {
93    /// Forward execution message to module
94    ExecOnModule {
95        module_id: String,
96        exec_msg: Binary,
97    },
98    /// Updates the `OS_MODULES` map
99    /// Only callable by os factory or root.
100    UpdateModuleAddresses {
101        to_add: Option<Vec<(String, String)>>,
102        to_remove: Option<Vec<String>>,
103    },
104    /// Install module using module factory, callable by Root
105    InstallModule {
106        // Module information.
107        module: ModuleInfo,
108        // Instantiate message used to instantiate the contract.
109        init_msg: Option<Binary>,
110    },
111    /// Registers a module after creation.
112    /// Used as a callback *only* by the Module Factory to register the module on the OS.
113    RegisterModule {
114        module_addr: String,
115        module: Module,
116    },
117    /// Remove a module
118    RemoveModule {
119        module_id: String,
120    },
121    /// Upgrade the module to a new version
122    /// If module is `abstract::manager` then the contract will do a self-migration.
123    Upgrade {
124        modules: Vec<(ModuleInfo, Option<Binary>)>,
125    },
126    /// Update info
127    UpdateInfo {
128        name: Option<String>,
129        description: Option<String>,
130        link: Option<String>,
131    },
132    /// Sets a new Root
133    SetRoot {
134        root: String,
135        governance_type: Option<String>,
136    },
137    /// Suspend manager contract
138    SuspendOs {
139        new_status: bool,
140    },
141    EnableIBC {
142        new_status: bool,
143    },
144    Callback(CallbackMsg),
145}
146
147#[cosmwasm_schema::cw_serde]
148#[derive(QueryResponses)]
149#[cfg_attr(feature = "boot", derive(boot_core::QueryFns))]
150pub enum QueryMsg {
151    /// Returns [`ModuleVersionsResponse`]
152    #[returns(ModuleVersionsResponse)]
153    ModuleVersions { ids: Vec<String> },
154    /// Returns [`ModuleAddressesResponse`]
155    #[returns(ModuleAddressesResponse)]
156    ModuleAddresses { ids: Vec<String> },
157    /// Returns [`ModuleInfosResponse`]
158    #[returns(ModuleInfosResponse)]
159    ModuleInfos {
160        start_after: Option<String>,
161        limit: Option<u8>,
162    },
163    /// Returns [`ConfigResponse`]
164    #[returns(ConfigResponse)]
165    Config {},
166    /// Returns [`InfoResponse`]
167    #[returns(InfoResponse)]
168    Info {},
169}
170
171#[cosmwasm_schema::cw_serde]
172pub struct ModuleVersionsResponse {
173    pub versions: Vec<ContractVersion>,
174}
175
176#[cosmwasm_schema::cw_serde]
177pub struct ModuleAddressesResponse {
178    pub modules: Vec<(String, String)>,
179}
180
181#[cosmwasm_schema::cw_serde]
182pub struct ConfigResponse {
183    pub root: String,
184    pub version_control_address: String,
185    pub module_factory_address: String,
186    pub os_id: Uint64,
187}
188
189#[cosmwasm_schema::cw_serde]
190pub struct InfoResponse {
191    pub info: OsInfo,
192}
193
194#[cosmwasm_schema::cw_serde]
195pub struct ManagerModuleInfo {
196    pub id: String,
197    pub version: ContractVersion,
198    pub address: String,
199}
200
201#[cosmwasm_schema::cw_serde]
202pub struct ModuleInfosResponse {
203    pub module_infos: Vec<ManagerModuleInfo>,
204}