Skip to content

Commit

Permalink
refactor: rename query
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x committed Apr 15, 2024
1 parent 417a06f commit 938dfff
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 25 deletions.
14 changes: 7 additions & 7 deletions contracts/liquidity_hub/pool-manager/schema/pool-manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions contracts/liquidity_hub/pool-manager/schema/raw/query.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions contracts/liquidity_hub/pool-manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Binary, ContractError> {
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,
Expand Down
12 changes: 5 additions & 7 deletions contracts/liquidity_hub/pool-manager/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -18,20 +16,20 @@ 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<NativeTokenDecimalsResponse, ContractError> {
) -> Result<AssetDecimalsResponse, ContractError> {
let pair_info = get_pair_by_identifier(&deps, &pair_identifier)?;
let decimal_index = pair_info
.asset_denoms
.iter()
.position(|d| d.clone() == denom)
.ok_or(ContractError::AssetMismatch {})?;

Ok(NativeTokenDecimalsResponse {
Ok(AssetDecimalsResponse {
pair_identifier,
denom,
decimals: pair_info.asset_decimals[decimal_index],
Expand Down
12 changes: 6 additions & 6 deletions packages/white-whale-std/src/pool_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 938dfff

Please sign in to comment.