feat: bring incentive into its own data provider

This commit is contained in:
Josh Stevens 2021-09-01 13:02:15 +01:00
parent 025a988a13
commit afa025265b
4 changed files with 256 additions and 142 deletions

View File

@ -0,0 +1,192 @@
// 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';
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)
{
AggregatedReserveIncentiveData[] memory reservesIncentivesData =
_getReservesIncentivesData(provider);
UserReserveIncentiveData[] memory userReservesIncentivesData =
_getUserReservesIncentivesData(provider, user);
return (reservesIncentivesData, userReservesIncentivesData);
}
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]);
IAaveIncentivesController aTokenIncentiveController =
IAToken(baseData.aTokenAddress).getIncentivesController();
(
uint256 aEmissionPerSecond,
uint256 aIncentivesLastUpdateTimestamp,
uint256 aTokenIncentivesIndex
) = aTokenIncentiveController.assets(baseData.aTokenAddress);
reserveIncentiveData.aIncentiveData = IncentiveData(
aEmissionPerSecond,
aIncentivesLastUpdateTimestamp,
aTokenIncentivesIndex,
aTokenIncentiveController.DISTRIBUTION_END(),
baseData.aTokenAddress,
aTokenIncentiveController.REWARD_TOKEN()
);
IAaveIncentivesController sTokenIncentiveController =
IStableDebtToken(baseData.stableDebtTokenAddress).getIncentivesController();
(
uint256 sEmissionPerSecond,
uint256 sIncentivesLastUpdateTimestamp,
uint256 sTokenIncentivesIndex
) = sTokenIncentiveController.assets(baseData.stableDebtTokenAddress);
reserveIncentiveData.sIncentiveData = IncentiveData(
sEmissionPerSecond,
sIncentivesLastUpdateTimestamp,
sTokenIncentivesIndex,
sTokenIncentiveController.DISTRIBUTION_END(),
baseData.stableDebtTokenAddress,
sTokenIncentiveController.REWARD_TOKEN()
);
IAaveIncentivesController vTokenIncentiveController =
IVariableDebtToken(baseData.variableDebtTokenAddress).getIncentivesController();
(
uint256 vEmissionPerSecond,
uint256 vIncentivesLastUpdateTimestamp,
uint256 vTokenIncentivesIndex
) = vTokenIncentiveController.assets(baseData.variableDebtTokenAddress);
reserveIncentiveData.vIncentiveData = IncentiveData(
vEmissionPerSecond,
vIncentivesLastUpdateTimestamp,
vTokenIncentivesIndex,
vTokenIncentiveController.DISTRIBUTION_END(),
baseData.variableDebtTokenAddress,
vTokenIncentiveController.REWARD_TOKEN()
);
}
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];
IAaveIncentivesController aTokenIncentiveController =
IAToken(baseData.aTokenAddress).getIncentivesController();
IUiIncentiveDataProvider.UserIncentiveData memory aUserIncentiveData;
aUserIncentiveData.tokenIncentivesUserData = aTokenIncentiveController.getUserAssetData(
user,
baseData.aTokenAddress
);
aUserIncentiveData.userUnclaimedRewards = aTokenIncentiveController.getUserUnclaimedRewards(
user
);
aUserIncentiveData.tokenAddress = baseData.aTokenAddress;
aUserIncentiveData.rewardTokenAddress = aTokenIncentiveController.REWARD_TOKEN();
userReservesIncentivesData[i].aTokenIncentivesUserData = aUserIncentiveData;
IAaveIncentivesController vTokenIncentiveController =
IVariableDebtToken(baseData.variableDebtTokenAddress).getIncentivesController();
UserIncentiveData memory vUserIncentiveData;
vUserIncentiveData.tokenIncentivesUserData = vTokenIncentiveController.getUserAssetData(
user,
baseData.variableDebtTokenAddress
);
vUserIncentiveData.userUnclaimedRewards = vTokenIncentiveController.getUserUnclaimedRewards(
user
);
vUserIncentiveData.tokenAddress = baseData.variableDebtTokenAddress;
vUserIncentiveData.rewardTokenAddress = vTokenIncentiveController.REWARD_TOKEN();
userReservesIncentivesData[i].vTokenIncentivesUserData = vUserIncentiveData;
IAaveIncentivesController sTokenIncentiveController =
IStableDebtToken(baseData.stableDebtTokenAddress).getIncentivesController();
UserIncentiveData memory sUserIncentiveData;
sUserIncentiveData.tokenIncentivesUserData = sTokenIncentiveController.getUserAssetData(
user,
baseData.stableDebtTokenAddress
);
sUserIncentiveData.userUnclaimedRewards = sTokenIncentiveController.getUserUnclaimedRewards(
user
);
sUserIncentiveData.tokenAddress = baseData.stableDebtTokenAddress;
sUserIncentiveData.rewardTokenAddress = sTokenIncentiveController.REWARD_TOKEN();
userReservesIncentivesData[i].sTokenIncentivesUserData = sUserIncentiveData;
}
return (userReservesIncentivesData);
}
}

View File

@ -4,7 +4,6 @@ pragma experimental ABIEncoderV2;
import {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detailed.sol';
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
import {IAaveIncentivesController} from '../interfaces/IAaveIncentivesController.sol';
import {IUiPoolDataProvider} from './interfaces/IUiPoolDataProvider.sol';
import {ILendingPool} from '../interfaces/ILendingPool.sol';
import {IPriceOracleGetter} from '../interfaces/IPriceOracleGetter.sol';
@ -25,11 +24,9 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
using UserConfiguration for DataTypes.UserConfigurationMap;
address public constant MOCK_USD_ADDRESS = 0x10F7Fc1F91Ba351f9C629c5947AD69bD03C05b96;
IAaveIncentivesController public immutable override incentivesController;
IPriceOracleGetter public immutable oracle;
constructor(IAaveIncentivesController _incentivesController, IPriceOracleGetter _oracle) public {
incentivesController = _incentivesController;
constructor(IPriceOracleGetter _oracle) public {
oracle = _oracle;
}
@ -65,11 +62,7 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
public
view
override
returns (
AggregatedReserveData[] memory,
uint256,
uint256
)
returns (AggregatedReserveData[] memory, uint256)
{
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
address[] memory reserves = lendingPool.getReservesList();
@ -134,45 +127,16 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
) = getInterestRateStrategySlopes(
DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress)
);
// incentives
if (address(0) != address(incentivesController)) {
(
reserveData.aEmissionPerSecond,
reserveData.aIncentivesLastUpdateTimestamp,
reserveData.aTokenIncentivesIndex
// ) = incentivesController.getAssetData(reserveData.aTokenAddress); TODO: temp fix
) = incentivesController.assets(reserveData.aTokenAddress);
(
reserveData.sEmissionPerSecond,
reserveData.sIncentivesLastUpdateTimestamp,
reserveData.sTokenIncentivesIndex
// ) = incentivesController.getAssetData(reserveData.stableDebtTokenAddress); TODO: temp fix
) = incentivesController.assets(reserveData.stableDebtTokenAddress);
(
reserveData.vEmissionPerSecond,
reserveData.vIncentivesLastUpdateTimestamp,
reserveData.vTokenIncentivesIndex
// ) = incentivesController.getAssetData(reserveData.variableDebtTokenAddress); TODO: temp fix
) = incentivesController.assets(reserveData.variableDebtTokenAddress);
}
}
uint256 emissionEndTimestamp;
if (address(0) != address(incentivesController)) {
emissionEndTimestamp = incentivesController.DISTRIBUTION_END();
}
return (reservesData, oracle.getAssetPrice(MOCK_USD_ADDRESS), emissionEndTimestamp);
return (reservesData, oracle.getAssetPrice(MOCK_USD_ADDRESS));
}
function getUserReservesData(ILendingPoolAddressesProvider provider, address user)
external
view
override
returns (UserReserveData[] memory, uint256)
returns (UserReserveData[] memory)
{
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
address[] memory reserves = lendingPool.getReservesList();
@ -183,21 +147,7 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
for (uint256 i = 0; i < reserves.length; i++) {
DataTypes.ReserveData memory baseData = lendingPool.getReserveData(reserves[i]);
// incentives
if (address(0) != address(incentivesController)) {
userReservesData[i].aTokenincentivesUserIndex = incentivesController.getUserAssetData(
user,
baseData.aTokenAddress
);
userReservesData[i].vTokenincentivesUserIndex = incentivesController.getUserAssetData(
user,
baseData.variableDebtTokenAddress
);
userReservesData[i].sTokenincentivesUserIndex = incentivesController.getUserAssetData(
user,
baseData.stableDebtTokenAddress
);
}
// user reserve data
userReservesData[i].underlyingAsset = reserves[i];
userReservesData[i].scaledATokenBalance = IAToken(baseData.aTokenAddress).scaledBalanceOf(
@ -225,12 +175,7 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
}
}
uint256 userUnclaimedRewards;
if (address(0) != address(incentivesController)) {
userUnclaimedRewards = incentivesController.getUserUnclaimedRewards(user);
}
return (userReservesData, userUnclaimedRewards);
return (userReservesData);
}
function getReservesData(ILendingPoolAddressesProvider provider, address user)
@ -240,8 +185,7 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
returns (
AggregatedReserveData[] memory,
UserReserveData[] memory,
uint256,
IncentivesControllerData memory
uint256
)
{
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
@ -312,46 +256,7 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress)
);
// incentives
if (address(0) != address(incentivesController)) {
(
reserveData.aTokenIncentivesIndex,
reserveData.aEmissionPerSecond,
reserveData.aIncentivesLastUpdateTimestamp
// ) = incentivesController.getAssetData(reserveData.aTokenAddress); TODO: temp fix
) = incentivesController.assets(reserveData.aTokenAddress);
(
reserveData.sTokenIncentivesIndex,
reserveData.sEmissionPerSecond,
reserveData.sIncentivesLastUpdateTimestamp
// ) = incentivesController.getAssetData(reserveData.stableDebtTokenAddress); TODO: temp fix
) = incentivesController.assets(reserveData.stableDebtTokenAddress);
(
reserveData.vTokenIncentivesIndex,
reserveData.vEmissionPerSecond,
reserveData.vIncentivesLastUpdateTimestamp
// ) = incentivesController.getAssetData(reserveData.variableDebtTokenAddress); TODO: temp fix
) = incentivesController.assets(reserveData.variableDebtTokenAddress);
}
if (user != address(0)) {
// incentives
if (address(0) != address(incentivesController)) {
userReservesData[i].aTokenincentivesUserIndex = incentivesController.getUserAssetData(
user,
reserveData.aTokenAddress
);
userReservesData[i].vTokenincentivesUserIndex = incentivesController.getUserAssetData(
user,
reserveData.variableDebtTokenAddress
);
userReservesData[i].sTokenincentivesUserIndex = incentivesController.getUserAssetData(
user,
reserveData.stableDebtTokenAddress
);
}
// user reserve data
userReservesData[i].underlyingAsset = reserveData.underlyingAsset;
userReservesData[i].scaledATokenBalance = IAToken(reserveData.aTokenAddress)
@ -385,21 +290,6 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
}
}
IncentivesControllerData memory incentivesControllerData;
if (address(0) != address(incentivesController)) {
if (user != address(0)) {
incentivesControllerData.userUnclaimedRewards = incentivesController
.getUserUnclaimedRewards(user);
}
incentivesControllerData.emissionEndTimestamp = incentivesController.DISTRIBUTION_END();
}
return (
reservesData,
userReservesData,
oracle.getAssetPrice(MOCK_USD_ADDRESS),
incentivesControllerData
);
return (reservesData, userReservesData, oracle.getAssetPrice(MOCK_USD_ADDRESS));
}
}

View File

@ -0,0 +1,53 @@
// 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;
}
struct UserReserveIncentiveData {
address underlyingAsset;
UserIncentiveData aTokenIncentivesUserData;
UserIncentiveData vTokenIncentivesUserData;
UserIncentiveData sTokenIncentivesUserData;
}
struct UserIncentiveData {
uint256 tokenIncentivesUserData;
uint256 userUnclaimedRewards;
address tokenAddress;
address rewardTokenAddress;
}
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);
}

View File

@ -42,16 +42,6 @@ interface IUiPoolDataProvider {
uint256 variableRateSlope2;
uint256 stableRateSlope1;
uint256 stableRateSlope2;
// incentives
uint256 aEmissionPerSecond;
uint256 vEmissionPerSecond;
uint256 sEmissionPerSecond;
uint256 aIncentivesLastUpdateTimestamp;
uint256 vIncentivesLastUpdateTimestamp;
uint256 sIncentivesLastUpdateTimestamp;
uint256 aTokenIncentivesIndex;
uint256 vTokenIncentivesIndex;
uint256 sTokenIncentivesIndex;
}
struct UserReserveData {
@ -62,10 +52,6 @@ interface IUiPoolDataProvider {
uint256 scaledVariableDebt;
uint256 principalStableDebt;
uint256 stableBorrowLastUpdateTimestamp;
// incentives
uint256 aTokenincentivesUserIndex;
uint256 vTokenincentivesUserIndex;
uint256 sTokenincentivesUserIndex;
}
struct IncentivesControllerData {
@ -78,24 +64,18 @@ interface IUiPoolDataProvider {
view
returns (address[] memory);
function incentivesController() external view returns (IAaveIncentivesController);
function getSimpleReservesData(ILendingPoolAddressesProvider provider)
external
view
returns (
AggregatedReserveData[] memory,
uint256, // usd price eth
uint256 // emission end timestamp
uint256 // usd price eth
);
function getUserReservesData(ILendingPoolAddressesProvider provider, address user)
external
view
returns (
UserReserveData[] memory,
uint256 // user unclaimed rewards
);
returns (UserReserveData[] memory);
// generic method with full data
function getReservesData(ILendingPoolAddressesProvider provider, address user)
@ -104,7 +84,6 @@ interface IUiPoolDataProvider {
returns (
AggregatedReserveData[] memory,
UserReserveData[] memory,
uint256,
IncentivesControllerData memory
uint256
);
}