fixed dai exchangeRate logic

This commit is contained in:
Thrilok Kumar 2020-09-28 13:52:26 +05:30
parent 9eab74bc40
commit f935e7e3f2

View File

@ -12,6 +12,10 @@ interface CTokenInterface {
function underlying() external view returns (address); function underlying() external view returns (address);
} }
interface TokenInterface {
function balanceOf(address owner) external view returns (uint256);
}
interface CompTroller { interface CompTroller {
function getAllMarkets() external view returns (address[] memory); function getAllMarkets() external view returns (address[] memory);
} }
@ -20,9 +24,6 @@ interface ICurve {
function get_virtual_price() external view returns (uint256 out); function get_virtual_price() external view returns (uint256 out);
} }
interface TokenInterface {
function balanceOf(address owner) external view returns (uint256);
}
interface PriceFeedInterface { interface PriceFeedInterface {
function getPrices(address[] memory tokens) external view returns (uint256[] memory pricesInETH); function getPrices(address[] memory tokens) external view returns (uint256[] memory pricesInETH);
@ -76,26 +77,26 @@ contract DaiRateLogic is DSMath {
_netBal = add(_netBal, amtInETH); _netBal = add(_netBal, amtInETH);
} }
function getNetDsaAssets(address _dsa) private returns (uint256 _netBal) { function getNetDsaAssetsInEth(address _dsa) private returns (uint256 _netBal) {
_netBal = _dsa.balance;
_netBal += getCompoundNetAssetsInEth(_dsa); _netBal += getCompoundNetAssetsInEth(_dsa);
_netBal += getCurveNetAssetsInEth(_dsa); _netBal += getCurveNetAssetsInEth(_dsa);
} }
function getTotalToken() public returns (uint256) { function getTotalToken() public returns (uint256 _daiBal) {
address _dsa = 0x0000000000000000000000000000000000000000; address _dsa = 0x0000000000000000000000000000000000000000;
PriceFeedInterface priceFeedContract = PriceFeedInterface(PriceFeedAddr); PriceFeedInterface priceFeedContract = PriceFeedInterface(PriceFeedAddr);
uint daiPriceInETH = priceFeedContract.getPrice(daiAddr); uint daiPriceInETH = priceFeedContract.getPrice(daiAddr);
uint256 balInEth = poolToken.balance; TokenInterface daiToken = TokenInterface(daiAddr);
balInEth += getNetDsaAssets(_dsa); _daiBal = daiToken.balanceOf(poolToken);
uint balInDai = wdiv(balInEth, daiPriceInETH); _daiBal += daiToken.balanceOf(_dsa);
return balInDai;
uint balInEth = getNetDsaAssetsInEth(_dsa);
_daiBal = wdiv(balInEth, daiPriceInETH);
} }
constructor (address daiPool, address _dsa) public { constructor (address daiPool, address _dsa) public {
poolToken = address(daiPool); poolToken = address(daiPool);
dsa = _dsa; dsa = _dsa;
} }
} }