From e81ddb4e2f66039a819183027dafd36bd609965f Mon Sep 17 00:00:00 2001 From: sendra Date: Mon, 29 Mar 2021 17:10:35 +0200 Subject: [PATCH] Added incentives information to UI data provider contract --- .../interfaces/IAaveIncentivesController.sol | 6 ++ contracts/misc/UiPoolDataProvider.sol | 91 +++++++++++-------- .../misc/interfaces/IUiPoolDataProvider.sol | 33 +++++-- 3 files changed, 85 insertions(+), 45 deletions(-) diff --git a/contracts/interfaces/IAaveIncentivesController.sol b/contracts/interfaces/IAaveIncentivesController.sol index 5125ac7b..8e9c74a7 100644 --- a/contracts/interfaces/IAaveIncentivesController.sol +++ b/contracts/interfaces/IAaveIncentivesController.sol @@ -11,6 +11,8 @@ interface IAaveIncentivesController { function REWARD_TOKEN() external view returns (address rewardToken); + function PRECISION() external view returns (uint8); + function assets(address underlying) external view returns (AssetData memory assets); function handleAction( @@ -23,4 +25,8 @@ interface IAaveIncentivesController { external view returns (uint256); + + function getUserUnclaimedRewards(address _user) external view returns (uint256); + + function getUserAssetData(address user, address asset) external view returns (uint256); } diff --git a/contracts/misc/UiPoolDataProvider.sol b/contracts/misc/UiPoolDataProvider.sol index aff0c92d..28b0da0b 100644 --- a/contracts/misc/UiPoolDataProvider.sol +++ b/contracts/misc/UiPoolDataProvider.sol @@ -46,7 +46,7 @@ contract UiPoolDataProvider is IUiPoolDataProvider { function getReservesData( ILendingPoolAddressesProvider provider, - IAaveIncentivesController incentivesControllerAddr, + IAaveIncentivesController incentivesController, address user ) external @@ -55,7 +55,8 @@ contract UiPoolDataProvider is IUiPoolDataProvider { returns ( AggregatedReserveData[] memory, UserReserveData[] memory, - uint256 + uint256, + IncentivesDataUser memory ) { ILendingPool lendingPool = ILendingPool(provider.getLendingPool()); @@ -128,19 +129,54 @@ contract UiPoolDataProvider is IUiPoolDataProvider { ); // incentives + // IncentivesAssetData memory aTokenIncentives = incentivesController.assets(reserveData.aTokenAddress); reserveData.aEmissionPerSecond = incentivesController .assets(reserveData.aTokenAddress) .emissionPerSecond; + reserveData.aIncentivesLastUpdateTimestamp = incentivesController + .assets(reserveData.aTokenAddress) + .lastUpdateTimestamp; + reserveData.aTokenIncentivesIndex = incentivesController + .assets(reserveData.aTokenAddress) + .index; - reserveData.vEmissionPerSecond = incentivesController - .assets(reserveData.variableDebtTokenAddress) - .emissionPerSecond; - + // IncentivesAssetData memory sTokenIncentives = incentivesController.assets(reserveData.stableDebtTokenAddress); reserveData.sEmissionPerSecond = incentivesController .assets(reserveData.stableDebtTokenAddress) .emissionPerSecond; + reserveData.sIncentivesLastUpdateTimestamp = incentivesController + .assets(reserveData.stableDebtTokenAddress) + .lastUpdateTimestamp; + reserveData.sTokenIncentivesIndex = incentivesController + .assets(reserveData.stableDebtTokenAddress) + .index; + + // IncentivesAssetData memory vTokenIncentives = incentivesController.assets(reserveData.variableDebtTokenAddress); + reserveData.vEmissionPerSecond = incentivesController + .assets(reserveData.variableDebtTokenAddress) + .emissionPerSecond; + reserveData.vIncentivesLastUpdateTimestamp = incentivesController + .assets(reserveData.variableDebtTokenAddress) + .lastUpdateTimestamp; + reserveData.vTokenIncentivesIndex = incentivesController + .assets(reserveData.variableDebtTokenAddress) + .index; if (user != address(0)) { + // incentives + // userIncentives.incentivesLastUpdated = + userReservesData[i].aTokenincentivesUserIndex = incentivesController.getUserAssetData( + user, + reserveData.aTokenAddress + ); + userReservesData[i].sTokenincentivesUserIndex = incentivesController.getUserAssetData( + user, + reserveData.stableDebtTokenAddress + ); + userReservesData[i].vTokenincentivesUserIndex = incentivesController.getUserAssetData( + user, + reserveData.variableDebtTokenAddress + ); // user reserve data userReservesData[i].underlyingAsset = reserveData.underlyingAsset; userReservesData[i].scaledATokenBalance = IAToken(reserveData.aTokenAddress) @@ -174,40 +210,21 @@ contract UiPoolDataProvider is IUiPoolDataProvider { } } - return (reservesData, userReservesData, oracle.getAssetPrice(MOCK_USD_ADDRESS)); - } - - function getUserIncentivesBalance( - ILendingPoolAddressesProvider provider, - IAaveIncentivesController incentivesControllerAddr, - address user - ) external view override returns (IncentivesDataUser memory) { - ILendingPool lendingPool = ILendingPool(provider.getLendingPool()); - IPriceOracleGetter oracle = IPriceOracleGetter(provider.getPriceOracle()); - address[] memory reserves = lendingPool.getReservesList(); - - // array of atokens that have incentives - address[] memory incentivesATokens = new address[](user != address(0) ? reserves.length : 0); - - for (uint256 i = 0; i < reserves.length; i++) { - DataTypes.ReserveData memory baseData = lendingPool.getReserveData(reserves[i]); - if (user != address(0)) { - incentivesATokens[i] = baseData.aTokenAddress; - } - } - - IncentivesDataUser memory userRewardsBalance; + IncentivesDataUser memory incentivesDataUser; if (user != address(0)) { - userRewardsBalance.rewardToken = incentivesController.REWARD_TOKEN(); - userRewardsBalance.claimableRewards = incentivesController.getRewardsBalance( - incentivesATokens, - user - ); - userRewardsBalance.rewardTokenDecimals = IERC20Detailed(userRewardsBalance.rewardToken) + incentivesDataUser.userUnclaimedRewards = incentivesController.getUserUnclaimedRewards(user); + incentivesDataUser.rewardToken = incentivesController.REWARD_TOKEN(); + incentivesDataUser.precision = incentivesController.PRECISION(); + incentivesDataUser.rewardTokenDecimals = IERC20Detailed(incentivesDataUser.rewardToken) .decimals(); - userRewardsBalance.rewardTokenPriceEth = oracle.getAssetPrice(userRewardsBalance.rewardToken); + incentivesDataUser.rewardTokenPriceEth = oracle.getAssetPrice(incentivesDataUser.rewardToken); } - return (userRewardsBalance); + return ( + reservesData, + userReservesData, + oracle.getAssetPrice(MOCK_USD_ADDRESS), + incentivesDataUser + ); } } diff --git a/contracts/misc/interfaces/IUiPoolDataProvider.sol b/contracts/misc/interfaces/IUiPoolDataProvider.sol index 41519611..9ad0c8c4 100644 --- a/contracts/misc/interfaces/IUiPoolDataProvider.sol +++ b/contracts/misc/interfaces/IUiPoolDataProvider.sol @@ -46,14 +46,20 @@ interface IUiPoolDataProvider { uint128 aEmissionPerSecond; uint128 vEmissionPerSecond; uint128 sEmissionPerSecond; + uint256 aIncentivesLastUpdateTimestamp; + uint256 vIncentivesLastUpdateTimestamp; + uint256 sIncentivesLastUpdateTimestamp; + uint256 aTokenIncentivesIndex; + uint256 vTokenIncentivesIndex; + uint256 sTokenIncentivesIndex; } struct IncentivesDataUser { address rewardToken; - uint256 claimableRewards; + uint256 userUnclaimedRewards; uint256 rewardTokenDecimals; uint256 rewardTokenPriceEth; - uint128 emissionPerSecond; + uint8 precision; } // @@ -70,6 +76,16 @@ interface IUiPoolDataProvider { uint256 scaledVariableDebt; uint256 principalStableDebt; uint256 stableBorrowLastUpdateTimestamp; + // incentives + uint256 aTokenincentivesUserIndex; + uint256 vTokenincentivesUserIndex; + uint256 sTokenincentivesUserIndex; + } + + struct IncentivesAssetData { + uint128 emissionPerSecond; + uint128 lastUpdateTimestamp; + uint256 index; } // @@ -91,14 +107,15 @@ interface IUiPoolDataProvider { returns ( AggregatedReserveData[] memory, UserReserveData[] memory, - uint256 + uint256, + IncentivesDataUser memory ); - function getUserIncentivesBalance( - ILendingPoolAddressesProvider provider, - IAaveIncentivesController incentives, - address user - ) external view returns (IncentivesDataUser memory); + // function getUserIncentivesBalance( + // ILendingPoolAddressesProvider provider, + // IAaveIncentivesController incentives, + // address user + // ) external view returns (IncentivesDataUser memory); // function getUserReservesData(ILendingPoolAddressesProvider provider, address user) // external