mirror of
https://github.com/Instadapp/dsa-resolvers-deprecated.git
synced 2024-07-29 22:38:16 +00:00
Added tokenPriceInUsd for aave resolver
This commit is contained in:
parent
0911656f59
commit
0c2903bf06
|
@ -59,6 +59,11 @@ interface AaveCoreInterface {
|
||||||
function getReserveCurrentVariableBorrowRate(address _reserve) external view returns (uint256);
|
function getReserveCurrentVariableBorrowRate(address _reserve) external view returns (uint256);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ChainLinkInterface {
|
||||||
|
function latestAnswer() external view returns (int256);
|
||||||
|
function decimals() external view returns (uint256);
|
||||||
|
}
|
||||||
|
|
||||||
contract DSMath {
|
contract DSMath {
|
||||||
|
|
||||||
function add(uint x, uint y) internal pure returns (uint z) {
|
function add(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
@ -103,8 +108,17 @@ contract AaveHelpers is DSMath {
|
||||||
return 0x506B0B2CF20FAA8f38a4E2B524EE43e1f4458Cc5; //kovan
|
return 0x506B0B2CF20FAA8f38a4E2B524EE43e1f4458Cc5; //kovan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev get Chainlink ETH price feed Address
|
||||||
|
*/
|
||||||
|
function getChainlinkEthFeed() internal pure returns (address) {
|
||||||
|
// return 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419; //mainnet
|
||||||
|
return 0x9326BFA02ADD2366b30bacB125260Af641031331; //kovan
|
||||||
|
}
|
||||||
|
|
||||||
struct AaveUserTokenData {
|
struct AaveUserTokenData {
|
||||||
uint tokenPrice;
|
uint tokenPriceInEth;
|
||||||
|
uint tokenPriceInUsd;
|
||||||
uint supplyBalance;
|
uint supplyBalance;
|
||||||
uint borrowBalance;
|
uint borrowBalance;
|
||||||
uint borrowFee;
|
uint borrowFee;
|
||||||
|
@ -123,6 +137,7 @@ contract AaveHelpers is DSMath {
|
||||||
uint currentLiquidationThreshold;
|
uint currentLiquidationThreshold;
|
||||||
uint ltv;
|
uint ltv;
|
||||||
uint healthFactor;
|
uint healthFactor;
|
||||||
|
uint ethPriceInUsd;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AaveTokenData {
|
struct AaveTokenData {
|
||||||
|
@ -134,8 +149,25 @@ contract AaveHelpers is DSMath {
|
||||||
bool isActive;
|
bool isActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct TokenPrice {
|
||||||
|
uint priceInEth;
|
||||||
|
uint priceInUsd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getTokensPrices(AaveProviderInterface AaveProvider, address[] memory tokens)
|
||||||
|
internal view returns(TokenPrice[] memory tokenPrices, uint ethPrice) {
|
||||||
|
uint[] memory _tokenPrices = AavePriceInterface(AaveProvider.getPriceOracle()).getAssetsPrices(tokens);
|
||||||
|
ethPrice = uint(ChainLinkInterface(getChainlinkEthFeed()).latestAnswer());
|
||||||
|
tokenPrices = new TokenPrice[](_tokenPrices.length);
|
||||||
|
for (uint i = 0; i < _tokenPrices.length; i++) {
|
||||||
|
tokenPrices[i] = TokenPrice(
|
||||||
|
_tokenPrices[i],
|
||||||
|
wmul(_tokenPrices[i], uint(ethPrice) * 10 ** 10)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function collateralData(AaveInterface aave, address token) internal view returns(AaveTokenData memory) {
|
function collateralData(AaveInterface aave, address token) internal view returns(AaveTokenData memory) {
|
||||||
AaveTokenData memory aaveTokenData;
|
AaveTokenData memory aaveTokenData;
|
||||||
(
|
(
|
||||||
|
@ -156,7 +188,8 @@ contract AaveHelpers is DSMath {
|
||||||
AaveInterface aave,
|
AaveInterface aave,
|
||||||
address user,
|
address user,
|
||||||
address token,
|
address token,
|
||||||
uint price)
|
uint priceInEth,
|
||||||
|
uint priceInUsd)
|
||||||
internal view returns(AaveUserTokenData memory tokenData) {
|
internal view returns(AaveUserTokenData memory tokenData) {
|
||||||
(
|
(
|
||||||
uint supplyBal,
|
uint supplyBal,
|
||||||
|
@ -174,7 +207,8 @@ contract AaveHelpers is DSMath {
|
||||||
AaveTokenData memory aaveTokenData = collateralData(aave, token);
|
AaveTokenData memory aaveTokenData = collateralData(aave, token);
|
||||||
|
|
||||||
tokenData = AaveUserTokenData(
|
tokenData = AaveUserTokenData(
|
||||||
price,
|
priceInEth,
|
||||||
|
priceInUsd,
|
||||||
supplyBal,
|
supplyBal,
|
||||||
borrowBal,
|
borrowBal,
|
||||||
fee,
|
fee,
|
||||||
|
@ -185,7 +219,7 @@ contract AaveHelpers is DSMath {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserData(AaveInterface aave, address user)
|
function getUserData(AaveInterface aave, address user, uint ethPrice)
|
||||||
internal view returns (AaveUserData memory userData) {
|
internal view returns (AaveUserData memory userData) {
|
||||||
(
|
(
|
||||||
uint totalSupplyETH,
|
uint totalSupplyETH,
|
||||||
|
@ -206,7 +240,8 @@ contract AaveHelpers is DSMath {
|
||||||
availableBorrowsETH,
|
availableBorrowsETH,
|
||||||
currentLiquidationThreshold,
|
currentLiquidationThreshold,
|
||||||
ltv,
|
ltv,
|
||||||
healthFactor
|
healthFactor,
|
||||||
|
ethPrice
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,14 +253,14 @@ contract Resolver is AaveHelpers {
|
||||||
AaveCoreInterface aaveCore = AaveCoreInterface(AaveProvider.getLendingPoolCore());
|
AaveCoreInterface aaveCore = AaveCoreInterface(AaveProvider.getLendingPoolCore());
|
||||||
|
|
||||||
AaveUserTokenData[] memory tokensData = new AaveUserTokenData[](tokens.length);
|
AaveUserTokenData[] memory tokensData = new AaveUserTokenData[](tokens.length);
|
||||||
uint[] memory tokenPrices = AavePriceInterface(AaveProvider.getPriceOracle()).getAssetsPrices(tokens);
|
(TokenPrice[] memory tokenPrices, uint ethPrice) = getTokensPrices(AaveProvider, tokens);
|
||||||
for (uint i = 0; i < tokens.length; i++) {
|
for (uint i = 0; i < tokens.length; i++) {
|
||||||
tokensData[i] = getTokenData(aaveCore, aave, user, tokens[i], tokenPrices[i]);
|
tokensData[i] = getTokenData(aaveCore, aave, user, tokens[i], tokenPrices[i].priceInEth, tokenPrices[i].priceInUsd);
|
||||||
}
|
}
|
||||||
return (tokensData, getUserData(aave, user));
|
return (tokensData, getUserData(aave, user, ethPrice));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract InstaAaveResolver is Resolver {
|
contract InstaAaveResolver is Resolver {
|
||||||
string public constant name = "Aave-Resolver-v1";
|
string public constant name = "Aave-Resolver-v1.1";
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user