Assessment reports>Magma Finance>Design>Component: CLMM

Component: CLMM

Description

The core module of the CLMM is composed of pool.move, tick.move, and position.move. The pool module manages the configuration of pool, including fee and reward rates, and handles all trading operations. Users can swap between two tokens and open or close positions for token pairs with liquidity to earn trading fees. The tick module manages the liquidity of each tick and calculates each fee for the tick range. The position module manages the position of each user and updates each fee and reward.

Invariants

  • Users receive an AddLiquidityReceipt when they add liquidity to a position. This struct contains the amount of tokens to pay and cannot be dropped, ensuring that the user has to pay the correct amount of tokens.

  • The CLMM pool should have correct swap logic for the token pair, ensuring that the liquidity in ticks, amount of tokens, and fees are correct.

  • Ticks and liquidity should be updated correctly when the swap amount exceeds the current tick's liquidity (crossing ticks).

  • The access control for the pool should be correct, ensuring that only signers with proper capabilities can extract fees from the pool, update fee rates, and pause the pool.

  • The pool's total liquidity and individual tick liquidity must remain accurate at all times, particularly during tick crossing.

  • Each tick is managed by the pool module, ensuring that the tick is not manipulated by other modules.

  • Each position is managed by the pool module, ensuring that the position is not manipulated by other modules.

Test coverage

Cases covered

  • Open and close position

  • Add and remove liquidity

  • Stake and unstake position

Cases not covered

  • Swap between two tokens

  • Swap crossing the tick

  • Collect rewards and fees

Zellic © 2025Back to top ↑