diff --git a/contracts/liquidity_hub/pool-manager/src/contract.rs b/contracts/liquidity_hub/pool-manager/src/contract.rs index 465871c2..44ec8b86 100644 --- a/contracts/liquidity_hub/pool-manager/src/contract.rs +++ b/contracts/liquidity_hub/pool-manager/src/contract.rs @@ -9,7 +9,7 @@ use cosmwasm_std::{ use cw2::set_contract_version; use semver::Version; use white_whale_std::pool_manager::{ - ExecuteMsg, FeatureToggle, InstantiateMsg, MigrateMsg, QueryMsg, + ExecuteMsg, FeatureToggle, InstantiateMsg, MigrateMsg, PairInfoResponse, QueryMsg, }; // version info for migration info @@ -236,9 +236,9 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result Ok(to_json_binary(&get_swap_routes(deps)?)?), QueryMsg::Ownership {} => Ok(to_json_binary(&cw_ownable::get_ownership(deps.storage)?)?), - QueryMsg::Pair { pair_identifier } => Ok(to_json_binary( - &PAIRS.load(deps.storage, &pair_identifier)?, - )?), + QueryMsg::Pair { pair_identifier } => Ok(to_json_binary(&PairInfoResponse { + pair_info: PAIRS.load(deps.storage, &pair_identifier)?, + })?), } } diff --git a/contracts/liquidity_hub/pool-manager/src/queries.rs b/contracts/liquidity_hub/pool-manager/src/queries.rs index 45b8d47d..36498988 100644 --- a/contracts/liquidity_hub/pool-manager/src/queries.rs +++ b/contracts/liquidity_hub/pool-manager/src/queries.rs @@ -3,7 +3,7 @@ use std::cmp::Ordering; use cosmwasm_std::{Coin, Decimal256, Deps, Env, Fraction, Order, StdResult, Uint128}; use white_whale_std::pool_manager::{ - AssetDecimalsResponse, Config, SwapOperation, SwapRouteResponse, + AssetDecimalsResponse, Config, SwapRoute, SwapRouteResponse, SwapRoutesResponse, }; use white_whale_std::pool_network::{ asset::PairType, @@ -245,40 +245,48 @@ pub fn query_reverse_simulation( // Router related queries, swap routes and SwapOperations // get_swap_routes which only takes deps: Deps as input // the function will read from SWAP_ROUTES and return all swpa routes in a vec -pub fn get_swap_routes(deps: Deps) -> Result, ContractError> { - let swap_routes: Vec = SWAP_ROUTES +pub fn get_swap_routes(deps: Deps) -> Result { + let swap_routes: Vec = SWAP_ROUTES .range(deps.storage, None, None, Order::Ascending) .map(|item| { let swap_info = item?; // Destructure key into (offer_asset, ask_asset) let (offer_asset_denom, ask_asset_denom) = swap_info.0; // Destructure value into vec of SwapOperation - let swap_route = swap_info.1; + let swap_operations = swap_info.1; - Ok(SwapRouteResponse { + Ok(SwapRoute { offer_asset_denom, ask_asset_denom, - swap_route, + swap_operations, }) }) - .collect::>>()?; + .collect::>>()?; - Ok(swap_routes) + Ok(SwapRoutesResponse { swap_routes }) } pub fn get_swap_route( deps: Deps, offer_asset_denom: String, ask_asset_denom: String, -) -> Result, ContractError> { +) -> Result { let swap_route_key = SWAP_ROUTES.key((&offer_asset_denom, &ask_asset_denom)); - swap_route_key - .load(deps.storage) - .map_err(|_| ContractError::NoSwapRouteForAssets { - offer_asset: offer_asset_denom, - ask_asset: ask_asset_denom, - }) + let swap_operations = + swap_route_key + .load(deps.storage) + .map_err(|_| ContractError::NoSwapRouteForAssets { + offer_asset: offer_asset_denom.clone(), + ask_asset: ask_asset_denom.clone(), + })?; + Ok(SwapRouteResponse { + swap_route: SwapRoute { + offer_asset_denom, + ask_asset_denom, + swap_operations, + }, + }) } // TODO: May need to remove this for a new implementation, router swap operation queries diff --git a/contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs b/contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs index bc2e83a5..73cc6abc 100644 --- a/contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs +++ b/contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs @@ -1754,7 +1754,7 @@ mod swapping { } mod ownership { - use white_whale_std::pool_network::pair::FeatureToggle; + use white_whale_std::pool_manager::FeatureToggle; use super::*; diff --git a/contracts/liquidity_hub/pool-manager/src/tests/suite.rs b/contracts/liquidity_hub/pool-manager/src/tests/suite.rs index 888f49f4..9694e8db 100644 --- a/contracts/liquidity_hub/pool-manager/src/tests/suite.rs +++ b/contracts/liquidity_hub/pool-manager/src/tests/suite.rs @@ -1,5 +1,5 @@ use cosmwasm_std::testing::MockStorage; -use white_whale_std::pool_manager::{Config, SwapOperation}; +use white_whale_std::pool_manager::{Config, FeatureToggle, SwapOperation}; use white_whale_std::pool_manager::{InstantiateMsg, PairInfo}; use cosmwasm_std::{coin, Addr, Coin, Decimal, Empty, StdResult, Timestamp, Uint128, Uint64}; @@ -9,9 +9,7 @@ use cw_multi_test::{ }; use white_whale_std::fee::PoolFee; use white_whale_std::pool_network::asset::{AssetInfo, PairType}; -use white_whale_std::pool_network::pair::{ - FeatureToggle, ReverseSimulationResponse, SimulationResponse, -}; +use white_whale_std::pool_network::pair::{ReverseSimulationResponse, SimulationResponse}; use white_whale_testing::multi_test::stargate_mock::StargateMock; use cw_multi_test::addons::{MockAddressGenerator, MockApiBech32}; diff --git a/packages/white-whale-std/src/pool_manager.rs b/packages/white-whale-std/src/pool_manager.rs index 02800099..9ddd957c 100644 --- a/packages/white-whale-std/src/pool_manager.rs +++ b/packages/white-whale-std/src/pool_manager.rs @@ -57,9 +57,7 @@ pub struct SwapRoute { // Used for all swap routes #[cw_serde] pub struct SwapRouteResponse { - pub offer_asset_denom: String, - pub ask_asset_denom: String, - pub swap_route: Vec, + pub swap_route: SwapRoute, } impl fmt::Display for SwapRoute { @@ -204,7 +202,7 @@ pub enum ExecuteMsg { #[derive(QueryResponses)] pub enum QueryMsg { /// Retrieves the contract's config. - #[returns(Config)] + #[returns(ConfigResponse)] Config {}, /// Retrieves the decimals for the given asset. @@ -231,13 +229,13 @@ pub enum QueryMsg { }, /// Gets the swap route for the given offer and ask assets. - #[returns(Vec)] + #[returns(SwapRouteResponse)] SwapRoute { offer_asset_denom: String, ask_asset_denom: String, }, /// Gets all swap routes registered - #[returns(Vec)] + #[returns(SwapRoutesResponse)] SwapRoutes {}, // /// Simulates swap operations. @@ -253,10 +251,25 @@ pub enum QueryMsg { // ask_amount: Uint128, // operations: Vec, // }, - #[returns(PairInfo)] + #[returns(PairInfoResponse)] Pair { pair_identifier: String }, } +#[cw_serde] +pub struct ConfigResponse { + pub config: Config, +} + +#[cw_serde] +pub struct SwapRoutesResponse { + pub swap_routes: Vec, +} + +#[cw_serde] +pub struct PairInfoResponse { + pub pair_info: PairInfo, +} + /// The response for the `AssetDecimals` query. #[cw_serde] pub struct AssetDecimalsResponse {