mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
feat: added UiIncentiveDataProvider
This commit is contained in:
parent
d1ada764d1
commit
7e84216ba8
288
contracts/misc/UiIncentiveDataProvider.sol
Normal file
288
contracts/misc/UiIncentiveDataProvider.sol
Normal file
|
@ -0,0 +1,288 @@
|
||||||
|
// SPDX-License-Identifier: agpl-3.0
|
||||||
|
pragma solidity 0.6.12;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
|
||||||
|
import {IAaveIncentivesController} from '../interfaces/IAaveIncentivesController.sol';
|
||||||
|
import {IUiIncentiveDataProvider} from './interfaces/IUiIncentiveDataProvider.sol';
|
||||||
|
import {ILendingPool} from '../interfaces/ILendingPool.sol';
|
||||||
|
import {IAToken} from '../interfaces/IAToken.sol';
|
||||||
|
import {IVariableDebtToken} from '../interfaces/IVariableDebtToken.sol';
|
||||||
|
import {IStableDebtToken} from '../interfaces/IStableDebtToken.sol';
|
||||||
|
import {UserConfiguration} from '../protocol/libraries/configuration/UserConfiguration.sol';
|
||||||
|
import {DataTypes} from '../protocol/libraries/types/DataTypes.sol';
|
||||||
|
import {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detailed.sol';
|
||||||
|
|
||||||
|
contract UiIncentiveDataProvider is IUiIncentiveDataProvider {
|
||||||
|
using UserConfiguration for DataTypes.UserConfigurationMap;
|
||||||
|
|
||||||
|
constructor() public {}
|
||||||
|
|
||||||
|
function getFullReservesIncentiveData(ILendingPoolAddressesProvider provider, address user)
|
||||||
|
external
|
||||||
|
view
|
||||||
|
override
|
||||||
|
returns (AggregatedReserveIncentiveData[] memory, UserReserveIncentiveData[] memory)
|
||||||
|
{
|
||||||
|
return (_getReservesIncentivesData(provider), _getUserReservesIncentivesData(provider, user));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getReservesIncentivesData(ILendingPoolAddressesProvider provider)
|
||||||
|
external
|
||||||
|
view
|
||||||
|
override
|
||||||
|
returns (AggregatedReserveIncentiveData[] memory)
|
||||||
|
{
|
||||||
|
return _getReservesIncentivesData(provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _getReservesIncentivesData(ILendingPoolAddressesProvider provider)
|
||||||
|
private
|
||||||
|
view
|
||||||
|
returns (AggregatedReserveIncentiveData[] memory)
|
||||||
|
{
|
||||||
|
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
|
||||||
|
address[] memory reserves = lendingPool.getReservesList();
|
||||||
|
AggregatedReserveIncentiveData[] memory reservesIncentiveData =
|
||||||
|
new AggregatedReserveIncentiveData[](reserves.length);
|
||||||
|
|
||||||
|
for (uint256 i = 0; i < reserves.length; i++) {
|
||||||
|
AggregatedReserveIncentiveData memory reserveIncentiveData = reservesIncentiveData[i];
|
||||||
|
reserveIncentiveData.underlyingAsset = reserves[i];
|
||||||
|
|
||||||
|
DataTypes.ReserveData memory baseData = lendingPool.getReserveData(reserves[i]);
|
||||||
|
|
||||||
|
try IStableDebtToken(baseData.aTokenAddress).getIncentivesController() returns (IAaveIncentivesController aTokenIncentiveController) {
|
||||||
|
if (address(aTokenIncentiveController) != address(0)) {
|
||||||
|
address aRewardToken = aTokenIncentiveController.REWARD_TOKEN();
|
||||||
|
|
||||||
|
try aTokenIncentiveController.getAssetData(baseData.aTokenAddress) returns (
|
||||||
|
uint256 aTokenIncentivesIndex,
|
||||||
|
uint256 aEmissionPerSecond,
|
||||||
|
uint256 aIncentivesLastUpdateTimestamp
|
||||||
|
) {
|
||||||
|
reserveIncentiveData.aIncentiveData = IncentiveData(
|
||||||
|
aEmissionPerSecond,
|
||||||
|
aIncentivesLastUpdateTimestamp,
|
||||||
|
aTokenIncentivesIndex,
|
||||||
|
aTokenIncentiveController.DISTRIBUTION_END(),
|
||||||
|
baseData.aTokenAddress,
|
||||||
|
aRewardToken,
|
||||||
|
address(aTokenIncentiveController),
|
||||||
|
IERC20Detailed(aRewardToken).decimals(),
|
||||||
|
aTokenIncentiveController.PRECISION()
|
||||||
|
);
|
||||||
|
} catch (bytes memory /*lowLevelData*/) {
|
||||||
|
(
|
||||||
|
uint256 aEmissionPerSecond,
|
||||||
|
uint256 aIncentivesLastUpdateTimestamp,
|
||||||
|
uint256 aTokenIncentivesIndex
|
||||||
|
) = aTokenIncentiveController.assets(baseData.aTokenAddress);
|
||||||
|
|
||||||
|
reserveIncentiveData.aIncentiveData = IncentiveData(
|
||||||
|
aEmissionPerSecond,
|
||||||
|
aIncentivesLastUpdateTimestamp,
|
||||||
|
aTokenIncentivesIndex,
|
||||||
|
aTokenIncentiveController.DISTRIBUTION_END(),
|
||||||
|
baseData.aTokenAddress,
|
||||||
|
aRewardToken,
|
||||||
|
address(aTokenIncentiveController),
|
||||||
|
IERC20Detailed(aRewardToken).decimals(),
|
||||||
|
aTokenIncentiveController.PRECISION()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(bytes memory /*lowLevelData*/) {
|
||||||
|
// Will not get here
|
||||||
|
}
|
||||||
|
|
||||||
|
try IStableDebtToken(baseData.stableDebtTokenAddress).getIncentivesController() returns (IAaveIncentivesController sTokenIncentiveController) {
|
||||||
|
if (address(sTokenIncentiveController) != address(0)) {
|
||||||
|
|
||||||
|
address sRewardToken = sTokenIncentiveController.REWARD_TOKEN();
|
||||||
|
try sTokenIncentiveController.getAssetData(baseData.stableDebtTokenAddress) returns (
|
||||||
|
uint256 sTokenIncentivesIndex,
|
||||||
|
uint256 sEmissionPerSecond,
|
||||||
|
uint256 sIncentivesLastUpdateTimestamp
|
||||||
|
) {
|
||||||
|
reserveIncentiveData.sIncentiveData = IncentiveData(
|
||||||
|
sEmissionPerSecond,
|
||||||
|
sIncentivesLastUpdateTimestamp,
|
||||||
|
sTokenIncentivesIndex,
|
||||||
|
sTokenIncentiveController.DISTRIBUTION_END(),
|
||||||
|
baseData.stableDebtTokenAddress,
|
||||||
|
sRewardToken,
|
||||||
|
address(sTokenIncentiveController),
|
||||||
|
IERC20Detailed(sRewardToken).decimals(),
|
||||||
|
sTokenIncentiveController.PRECISION()
|
||||||
|
);
|
||||||
|
} catch (bytes memory /*lowLevelData*/) {
|
||||||
|
(
|
||||||
|
uint256 sEmissionPerSecond,
|
||||||
|
uint256 sIncentivesLastUpdateTimestamp,
|
||||||
|
uint256 sTokenIncentivesIndex
|
||||||
|
) = sTokenIncentiveController.assets(baseData.stableDebtTokenAddress);
|
||||||
|
|
||||||
|
reserveIncentiveData.sIncentiveData = IncentiveData(
|
||||||
|
sEmissionPerSecond,
|
||||||
|
sIncentivesLastUpdateTimestamp,
|
||||||
|
sTokenIncentivesIndex,
|
||||||
|
sTokenIncentiveController.DISTRIBUTION_END(),
|
||||||
|
baseData.stableDebtTokenAddress,
|
||||||
|
sRewardToken,
|
||||||
|
address(sTokenIncentiveController),
|
||||||
|
IERC20Detailed(sRewardToken).decimals(),
|
||||||
|
sTokenIncentiveController.PRECISION()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(bytes memory /*lowLevelData*/) {
|
||||||
|
// Will not get here
|
||||||
|
}
|
||||||
|
|
||||||
|
try IStableDebtToken(baseData.variableDebtTokenAddress).getIncentivesController() returns (IAaveIncentivesController vTokenIncentiveController) {
|
||||||
|
if (address(vTokenIncentiveController) != address(0)) {
|
||||||
|
address vRewardToken = vTokenIncentiveController.REWARD_TOKEN();
|
||||||
|
|
||||||
|
try vTokenIncentiveController.getAssetData(baseData.variableDebtTokenAddress) returns (
|
||||||
|
uint256 vTokenIncentivesIndex,
|
||||||
|
uint256 vEmissionPerSecond,
|
||||||
|
uint256 vIncentivesLastUpdateTimestamp
|
||||||
|
) {
|
||||||
|
reserveIncentiveData.vIncentiveData = IncentiveData(
|
||||||
|
vEmissionPerSecond,
|
||||||
|
vIncentivesLastUpdateTimestamp,
|
||||||
|
vTokenIncentivesIndex,
|
||||||
|
vTokenIncentiveController.DISTRIBUTION_END(),
|
||||||
|
baseData.variableDebtTokenAddress,
|
||||||
|
vRewardToken,
|
||||||
|
address(vTokenIncentiveController),
|
||||||
|
IERC20Detailed(vRewardToken).decimals(),
|
||||||
|
vTokenIncentiveController.PRECISION()
|
||||||
|
);
|
||||||
|
} catch (bytes memory /*lowLevelData*/) {
|
||||||
|
(
|
||||||
|
uint256 vEmissionPerSecond,
|
||||||
|
uint256 vIncentivesLastUpdateTimestamp,
|
||||||
|
uint256 vTokenIncentivesIndex
|
||||||
|
) = vTokenIncentiveController.assets(baseData.variableDebtTokenAddress);
|
||||||
|
|
||||||
|
reserveIncentiveData.vIncentiveData = IncentiveData(
|
||||||
|
vEmissionPerSecond,
|
||||||
|
vIncentivesLastUpdateTimestamp,
|
||||||
|
vTokenIncentivesIndex,
|
||||||
|
vTokenIncentiveController.DISTRIBUTION_END(),
|
||||||
|
baseData.variableDebtTokenAddress,
|
||||||
|
vRewardToken,
|
||||||
|
address(vTokenIncentiveController),
|
||||||
|
IERC20Detailed(vRewardToken).decimals(),
|
||||||
|
vTokenIncentiveController.PRECISION()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(bytes memory /*lowLevelData*/) {
|
||||||
|
// Will not get here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (reservesIncentiveData);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUserReservesIncentivesData(ILendingPoolAddressesProvider provider, address user)
|
||||||
|
external
|
||||||
|
view
|
||||||
|
override
|
||||||
|
returns (UserReserveIncentiveData[] memory)
|
||||||
|
{
|
||||||
|
return _getUserReservesIncentivesData(provider, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _getUserReservesIncentivesData(ILendingPoolAddressesProvider provider, address user)
|
||||||
|
private
|
||||||
|
view
|
||||||
|
returns (UserReserveIncentiveData[] memory)
|
||||||
|
{
|
||||||
|
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
|
||||||
|
address[] memory reserves = lendingPool.getReservesList();
|
||||||
|
|
||||||
|
UserReserveIncentiveData[] memory userReservesIncentivesData =
|
||||||
|
new UserReserveIncentiveData[](user != address(0) ? reserves.length : 0);
|
||||||
|
|
||||||
|
for (uint256 i = 0; i < reserves.length; i++) {
|
||||||
|
DataTypes.ReserveData memory baseData = lendingPool.getReserveData(reserves[i]);
|
||||||
|
|
||||||
|
// user reserve data
|
||||||
|
userReservesIncentivesData[i].underlyingAsset = reserves[i];
|
||||||
|
|
||||||
|
IUiIncentiveDataProvider.UserIncentiveData memory aUserIncentiveData;
|
||||||
|
|
||||||
|
try IAToken(baseData.aTokenAddress).getIncentivesController() returns (IAaveIncentivesController aTokenIncentiveController) {
|
||||||
|
if (address(aTokenIncentiveController) != address(0)) {
|
||||||
|
address aRewardToken = aTokenIncentiveController.REWARD_TOKEN();
|
||||||
|
aUserIncentiveData.tokenincentivesUserIndex = aTokenIncentiveController.getUserAssetData(
|
||||||
|
user,
|
||||||
|
baseData.aTokenAddress
|
||||||
|
);
|
||||||
|
aUserIncentiveData.userUnclaimedRewards = aTokenIncentiveController.getUserUnclaimedRewards(
|
||||||
|
user
|
||||||
|
);
|
||||||
|
aUserIncentiveData.tokenAddress = baseData.aTokenAddress;
|
||||||
|
aUserIncentiveData.rewardTokenAddress = aRewardToken;
|
||||||
|
aUserIncentiveData.incentiveControllerAddress = address(aTokenIncentiveController);
|
||||||
|
aUserIncentiveData.rewardTokenDecimals = IERC20Detailed(aRewardToken).decimals();
|
||||||
|
}
|
||||||
|
} catch (bytes memory /*lowLevelData*/) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
userReservesIncentivesData[i].aTokenIncentivesUserData = aUserIncentiveData;
|
||||||
|
|
||||||
|
UserIncentiveData memory vUserIncentiveData;
|
||||||
|
|
||||||
|
try IVariableDebtToken(baseData.variableDebtTokenAddress).getIncentivesController() returns(IAaveIncentivesController vTokenIncentiveController) {
|
||||||
|
if (address(vTokenIncentiveController) != address(0)) {
|
||||||
|
address vRewardToken = vTokenIncentiveController.REWARD_TOKEN();
|
||||||
|
vUserIncentiveData.tokenincentivesUserIndex = vTokenIncentiveController.getUserAssetData(
|
||||||
|
user,
|
||||||
|
baseData.variableDebtTokenAddress
|
||||||
|
);
|
||||||
|
vUserIncentiveData.userUnclaimedRewards = vTokenIncentiveController.getUserUnclaimedRewards(
|
||||||
|
user
|
||||||
|
);
|
||||||
|
vUserIncentiveData.tokenAddress = baseData.variableDebtTokenAddress;
|
||||||
|
vUserIncentiveData.rewardTokenAddress = vRewardToken;
|
||||||
|
vUserIncentiveData.incentiveControllerAddress = address(vTokenIncentiveController);
|
||||||
|
vUserIncentiveData.rewardTokenDecimals = IERC20Detailed(vRewardToken).decimals();
|
||||||
|
}
|
||||||
|
} catch (bytes memory /*lowLevelData*/) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
userReservesIncentivesData[i].vTokenIncentivesUserData = vUserIncentiveData;
|
||||||
|
|
||||||
|
UserIncentiveData memory sUserIncentiveData;
|
||||||
|
|
||||||
|
try IStableDebtToken(baseData.stableDebtTokenAddress).getIncentivesController() returns (IAaveIncentivesController sTokenIncentiveController) {
|
||||||
|
if (address(sTokenIncentiveController) != address(0)) {
|
||||||
|
address sRewardToken = sTokenIncentiveController.REWARD_TOKEN();
|
||||||
|
sUserIncentiveData.tokenincentivesUserIndex = sTokenIncentiveController.getUserAssetData(
|
||||||
|
user,
|
||||||
|
baseData.stableDebtTokenAddress
|
||||||
|
);
|
||||||
|
sUserIncentiveData.userUnclaimedRewards = sTokenIncentiveController.getUserUnclaimedRewards(
|
||||||
|
user
|
||||||
|
);
|
||||||
|
sUserIncentiveData.tokenAddress = baseData.stableDebtTokenAddress;
|
||||||
|
sUserIncentiveData.rewardTokenAddress = sRewardToken;
|
||||||
|
sUserIncentiveData.incentiveControllerAddress = address(sTokenIncentiveController);
|
||||||
|
sUserIncentiveData.rewardTokenDecimals = IERC20Detailed(sRewardToken).decimals();
|
||||||
|
}
|
||||||
|
} catch (bytes memory /*lowLevelData*/) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
userReservesIncentivesData[i].sTokenIncentivesUserData = sUserIncentiveData;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (userReservesIncentivesData);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ import {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detai
|
||||||
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
|
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
|
||||||
import {IUiPoolDataProvider} from './interfaces/IUiPoolDataProvider.sol';
|
import {IUiPoolDataProvider} from './interfaces/IUiPoolDataProvider.sol';
|
||||||
import {ILendingPool} from '../interfaces/ILendingPool.sol';
|
import {ILendingPool} from '../interfaces/ILendingPool.sol';
|
||||||
import {IPriceOracleGetter} from '../interfaces/IPriceOracleGetter.sol';
|
import {IAaveOracle} from './IAaveOracle.sol';
|
||||||
import {IAToken} from '../interfaces/IAToken.sol';
|
import {IAToken} from '../interfaces/IAToken.sol';
|
||||||
import {IVariableDebtToken} from '../interfaces/IVariableDebtToken.sol';
|
import {IVariableDebtToken} from '../interfaces/IVariableDebtToken.sol';
|
||||||
import {IStableDebtToken} from '../interfaces/IStableDebtToken.sol';
|
import {IStableDebtToken} from '../interfaces/IStableDebtToken.sol';
|
||||||
|
@ -24,10 +24,8 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
|
||||||
using UserConfiguration for DataTypes.UserConfigurationMap;
|
using UserConfiguration for DataTypes.UserConfigurationMap;
|
||||||
|
|
||||||
address public constant MOCK_USD_ADDRESS = 0x10F7Fc1F91Ba351f9C629c5947AD69bD03C05b96;
|
address public constant MOCK_USD_ADDRESS = 0x10F7Fc1F91Ba351f9C629c5947AD69bD03C05b96;
|
||||||
IPriceOracleGetter public immutable oracle;
|
|
||||||
|
|
||||||
constructor(IPriceOracleGetter _oracle) public {
|
constructor() public {
|
||||||
oracle = _oracle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInterestRateStrategySlopes(DefaultReserveInterestRateStrategy interestRateStrategy)
|
function getInterestRateStrategySlopes(DefaultReserveInterestRateStrategy interestRateStrategy)
|
||||||
|
@ -68,72 +66,11 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
|
||||||
uint256
|
uint256
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
IAaveOracle oracle = IAaveOracle(provider.getPriceOracle());
|
||||||
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
|
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
|
||||||
address[] memory reserves = lendingPool.getReservesList();
|
address[] memory reserves = lendingPool.getReservesList();
|
||||||
AggregatedReserveData[] memory reservesData = new AggregatedReserveData[](reserves.length);
|
|
||||||
|
|
||||||
for (uint256 i = 0; i < reserves.length; i++) {
|
return (_getReserveData(oracle, reserves), oracle.getAssetPrice(MOCK_USD_ADDRESS));
|
||||||
AggregatedReserveData memory reserveData = reservesData[i];
|
|
||||||
reserveData.underlyingAsset = reserves[i];
|
|
||||||
|
|
||||||
// reserve current state
|
|
||||||
DataTypes.ReserveData memory baseData =
|
|
||||||
lendingPool.getReserveData(reserveData.underlyingAsset);
|
|
||||||
reserveData.liquidityIndex = baseData.liquidityIndex;
|
|
||||||
reserveData.variableBorrowIndex = baseData.variableBorrowIndex;
|
|
||||||
reserveData.liquidityRate = baseData.currentLiquidityRate;
|
|
||||||
reserveData.variableBorrowRate = baseData.currentVariableBorrowRate;
|
|
||||||
reserveData.stableBorrowRate = baseData.currentStableBorrowRate;
|
|
||||||
reserveData.lastUpdateTimestamp = baseData.lastUpdateTimestamp;
|
|
||||||
reserveData.aTokenAddress = baseData.aTokenAddress;
|
|
||||||
reserveData.stableDebtTokenAddress = baseData.stableDebtTokenAddress;
|
|
||||||
reserveData.variableDebtTokenAddress = baseData.variableDebtTokenAddress;
|
|
||||||
reserveData.interestRateStrategyAddress = baseData.interestRateStrategyAddress;
|
|
||||||
reserveData.priceInEth = oracle.getAssetPrice(reserveData.underlyingAsset);
|
|
||||||
|
|
||||||
reserveData.availableLiquidity = IERC20Detailed(reserveData.underlyingAsset).balanceOf(
|
|
||||||
reserveData.aTokenAddress
|
|
||||||
);
|
|
||||||
(
|
|
||||||
reserveData.totalPrincipalStableDebt,
|
|
||||||
,
|
|
||||||
reserveData.averageStableRate,
|
|
||||||
reserveData.stableDebtLastUpdateTimestamp
|
|
||||||
) = IStableDebtToken(reserveData.stableDebtTokenAddress).getSupplyData();
|
|
||||||
reserveData.totalScaledVariableDebt = IVariableDebtToken(reserveData.variableDebtTokenAddress)
|
|
||||||
.scaledTotalSupply();
|
|
||||||
|
|
||||||
// reserve configuration
|
|
||||||
|
|
||||||
// we're getting this info from the aToken, because some of assets can be not compliant with ETC20Detailed
|
|
||||||
reserveData.symbol = IERC20Detailed(reserveData.underlyingAsset).symbol();
|
|
||||||
reserveData.name = '';
|
|
||||||
|
|
||||||
(
|
|
||||||
reserveData.baseLTVasCollateral,
|
|
||||||
reserveData.reserveLiquidationThreshold,
|
|
||||||
reserveData.reserveLiquidationBonus,
|
|
||||||
reserveData.decimals,
|
|
||||||
reserveData.reserveFactor
|
|
||||||
) = baseData.configuration.getParamsMemory();
|
|
||||||
(
|
|
||||||
reserveData.isActive,
|
|
||||||
reserveData.isFrozen,
|
|
||||||
reserveData.borrowingEnabled,
|
|
||||||
reserveData.stableBorrowRateEnabled
|
|
||||||
) = baseData.configuration.getFlagsMemory();
|
|
||||||
reserveData.usageAsCollateralEnabled = reserveData.baseLTVasCollateral != 0;
|
|
||||||
(
|
|
||||||
reserveData.variableRateSlope1,
|
|
||||||
reserveData.variableRateSlope2,
|
|
||||||
reserveData.stableRateSlope1,
|
|
||||||
reserveData.stableRateSlope2
|
|
||||||
) = getInterestRateStrategySlopes(
|
|
||||||
DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (reservesData, oracle.getAssetPrice(MOCK_USD_ADDRESS));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserReservesData(ILendingPoolAddressesProvider provider, address user)
|
function getUserReservesData(ILendingPoolAddressesProvider provider, address user)
|
||||||
|
@ -192,6 +129,7 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
|
||||||
uint256
|
uint256
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
IAaveOracle oracle = IAaveOracle(provider.getPriceOracle());
|
||||||
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
|
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
|
||||||
address[] memory reserves = lendingPool.getReservesList();
|
address[] memory reserves = lendingPool.getReservesList();
|
||||||
DataTypes.UserConfigurationMap memory userConfig = lendingPool.getUserConfiguration(user);
|
DataTypes.UserConfigurationMap memory userConfig = lendingPool.getUserConfiguration(user);
|
||||||
|
@ -300,4 +238,73 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
|
||||||
oracle.getAssetPrice(MOCK_USD_ADDRESS),
|
oracle.getAssetPrice(MOCK_USD_ADDRESS),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _getReserveData(IAaveOracle oracle, ILendingPool lendingPool) private returns (AggregatedReserveData[] memory) {
|
||||||
|
AggregatedReserveData[] memory reservesData = new AggregatedReserveData[](reserves.length);
|
||||||
|
|
||||||
|
for (uint256 i = 0; i < reserves.length; i++) {
|
||||||
|
AggregatedReserveData memory reserveData = reservesData[i];
|
||||||
|
reserveData.underlyingAsset = reserves[i];
|
||||||
|
|
||||||
|
// reserve current state
|
||||||
|
DataTypes.ReserveData memory baseData =
|
||||||
|
lendingPool.getReserveData(reserveData.underlyingAsset);
|
||||||
|
reserveData.liquidityIndex = baseData.liquidityIndex;
|
||||||
|
reserveData.variableBorrowIndex = baseData.variableBorrowIndex;
|
||||||
|
reserveData.liquidityRate = baseData.currentLiquidityRate;
|
||||||
|
reserveData.variableBorrowRate = baseData.currentVariableBorrowRate;
|
||||||
|
reserveData.stableBorrowRate = baseData.currentStableBorrowRate;
|
||||||
|
reserveData.lastUpdateTimestamp = baseData.lastUpdateTimestamp;
|
||||||
|
reserveData.aTokenAddress = baseData.aTokenAddress;
|
||||||
|
reserveData.stableDebtTokenAddress = baseData.stableDebtTokenAddress;
|
||||||
|
reserveData.variableDebtTokenAddress = baseData.variableDebtTokenAddress;
|
||||||
|
reserveData.interestRateStrategyAddress = baseData.interestRateStrategyAddress;
|
||||||
|
// TODO: change naming to base something
|
||||||
|
reserveData.priceInEth = oracle.getAssetPrice(reserveData.underlyingAsset);
|
||||||
|
|
||||||
|
reserveData.availableLiquidity = IERC20Detailed(reserveData.underlyingAsset).balanceOf(
|
||||||
|
reserveData.aTokenAddress
|
||||||
|
);
|
||||||
|
(
|
||||||
|
reserveData.totalPrincipalStableDebt,
|
||||||
|
,
|
||||||
|
reserveData.averageStableRate,
|
||||||
|
reserveData.stableDebtLastUpdateTimestamp
|
||||||
|
) = IStableDebtToken(reserveData.stableDebtTokenAddress).getSupplyData();
|
||||||
|
reserveData.totalScaledVariableDebt = IVariableDebtToken(reserveData.variableDebtTokenAddress)
|
||||||
|
.scaledTotalSupply();
|
||||||
|
|
||||||
|
// reserve configuration
|
||||||
|
|
||||||
|
// we're getting this info from the aToken, because some of assets can be not compliant with ETC20Detailed
|
||||||
|
reserveData.symbol = IERC20Detailed(reserveData.underlyingAsset).symbol();
|
||||||
|
reserveData.name = '';
|
||||||
|
|
||||||
|
(
|
||||||
|
reserveData.baseLTVasCollateral,
|
||||||
|
reserveData.reserveLiquidationThreshold,
|
||||||
|
reserveData.reserveLiquidationBonus,
|
||||||
|
reserveData.decimals,
|
||||||
|
reserveData.reserveFactor
|
||||||
|
) = baseData.configuration.getParamsMemory();
|
||||||
|
(
|
||||||
|
reserveData.isActive,
|
||||||
|
reserveData.isFrozen,
|
||||||
|
reserveData.borrowingEnabled,
|
||||||
|
reserveData.stableBorrowRateEnabled
|
||||||
|
) = baseData.configuration.getFlagsMemory();
|
||||||
|
reserveData.usageAsCollateralEnabled = reserveData.baseLTVasCollateral != 0;
|
||||||
|
(
|
||||||
|
reserveData.variableRateSlope1,
|
||||||
|
reserveData.variableRateSlope2,
|
||||||
|
reserveData.stableRateSlope1,
|
||||||
|
reserveData.stableRateSlope2
|
||||||
|
) = getInterestRateStrategySlopes(
|
||||||
|
DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return reserveData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
18
contracts/misc/interfaces/IAaveOracle.sol
Normal file
18
contracts/misc/interfaces/IAaveOracle.sol
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
// SPDX-License-Identifier: agpl-3.0
|
||||||
|
pragma solidity 0.6.12;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title IAaveOracle interface
|
||||||
|
* @notice Interface for the Aave oracle.
|
||||||
|
**/
|
||||||
|
|
||||||
|
interface IAaveOracle {
|
||||||
|
address public immutable BASE_CURRENCY;
|
||||||
|
uint256 public immutable BASE_CURRENCY_UNIT;
|
||||||
|
address public immutable WETH;
|
||||||
|
|
||||||
|
/***********
|
||||||
|
@dev returns the asset price in ETH
|
||||||
|
*/
|
||||||
|
function getAssetPrice(address asset) external view returns (uint256);
|
||||||
|
}
|
58
contracts/misc/interfaces/IUiIncentiveDataprovider.sol
Normal file
58
contracts/misc/interfaces/IUiIncentiveDataprovider.sol
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
// SPDX-License-Identifier: agpl-3.0
|
||||||
|
pragma solidity 0.6.12;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
|
||||||
|
|
||||||
|
interface IUiIncentiveDataProvider {
|
||||||
|
struct AggregatedReserveIncentiveData {
|
||||||
|
address underlyingAsset;
|
||||||
|
IncentiveData aIncentiveData;
|
||||||
|
IncentiveData vIncentiveData;
|
||||||
|
IncentiveData sIncentiveData;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct IncentiveData {
|
||||||
|
uint256 emissionPerSecond;
|
||||||
|
uint256 incentivesLastUpdateTimestamp;
|
||||||
|
uint256 tokenIncentivesIndex;
|
||||||
|
uint256 emissionEndTimestamp;
|
||||||
|
address tokenAddress;
|
||||||
|
address rewardTokenAddress;
|
||||||
|
address incentiveControllerAddress;
|
||||||
|
uint8 rewardTokenDecimals;
|
||||||
|
uint8 precision;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct UserReserveIncentiveData {
|
||||||
|
address underlyingAsset;
|
||||||
|
UserIncentiveData aTokenIncentivesUserData;
|
||||||
|
UserIncentiveData vTokenIncentivesUserData;
|
||||||
|
UserIncentiveData sTokenIncentivesUserData;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct UserIncentiveData {
|
||||||
|
uint256 tokenincentivesUserIndex;
|
||||||
|
uint256 userUnclaimedRewards;
|
||||||
|
address tokenAddress;
|
||||||
|
address rewardTokenAddress;
|
||||||
|
address incentiveControllerAddress;
|
||||||
|
uint8 rewardTokenDecimals;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getReservesIncentivesData(ILendingPoolAddressesProvider provider)
|
||||||
|
external
|
||||||
|
view
|
||||||
|
returns (AggregatedReserveIncentiveData[] memory);
|
||||||
|
|
||||||
|
function getUserReservesIncentivesData(ILendingPoolAddressesProvider provider, address user)
|
||||||
|
external
|
||||||
|
view
|
||||||
|
returns (UserReserveIncentiveData[] memory);
|
||||||
|
|
||||||
|
// generic method with full data
|
||||||
|
function getFullReservesIncentiveData(ILendingPoolAddressesProvider provider, address user)
|
||||||
|
external
|
||||||
|
view
|
||||||
|
returns (AggregatedReserveIncentiveData[] memory, UserReserveIncentiveData[] memory);
|
||||||
|
}
|
|
@ -51,6 +51,7 @@ import {
|
||||||
WETH9MockedFactory,
|
WETH9MockedFactory,
|
||||||
WETHGatewayFactory,
|
WETHGatewayFactory,
|
||||||
FlashLiquidationAdapterFactory,
|
FlashLiquidationAdapterFactory,
|
||||||
|
UiIncentiveDataProviderFactory,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import {
|
import {
|
||||||
withSaveAndVerify,
|
withSaveAndVerify,
|
||||||
|
@ -69,6 +70,14 @@ import { LendingPoolLibraryAddresses } from '../types/LendingPoolFactory';
|
||||||
import { UiPoolDataProvider } from '../types';
|
import { UiPoolDataProvider } from '../types';
|
||||||
import { eNetwork } from './types';
|
import { eNetwork } from './types';
|
||||||
|
|
||||||
|
export const deployUiIncentiveDataProvider = async (verify?: boolean) =>
|
||||||
|
withSaveAndVerify(
|
||||||
|
await new UiIncentiveDataProviderFactory(await getFirstSigner()).deploy(),
|
||||||
|
eContractid.UiIncentiveDataProvider,
|
||||||
|
[],
|
||||||
|
verify
|
||||||
|
);
|
||||||
|
|
||||||
export const deployUiPoolDataProvider = async (
|
export const deployUiPoolDataProvider = async (
|
||||||
[incentivesController, aaveOracle]: [tEthereumAddress, tEthereumAddress],
|
[incentivesController, aaveOracle]: [tEthereumAddress, tEthereumAddress],
|
||||||
verify?: boolean
|
verify?: boolean
|
||||||
|
|
|
@ -98,6 +98,7 @@ export enum eContractid {
|
||||||
MockParaSwapAugustus = 'MockParaSwapAugustus',
|
MockParaSwapAugustus = 'MockParaSwapAugustus',
|
||||||
MockParaSwapAugustusRegistry = 'MockParaSwapAugustusRegistry',
|
MockParaSwapAugustusRegistry = 'MockParaSwapAugustusRegistry',
|
||||||
ParaSwapLiquiditySwapAdapter = 'ParaSwapLiquiditySwapAdapter',
|
ParaSwapLiquiditySwapAdapter = 'ParaSwapLiquiditySwapAdapter',
|
||||||
|
UiIncentiveDataProvider = 'UiIncentiveDataProvider',
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -14793,7 +14793,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ethereumjs-abi": {
|
"ethereumjs-abi": {
|
||||||
"version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#ee3994657fa7a427238e6ba92a84d0b529bbcde0",
|
"version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#1a27c59c15ab1e95ee8e5c4ed6ad814c49cc439e",
|
||||||
"from": "git+https://github.com/ethereumjs/ethereumjs-abi.git",
|
"from": "git+https://github.com/ethereumjs/ethereumjs-abi.git",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
|
|
@ -76,6 +76,10 @@
|
||||||
"matic:deployUIProvider": "hardhat --network matic deploy-UiPoolDataProvider",
|
"matic:deployUIProvider": "hardhat --network matic deploy-UiPoolDataProvider",
|
||||||
"mumbai:deployUIProvider": "hardhat --network mumbai deploy-UiPoolDataProvider",
|
"mumbai:deployUIProvider": "hardhat --network mumbai deploy-UiPoolDataProvider",
|
||||||
"fuji:deployUIProvider": "hardhat --network fuji deploy-UiPoolDataProvider",
|
"fuji:deployUIProvider": "hardhat --network fuji deploy-UiPoolDataProvider",
|
||||||
|
"dev:deployUIIncentivesProvider": "hardhat --network kovan deploy-UiIncentiveDataProvider --verify",
|
||||||
|
"main:deployUIIncentivesProvider": "hardhat --network main deploy-UiIncentiveDataProvider --verify",
|
||||||
|
"matic:deployUIIncentivesProvider": "hardhat --network matic deploy-UiIncentiveDataProvider --verify",
|
||||||
|
"mumbai:deployUIIncentivesProvider": "hardhat --network mumbai deploy-UiIncentiveDataProvider --verify",
|
||||||
"dev:deployUniswapRepayAdapter": "hardhat --network kovan deploy-UniswapRepayAdapter --provider 0x88757f2f99175387aB4C6a4b3067c77A695b0349 --router 0xfcd87315f0e4067070ade8682fcdbc3006631441 --weth 0xd0a1e359811322d97991e03f863a0c30c2cf029c",
|
"dev:deployUniswapRepayAdapter": "hardhat --network kovan deploy-UniswapRepayAdapter --provider 0x88757f2f99175387aB4C6a4b3067c77A695b0349 --router 0xfcd87315f0e4067070ade8682fcdbc3006631441 --weth 0xd0a1e359811322d97991e03f863a0c30c2cf029c",
|
||||||
"dev:UniswapLiquiditySwapAdapter": "hardhat --network kovan deploy-UniswapLiquiditySwapAdapter --provider 0x88757f2f99175387aB4C6a4b3067c77A695b0349 --router 0xfcd87315f0e4067070ade8682fcdbc3006631441 --weth 0xd0a1e359811322d97991e03f863a0c30c2cf029c",
|
"dev:UniswapLiquiditySwapAdapter": "hardhat --network kovan deploy-UniswapLiquiditySwapAdapter --provider 0x88757f2f99175387aB4C6a4b3067c77A695b0349 --router 0xfcd87315f0e4067070ade8682fcdbc3006631441 --weth 0xd0a1e359811322d97991e03f863a0c30c2cf029c",
|
||||||
"main:deployUniswapRepayAdapter": "hardhat --network main deploy-UniswapRepayAdapter --provider 0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5 --router 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D --weth 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"main:deployUniswapRepayAdapter": "hardhat --network main deploy-UniswapRepayAdapter --provider 0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5 --router 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D --weth 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
|
|
23
tasks/deployments/deploy-UiIncentiveDataProvider.ts
Normal file
23
tasks/deployments/deploy-UiIncentiveDataProvider.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import { task } from 'hardhat/config';
|
||||||
|
import { eContractid, eEthereumNetwork, eNetwork, ePolygonNetwork } from '../../helpers/types';
|
||||||
|
import { deployUiIncentiveDataProvider } from '../../helpers/contracts-deployments';
|
||||||
|
import { exit } from 'process';
|
||||||
|
|
||||||
|
task(
|
||||||
|
`deploy-${eContractid.UiIncentiveDataProvider}`,
|
||||||
|
`Deploys the UiIncentiveDataProvider contract`
|
||||||
|
)
|
||||||
|
.addFlag('verify', 'Verify UiIncentiveDataProvider contract via Etherscan API.')
|
||||||
|
.setAction(async ({ verify }, localBRE) => {
|
||||||
|
await localBRE.run('set-DRE');
|
||||||
|
if (!localBRE.network.config.chainId) {
|
||||||
|
throw new Error('INVALID_CHAIN_ID');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`\n- UiIncentiveDataProvider deployment`);
|
||||||
|
|
||||||
|
const uiIncentiveDataProvider = await deployUiIncentiveDataProvider(verify);
|
||||||
|
|
||||||
|
console.log('UiPoolDataProvider deployed at:', uiIncentiveDataProvider.address);
|
||||||
|
console.log(`\tFinished UiPoolDataProvider deployment`);
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user