From 995ea3c37d3bdd3c309a4a205fe46ec31291ba67 Mon Sep 17 00:00:00 2001 From: nick134 <76399455+nick134-bit@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:55:51 +0200 Subject: [PATCH 1/2] feat: add threshold for aggregation --- .../fee_collector/src/commands.rs | 68 ++++++++++++------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/contracts/liquidity_hub/fee_collector/src/commands.rs b/contracts/liquidity_hub/fee_collector/src/commands.rs index 620b74eb4..c94bbee91 100644 --- a/contracts/liquidity_hub/fee_collector/src/commands.rs +++ b/contracts/liquidity_hub/fee_collector/src/commands.rs @@ -273,35 +273,57 @@ pub fn aggregate_fees( Ok(operations) => { let execute_swap_operations_msg = to_json_binary(&router::ExecuteMsg::ExecuteSwapOperations { - operations, + operations: operations.clone(), minimum_receive: None, to: None, max_spread: Some(Decimal::percent(50u64)), })?; - - match offer_asset_info.clone() { - AssetInfo::Token { contract_addr } => { - aggregate_fees_messages.push(CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr, - funds: vec![], - msg: to_json_binary(&Cw20ExecuteMsg::Send { - contract: config.pool_router.to_string(), - amount: balance, - msg: execute_swap_operations_msg, - })?, - })); + let operations_simulation: StdResult = + deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { + contract_addr: config.pool_router.to_string(), + msg: to_json_binary(&router::QueryMsg::SimulateSwapOperations { + offer_amount: balance.clone(), + operations: operations.clone(), + })?, + })); + + match operations_simulation { + Ok(_) => { + if balance < MINIMUM_AGGREGABLE_BALANCE { + continue; + } + match offer_asset_info.clone() { + AssetInfo::Token { contract_addr } => { + aggregate_fees_messages.push(CosmosMsg::Wasm( + WasmMsg::Execute { + contract_addr, + funds: vec![], + msg: to_json_binary(&Cw20ExecuteMsg::Send { + contract: config.pool_router.to_string(), + amount: balance, + msg: execute_swap_operations_msg, + })?, + }, + )); + } + AssetInfo::NativeToken { denom } => { + aggregate_fees_messages.push(CosmosMsg::Wasm( + WasmMsg::Execute { + contract_addr: config.pool_router.to_string(), + funds: vec![Coin { + denom, + amount: balance, + }], + msg: execute_swap_operations_msg, + }, + )); + } + }; } - AssetInfo::NativeToken { denom } => { - aggregate_fees_messages.push(CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: config.pool_router.to_string(), - funds: vec![Coin { - denom, - amount: balance, - }], - msg: execute_swap_operations_msg, - })); + Err(_) => { + continue; } - }; + } } Err(_) => { // if there is no swap route, skip swap and keep the asset in contract From af61ede76778c0af8f8aa34f447d4c1a6e074da5 Mon Sep 17 00:00:00 2001 From: nick134 <76399455+nick134-bit@users.noreply.github.com> Date: Fri, 30 Aug 2024 17:21:34 +0200 Subject: [PATCH 2/2] chore: remove clone --- contracts/liquidity_hub/fee_collector/src/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/liquidity_hub/fee_collector/src/commands.rs b/contracts/liquidity_hub/fee_collector/src/commands.rs index c94bbee91..0a1dd632c 100644 --- a/contracts/liquidity_hub/fee_collector/src/commands.rs +++ b/contracts/liquidity_hub/fee_collector/src/commands.rs @@ -282,7 +282,7 @@ pub fn aggregate_fees( deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: config.pool_router.to_string(), msg: to_json_binary(&router::QueryMsg::SimulateSwapOperations { - offer_amount: balance.clone(), + offer_amount: balance, operations: operations.clone(), })?, }));