abstract_os/native/
version_control.rs

1//! # Version Control
2//!
3//! `abstract_os::version_control` stores chain-specific code-ids, addresses and an os_id map.
4//!
5//! ## Description
6//! Code-ids and api-contract addresses are stored on this address. This data can not be changed and allows for complex factory logic.
7//! Both code-ids and addresses are stored on a per-module version basis which allows users to easily upgrade their modules.
8//!
9//! An internal os-id store provides external verification for manager and proxy addresses.  
10
11pub type ModuleMapEntry = (ModuleInfo, ModuleReference);
12
13pub mod state {
14    use cw_controllers::Admin;
15    use cw_storage_plus::Map;
16
17    use crate::objects::{
18        common_namespace::ADMIN_NAMESPACE, core::OsId, module::ModuleInfo,
19        module_reference::ModuleReference,
20    };
21
22    use super::Core;
23
24    pub const ADMIN: Admin = Admin::new(ADMIN_NAMESPACE);
25    pub const FACTORY: Admin = Admin::new("factory");
26
27    // We can iterate over the map giving just the prefix to get all the versions
28    pub const MODULE_LIBRARY: Map<&ModuleInfo, ModuleReference> = Map::new("module_lib");
29    /// Maps OS ID to the address of its core contracts
30    pub const OS_ADDRESSES: Map<OsId, Core> = Map::new("os_core");
31}
32
33use crate::objects::{
34    core::OsId,
35    module::{Module, ModuleInfo},
36    module_reference::ModuleReference,
37};
38use cosmwasm_schema::QueryResponses;
39use cosmwasm_std::Addr;
40
41/// Contains the minimal Abstract-OS contract addresses.
42#[cosmwasm_schema::cw_serde]
43pub struct Core {
44    pub manager: Addr,
45    pub proxy: Addr,
46}
47
48#[cosmwasm_schema::cw_serde]
49pub struct InstantiateMsg {}
50
51#[cosmwasm_schema::cw_serde]
52#[cfg_attr(feature = "boot", derive(boot_core::ExecuteFns))]
53pub enum ExecuteMsg {
54    /// Remove some version of a module
55    RemoveModule { module: ModuleInfo },
56    /// Add new modules
57    AddModules { modules: Vec<ModuleMapEntry> },
58    /// Add a new OS to the deployed OSs.  
59    /// Only Factory can call this
60    AddOs { os_id: OsId, core: Core },
61    /// Sets a new Admin
62    SetAdmin { new_admin: String },
63    /// Sets a new Factory
64    SetFactory { new_factory: String },
65}
66
67/// A ModuleFilter that mirrors the [`ModuleInfo`] struct.
68#[derive(Default)]
69#[cosmwasm_schema::cw_serde]
70pub struct ModuleFilter {
71    pub provider: Option<String>,
72    pub name: Option<String>,
73    pub version: Option<String>,
74}
75
76#[cosmwasm_schema::cw_serde]
77#[derive(QueryResponses)]
78#[cfg_attr(feature = "boot", derive(boot_core::QueryFns))]
79pub enum QueryMsg {
80    /// Query Core of an OS
81    /// Returns [`OsCoreResponse`]
82    #[returns(OsCoreResponse)]
83    OsCore { os_id: OsId },
84    /// Queries api addresses
85    /// Returns [`ModulesResponse`]
86    #[returns(ModulesResponse)]
87    Modules { infos: Vec<ModuleInfo> },
88    /// Returns [`ConfigResponse`]
89    #[returns(ConfigResponse)]
90    Config {},
91    /// Returns [`ModulesListResponse`]
92    #[returns(ModulesListResponse)]
93    ModuleList {
94        filter: Option<ModuleFilter>,
95        start_after: Option<ModuleInfo>,
96        limit: Option<u8>,
97    },
98}
99
100#[cosmwasm_schema::cw_serde]
101pub struct OsCoreResponse {
102    pub os_core: Core,
103}
104
105#[cosmwasm_schema::cw_serde]
106pub struct ModulesResponse {
107    pub modules: Vec<Module>,
108}
109
110#[cosmwasm_schema::cw_serde]
111pub struct ModulesListResponse {
112    pub modules: Vec<Module>,
113}
114
115#[cosmwasm_schema::cw_serde]
116pub struct ConfigResponse {
117    pub admin: String,
118    pub factory: String,
119}
120
121#[cosmwasm_schema::cw_serde]
122pub struct MigrateMsg {}