✔️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:

solidityCopyinterface IPriceProvider {
    function isPriceProvider() external view returns (bool);
    function getCollateralTokenPrice() external view returns (uint256 price);
}

Key Functions

  1. isPriceProvider(): Validates that the contract is a legitimate Price Provider.

  2. 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:

  1. Implement the IPriceProvider interface.

  2. Define your price fetching logic in the getCollateralTokenPrice() function.

  3. Ensure isPriceProvider() returns true.

Example:

solidityCopycontract MyCustomPriceProvider is IPriceProvider {
    uint256 public price;
    address public owner;

    constructor() {
        owner = msg.sender;
    }

    function isPriceProvider() external pure returns (bool) {
        return true;
    }

    function getCollateralTokenPrice() external view returns (uint256) {
        return price;
    }

    function setCollateralTokenPrice(uint256 _price) external {
        require(msg.sender == owner, "Only owner can set price");
        price = _price;
    }
}

Using a Custom Price Provider

  1. Deploy your custom Price Provider contract.

  2. When creating a new market, include the address of your Price Provider in the marketConfigs.oracle field:

    solidityCopyfunction createMarket(MarketConfigs memory marketConfigs) external payable returns (uint256);

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