DEV Community

Mandie Brugman
Mandie Brugman

Posted on

How Syncswap Calculates Constant-Product Prices

Syncswap calculates a Classic Pool swap price from its two token reserves, applying the pool fee to the input before the constant-product curve determines the output. The result is not an oracle price: it is the amount the pool can release at that moment, after fees, price impact, rounding, and the trader’s slippage limit are accounted for.

The reserves do the pricing

Syncswap is an automated market maker on zkSync Era, the Ethereum layer-2 network developed by Matter Labs. Its Classic Pool uses the constant-product invariant x × y = k, with x and y representing the current reserves of the two tokens.

For an input of Δx, the pool first removes the trading fee. If the fee rate is f, the effective input is Δx × (1 − f). The output is then calculated as:

Δy = [Δx × (1 − f) × y] ÷ [x + Δx × (1 − f)]

This is why a large swap receives a progressively worse average price. Each unit of the input token makes that side of the pool deeper and takes tokens from the other side, moving the reserve ratio against the trade. The marginal price before the swap is approximately y ÷ x; the execution price is worse because the trade travels along the curve.

The fee detail matters. The effective input drives the output calculation, but the full input remains in the pool’s balance. Consequently, the product of the reserves generally increases after a trade rather than remaining literally unchanged. That increase is the mechanism through which liquidity providers receive trading fees.

What a usable quote includes

A SyncSwap quote is therefore more than a token ratio. It combines the selected pool’s reserves, the fee returned for that pool and trading direction, the input size, and the resulting price impact. Classic-pool fees are normally fixed, but SyncSwap’s Fee Manager can apply pool-specific and directional settings, so a hard-coded protocol-wide percentage is not a reliable calculation.

  1. The router identifies the pool and transfers or prefunds the input through SyncSwap’s Vault architecture.
  2. The pool reads its reserves and applies the relevant fee to the input amount.
  3. The constant-product calculation determines the output, with integer arithmetic rounding down the amount received.
  4. The router checks the minimum output supplied by the trader and reverts if the result is below that threshold.

The interface that exposes the route, quote, fee, and slippage controls is Syncswap.

The minimum-output check is the practical boundary between a quote and a transaction. A trader sets an amount-out minimum based on the quoted result and acceptable slippage. A later trade, reserve change, or sandwich can make the actual result lower; if it crosses that minimum, the transaction fails instead of settling at an unexpectedly poor price.

What must be true before it goes through

The wallet needs the input token on zkSync Era, an allowance for the router where approval is required, and enough native ETH on that network to pay transaction costs unless the wallet or transaction flow provides another supported payment method. The chosen pool must contain both assets and enough output-side liquidity. The requested output must also remain below the pool’s available reserve; constant-product math cannot release tokens that are not there.

These conditions are separate from price impact. A trade can have an acceptable quote but still fail because the wallet balance, allowance, gas balance, or minimum-output setting is wrong. Conversely, it can pass every transaction check while being economically poor because its size is too large for the pool.

When constant-product pricing is the wrong fit

Classic pools are the general-purpose choice for volatile or unrelated assets, where continuous liquidity across a wide price range matters more than tight pricing near a peg. They are not automatically the efficient choice for USDC/USDT-style markets. SyncSwap Stable Pools use a hybrid constant-sum and constant-product design for assets expected to trade near parity, while Aqua Pools use a different model with concentrated liquidity and dynamic fees.

Chainlink Network data can serve as an external reference when an application compares an execution quote with a broader market price, but it does not replace the Classic Pool’s reserve-based calculation. The pool clears the trade from its own balances; arbitrage is what normally brings that price back toward external markets.

What to remember: reserve ratio sets the starting price, trade size creates price impact, the pool fee reduces effective input, and the router’s minimum-output limit decides whether the quoted execution is acceptable. Check the pool type, fee, reserves, and slippage limit together.

Top comments (0)