Chainlink Oracle Integration Discussion

FEI is pegged to $1 USD and needs to have the most robust and accurate access to the value of its peg. This post aims to kick off a discussion about transitioning our primary oracle to Chainlink ETH/USD from the existing Uniswap ETH-USDC TWAP.

At present, Fei Protocol utilizes the UniV2 ETH-USDC TWAP oracle as the reference mechanism. This is a reliable and effective deployment, but with an ever-evolving DeFi ecosystem, it would be worthwhile to evaluate available options and consider upgrading to a more robust approach. As part of an in-process audit, we wanted to help diversify the idiosyncratic risk of our current oracle by introducing support for Chainlink oracles, and the ability for including a backup oracle. For increased manipulation resistance and faster response to sharp market moves, in addition to improving on some drawbacks of the current TWAP, we propose using Chainlink as the primary oracle.

The current implementation requires UniV2 swaps on the FEI token every 10 minutes to keep an up-to-date oracle value. Fei Labs has been manually maintaining the oracle outside of these automatic updates. This is not a scalable solution, and subject to failure if our relayer runs out of gas or encounters an error. This periodic update also increases user gas costs for those transactions where the update is triggered.

The most important reason to consider switching oracles is security. The current oracle relies on USDC, which makes USDC risk a central point of failure for Fei protocol, and goes against the protocol’s efforts to remain as decentralized as possible. Another consideration is that, as liquidity drops from UniV2 and transitions to UniV3, it could subject the existing oracle to cheaper price manipulation.

The design of robust oracles is a challenging undertaking, as many high-profile oracle attacks have shown in the last year. Ensuring that our oracle is resistant to manipulation is a technical challenge we as a community need to address.

Chainlink has a robust oracle network, which leverages data from both on- and off-chain sources. Many other Ethereum projects collectively support the Chainlink ETH/USD oracle, including Synthetix, Aave, Set Protocol, Loopring, and many more. Chainlink serves as a sustainable service for the Ethereum ecosystem, and has become the de facto oracle provider across DeFi.

We recognize the decentralization trade-off due to the fact that Chainlink has an admin multisig, which determines which oracles are included in the aggregation. For this reason, we propose to include Uniswap TWAPs as a fallback oracle that can be triggered by the Guardian. This distributes risks between the two sources, while simultaneously aligning us more closely with the Chainlink ecosystem.

We want to hear from the Tribe with regard to moving in this direction, so we can act accordingly.

7 Likes

I heard that Uni may become an oracle token. Fully decentralized. UNI should become an oracle token - Proposal Discussion - Uniswap Governance

Great post! It also seems that by changing to Chainlink Oracle would help with integrations with other protocols.

I was wondering how projects that are studying integrations with FEI would see that option? It is not clear to me if this trigger could turn integrations more difficult as the other project would need to be prepared to this scenario.

This would be quite interesting and useful to explore if and when it is implemented. My first thoughts on that proposal are that it would have a longer lag time and be more useful for lending type integrations rather than stablecoin use cases.

Other projects would be responsible for managing their own oracle strategy, for example Compound is considering upgrading to Chainlink Oracle Infrastructure: Chainlink Proposal - Ideas - Compound Community Forum but subject to an Anchoring to a Uniswap TWAP.

In our case we are proposing to use Chainlink for Fei specific use cases and if there is some kind of issue with the feed the oracle would fall back automatically to a twap or some other oracle.

1 Like

true but it would be decentralized. I like chainlink a lot in any case.

Snapshot is live here:

https://snapshot.fei.money/#/fei.eth/proposal/QmNm6gt7vQwa2HKqHNB6vRASrrNjpirDj1mx3hvmS54ghJ

I voted in favor, notably there is no current support for backup oracles until the new audit is complete.

1 Like

I have been running some comparisons between Fei’s current TWAP ETH/USDC oracle and Chainlink’s ETH/USD oracle.

TLDR: A variety of data quality metrics suggest Chainlink’s oracle is superior to Fei’s current TWAP oracle

The Data

I am looking at the range of blocks starting shortly after Genesis and ending shortly before the present day. This is about 365,000 blocks.


(The blue line is wider just so that both lines are visible. The blue line is not actually more variable over time. It’s just that other plotting schemes like dotted lines don’t work well with 365k datapoints)

This graph shows the two oracles overlaid, and there’s a clear similarity between them. How do we know which one is better? There’s not a well-defined “ground truth” to measure which oracle is more accurate, but we can run some summary statistics that measure other aspects of oracle quality.

Mean number of blocks between updates:

  • FEI TWAP: 69.14 blocks
  • Chainlink: 46.44 blocks

Mean time between updates:

  • FEI TWAP: 922.76 seconds
  • Chainlink: 619.49 seconds

Mean update size:

  • FEI TWAP: 0.44%
  • Chainlink 0.35%

The Chainlink oracle updates more frequently and also has smaller value gaps between updates, both of which are desirable qualities in an oracle.

Deviation Analysis

Fully zoomed out, the oracles appear to have nearly identical values. But how close are they? This is a plot of the deviation between these two oracles over time, both subtractively and divisively:

And this is the distribution of deviations (note the log scale on the y axis):

Most of the time, the deviations between the oracles are small. But occasionally they are very large. Let’s see what the the raw data looks like during some periods of maximum deviation:

Example 1:

Example 2:

Example 3:

These plots are very concerning because Fei’s TWAP oracle is consistently outdated in time compared to the Chainlink oracle. This is a separate issue from merely having a lower sampling rate. The TWAP is also delayed in time, “shifted to the right” in the graphs above. When the price of ETH goes up, Fei’s TWAP takes longer to go up. When the price of ETH goes down, Fei’s TWAP takes longer to go down.

This means that Fei’s protocol mechanisms are always trading with stale information, allowing traders to make advantaged trades against the protocol that are more similar to front-running than arbitrage.

Cross-correlation Analysis

To quantify the delay between the oracles we can use a statistical metric called cross-correlation.

Cross-correlation is a measure of the correlation between two signals taken at different time delays. If two signals are measuring the same underlying thing and neither signal is delayed in time, then the cross-correlation will show a peak at 0. If one signal is a delayed version of the other, the cross-correlation will show a peak offset some distance from 0 corresponding to the size of the delay.

Instead of peaking at 0, the cross-correlation of the TWAP and Chainlink oracles shows a peak around 45 blocks. This indicates something like “the TWAP oracle is 45 blocks delayed compared to Chainlink oracle”. 45 blocks is roughly 10 minutes, which is even higher than would be expected for a 10 minute TWAP oracle compared to an instantaneous source of ground truth. This is further evidence that the TWAP is consistently delayed compared to Chainlink.

Conclusion

Taken together these results paint a much prettier picture of the Chainlink oracle compared to the TWAP. Upgrading Fei’s oracle to Chainlink should allow Fei’s various mechanisms to operate more effectively by using more up-to-date information about current market conditions.

8 Likes