use crate::market::client::MarketClient;
use crate::market::error::MarketError;
use serde::{Deserialize, Serialize};
impl MarketClient {
pub async fn asset_pairs(
&self,
market_address: String,
) -> Result<AssetPairsResponse, MarketError> {
let query = Query {
asset_pairs: AssetPairsRequest {},
};
let response = self
.cosmos_client
.query_contract(market_address, &query, None)
.await?
.data;
Ok(response)
}
}
#[derive(Serialize)]
struct Query {
pub asset_pairs: AssetPairsRequest,
}
#[derive(Serialize)]
pub struct AssetPairsRequest {}
#[derive(Debug, Deserialize)]
pub struct AssetPairsResponse {
pub base_asset_symbol: String,
pub quote_assets_symbols: Vec<String>,
}
#[cfg(test)]
mod tests {
use crate::market::client::MarketClient;
use crate::market::error::MarketError;
use crate::oracle::client::OracleAdminClient;
use crate::test_utils::helpers::{TEST_ASSET_ARCH_SYMBOL, TEST_ASSET_USDT_SYMBOL};
use crate::test_utils::test_scenario::TestScenario;
use cosmwasm_std::{Decimal256, Uint128};
use serial_test::serial;
use std::ops::Add;
use std::str::FromStr;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
#[tokio::test]
#[serial]
async fn test_asset_pairs() {
let mut test_scenario = TestScenario::new_from_config("config.json".to_string()).await;
let price_threshold_ratio = Decimal256::from_str("0.1").unwrap();
let price_expire_millis = Some(1000);
let oracle_contract_address = test_scenario
.instantiate_oracle_contract(price_threshold_ratio, price_expire_millis)
.await;
let client = OracleAdminClient::from_scenario(&test_scenario, &oracle_contract_address)
.expect("Failed to create oracle admin client");
test_scenario.set_default_assets(&client).await;
let price_expiry_time = SystemTime::now().add(Duration::from_secs(7200)); let price_expiry_timestamp = price_expiry_time
.duration_since(UNIX_EPOCH)
.expect("Converting to timestamp failed");
test_scenario
.set_default_prices(&client, price_expiry_timestamp, "50000")
.await;
let protocol_fee_recipient = test_scenario.admin_address.clone();
let protocol_fee = Decimal256::percent(10);
let lp_fee = Decimal256::percent(10);
let min_base_out = Uint128::new(10);
let market_contract_addr = test_scenario
.instantiate_settlement_contract(
oracle_contract_address.clone(),
protocol_fee_recipient,
protocol_fee,
lp_fee,
TEST_ASSET_ARCH_SYMBOL.to_owned(),
vec![TEST_ASSET_USDT_SYMBOL.to_owned()],
min_base_out,
)
.await;
let market_client =
MarketClient::new(test_scenario.cosmos_client).expect("Failed to create market client");
let asset_pairs_err = market_client
.asset_pairs(oracle_contract_address.clone())
.await
.expect_err("Expected error querying asset pairs");
assert!(matches!(asset_pairs_err, MarketError::CosmosClientError(_)));
let asset_pairs = market_client
.asset_pairs(market_contract_addr.clone())
.await
.expect("Failed to get asset_pairs");
assert_eq!(asset_pairs.base_asset_symbol, TEST_ASSET_ARCH_SYMBOL);
assert_eq!(
asset_pairs.quote_assets_symbols,
vec![TEST_ASSET_USDT_SYMBOL]
);
}
}