Assessment reports>CetusProtocol>Design>Component: cetus_clmm/pool.move

Component: cetus_clmm/pool.move

Description

The pool module is the core of the Cetus CLMM protocol. It manages token trading pairs and implements CLMMs that enhance capital efficiency beyond automated market makers (AMMs). This module adjusts liquidity and token swaps while tracking liquidity positions, price ranges, fee, and reward.

Each pool manages token trading pairs, monitors current price and liquidity, and executes key operations including position management, liquidity adjustments, token swaps, flash loans, and fee collection. This module provides comprehensive API for interaction and connects with tick, position, and rewarder components.

Invariants

  • The current price must be in valid bounds defined by min_sqrt_price() and max_sqrt_price().

  • The price after swap must respect the provided price limit.

  • Pool liquidity must reflect correctly the sum of all currently active liquidity positions.

  • Fee and reward-growth accumulators must accurately track the global amount of fee and reward generated.

  • Global fee growth and reward-growth value must be distributed to positions based on liquidity contribution.

  • During a swap, all crossed ticks must be updated with the latest fee and reward-accumulator values.

  • When a tick is crossed, liquidity must be added or removed from the pool's active liquidity.

  • The protocol fee and partner-referral fee must be collected according to respective rates.

  • Flash loans and flash swaps must be repaid with appropriate fees before the transaction end.

  • Pool must not operate when paused — enforced by the is_pause flag.

  • Position operations (open, add liquidity, remove liquidity, close) must maintain consistency between position and the pool's state.

Test coverage

Cases covered

  • Pool initialization with parameters

  • Opening and closing positions

  • Adding and removing liquidity (both fixed liquidity and fixed coin amounts)

  • Swapping with various parameters (a2b/b2a, by_amount_in, price limits)

  • Fee calculation and collection for positions

  • Reward calculation and collection

  • Protocol-fee collection

  • Flash loans and flash swaps

  • Partner-fee handling

  • Pool pausing and unpausing

  • Edge cases such as swapping to price limits and tick boundaries

  • Liquidity distribution across multiple positions

  • Swap verification with complex tick setups

  • Tick-crossing boundary handling

  • Fee distribution across multiple positions

  • Flash-loan execution and repayment

  • Partner-based swap with referral-fee handling

  • Multiposition fee collection

  • Full range liquidity positions

  • Swap calculations with different fee tiers

Zellic © 2025Back to top ↑