Skip to content

Commit

Permalink
chore: simulate aggregation swap
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x authored Aug 30, 2024
2 parents db07889 + af61ede commit 18bd015
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,
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 18bd015

Please sign in to comment.