Skip to content

Commit

Permalink
fix(pool-manager): send protocol fees via FillRewards
Browse files Browse the repository at this point in the history
Rather than a BankMsg::Send.
  • Loading branch information
kaimen-sano committed Apr 20, 2024
1 parent b5495f1 commit e180cc6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
15 changes: 9 additions & 6 deletions contracts/liquidity_hub/pool-manager/src/router/commands.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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()],
}));
}

Expand Down
17 changes: 11 additions & 6 deletions contracts/liquidity_hub/pool-manager/src/swap/commands.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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()],
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit e180cc6

Please sign in to comment.