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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/interfaces/liquity/IPriceFeed.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity >0.8.10;

interface IPriceFeed {
// --- Events ---
event LastGoodPriceUpdated(uint256 _lastGoodPrice);

// --- Function ---
function fetchPrice() external returns (uint256);

function lastGoodPrice() external view returns (uint256);
}
4 changes: 2 additions & 2 deletions src/lib/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ library Constants {
address public constant CHAINLINK_USDC_ETH_PRICE_FEED = 0x986b5E1e1755e3C2440e960477f25201B0a8bbD4;
// Chainlink pricefeed (stETH -> ETH)
address public constant CHAINLINK_STETH_ETH_PRICE_FEED = 0x86392dC19c0b719886221c78AB11eb8Cf5c52812;
// Chainlink pricefeed (stETH -> USD)
address public constant CHAINLINK_LUSD_ETH_PRICE_FEED = 0x60c0b047133f696334a2b7f68af0b49d2F3D4F72;
// Liquity pricefeed (USD -> ETH) with Chainlink as primary and Tellor as backup.
address public constant LIQUITY_USD_ETH_PRICE_FEED = 0x4c517D4e2C851CA76d7eC94B805269Df0f2201De;

// address of the Balancer vault contract
address public constant BALANCER_VAULT = 0xBA12222222228d8Ba445958a75a0704d566BF2C8;
Expand Down
8 changes: 4 additions & 4 deletions src/liquity/scLiquity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol";

import {Constants as C} from "../lib/Constants.sol";
import {IStabilityPool} from "../interfaces/liquity/IStabilityPool.sol";
import {IPriceFeed} from "../interfaces/chainlink/IPriceFeed.sol";
import {IPriceFeed} from "../interfaces/liquity/IPriceFeed.sol";
import {sc4626} from "../sc4626.sol";

contract scLiquity is sc4626 {
Expand All @@ -23,7 +23,7 @@ contract scLiquity is sc4626 {
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
ERC20 public lqty = ERC20(C.LIQUITY_LQTY_TOKEN);

// 0x swap router
Expand All @@ -46,8 +46,8 @@ contract scLiquity is sc4626 {
function totalAssets() public view override returns (uint256 assets) {
uint256 ethBalance = address(this).balance + stabilityPool.getDepositorETHGain(address(this));

// add eth balance in lusd terms using chainlink oracle
assets = ethBalance.mulWadDown(uint256(lusd2eth.latestAnswer()));
// add eth balance in lusd terms using liquity oracle
assets = ethBalance.mulWadDown(uint256(usd2eth.lastGoodPrice()));

// add float
assets += asset.balanceOf(address(this));
Expand Down
16 changes: 10 additions & 6 deletions test/mocks/liquity/MockPriceFeed.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity >0.8.10;

import {IPriceFeed} from "../../../src/interfaces/chainlink/IPriceFeed.sol";
import {IPriceFeed} from "../../../src/interfaces/liquity/IPriceFeed.sol";

contract MockPriceFeed is IPriceFeed {
string public constant NAME = "PriceFeed";

int256 public lastGoodPrice;
uint256 public price;

function latestAnswer() external view override returns (int256) {
return lastGoodPrice;
function lastGoodPrice() external view override returns (uint256) {
return price;
}

function setPrice(uint256 price) external {
lastGoodPrice = int256(price);
function fetchPrice() external view override returns (uint256) {
return price;
}

function setPrice(uint256 _price) external {
price = _price;
}
}
10 changes: 5 additions & 5 deletions test/scLiquity.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract MockVault is Vault {
address _xrouter
) Vault(_admin, _keeper, _lusd) {
stabilityPool = _stabilityPool;
lusd2eth = _priceFeed;
usd2eth = _priceFeed;
lqty = _lqty;
xrouter = _xrouter;
asset.approve(address(stabilityPool), type(uint256).max);
Expand All @@ -37,17 +37,17 @@ contract SandclockLUSDTest is DSTestPlus {
MockVault vault;
MockStabilityPool stabilityPool;
MockLiquityPriceFeed priceFeed;
MockPriceFeed lusd2eth;
MockPriceFeed usd2eth;

function setUp() public {
underlying = new MockERC20("Mock LUSD", "LUSD", 18);
lqty = new MockERC20("Mock LQTY", "LQTY", 18);
xrouter = new Mock0x();
priceFeed = new MockLiquityPriceFeed();
stabilityPool = new MockStabilityPool(address(underlying), address(lqty), address(priceFeed));
lusd2eth = new MockPriceFeed();
lusd2eth.setPrice(935490589304841);
vault = new MockVault(address(this), address(this), underlying, stabilityPool, lusd2eth, lqty, address(xrouter));
usd2eth = new MockPriceFeed();
usd2eth.setPrice(935490589304841);
vault = new MockVault(address(this), address(this), underlying, stabilityPool, usd2eth, lqty, address(xrouter));
vault.grantRole(vault.KEEPER_ROLE(), address(this));
}

Expand Down