use crate::{
cw_helpers::wasm_smart_query,
features::{AbstractNameService, AccountIdentification},
AbstractSdkResult,
};
use abstract_core::{objects::AssetEntry, proxy::QueryMsg};
use cosmwasm_std::{Deps, Uint128};
use abstract_core::{
objects::oracle::{self, AccountValue},
proxy::{AssetsInfoResponse, BaseAssetResponse, TokenValueResponse},
};
pub trait AccountingInterface: AbstractNameService + AccountIdentification {
fn accountant<'a>(&'a self, deps: Deps<'a>) -> Accountant<Self> {
Accountant { base: self, deps }
}
}
impl<T> AccountingInterface for T where T: AbstractNameService + AccountIdentification {}
#[derive(Clone)]
pub struct Accountant<'a, T: AccountingInterface> {
base: &'a T,
deps: Deps<'a>,
}
impl<'a, T: AccountingInterface> Accountant<'a, T> {
pub fn query_total_value(&self) -> AbstractSdkResult<AccountValue> {
let querier = self.deps.querier;
let proxy_address = self.base.proxy_address(self.deps)?;
let response: AccountValue = querier.query(&wasm_smart_query(
proxy_address.to_string(),
&QueryMsg::TotalValue {},
)?)?;
Ok(response)
}
pub fn asset_value(&self, asset_entry: AssetEntry) -> AbstractSdkResult<Uint128> {
let querier = self.deps.querier;
let proxy_address = self.base.proxy_address(self.deps)?;
let response: TokenValueResponse = querier.query(&wasm_smart_query(
proxy_address.to_string(),
&QueryMsg::TokenValue {
identifier: asset_entry,
},
)?)?;
Ok(response.value)
}
pub fn base_asset(&self) -> AbstractSdkResult<BaseAssetResponse> {
let querier = self.deps.querier;
let proxy_address = self.base.proxy_address(self.deps)?;
let response: BaseAssetResponse = querier.query(&wasm_smart_query(
proxy_address.to_string(),
&QueryMsg::BaseAsset {},
)?)?;
Ok(response)
}
pub fn assets_list(&self) -> AbstractSdkResult<AssetsInfoResponse> {
let querier = self.deps.querier;
let proxy_address = self.base.proxy_address(self.deps)?;
let resp: AssetsInfoResponse = querier.query_wasm_smart(
proxy_address,
&QueryMsg::AssetsInfo {
start_after: None,
limit: Some(oracle::LIST_SIZE_LIMIT),
},
)?;
Ok(resp)
}
}
#[cfg(test)]
mod test {
mod query_total_value {
}
}