VWAP

GnoSwap leverages the Volume-Weighted Average Price (VWAP) algorithm to provide accurate and temper-proof prices of tokens. The VWAP is calculated as the sum of the product of price and volume for each trade within the specified time frame, divided by the total volume:

VWAP={i=1n(Pricei×Volumei)i=1nVolumeiif i=1nVolumei>0LastActivePriceif i=1nVolumei=0VWAP = \begin{cases} \frac{\sum_{i=1}^{n}{(Price_i \times Volume_i)}}{\sum_{i=1}^{n}{Volume_i}} & \text{if } \sum_{i=1}^{n}{Volume_i} > 0 \\ LastActivePrice & \text{if } \sum_{i=1}^{n}{Volume_i} = 0 \end{cases}

Implementing VWAP to token prices comes with multiple advantages.

  • High Accuracy: Weighting the exchange rate by volume traded allows VWAP to accurately reflect the prices at which the token was actually traded, deriving a price that closely tracks market behavior.

  • Price Manipulation Resistance: Manipulating a VWAP-based price is highly difficult, as it would require a market-wide manipulation with tremendous volume at unfavorable rates against liquid assets, leaving the attacker vulnerable to arbitrage.

  • Wide Coverage: VWAP is highly scalable, providing prices to any token that is paired with reputable assets without reliance on third-party Oracle integrations.

VWAP is a secure, proven pricing algorithm adopted by leading data providers including ChainLink and CoinGecko. To further prevent price manipulations, GnoSwap only accounts for trades against reputable, verified assets with sufficient market liquidity. The liveliness of prices is ensured by setting the time frame to only include fresh, recent data.

VWAP Calculation Example

Assuming there were 3 trades in the past 10 minutes, let's calculate the price of token $AAA (a sample token).

  • Trade #1 | 100 $AAA → 10 $USDC

    • Volume: 100 $AAA

    • Applied Price: 1 $AAA = 0.1 $USDC

  • Trade #2 | 500 $AAA → 1000 $BBB

    • Volume: 500 $AAA

    • Applied Price: 1 $AAA = 2 $BBB

  • Trade #3 | 200 $AAA → 15 $USDC

    • Volume: 200 $AAA

    • Applied Price: 1 $AAA = 0.075 $USDC

VWAP Price of $AAA = (100*0.1+200*0.075)/(100+200) = $0.08333...

** Trade #2 was excluded as the trade was executed against an invalid asset.

Disclaimer

The VWAP-based prices are provided for informational purposes only. The prices may differ from the actual rate at which the tokens are swapped. You should not solely rely on VWAP prices when swapping. GnoSwap will not be liable for any losses that occur from discrepancies between VWAP and the actual market rates.

Last updated