Trustless Prices using Uniswap

The Trustless Team
June 16, 2022


The Trustless Currency Protocol (TCP) allows someone to lock Eth collateral and borrow Hue debt. For TCP to determine if a position does not have enough collateral to cover the debt, it needs a price between Eth and Hue. 


The most common way lending protocols get prices is from a trusted price provider that brings prices from off-chain to on-chain. This introduces trust. Suppose the trusted price provider gives an incorrect price. In that case, they may be able to steal people's collateral by liquidating positions that are well collateralized. However, this approach has an even more significant flaw: it relies on bringing prices for on-chain assets from off-chain. Why get an on-chain price from trusted actors off-chain? Because it's easier than building in a completely decentralized way.

Uniswap to the rescue. 

Uniswap allows people to trade between two on-chain assets. The relative balances of the two on-chain assets in a Uniswap pool determine their relative price! Voilá! We have an on-chain price.

Simply using the balance between the two assets as the on-chain price is risky. Anyone can change that relative balance by trading through the pool!

TWAPs

Time Weighted Average Prices, or TWAPs, protect from an attacker manipulating a price. A protocol gets a TWAP by averaging the price over a period. The attacker must keep the price in an incorrect state for an extended period, losing money to arbitrageurs as they do.

Conclusion

Trustless uses fully decentralized, on-chain prices. Trustless uses Uniswap to get the price of two assets on-chain without adding trust assumptions or centralization. Trustless takes a TWAP instead of an instant price to make it too expensive for an attacker to profit from an attack.


Next: Uniswap V3 Prices >