diff --git a/contracts/liquidity_hub/pool-manager/src/manager/commands.rs b/contracts/liquidity_hub/pool-manager/src/manager/commands.rs index d5340899..c0139221 100644 --- a/contracts/liquidity_hub/pool-manager/src/manager/commands.rs +++ b/contracts/liquidity_hub/pool-manager/src/manager/commands.rs @@ -35,6 +35,7 @@ pub const MAX_ASSETS_PER_POOL: usize = 4; /// "uatom".into(), /// "uscrt".into(), /// ]; +/// let asset_decimals = vec![6, 6]; /// #[cfg(not(feature = "osmosis"))] /// let pool_fees = PoolFee { /// protocol_fee: Fee { @@ -68,7 +69,7 @@ pub const MAX_ASSETS_PER_POOL: usize = 4; /// let pair_type = PairType::ConstantProduct; /// let token_factory_lp = false; /// -/// let response = create_pair(deps, env, info, asset_infos, pool_fees, pair_type, None)?; +/// let response = create_pair(deps, env, info, asset_infos, asset_decimals, pool_fees, pair_type, None)?; /// # Ok(response) /// # } /// ``` diff --git a/contracts/liquidity_hub/pool-manager/src/router/commands.rs b/contracts/liquidity_hub/pool-manager/src/router/commands.rs index 81e92f19..c293b1c2 100644 --- a/contracts/liquidity_hub/pool-manager/src/router/commands.rs +++ b/contracts/liquidity_hub/pool-manager/src/router/commands.rs @@ -1,7 +1,9 @@ use cosmwasm_std::{ - attr, coin, Addr, BankMsg, Coin, CosmosMsg, Decimal, DepsMut, MessageInfo, Response, Uint128, + attr, coin, to_json_binary, Addr, BankMsg, Coin, CosmosMsg, Decimal, DepsMut, MessageInfo, + Response, Uint128, WasmMsg, }; use white_whale_std::pool_manager::{SwapOperation, SwapRoute}; +use white_whale_std::whale_lair; use crate::{ helpers::simulate_swap_operations, @@ -117,12 +119,13 @@ pub fn execute_swap_operations( amount: vec![swap_result.burn_fee_asset], })); } - - // todo this should be not a BankMsg but a fill_rewards msg if !swap_result.protocol_fee_asset.amount.is_zero() { - fee_messages.push(CosmosMsg::Bank(BankMsg::Send { - to_address: config.whale_lair_addr.to_string(), - amount: vec![swap_result.protocol_fee_asset], + 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()], + })?, + 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 c597a649..66ae981b 100644 --- a/contracts/liquidity_hub/pool-manager/src/swap/commands.rs +++ b/contracts/liquidity_hub/pool-manager/src/swap/commands.rs @@ -1,9 +1,12 @@ use crate::{state::MANAGER_CONFIG, ContractError}; -use cosmwasm_std::{Addr, BankMsg, Coin, CosmosMsg, DepsMut, Env, MessageInfo, Response}; +use cosmwasm_std::{ + to_json_binary, Addr, BankMsg, Coin, CosmosMsg, DepsMut, Env, MessageInfo, Response, WasmMsg, +}; pub const MAX_ASSETS_PER_POOL: usize = 4; use cosmwasm_std::Decimal; +use white_whale_std::whale_lair; use super::perform_swap::perform_swap; @@ -52,18 +55,20 @@ pub fn swap( amount: vec![swap_result.return_asset.clone()], })); } + // then we add the fees if !swap_result.burn_fee_asset.amount.is_zero() { messages.push(CosmosMsg::Bank(BankMsg::Burn { amount: vec![swap_result.burn_fee_asset.clone()], })); } - - //todo this should be not a BankMsg but a fill_rewards msg if !swap_result.protocol_fee_asset.amount.is_zero() { - messages.push(CosmosMsg::Bank(BankMsg::Send { - to_address: config.whale_lair_addr.to_string(), - amount: vec![swap_result.protocol_fee_asset.clone()], + 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()], + })?, + funds: vec![swap_result.protocol_fee_asset.clone()], })); } 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 bac0820a..a24a1060 100644 --- a/contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs +++ b/contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs @@ -20,8 +20,8 @@ fn instantiate_normal() { #[test] fn deposit_and_withdraw_sanity_check() { let mut suite = TestingSuite::default_with_balances(vec![ - coin(1_000_001u128, "uwhale".to_string()), - coin(1_000_001u128, "uluna".to_string()), + coin(1_000_000u128, "uwhale".to_string()), + coin(1_000_000u128, "uluna".to_string()), coin(1_000u128, "uusd".to_string()), ]); let creator = suite.creator(); @@ -323,9 +323,9 @@ mod router { #[test] fn basic_swap_operations_test() { let mut suite = TestingSuite::default_with_balances(vec![ - coin(1_000_000_001u128, "uwhale".to_string()), + coin(1_000_000_000u128, "uwhale".to_string()), coin(1_000_000_000u128, "uluna".to_string()), - coin(1_000_000_001u128, "uusd".to_string()), + coin(1_000_000_000u128, "uusd".to_string()), ]); let creator = suite.creator(); let _other = suite.senders[1].clone(); @@ -451,10 +451,9 @@ mod router { }, ]; - // before swap uusd balance = 1_000_000_001 + // before swap uusd balance = 1_000_000_000 // - 2*1_000 pair creation fee // - 1_000_000 liquidity provision - // - 1 for native token creation (for decimal precisions) // = 998_998_000 let pre_swap_amount = 998_998_000; suite.query_balance(creator.to_string(), "uusd".to_string(), |amt| { @@ -799,9 +798,9 @@ mod router { #[test] fn sends_to_correct_receiver() { let mut suite = TestingSuite::default_with_balances(vec![ - coin(1_000_000_001u128, "uwhale".to_string()), + coin(1_000_000_000u128, "uwhale".to_string()), coin(1_000_000_000u128, "uluna".to_string()), - coin(1_000_000_001u128, "uusd".to_string()), + coin(1_000_000_000u128, "uusd".to_string()), ]); let creator = suite.creator(); let other = suite.senders[1].clone(); @@ -931,10 +930,10 @@ mod router { }, ]; - // before swap uusd balance = 1_000_000_001 - // before swap uwhale balance = 1_000_000_001 - // before swap uluna balance = 1_000_000_001 - let pre_swap_amount = 1_000_000_001; + // before swap uusd balance = 1_000_000_000 + // before swap uwhale balance = 1_000_000_000 + // before swap uluna balance = 1_000_000_000 + let pre_swap_amount = 1_000_000_000; suite.query_balance(other.to_string(), "uusd".to_string(), |amt| { assert_eq!(amt.unwrap().amount.u128(), pre_swap_amount); }); @@ -942,7 +941,7 @@ mod router { assert_eq!(amt.unwrap().amount.u128(), pre_swap_amount); }); suite.query_balance(other.to_string(), "uluna".to_string(), |amt| { - assert_eq!(amt.unwrap().amount.u128(), pre_swap_amount - 1); + assert_eq!(amt.unwrap().amount.u128(), pre_swap_amount); }); // also check the same for unauthorized receiver suite.query_balance(other.to_string(), "uusd".to_string(), |amt| { @@ -952,30 +951,28 @@ mod router { assert_eq!(amt.unwrap().amount.u128(), pre_swap_amount); }); suite.query_balance(other.to_string(), "uluna".to_string(), |amt| { - assert_eq!(amt.unwrap().amount.u128(), pre_swap_amount - 1); + assert_eq!(amt.unwrap().amount.u128(), pre_swap_amount); }); // also check for contract - // when we add tokens to the contract, we must send a fee of 1_u128 so the contract - // can register the native token suite.query_balance( suite.pool_manager_addr.to_string(), "uusd".to_string(), |amt| { - assert_eq!(amt.unwrap().amount.u128(), liquidity_amount + 1); + assert_eq!(amt.unwrap().amount.u128(), liquidity_amount); }, ); suite.query_balance( suite.pool_manager_addr.to_string(), "uwhale".to_string(), |amt| { - assert_eq!(amt.unwrap().amount.u128(), liquidity_amount + 1); + assert_eq!(amt.unwrap().amount.u128(), liquidity_amount); }, ); suite.query_balance( suite.pool_manager_addr.to_string(), "uluna".to_string(), |amt| { - assert_eq!(amt.unwrap().amount.u128(), 2 * liquidity_amount + 1); + assert_eq!(amt.unwrap().amount.u128(), 2 * liquidity_amount); }, ); @@ -1003,21 +1000,21 @@ mod router { suite.pool_manager_addr.to_string(), "uusd".to_string(), |amt| { - assert_eq!(amt.unwrap().amount.u128(), liquidity_amount - 998 + 1); + assert_eq!(amt.unwrap().amount.u128(), liquidity_amount - 998); }, ); suite.query_balance( suite.pool_manager_addr.to_string(), "uwhale".to_string(), |amt| { - assert_eq!(amt.unwrap().amount.u128(), liquidity_amount + 1000 + 1); + assert_eq!(amt.unwrap().amount.u128(), liquidity_amount + 1000); }, ); suite.query_balance( suite.pool_manager_addr.to_string(), "uluna".to_string(), |amt| { - assert_eq!(amt.unwrap().amount.u128(), 2 * liquidity_amount + 1); + assert_eq!(amt.unwrap().amount.u128(), 2 * liquidity_amount); }, ); } @@ -1025,9 +1022,9 @@ mod router { #[test] fn checks_minimum_receive() { let mut suite = TestingSuite::default_with_balances(vec![ - coin(1_000_000_001u128, "uwhale".to_string()), + coin(1_000_000_000u128, "uwhale".to_string()), coin(1_000_000_000u128, "uluna".to_string()), - coin(1_000_000_001u128, "uusd".to_string()), + coin(1_000_000_000u128, "uusd".to_string()), ]); let creator = suite.creator(); let _other = suite.senders[1].clone(); @@ -1153,10 +1150,9 @@ mod router { }, ]; - // before swap uusd balance = 1_000_000_001 + // before swap uusd balance = 1_000_000_000 // - 2*1_000 pair creation fee // - 1_000_000 liquidity provision - // - 1 for native token creation (for decimal precisions) // = 998_998_000 let pre_swap_amount = 998_998_000; suite.query_balance(creator.to_string(), "uusd".to_string(), |amt| { @@ -2093,7 +2089,7 @@ mod swapping { }, ); - // Verify fee collection by querying the address of the fee_collector and checking its balance + // Verify fee collection by querying the address of the whale lair and checking its balance // Should be 297 uLUNA suite.query_balance( suite.whale_lair_addr.to_string(), diff --git a/contracts/liquidity_hub/pool-manager/src/tests/suite.rs b/contracts/liquidity_hub/pool-manager/src/tests/suite.rs index 3a8c9974..117d402f 100644 --- a/contracts/liquidity_hub/pool-manager/src/tests/suite.rs +++ b/contracts/liquidity_hub/pool-manager/src/tests/suite.rs @@ -509,7 +509,7 @@ impl TestingSuite { result: impl Fn(StdResult), ) -> &mut Self { // Get the LP token from Config - let lp_token_response: PairInfo = self + let lp_token_response: PairInfoResponse = self .app .wrap() .query_wasm_smart( @@ -525,7 +525,7 @@ impl TestingSuite { let balance: Uint128 = self .app .wrap() - .query_balance(sender, lp_token_response.lp_denom) + .query_balance(sender, lp_token_response.pair_info.lp_denom) .unwrap() .amount;