GnoSwap Docs
  • Welcome
  • Why GnoSwap?
  • Disclaimer
    • General Disclaimer
    • Risk and Security
  • User Guide
    • Getting Started
      • Create an Account
        • Adena Wallet
        • Social Login
      • Connect to GnoSwap
      • Quick Tour
    • Trading
      • Swap Tokens
      • Swap With Details
    • Providing Liquidity
      • Create a Pool
      • Create a Position
      • Remove a Position
      • Reposition
      • Increase Liquidity
      • Decrease Liquidity
    • Staking
      • Stake Positions
      • Claim Rewards
      • Unstake Positions
      • Add Incentives
    • Launchpad
      • Participate in Launches
    • Governance
      • Delegate
      • Undelegate
      • Create a Proposal
      • Vote
  • core concepts
    • AMM
      • Constant Product Market Maker
      • Problem: Lazy Liquidity
      • Concentrated Liquidity
    • Positions
    • Liquidity Mining
    • Fees
    • Governance
    • Launchpad
  • GnoSwap Token
    • What's GNS?
    • Genesis Supply
    • Emission
    • Release Schedule
    • xGNS
  • Contracts
    • Overview
    • Errors
      • Pool
      • Position
      • Router
      • Staker
      • Governance
      • Launchpad
    • Pool
      • pool.gno
      • pool_manager.gno
      • protocol_fee_pool_creation.gno
      • protocol_fee_withdrawal.gno
    • Position
      • position.gno
    • Router
      • exact_in.gno
      • exact_out.gno
      • protocol_fee_swap.gno
    • Staker
      • staker.gno
      • mint_stake.gno
      • protocol_fee_unstaking.gno
      • external_deposit_fee.gno
    • Governance
      • staker.gno
      • proposal.gno
      • vote.gno
      • execute.gno
    • Launchpad
      • launchpad.gno
      • deposit.gno
      • reward.gno
  • References
    • Onboarding Guide
    • Warm-up Periods
    • Leaderboard
    • VWAP
    • FAQ
  • urls
    • GitHub
    • X (Twitter)
    • Discord
    • Medium
Powered by GitBook
On this page

Was this helpful?

  1. core concepts
  2. AMM

Constant Product Market Maker

PreviousAMMNextProblem: Lazy Liquidity

Last updated 9 months ago

Was this helpful?

Liquidity pools on GnoSwap utilize the Constant Product Formula to achieve deterministic pricing of any token in a pool, ensuring that trades can occur at any price within the range of (0, ∞). Liquidity pools maintain a constant k value, which is the product of x and y, representing the quantity of token x and token y in the pool, respectively. This mechanism results in the following formula:

x∗y=kx *y=kx∗y=k

When a trade occurs in a pool, the values of x and y change. Let's assume that ∆ represents the change in the quantity of a token. If a trader sells ∆x amount of token x, the pool receives ∆x amount of token x and pays out ∆y amount of token y (minus the swap fee) as the output in a way that satisfies the equation below:

(x+∆x)(y−∆y)=k(x+∆x)(y-∆y)=k(x+∆x)(y−∆y)=k

Based on the above formula, we can plot a graph that illustrates changes in token reserves in a pool after a trade.

To illustrate this concept, let's consider a scenario where Pool A holds 10 $GNOT and 10,000 $USDC. If Alice wishes to exchange 1 $GNOT for $USDC in Pool A, an equation reflecting the current reserves and ∆x (change in $GNOT) is set up as follows:

Solving for ∆y, we get:

Therefore, we can expect Alice would receive 909.090909... $USDC if she were to sell 1 $GNOT in Pool A.

When adding liquidity to an existing pool, liquidity providers must deposit an amount of token x and token y that is proportional to the current x : y ratio in the pool. Once liquidity is added, the value of k adjusts to the new values of x and y.

As k is proportional to the liquidity of the pool, this structure can be seen as a virtual order book where liquidity is evenly distributed across the entire price range.

k=10∗10,000=100,000=(10+1)(10,000−∆y)k = 10*10,000 = 100,000 = (10+1)(10,000-∆y)k=10∗10,000=100,000=(10+1)(10,000−∆y)
∆y=10,000−(100,000/11)=909.090909...∆y = 10,000-(100,000/11) = 909.090909...∆y=10,000−(100,000/11)=909.090909...