abstract_core/native/
account_factory.rs

1//! # Account Factory
2//!
3//! `abstract_core::account_factory` handles Account creation and registration.
4//!
5//! ## Description
6//! The Account factory instantiates a new Account instance and registers it with the [`crate::version_control`] contract.  
7//! ## Create a new Account
8//! Call [`ExecuteMsg::CreateAccount`] on this contract along with a [`crate::objects::gov_type`] and name you'd like to display on your Account.
9//!
10pub mod state {
11    use cosmwasm_std::Addr;
12    use cw_storage_plus::Item;
13    use serde::{Deserialize, Serialize};
14
15    use crate::{
16        objects::{
17            account::{AccountId, AccountSequence},
18            module::Module,
19        },
20        version_control::AccountBase,
21    };
22
23    /// Account Factory configuration
24    #[cosmwasm_schema::cw_serde]
25    pub struct Config {
26        pub version_control_contract: Addr,
27        pub ans_host_contract: Addr,
28        pub module_factory_address: Addr,
29        pub ibc_host: Option<Addr>,
30    }
31
32    /// Account Factory context for post-[`crate::manager`] [`crate::proxy`] creation
33    #[derive(Serialize, Deserialize, Clone, Debug)]
34    pub struct Context {
35        pub account_base: AccountBase,
36        pub manager_module: Module,
37        pub proxy_module: Module,
38        pub account_id: AccountId,
39    }
40
41    pub const CONFIG: Item<Config> = Item::new("cfg");
42    pub const CONTEXT: Item<Context> = Item::new("contxt");
43    pub const LOCAL_ACCOUNT_SEQUENCE: Item<AccountSequence> = Item::new("acseq");
44}
45
46use cosmwasm_schema::QueryResponses;
47use cosmwasm_std::Addr;
48
49use crate::{
50    manager::ModuleInstallConfig,
51    objects::{
52        account::{AccountId, AccountSequence, AccountTrace},
53        gov_type::GovernanceDetails,
54        AssetEntry,
55    },
56};
57
58/// Msg used on instantiation
59#[cosmwasm_schema::cw_serde]
60pub struct InstantiateMsg {
61    /// Admin of the contract
62    pub admin: String,
63    /// Version control contract used to get code-ids and register Account
64    pub version_control_address: String,
65    /// AnsHost contract
66    pub ans_host_address: String,
67    /// AnsHosts of module factory. Used for instantiating manager.
68    pub module_factory_address: String,
69}
70
71/// Account Factory execute messages
72#[cw_ownable::cw_ownable_execute]
73#[cosmwasm_schema::cw_serde]
74#[cfg_attr(feature = "interface", derive(cw_orch::ExecuteFns))]
75pub enum ExecuteMsg {
76    /// Update config
77    UpdateConfig {
78        // New ans_host contract
79        ans_host_contract: Option<String>,
80        // New version control contract
81        version_control_contract: Option<String>,
82        // New module factory contract
83        module_factory_address: Option<String>,
84        // New ibc host contract
85        ibc_host: Option<String>,
86    },
87    /// Creates the core contracts and sets the permissions.
88    /// [`crate::manager`] and [`crate::proxy`]
89    #[cfg_attr(feature = "interface", payable)]
90    CreateAccount {
91        // Governance details
92        governance: GovernanceDetails<String>,
93        // Account name
94        name: String,
95        // Optionally specify a base asset for the account
96        base_asset: Option<AssetEntry>,
97        // Account description
98        description: Option<String>,
99        // Account link
100        link: Option<String>,
101        /// Indicates the AccountId for the new account.
102        ///
103        /// If `None`, will create a new local account without asserting account-id.
104        ///
105        /// When [`AccountTrace::Local`]: Signals the expected Account Id. The tx will error if this does not match the account-id at runtime. Useful for instantiate2 address prediction. \
106        /// When [`AccountTrace::Remote`]: Account id on the remote chain.
107        account_id: Option<AccountId>,
108        // optionally specify a namespace for the account
109        namespace: Option<String>,
110        // Provide list of module to install after account creation
111        install_modules: Vec<ModuleInstallConfig>,
112    },
113}
114
115/// Account Factory query messages
116#[cw_ownable::cw_ownable_query]
117#[cosmwasm_schema::cw_serde]
118#[derive(QueryResponses)]
119#[cfg_attr(feature = "interface", derive(cw_orch::QueryFns))]
120pub enum QueryMsg {
121    /// Returns [`ConfigResponse`]
122    #[returns(ConfigResponse)]
123    Config {},
124}
125
126/// Account Factory config response
127#[cosmwasm_schema::cw_serde]
128pub struct ConfigResponse {
129    pub ans_host_contract: Addr,
130    pub version_control_contract: Addr,
131    pub module_factory_address: Addr,
132    pub ibc_host: Option<Addr>,
133    pub local_account_sequence: AccountSequence,
134}
135
136/// Sequence numbers for each origin.
137#[cosmwasm_schema::cw_serde]
138pub struct SequencesResponse {
139    pub sequences: Vec<(AccountTrace, AccountSequence)>,
140}
141
142#[cosmwasm_schema::cw_serde]
143pub struct SequenceResponse {
144    pub sequence: AccountSequence,
145}
146
147/// Account Factory migrate messages
148#[cosmwasm_schema::cw_serde]
149pub struct MigrateMsg {}