Implementing a Price Oracle for Crypto Loans
In the previous chapter, you learned that the decentralized crypto loan smart contacts rely heavily on token prices and that the prices help maintain the balance between liquidity for collaterals and borrowed assets. Inaccurate price information may lead to the loss of assets, affecting liquidity and resulting in inadequate funds for borrowing and withdrawal. Even worse, the attackers can drain all the funds by manipulating the price utilized by the crypto loan system. Building a reliable and manipulation-resistant price oracle is essential for a crypto loan system.
A price oracle is a source of truth for token prices that can be accessed by smart contracts running on the blockchain. The price oracle we will build in this chapter supports all the tokens that have the WETH liquidity pools (e.g., FOO/WETH) in the DEX we built in Part 2 of this book.
By reading this chapter, you will learn the following:
- How price manipulation...