IIP-47: Upgrade FLI to use Chainlink oracles

IIP: 47
Title: Upgrade FLI to use Chainlink oracles
Status: Proposed
Author: Noah Citron (@ncitron), Richard Liang (@richard)
Created: 2021-5-28


Simple Summary

Update both ETH2x-FLI and BTC2x-FLI to use Chainlink’s oracles for price feeds rather than Compound’s.

Abstract

The Flexible Leverage Index uses a smart contract called FlexibleLeverageStrategyAdapter to execute rebalances. This contract uses Compound’s Open Price Feed as a source of truth for the prices of ETH, BTC, and USDC. We propose upgrading this contract to use Chainlink for these price feeds.

Motivation

On May 19th, the prices of Ether and Bitcoin experienced a severe crash. Gas prices peaked at around 1800 gwei during the worst of it, and exposed weaknesses in Compound’s oracles. Due to the high gas prices, Keepers stopped updating the oracles. This meant that Compound believed the price of Ether and Bitcoin was significantly higher than what they were actually trading for. The FlexibleLeverageStrategyAdapter uses these oracles to determine suitable slippage values for rebalancing trades on Sushiswap. Since Compound was reporting artificially high prices, the FLI’s Sushiswap trades would fail. During this event, the FLI was never at any risk of liquidation. Additionally, since Compound uses its own oracles for liquidations, it would have not been possible to liquidate our position had prices continued to decline. Had we been using a more lively oracle, there would have been no mismatch between the oracle price and the on-chain price, preventing these issues from happening.

Specification

Overview

The FlexibleLeverageStrategyAdapter is responsible for checking prices and executing rebalances. This change will require deploying two new versions of this contract (one for each FLI product) that uses Chainlink. Additionally, the Index Coop multisig will have to add these contracts to the respective FLI managers and remove the older versions.

Technical Specification

The proposed changes to the contract can be viewed on GitHub here:

Additionally, we will have to execute a total of six transactions from the Index Coop multisig to enable these adapters. A table detailing them is provided below:

To Description
BaseManager (ETH2x) Add adapter to BaseManager
BaseManager (BTC2x) Add adapter to BaseManager
New FLI Strategy Adapter (ETH2x) Whitelist the following keeper bots: 0x1a0e49631D8fF32bfD8141748582e75E7e40e928, 0x0663456cf49b753c8694a17cf8a53e75246cb2ca
New FLI Strategy Adapter (BTC2x) Whitelist the following keeper bots: 0x0663456cf49b753c8694a17cf8a53e75246cb2ca, 0xf303FdE05c53b4545edD8568DAea56Dd10794b7F
BaseManager (ETH2x) Remove old FLI Strategy Adapter (ETH2x)
BaseManager (BTC2x) Remove old FLI Strategy Adapter (BTC2x)
10 Likes

Will support.

I was going to ask about on-chain TWAPs versus Chainlink but found this very interesting article on oracles that pretty much covered my questions. Sharing just in case anyone else is interested.

2 Likes

Will support! Glad to see we are learning from data during abnormal events and increasing FLI’s stability!

1 Like

+1 on this. After learning they FLI was using TWAP oracles to get price data I immediately grew concerned about the implications that this could have and I was also confused as to why chainlink’s oracle system was not the go-to solution. A few months prior to the release or FLI, an issue with the compound oracles had already lost user close to 100 million dollars due to false liquidations.

Whatever the case tho i am happy to see this in the pipeline. I’m happy to help out on the integration of chainlink price feeds within our smart contracts. I’ve worked with chainlink oracles in the past so let me know if i could assist in getting this out the door ASAP. @ncitron @justin

@mrvls_brkfst linked to this already but im adding again as I really think it’s a must read.

2 Likes

Will support, thanks for putting this together. I think this is especially important as the FLI product suite grows.

1 Like

So this only affects the price that we try to sell assets at and not the price we use to value collateral in Compound?
I’m all for Chainlink but if this also changes collateral valuation doesn’t this upon up to more price risk if the prices between the two oracles diverge? Compound oracles could say prices are crashing and we don’t respond because we think it’s all good from Chainlink and then we get liquidated.

2 Likes

That’s a good question. I still don’t know what actually occurred. Did the keeper bots have an issue, or was it the compound oracle? and I’m confused as to how this instance was different than last years?

This event would only occur if compound’s oracle ran into an issue similar to the 1 last year where it wrongly liquidated all those user’s funds. It’s great that FLI could protect against this, but i have to wonder if that what we should aim for? Best case scenario - FLI rebalances according to incorrect data in order to stay above water on compound while negatively impacting the value of ETH-2xFLI.

Is FLI using the same oracle that compound uses for liquidations? Because if it is, then that means compound had all user funds at risk (again) and if that was the case, then I think that migrating to a different platform is the only way to avoid issues related to the compound oracle. Specifically, Aave v2, which uses chainlink natively and is yet to have an issue.

One last question i have is how is the FLI token never at risk for liquidation even in the event that a major price data discrepancy causes compound to wrongly liquidated user funds? How does FLI account for that ?

1 Like

@Kiba This upgrade will change migrate all price feeds to use chainlink, inclusive of those that calculate the leverage ratio. In the past, when the price feeds diverge, it is when the Compound oracles are simply behind the Chainlink oracles, rather than Compound actually reporting bad data.

@tgreco This IIP is addressing a smart-contract level problem, not one with our off-chain keepers. The issue Compound’s oracles had was due to the price feeds not being updated, causing our system to believe that the price was higher than it actually was. Chainlink’s price feeds rarely have this problem which is why we are switching to them.

1 Like

Thanks for the reply! I get the change, but still have a questions.

Hypothetically speaking, wouldn’t this still leave us susceptible to liquidation if compound’s oracle happened to report data?