✔️Oracle
Overview
The Bank contract allows for the use of custom Price Providers (also known as Oracles) to provide price information for collateral tokens in different markets. This feature enables flexible and accurate price feeds tailored to specific assets and market conditions.
PriceProvider Interface
Custom Price Providers must implement the IPriceProvider
interface:
Key Functions
isPriceProvider()
: Validates that the contract is a legitimate Price Provider.getCollateralTokenPrice()
: Returns the current price of the collateral token denominated in the loan token.
Creating a Custom Price Provider
To create a custom Price Provider:
Implement the
IPriceProvider
interface.Define your price fetching logic in the
getCollateralTokenPrice()
function.Ensure
isPriceProvider()
returnstrue
.
Example:
Using a Custom Price Provider
Deploy your custom Price Provider contract.
When creating a new market, include the address of your Price Provider in the
marketConfigs.oracle
field:
Important Notes
Unlike IRMs, Price Providers do not need to be registered with the Bank contract before use.
Ensure your Price Provider returns prices in the correct denomination (collateral token price in terms of the loan token).
The Bank contract will call the Price Provider's
getCollateralTokenPrice()
function during various operations, including liquidations, so make sure it's gas-efficient and always returns a valid price.For production use, consider implementing additional security measures such as:
Price update frequency limits
Multiple data sources for price information
Deviation checks to prevent sudden large price changes
Test your Price Provider thoroughly before deployment to avoid potential issues in live markets.
In the example above, the price is set manually. In a real-world scenario, you would typically fetch this data from reliable external sources.
Security Considerations
Ensure that only authorized entities can update the price in your Price Provider.
Consider implementing circuit breakers or pause mechanisms for emergency situations.
Regularly audit and monitor your Price Provider to ensure it's functioning correctly.
By following these guidelines, you can create and integrate custom Price Providers to provide accurate and reliable price data for various assets within the Bank ecosystem. This flexibility allows for the creation of markets with different collateral types while ensuring proper valuation for lending and liquidation purposes.
Last updated