From 549355b1b7113228baf1dd62e7cb63ae3b2072a3 Mon Sep 17 00:00:00 2001 From: Daksh Miglani Date: Sun, 4 Jul 2021 01:39:25 +0530 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20fetchETHPrice=20an?= =?UTF-8?q?d=20refactor=20old=20functions=20to=20use=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contracts/protocols/mainnet/liquity.sol | 28 +++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/contracts/protocols/mainnet/liquity.sol b/contracts/protocols/mainnet/liquity.sol index 04c5ee5..9926504 100644 --- a/contracts/protocols/mainnet/liquity.sol +++ b/contracts/protocols/mainnet/liquity.sol @@ -1,6 +1,10 @@ pragma solidity ^0.6.0; pragma experimental ABIEncoderV2; +interface PriceFeedOracle { + function fetchPrice() external returns (uint); +} + interface TroveManagerLike { function getBorrowingRateWithDecay() external view returns (uint); function getTCR(uint _price) external view returns (uint); @@ -97,7 +101,10 @@ contract Helpers is Math { SortedTrovesLike internal constant sortedTroves = SortedTrovesLike(0x8FdD3fbFEb32b28fb73555518f8b361bCeA741A6); - + + PriceFeedOracle internal constant priceFeedOracle = + PriceFeedOracle(0x4c517D4e2C851CA76d7eC94B805269Df0f2201De); + struct Trove { uint collateral; uint debt; @@ -132,7 +139,13 @@ contract Helpers is Math { contract Resolver is Helpers { - function getTrove(address owner, uint oracleEthPrice) public view returns (Trove memory) { + + function fetchETHPrice() public returns (uint) { + return priceFeedOracle.fetchPrice(); + } + + function getTrove(address owner) public returns (Trove memory) { + uint oracleEthPrice = fetchETHPrice(); (uint debt, uint collateral, , ) = troveManager.getEntireDebtAndColl(owner); uint icr = troveManager.getCurrentICR(owner, oracleEthPrice); return Trove(collateral, debt, icr); @@ -152,14 +165,15 @@ contract Resolver is Helpers { return Stake(amount, ethGain, lusdGain); } - function getPosition(address owner, uint oracleEthPrice) external view returns (Position memory) { - Trove memory trove = getTrove(owner, oracleEthPrice); + function getPosition(address owner) external returns (Position memory) { + Trove memory trove = getTrove(owner); StabilityDeposit memory stability = getStabilityDeposit(owner); Stake memory stake = getStake(owner); return Position(trove, stability, stake); } - function getSystemState(uint oracleEthPrice) external view returns (System memory) { + function getSystemState() external returns (System memory) { + uint oracleEthPrice = fetchETHPrice(); uint borrowFee = troveManager.getBorrowingRateWithDecay(); uint ethTvl = add(activePool.getETH(), defaultPool.getETH()); uint tcr = troveManager.getTCR(oracleEthPrice); @@ -179,12 +193,14 @@ contract Resolver is Helpers { return sortedTroves.findInsertPosition(nominalCr, hintAddress, hintAddress); } - function getRedemptionPositionHints(uint amount, uint oracleEthPrice, uint searchIterations, uint randomSeed) external view returns ( + function getRedemptionPositionHints(uint amount, uint searchIterations, uint randomSeed) external returns ( + uint partialHintNicr, address firstHint, address upperHint, address lowerHint ) { + uint oracleEthPrice = fetchETHPrice(); // See: https://github.com/liquity/dev#hints-for-redeemcollateral (firstHint, partialHintNicr, ) = hintHelpers.getRedemptionHints(amount, oracleEthPrice, 0); searchIterations = searchIterations == 0 ? mul(10, sqrt(sortedTroves.getSize())) : searchIterations;