mirror of
https://github.com/Instadapp/dsa-resolvers-deprecated.git
synced 2024-07-29 22:38:16 +00:00
done with aave resolver
This commit is contained in:
parent
1289707a61
commit
0f45593b95
223
contracts/protocols/aave.sol
Normal file
223
contracts/protocols/aave.sol
Normal file
|
|
@ -0,0 +1,223 @@
|
||||||
|
pragma solidity ^0.6.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
interface AaveInterface {
|
||||||
|
function deposit(address _reserve, uint256 _amount, uint16 _referralCode) external payable;
|
||||||
|
function redeemUnderlying(
|
||||||
|
address _reserve,
|
||||||
|
address payable _user,
|
||||||
|
uint256 _amount,
|
||||||
|
uint256 _aTokenBalanceAfterRedeem
|
||||||
|
) external;
|
||||||
|
function setUserUseReserveAsCollateral(address _reserve, bool _useAsCollateral) external;
|
||||||
|
function getUserReserveData(address _reserve, address _user) external view returns (
|
||||||
|
uint256 currentATokenBalance,
|
||||||
|
uint256 currentBorrowBalance,
|
||||||
|
uint256 principalBorrowBalance,
|
||||||
|
uint256 borrowRateMode,
|
||||||
|
uint256 borrowRate,
|
||||||
|
uint256 liquidityRate,
|
||||||
|
uint256 originationFee,
|
||||||
|
uint256 variableBorrowIndex,
|
||||||
|
uint256 lastUpdateTimestamp,
|
||||||
|
bool usageAsCollateralEnabled
|
||||||
|
);
|
||||||
|
function borrow(address _reserve, uint256 _amount, uint256 _interestRateMode, uint16 _referralCode) external;
|
||||||
|
function repay(address _reserve, uint256 _amount, address payable _onBehalfOf) external payable;
|
||||||
|
function getUserAccountData(address _user) external view returns (
|
||||||
|
uint256 totalLiquidityETH,
|
||||||
|
uint256 totalCollateralETH,
|
||||||
|
uint256 totalBorrowsETH,
|
||||||
|
uint256 totalFeesETH,
|
||||||
|
uint256 availableBorrowsETH,
|
||||||
|
uint256 currentLiquidationThreshold,
|
||||||
|
uint256 ltv,
|
||||||
|
uint256 healthFactor
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AaveProviderInterface {
|
||||||
|
function getLendingPool() external view returns (address);
|
||||||
|
function getLendingPoolCore() external view returns (address);
|
||||||
|
function getPriceOracle() external view returns (address);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AaveCoreInterface {
|
||||||
|
function getReserveATokenAddress(address _reserve) external view returns (address);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ATokenInterface {
|
||||||
|
function redeem(uint256 _amount) external;
|
||||||
|
function balanceOf(address _user) external view returns(uint256);
|
||||||
|
function principalBalanceOf(address _user) external view returns(uint256);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AavePriceInterface {
|
||||||
|
function getAssetPrice(address _asset) external view returns (uint256);
|
||||||
|
function getAssetsPrices(address[] calldata _assets) external view returns(uint256[] memory);
|
||||||
|
function getSourceOfAsset(address _asset) external view returns(address);
|
||||||
|
function getFallbackOracle() external view returns(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract DSMath {
|
||||||
|
|
||||||
|
function add(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
require((z = x + y) >= x, "math-not-safe");
|
||||||
|
}
|
||||||
|
|
||||||
|
function sub(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
z = x - y <= x ? x - y : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mul(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
require(y == 0 || (z = x * y) / y == x, "math-not-safe");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint constant WAD = 10 ** 18;
|
||||||
|
uint constant RAY = 10 ** 27;
|
||||||
|
|
||||||
|
function rmul(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
z = add(mul(x, y), RAY / 2) / RAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
function wmul(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
z = add(mul(x, y), WAD / 2) / WAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rdiv(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
z = add(mul(x, RAY), y / 2) / y;
|
||||||
|
}
|
||||||
|
|
||||||
|
function wdiv(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
z = add(mul(x, WAD), y / 2) / y;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
contract AaveHelpers is DSMath {
|
||||||
|
/**
|
||||||
|
* @dev get Aave Address
|
||||||
|
*/
|
||||||
|
function getAaveProviderAddress() internal pure returns (address) {
|
||||||
|
// return 0x24a42fD28C976A61Df5D00D0599C34c4f90748c8; //mainnet
|
||||||
|
return 0x506B0B2CF20FAA8f38a4E2B524EE43e1f4458Cc5; //kovan
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev get Aave Address
|
||||||
|
*/
|
||||||
|
function getAaveAddress() internal pure returns (address) {
|
||||||
|
// return 0x24a42fD28C976A61Df5D00D0599C34c4f90748c8; //mainnet
|
||||||
|
return 0x580D4Fdc4BF8f9b5ae2fb9225D584fED4AD5375c; //kovan
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev get Aave Core Address
|
||||||
|
*/
|
||||||
|
function getAaveCoreAddress() internal pure returns (address) {
|
||||||
|
// return 0x24a42fD28C976A61Df5D00D0599C34c4f90748c8; //mainnet
|
||||||
|
return 0x95D1189Ed88B380E319dF73fF00E479fcc4CFa45; //kovan
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev get Referral Code
|
||||||
|
*/
|
||||||
|
function getReferralCode() internal pure returns (uint16) {
|
||||||
|
return 3228;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getIsColl(AaveInterface aave, address token) internal view returns (bool isCol) {
|
||||||
|
(, , , , , , , , , isCol) = aave.getUserReserveData(token, address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getWithdrawBalance(address token) internal view returns (uint bal) {
|
||||||
|
AaveInterface aave = AaveInterface(getAaveAddress());
|
||||||
|
(bal, , , , , , , , , ) = aave.getUserReserveData(token, address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPaybackBalance(AaveInterface aave, address token) internal view returns (uint bal, uint fee) {
|
||||||
|
(, bal, , , , , fee, , , ) = aave.getUserReserveData(token, address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AaveTokenData {
|
||||||
|
uint tokenPrice;
|
||||||
|
uint supplyBalance;
|
||||||
|
uint borrowBalance;
|
||||||
|
uint borrowFee;
|
||||||
|
uint supplyRate;
|
||||||
|
uint borrowRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AaveUserData {
|
||||||
|
uint totalSupplyETH;
|
||||||
|
uint totalCollateralETH;
|
||||||
|
uint totalBorrowsETH;
|
||||||
|
uint totalFeesETH;
|
||||||
|
uint availableBorrowsETH;
|
||||||
|
uint currentLiquidationThreshold;
|
||||||
|
uint healthFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTokenData(AaveInterface aave, address user, address token, uint price)
|
||||||
|
internal view returns(AaveTokenData memory tokenData) {
|
||||||
|
(
|
||||||
|
uint supplyBal,
|
||||||
|
uint borrowBal,
|
||||||
|
,
|
||||||
|
,
|
||||||
|
uint borrowRate,
|
||||||
|
uint supplyRate,
|
||||||
|
uint fee,
|
||||||
|
,,
|
||||||
|
) = aave.getUserReserveData(token, user);
|
||||||
|
tokenData = AaveTokenData(
|
||||||
|
price,
|
||||||
|
supplyBal,
|
||||||
|
borrowBal,
|
||||||
|
fee,
|
||||||
|
supplyRate,
|
||||||
|
borrowRate
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUserData(AaveInterface aave, address user)
|
||||||
|
internal view returns (AaveUserData memory userData) {
|
||||||
|
(
|
||||||
|
uint totalSupplyETH,
|
||||||
|
uint totalCollateralETH,
|
||||||
|
uint totalBorrowsETH,
|
||||||
|
uint totalFeesETH,
|
||||||
|
uint availableBorrowsETH,
|
||||||
|
uint currentLiquidationThreshold,
|
||||||
|
,
|
||||||
|
uint healthFactor
|
||||||
|
) = aave.getUserAccountData(user);
|
||||||
|
|
||||||
|
userData = AaveUserData(
|
||||||
|
totalSupplyETH,
|
||||||
|
totalCollateralETH,
|
||||||
|
totalBorrowsETH,
|
||||||
|
totalFeesETH,
|
||||||
|
availableBorrowsETH,
|
||||||
|
currentLiquidationThreshold,
|
||||||
|
healthFactor
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract Resolver is AaveHelpers {
|
||||||
|
function getPosition(address user, address[] memory tokens) public view returns(AaveTokenData[] memory, AaveUserData memory) {
|
||||||
|
AaveInterface aave = AaveInterface(getAaveAddress());
|
||||||
|
AaveProviderInterface AaveProvider = AaveProviderInterface(getAaveProviderAddress());
|
||||||
|
AaveTokenData[] memory tokensData = new AaveTokenData[](tokens.length);
|
||||||
|
uint[] memory tokenPrices = AavePriceInterface(AaveProvider.getPriceOracle()).getAssetsPrices(tokens);
|
||||||
|
for (uint i = 0; i < tokens.length; i++) {
|
||||||
|
tokensData[i] = getTokenData(aave, user, tokens[i], tokenPrices[i]);
|
||||||
|
}
|
||||||
|
return (tokensData, getUserData(aave, user));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract InstaDydxResolver is Resolver {
|
||||||
|
string public constant name = "Dydx-Resolver-v1";
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user