abstract_core/native/
module_factory.rs

1//! # Module Factory
2//!
3//! `abstract_core::module_factory` is a native contract that handles instantiation and migration of account 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
9    use cosmwasm_std::{Addr, Binary};
10    use cw_storage_plus::{Item, Map};
11    use schemars::JsonSchema;
12    use serde::{Deserialize, Serialize};
13
14    use crate::objects::module::ModuleInfo;
15
16    #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
17    pub struct Config {
18        pub version_control_address: Addr,
19        pub ans_host_address: Addr,
20    }
21
22    pub const CONFIG: Item<Config> = Item::new("\u{0}{5}config");
23    pub const MODULE_INIT_BINARIES: Map<&ModuleInfo, Binary> = Map::new("module_init_binaries");
24}
25
26use cosmwasm_schema::QueryResponses;
27use cosmwasm_std::{Addr, Binary, Coin};
28
29use crate::objects::module::ModuleInfo;
30
31#[cosmwasm_schema::cw_serde]
32pub struct InstantiateMsg {
33    pub admin: String,
34    /// Version control address used to get code-ids and register Account
35    pub version_control_address: String,
36    /// AnsHost address
37    pub ans_host_address: String,
38}
39
40/// Module Factory Execute messages
41#[cw_ownable::cw_ownable_execute]
42#[cosmwasm_schema::cw_serde]
43#[cfg_attr(feature = "interface", derive(cw_orch::ExecuteFns))]
44pub enum ExecuteMsg {
45    /// Update config
46    UpdateConfig {
47        ans_host_address: Option<String>,
48        version_control_address: Option<String>,
49    },
50    /// Install modules
51    InstallModules {
52        modules: Vec<FactoryModuleInstallConfig>,
53        salt: Binary,
54    },
55    UpdateFactoryBinaryMsgs {
56        to_add: Vec<(ModuleInfo, Binary)>,
57        to_remove: Vec<ModuleInfo>,
58    },
59}
60
61/// Module info, init message and salt
62#[non_exhaustive]
63#[cosmwasm_schema::cw_serde]
64pub struct FactoryModuleInstallConfig {
65    pub module: ModuleInfo,
66    pub init_msg: Option<Binary>,
67}
68
69impl FactoryModuleInstallConfig {
70    pub fn new(module: ModuleInfo, init_msg: Option<Binary>) -> Self {
71        Self { module, init_msg }
72    }
73}
74
75/// Module factory query messages
76#[cw_ownable::cw_ownable_query]
77#[cosmwasm_schema::cw_serde]
78#[derive(QueryResponses)]
79#[cfg_attr(feature = "interface", derive(cw_orch::QueryFns))]
80pub enum QueryMsg {
81    /// Get the configuration for the module factory.
82    /// Returns [`ConfigResponse`]
83    #[returns(ConfigResponse)]
84    Config {},
85    /// Simulate install module cost
86    /// Returns [`SimulateInstallModulesResponse`]
87    #[returns(SimulateInstallModulesResponse)]
88    SimulateInstallModules { modules: Vec<ModuleInfo> },
89}
90
91/// Module factory config response
92#[cosmwasm_schema::cw_serde]
93pub struct ConfigResponse {
94    pub ans_host_address: Addr,
95    pub version_control_address: Addr,
96}
97
98#[cosmwasm_schema::cw_serde]
99pub struct SimulateInstallModulesResponse {
100    pub total_required_funds: Vec<Coin>,
101    /// Funds transferred to the module creator
102    pub monetization_funds: Vec<(String, Coin)>,
103    /// Funds transferred to the module contract at instantiation
104    pub initialization_funds: Vec<(String, Vec<Coin>)>,
105}
106
107/// We currently take no arguments for migrations
108#[cosmwasm_schema::cw_serde]
109pub struct MigrateMsg {}