THORChain keeps exchange rates accurate using its CLP design and external arbitrageurs. It does this without fragile external sources like oracles and weighted averages.
This document first explains how THORChain maintains the prices for a single pool. Then it explains how THORChain sets the exchange rate of 2 external assets.
This pool has 16,000 MATIC in it and 1,000 RUNE. The price of MATIC on external exchanges is $0.02. The price of RUNE on external exchanges is $0.32. Right now, the ratio of MATIC to RUNE in the pool is 16:1, and accurately reflects how the world values the two assets.
But someone swaps some MATIC for RUNE. They swap in 2,000 MATIC. Here are those numbers plugged into the swap formula—
This swapper takes 98.76 RUNE out of the pool. Now the pool has 18,000 MATIC and 901.24 RUNE. This is a ratio of roughly 20:1. But the ratio according to the wider market is still 16:1. This means that swapping MATIC for RUNE on THORChain right now will not be economically rational. Swapping now would yield less RUNE than if swapping on an external exchange. But arbitrageurs will quickly fix the issue with their bots.
Arbitrage bots fix the situation by swapping RUNE for MATIC. When they do this they get MATIC at a lower cost, and can sell it on external markets for a profit. As the amount of RUNE in the pool increases and MATIC decreases, restoring the ratio to 16:1. This reflects the externally-accepted price for the 2 assets.
The previous section explains how THORChain gets prices for a single pool. A pool which involves an external asset and RUNE. But how does THORChain get the prices of pairs that don't involve RUNE? Particularly ones tied to fiat value, like USD stablecoins?
RUNE is the rope which binds all liquidity pools together. It lets THORChain know what MATIC is worth in USD because it passes the value of both via RUNE. This will become clearer in the example below.
The following example works out the value of MATIC in USD. It looks at the ratio of assets in the MATIC:RUNE and TUSDB:RUNE pools.
The MATIC:RUNE pool has 16,000 MATIC and 1,000 RUNE. The TUSDB:RUNE has 3,300 TUSDB and 10,000 RUNE. Based on this information alone, THORChain can know what 1 MATIC is worth in TUSDB. Here's the formula to work out the MATIC/USD price—
Here's that formula with the actual numbers from the pool input—
This information is available within the THORChain network. It doesn't rely on direct external price sources. It works through arbitrageurs and simple market forces.
Here is the formula for working out the exchange rate between any 2 external assets—
THORChain's reference price model differs to other decentralised exchanges. Other exchanges use external oracles and weighted averages to set their prices. This has proven problematic as these external sources become attack vectors.
These external sources are problematic because people can manipulate them. Technical and ecosystem factors can also affect them. For example, the network underlying oracles can become congested and affect their performance. Weighted averages are better than taking direct price references. But large actors can still manipulate them.
This creates issues of trust and reliability for the exchanges in question.