Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TOB-SANDCLOCK-6] use Liquity USD/ETH oracle (chainlink + tellor backup) #101

Merged
merged 4 commits into from
Jul 25, 2023

Conversation

coolhill
Copy link
Contributor

@coolhill coolhill commented Jul 21, 2023

Description

The LUSD/ETH price feed used by the scLiquity vault is an intermediate contract that calls depricated latestAnswer methods on upstream chainlink oracles. It also connects to upgradable proxie pricefeeds with unclear owners.

Solution

Instead of the intermediate contract use the Liquity USD->ETH oracle which uses Chainlink USD->ETH as a primary and Tellor USD->ETH as a backup and has extra safety checks. Disregard LUSD peg and estimate ETH holdings at LUSD/USD 1:1.

Side-effects

This means we estimate the ETH holdings to be worth as many LUSD as it is worth USD (as if LUSD is pegged 1:1), disregarding current market value/peg of LUSD. If LUSD trades at less than USD we would overestimate the total assets and users could redeem at a slight advantage until the keeper sells the ETH for LUSD. If the LUSD trades above the dollar then we would under-report the total holdings until the keeper rebalances into LUSD.

Since ETH is to be traded into LUSD asap and ETH total would only be a small temporary portion of the total holdings this is an OK compromise. Depending on the Liquity USD->ETH oracle is preferable to the previous intermediate contract that connects to upgradable proxies with unknown owners.

Previous Liquity oracle bug

Because of the complexity in the dual-oracle Liquity design there was a bug in the Tellor fallback functionality. However it has been fixed. Using the same oracle for scLUSD as is used for LUSD makes sense and a bug in LUSD or its oracle cannot be avoided anyways, since we fundamentally depend on LUSD as our underlying.

Rundown on different oracles

2023-07-25-190302_1279x763_scrot

src/liquity/scLiquity.sol Fixed Show fixed Hide fixed
src/lib/Constants.sol Outdated Show resolved Hide resolved
src/liquity/scLiquity.sol Outdated Show resolved Hide resolved
src/liquity/scLiquity.sol Outdated Show resolved Hide resolved
src/lib/Constants.sol Outdated Show resolved Hide resolved
src/liquity/scLiquity.sol Outdated Show resolved Hide resolved
src/lib/Constants.sol Outdated Show resolved Hide resolved
src/liquity/scLiquity.sol Outdated Show resolved Hide resolved
src/liquity/scLiquity.sol Outdated Show resolved Hide resolved
@@ -23,7 +23,7 @@
uint256 public totalProfit;

IStabilityPool public stabilityPool = IStabilityPool(C.LIQUITY_STABILITY_POOL);
IPriceFeed public lusd2eth = IPriceFeed(C.CHAINLINK_LUSD_ETH_PRICE_FEED);
IPriceFeed public usd2eth = IPriceFeed(C.LIQUITY_USD_ETH_PRICE_FEED);

Check warning

Code scanning / Slither

State variables that could be declared immutable

scLiquity.usd2eth (src/liquity/scLiquity.sol#26) should be immutable
@coolhill coolhill requested review from 0xrin1 and fyang1024 July 24, 2023 12:52
@coolhill coolhill merged commit 69ec9cb into main Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants