abstract_interface/
interfaces.rs

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
use abstract_std::{objects::AccountId, ANS_HOST, IBC_CLIENT, IBC_HOST, MODULE_FACTORY, REGISTRY};
use cw_orch::{environment::Environment, prelude::*};

use crate::{
    AbstractInterfaceError, AccountI, AnsHost, IbcClient, IbcHost, ModuleFactory, Registry,
};

#[allow(clippy::type_complexity)]
pub fn get_native_contracts<Chain: CwEnv>(
    chain: Chain,
) -> (AnsHost<Chain>, Registry<Chain>, ModuleFactory<Chain>)
where
    <Chain as cw_orch::environment::TxHandler>::Response: IndexResponse,
{
    let ans_host = AnsHost::new(ANS_HOST, chain.clone());
    let registry = Registry::new(REGISTRY, chain.clone());
    let module_factory = ModuleFactory::new(MODULE_FACTORY, chain.clone());
    (ans_host, registry, module_factory)
}

pub fn get_account_contract<Chain: CwEnv>(
    registry: &Registry<Chain>,
    account_id: AccountId,
) -> Result<AccountI<Chain>, AbstractInterfaceError>
where
    <Chain as cw_orch::environment::TxHandler>::Response: IndexResponse,
{
    let chain = registry.environment().clone();

    let account_interface = AccountI::new_from_id(&account_id, chain.clone());

    let account = registry.account(account_id.clone())?;
    account_interface.set_address(account.addr());

    Ok(account_interface)
}

pub fn get_ibc_contracts<Chain: CwEnv>(chain: Chain) -> (IbcClient<Chain>, IbcHost<Chain>)
where
    <Chain as cw_orch::environment::TxHandler>::Response: IndexResponse,
{
    let ibc_client = IbcClient::new(IBC_CLIENT, chain.clone());
    let ibc_host = IbcHost::new(IBC_HOST, chain);

    (ibc_client, ibc_host)
}