TL;DR
Introduce to the community a solution to remove price synchronicity problems on price-correlated assets listed on Aave, for example, USD stablecoins, or LSTs (liquid staking tokens).
To be initially applied to price WBTC and wstETH on the upcoming Aave v3 Ethereum.
https://github.com/bgd-labs/cl-synchronicity-price-adapter
Context. How assets are priced in the Aave liquidity protocol?
As generally known, since Aave v1, the assets price provider for the Aave protocol is the Chainlink network.
This Chainlink-based pricing mechanism works as follows:
- Chainlink provides open and independent price feeds, of the shape ASSET/REFERENCE_CURRENCY, for example, AAVE/ETH or MKR/USD. Each price feed has different configurations associated, like:
- Deviation percentage. Indicating on which price movement the feed should be updated. E.g. a deviation of 2% on AAVE/ETH means that if the price of AAVE in ETH changes more than 2% (up/down) from the previous value, the feed should be updated to the new price.
- Heartbeat. Time duration, indicating which is the maximum time the feed can be without an update, even if not required by deviation percentage. E.g. AAVE/ETH has a 24h Heartbeat, so at least there must be 1 price update every 24h, even if the price of AAVE/ETH remains within the 2% margin.
- The Aave liquidity protocol has a smart contract component called
AaveOracle
, which acts as an aggregator of the aforementioned Chainlink independent feeds. This aggregator links the address of an asset listed on Aave, to a specific Chainlink feed, that will return the price for the asset in a reference price. - Every Aave pool (v2 Ethereum, v3 Polygon, v3 Avalanche, etc) points to only one
AaveOracle
contract and has only one reference currency for all the assets listed. For example, Aave v2 Ethereum has ETH as the reference currency, while all current v3 instances have USD.
This architecture has been working pretty well, but same as with everything, there is always room for improvement.
The problem. Artificial price de-sync
Some of the assets listed on Aave are quite price-correlated with each other, like the so-called USD-pegged stablecoins.
Their pricing mechanism works exactly the same as with any other asset: for each stablecoin, there is a price feed, and all of them share the reference currency of the Aave pool, ETH on Aave v2 Ethereum, USD on Aave v3. So on the AaveOracle
, DAI is “connected” to a DAI/ETH price feed; USDC to USDC/ETH; USDT to USDT/ETH, and so on.
Now, let’s imagine a user of Aave has a position composed of DAI collateral and USDC borrowings. At some point, the ETH price in USD suddenly increases (meaning the price of USD in ETH goes down). With price feeds updating independently, something that could happen is that the DAI/ETH feed updates first, and USDC/ETH feed updates after. If the update is aggressive enough, this could potentially mean that for an instant (time between both updates), the value of DAI in ETH is significantly lower than the value of USDC in ETH, which could cause a liquidation event!
But in reality, the price of USDC and DAI has been almost the same all the time in USD terms; so it seems the mechanism can be improved.
Practical Example
- Alice has a position with 100 USDC as collateral and 70 DAI as borrowings, with a liquidation threshold of 70% on USDC.
- Both USDC and DAI are priced exactly at $1, but given that their oracle has ETH reference, each unit is actually 0.000625 ETH (ETH at $1600).
- In ETH terms, Alice has a position worth 0.0625 ETH and a debt worth 0.04375 ETH.
Her Health Factor is exactly 1. - ETH price increases to $1700. Given the architecture of Chainlink and the working of the Ethereum network, the USDC price feed is updated slightly before the DAI one. This means the USDC update transaction comes earlier in the block than DAI’s.
- Once the USDC update transaction is executed, USDC will have a price of 0.000588
ETH and Alice’s collateral will be worth 0.0588 ETH. DAI price feed’s update was not executed yet, so the value of Alice borrowings is still 0.04375.
0.04375 (value of borrowings) / 0.0588 (value of collateral) = ~0.74 (74%), which means the position is above the 70% liquidation threshold, equal to below 1 Health Factor.
If a liquidator is fast enough to introduce a transaction before DAI price’s feed updates, Alice will be liquidated.
So, change the oracle reference to USD?
One initial solution could seem to be just “swap” all the price feeds on the AaveOracle from asset/ETH to asset/USD.
However, by doing this, even if stablecoins will not have any more edge cases, they appear for other assets, for example, WETH and stETH, that will suffer exactly the same, whenever there is a sudden price change on ETH/USD.
In addition, historically there has been quite an important price correlation between multiple assets listed on Aave v2 Ethereum and ETH itself, so changing the reference to USD would only “move” the problem, without solving it.
Our solution
To solve the previously explained problem, we want to introduce what we call the Chainlink Synchronicity Price Adapter.
The idea is simple, instead of using asset/ETH price feeds for stablecoins on Aave v2 Ethereum, the price feed will be a custom smart contract, still connected to Chainlink feeds under the hood, but calculating the price as follows:
By doing this, the “artificial volatility” created by the de-synchronization between asset/ETH feeds, gets removed, as now, prices change when either:
- ETH/USD updates; but being common to all assets, this makes the update fully synchronized for all of them.
- asset/USD updates; but not creating any problem, as by general rule, the price changes of USD-stablecoins in USD are really light.
It is important to highlight that this approach can (and should) be applied, apart from stablecoins on Aave v2 Ethereum, or wstETH on Aave v3 Ethereum, to other “groups” on assets on the same or different pool/network.
Candidates would be WBTC and BTC.b on Aave v3 Avalanche or WMATIC/stMATIC/MATICx on Aave v3 Polygon.
This will make it technically possible to tune up both the base and eMode risk parameters of those groups of assets.
Security procedures applied
Apart from the testing included in the repository of the project, both Certora and SigmaPrime have reviewed the adapter smart contracts.
The reports can be found HERE
Additionally, before moving to production these price adapters, we will be doing back-testing comparing with non-synced price feeds, whenever they are available.
Next steps
The initial targets for this adapter will be the pricing of WBTC and wstETH on Aave v3 Ethereum. Afterward, we will create a proposal for the same strategy on all USD-pegged assets listed on Aave v2 Ethereum.
We will also proceed with extra proposals in other groups of assets.
Props to the Aave community member @pakim249, who created an early discussion around the topic, which finally led to this development.