mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Added incentives information to UI data provider contract
This commit is contained in:
parent
2028631ad7
commit
e81ddb4e2f
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user