Skip to content

Commit 644350c

Browse files
authored
Merge pull request #61 from aave/feat/update-dataproviderhelper-incentives
Added incentives data to ui helper
2 parents 4b8fabf + c1c2cff commit 644350c

File tree

7 files changed

+405
-183
lines changed

7 files changed

+405
-183
lines changed

contracts/interfaces/IAaveIncentivesController.sol

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,126 @@ pragma solidity 0.6.12;
33
pragma experimental ABIEncoderV2;
44

55
interface IAaveIncentivesController {
6+
event RewardsAccrued(address indexed user, uint256 amount);
7+
8+
event RewardsClaimed(address indexed user, address indexed to, uint256 amount);
9+
10+
event RewardsClaimed(
11+
address indexed user,
12+
address indexed to,
13+
address indexed claimer,
14+
uint256 amount
15+
);
16+
17+
event ClaimerSet(address indexed user, address indexed claimer);
18+
19+
/*
20+
* @dev Returns the configuration of the distribution for a certain asset
21+
* @param asset The address of the reference asset of the distribution
22+
* @return The asset index, the emission per second and the last updated timestamp
23+
**/
24+
function getAssetData(address asset)
25+
external
26+
view
27+
returns (
28+
uint256,
29+
uint256,
30+
uint256
31+
);
32+
33+
/**
34+
* @dev Whitelists an address to claim the rewards on behalf of another address
35+
* @param user The address of the user
36+
* @param claimer The address of the claimer
37+
*/
38+
function setClaimer(address user, address claimer) external;
39+
40+
/**
41+
* @dev Returns the whitelisted claimer for a certain address (0x0 if not set)
42+
* @param user The address of the user
43+
* @return The claimer address
44+
*/
45+
function getClaimer(address user) external view returns (address);
46+
47+
/**
48+
* @dev Configure assets for a certain rewards emission
49+
* @param assets The assets to incentivize
50+
* @param emissionsPerSecond The emission for each asset
51+
*/
52+
function configureAssets(address[] calldata assets, uint256[] calldata emissionsPerSecond)
53+
external;
54+
55+
/**
56+
* @dev Called by the corresponding asset on any update that affects the rewards distribution
57+
* @param asset The address of the user
58+
* @param userBalance The balance of the user of the asset in the lending pool
59+
* @param totalSupply The total supply of the asset in the lending pool
60+
**/
661
function handleAction(
7-
address user,
62+
address asset,
863
uint256 userBalance,
964
uint256 totalSupply
1065
) external;
66+
67+
/**
68+
* @dev Returns the total of rewards of an user, already accrued + not yet accrued
69+
* @param user The address of the user
70+
* @return The rewards
71+
**/
72+
function getRewardsBalance(address[] calldata assets, address user)
73+
external
74+
view
75+
returns (uint256);
76+
77+
/**
78+
* @dev Claims reward for an user, on all the assets of the lending pool, accumulating the pending rewards
79+
* @param amount Amount of rewards to claim
80+
* @param to Address that will be receiving the rewards
81+
* @return Rewards claimed
82+
**/
83+
function claimRewards(
84+
address[] calldata assets,
85+
uint256 amount,
86+
address to
87+
) external returns (uint256);
88+
89+
/**
90+
* @dev Claims reward for an user on behalf, on all the assets of the lending pool, accumulating the pending rewards. The caller must
91+
* be whitelisted via "allowClaimOnBehalf" function by the RewardsAdmin role manager
92+
* @param amount Amount of rewards to claim
93+
* @param user Address to check and claim rewards
94+
* @param to Address that will be receiving the rewards
95+
* @return Rewards claimed
96+
**/
97+
function claimRewardsOnBehalf(
98+
address[] calldata assets,
99+
uint256 amount,
100+
address user,
101+
address to
102+
) external returns (uint256);
103+
104+
/**
105+
* @dev returns the unclaimed rewards of the user
106+
* @param user the address of the user
107+
* @return the unclaimed user rewards
108+
*/
109+
function getUserUnclaimedRewards(address user) external view returns (uint256);
110+
111+
/**
112+
* @dev returns the unclaimed rewards of the user
113+
* @param user the address of the user
114+
* @param asset The asset to incentivize
115+
* @return the user index for the asset
116+
*/
117+
function getUserAssetData(address user, address asset) external view returns (uint256);
118+
119+
/**
120+
* @dev for backward compatibility with previous implementation of the Incentives controller
121+
*/
122+
function REWARD_TOKEN() external view returns (address);
123+
124+
/**
125+
* @dev for backward compatibility with previous implementation of the Incentives controller
126+
*/
127+
function PRECISION() external view returns (uint8);
11128
}

contracts/misc/UiPoolDataProvider.sol

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pragma experimental ABIEncoderV2;
44

55
import {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detailed.sol';
66
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
7+
import {IAaveIncentivesController} from '../interfaces/IAaveIncentivesController.sol';
78
import {IUiPoolDataProvider} from './interfaces/IUiPoolDataProvider.sol';
89
import {ILendingPool} from '../interfaces/ILendingPool.sol';
910
import {IPriceOracleGetter} from '../interfaces/IPriceOracleGetter.sol';
@@ -24,6 +25,13 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
2425
using UserConfiguration for DataTypes.UserConfigurationMap;
2526

2627
address public constant MOCK_USD_ADDRESS = 0x10F7Fc1F91Ba351f9C629c5947AD69bD03C05b96;
28+
IAaveIncentivesController public immutable incentivesController;
29+
IPriceOracleGetter public immutable oracle;
30+
31+
constructor(IAaveIncentivesController _incentivesController, IPriceOracleGetter _oracle) public {
32+
incentivesController = _incentivesController;
33+
oracle = _oracle;
34+
}
2735

2836
function getInterestRateStrategySlopes(DefaultReserveInterestRateStrategy interestRateStrategy)
2937
internal
@@ -50,11 +58,11 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
5058
returns (
5159
AggregatedReserveData[] memory,
5260
UserReserveData[] memory,
61+
uint256,
5362
uint256
5463
)
5564
{
5665
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
57-
IPriceOracleGetter oracle = IPriceOracleGetter(provider.getPriceOracle());
5866
address[] memory reserves = lendingPool.getReservesList();
5967
DataTypes.UserConfigurationMap memory userConfig = lendingPool.getUserConfiguration(user);
6068

@@ -122,7 +130,43 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
122130
DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress)
123131
);
124132

133+
// incentives
134+
if (address(0) != address(incentivesController)) {
135+
(
136+
reserveData.aEmissionPerSecond,
137+
reserveData.aIncentivesLastUpdateTimestamp,
138+
reserveData.aTokenIncentivesIndex
139+
) = incentivesController.getAssetData(reserveData.aTokenAddress);
140+
141+
(
142+
reserveData.sEmissionPerSecond,
143+
reserveData.sIncentivesLastUpdateTimestamp,
144+
reserveData.sTokenIncentivesIndex
145+
) = incentivesController.getAssetData(reserveData.stableDebtTokenAddress);
146+
147+
(
148+
reserveData.vEmissionPerSecond,
149+
reserveData.vIncentivesLastUpdateTimestamp,
150+
reserveData.vTokenIncentivesIndex
151+
) = incentivesController.getAssetData(reserveData.variableDebtTokenAddress);
152+
}
153+
125154
if (user != address(0)) {
155+
// incentives
156+
if (address(0) != address(incentivesController)) {
157+
userReservesData[i].aTokenincentivesUserIndex = incentivesController.getUserAssetData(
158+
user,
159+
reserveData.aTokenAddress
160+
);
161+
userReservesData[i].vTokenincentivesUserIndex = incentivesController.getUserAssetData(
162+
user,
163+
reserveData.variableDebtTokenAddress
164+
);
165+
userReservesData[i].sTokenincentivesUserIndex = incentivesController.getUserAssetData(
166+
user,
167+
reserveData.stableDebtTokenAddress
168+
);
169+
}
126170
// user reserve data
127171
userReservesData[i].underlyingAsset = reserveData.underlyingAsset;
128172
userReservesData[i].scaledATokenBalance = IAToken(reserveData.aTokenAddress)
@@ -155,6 +199,12 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
155199
}
156200
}
157201
}
158-
return (reservesData, userReservesData, oracle.getAssetPrice(MOCK_USD_ADDRESS));
202+
203+
return (
204+
reservesData,
205+
userReservesData,
206+
oracle.getAssetPrice(MOCK_USD_ADDRESS),
207+
incentivesController.getUserUnclaimedRewards(user)
208+
);
159209
}
160210
}

contracts/misc/interfaces/IUiPoolDataProvider.sol

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pragma solidity 0.6.12;
33
pragma experimental ABIEncoderV2;
44

55
import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
6+
import {IAaveIncentivesController} from '../../interfaces/IAaveIncentivesController.sol';
67

78
interface IUiPoolDataProvider {
89
struct AggregatedReserveData {
@@ -41,12 +42,17 @@ interface IUiPoolDataProvider {
4142
uint256 variableRateSlope2;
4243
uint256 stableRateSlope1;
4344
uint256 stableRateSlope2;
45+
// incentives
46+
uint256 aEmissionPerSecond;
47+
uint256 vEmissionPerSecond;
48+
uint256 sEmissionPerSecond;
49+
uint256 aIncentivesLastUpdateTimestamp;
50+
uint256 vIncentivesLastUpdateTimestamp;
51+
uint256 sIncentivesLastUpdateTimestamp;
52+
uint256 aTokenIncentivesIndex;
53+
uint256 vTokenIncentivesIndex;
54+
uint256 sTokenIncentivesIndex;
4455
}
45-
//
46-
// struct ReserveData {
47-
// uint256 averageStableBorrowRate;
48-
// uint256 totalLiquidity;
49-
// }
5056

5157
struct UserReserveData {
5258
address underlyingAsset;
@@ -56,38 +62,19 @@ interface IUiPoolDataProvider {
5662
uint256 scaledVariableDebt;
5763
uint256 principalStableDebt;
5864
uint256 stableBorrowLastUpdateTimestamp;
65+
// incentives
66+
uint256 aTokenincentivesUserIndex;
67+
uint256 vTokenincentivesUserIndex;
68+
uint256 sTokenincentivesUserIndex;
5969
}
6070

61-
//
62-
// struct ATokenSupplyData {
63-
// string name;
64-
// string symbol;
65-
// uint8 decimals;
66-
// uint256 totalSupply;
67-
// address aTokenAddress;
68-
// }
69-
7071
function getReservesData(ILendingPoolAddressesProvider provider, address user)
7172
external
7273
view
7374
returns (
7475
AggregatedReserveData[] memory,
7576
UserReserveData[] memory,
77+
uint256,
7678
uint256
7779
);
78-
79-
// function getUserReservesData(ILendingPoolAddressesProvider provider, address user)
80-
// external
81-
// view
82-
// returns (UserReserveData[] memory);
83-
//
84-
// function getAllATokenSupply(ILendingPoolAddressesProvider provider)
85-
// external
86-
// view
87-
// returns (ATokenSupplyData[] memory);
88-
//
89-
// function getATokenSupply(address[] calldata aTokens)
90-
// external
91-
// view
92-
// returns (ATokenSupplyData[] memory);
9380
}

helpers/contracts-deployments.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,28 @@ import {
5555
registerContractInJsonDb,
5656
linkBytecode,
5757
insertContractAddressInDb,
58+
deployContract,
5859
} from './contracts-helpers';
5960
import { StableAndVariableTokensHelperFactory } from '../types/StableAndVariableTokensHelperFactory';
6061
import { MintableDelegationERC20 } from '../types/MintableDelegationERC20';
6162
import { readArtifact as buidlerReadArtifact } from '@nomiclabs/buidler/plugins';
6263
import { HardhatRuntimeEnvironment } from 'hardhat/types';
6364
import { LendingPoolLibraryAddresses } from '../types/LendingPoolFactory';
65+
import { UiPoolDataProvider } from '../types';
66+
import { verifyContract } from './etherscan-verification';
67+
68+
export const deployUiPoolDataProvider = async (
69+
[incentivesController, aaveOracle]: [tEthereumAddress, tEthereumAddress],
70+
verify?: boolean
71+
) => {
72+
const id = eContractid.UiPoolDataProvider;
73+
const args: string[] = [incentivesController, aaveOracle];
74+
const instance = await deployContract<UiPoolDataProvider>(id, args);
75+
if (verify) {
76+
await verifyContract(instance.address, args);
77+
}
78+
return instance;
79+
};
6480

6581
const readArtifact = async (id: string) => {
6682
if (DRE.network.name === eEthereumNetwork.buidlerevm) {
@@ -546,7 +562,15 @@ export const deployMockVariableDebtToken = async (
546562
};
547563

548564
export const deployMockAToken = async (
549-
args: [tEthereumAddress, tEthereumAddress, tEthereumAddress, tEthereumAddress, string, string, string],
565+
args: [
566+
tEthereumAddress,
567+
tEthereumAddress,
568+
tEthereumAddress,
569+
tEthereumAddress,
570+
string,
571+
string,
572+
string
573+
],
550574
verify?: boolean
551575
) => {
552576
const instance = await withSaveAndVerify(

0 commit comments

Comments
 (0)