# MU07 - Chainlink Price Feed integration

**URL:** <https://forum.celo.org/t/mu07-chainlink-price-feed-integration/8850>\
**Category:** Governance Proposals\
**Tags:** mento, technical\
**Created:** [August 27, 2024, 9:45am UTC](https://forum.celo.org/t/mu07-chainlink-price-feed-integration/8850 "2024-08-27T09:45:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![philbow61](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.celo.org/philbow61/32/9308_2.png) [@philbow61](https://forum.celo.org/u/philbow61)\
**Post date:** [August 27, 2024, 9:45am UTC](https://forum.celo.org/t/mu07-chainlink-price-feed-integration/8850/1 "2024-08-27T09:45:35Z")

</div>

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](https://github.com/mento-protocol/mento-deployment/blob/main/script/upgrades/eXOF/eXOF.sol) 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](https://docs.mento.org/mento/protocol-concepts/governance/verification) 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](https://emn178.github.io/online-tools/keccak_256.html) to compute the keccak
  - Take the last 40 characters (20 bytes) of the keccak and compare with the value

- Is it a Mento contract?
  - Did it exist prior to MU01? (e.g. SortedOracles, StableToken, etc)
    - Yes:
      - It’s probably a proxy so you can check the addresses in the docs: [Addresses - Mento Protocol 1](https://docs.mento.org/mento/developers/deployments/addresses)
      - You can also query the Registry contract on the target network

    - No:
      - New contracts can also be checked in the docs: [Addresses - Mento Protocol 1](https://docs.mento.org/mento/developers/deployments/addresses)
      - Bytecode verification can be done by following the instructions here: [Verification | Mento Protocol](https://docs.mento.org/mento/developers/deployments/verification)

- Is it a Core Celo contract?
  - Yes:
    - It’s probably **GoldToken** or **FeeCurrencyWhiteList** which can be both verified in the Celo Registry
