Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: pool manager cleanup #350

Merged
merged 8 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions contracts/liquidity_hub/bonding-manager/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use white_whale_std::bonding_manager::{ClaimableEpochsResponse, EpochResponse};
use white_whale_std::constants::LP_SYMBOL;
use white_whale_std::epoch_manager::epoch_manager::EpochConfig;
use white_whale_std::pool_manager::{
PairInfoResponse, SimulateSwapOperationsResponse, SwapRouteResponse,
PoolInfoResponse, SimulateSwapOperationsResponse, SwapRouteResponse,
};

use crate::contract::LP_WITHDRAWAL_REPLY_ID;
Expand Down Expand Up @@ -128,13 +128,13 @@ pub fn handle_lp_tokens(
.collect();
for lp_token in lp_tokens {
// LP tokens have the format "{pair_label}.pool.{identifier}.{LP_SYMBOL}", get the identifier and not the LP SYMBOL
let pair_identifier = lp_token.denom.split(".pool.").collect::<Vec<&str>>()[1]
let pool_identifier = lp_token.denom.split(".pool.").collect::<Vec<&str>>()[1]
.split('.')
.collect::<Vec<&str>>()[0];

// if LP Tokens ,verify and withdraw then swap to whale
let lp_withdrawal_msg = white_whale_std::pool_manager::ExecuteMsg::WithdrawLiquidity {
pair_identifier: pair_identifier.to_string(),
pool_identifier: pool_identifier.to_string(),
};
// Add a submessage to withdraw the LP tokens
let lp_msg: SubMsg = SubMsg {
Expand Down Expand Up @@ -190,8 +190,8 @@ pub fn swap_coins_to_main_token(
);
// check if the pool has any assets, if not skip the swap
// Note we are only checking the first operation here. Might be better to another loop to check all operations
let pool_query = white_whale_std::pool_manager::QueryMsg::Pair {
pair_identifier: swap_routes
let pool_query = white_whale_std::pool_manager::QueryMsg::Pool {
pool_identifier: swap_routes
.swap_route
.swap_operations
.first()
Expand All @@ -200,11 +200,11 @@ pub fn swap_coins_to_main_token(
};
let mut skip_swap = false;
// Query for the pool to check if it has any assets
let resp: PairInfoResponse = deps
let resp: PoolInfoResponse = deps
.querier
.query_wasm_smart(config.pool_manager_addr.to_string(), &pool_query)?;
// Check pair 'assets' and if either one has 0 amount then don't do swaps
resp.pair_info.assets.iter().for_each(|asset| {
resp.pool_info.assets.iter().for_each(|asset| {
if asset.amount.is_zero() {
skip_swap = true;
}
Expand All @@ -226,7 +226,7 @@ pub fn swap_coins_to_main_token(
let msg = white_whale_std::pool_manager::ExecuteMsg::ExecuteSwapOperations {
operations: swap_routes.swap_route.swap_operations.clone(),
minimum_receive: Some(simulate.amount),
to: None,
receiver: None,
max_spread: Some(Decimal::percent(5)),
};
let binary_msg = to_json_binary(&msg)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fn test_claim_successfully() {
sender.clone(),
asset_infos.clone(),
pool_fees.clone(),
white_whale_std::pool_network::asset::PairType::ConstantProduct,
white_whale_std::pool_manager::PoolType::ConstantProduct,
Some("whale-uusdc".to_string()),
vec![coin(1000, "uwhale")],
|result| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn test_fill_rewards_from_pool_manager() {
creator.clone(),
asset_infos.clone(),
pool_fees.clone(),
white_whale_std::pool_network::asset::PairType::ConstantProduct,
white_whale_std::pool_manager::PoolType::ConstantProduct,
Some("whale-uusdc".to_string()),
vec![coin(1000, "uwhale")],
|result| {
Expand Down Expand Up @@ -123,7 +123,7 @@ fn test_fill_rewards_from_pool_manager() {
creator.clone(),
asset_infos.clone(),
pool_fees.clone(),
white_whale_std::pool_network::asset::PairType::ConstantProduct,
white_whale_std::pool_manager::PoolType::ConstantProduct,
Some("whale-uusdc-second".to_string()),
vec![coin(1000, "uwhale")],
|result| {
Expand All @@ -145,7 +145,7 @@ fn test_fill_rewards_from_pool_manager() {
creator.clone(),
asset_infos,
pool_fees,
white_whale_std::pool_network::asset::PairType::ConstantProduct,
white_whale_std::pool_manager::PoolType::ConstantProduct,
Some("whale-uusdc-third".to_string()),
vec![coin(1000, "uwhale")],
|result| {
Expand Down
26 changes: 13 additions & 13 deletions contracts/liquidity_hub/bonding-manager/src/tests/robot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use white_whale_std::bonding_manager::{
};
use white_whale_std::bonding_manager::{ClaimableEpochsResponse, Epoch};
use white_whale_std::epoch_manager::epoch_manager::{Epoch as EpochV2, EpochConfig};
use white_whale_std::pool_manager::PoolType;
use white_whale_std::pool_network::asset::PairType;

pub fn bonding_manager_contract() -> Box<dyn Contract<Empty>> {
Expand Down Expand Up @@ -619,12 +620,12 @@ impl TestingRobot {
pub(crate) fn provide_liquidity(
&mut self,
sender: Addr,
pair_identifier: String,
pool_identifier: String,
funds: Vec<Coin>,
result: impl Fn(Result<AppResponse, anyhow::Error>),
) -> &mut Self {
let msg = white_whale_std::pool_manager::ExecuteMsg::ProvideLiquidity {
pair_identifier,
pool_identifier,
slippage_tolerance: None,
receiver: None,
lock_position_identifier: None,
Expand All @@ -644,22 +645,21 @@ impl TestingRobot {
pub(crate) fn swap(
&mut self,
sender: Addr,
offer_asset: Coin,
_offer_asset: Coin,
ask_asset_denom: String,
belief_price: Option<Decimal>,
max_spread: Option<Decimal>,
to: Option<String>,
pair_identifier: String,
receiver: Option<String>,
pool_identifier: String,
funds: Vec<Coin>,
result: impl Fn(Result<AppResponse, anyhow::Error>),
) -> &mut Self {
let msg = white_whale_std::pool_manager::ExecuteMsg::Swap {
offer_asset,
ask_asset_denom,
belief_price,
max_spread,
to,
pair_identifier,
receiver,
pool_identifier,
};

result(
Expand Down Expand Up @@ -710,16 +710,16 @@ impl TestingRobot {
sender: Addr,
asset_denoms: Vec<String>,
pool_fees: PoolFee,
pair_type: PairType,
pair_identifier: Option<String>,
pool_type: PoolType,
pool_identifier: Option<String>,
pair_creation_fee_funds: Vec<Coin>,
result: impl Fn(Result<AppResponse, anyhow::Error>),
) -> &mut Self {
let msg = white_whale_std::pool_manager::ExecuteMsg::CreatePair {
let msg = white_whale_std::pool_manager::ExecuteMsg::CreatePool {
asset_denoms,
pool_fees,
pair_type,
pair_identifier,
pool_type,
pool_identifier,
asset_decimals: vec![6, 6],
};

Expand Down
Loading
Loading