Skip to content

Commit 258a9be

Browse files
committed
Merge branch 'master' into paraswap
2 parents 0ec5e21 + 53b2723 commit 258a9be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+15406
-15625
lines changed

.github/workflows/node.js.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [14.x]
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v2
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
- uses: actions/cache@v2
24+
with:
25+
path: ~/.npm
26+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
27+
restore-keys: |
28+
${{ runner.os }}-node-
29+
- name: Install dependencies
30+
run: npm ci
31+
- name: Test
32+
run: npm run ci:test
33+
- name: Dev deployment
34+
run: npm run aave:evm:dev:migration
35+
- name: Mainnet deployment at Mainnet fork
36+
run: npm run aave:fork:main
37+
env:
38+
ALCHEMY_KEY: ${{ secrets.ALCHEMY_KEY }}
39+
- name: Amm deployment at Mainnet fork
40+
run: npm run amm:fork:main
41+
env:
42+
ALCHEMY_KEY: ${{ secrets.ALCHEMY_KEY }}
43+
- name: Aave deployment at Kovan fork
44+
run: npm run aave:fork:kovan
45+
env:
46+
ALCHEMY_KEY: ${{ secrets.ALCHEMY_KEY }}
47+
# - name: Coverage
48+
# run: npm run coverage
49+
# - uses: codecov/codecov-action@v1
50+
# with:
51+
# fail_ci_if_error: true

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
2+
[![Build pass](https://github.com/AAVE/protocol-v2/actions/workflows/node.js.yml/badge.svg)](https://github.com/aave/protocol-v2/actions/workflows/node.js.yml)
13
```
24
.///. .///. //. .// `/////////////-
35
`++:++` .++:++` :++` `++: `++:......---.`
@@ -53,8 +55,8 @@ import {ILendingPool} from "@aave/protocol-v2/contracts/interfaces/ILendingPool.
5355
5456
contract Misc {
5557
56-
function deposit(address pool, address token, address user, uint256 amount) {
57-
ILendingPool(pool).deposit(token, amount, user, '0');
58+
function deposit(address pool, address token, address user, uint256 amount) public {
59+
ILendingPool(pool).deposit(token, amount, user, 0);
5860
{...}
5961
}
6062
}

aave-v2-whitepaper.pdf

-1 Bytes
Binary file not shown.

contracts/deployments/ATokensAndRatesHelper.sol

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ contract ATokensAndRatesHelper is Ownable {
3232
uint256 liquidationBonus;
3333
uint256 reserveFactor;
3434
bool stableBorrowingEnabled;
35+
bool borrowingEnabled;
3536
}
3637

3738
constructor(
@@ -73,10 +74,12 @@ contract ATokensAndRatesHelper is Ownable {
7374
inputParams[i].liquidationBonus
7475
);
7576

76-
configurator.enableBorrowingOnReserve(
77-
inputParams[i].asset,
78-
inputParams[i].stableBorrowingEnabled
79-
);
77+
if (inputParams[i].borrowingEnabled) {
78+
configurator.enableBorrowingOnReserve(
79+
inputParams[i].asset,
80+
inputParams[i].stableBorrowingEnabled
81+
);
82+
}
8083
configurator.setReserveFactor(inputParams[i].asset, inputParams[i].reserveFactor);
8184
}
8285
}

contracts/interfaces/IAToken.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,9 @@ interface IAToken is IERC20, IScaledBalanceToken, IInitializableAToken {
9999
* @dev Returns the address of the incentives controller contract
100100
**/
101101
function getIncentivesController() external view returns (IAaveIncentivesController);
102+
103+
/**
104+
* @dev Returns the address of the underlying asset of this aToken (E.g. WETH for aWETH)
105+
**/
106+
function UNDERLYING_ASSET_ADDRESS() external view returns (address);
102107
}

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
}

0 commit comments

Comments
 (0)