Problem
calculate_swap_output in liquidity.rs computes output from the constant-product formula, but swaps execute without a caller-supplied minimum. Between quote and execution, reserves can move (front-running/MEV or concurrent swaps), so a trader can receive far less than expected with no protection.
Requirements
- Add a
min_amount_out: i128 parameter to the swap entrypoint; revert with a new SlippageExceeded error when amount_out < min_amount_out.
- Add an optional
deadline (ledger timestamp) check; revert DeadlineExpired when env.ledger().timestamp() > deadline.
- Keep all math on the checked-arithmetic path already used in
liquidity.rs.
Acceptance Criteria
- Swap succeeds at/above the minimum, reverts below it, and reverts past the deadline. Covered by tests.
Files
contracts/open-market/src/liquidity.rs
contracts/open-market/src/market.rs
contracts/open-market/src/errors.rs
contracts/open-market/tests/liquidity_tests.rs
Problem
calculate_swap_outputinliquidity.rscomputes output from the constant-product formula, but swaps execute without a caller-supplied minimum. Between quote and execution, reserves can move (front-running/MEV or concurrent swaps), so a trader can receive far less than expected with no protection.Requirements
min_amount_out: i128parameter to the swap entrypoint; revert with a newSlippageExceedederror whenamount_out < min_amount_out.deadline(ledger timestamp) check; revertDeadlineExpiredwhenenv.ledger().timestamp() > deadline.liquidity.rs.Acceptance Criteria
Files
contracts/open-market/src/liquidity.rscontracts/open-market/src/market.rscontracts/open-market/src/errors.rscontracts/open-market/tests/liquidity_tests.rs