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

Send protocol fees from pool manager via FillRewards rather than BankMsg #334

Merged
merged 1 commit into from
Apr 22, 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
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a function in the ww-std package (whale_lair.rs) that contains a function that builds this message for you. We can refactor this in the future.

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
Loading