Skip to content

Commit

Permalink
Update commands.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
nick134-bit committed Aug 30, 2024
1 parent db07889 commit c960f14
Showing 1 changed file with 41 additions and 23 deletions.
64 changes: 41 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,53 @@ 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(_) => {
// maybe add a minimum amount to aggregate? to save gas for user
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 c960f14

Please sign in to comment.