Trading Mechanism

Trading in a Magma Finance ALMM pool offers a unique experience due to the bin-based architecture, which can lead to better execution prices for traders.

The Swap Process

When you initiate a swap in an ALMM pool, the protocol first looks at the active bin—the price bin that contains the current market price.

  1. Executing within the Active Bin: Your trade will first be routed to the liquidity available in this active bin. All swaps that are filled by the liquidity in this bin are executed at the single, fixed price of the bin. This means there is zero slippage for this portion of your trade.

  2. Crossing to the Next Bin: If your trade is large enough to consume all of the available liquidity of one asset in the active bin, the price will then move to the next adjacent bin. This bin becomes the new active bin, and the remainder of your trade will be filled using the liquidity available at this new price.

Price Impact and Slippage

  • Price Impact: This is the effect that your trade has on the market price. In an ALMM, price impact occurs when your trade is large enough to move the price from one bin to the next.

  • Slippage: Slippage is the difference between the expected price of a trade and the price at which it is actually executed. Because trades within a single bin have a fixed price, there is no slippage within a bin. Slippage in an ALMM only occurs when the price moves across multiple bins during your trade.

For most trades, the ALMM's bin architecture results in lower slippage compared to traditional AMMs, as the price doesn't change with every small trade. It only moves when a bin's liquidity is fully utilized.

  • Bin-Based Liquidity:

    • Liquidity is divided into bins, each corresponding to a specific price point .

    • The bin step (e.g., 0.01% or 1 basis point) determines the price increment between bins.

    • Each bin holds reserves of two tokens (X and Y), but only the active bin (where the current market price lies) contains both tokens. Bins to the left (lower prices) hold only token Y, and bins to the right (higher prices) hold only token X.

  • Active Bin:

    • The active bin is where trading happens. It contains both tokens and supports swaps at its fixed price.

    • Trades within the active bin follow a constant sum formula (X + Y = k), meaning the price remains constant until one token is depleted. This contrasts with the constant product formula (x * y = k) in traditional AMMs.

Current price for 1 wUSDT is 1 USDC
  • Trades consume liquidity within the active bin at its set price. If demand exceeds the bin’s reserves (e.g., swapping 10 SUI when only 8 are available), the system shifts to the next bin (e.g., $3.10), executing the remainder at that price.

  • This stepwise progression mimics a limit order book but retains AMM decentralization and composability.

Last updated