MU07 - Chainlink Price Feed integration

Hi folks,

this post outlines the transactions integrating chainlink rate feeds into the SortedOracles contract. As with previous proposals, the Celo community will have the opportunity to verify these transactions. In preparation for the upcoming CGP, we have done the following:

  • Tested the proposal Alfajores
  • Simulated the proposal on a fork of Celo Mainnet, in addition to running tests against the fork

The transactions that will be in the upcoming CGP will be broken down into the following sections, noted here with transaction indices in brackets:

  1. Whitelisting and configuring of Chainlink Relayers in SortedOracles (0-3)
  2. Configuring rate feed alias in SortedOracles(3-4)

Before we dive deep into each section and transaction, we recommend you have celocli set up to follow along. For the tech savvy, you can find everything we are describing here in our deployment tooling repository as code. For verifying that addresses included in the proposal are correct, please refer to the Appendix at the bottom for some handy tips.

1. Whitelisting and configuring of Chainlink Relayers in SortedOracles

With this Mento Upgrade a Chainlink Relayer contract is introduced.

The ChainlinkRelayer relays rate feed data from a Chainlink price feed or an aggregation of multiple Chainlink price feeds to the SortedOracles contract.
This contract can aggregate multiple Chainlink price feeds to provide derived rate feeds to the rest of the protocol. This is needed because it is more efficient for Oracle providers to report FX rates against the dollar and crypto-asset rates against the dollar, instead of all possible combinations.
For example, for the Philippine Peso, Chainlink reports PHP/USD,
but does not report CELO/PHP which is required to pay for gas in a PHP stable token. But using both PHP/USD and CELO/USD, one can create a path:
CELO/USD * inverse(PHP/USD) = CELO/PHP.

A separate ChainlinkRelayer instance will be deployed for each rate feed.

TX#0 - whitelist CELO/PHP Relayer in SortedOracles - addOracle()

  • Verify the SortedOracleProxy address
  • Verify the Rate Feed Identifier
    • address(uint160(uint256(keccak256(abi.encodePacked("relayed:CELOPHP”)))));
  • Verify the ChainlinkRelayer address

TX#1 - configure CELO/PHP token report expiry time in SortedOracles - setTokenReportExpiry()

  • Verify the SortedOracleProxy address
  • Verify the Rate Feed Identifier
    • address(uint160(uint256(keccak256(abi.encodePacked("relayed:CELOPHP”)))));
  • Verify Report Expiry Seconds
    • 5 minutes = 300

TX#2 - whitelist PHP/USD Relayer in SortedOracles - addOracle()

  • Verify the SortedOracleProxy address
  • Verify the Rate Feed Identifier
    • address(uint160(uint256(keccak256(abi.encodePacked("relayed:PHPUSD”)))));
  • Verify the ChainlinkRelayer address

TX#3 - configure PHP/USD token report expiry time in SortedOracles-setTokenReportExpiry()

  • Verify the SortedOracleProxy address
  • Verify the Rate Feed Identifier
    • address(uint160(uint256(keccak256(abi.encodePacked("relayed:PHPUSD”)))));
  • Verify Report Expiry Seconds
    • 5 minutes = 300

2. Configuring rate feed alias in SortedOracles

Sorted Oracles has a new feature of equivalent tokens. When a token has an
equivalent token configured, SortedOracles will return the equivalent token’s median
rate when asked. This was used for gas payments with USDC, by setting USDC’s equivalent
token to be cUSD. But this also allows us to remove this duality between rate feeds that
are tokens, and rate feeds derived from identifiers.
In the context of PUSO it means that we can report to the rateFeed defined by the
canonical id: relayed:CELOPHP, and then have address(PUSO) point to that for
gas payments.

TX#4 - configure equivalent token for CELO/PHP rate in SortedOracles-setEquivalentToken()

  • Verify the SortedOracleProxy address
  • Verify the token address
    • StableTokenPHPProxy address
  • Verify the Rate Feed Identifier
    • address(uint160(uint256(keccak256(abi.encodePacked("relayed:CELOPHP”)))));

Appendix: Verifying an address

Verifying that an address in the CGP is correct requires a few different strategies depending on what that address is (see the mento docs for some additional information). Here are common situations:

  • Is it a rate feed identifier like: address(uint160(keccack256(”relayed:CELOPHP”)))
    • Use Keccak-256 Online 2 to compute the keccak
    • Take the last 40 characters (20 bytes) of the keccak and compare with the value
  • Is it a Mento contract?
  • Is it a Core Celo contract?
    • Yes:
      • It’s probably GoldToken or FeeCurrencyWhiteList which can be both verified in the Celo Registry
5 Likes