From e180cc69a3d9284453baf1099e1b8d2b967f6f0c Mon Sep 17 00:00:00 2001 From: kaimen-sano Date: Sat, 20 Apr 2024 13:12:47 +1200 Subject: [PATCH] fix(pool-manager): send protocol fees via FillRewards Rather than a BankMsg::Send. --- .../pool-manager/src/router/commands.rs | 15 +++++++++------ .../pool-manager/src/swap/commands.rs | 17 +++++++++++------ .../pool-manager/src/tests/integration_tests.rs | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/contracts/liquidity_hub/pool-manager/src/router/commands.rs b/contracts/liquidity_hub/pool-manager/src/router/commands.rs index dab3a893..26771f76 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; +use white_whale_std::whale_lair; use crate::{state::MANAGER_CONFIG, swap::perform_swap::perform_swap, ContractError}; @@ -112,12 +114,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 ccadf96f..4adfa37b 100644 --- a/contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs +++ b/contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs @@ -1743,7 +1743,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(),