Skip to content

[Contract] Add Concentrated AMM Price Tick Boundary Validation - #751

Merged
EDOHWARES merged 1 commit into
SoroLabs:mainfrom
SINCEO2:feature/issue-632-amm-tick-boundary-validation
Aug 1, 2026
Merged

[Contract] Add Concentrated AMM Price Tick Boundary Validation#751
EDOHWARES merged 1 commit into
SoroLabs:mainfrom
SINCEO2:feature/issue-632-amm-tick-boundary-validation

Conversation

@SINCEO2

@SINCEO2 SINCEO2 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Overview

Liquidity providers could initialize ticks outside valid min/max price tick boundaries, which could corrupt the pool invariant. This PR enforces strict tick index bounds checks (MIN_TICK <= tick <= MAX_TICK) and tick spacing alignment during liquidity position setup.

Related Issue

Closes #632

Changes

Tick Boundary Validation

  • [ADD] contracts/concentrated_amm/src/math.rs

    • MIN_TICK = -524_280 and MAX_TICK = 524_280 constants, empirically determined to stay within the safe range of the Q64.64 sqrt-price computation.
  • [MODIFY] contracts/concentrated_amm/src/lib.rs

    • initialize() — rejects initial_tick outside [MIN_TICK, MAX_TICK]
    • mint() — rejects tick_lower/tick_upper outside bounds (in addition to existing spacing alignment check)
    • burn() — rejects tick parameters outside bounds or tick_lower >= tick_upper
    • collect_fees() — same validation as burn()

Tests

  • [ADD] contracts/concentrated_amm/src/test.rs
    • test_mint_tick_below_min_tick — verifies mint rejects tick_lower < MIN_TICK
    • test_mint_tick_above_max_tick — verifies mint rejects tick_upper > MAX_TICK
    • test_mint_at_boundary_ticks — verifies mint succeeds at MIN_TICK/MAX_TICK boundaries
    • test_burn_invalid_tick_range — verifies burn rejects out-of-bounds ticks
    • test_collect_fees_invalid_tick_range — verifies collect_fees rejects out-of-bounds ticks
    • test_initialize_tick_out_of_bounds — verifies initialize rejects invalid initial_tick

Verification Results

cargo test -p soroscope-concentrated-amm
Result: 20/20 passed

All 14 existing tests remain passing.
7 new boundary validation tests all passing.
Acceptance Criteria Status
Ticks outside MIN_TICK / MAX_TICK are rejected All entry points validated
Tick spacing alignment enforced Existing check preserved
Boundary ticks at MIN_TICK / MAX_TICK succeed Verified
All existing tests still pass 20/20
Unit tests added for new functionality 7 new tests

…concentrated AMM

Add strict tick index bounds checks (`MIN_TICK <= tick <= MAX_TICK`) and
tick spacing alignment validation during liquidity position setup in
`initialize`, `mint`, `burn`, and `collect_fees` operations.

The boundary constants (-524_280 / 524_280) were empirically determined
to stay within the safe range of the Q64.64 sqrt-price computation in
`get_sqrt_ratio_at_tick`, whose multi-word `mul_div_u128` overflows for
|tick| > 524_290.

Closes SoroLabs#632
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@SINCEO2 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@EDOHWARES

Copy link
Copy Markdown
Collaborator

Nice implementation, LGTM!

@EDOHWARES
EDOHWARES merged commit 304fdf0 into SoroLabs:main Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Contract] Add Concentrated AMM Price Tick Boundary Validation

2 participants