diff --git a/src/interfaces/liquity/IPriceFeed.sol b/src/interfaces/liquity/IPriceFeed.sol new file mode 100644 index 00000000..4a03a53e --- /dev/null +++ b/src/interfaces/liquity/IPriceFeed.sol @@ -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); +} diff --git a/src/lib/Constants.sol b/src/lib/Constants.sol index d8215978..c12bde77 100644 --- a/src/lib/Constants.sol +++ b/src/lib/Constants.sol @@ -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; diff --git a/src/liquity/scLiquity.sol b/src/liquity/scLiquity.sol index 4f975867..9159d89c 100644 --- a/src/liquity/scLiquity.sol +++ b/src/liquity/scLiquity.sol @@ -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 { @@ -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); ERC20 public lqty = ERC20(C.LIQUITY_LQTY_TOKEN); // 0x swap router @@ -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)); diff --git a/test/mocks/liquity/MockPriceFeed.sol b/test/mocks/liquity/MockPriceFeed.sol index ebe6b775..2eadfb11 100644 --- a/test/mocks/liquity/MockPriceFeed.sol +++ b/test/mocks/liquity/MockPriceFeed.sol @@ -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; } } diff --git a/test/scLiquity.t.sol b/test/scLiquity.t.sol index 3f018694..65d8790f 100644 --- a/test/scLiquity.t.sol +++ b/test/scLiquity.t.sol @@ -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); @@ -37,7 +37,7 @@ contract SandclockLUSDTest is DSTestPlus { MockVault vault; MockStabilityPool stabilityPool; MockLiquityPriceFeed priceFeed; - MockPriceFeed lusd2eth; + MockPriceFeed usd2eth; function setUp() public { underlying = new MockERC20("Mock LUSD", "LUSD", 18); @@ -45,9 +45,9 @@ contract SandclockLUSDTest is DSTestPlus { 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)); }