use abstract_std::{
objects::{
oracle::{self, AccountValue},
AssetEntry,
},
proxy::{AssetsInfoResponse, BaseAssetResponse, QueryMsg, TokenValueResponse},
};
use cosmwasm_std::{Deps, Uint128};
use super::{AbstractApi, ApiIdentification};
use crate::{
cw_helpers::ApiQuery,
features::{AbstractNameService, AccountIdentification, ModuleIdentification},
AbstractSdkResult,
};
pub trait AccountingInterface:
AbstractNameService + AccountIdentification + ModuleIdentification
{
fn accountant<'a>(&'a self, deps: Deps<'a>) -> Accountant<Self> {
Accountant { base: self, deps }
}
}
impl<T> AccountingInterface for T where
T: AbstractNameService + AccountIdentification + ModuleIdentification
{
}
impl<'a, T: AccountingInterface> AbstractApi<T> for Accountant<'a, T> {
fn base(&self) -> &T {
self.base
}
fn deps(&self) -> Deps {
self.deps
}
}
impl<'a, T: AccountingInterface> ApiIdentification for Accountant<'a, T> {
fn api_id() -> String {
"Accountant".to_owned()
}
}
#[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 proxy_address = self.base.proxy_address(self.deps)?;
let response: AccountValue =
self.smart_query(proxy_address.to_string(), &QueryMsg::TotalValue {})?;
Ok(response)
}
pub fn asset_value(&self, asset_entry: AssetEntry) -> AbstractSdkResult<Uint128> {
let proxy_address = self.base.proxy_address(self.deps)?;
let response: TokenValueResponse = self.smart_query(
proxy_address.to_string(),
&QueryMsg::TokenValue {
identifier: asset_entry,
},
)?;
Ok(response.value)
}
pub fn base_asset(&self) -> AbstractSdkResult<BaseAssetResponse> {
let proxy_address = self.base.proxy_address(self.deps)?;
let response: BaseAssetResponse =
self.smart_query(proxy_address.to_string(), &QueryMsg::BaseAsset {})?;
Ok(response)
}
pub fn assets_list(&self) -> AbstractSdkResult<AssetsInfoResponse> {
let proxy_address = self.base.proxy_address(self.deps)?;
let resp: AssetsInfoResponse = self.smart_query(
proxy_address,
&QueryMsg::AssetsInfo {
start_after: None,
limit: Some(oracle::LIST_SIZE_LIMIT),
},
)?;
Ok(resp)
}
}
#[cfg(test)]
mod test {
mod query_total_value {
}
}