From 30712fb66554a4f4ae04422c4058d3022f7f5a21 Mon Sep 17 00:00:00 2001 From: 0xFable <0xfable@protonmail.com> Date: Fri, 26 Apr 2024 13:07:10 +0100 Subject: [PATCH] feat: Finish Swap usecase and Lp withdrawal, update pool manager to use new method, update tests --- .../bonding-manager/src/commands.rs | 106 +++++----------- .../bonding-manager/src/contract.rs | 14 ++- .../bonding-manager/src/helpers.rs | 118 +++++++++++++++++- .../bonding-manager/src/tests/claim.rs | 11 +- .../bonding-manager/src/tests/instantiate.rs | 2 + .../bonding-manager/src/tests/rewards.rs | 30 ++++- .../bonding-manager/src/tests/robot.rs | 27 +++- .../src/tests/update_config.rs | 16 +++ .../pool-manager/src/router/commands.rs | 3 +- .../pool-manager/src/swap/commands.rs | 3 +- .../white-whale-std/src/bonding_manager.rs | 7 ++ packages/white-whale-std/src/lib.rs | 1 - packages/white-whale-std/src/pool_manager.rs | 6 + 13 files changed, 249 insertions(+), 95 deletions(-) diff --git a/contracts/liquidity_hub/bonding-manager/src/commands.rs b/contracts/liquidity_hub/bonding-manager/src/commands.rs index 7c207bec..71597e8f 100644 --- a/contracts/liquidity_hub/bonding-manager/src/commands.rs +++ b/contracts/liquidity_hub/bonding-manager/src/commands.rs @@ -1,9 +1,7 @@ use cosmwasm_std::{ - ensure, to_json_binary, Addr, BankMsg, Coin, CosmosMsg, Decimal, DepsMut, Env, MessageInfo, - Order, Response, StdError, StdResult, Timestamp, Uint128, Uint64, WasmMsg, + ensure, Addr, BankMsg, Coin, CosmosMsg, Decimal, DepsMut, Env, MessageInfo, Order, Response, + StdError, StdResult, Timestamp, Uint128, Uint64, }; -use white_whale_std::constants::LP_SYMBOL; -use white_whale_std::pool_manager::PairInfoResponse; use white_whale_std::pool_network::asset; use white_whale_std::bonding_manager::Bond; @@ -188,6 +186,7 @@ pub(crate) fn update_config( deps: DepsMut, info: MessageInfo, owner: Option, + pool_manager_addr: Option, unbonding_period: Option, growth_rate: Option, ) -> Result { @@ -197,6 +196,10 @@ pub(crate) fn update_config( return Err(ContractError::Unauthorized {}); } + if let Some(pool_manager_addr) = pool_manager_addr { + config.pool_manager_addr = deps.api.addr_validate(&pool_manager_addr)?; + } + if let Some(owner) = owner { config.owner = deps.api.addr_validate(&owner)?; } @@ -215,6 +218,7 @@ pub(crate) fn update_config( Ok(Response::default().add_attributes(vec![ ("action", "update_config".to_string()), ("owner", config.owner.to_string()), + ("pool_manager_addr", config.pool_manager_addr.to_string()), ("unbonding_period", config.unbonding_period.to_string()), ("growth_rate", config.growth_rate.to_string()), ])) @@ -320,93 +324,45 @@ pub(crate) fn fill_rewards( info: MessageInfo, ) -> Result { { - // Use aggregate_coins to get the total amount of new coins // Finding the most recent EpochID let most_recent_epoch_id = EPOCHS .keys(deps.storage, None, None, Order::Descending) .next() .unwrap()?; + let config = CONFIG.load(deps.storage)?; + let distribution_denom = config.distribution_denom.clone(); + let mut messages: Vec = vec![]; - // Verify coins are coming // swap non-whale to whale // Search info funds for LP tokens, LP tokens will contain LP_SYMBOL from lp_common and the string .pair. - let _lp_tokens = info + let mut whale = info .funds .iter() - .filter(|coin| coin.denom.contains(".pair.") | coin.denom.contains(LP_SYMBOL)); - // LP tokens have the format "{pair_label}.pair.{identifier}.{LP_SYMBOL}", get the identifier and not the LP SYMBOL - // let _pair_identifier = lp_tokens - // .map(|coin| coin.denom.split(".pair.").collect::>()[1]) - // .next() - // .unwrap(); - - // // 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() }; - // messages.push(CosmosMsg::Wasm(WasmMsg::Execute { - // contract_addr: , - // msg: to_json_binary(&lp_withdrawal_msg)?, - // funds: vec![], - // })); - - let pool_identifier = "whale-uusdc".to_string(); - let pool_query = white_whale_std::pool_manager::QueryMsg::Pair { - pair_identifier: pool_identifier.clone(), - }; - let resp: PairInfoResponse = deps - .querier - .query_wasm_smart("contract2".to_string(), &pool_query)?; - let mut skip_swap = false; - // Check pair 'assets' and if either one has 0 amount then don't do swaps - resp.pair_info.assets.iter().for_each(|asset| { - if asset.amount.is_zero() { - skip_swap = true; - } - }); - // Suggested method for swaps - // Loop over the assets in info.funds - // If whale is in the fund object then skip that - // Everything else either gets swapped or if its an LP token withdrawn and then swapped - // For each swapped coin we need to simulate swap operations and get the route from SwapRoutes - // For each swapped coin if there is no funds found in the pool found via SwapRoutes, skip it. e.g newly made pools - // Might need to add a reply to the contract as if doing it only in this method we can only save the simulation amount in the state - // Alternatively we could add a reply and try to get the actual amount swapped from there. - - if !skip_swap { - let swap_operations = vec![white_whale_std::pool_manager::SwapOperation::WhaleSwap { - token_in_denom: info.funds[0].denom.to_string(), - token_out_denom: "uwhale".to_string(), - pool_identifier, - }]; - let msg = white_whale_std::pool_manager::ExecuteMsg::ExecuteSwapOperations { - operations: swap_operations, - minimum_receive: None, - to: None, - max_spread: None, - }; - let binary_msg = to_json_binary(&msg)?; - let wrapped_msg = WasmMsg::Execute { - contract_addr: "contract2".to_string(), - msg: binary_msg, - funds: info.funds.to_vec(), - }; - messages.push(wrapped_msg.into()); - } - // Note: Might need to convert back to ints and use that for ranking to get the most recent ID - // Note: After swap, - // TODO: Remove hardcode below after more testing + .find(|coin| coin.denom.eq(distribution_denom.as_str())) + .unwrap() + .to_owned(); + // Each of these helpers will add messages to the messages vector + // and may increment the whale Coin above with the result of the swaps + helpers::handle_lp_tokens(&info, &config, &mut messages)?; + helpers::swap_coins_to_main_token( + info, + &deps, + config, + &mut whale, + &distribution_denom, + &mut messages, + )?; + // Add the whale to the funds, the whale figure now should be the result + // of all the LP token withdrawals and swaps + // Because we are using minimum receive, it is possible the contract can accumulate micro amounts of whale if we get more than what the swap query returned + // If this became an issue would could look at replys instead of the query EPOCHS.update( deps.storage, &most_recent_epoch_id, |bucket| -> StdResult<_> { let mut bucket = bucket.unwrap_or_default(); - bucket.available = asset::aggregate_coins( - bucket.available, - vec![Coin { - denom: "uwhale".to_string(), - amount: Uint128::new(1000u128), - }], - )?; + bucket.available = asset::aggregate_coins(bucket.available, vec![whale.clone()])?; Ok(bucket) }, )?; diff --git a/contracts/liquidity_hub/bonding-manager/src/contract.rs b/contracts/liquidity_hub/bonding-manager/src/contract.rs index 71ca893d..dc6d021a 100644 --- a/contracts/liquidity_hub/bonding-manager/src/contract.rs +++ b/contracts/liquidity_hub/bonding-manager/src/contract.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{ensure, entry_point, Coin}; +use cosmwasm_std::{ensure, entry_point, Addr, Coin}; use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; use cw2::{get_contract_version, set_contract_version}; use cw_utils::PaymentError; @@ -38,6 +38,8 @@ pub fn instantiate( let config = Config { owner: deps.api.addr_validate(info.sender.as_str())?, + pool_manager_addr: Addr::unchecked(""), + distribution_denom: msg.distribution_denom, unbonding_period: msg.unbonding_period, growth_rate: msg.growth_rate, bonding_assets: msg.bonding_assets.clone(), @@ -116,9 +118,17 @@ pub fn execute( } ExecuteMsg::UpdateConfig { owner, + pool_manager_addr, unbonding_period, growth_rate, - } => commands::update_config(deps, info, owner, unbonding_period, growth_rate), + } => commands::update_config( + deps, + info, + owner, + pool_manager_addr, + unbonding_period, + growth_rate, + ), ExecuteMsg::FillRewards { .. } => commands::fill_rewards(deps, env, info), ExecuteMsg::FillRewardsCoin => commands::fill_rewards(deps, env, info), ExecuteMsg::Claim { .. } => commands::claim(deps, env, info), diff --git a/contracts/liquidity_hub/bonding-manager/src/helpers.rs b/contracts/liquidity_hub/bonding-manager/src/helpers.rs index a78b4e30..a6d091de 100644 --- a/contracts/liquidity_hub/bonding-manager/src/helpers.rs +++ b/contracts/liquidity_hub/bonding-manager/src/helpers.rs @@ -1,6 +1,13 @@ -use cosmwasm_std::{Coin, Decimal, DepsMut, Env, MessageInfo, StdResult, Timestamp, Uint64}; +use cosmwasm_std::{ + to_json_binary, Coin, CosmosMsg, Decimal, DepsMut, Env, MessageInfo, StdResult, Timestamp, + Uint64, WasmMsg, +}; 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, +}; use crate::error::ContractError; use crate::queries::{get_claimable_epochs, get_current_epoch}; @@ -90,6 +97,115 @@ pub fn calculate_epoch( Ok(epoch) } +// Used in FillRewards to search the funds for LP tokens and withdraw them +// If we do get some LP tokens to withdraw they could be swapped to whale in the reply +pub fn handle_lp_tokens( + info: &MessageInfo, + config: &white_whale_std::bonding_manager::Config, + messages: &mut Vec, +) -> Result<(), ContractError> { + let lp_tokens: Vec<&Coin> = info + .funds + .iter() + .filter(|coin| coin.denom.contains(".pair.") | coin.denom.contains(LP_SYMBOL)) + .collect(); + for lp_token in lp_tokens { + // LP tokens have the format "{pair_label}.pair.{identifier}.{LP_SYMBOL}", get the identifier and not the LP SYMBOL + let pair_identifier = lp_token.denom.split(".pair.").collect::>()[1]; + + // 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(), + }; + messages.push(CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: config.pool_manager_addr.to_string(), + msg: to_json_binary(&lp_withdrawal_msg)?, + funds: vec![lp_token.clone()], + })); + } + Ok(()) +} + +// Used in FillRewards to search the funds for coins that are neither LP tokens nor whale and swap them to whale +pub fn swap_coins_to_main_token( + info: MessageInfo, + deps: &DepsMut, + config: white_whale_std::bonding_manager::Config, + whale: &mut Coin, + distribution_denom: &String, + messages: &mut Vec, +) -> Result<(), ContractError> { + let coins_to_swap: Vec<&Coin> = info + .funds + .iter() + .filter(|coin| { + !coin.denom.contains(".pair.") + & !coin.denom.contains(LP_SYMBOL) + & !coin.denom.eq(distribution_denom) + }) + .collect(); + for coin in coins_to_swap { + let swap_route_query = white_whale_std::pool_manager::QueryMsg::SwapRoute { + offer_asset_denom: coin.denom.to_string(), + ask_asset_denom: distribution_denom.to_string(), + }; + + // Query for the routes and pool + let swap_routes: SwapRouteResponse = deps + .querier + .query_wasm_smart(config.pool_manager_addr.to_string(), &swap_route_query)?; + + // 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 + .swap_route + .swap_operations + .first() + .unwrap() + .get_pool_identifer(), + }; + let resp: PairInfoResponse = deps + .querier + .query_wasm_smart(config.pool_manager_addr.to_string(), &pool_query)?; + let mut skip_swap = false; + // Check pair 'assets' and if either one has 0 amount then don't do swaps + resp.pair_info.assets.iter().for_each(|asset| { + if asset.amount.is_zero() { + skip_swap = true; + } + }); + + let simulate: SimulateSwapOperationsResponse = deps.querier.query_wasm_smart( + config.pool_manager_addr.to_string(), + &white_whale_std::pool_manager::QueryMsg::SimulateSwapOperations { + offer_amount: coin.amount, + operations: swap_routes.swap_route.swap_operations.clone(), + }, + )?; + // Add the simulate amount received to the whale amount, if the swap fails this should also be rolled back + whale.amount = whale.amount.checked_add(simulate.amount)?; + + if !skip_swap { + // 1% max spread for the swap + let msg = white_whale_std::pool_manager::ExecuteMsg::ExecuteSwapOperations { + operations: swap_routes.swap_route.swap_operations.clone(), + minimum_receive: Some(simulate.amount), + to: None, + max_spread: Some(Decimal::percent(1)), + }; + let binary_msg = to_json_binary(&msg)?; + let wrapped_msg = WasmMsg::Execute { + contract_addr: config.pool_manager_addr.to_string(), + msg: binary_msg, + funds: vec![coin.clone()], + }; + messages.push(wrapped_msg.into()); + } + } + Ok(()) +} + #[cfg(test)] mod tests { use super::*; diff --git a/contracts/liquidity_hub/bonding-manager/src/tests/claim.rs b/contracts/liquidity_hub/bonding-manager/src/tests/claim.rs index 223f35e7..703a780c 100644 --- a/contracts/liquidity_hub/bonding-manager/src/tests/claim.rs +++ b/contracts/liquidity_hub/bonding-manager/src/tests/claim.rs @@ -182,7 +182,7 @@ fn test_bond_successfully() { pool_fees.clone(), white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("whale-uusdc".to_string()), - vec![coin(1000, "uusdc")], + vec![coin(1000, "uwhale")], |result| { result.unwrap(); }, @@ -240,6 +240,13 @@ fn test_bond_successfully() { }); robot.claim(sender, |res| { - println!("{:?}", res); + let result = res.unwrap(); + println!("{:?}", result); + assert!(result.events.iter().any(|event| { + event + .attributes + .iter() + .any(|attr| attr.key == "amount" && attr.value == "390uwhale") + })); }); } diff --git a/contracts/liquidity_hub/bonding-manager/src/tests/instantiate.rs b/contracts/liquidity_hub/bonding-manager/src/tests/instantiate.rs index 609c4fa6..91166618 100644 --- a/contracts/liquidity_hub/bonding-manager/src/tests/instantiate.rs +++ b/contracts/liquidity_hub/bonding-manager/src/tests/instantiate.rs @@ -16,6 +16,8 @@ fn test_instantiate_successfully() { ) .assert_config(Config { owner: Addr::unchecked("owner"), + pool_manager_addr: Addr::unchecked("contract2"), + distribution_denom: "uwhale".to_string(), unbonding_period: Uint64::new(1_000u64), growth_rate: Decimal::one(), grace_period: Uint64::new(21u64), diff --git a/contracts/liquidity_hub/bonding-manager/src/tests/rewards.rs b/contracts/liquidity_hub/bonding-manager/src/tests/rewards.rs index 224d14aa..00b92b23 100644 --- a/contracts/liquidity_hub/bonding-manager/src/tests/rewards.rs +++ b/contracts/liquidity_hub/bonding-manager/src/tests/rewards.rs @@ -1,5 +1,8 @@ +use std::vec; + use cosmwasm_std::{coin, Coin, Decimal, Uint128}; use white_whale_std::fee::{Fee, PoolFee}; +use white_whale_std::pool_manager::SwapRoute; use white_whale_std::pool_network::asset::MINIMUM_LIQUIDITY_AMOUNT; use crate::tests::robot::TestingRobot; @@ -38,7 +41,7 @@ fn test_fill_rewards_from_pool_manager() { pool_fees.clone(), white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("whale-uusdc".to_string()), - vec![coin(1000, "uusdc")], + vec![coin(1000, "uwhale")], |result| { result.unwrap(); }, @@ -71,6 +74,20 @@ fn test_fill_rewards_from_pool_manager() { }, ); + // Lets try to add a swap route + let swap_route_1 = SwapRoute { + offer_asset_denom: "uwhale".to_string(), + ask_asset_denom: "uusd".to_string(), + swap_operations: vec![white_whale_std::pool_manager::SwapOperation::WhaleSwap { + token_in_denom: "uusdc".to_string(), + token_out_denom: "uwhale".to_string(), + pool_identifier: "whale-uusdc".to_string(), + }], + }; + robot.add_swap_routes(creator.clone(), vec![swap_route_1], |res| { + println!("{:?}", res.unwrap()); + }); + robot.swap( creator.clone(), coin(1_000u128, "uusdc"), @@ -94,7 +111,8 @@ fn test_fill_rewards_from_pool_manager() { robot.bonding_manager_addr.clone(), |res| { // 1_000u128 - 9u128 swap_fee - 9u128 protocol_fee where protocol_fee and swap_fee are 1% of the swap amount - assert_eq!(res, Uint128::from(18u128)); + // + 1_000u128 uwhale pool creation fee + assert_eq!(res, Uint128::from(1018u128)); }, ); @@ -104,7 +122,7 @@ fn test_fill_rewards_from_pool_manager() { pool_fees.clone(), white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("whale-uusdc-second".to_string()), - vec![coin(1000, "uusdc")], + vec![coin(1000, "uwhale")], |result| { result.unwrap(); }, @@ -115,7 +133,7 @@ fn test_fill_rewards_from_pool_manager() { "uwhale".to_string(), robot.bonding_manager_addr.clone(), |res| { - assert_eq!(res, Uint128::from(1017u128)); + assert_eq!(res, Uint128::from(2018u128)); }, ); @@ -126,7 +144,7 @@ fn test_fill_rewards_from_pool_manager() { pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, Some("whale-uusdc-third".to_string()), - vec![coin(1000, "uusdc")], + vec![coin(1000, "uwhale")], |result| { result.unwrap(); }, @@ -136,7 +154,7 @@ fn test_fill_rewards_from_pool_manager() { "uwhale".to_string(), robot.bonding_manager_addr.clone(), |res| { - assert_eq!(res, Uint128::from(2016u128)); + assert_eq!(res, Uint128::from(3018u128)); }, ); } diff --git a/contracts/liquidity_hub/bonding-manager/src/tests/robot.rs b/contracts/liquidity_hub/bonding-manager/src/tests/robot.rs index 4a366855..57a04abc 100644 --- a/contracts/liquidity_hub/bonding-manager/src/tests/robot.rs +++ b/contracts/liquidity_hub/bonding-manager/src/tests/robot.rs @@ -209,7 +209,7 @@ impl TestingRobot { fee_collector_addr: bonding_manager_addr.clone().to_string(), pool_creation_fee: Coin { amount: Uint128::from(1_000u128), - denom: "uusdc".to_string(), + denom: "uwhale".to_string(), }, }; @@ -228,12 +228,11 @@ impl TestingRobot { Some(creator.into_string()), ) .unwrap(); - // Now set the fee distributor on the config of the whale lair - // So that we can check claims before letting them bond/unbond let msg = ExecuteMsg::UpdateConfig { + pool_manager_addr: Some(pool_manager_addr.clone().to_string()), + growth_rate: None, owner: None, unbonding_period: None, - growth_rate: None, }; self.app .execute_contract(self.sender.clone(), bonding_manager_addr.clone(), &msg, &[]) @@ -356,12 +355,14 @@ impl TestingRobot { &mut self, sender: Addr, owner: Option, + pool_manager_addr: Option, unbonding_period: Option, growth_rate: Option, response: impl Fn(Result), ) -> &mut Self { let msg = ExecuteMsg::UpdateConfig { owner, + pool_manager_addr, unbonding_period, growth_rate, }; @@ -398,6 +399,7 @@ fn instantiate_contract( ) -> anyhow::Result { let msg = InstantiateMsg { unbonding_period, + distribution_denom: "uwhale".to_string(), growth_rate, bonding_assets, grace_period: Uint64::new(21), @@ -649,6 +651,23 @@ impl TestingRobot { self } + #[track_caller] + pub(crate) fn add_swap_routes( + &mut self, + sender: Addr, + swap_routes: Vec, + result: impl Fn(Result), + ) -> &mut Self { + let msg = white_whale_std::pool_manager::ExecuteMsg::AddSwapRoutes { swap_routes }; + + result( + self.app + .execute_contract(sender, self.pool_manager_addr.clone(), &msg, &[]), + ); + + self + } + #[track_caller] pub(crate) fn create_pair( &mut self, diff --git a/contracts/liquidity_hub/bonding-manager/src/tests/update_config.rs b/contracts/liquidity_hub/bonding-manager/src/tests/update_config.rs index 25bed29f..96f586cc 100644 --- a/contracts/liquidity_hub/bonding-manager/src/tests/update_config.rs +++ b/contracts/liquidity_hub/bonding-manager/src/tests/update_config.rs @@ -13,6 +13,8 @@ fn test_update_config_successfully() { .instantiate_default() .assert_config(Config { owner: Addr::unchecked("owner"), + pool_manager_addr: Addr::unchecked("contract2"), + distribution_denom: "uwhale".to_string(), unbonding_period: Uint64::new(1_000_000_000_000u64), growth_rate: Decimal::one(), grace_period: Uint64::new(21u64), @@ -21,6 +23,7 @@ fn test_update_config_successfully() { .update_config( owner.clone(), None, + None, Some(Uint64::new(500u64)), Some(Decimal::from_ratio( Uint128::new(1u128), @@ -30,6 +33,8 @@ fn test_update_config_successfully() { ) .assert_config(Config { owner: owner.clone(), + pool_manager_addr: Addr::unchecked("contract2"), + distribution_denom: "uwhale".to_string(), unbonding_period: Uint64::new(500u64), growth_rate: Decimal::from_ratio(Uint128::new(1u128), Uint128::new(2u128)), grace_period: Uint64::new(21u64), @@ -39,11 +44,14 @@ fn test_update_config_successfully() { owner, Some("new_owner".to_string()), None, + None, Some(Decimal::one()), |_res| {}, ) .assert_config(Config { owner: Addr::unchecked("new_owner"), + pool_manager_addr: Addr::unchecked("contract2"), + distribution_denom: "uwhale".to_string(), unbonding_period: Uint64::new(500u64), growth_rate: Decimal::one(), grace_period: Uint64::new(21u64), @@ -59,6 +67,8 @@ fn test_update_config_unsuccessfully() { .instantiate_default() .assert_config(Config { owner: Addr::unchecked("owner"), + pool_manager_addr: Addr::unchecked("contract2"), + distribution_denom: "uwhale".to_string(), unbonding_period: Uint64::new(1_000_000_000_000u64), growth_rate: Decimal::one(), grace_period: Uint64::new(21u64), @@ -67,6 +77,7 @@ fn test_update_config_unsuccessfully() { .update_config( Addr::unchecked("unauthorized"), None, + None, Some(Uint64::new(500u64)), Some(Decimal::from_ratio( Uint128::new(1u128), @@ -82,6 +93,8 @@ fn test_update_config_unsuccessfully() { ) .assert_config(Config { owner: Addr::unchecked("owner"), + pool_manager_addr: Addr::unchecked("contract2"), + distribution_denom: "uwhale".to_string(), unbonding_period: Uint64::new(1_000_000_000_000u64), growth_rate: Decimal::one(), grace_period: Uint64::new(21u64), @@ -90,6 +103,7 @@ fn test_update_config_unsuccessfully() { .update_config( Addr::unchecked("owner"), None, + None, Some(Uint64::new(500u64)), Some(Decimal::from_ratio( Uint128::new(2u128), @@ -105,6 +119,8 @@ fn test_update_config_unsuccessfully() { ) .assert_config(Config { owner: Addr::unchecked("owner"), + pool_manager_addr: Addr::unchecked("contract2"), + distribution_denom: "uwhale".to_string(), unbonding_period: Uint64::new(1_000_000_000_000u64), growth_rate: Decimal::one(), grace_period: Uint64::new(21u64), diff --git a/contracts/liquidity_hub/pool-manager/src/router/commands.rs b/contracts/liquidity_hub/pool-manager/src/router/commands.rs index 2f4b662c..724dd493 100644 --- a/contracts/liquidity_hub/pool-manager/src/router/commands.rs +++ b/contracts/liquidity_hub/pool-manager/src/router/commands.rs @@ -119,8 +119,7 @@ pub fn execute_swap_operations( if !swap_result.protocol_fee_asset.amount.is_zero() { fee_messages.push(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: config.whale_lair_addr.to_string(), - msg: to_json_binary(&whale_lair::ExecuteMsg::FillRewards { - assets: vec![swap_result.protocol_fee_asset.clone()], + msg: to_json_binary(&whale_lair::ExecuteMsg::FillRewardsCoin { })?, funds: vec![swap_result.protocol_fee_asset.clone()], })); diff --git a/contracts/liquidity_hub/pool-manager/src/swap/commands.rs b/contracts/liquidity_hub/pool-manager/src/swap/commands.rs index 5bd7c4fc..4afdba5f 100644 --- a/contracts/liquidity_hub/pool-manager/src/swap/commands.rs +++ b/contracts/liquidity_hub/pool-manager/src/swap/commands.rs @@ -64,8 +64,7 @@ pub fn swap( if !swap_result.protocol_fee_asset.amount.is_zero() { messages.push(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: config.whale_lair_addr.to_string(), - msg: to_json_binary(&whale_lair::ExecuteMsg::FillRewards { - assets: vec![swap_result.protocol_fee_asset.clone()], + msg: to_json_binary(&whale_lair::ExecuteMsg::FillRewardsCoin { })?, funds: vec![swap_result.protocol_fee_asset.clone()], })); diff --git a/packages/white-whale-std/src/bonding_manager.rs b/packages/white-whale-std/src/bonding_manager.rs index 87245f04..8ec81782 100644 --- a/packages/white-whale-std/src/bonding_manager.rs +++ b/packages/white-whale-std/src/bonding_manager.rs @@ -12,6 +12,10 @@ use cosmwasm_std::{ pub struct Config { /// Owner of the contract. pub owner: Addr, + /// Pool Manager contract address for swapping + pub pool_manager_addr: Addr, + /// Distribution denom for the rewards + pub distribution_denom: String, /// Unbonding period in nanoseconds. pub unbonding_period: Uint64, /// A fraction that controls the effect of time on the weight of a bond. If the growth rate is set @@ -78,6 +82,8 @@ pub struct GlobalIndex { #[cw_serde] pub struct InstantiateMsg { + /// Denom to be swapped to and rewarded + pub distribution_denom: String, /// Unbonding period in nanoseconds. pub unbonding_period: Uint64, /// Weight grow rate. Needs to be between 0 and 1. @@ -108,6 +114,7 @@ pub enum ExecuteMsg { /// Updates the [Config] of the contract. UpdateConfig { owner: Option, + pool_manager_addr: Option, unbonding_period: Option, growth_rate: Option, }, diff --git a/packages/white-whale-std/src/lib.rs b/packages/white-whale-std/src/lib.rs index 5436073e..6af2ef3f 100644 --- a/packages/white-whale-std/src/lib.rs +++ b/packages/white-whale-std/src/lib.rs @@ -14,7 +14,6 @@ pub mod pool_network; pub mod token_factory; pub mod bonding_manager; -pub mod coin; #[cfg(any( feature = "token_factory", diff --git a/packages/white-whale-std/src/pool_manager.rs b/packages/white-whale-std/src/pool_manager.rs index 25dfc83e..8b98b6a0 100644 --- a/packages/white-whale-std/src/pool_manager.rs +++ b/packages/white-whale-std/src/pool_manager.rs @@ -29,6 +29,12 @@ impl SwapOperation { } => token_out_denom.clone(), } } + + pub fn get_pool_identifer(&self) -> String { + match self { + SwapOperation::WhaleSwap { pool_identifier, .. } => pool_identifier.clone(), + } + } } impl fmt::Display for SwapOperation {