From 417a06f233f31e3ac418d119274f3c7e1238564d Mon Sep 17 00:00:00 2001 From: Kerber0x Date: Mon, 15 Apr 2024 14:40:14 +0100 Subject: [PATCH] refactor: add asset_decimals to the create_pair msg --- .../pool-manager/schema/pool-manager.json | 120 +++++++++---- .../pool-manager/schema/raw/execute.json | 69 +++---- .../pool-manager/schema/raw/query.json | 6 +- .../response_to_native_token_decimals.json | 14 +- .../schema/raw/response_to_pair.json | 31 +++- .../pool-manager/src/contract.rs | 16 +- .../pool-manager/src/manager/commands.rs | 49 +---- .../liquidity_hub/pool-manager/src/queries.rs | 23 ++- .../liquidity_hub/pool-manager/src/state.rs | 2 - .../pool-manager/src/swap/perform_swap.rs | 1 - .../src/tests/integration_tests.rs | 170 ++++++++---------- .../pool-manager/src/tests/suite.rs | 31 +--- packages/white-whale-std/Cargo.toml | 2 +- packages/white-whale-std/src/pool_manager.rs | 34 ++-- 14 files changed, 294 insertions(+), 274 deletions(-) diff --git a/contracts/liquidity_hub/pool-manager/schema/pool-manager.json b/contracts/liquidity_hub/pool-manager/schema/pool-manager.json index aa2d9fcdb..ae8b5df32 100644 --- a/contracts/liquidity_hub/pool-manager/schema/pool-manager.json +++ b/contracts/liquidity_hub/pool-manager/schema/pool-manager.json @@ -58,11 +58,20 @@ "create_pair": { "type": "object", "required": [ + "asset_decimals", "asset_denoms", "pair_type", "pool_fees" ], "properties": { + "asset_decimals": { + "type": "array", + "items": { + "type": "integer", + "format": "uint8", + "minimum": 0.0 + } + }, "asset_denoms": { "type": "array", "items": { @@ -182,6 +191,7 @@ "additionalProperties": false }, { + "description": "Withdraws liquidity from the pool.", "type": "object", "required": [ "withdraw_liquidity" @@ -202,34 +212,6 @@ }, "additionalProperties": false }, - { - "description": "Adds native token info to the contract so it can instantiate pair contracts that include it", - "type": "object", - "required": [ - "add_native_token_decimals" - ], - "properties": { - "add_native_token_decimals": { - "type": "object", - "required": [ - "decimals", - "denom" - ], - "properties": { - "decimals": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - }, - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, { "description": "Execute multiple [`SwapOperations`] to allow for multi-hop swaps.", "type": "object", @@ -489,22 +471,45 @@ ] }, "PoolFee": { - "description": "Fees used by the pools on the pool network", + "description": "Represents the fee structure for transactions within a pool.\n\n# Fields - `protocol_fee`: The fee percentage charged by the protocol on each transaction to support operational and developmental needs. - `swap_fee`: The fee percentage allocated to liquidity providers as a reward for supplying liquidity to the pool, incentivizing participation and ensuring pool health. - `burn_fee`: A fee percentage that is burned on each transaction, helping manage the token economy by reducing supply over time, potentially increasing token value. - `osmosis_fee` (optional): Specific to the Osmosis feature, this fee is charged on each transaction when the Osmosis feature is enabled, supporting specific ecosystem requirements. - `extra_fees`: A vector of custom fees allowing for extensible and adaptable fee structures to meet diverse and evolving needs. Validation ensures that the total of all fees does not exceed 100%, maintaining fairness and avoiding overcharging.\n\n# Features - `osmosis`: Enables the `osmosis_fee` field, integrating specific fee requirements for the Osmosis protocol within the pool's fee structure.", "type": "object", "required": [ "burn_fee", + "extra_fees", "protocol_fee", "swap_fee" ], "properties": { "burn_fee": { - "$ref": "#/definitions/Fee" + "description": "Fee percentage that is burned on each transaction. Burning a portion of the transaction fee helps in reducing the overall token supply.", + "allOf": [ + { + "$ref": "#/definitions/Fee" + } + ] + }, + "extra_fees": { + "description": "A list of custom, additional fees that can be defined for specific use cases or additional functionalities. This vector enables the flexibility to introduce new fees without altering the core fee structure. Total of all fees, including custom ones, is validated to not exceed 100%, ensuring a balanced and fair fee distribution.", + "type": "array", + "items": { + "$ref": "#/definitions/Fee" + } }, "protocol_fee": { - "$ref": "#/definitions/Fee" + "description": "Fee percentage charged on each transaction for the protocol's benefit.", + "allOf": [ + { + "$ref": "#/definitions/Fee" + } + ] }, "swap_fee": { - "$ref": "#/definitions/Fee" + "description": "Fee percentage allocated to liquidity providers on each swap.", + "allOf": [ + { + "$ref": "#/definitions/Fee" + } + ] } }, "additionalProperties": false @@ -597,11 +602,15 @@ "native_token_decimals": { "type": "object", "required": [ - "denom" + "denom", + "pair_identifier" ], "properties": { "denom": { "type": "string" + }, + "pair_identifier": { + "type": "string" } }, "additionalProperties": false @@ -779,15 +788,27 @@ "native_token_decimals": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "NativeTokenDecimalsResponse", + "description": "The response for the `NativeTokenDecimals` query.", "type": "object", "required": [ - "decimals" + "decimals", + "denom", + "pair_identifier" ], "properties": { "decimals": { + "description": "The decimals for the requested denom.", "type": "integer", "format": "uint8", "minimum": 0.0 + }, + "denom": { + "description": "The denom to get the decimals in the given pair_identifier for.", + "type": "string" + }, + "pair_identifier": { + "description": "The pair identifier to do the query for.", + "type": "string" } }, "additionalProperties": false @@ -998,22 +1019,45 @@ ] }, "PoolFee": { - "description": "Fees used by the pools on the pool network", + "description": "Represents the fee structure for transactions within a pool.\n\n# Fields - `protocol_fee`: The fee percentage charged by the protocol on each transaction to support operational and developmental needs. - `swap_fee`: The fee percentage allocated to liquidity providers as a reward for supplying liquidity to the pool, incentivizing participation and ensuring pool health. - `burn_fee`: A fee percentage that is burned on each transaction, helping manage the token economy by reducing supply over time, potentially increasing token value. - `osmosis_fee` (optional): Specific to the Osmosis feature, this fee is charged on each transaction when the Osmosis feature is enabled, supporting specific ecosystem requirements. - `extra_fees`: A vector of custom fees allowing for extensible and adaptable fee structures to meet diverse and evolving needs. Validation ensures that the total of all fees does not exceed 100%, maintaining fairness and avoiding overcharging.\n\n# Features - `osmosis`: Enables the `osmosis_fee` field, integrating specific fee requirements for the Osmosis protocol within the pool's fee structure.", "type": "object", "required": [ "burn_fee", + "extra_fees", "protocol_fee", "swap_fee" ], "properties": { "burn_fee": { - "$ref": "#/definitions/Fee" + "description": "Fee percentage that is burned on each transaction. Burning a portion of the transaction fee helps in reducing the overall token supply.", + "allOf": [ + { + "$ref": "#/definitions/Fee" + } + ] + }, + "extra_fees": { + "description": "A list of custom, additional fees that can be defined for specific use cases or additional functionalities. This vector enables the flexibility to introduce new fees without altering the core fee structure. Total of all fees, including custom ones, is validated to not exceed 100%, ensuring a balanced and fair fee distribution.", + "type": "array", + "items": { + "$ref": "#/definitions/Fee" + } }, "protocol_fee": { - "$ref": "#/definitions/Fee" + "description": "Fee percentage charged on each transaction for the protocol's benefit.", + "allOf": [ + { + "$ref": "#/definitions/Fee" + } + ] }, "swap_fee": { - "$ref": "#/definitions/Fee" + "description": "Fee percentage allocated to liquidity providers on each swap.", + "allOf": [ + { + "$ref": "#/definitions/Fee" + } + ] } }, "additionalProperties": false diff --git a/contracts/liquidity_hub/pool-manager/schema/raw/execute.json b/contracts/liquidity_hub/pool-manager/schema/raw/execute.json index eb439e1d6..a74ce039a 100644 --- a/contracts/liquidity_hub/pool-manager/schema/raw/execute.json +++ b/contracts/liquidity_hub/pool-manager/schema/raw/execute.json @@ -11,11 +11,20 @@ "create_pair": { "type": "object", "required": [ + "asset_decimals", "asset_denoms", "pair_type", "pool_fees" ], "properties": { + "asset_decimals": { + "type": "array", + "items": { + "type": "integer", + "format": "uint8", + "minimum": 0.0 + } + }, "asset_denoms": { "type": "array", "items": { @@ -135,6 +144,7 @@ "additionalProperties": false }, { + "description": "Withdraws liquidity from the pool.", "type": "object", "required": [ "withdraw_liquidity" @@ -155,34 +165,6 @@ }, "additionalProperties": false }, - { - "description": "Adds native token info to the contract so it can instantiate pair contracts that include it", - "type": "object", - "required": [ - "add_native_token_decimals" - ], - "properties": { - "add_native_token_decimals": { - "type": "object", - "required": [ - "decimals", - "denom" - ], - "properties": { - "decimals": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - }, - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, { "description": "Execute multiple [`SwapOperations`] to allow for multi-hop swaps.", "type": "object", @@ -442,22 +424,45 @@ ] }, "PoolFee": { - "description": "Fees used by the pools on the pool network", + "description": "Represents the fee structure for transactions within a pool.\n\n# Fields - `protocol_fee`: The fee percentage charged by the protocol on each transaction to support operational and developmental needs. - `swap_fee`: The fee percentage allocated to liquidity providers as a reward for supplying liquidity to the pool, incentivizing participation and ensuring pool health. - `burn_fee`: A fee percentage that is burned on each transaction, helping manage the token economy by reducing supply over time, potentially increasing token value. - `osmosis_fee` (optional): Specific to the Osmosis feature, this fee is charged on each transaction when the Osmosis feature is enabled, supporting specific ecosystem requirements. - `extra_fees`: A vector of custom fees allowing for extensible and adaptable fee structures to meet diverse and evolving needs. Validation ensures that the total of all fees does not exceed 100%, maintaining fairness and avoiding overcharging.\n\n# Features - `osmosis`: Enables the `osmosis_fee` field, integrating specific fee requirements for the Osmosis protocol within the pool's fee structure.", "type": "object", "required": [ "burn_fee", + "extra_fees", "protocol_fee", "swap_fee" ], "properties": { "burn_fee": { - "$ref": "#/definitions/Fee" + "description": "Fee percentage that is burned on each transaction. Burning a portion of the transaction fee helps in reducing the overall token supply.", + "allOf": [ + { + "$ref": "#/definitions/Fee" + } + ] + }, + "extra_fees": { + "description": "A list of custom, additional fees that can be defined for specific use cases or additional functionalities. This vector enables the flexibility to introduce new fees without altering the core fee structure. Total of all fees, including custom ones, is validated to not exceed 100%, ensuring a balanced and fair fee distribution.", + "type": "array", + "items": { + "$ref": "#/definitions/Fee" + } }, "protocol_fee": { - "$ref": "#/definitions/Fee" + "description": "Fee percentage charged on each transaction for the protocol's benefit.", + "allOf": [ + { + "$ref": "#/definitions/Fee" + } + ] }, "swap_fee": { - "$ref": "#/definitions/Fee" + "description": "Fee percentage allocated to liquidity providers on each swap.", + "allOf": [ + { + "$ref": "#/definitions/Fee" + } + ] } }, "additionalProperties": false diff --git a/contracts/liquidity_hub/pool-manager/schema/raw/query.json b/contracts/liquidity_hub/pool-manager/schema/raw/query.json index e43c3d5e7..31e3fa4e6 100644 --- a/contracts/liquidity_hub/pool-manager/schema/raw/query.json +++ b/contracts/liquidity_hub/pool-manager/schema/raw/query.json @@ -12,11 +12,15 @@ "native_token_decimals": { "type": "object", "required": [ - "denom" + "denom", + "pair_identifier" ], "properties": { "denom": { "type": "string" + }, + "pair_identifier": { + "type": "string" } }, "additionalProperties": false diff --git a/contracts/liquidity_hub/pool-manager/schema/raw/response_to_native_token_decimals.json b/contracts/liquidity_hub/pool-manager/schema/raw/response_to_native_token_decimals.json index 70700bba5..c60a66060 100644 --- a/contracts/liquidity_hub/pool-manager/schema/raw/response_to_native_token_decimals.json +++ b/contracts/liquidity_hub/pool-manager/schema/raw/response_to_native_token_decimals.json @@ -1,15 +1,27 @@ { "$schema": "http://json-schema.org/draft-07/schema#", "title": "NativeTokenDecimalsResponse", + "description": "The response for the `NativeTokenDecimals` query.", "type": "object", "required": [ - "decimals" + "decimals", + "denom", + "pair_identifier" ], "properties": { "decimals": { + "description": "The decimals for the requested denom.", "type": "integer", "format": "uint8", "minimum": 0.0 + }, + "denom": { + "description": "The denom to get the decimals in the given pair_identifier for.", + "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/schema/raw/response_to_pair.json b/contracts/liquidity_hub/pool-manager/schema/raw/response_to_pair.json index 9d9d73a9e..fd23cc1ab 100644 --- a/contracts/liquidity_hub/pool-manager/schema/raw/response_to_pair.json +++ b/contracts/liquidity_hub/pool-manager/schema/raw/response_to_pair.json @@ -109,22 +109,45 @@ ] }, "PoolFee": { - "description": "Fees used by the pools on the pool network", + "description": "Represents the fee structure for transactions within a pool.\n\n# Fields - `protocol_fee`: The fee percentage charged by the protocol on each transaction to support operational and developmental needs. - `swap_fee`: The fee percentage allocated to liquidity providers as a reward for supplying liquidity to the pool, incentivizing participation and ensuring pool health. - `burn_fee`: A fee percentage that is burned on each transaction, helping manage the token economy by reducing supply over time, potentially increasing token value. - `osmosis_fee` (optional): Specific to the Osmosis feature, this fee is charged on each transaction when the Osmosis feature is enabled, supporting specific ecosystem requirements. - `extra_fees`: A vector of custom fees allowing for extensible and adaptable fee structures to meet diverse and evolving needs. Validation ensures that the total of all fees does not exceed 100%, maintaining fairness and avoiding overcharging.\n\n# Features - `osmosis`: Enables the `osmosis_fee` field, integrating specific fee requirements for the Osmosis protocol within the pool's fee structure.", "type": "object", "required": [ "burn_fee", + "extra_fees", "protocol_fee", "swap_fee" ], "properties": { "burn_fee": { - "$ref": "#/definitions/Fee" + "description": "Fee percentage that is burned on each transaction. Burning a portion of the transaction fee helps in reducing the overall token supply.", + "allOf": [ + { + "$ref": "#/definitions/Fee" + } + ] + }, + "extra_fees": { + "description": "A list of custom, additional fees that can be defined for specific use cases or additional functionalities. This vector enables the flexibility to introduce new fees without altering the core fee structure. Total of all fees, including custom ones, is validated to not exceed 100%, ensuring a balanced and fair fee distribution.", + "type": "array", + "items": { + "$ref": "#/definitions/Fee" + } }, "protocol_fee": { - "$ref": "#/definitions/Fee" + "description": "Fee percentage charged on each transaction for the protocol's benefit.", + "allOf": [ + { + "$ref": "#/definitions/Fee" + } + ] }, "swap_fee": { - "$ref": "#/definitions/Fee" + "description": "Fee percentage allocated to liquidity providers on each swap.", + "allOf": [ + { + "$ref": "#/definitions/Fee" + } + ] } }, "additionalProperties": false diff --git a/contracts/liquidity_hub/pool-manager/src/contract.rs b/contracts/liquidity_hub/pool-manager/src/contract.rs index bf096dd20..7f035f678 100644 --- a/contracts/liquidity_hub/pool-manager/src/contract.rs +++ b/contracts/liquidity_hub/pool-manager/src/contract.rs @@ -52,6 +52,7 @@ pub fn execute( match msg { ExecuteMsg::CreatePair { asset_denoms, + asset_decimals, pool_fees, pair_type, pair_identifier, @@ -60,6 +61,7 @@ pub fn execute( env, info, asset_denoms, + asset_decimals, pool_fees, pair_type, pair_identifier, @@ -106,9 +108,6 @@ pub fn execute( ExecuteMsg::WithdrawLiquidity { pair_identifier } => { liquidity::commands::withdraw_liquidity(deps, env, info, pair_identifier) } - ExecuteMsg::AddNativeTokenDecimals { denom, decimals } => { - manager::commands::add_native_token_decimals(deps, env, denom, decimals) - } ExecuteMsg::UpdateOwnership(action) => { Ok( cw_ownable::update_ownership(deps, &env.block, &info.sender, action).map( @@ -174,9 +173,14 @@ 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 { denom } => Ok(to_json_binary( - &queries::query_native_token_decimal(deps, denom)?, - )?), + QueryMsg::NativeTokenDecimals { + pair_identifier, + denom, + } => Ok(to_json_binary(&queries::query_native_token_decimal( + deps, + pair_identifier, + denom, + )?)?), QueryMsg::Simulation { offer_asset, ask_asset, diff --git a/contracts/liquidity_hub/pool-manager/src/manager/commands.rs b/contracts/liquidity_hub/pool-manager/src/manager/commands.rs index 46925677f..d53408999 100644 --- a/contracts/liquidity_hub/pool-manager/src/manager/commands.rs +++ b/contracts/liquidity_hub/pool-manager/src/manager/commands.rs @@ -1,13 +1,9 @@ use cosmwasm_std::{ attr, Attribute, Coin, CosmosMsg, DepsMut, Env, MessageInfo, Response, Uint128, }; -use white_whale_std::{ - fee::PoolFee, - pool_network::{asset::PairType, querier::query_native_decimals}, - whale_lair::fill_rewards_msg, -}; +use white_whale_std::{fee::PoolFee, pool_network::asset::PairType, whale_lair::fill_rewards_msg}; -use crate::state::{get_pair_by_identifier, NATIVE_TOKEN_DECIMALS, PAIR_COUNTER}; +use crate::state::{get_pair_by_identifier, PAIR_COUNTER}; use crate::{ state::{Config, MANAGER_CONFIG, PAIRS}, ContractError, @@ -15,7 +11,6 @@ use crate::{ use white_whale_std::lp_common::LP_SYMBOL; use white_whale_std::pool_manager::PairInfo; -use white_whale_std::pool_network::querier::query_balance; pub const MAX_ASSETS_PER_POOL: usize = 4; @@ -83,7 +78,8 @@ pub fn create_pair( deps: DepsMut, env: Env, info: MessageInfo, - asset_denoms: Vec, //Review just a vec + asset_denoms: Vec, + asset_decimals: Vec, pool_fees: PoolFee, pair_type: PairType, pair_identifier: Option, @@ -115,22 +111,6 @@ pub fn create_pair( creation_fee, )?); - let asset_decimals_vec = asset_denoms - .iter() - .map(|asset| { - //todo pass the asset_decimals in the create_pair msg. Let the user creating the pool - // defining the decimals, they are incentivized to do it right as they are paying a fee - - let _ = query_native_decimals( - &deps.querier, - env.contract.address.clone(), - asset.to_string(), - ); - - 0u8 - }) - .collect::>(); - // Check if the asset infos are the same if asset_denoms .iter() @@ -184,7 +164,7 @@ pub fn create_pair( asset_denoms, pair_type: pair_type.clone(), lp_denom: lp_asset.clone(), - asset_decimals: asset_decimals_vec, + asset_decimals, pool_fees, assets, }, @@ -222,22 +202,3 @@ pub fn create_pair( .add_attributes(attributes) .add_messages(messages)) } - -/// Adds native/ibc token with decimals to the factory's whitelist so it can create pairs with that asset -pub fn add_native_token_decimals( - deps: DepsMut, - env: Env, - denom: String, - decimals: u8, -) -> Result { - let balance = query_balance(&deps.querier, env.contract.address, denom.to_string())?; - if balance.is_zero() { - return Err(ContractError::InvalidVerificationBalance {}); - } - NATIVE_TOKEN_DECIMALS.save(deps.storage, denom.as_bytes(), &decimals)?; - Ok(Response::new().add_attributes(vec![ - ("action", "add_allow_native_token"), - ("denom", &denom), - ("decimals", &decimals.to_string()), - ])) -} diff --git a/contracts/liquidity_hub/pool-manager/src/queries.rs b/contracts/liquidity_hub/pool-manager/src/queries.rs index 3090ed6ad..5a913c93f 100644 --- a/contracts/liquidity_hub/pool-manager/src/queries.rs +++ b/contracts/liquidity_hub/pool-manager/src/queries.rs @@ -1,15 +1,16 @@ use std::cmp::Ordering; use cosmwasm_std::{Coin, Decimal256, Deps, Env, Fraction, Order, StdResult, Uint128}; -use white_whale_std::pool_manager::{SwapOperation, SwapRouteResponse}; + +use white_whale_std::pool_manager::{ + NativeTokenDecimalsResponse, SwapOperation, SwapRouteResponse, +}; use white_whale_std::pool_network::{ asset::PairType, - factory::NativeTokenDecimalsResponse, pair::{ReverseSimulationResponse, SimulationResponse}, // router::SimulateSwapOperationsResponse, }; -use crate::state::NATIVE_TOKEN_DECIMALS; use crate::{ helpers::{self, calculate_stableswap_y, StableSwapDirection}, state::get_pair_by_identifier, @@ -20,11 +21,21 @@ use crate::{math::Decimal256Helper, state::SWAP_ROUTES}; /// Query the native token decimals pub fn query_native_token_decimal( deps: Deps, + pair_identifier: String, denom: String, ) -> Result { - let decimals = NATIVE_TOKEN_DECIMALS.load(deps.storage, denom.as_bytes())?; - - Ok(NativeTokenDecimalsResponse { decimals }) + 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 { + pair_identifier, + denom, + decimals: pair_info.asset_decimals[decimal_index], + }) } // Simulate a swap with the provided asset to determine the amount of the other asset that would be received diff --git a/contracts/liquidity_hub/pool-manager/src/state.rs b/contracts/liquidity_hub/pool-manager/src/state.rs index 896bf509c..22b40ba3d 100644 --- a/contracts/liquidity_hub/pool-manager/src/state.rs +++ b/contracts/liquidity_hub/pool-manager/src/state.rs @@ -34,8 +34,6 @@ pub fn get_pair_by_identifier( .may_load(deps.storage, pair_identifier)? .ok_or(ContractError::UnExistingPair {}) } -// Remove after adding decimals to pair info -pub const NATIVE_TOKEN_DECIMALS: Map<&[u8], u8> = Map::new("allow_native_token"); // Swap routes are used to establish defined routes for a given fee token to a desired fee token and is used for fee collection pub const SWAP_ROUTES: Map<(&str, &str), Vec> = Map::new("swap_routes"); diff --git a/contracts/liquidity_hub/pool-manager/src/swap/perform_swap.rs b/contracts/liquidity_hub/pool-manager/src/swap/perform_swap.rs index 9a443605d..c928aa7c7 100644 --- a/contracts/liquidity_hub/pool-manager/src/swap/perform_swap.rs +++ b/contracts/liquidity_hub/pool-manager/src/swap/perform_swap.rs @@ -129,7 +129,6 @@ pub fn perform_swap( swap_fee_asset, burn_fee_asset, protocol_fee_asset, - pair_info, spread_amount: swap_computation.spread_amount, }) 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 2ffe6794c..145b60020 100644 --- a/contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs +++ b/contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs @@ -126,21 +126,18 @@ fn deposit_and_withdraw_sanity_check() { }; // Create a pair - suite - .instantiate_default() - .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) - .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) - .create_pair( - creator.clone(), - asset_denoms, - pool_fees, - white_whale_std::pool_network::asset::PairType::ConstantProduct, - Some("whale-uluna".to_string()), - vec![coin(1000, "uusd")], - |result| { - result.unwrap(); - }, - ); + suite.instantiate_default().create_pair( + creator.clone(), + asset_denoms, + vec![6u8, 6u8], + pool_fees, + white_whale_std::pool_network::asset::PairType::ConstantProduct, + Some("whale-uluna".to_string()), + vec![coin(1000, "uusd")], + |result| { + result.unwrap(); + }, + ); let contract_addr = suite.pool_manager_addr.clone(); let lp_denom = suite.get_lp_denom("whale-uluna".to_string()); @@ -281,25 +278,23 @@ mod pair_creation_failures { extra_fees: vec![], }; // Create a pair - suite - .instantiate_default() - .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) - .create_pair( - creator.clone(), - asset_infos, - pool_fees, - white_whale_std::pool_network::asset::PairType::ConstantProduct, - None, - vec![coin(90, "uusd")], - |result| { - let err = result.unwrap_err().downcast::().unwrap(); + suite.instantiate_default().create_pair( + creator.clone(), + asset_infos, + vec![6u8, 6u8], + pool_fees, + white_whale_std::pool_network::asset::PairType::ConstantProduct, + None, + vec![coin(90, "uusd")], + |result| { + let err = result.unwrap_err().downcast::().unwrap(); - match err { - ContractError::InvalidPairCreationFee { .. } => {} - _ => panic!("Wrong error type, should return ContractError::Unauthorized"), - } - }, - ); + match err { + ContractError::InvalidPairCreationFee { .. } => {} + _ => panic!("Wrong error type, should return ContractError::Unauthorized"), + } + }, + ); } #[test] @@ -351,10 +346,10 @@ mod pair_creation_failures { // Create a pair suite .instantiate_default() - .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) .create_pair( creator.clone(), asset_infos.clone(), + vec![6u8, 6u8], pool_fees.clone(), white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("mycoolpair".to_string()), @@ -366,6 +361,7 @@ mod pair_creation_failures { .create_pair( creator.clone(), asset_infos, + vec![6u8, 6u8], pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("mycoolpair".to_string()), @@ -433,12 +429,10 @@ mod router { // Create a pair suite .instantiate_default() - .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) - .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) - .add_native_token_decimals(creator.clone(), "uusd".to_string(), 6) .create_pair( creator.clone(), first_pair, + vec![6u8, 6u8], pool_fees.clone(), white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("whale-uluna".to_string()), @@ -450,6 +444,7 @@ mod router { .create_pair( creator.clone(), second_pair, + vec![6u8, 6u8], pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("uluna-uusd".to_string()), @@ -622,12 +617,10 @@ mod router { // Create a pair suite .instantiate_default() - .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) - .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) - .add_native_token_decimals(creator.clone(), "uusd".to_string(), 6) .create_pair( creator.clone(), first_pair, + vec![6u8, 6u8], pool_fees.clone(), white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("whale-uluna".to_string()), @@ -639,6 +632,7 @@ mod router { .create_pair( creator.clone(), second_pair, + vec![6u8, 6u8], pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("uluna-uusd".to_string()), @@ -760,12 +754,10 @@ mod router { // Create a pair suite .instantiate_default() - .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) - .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) - .add_native_token_decimals(creator.clone(), "uusd".to_string(), 6) .create_pair( creator.clone(), first_pair, + vec![6u8, 6u8], pool_fees.clone(), white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("whale-uluna".to_string()), @@ -777,6 +769,7 @@ mod router { .create_pair( creator.clone(), second_pair, + vec![6u8, 6u8], pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("uluna-uusd".to_string()), @@ -915,12 +908,10 @@ mod router { // Create a pair suite .instantiate_default() - .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) - .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) - .add_native_token_decimals(creator.clone(), "uusd".to_string(), 6) .create_pair( creator.clone(), first_pair, + vec![6u8, 6u8], pool_fees.clone(), white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("whale-uluna".to_string()), @@ -932,6 +923,7 @@ mod router { .create_pair( creator.clone(), second_pair, + vec![6u8, 6u8], pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("uluna-uusd".to_string()), @@ -1139,12 +1131,10 @@ mod router { // Create a pair suite .instantiate_default() - .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) - .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) - .add_native_token_decimals(creator.clone(), "uusd".to_string(), 6) .create_pair( creator.clone(), first_pair, + vec![6u8, 6u8], pool_fees.clone(), white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("whale-uluna".to_string()), @@ -1156,6 +1146,7 @@ mod router { .create_pair( creator.clone(), second_pair, + vec![6u8, 6u8], pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("uluna-uusd".to_string()), @@ -1309,21 +1300,18 @@ mod swapping { }; // Create a pair - suite - .instantiate_default() - .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) - .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) - .create_pair( - creator.clone(), - asset_infos, - pool_fees, - white_whale_std::pool_network::asset::PairType::ConstantProduct, - Some("whale-uluna".to_string()), - vec![coin(1000, "uusd")], - |result| { - result.unwrap(); - }, - ); + suite.instantiate_default().create_pair( + creator.clone(), + asset_infos, + vec![6u8, 6u8], + pool_fees, + white_whale_std::pool_network::asset::PairType::ConstantProduct, + Some("whale-uluna".to_string()), + vec![coin(1000, "uusd")], + |result| { + result.unwrap(); + }, + ); // Lets try to add liquidity suite.provide_liquidity( @@ -1523,21 +1511,18 @@ mod swapping { }; // Create a pair - suite - .instantiate_default() - .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) - .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) - .create_pair( - creator.clone(), - asset_infos, - pool_fees, - white_whale_std::pool_network::asset::PairType::StableSwap { amp: 100 }, - Some("whale-uluna".to_string()), - vec![coin(1000, "uusd")], - |result| { - result.unwrap(); - }, - ); + suite.instantiate_default().create_pair( + creator.clone(), + asset_infos, + vec![6u8, 6u8], + pool_fees, + white_whale_std::pool_network::asset::PairType::StableSwap { amp: 100 }, + Some("whale-uluna".to_string()), + vec![coin(1000, "uusd")], + |result| { + result.unwrap(); + }, + ); // Lets try to add liquidity suite.provide_liquidity( @@ -1728,21 +1713,18 @@ mod swapping { }; // Create a pair - suite - .instantiate_default() - .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) - .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) - .create_pair( - creator.clone(), - asset_infos, - pool_fees, - white_whale_std::pool_network::asset::PairType::ConstantProduct, - Some("whale-uluna".to_string()), - vec![coin(1000, "uusd")], - |result| { - result.unwrap(); - }, - ); + suite.instantiate_default().create_pair( + creator.clone(), + asset_infos, + vec![6u8, 6u8], + pool_fees, + white_whale_std::pool_network::asset::PairType::ConstantProduct, + Some("whale-uluna".to_string()), + vec![coin(1000, "uusd")], + |result| { + result.unwrap(); + }, + ); // Lets try to add liquidity, 1000 of each token. suite.provide_liquidity( diff --git a/contracts/liquidity_hub/pool-manager/src/tests/suite.rs b/contracts/liquidity_hub/pool-manager/src/tests/suite.rs index d74de6e50..a2e305387 100644 --- a/contracts/liquidity_hub/pool-manager/src/tests/suite.rs +++ b/contracts/liquidity_hub/pool-manager/src/tests/suite.rs @@ -188,35 +188,6 @@ impl TestingSuite { ) .unwrap(); } - - #[track_caller] - pub fn add_native_token_decimals( - &mut self, - sender: Addr, - native_token_denom: String, - decimals: u8, - ) -> &mut Self { - let msg = white_whale_std::pool_manager::ExecuteMsg::AddNativeTokenDecimals { - denom: native_token_denom.clone(), - decimals, - }; - - let _creator = self.creator().clone(); - - self.app - .execute_contract( - sender, - self.pool_manager_addr.clone(), - &msg, - &[Coin { - denom: native_token_denom.to_string(), - amount: Uint128::from(1u128), - }], - ) - .unwrap(); - - self - } } /// execute messages @@ -321,6 +292,7 @@ impl TestingSuite { &mut self, sender: Addr, asset_denoms: Vec, + asset_decimals: Vec, pool_fees: PoolFee, pair_type: PairType, pair_identifier: Option, @@ -329,6 +301,7 @@ impl TestingSuite { ) -> &mut Self { let msg = white_whale_std::pool_manager::ExecuteMsg::CreatePair { asset_denoms, + asset_decimals, pool_fees, pair_type, pair_identifier, diff --git a/packages/white-whale-std/Cargo.toml b/packages/white-whale-std/Cargo.toml index 7ad29f12c..bbbcf61a9 100644 --- a/packages/white-whale-std/Cargo.toml +++ b/packages/white-whale-std/Cargo.toml @@ -46,4 +46,4 @@ cw20-base.workspace = true [dev-dependencies] cw-multi-test.workspace = true -test-case.workspace = true \ No newline at end of file +test-case.workspace = true diff --git a/packages/white-whale-std/src/pool_manager.rs b/packages/white-whale-std/src/pool_manager.rs index 6c12a4e71..3500b95e9 100644 --- a/packages/white-whale-std/src/pool_manager.rs +++ b/packages/white-whale-std/src/pool_manager.rs @@ -4,7 +4,6 @@ use crate::{ fee::PoolFee, pool_network::{ asset::PairType, - factory::NativeTokenDecimalsResponse, pair::{ReverseSimulationResponse, SimulationResponse}, }, }; @@ -128,6 +127,7 @@ pub struct MigrateMsg {} pub enum ExecuteMsg { CreatePair { asset_denoms: Vec, + asset_decimals: Vec, pool_fees: PoolFee, pair_type: PairType, pair_identifier: Option, @@ -147,16 +147,8 @@ pub enum ExecuteMsg { to: Option, pair_identifier: String, }, - // /// Withdraws liquidity from the pool. - WithdrawLiquidity { - pair_identifier: String, - }, - /// Adds native token info to the contract so it can instantiate pair contracts that include it - AddNativeTokenDecimals { - denom: String, - decimals: u8, - }, - + /// Withdraws liquidity from the pool. + WithdrawLiquidity { pair_identifier: String }, /// Execute multiple [`SwapOperations`] to allow for multi-hop swaps. ExecuteSwapOperations { /// The operations that should be performed in sequence. @@ -191,9 +183,7 @@ pub enum ExecuteMsg { // receiver: String, // }, /// Adds swap routes to the router. - AddSwapRoutes { - swap_routes: Vec, - }, + AddSwapRoutes { swap_routes: Vec }, } #[cw_ownable_query] @@ -202,7 +192,10 @@ pub enum ExecuteMsg { pub enum QueryMsg { /// Retrieves the decimals for the given native or ibc denom. #[returns(NativeTokenDecimalsResponse)] - NativeTokenDecimals { denom: String }, + NativeTokenDecimals { + pair_identifier: String, + denom: String, + }, /// Simulates a swap. #[returns(SimulationResponse)] @@ -246,3 +239,14 @@ pub enum QueryMsg { #[returns(PairInfo)] Pair { pair_identifier: String }, } + +/// The response for the `NativeTokenDecimals` query. +#[cw_serde] +pub struct NativeTokenDecimalsResponse { + /// The pair identifier to do the query for. + pub pair_identifier: String, + /// The denom to get the decimals in the given pair_identifier for. + pub denom: String, + /// The decimals for the requested denom. + pub decimals: u8, +}