Merge branch 'master' into polygon-verifier

This commit is contained in:
David Racero 2021-05-11 12:55:17 +02:00 committed by GitHub
commit 4f7ce7e202
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 2232 additions and 1844 deletions

37
.github/workflows/node.js.yml vendored Normal file
View File

@ -0,0 +1,37 @@
name: Build
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
- name: Test
run: npm run ci:test
# - name: Coverage
# run: npm run coverage
# - uses: codecov/codecov-action@v1
# with:
# fail_ci_if_error: true

View File

@ -1,3 +1,5 @@
[![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
[![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)
```
.///. .///. //. .// `/////////////-
`++:++` .++:++` :++` `++: `++:......---.`
@ -53,8 +55,8 @@ import {ILendingPool} from "@aave/protocol-v2/contracts/interfaces/ILendingPool.
contract Misc {
function deposit(address pool, address token, address user, uint256 amount) {
ILendingPool(pool).deposit(token, amount, user, '0');
function deposit(address pool, address token, address user, uint256 amount) public {
ILendingPool(pool).deposit(token, amount, user, 0);
{...}
}
}

Binary file not shown.

View File

@ -99,4 +99,9 @@ interface IAToken is IERC20, IScaledBalanceToken, IInitializableAToken {
* @dev Returns the address of the incentives controller contract
**/
function getIncentivesController() external view returns (IAaveIncentivesController);
/**
* @dev Returns the address of the underlying asset of this aToken (E.g. WETH for aWETH)
**/
function UNDERLYING_ASSET_ADDRESS() external view returns (address);
}

View File

@ -3,9 +3,126 @@ pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
interface IAaveIncentivesController {
event RewardsAccrued(address indexed user, uint256 amount);
event RewardsClaimed(address indexed user, address indexed to, uint256 amount);
event RewardsClaimed(
address indexed user,
address indexed to,
address indexed claimer,
uint256 amount
);
event ClaimerSet(address indexed user, address indexed claimer);
/*
* @dev Returns the configuration of the distribution for a certain asset
* @param asset The address of the reference asset of the distribution
* @return The asset index, the emission per second and the last updated timestamp
**/
function getAssetData(address asset)
external
view
returns (
uint256,
uint256,
uint256
);
/**
* @dev Whitelists an address to claim the rewards on behalf of another address
* @param user The address of the user
* @param claimer The address of the claimer
*/
function setClaimer(address user, address claimer) external;
/**
* @dev Returns the whitelisted claimer for a certain address (0x0 if not set)
* @param user The address of the user
* @return The claimer address
*/
function getClaimer(address user) external view returns (address);
/**
* @dev Configure assets for a certain rewards emission
* @param assets The assets to incentivize
* @param emissionsPerSecond The emission for each asset
*/
function configureAssets(address[] calldata assets, uint256[] calldata emissionsPerSecond)
external;
/**
* @dev Called by the corresponding asset on any update that affects the rewards distribution
* @param asset The address of the user
* @param userBalance The balance of the user of the asset in the lending pool
* @param totalSupply The total supply of the asset in the lending pool
**/
function handleAction(
address user,
address asset,
uint256 userBalance,
uint256 totalSupply
) external;
/**
* @dev Returns the total of rewards of an user, already accrued + not yet accrued
* @param user The address of the user
* @return The rewards
**/
function getRewardsBalance(address[] calldata assets, address user)
external
view
returns (uint256);
/**
* @dev Claims reward for an user, on all the assets of the lending pool, accumulating the pending rewards
* @param amount Amount of rewards to claim
* @param to Address that will be receiving the rewards
* @return Rewards claimed
**/
function claimRewards(
address[] calldata assets,
uint256 amount,
address to
) external returns (uint256);
/**
* @dev Claims reward for an user on behalf, on all the assets of the lending pool, accumulating the pending rewards. The caller must
* be whitelisted via "allowClaimOnBehalf" function by the RewardsAdmin role manager
* @param amount Amount of rewards to claim
* @param user Address to check and claim rewards
* @param to Address that will be receiving the rewards
* @return Rewards claimed
**/
function claimRewardsOnBehalf(
address[] calldata assets,
uint256 amount,
address user,
address to
) external returns (uint256);
/**
* @dev returns the unclaimed rewards of the user
* @param user the address of the user
* @return the unclaimed user rewards
*/
function getUserUnclaimedRewards(address user) external view returns (uint256);
/**
* @dev returns the unclaimed rewards of the user
* @param user the address of the user
* @param asset The asset to incentivize
* @return the user index for the asset
*/
function getUserAssetData(address user, address asset) external view returns (uint256);
/**
* @dev for backward compatibility with previous implementation of the Incentives controller
*/
function REWARD_TOKEN() external view returns (address);
/**
* @dev for backward compatibility with previous implementation of the Incentives controller
*/
function PRECISION() external view returns (uint8);
}

View File

@ -4,6 +4,7 @@ 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';
@ -24,6 +25,13 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
using UserConfiguration for DataTypes.UserConfigurationMap;
address public constant MOCK_USD_ADDRESS = 0x10F7Fc1F91Ba351f9C629c5947AD69bD03C05b96;
IAaveIncentivesController public immutable incentivesController;
IPriceOracleGetter public immutable oracle;
constructor(IAaveIncentivesController _incentivesController, IPriceOracleGetter _oracle) public {
incentivesController = _incentivesController;
oracle = _oracle;
}
function getInterestRateStrategySlopes(DefaultReserveInterestRateStrategy interestRateStrategy)
internal
@ -50,11 +58,11 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
returns (
AggregatedReserveData[] memory,
UserReserveData[] memory,
uint256,
uint256
)
{
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
IPriceOracleGetter oracle = IPriceOracleGetter(provider.getPriceOracle());
address[] memory reserves = lendingPool.getReservesList();
DataTypes.UserConfigurationMap memory userConfig = lendingPool.getUserConfiguration(user);
@ -122,7 +130,43 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress)
);
// incentives
if (address(0) != address(incentivesController)) {
(
reserveData.aEmissionPerSecond,
reserveData.aIncentivesLastUpdateTimestamp,
reserveData.aTokenIncentivesIndex
) = incentivesController.getAssetData(reserveData.aTokenAddress);
(
reserveData.sEmissionPerSecond,
reserveData.sIncentivesLastUpdateTimestamp,
reserveData.sTokenIncentivesIndex
) = incentivesController.getAssetData(reserveData.stableDebtTokenAddress);
(
reserveData.vEmissionPerSecond,
reserveData.vIncentivesLastUpdateTimestamp,
reserveData.vTokenIncentivesIndex
) = incentivesController.getAssetData(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)
@ -155,6 +199,12 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
}
}
}
return (reservesData, userReservesData, oracle.getAssetPrice(MOCK_USD_ADDRESS));
return (
reservesData,
userReservesData,
oracle.getAssetPrice(MOCK_USD_ADDRESS),
incentivesController.getUserUnclaimedRewards(user)
);
}
}

View File

@ -3,6 +3,7 @@ pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
import {IAaveIncentivesController} from '../../interfaces/IAaveIncentivesController.sol';
interface IUiPoolDataProvider {
struct AggregatedReserveData {
@ -41,12 +42,17 @@ 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 ReserveData {
// uint256 averageStableBorrowRate;
// uint256 totalLiquidity;
// }
struct UserReserveData {
address underlyingAsset;
@ -56,38 +62,19 @@ interface IUiPoolDataProvider {
uint256 scaledVariableDebt;
uint256 principalStableDebt;
uint256 stableBorrowLastUpdateTimestamp;
// incentives
uint256 aTokenincentivesUserIndex;
uint256 vTokenincentivesUserIndex;
uint256 sTokenincentivesUserIndex;
}
//
// struct ATokenSupplyData {
// string name;
// string symbol;
// uint8 decimals;
// uint256 totalSupply;
// address aTokenAddress;
// }
function getReservesData(ILendingPoolAddressesProvider provider, address user)
external
view
returns (
AggregatedReserveData[] memory,
UserReserveData[] memory,
uint256,
uint256
);
// function getUserReservesData(ILendingPoolAddressesProvider provider, address user)
// external
// view
// returns (UserReserveData[] memory);
//
// function getAllATokenSupply(ILendingPoolAddressesProvider provider)
// external
// view
// returns (ATokenSupplyData[] memory);
//
// function getATokenSupply(address[] calldata aTokens)
// external
// view
// returns (ATokenSupplyData[] memory);
}

View File

@ -8,7 +8,6 @@ import {PercentageMath} from '../libraries/math/PercentageMath.sol';
import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
import {ILendingRateOracle} from '../../interfaces/ILendingRateOracle.sol';
import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol';
import 'hardhat/console.sol';
/**
* @title DefaultReserveInterestRateStrategy contract

View File

@ -273,7 +273,7 @@ contract AToken is
/**
* @dev Returns the address of the underlying asset of this aToken (E.g. WETH for aWETH)
**/
function UNDERLYING_ASSET_ADDRESS() public view returns (address) {
function UNDERLYING_ASSET_ADDRESS() public override view returns (address) {
return _underlyingAsset;
}

View File

@ -15,6 +15,7 @@ import 'temp-hardhat-etherscan';
import 'hardhat-gas-reporter';
import 'hardhat-typechain';
import '@tenderly/hardhat-tenderly';
import 'solidity-coverage';
const SKIP_LOAD = process.env.SKIP_LOAD === 'true';
const DEFAULT_BLOCK_GAS_LIMIT = 12450000;
@ -99,7 +100,7 @@ const buidlerConfig: HardhatUserConfig = {
mumbai: getCommonNetworkConfig(ePolygonNetwork.mumbai, 80001),
xdai: getCommonNetworkConfig(eXDaiNetwork.xdai, 100),
hardhat: {
hardfork: 'istanbul',
hardfork: 'berlin',
blockGasLimit: DEFAULT_BLOCK_GAS_LIMIT,
gas: DEFAULT_BLOCK_GAS_LIMIT,
gasPrice: 8000000000,
@ -113,7 +114,7 @@ const buidlerConfig: HardhatUserConfig = {
forking: mainnetFork,
},
buidlerevm_docker: {
hardfork: 'istanbul',
hardfork: 'berlin',
blockGasLimit: 9500000,
gas: 9500000,
gasPrice: 8000000000,

View File

@ -55,12 +55,28 @@ import {
registerContractInJsonDb,
linkBytecode,
insertContractAddressInDb,
deployContract,
} from './contracts-helpers';
import { StableAndVariableTokensHelperFactory } from '../types/StableAndVariableTokensHelperFactory';
import { MintableDelegationERC20 } from '../types/MintableDelegationERC20';
import { readArtifact as buidlerReadArtifact } from '@nomiclabs/buidler/plugins';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { LendingPoolLibraryAddresses } from '../types/LendingPoolFactory';
import { UiPoolDataProvider } from '../types';
import { verifyContract } from './etherscan-verification';
export const deployUiPoolDataProvider = async (
[incentivesController, aaveOracle]: [tEthereumAddress, tEthereumAddress],
verify?: boolean
) => {
const id = eContractid.UiPoolDataProvider;
const args: string[] = [incentivesController, aaveOracle];
const instance = await deployContract<UiPoolDataProvider>(id, args);
if (verify) {
await verifyContract(instance.address, args);
}
return instance;
};
const readArtifact = async (id: string) => {
if (DRE.network.name === eEthereumNetwork.buidlerevm) {
@ -546,7 +562,15 @@ export const deployMockVariableDebtToken = async (
};
export const deployMockAToken = async (
args: [tEthereumAddress, tEthereumAddress, tEthereumAddress, tEthereumAddress, string, string, string],
args: [
tEthereumAddress,
tEthereumAddress,
tEthereumAddress,
tEthereumAddress,
string,
string,
string
],
verify?: boolean
) => {
const instance = await withSaveAndVerify(

3729
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@
"hardhat": "hardhat",
"hardhat:kovan": "hardhat --network kovan",
"hardhat:tenderly-main": "hardhat --network tenderlyMain",
"hardhat:ropsten": "hardhat--network ropsten",
"hardhat:ropsten": "hardhat --network ropsten",
"hardhat:main": "hardhat --network main",
"hardhat:docker": "hardhat --network hardhatevm_docker",
"hardhat:mumbai": "hardhat --network mumbai",
@ -61,7 +61,10 @@
"print-contracts:kovan": "npm run hardhat:kovan -- print-contracts",
"print-contracts:main": "npm run hardhat:main -- print-contracts",
"print-contracts:ropsten": "npm run hardhat:main -- print-contracts",
"dev:deployUIProvider": "npm run hardhat:kovan deploy-UiPoolDataProvider",
"dev:deployUIProvider": "hardhat --network kovan deploy-UiPoolDataProvider --verify",
"main:deployUIProvider": "hardhat --network main deploy-UiPoolDataProvider --verify",
"matic:deployUIProvider": "hardhat --network matic deploy-UiPoolDataProvider",
"mumbai:deployUIProvider": "hardhat --network mumbai deploy-UiPoolDataProvider",
"dev:deployUniswapRepayAdapter": "hardhat --network kovan deploy-UniswapRepayAdapter --provider 0x88757f2f99175387aB4C6a4b3067c77A695b0349 --router 0xfcd87315f0e4067070ade8682fcdbc3006631441 --weth 0xd0a1e359811322d97991e03f863a0c30c2cf029c",
"dev:UniswapLiquiditySwapAdapter": "hardhat --network kovan deploy-UniswapLiquiditySwapAdapter --provider 0x88757f2f99175387aB4C6a4b3067c77A695b0349 --router 0xfcd87315f0e4067070ade8682fcdbc3006631441 --weth 0xd0a1e359811322d97991e03f863a0c30c2cf029c",
"main:deployUniswapRepayAdapter": "hardhat --network main deploy-UniswapRepayAdapter --provider 0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5 --router 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D --weth 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
@ -111,7 +114,7 @@
"ethereumjs-util": "7.0.2",
"ethers": "^5.0.19",
"globby": "^11.0.1",
"hardhat": "^2.0.8",
"hardhat": "^2.2.0",
"hardhat-gas-reporter": "^1.0.0",
"hardhat-typechain": "^0.3.3",
"husky": "^4.2.5",
@ -119,7 +122,7 @@
"prettier": "^2.0.5",
"prettier-plugin-solidity": "^1.0.0-alpha.53",
"pretty-quick": "^2.0.1",
"solidity-coverage": "0.7.10",
"solidity-coverage": "^0.7.16",
"temp-hardhat-etherscan": "^2.0.2",
"ts-generator": "^0.1.1",
"ts-node": "^8.10.2",

View File

@ -1,18 +1,36 @@
import { task } from 'hardhat/config';
import { UiPoolDataProviderFactory } from '../../types';
import { verifyContract } from '../../helpers/contracts-helpers';
import { eContractid } from '../../helpers/types';
task(`deploy-${eContractid.UiPoolDataProvider}`, `Deploys the UiPoolDataProvider contract`)
.addFlag('verify', 'Verify UiPoolDataProvider contract via Etherscan API.')
.setAction(async ({ verify }, localBRE) => {
await localBRE.run('set-DRE');
if (!localBRE.network.config.chainId) {
throw new Error('INVALID_CHAIN_ID');
}
const addressesByNetwork = {
[eEthereumNetwork.kovan]: {
incentivesController: '0x0000000000000000000000000000000000000000',
aaveOracle: '0x8fb777d67e9945e2c01936e319057f9d41d559e6',
},
[eEthereumNetwork.main]: {
incentivesController: '0xd784927Ff2f95ba542BfC824c8a8a98F3495f6b5',
aaveOracle: '0xa50ba011c48153de246e5192c8f9258a2ba79ca9',
},
[ePolygonNetwork.matic]: {
incentivesController: '0x357D51124f59836DeD84c8a1730D72B749d8BC23',
aaveOracle: '0x21451bD7b528896B4AB2b9764b521D6ed641708d',
},
[ePolygonNetwork.mumbai]: {
incentivesController: '0xd41aE58e803Edf4304334acCE4DC4Ec34a63C644',
aaveOracle: '0xC365C653f7229894F93994CD0b30947Ab69Ff1D5',
},
};
console.log(`\n- UiPoolDataProvider deployment`);
console.log(`\tDeploying UiPoolDataProvider implementation ...`);

View File

@ -82,12 +82,12 @@ WRONG RESERVE ASSET SETUP:
const rates = await deployDefaultReserveInterestRateStrategy(
[
addressProvider.address,
strategyParams.optimalUtilizationRate,
strategyParams.baseVariableBorrowRate,
strategyParams.variableRateSlope1,
strategyParams.variableRateSlope2,
strategyParams.stableRateSlope1,
strategyParams.stableRateSlope2,
strategyParams.strategy.optimalUtilizationRate,
strategyParams.strategy.baseVariableBorrowRate,
strategyParams.strategy.variableRateSlope1,
strategyParams.strategy.variableRateSlope2,
strategyParams.strategy.stableRateSlope1,
strategyParams.strategy.stableRateSlope2,
],
verify
);

View File

@ -4,7 +4,7 @@ import { ConfigNames } from '../../helpers/configuration';
import { printContracts } from '../../helpers/misc-utils';
task('aave:dev', 'Deploy development enviroment')
.addOptionalParam('verify', 'Verify contracts at Etherscan')
.addFlag('verify', 'Verify contracts at Etherscan')
.setAction(async ({ verify }, localBRE) => {
const POOL_NAME = ConfigNames.Aave;