Skip to content

Commit

Permalink
feat: add threshold for aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
nick134-bit committed Aug 30, 2024
1 parent db07889 commit 995ea3c
Showing 1 changed file with 45 additions and 23 deletions.
68 changes: 45 additions & 23 deletions contracts/liquidity_hub/fee_collector/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<router::SimulateSwapOperationsResponse> =
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
Expand Down

0 comments on commit 995ea3c

Please sign in to comment.