From 12627e3c2627214d86372b9c8939e181419dbefc Mon Sep 17 00:00:00 2001 From: Kerber0x Date: Tue, 5 Dec 2023 11:19:24 +0000 Subject: [PATCH] chore: cleanup unused variables --- .../fee_collector/schema/fee_collector.json | 8 ++------ .../fee_collector/schema/raw/execute.json | 8 ++------ .../fee_collector/src/commands.rs | 19 ++++--------------- .../fee_collector/src/contract.rs | 17 ++++++++--------- .../fee_collector/src/queries.rs | 15 ++++++++++++++- .../liquidity_hub/fee_collector/src/state.rs | 2 +- packages/white-whale/src/fee_collector.rs | 9 +++------ 7 files changed, 34 insertions(+), 44 deletions(-) diff --git a/contracts/liquidity_hub/fee_collector/schema/fee_collector.json b/contracts/liquidity_hub/fee_collector/schema/fee_collector.json index c748c1ce..8552cba1 100644 --- a/contracts/liquidity_hub/fee_collector/schema/fee_collector.json +++ b/contracts/liquidity_hub/fee_collector/schema/fee_collector.json @@ -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" @@ -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 diff --git a/contracts/liquidity_hub/fee_collector/schema/raw/execute.json b/contracts/liquidity_hub/fee_collector/schema/raw/execute.json index 4f1dede2..840dd6b2 100644 --- a/contracts/liquidity_hub/fee_collector/schema/raw/execute.json +++ b/contracts/liquidity_hub/fee_collector/schema/raw/execute.json @@ -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" @@ -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 diff --git a/contracts/liquidity_hub/fee_collector/src/commands.rs b/contracts/liquidity_hub/fee_collector/src/commands.rs index 336159a6..379c09da 100644 --- a/contracts/liquidity_hub/fee_collector/src/commands.rs +++ b/contracts/liquidity_hub/fee_collector/src/commands.rs @@ -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; @@ -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 { 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 = Vec::new(); @@ -340,7 +332,6 @@ pub fn forward_fees( info: MessageInfo, env: Env, epoch: Epoch, - forward_fees_as: AssetInfo, ) -> Result { let config = CONFIG.load(deps.storage)?; @@ -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 { @@ -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 { @@ -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") diff --git a/contracts/liquidity_hub/fee_collector/src/contract.rs b/contracts/liquidity_hub/fee_collector/src/contract.rs index 2562a13b..5a0ce7cf 100644 --- a/contracts/liquidity_hub/fee_collector/src/contract.rs +++ b/contracts/liquidity_hub/fee_collector/src/contract.rs @@ -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}; @@ -49,10 +50,12 @@ pub fn instantiate( #[entry_point] pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result { 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 {}) @@ -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), } } diff --git a/contracts/liquidity_hub/fee_collector/src/queries.rs b/contracts/liquidity_hub/fee_collector/src/queries.rs index 5dd6ca21..fb436ee3 100644 --- a/contracts/liquidity_hub/fee_collector/src/queries.rs +++ b/contracts/liquidity_hub/fee_collector/src/queries.rs @@ -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; @@ -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 { + 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) +} diff --git a/contracts/liquidity_hub/fee_collector/src/state.rs b/contracts/liquidity_hub/fee_collector/src/state.rs index 2026a838..cfc6dadf 100644 --- a/contracts/liquidity_hub/fee_collector/src/state.rs +++ b/contracts/liquidity_hub/fee_collector/src/state.rs @@ -6,7 +6,7 @@ use white_whale::pool_network::asset::AssetInfo; pub const CONFIG: Item = Item::new("config"); pub const TMP_ASSET_INFOS: Map = Map::new("tmp_asset_infos"); -pub const TMP_EPOCH: Item<(Epoch, AssetInfo)> = Item::new("tmp_epoch"); +pub const TMP_EPOCH: Item = Item::new("tmp_epoch"); pub fn store_temporal_asset_info(deps: DepsMut, asset_info: AssetInfo) -> StdResult<()> { let key = asset_info diff --git a/packages/white-whale/src/fee_collector.rs b/packages/white-whale/src/fee_collector.rs index 57a80ccb..d4c68196 100644 --- a/packages/white-whale/src/fee_collector.rs +++ b/packages/white-whale/src/fee_collector.rs @@ -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,