abstract_std/native/
module_factory.rs

1//! # Module Factory
2//!
3//! `abstract_std::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::account::ExecuteMsg`] endpoint.  
7pub mod state {
8    use cw_storage_plus::Item;
9
10    use crate::{objects::storage_namespaces, registry::Account};
11
12    /// Base of account on which modules getting installed right now
13    /// It's set only if one of the modules is standalone
14    pub const CURRENT_BASE: Item<Account> =
15        Item::new(storage_namespaces::module_factory::CURRENT_BASE);
16}
17
18use cosmwasm_schema::QueryResponses;
19use cosmwasm_std::{Addr, Binary, Coin};
20
21use crate::objects::module::ModuleInfo;
22
23#[cosmwasm_schema::cw_serde]
24pub struct InstantiateMsg {
25    pub admin: String,
26}
27
28/// Module Factory Execute messages
29#[cw_ownable::cw_ownable_execute]
30#[cosmwasm_schema::cw_serde]
31#[derive(cw_orch::ExecuteFns)]
32pub enum ExecuteMsg {
33    /// Install modules
34    InstallModules {
35        modules: Vec<FactoryModuleInstallConfig>,
36        salt: Binary,
37    },
38}
39
40/// Module info, init message and salt
41#[non_exhaustive]
42#[cosmwasm_schema::cw_serde]
43pub struct FactoryModuleInstallConfig {
44    pub module: ModuleInfo,
45    pub init_msg: Option<Binary>,
46}
47
48impl FactoryModuleInstallConfig {
49    pub fn new(module: ModuleInfo, init_msg: Option<Binary>) -> Self {
50        Self { module, init_msg }
51    }
52}
53
54/// Module factory query messages
55#[cw_ownable::cw_ownable_query]
56#[cosmwasm_schema::cw_serde]
57#[derive(QueryResponses, cw_orch::QueryFns)]
58pub enum QueryMsg {
59    /// Get the configuration for the module factory.
60    /// Returns [`ConfigResponse`]
61    #[returns(ConfigResponse)]
62    Config {},
63    /// Simulate install module cost
64    /// Returns [`SimulateInstallModulesResponse`]
65    #[returns(SimulateInstallModulesResponse)]
66    SimulateInstallModules { modules: Vec<ModuleInfo> },
67}
68
69/// Module factory config response
70#[cosmwasm_schema::cw_serde]
71pub struct ConfigResponse {
72    pub ans_host_address: Addr,
73    pub registry_address: Addr,
74}
75
76#[cosmwasm_schema::cw_serde]
77pub struct SimulateInstallModulesResponse {
78    pub total_required_funds: Vec<Coin>,
79    /// Funds transferred to the module creator
80    pub monetization_funds: Vec<(String, Coin)>,
81    /// Funds transferred to the module contract at instantiation
82    pub initialization_funds: Vec<(String, Vec<Coin>)>,
83}
84
85/// We currently take no arguments for migrations
86#[cosmwasm_schema::cw_serde]
87pub enum MigrateMsg {
88    /// Migrating from blob contract
89    Instantiate(InstantiateMsg),
90    /// Migrating from previous version
91    Migrate {},
92}