1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::{AccountFactory, AnsHost, IbcClient, Manager, ModuleFactory, Proxy, VersionControl};
use abstract_core::{
    objects::AccountId, ACCOUNT_FACTORY, ANS_HOST, IBC_CLIENT, MANAGER, MODULE_FACTORY, PROXY,
    VERSION_CONTROL,
};
use cw_orch::prelude::*;

#[allow(clippy::type_complexity)]
pub fn get_native_contracts<Chain: CwEnv>(
    chain: Chain,
) -> (
    AnsHost<Chain>,
    AccountFactory<Chain>,
    VersionControl<Chain>,
    ModuleFactory<Chain>,
    IbcClient<Chain>,
)
where
    <Chain as cw_orch::environment::TxHandler>::Response: IndexResponse,
{
    let ans_host = AnsHost::new(ANS_HOST, chain.clone());
    let account_factory = AccountFactory::new(ACCOUNT_FACTORY, chain.clone());
    let version_control = VersionControl::new(VERSION_CONTROL, chain.clone());
    let module_factory = ModuleFactory::new(MODULE_FACTORY, chain.clone());
    let ibc_client = IbcClient::new(IBC_CLIENT, chain);
    (
        ans_host,
        account_factory,
        version_control,
        module_factory,
        ibc_client,
    )
}

pub fn get_account_contracts<Chain: CwEnv>(
    chain: Chain,
    account_id: Option<AccountId>,
) -> (Manager<Chain>, Proxy<Chain>)
where
    <Chain as cw_orch::environment::TxHandler>::Response: IndexResponse,
{
    if let Some(account_id) = account_id {
        let version_control = VersionControl::new(VERSION_CONTROL, chain.clone());
        let account_base = version_control.get_account(account_id).unwrap();
        chain.state().set_address(MANAGER, &account_base.manager);
        chain.state().set_address(PROXY, &account_base.proxy);
        let manager = Manager::new(MANAGER, chain.clone());
        let proxy = Proxy::new(PROXY, chain);
        (manager, proxy)
    } else {
        let manager = Manager::new(MANAGER, chain.clone());
        let proxy = Proxy::new(PROXY, chain);
        (manager, proxy)
    }
}