abstract_std/
app.rs

1//! # Abstract App
2//!
3//! `abstract_std::app` implements shared functionality that's useful for creating new Abstract apps.
4//!
5//! ## Description
6//! An app is a contract that is allowed to perform actions on a [account](crate::account) contract while also being migratable.
7use crate::{
8    base::{
9        ExecuteMsg as EndpointExecMsg, InstantiateMsg as EndpointInstantiateMsg,
10        MigrateMsg as EndpointMigrateMsg, QueryMsg as EndpointQueryMsg,
11    },
12    objects::{gov_type::TopLevelOwnerResponse, module_version::ModuleDataResponse},
13    registry::Account,
14};
15
16pub type ExecuteMsg<ModuleMsg = Empty> = EndpointExecMsg<BaseExecuteMsg, ModuleMsg>;
17pub type QueryMsg<ModuleMsg = Empty> = EndpointQueryMsg<BaseQueryMsg, ModuleMsg>;
18pub type InstantiateMsg<ModuleMsg = Empty> = EndpointInstantiateMsg<BaseInstantiateMsg, ModuleMsg>;
19pub type MigrateMsg<ModuleMsg = Empty> = EndpointMigrateMsg<BaseMigrateMsg, ModuleMsg>;
20
21use cosmwasm_schema::QueryResponses;
22use cosmwasm_std::{Addr, Empty};
23#[allow(unused_imports)]
24use cw_controllers::AdminResponse;
25use serde::Serialize;
26
27/// Trait indicates that the type is used as an app message
28/// in the [`ExecuteMsg`] enum.
29/// Enables [`Into<ExecuteMsg>`] for BOOT fn-generation support.
30pub trait AppExecuteMsg: Serialize {}
31impl<T: AppExecuteMsg> From<T> for ExecuteMsg<T> {
32    fn from(module: T) -> Self {
33        Self::Module(module)
34    }
35}
36
37impl AppExecuteMsg for Empty {}
38
39/// Trait indicates that the type is used as an app message
40/// in the [`QueryMsg`] enum.
41/// Enables [`Into<QueryMsg>`] for BOOT fn-generation support.
42pub trait AppQueryMsg: Serialize {}
43impl<T: AppQueryMsg> From<T> for QueryMsg<T> {
44    fn from(module: T) -> Self {
45        Self::Module(module)
46    }
47}
48impl AppQueryMsg for Empty {}
49
50/// Used by Module Factory to instantiate App
51#[cosmwasm_schema::cw_serde]
52pub struct BaseInstantiateMsg {
53    pub account: Account,
54}
55
56#[cosmwasm_schema::cw_serde]
57#[derive(cw_orch::ExecuteFns)]
58pub enum BaseExecuteMsg {}
59
60impl<T> From<BaseExecuteMsg> for ExecuteMsg<T> {
61    fn from(base: BaseExecuteMsg) -> Self {
62        Self::Base(base)
63    }
64}
65
66#[cosmwasm_schema::cw_serde]
67#[derive(QueryResponses, cw_orch::QueryFns)]
68pub enum BaseQueryMsg {
69    /// Returns [`AppConfigResponse`]
70    #[returns(AppConfigResponse)]
71    BaseConfig {},
72    /// Returns the admin.
73    /// Returns [`AdminResponse`]
74    #[returns(AdminResponse)]
75    BaseAdmin {},
76    /// Returns module data
77    /// Returns [`ModuleDataResponse`]
78    #[returns(ModuleDataResponse)]
79    ModuleData {},
80    /// Returns top level owner
81    /// Returns [`TopLevelOwnerResponse`]
82    #[returns(TopLevelOwnerResponse)]
83    TopLevelOwner {},
84}
85
86impl<T> From<BaseQueryMsg> for QueryMsg<T> {
87    fn from(base: BaseQueryMsg) -> Self {
88        Self::Base(base)
89    }
90}
91
92#[cosmwasm_schema::cw_serde]
93pub struct AppConfigResponse {
94    pub account: Addr,
95    pub ans_host_address: Addr,
96    pub registry_address: Addr,
97}
98
99#[cosmwasm_schema::cw_serde]
100pub struct BaseMigrateMsg {}
101
102/// The BaseState contains the main addresses needed for sending and verifying messages
103#[cosmwasm_schema::cw_serde]
104pub struct AppState {
105    /// Account contract address for accounting transactions
106    pub account: Account,
107}