Skip to main content

clp_feed_interface/
helpers.rs

1use cosmwasm_std::{Addr, QuerierWrapper, StdResult};
2use crate::msg::{QueryMsg, AggregatedPriceResponse, AllPricesResponse};
3
4/// Helper struct for querying the CLP Feed contract
5pub struct ClpFeedQuerier<'a> {
6    querier: &'a QuerierWrapper<'a>,
7    contract_addr: Addr,
8}
9
10impl<'a> ClpFeedQuerier<'a> {
11    pub fn new(querier: &'a QuerierWrapper<'a>, contract_addr: Addr) -> Self {
12        Self {
13            querier,
14            contract_addr,
15        }
16    }
17
18    /// Query price by asset name
19    pub fn query_price(&self, asset: String) -> StdResult<AggregatedPriceResponse> {
20        self.querier.query_wasm_smart(
21            self.contract_addr.to_string(),
22            &QueryMsg::GetPrice { asset },
23        )
24    }
25
26    /// Query price by denom
27    pub fn query_price_by_denom(&self, denom: String) -> StdResult<AggregatedPriceResponse> {
28        self.querier.query_wasm_smart(
29            self.contract_addr.to_string(),
30            &QueryMsg::GetPriceByDenom { denom },
31        )
32    }
33
34    /// Query all prices
35    pub fn query_all_prices(&self) -> StdResult<AllPricesResponse> {
36        self.querier.query_wasm_smart(
37            self.contract_addr.to_string(),
38            &QueryMsg::GetAllPrices {},
39        )
40    }
41
42    // TODO: add more helper methods
43}