abstract_sdk/base/features/
abstract_name_service.rs1use abstract_std::{
2 ans_host::{
3 AssetPairingFilter, AssetPairingMapEntry, PoolAddressListResponse, QueryMsg,
4 RegisteredDexesResponse,
5 },
6 objects::{ans_host::AnsHost, DexAssetPairing},
7};
8use cosmwasm_std::Deps;
9
10use super::ModuleIdentification;
11use crate::apis::AbstractApi;
12use crate::{ans_resolve::Resolve, cw_helpers::ApiQuery, AbstractSdkResult};
13
14pub trait AbstractNameService: Sized {
17 fn ans_host(&self, deps: Deps) -> AbstractSdkResult<AnsHost>;
19
20 fn name_service<'a>(&'a self, deps: Deps<'a>) -> AbstractNameServiceClient<'a, Self> {
22 AbstractNameServiceClient {
23 base: self,
24 deps,
25 host: self.ans_host(deps).unwrap(),
26 }
27 }
28}
29#[derive(Clone)]
32pub struct AbstractNameServiceClient<'a, T: AbstractNameService> {
33 base: &'a T,
34 deps: Deps<'a>,
35 pub host: AnsHost,
37}
38
39impl<T: ModuleIdentification + AbstractNameService> AbstractApi<T>
40 for AbstractNameServiceClient<'_, T>
41{
42 const API_ID: &'static str = "AbstractNameServiceClient";
43
44 fn base(&self) -> &T {
45 self.base
46 }
47 fn deps(&self) -> Deps {
48 self.deps
49 }
50}
51
52impl<T: ModuleIdentification + AbstractNameService> AbstractNameServiceClient<'_, T> {
53 pub fn query<R: Resolve>(&self, entry: &R) -> AbstractSdkResult<R::Output> {
55 entry
56 .resolve(&self.deps.querier, &self.host)
57 .map_err(|error| self.wrap_query_error(error))
58 }
59
60 pub fn is_registered(&self, entry: &impl Resolve) -> bool {
65 entry.is_registered(&self.deps.querier, &self.host)
66 }
67 pub fn assert_registered(&self, entry: &impl Resolve) -> AbstractSdkResult<()> {
69 entry
70 .assert_registered(&self.deps.querier, &self.host)
71 .map_err(|error| self.wrap_query_error(error))
72 }
73
74 pub fn host(&self) -> &AnsHost {
76 &self.host
77 }
78 pub fn pool_list(
80 &self,
81 filter: Option<AssetPairingFilter>,
82 page_limit: Option<u8>,
83 start_after: Option<DexAssetPairing>,
84 ) -> AbstractSdkResult<Vec<AssetPairingMapEntry>> {
85 let resp: PoolAddressListResponse = self.smart_query(
86 &self.host.address,
87 &QueryMsg::PoolList {
88 filter,
89 start_after,
90 limit: page_limit,
91 },
92 )?;
93 Ok(resp.pools)
94 }
95 pub fn registered_dexes(&self) -> AbstractSdkResult<RegisteredDexesResponse> {
97 self.host
98 .query_registered_dexes(&self.deps.querier)
99 .map_err(|error| self.wrap_query_error(error))
100 }
101}