mirror of
https://github.com/Instadapp/yield-contract.git
synced 2024-07-29 21:47:29 +00:00
done with eth pool exchange rate
This commit is contained in:
parent
7a5b127225
commit
17be61f608
|
@ -16,23 +16,6 @@ interface CompTroller {
|
|||
function getAllMarkets() external view returns (address[] memory);
|
||||
}
|
||||
|
||||
interface OracleComp {
|
||||
function getUnderlyingPrice(address) external view returns (uint);
|
||||
}
|
||||
|
||||
interface InstaMapping {
|
||||
function cTokenMapping(address) external view returns (address);
|
||||
}
|
||||
|
||||
interface CurveMapping {
|
||||
function curvePoolMapping(address poolAddr) external view returns (address);
|
||||
}
|
||||
|
||||
interface CurveRegistry {
|
||||
function pool_list(uint) external view returns (address poolAddress, address poolToken);
|
||||
function pool_count() external view returns (uint);
|
||||
}
|
||||
|
||||
interface ICurve {
|
||||
function get_virtual_price() external view returns (uint256 out);
|
||||
}
|
||||
|
@ -47,27 +30,65 @@ interface PriceFeedInterface {
|
|||
function getEthPrice() external view returns (uint256 ethPriceUSD);
|
||||
}
|
||||
|
||||
interface ManagerLike {
|
||||
function ilks(uint) external view returns (bytes32);
|
||||
function owns(uint) external view returns (address);
|
||||
function urns(uint) external view returns (address);
|
||||
function vat() external view returns (address);
|
||||
}
|
||||
|
||||
interface VatLike {
|
||||
function ilks(bytes32) external view returns (uint, uint, uint, uint, uint);
|
||||
function dai(address) external view returns (uint);
|
||||
function urns(bytes32, address) external view returns (uint, uint);
|
||||
function gem(bytes32, address) external view returns (uint);
|
||||
}
|
||||
|
||||
|
||||
contract EthRateLogic is DSMath {
|
||||
address public immutable poolToken;
|
||||
address public immutable dsa;
|
||||
|
||||
uint public immutable vaultId;
|
||||
address public immutable vaultUrn;
|
||||
|
||||
address public constant ethAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||
address public constant daiAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||
|
||||
address public constant PriceFeedAddr = address(0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88);
|
||||
|
||||
address public constant compTrollerAddr = address(0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88);
|
||||
address public constant cethAddr = address(0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88);
|
||||
address public constant ethAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||
address public constant compOracleAddr = address(0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88);
|
||||
address public constant PriceFeedAddr = address(0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88);
|
||||
address public constant ctokenMapping = address(0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88);
|
||||
|
||||
address public constant curve3poolAddr = address(0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88);
|
||||
address public constant curve3poolTokenAddr = address(0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88);
|
||||
|
||||
address public constant managerAddr = address(0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88);
|
||||
bytes32 public constant ethIlk = bytes32(0);
|
||||
|
||||
|
||||
function getMakerNetAssetsInEth() private view returns (uint256 _netBal) {
|
||||
ManagerLike managerContract = ManagerLike(managerAddr);
|
||||
VatLike vatContract = VatLike(managerContract.vat());
|
||||
uint daiPriceInETH = PriceFeedInterface(PriceFeedAddr).getPrice(daiAddr);
|
||||
|
||||
(uint coll, uint art) = vatContract.urns(ethIlk, vaultUrn);
|
||||
(,uint rate,,,) = vatContract.ilks(ethIlk);
|
||||
uint debt = rmul(art,rate);
|
||||
uint debtInEth = wmul(debt, daiPriceInETH);
|
||||
return sub(coll, debtInEth);
|
||||
|
||||
}
|
||||
|
||||
function getCompoundNetAssetsInEth(address _dsa) private returns (uint256 _netBal) {
|
||||
uint totalSupplyInETH;
|
||||
uint totalBorrowInETH;
|
||||
address[] memory allMarkets = CompTroller(compTrollerAddr).getAllMarkets();
|
||||
PriceFeedInterface priceFeedContract = PriceFeedInterface(PriceFeedAddr);
|
||||
// uint ethPrice = oracleContract.getUnderlyingPrice(cethAddr);
|
||||
|
||||
for (uint i = 0; i < allMarkets.length; i++) {
|
||||
CTokenInterface ctoken = CTokenInterface(allMarkets[i]);
|
||||
uint tokenPriceInETH = priceFeedContract.getPrice(address(ctoken) == cethAddr ? ethAddr : ctoken.underlying());
|
||||
uint tokenPriceInETH = address(ctoken) == cethAddr ? 10 ** 18 : priceFeedContract.getPrice(ctoken.underlying());
|
||||
uint supply = wmul(ctoken.balanceOf(_dsa), ctoken.exchangeRateCurrent());
|
||||
uint supplyInETH = wmul(supply, tokenPriceInETH);
|
||||
|
||||
|
@ -93,6 +114,7 @@ contract EthRateLogic is DSMath {
|
|||
function getNetDsaAssets(address _dsa) private returns (uint256 _netBal) {
|
||||
_netBal = _dsa.balance;
|
||||
_netBal += getCompoundNetAssetsInEth(_dsa);
|
||||
_netBal += getMakerNetAssetsInEth();
|
||||
_netBal += getCurveNetAssetsInEth(_dsa);
|
||||
}
|
||||
|
||||
|
@ -103,9 +125,11 @@ contract EthRateLogic is DSMath {
|
|||
return bal;
|
||||
}
|
||||
|
||||
constructor (address ethPool) public {
|
||||
constructor (address ethPool, address _dsa, uint _vaultId) public {
|
||||
poolToken = address(ethPool);
|
||||
}
|
||||
vaultId = _vaultId;
|
||||
dsa = _dsa;
|
||||
vaultUrn = ManagerLike(managerAddr).urns(_vaultId);
|
||||
|
||||
receive() external payable {}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user