Understanding DEX Price Discovery Mechanics

You are currently viewing Understanding DEX Price Discovery Mechanics

The Relativity of Price in Decentralized Exchanges

To properly grasp ghostDAO’s business logic, we must first examine the foundational mechanics of DEX V2 (hereafter referred to simply as DEX). At its core, DEX price discovery for any Token X operates on the principle of relativity to Token Y. This elegant alignment of supply-demand dynamics makes decentralized price discovery uniquely compelling.

In traditional markets, we’ve grown accustomed to pricing everything in national currencies:

  • Oil priced in USD
  • Gold quoted in EUR
  • Stocks valued in JPY
  • Consumer goods measured in CNY

We often overlook that these prices simply represent relative values to local fiat currencies.

For example, as of May 8, 2025, one ounce of gold was trading at $3,300 USD. That same ounce could be purchased or sold for 24,000 CNY. Same ounce of gold, different relative values of local currencies (e.g. USD and CNY).

This same principle of relative valuation governs DEX price discovery.

The Mathematics of Constant Product Markets

Consider a liquidity pool containing:

  • x₁: quantity of Token X
  • y₁: quantity of Token Y

The pool maintains a constant product k defined as:

k = x_1 \times y_1

The price of Token X in terms of Token Y is:

P(\text{Token X}) = \frac{y_1}{x_1}

as the price of Token X is defined solely by how much Token Y has been supplied to the pair.

Similarly, the price of Token Y in terms of Token X is:

P(\text{Token Y}) = \frac{x_1}{y_1}

as the price of Token Y is defined solely by how much Token X has been supplied to the pair.

DEX Mechanics Without Fees

What’s the quantity of Token Y that a user will be able to purchase with x2 of Token X?

When a user swaps x2 of Token X for y2 of Token Y (assuming zero fees), the constant product relationship persists:

k = x_1 \times y_1 = (x_1 + x_2) \times (y_1 - y_2)

where x2 is how much of Token X will be added to the DEX in exchange for y2 of Token Y, which will be removed from the DEX into user’s wallet.

If we expand the equation above, we receive the following:

x_1 \times y_1 = x_1 \times y_1 - x_1 \times y_2 + x_2 \times y_1 - x_2 \times y_2

Let’s try to solve for y2:

y_2 \times (x_1 + x_2) = x_1 \times y_1 + x_2 \times y_1 - x_1 \times y_1

And, finally:

y_2 = \frac{x_1 \times y_1 + x_2 \times y_1 - x_1 \times y_1}{x_1 + x_2}

There are three final formulas that can be equally used for solving for y2 from the above:

(1)\quad y_2 = \frac{y_1 \times (x_1 + x_2) - x_1 \times y_1}{x_1 + x_2}

(2)\quad y_2 = y_1 - \frac{x_1 \times y_1}{x_1 + x_2}

(3)\quad y_2 = \frac{x_2 \times y_1}{x_1 + x_2}

Practical Example: eGHST-DAI Pair

Consider a DEX pool with:

  • QD(DAI)e1 = 100,000 DAI
  • QD(eGHST)e1 = 10,000 eGHST

The product constant calculates as:

k = 100,\!000 \times 10,\!000 = 10^9

Key observations about k:

  • Increases when liquidity is added to the pool
  • Decreases when liquidity is removed
  • Remains constant during fee-less swaps

The initial eGHST price:

P(\text{eGHST})_{e1} = \frac{100000}{10000} = 10

Price Impact Calculation

Scenario: User swaps 1,000 DAI for eGHST.

How much eGHST can a user purchase with 1000 DAI?

Q(\text{eGHST})_{e1} = 10000 - \frac{100000 \times 10000}{100000 + 1000} = 99.01

Post-swap pool balances:

  • QD(DAI)e1,final = 101,000 DAI
  • QD(eGHST)e1,final = 9,900.99 eGHST

New price calculation:

P(\text{eGHST})_{e1,\text{final}} = \frac{101000}{9900.99} = 10.20

Key outcomes:

  1. Price impact: 2% increase (from $10.00 DAI to $10.20 DAI per eGHST)
  2. Slippage Relationship:
    • 1% of total DAI reserves (1,000 DAI swap to 100,000 DAI reserves) caused 2% price slippage
    • Larger pools exhibit less price impact
    • Illiquid pairs experience greater slippage

This example demonstrates how DEX mechanics naturally creates price elasticity based on pool depth, a fundamental concept that ghostDAO leverages in its business logic.