Skip to content

Commit

Permalink
feat(smart-contracts): add a query for simulate swap operations
Browse files Browse the repository at this point in the history
  • Loading branch information
nseguias committed Apr 23, 2024
1 parent 4abb16e commit 61f9235
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
18 changes: 9 additions & 9 deletions contracts/liquidity_hub/pool-manager/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::error::ContractError;
use crate::helpers::simulate_swap_operations;
use crate::queries::{get_swap_route, get_swap_route_creator, get_swap_routes};
use crate::router::commands::{add_swap_routes, remove_swap_routes};
use crate::state::{Config, MANAGER_CONFIG, PAIRS, PAIR_COUNTER};
Expand Down Expand Up @@ -214,15 +215,14 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result<Binary, ContractErro
offer_asset,
pair_identifier,
)?)?),
// QueryMsg::SimulateSwapOperations {
// offer_amount,
// operations,
// } => Ok(to_binary(&queries::simulate_swap_operations(
// deps,
// env,
// offer_amount,
// operations,
// )?)?),
QueryMsg::SimulateSwapOperations {
offer_amount,
operations,
} => Ok(to_json_binary(&simulate_swap_operations(

Check warning on line 221 in contracts/liquidity_hub/pool-manager/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/liquidity_hub/pool-manager/src/contract.rs#L219-L221

Added lines #L219 - L221 were not covered by tests
deps,
offer_amount,
operations,
)?)?),
// QueryMsg::ReverseSimulateSwapOperations {
// ask_amount,
// operations,
Expand Down
2 changes: 2 additions & 0 deletions contracts/liquidity_hub/pool-manager/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,8 @@ pub fn assert_admin(deps: Deps, env: &Env, sender: &Addr) -> Result<(), Contract
Ok(())

Check warning on line 599 in contracts/liquidity_hub/pool-manager/src/helpers.rs

View check run for this annotation

Codecov / codecov/patch

contracts/liquidity_hub/pool-manager/src/helpers.rs#L599

Added line #L599 was not covered by tests
}

/// This function iterates over the swap operations, simulates each swap
/// to get the final amount after all the swaps.
pub fn simulate_swap_operations(
deps: Deps,
offer_amount: Uint128,
Expand Down
10 changes: 5 additions & 5 deletions packages/white-whale-std/src/pool_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ pub enum QueryMsg {
SwapRoutes {},

// /// Simulates swap operations.
// #[returns(SimulateSwapOperationsResponse)]
// SimulateSwapOperations {
// offer_amount: Uint128,
// operations: Vec<SwapOperation>,
// },
#[returns(SimulateSwapOperationsResponse)]
SimulateSwapOperations {
offer_amount: Uint128,
operations: Vec<SwapOperation>,
},
// /// Simulates a reverse swap operations, i.e. given the ask asset, how much of the offer asset
// /// is needed to perform the swap.
// #[returns(SimulateSwapOperationsResponse)]
Expand Down

0 comments on commit 61f9235

Please sign in to comment.