abstract_interface/
interfaces.rs

1use abstract_std::{objects::AccountId, ANS_HOST, IBC_CLIENT, IBC_HOST, MODULE_FACTORY, REGISTRY};
2use cw_orch::{environment::Environment, prelude::*};
3
4use crate::{
5    AbstractInterfaceError, AccountI, AnsHost, IbcClient, IbcHost, ModuleFactory, Registry,
6};
7
8#[allow(clippy::type_complexity)]
9pub fn get_native_contracts<Chain: CwEnv>(
10    chain: Chain,
11) -> (AnsHost<Chain>, Registry<Chain>, ModuleFactory<Chain>)
12where
13    <Chain as cw_orch::environment::TxHandler>::Response: IndexResponse,
14{
15    let ans_host = AnsHost::new(ANS_HOST, chain.clone());
16    let registry = Registry::new(REGISTRY, chain.clone());
17    let module_factory = ModuleFactory::new(MODULE_FACTORY, chain.clone());
18    (ans_host, registry, module_factory)
19}
20
21pub fn get_account_contract<Chain: CwEnv>(
22    registry: &Registry<Chain>,
23    account_id: AccountId,
24) -> Result<AccountI<Chain>, AbstractInterfaceError>
25where
26    <Chain as cw_orch::environment::TxHandler>::Response: IndexResponse,
27{
28    let chain = registry.environment().clone();
29
30    let account_interface = AccountI::new_from_id(&account_id, chain.clone());
31
32    let account = registry.account(account_id.clone())?;
33    account_interface.set_address(account.addr());
34
35    Ok(account_interface)
36}
37
38pub fn get_ibc_contracts<Chain: CwEnv>(chain: Chain) -> (IbcClient<Chain>, IbcHost<Chain>)
39where
40    <Chain as cw_orch::environment::TxHandler>::Response: IndexResponse,
41{
42    let ibc_client = IbcClient::new(IBC_CLIENT, chain.clone());
43    let ibc_host = IbcHost::new(IBC_HOST, chain);
44
45    (ibc_client, ibc_host)
46}