Skip to content

Commit

Permalink
add before_swap_check validation in reverse swap and swap_exact_amoun…
Browse files Browse the repository at this point in the history
…t_out
  • Loading branch information
epanchee committed Jan 3, 2024
1 parent 19bfecb commit caaafa9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contracts/pair_concentrated/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ pub fn query_reverse_simulation(

let pools = query_pools(deps.querier, &env.contract.address, &config, &precisions)?;

before_swap_check(&pools, ask_asset_dec.amount)?;

let (ask_ind, _) = pools
.iter()
.find_position(|asset| asset.info == ask_asset.info)
Expand Down
10 changes: 10 additions & 0 deletions contracts/pair_concentrated/src/sudo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ fn swap_exact_amount_out(
.pair_info
.query_pools(&deps.querier, &env.contract.address)?;

// Before swap checks
ensure!(
!token_out.amount.is_zero(),
StdError::generic_err("Token out amount must not be zero")
);
ensure!(
pools.iter().all(|a| !a.amount.is_zero()),
StdError::generic_err("One of the pools is empty")
);

let ask_ind = pools
.iter()
.position(|asset| asset.info == ask_asset.info)
Expand Down

0 comments on commit caaafa9

Please sign in to comment.