Skip to content

Commit

Permalink
chore: cleanup unused variables
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x committed Dec 5, 2023
1 parent 5dbc3e7 commit 12627e3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"additionalProperties": false
},
{
"description": "Swaps the assets (fees) sitting in the fee collector into the given [AssetInfo] if possible. A [SwapRoute] should be available at the router to be able to make the swaps.",
"description": "Swaps the assets (fees) sitting in the fee collector into the distribution asset set by the fee collector. A [SwapRoute] should be available at the router to be able to make the swaps.",
"type": "object",
"required": [
"aggregate_fees"
Expand All @@ -44,15 +44,11 @@
"aggregate_fees": {
"type": "object",
"required": [
"aggregate_fees_for",
"asset_info"
"aggregate_fees_for"
],
"properties": {
"aggregate_fees_for": {
"$ref": "#/definitions/FeesFor"
},
"asset_info": {
"$ref": "#/definitions/AssetInfo"
}
},
"additionalProperties": false
Expand Down
8 changes: 2 additions & 6 deletions contracts/liquidity_hub/fee_collector/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"additionalProperties": false
},
{
"description": "Swaps the assets (fees) sitting in the fee collector into the given [AssetInfo] if possible. A [SwapRoute] should be available at the router to be able to make the swaps.",
"description": "Swaps the assets (fees) sitting in the fee collector into the distribution asset set by the fee collector. A [SwapRoute] should be available at the router to be able to make the swaps.",
"type": "object",
"required": [
"aggregate_fees"
Expand All @@ -34,15 +34,11 @@
"aggregate_fees": {
"type": "object",
"required": [
"aggregate_fees_for",
"asset_info"
"aggregate_fees_for"
],
"properties": {
"aggregate_fees_for": {
"$ref": "#/definitions/FeesFor"
},
"asset_info": {
"$ref": "#/definitions/AssetInfo"
}
},
"additionalProperties": false
Expand Down
19 changes: 4 additions & 15 deletions contracts/liquidity_hub/fee_collector/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use white_whale::pool_network::router::SwapOperation;
use white_whale::vault_network::vault_factory::VaultsResponse;

use crate::contract::{FEES_AGGREGATION_REPLY_ID, FEES_COLLECTION_REPLY_ID};
use crate::queries::query_distribution_asset;
use crate::state::{read_temporal_asset_infos, store_temporal_asset_info, CONFIG, TMP_EPOCH};
use crate::ContractError;

Expand Down Expand Up @@ -171,21 +172,12 @@ pub fn update_config(
pub fn aggregate_fees(
mut deps: DepsMut,
env: Env,
mut ask_asset_info: AssetInfo,
aggregate_fees_for: FeesFor,
) -> Result<Response, ContractError> {
let config: Config = CONFIG.load(deps.storage)?;

// query fee collector
let fee_distributor_config: white_whale::fee_distributor::Config =
deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: config.fee_distributor.to_string(),
msg: to_binary(&white_whale::fee_distributor::QueryMsg::Config {})?,
}))?;

// This was done in order to make this function permissionless so anyone can trigger the fee aggregation
// The signature for `ExecuteMsg::AggregateFees` was kept the same to avoid migrating multiple contracts
ask_asset_info = fee_distributor_config.distribution_asset;
// query fee collector to get the distribution asset
let ask_asset_info = query_distribution_asset(deps.as_ref())?;

let mut aggregate_fees_messages: Vec<CosmosMsg> = Vec::new();

Expand Down Expand Up @@ -340,7 +332,6 @@ pub fn forward_fees(
info: MessageInfo,
env: Env,
epoch: Epoch,
forward_fees_as: AssetInfo,
) -> Result<Response, ContractError> {
let config = CONFIG.load(deps.storage)?;

Expand Down Expand Up @@ -397,7 +388,6 @@ pub fn forward_fees(
contract_addr: env.contract.address.to_string(),
funds: vec![],
msg: to_binary(&ExecuteMsg::AggregateFees {
asset_info: forward_fees_as.clone(),
aggregate_fees_for: FeesFor::Factory {
factory_addr: config.vault_factory.to_string(),
factory_type: FactoryType::Vault {
Expand All @@ -417,7 +407,6 @@ pub fn forward_fees(
contract_addr: env.contract.address.to_string(),
funds: vec![],
msg: to_binary(&ExecuteMsg::AggregateFees {
asset_info: forward_fees_as.clone(),
aggregate_fees_for: FeesFor::Factory {
factory_addr: config.pool_factory.to_string(),
factory_type: FactoryType::Pool {
Expand All @@ -437,7 +426,7 @@ pub fn forward_fees(
messages.push(pools_fee_aggregation_msg);

// saving the epoch and the asset info to forward the fees as in temp storage
TMP_EPOCH.save(deps.storage, &(epoch, forward_fees_as))?;
TMP_EPOCH.save(deps.storage, &epoch)?;

Ok(Response::new()
.add_attribute("action", "forward_fees")
Expand Down
17 changes: 8 additions & 9 deletions contracts/liquidity_hub/fee_collector/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use white_whale::fee_collector::{
use white_whale::pool_network::asset::{Asset, AssetInfo, ToCoins};

use crate::error::ContractError;
use crate::queries::query_distribution_asset;
use crate::state::{CONFIG, TMP_EPOCH};
use crate::ContractError::MigrateInvalidVersion;
use crate::{commands, migrations, queries};
Expand Down Expand Up @@ -49,10 +50,12 @@ pub fn instantiate(
#[entry_point]
pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractError> {
if msg.id == FEES_AGGREGATION_REPLY_ID {
let (mut epoch, asset_info) = TMP_EPOCH
let mut epoch = TMP_EPOCH
.may_load(deps.storage)?
.ok_or(ContractError::CannotReadEpoch {})?;

let asset_info = query_distribution_asset(deps.as_ref())?;

let token_balance: Uint128 = match asset_info.clone() {
AssetInfo::Token { .. } => {
return Err(ContractError::InvalidContractsFeeAggregation {})
Expand Down Expand Up @@ -125,14 +128,10 @@ pub fn execute(
pool_factory,
vault_factory,
),
ExecuteMsg::AggregateFees {
asset_info,
aggregate_fees_for,
} => commands::aggregate_fees(deps, env, asset_info, aggregate_fees_for),
ExecuteMsg::ForwardFees {
epoch,
forward_fees_as,
} => commands::forward_fees(deps, info, env, epoch, forward_fees_as),
ExecuteMsg::AggregateFees { aggregate_fees_for } => {
commands::aggregate_fees(deps, env, aggregate_fees_for)
}
ExecuteMsg::ForwardFees { epoch, .. } => commands::forward_fees(deps, info, env, epoch),
}
}

Expand Down
15 changes: 14 additions & 1 deletion contracts/liquidity_hub/fee_collector/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use cosmwasm_std::{to_binary, Addr, Deps, QueryRequest, StdResult, WasmQuery};

use white_whale::fee_collector::{Config, ContractType, FactoryType, FeesFor};
use white_whale::pool_network;
use white_whale::pool_network::asset::Asset;
use white_whale::pool_network::asset::{Asset, AssetInfo};
use white_whale::pool_network::factory::PairsResponse;
use white_whale::pool_network::pair::ProtocolFeesResponse as ProtocolPairFeesResponse;
use white_whale::vault_network::vault::ProtocolFeesResponse as ProtocolVaultFeesResponse;
Expand Down Expand Up @@ -143,3 +143,16 @@ fn query_fees_for_factory(

Ok(fees)
}

/// Queries the fee collector to get the distribution asset
pub(crate) fn query_distribution_asset(deps: Deps) -> StdResult<AssetInfo> {
let config: Config = CONFIG.load(deps.storage)?;

let fee_distributor_config: white_whale::fee_distributor::Config =
deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: config.fee_distributor.to_string(),
msg: to_binary(&white_whale::fee_distributor::QueryMsg::Config {})?,
}))?;

Ok(fee_distributor_config.distribution_asset)
}
2 changes: 1 addition & 1 deletion contracts/liquidity_hub/fee_collector/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use white_whale::pool_network::asset::AssetInfo;

pub const CONFIG: Item<Config> = Item::new("config");
pub const TMP_ASSET_INFOS: Map<String, AssetInfo> = Map::new("tmp_asset_infos");
pub const TMP_EPOCH: Item<(Epoch, AssetInfo)> = Item::new("tmp_epoch");
pub const TMP_EPOCH: Item<Epoch> = Item::new("tmp_epoch");

pub fn store_temporal_asset_info(deps: DepsMut, asset_info: AssetInfo) -> StdResult<()> {
let key = asset_info
Expand Down
9 changes: 3 additions & 6 deletions packages/white-whale/src/fee_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ pub struct InstantiateMsg {}
pub enum ExecuteMsg {
/// Collects protocol fees based on the configuration indicated by [FeesFor]
CollectFees { collect_fees_for: FeesFor },
/// Swaps the assets (fees) sitting in the fee collector into the given [AssetInfo] if possible.
/// A [SwapRoute] should be available at the router to be able to make the swaps.
AggregateFees {
asset_info: AssetInfo,
aggregate_fees_for: FeesFor,
},
/// Swaps the assets (fees) sitting in the fee collector into the distribution asset set by the
/// fee collector. A [SwapRoute] should be available at the router to be able to make the swaps.
AggregateFees { aggregate_fees_for: FeesFor },
/// Forward fees to the fee distributor. This will collect and aggregate the fees, to send them back to the fee distributor.
ForwardFees {
epoch: Epoch,
Expand Down

0 comments on commit 12627e3

Please sign in to comment.