From 938dfff50d087e4253a9fd8e4e85813d258dac1e Mon Sep 17 00:00:00 2001 From: Kerber0x Date: Mon, 15 Apr 2024 17:50:24 +0100 Subject: [PATCH] refactor: rename query --- .../pool-manager/schema/pool-manager.json | 14 +++++----- .../pool-manager/schema/raw/query.json | 6 ++-- .../raw/response_to_asset_decimals.json | 28 +++++++++++++++++++ .../pool-manager/src/contract.rs | 4 +-- .../liquidity_hub/pool-manager/src/queries.rs | 12 ++++---- packages/white-whale-std/src/pool_manager.rs | 12 ++++---- 6 files changed, 51 insertions(+), 25 deletions(-) create mode 100644 contracts/liquidity_hub/pool-manager/schema/raw/response_to_asset_decimals.json diff --git a/contracts/liquidity_hub/pool-manager/schema/pool-manager.json b/contracts/liquidity_hub/pool-manager/schema/pool-manager.json index ae8b5df3..98eaaccb 100644 --- a/contracts/liquidity_hub/pool-manager/schema/pool-manager.json +++ b/contracts/liquidity_hub/pool-manager/schema/pool-manager.json @@ -593,13 +593,13 @@ "title": "QueryMsg", "oneOf": [ { - "description": "Retrieves the decimals for the given native or ibc denom.", + "description": "Retrieves the decimals for the given native asset.", "type": "object", "required": [ - "native_token_decimals" + "asset_decimals" ], "properties": { - "native_token_decimals": { + "asset_decimals": { "type": "object", "required": [ "denom", @@ -785,10 +785,10 @@ }, "sudo": null, "responses": { - "native_token_decimals": { + "asset_decimals": { "$schema": "http://json-schema.org/draft-07/schema#", - "title": "NativeTokenDecimalsResponse", - "description": "The response for the `NativeTokenDecimals` query.", + "title": "AssetDecimalsResponse", + "description": "The response for the `AssetDecimals` query.", "type": "object", "required": [ "decimals", @@ -803,7 +803,7 @@ "minimum": 0.0 }, "denom": { - "description": "The denom to get the decimals in the given pair_identifier for.", + "description": "The queried denom in the given pair_identifier.", "type": "string" }, "pair_identifier": { diff --git a/contracts/liquidity_hub/pool-manager/schema/raw/query.json b/contracts/liquidity_hub/pool-manager/schema/raw/query.json index 31e3fa4e..f900d499 100644 --- a/contracts/liquidity_hub/pool-manager/schema/raw/query.json +++ b/contracts/liquidity_hub/pool-manager/schema/raw/query.json @@ -3,13 +3,13 @@ "title": "QueryMsg", "oneOf": [ { - "description": "Retrieves the decimals for the given native or ibc denom.", + "description": "Retrieves the decimals for the given native asset.", "type": "object", "required": [ - "native_token_decimals" + "asset_decimals" ], "properties": { - "native_token_decimals": { + "asset_decimals": { "type": "object", "required": [ "denom", diff --git a/contracts/liquidity_hub/pool-manager/schema/raw/response_to_asset_decimals.json b/contracts/liquidity_hub/pool-manager/schema/raw/response_to_asset_decimals.json new file mode 100644 index 00000000..a64999bd --- /dev/null +++ b/contracts/liquidity_hub/pool-manager/schema/raw/response_to_asset_decimals.json @@ -0,0 +1,28 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "AssetDecimalsResponse", + "description": "The response for the `AssetDecimals` query.", + "type": "object", + "required": [ + "decimals", + "denom", + "pair_identifier" + ], + "properties": { + "decimals": { + "description": "The decimals for the requested denom.", + "type": "integer", + "format": "uint8", + "minimum": 0.0 + }, + "denom": { + "description": "The queried denom in the given pair_identifier.", + "type": "string" + }, + "pair_identifier": { + "description": "The pair identifier to do the query for.", + "type": "string" + } + }, + "additionalProperties": false +} diff --git a/contracts/liquidity_hub/pool-manager/src/contract.rs b/contracts/liquidity_hub/pool-manager/src/contract.rs index 7f035f67..32da77f7 100644 --- a/contracts/liquidity_hub/pool-manager/src/contract.rs +++ b/contracts/liquidity_hub/pool-manager/src/contract.rs @@ -173,10 +173,10 @@ fn optional_addr_validate( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result { match msg { - QueryMsg::NativeTokenDecimals { + QueryMsg::AssetDecimals { pair_identifier, denom, - } => Ok(to_json_binary(&queries::query_native_token_decimal( + } => Ok(to_json_binary(&queries::query_asset_decimals( deps, pair_identifier, denom, diff --git a/contracts/liquidity_hub/pool-manager/src/queries.rs b/contracts/liquidity_hub/pool-manager/src/queries.rs index 5a913c93..668b0aee 100644 --- a/contracts/liquidity_hub/pool-manager/src/queries.rs +++ b/contracts/liquidity_hub/pool-manager/src/queries.rs @@ -2,9 +2,7 @@ use std::cmp::Ordering; use cosmwasm_std::{Coin, Decimal256, Deps, Env, Fraction, Order, StdResult, Uint128}; -use white_whale_std::pool_manager::{ - NativeTokenDecimalsResponse, SwapOperation, SwapRouteResponse, -}; +use white_whale_std::pool_manager::{AssetDecimalsResponse, SwapOperation, SwapRouteResponse}; use white_whale_std::pool_network::{ asset::PairType, pair::{ReverseSimulationResponse, SimulationResponse}, @@ -18,12 +16,12 @@ use crate::{ }; use crate::{math::Decimal256Helper, state::SWAP_ROUTES}; -/// Query the native token decimals -pub fn query_native_token_decimal( +/// Query the native asset decimals +pub fn query_asset_decimals( deps: Deps, pair_identifier: String, denom: String, -) -> Result { +) -> Result { let pair_info = get_pair_by_identifier(&deps, &pair_identifier)?; let decimal_index = pair_info .asset_denoms @@ -31,7 +29,7 @@ pub fn query_native_token_decimal( .position(|d| d.clone() == denom) .ok_or(ContractError::AssetMismatch {})?; - Ok(NativeTokenDecimalsResponse { + Ok(AssetDecimalsResponse { pair_identifier, denom, decimals: pair_info.asset_decimals[decimal_index], diff --git a/packages/white-whale-std/src/pool_manager.rs b/packages/white-whale-std/src/pool_manager.rs index 3500b95e..78db0027 100644 --- a/packages/white-whale-std/src/pool_manager.rs +++ b/packages/white-whale-std/src/pool_manager.rs @@ -190,9 +190,9 @@ pub enum ExecuteMsg { #[cw_serde] #[derive(QueryResponses)] pub enum QueryMsg { - /// Retrieves the decimals for the given native or ibc denom. - #[returns(NativeTokenDecimalsResponse)] - NativeTokenDecimals { + /// Retrieves the decimals for the given native asset. + #[returns(AssetDecimalsResponse)] + AssetDecimals { pair_identifier: String, denom: String, }, @@ -240,12 +240,12 @@ pub enum QueryMsg { Pair { pair_identifier: String }, } -/// The response for the `NativeTokenDecimals` query. +/// The response for the `AssetDecimals` query. #[cw_serde] -pub struct NativeTokenDecimalsResponse { +pub struct AssetDecimalsResponse { /// The pair identifier to do the query for. pub pair_identifier: String, - /// The denom to get the decimals in the given pair_identifier for. + /// The queried denom in the given pair_identifier. pub denom: String, /// The decimals for the requested denom. pub decimals: u8,