Merge branch 'feat/curve-treasury' of github.com:aave/protocol-v2 into feat/curve-treasury

This commit is contained in:
David Racero 2021-06-30 17:41:24 +02:00
commit e9174e34fb
25 changed files with 933 additions and 584 deletions

View File

@ -125,4 +125,9 @@ interface IAaveIncentivesController {
* @dev for backward compatibility with previous implementation of the Incentives controller
*/
function PRECISION() external view returns (uint8);
/**
* @dev Gets the distribution end timestamp of the emissions
*/
function DISTRIBUTION_END() external view returns (uint256);
}

View File

@ -59,7 +59,7 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
AggregatedReserveData[] memory,
UserReserveData[] memory,
uint256,
uint256
IncentivesControllerData memory
)
{
ILendingPool lendingPool = ILendingPool(provider.getLendingPool());
@ -133,21 +133,21 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
// incentives
if (address(0) != address(incentivesController)) {
(
reserveData.aTokenIncentivesIndex,
reserveData.aEmissionPerSecond,
reserveData.aIncentivesLastUpdateTimestamp,
reserveData.aTokenIncentivesIndex
reserveData.aIncentivesLastUpdateTimestamp
) = incentivesController.getAssetData(reserveData.aTokenAddress);
(
reserveData.sTokenIncentivesIndex,
reserveData.sEmissionPerSecond,
reserveData.sIncentivesLastUpdateTimestamp,
reserveData.sTokenIncentivesIndex
reserveData.sIncentivesLastUpdateTimestamp
) = incentivesController.getAssetData(reserveData.stableDebtTokenAddress);
(
reserveData.vTokenIncentivesIndex,
reserveData.vEmissionPerSecond,
reserveData.vIncentivesLastUpdateTimestamp,
reserveData.vTokenIncentivesIndex
reserveData.vIncentivesLastUpdateTimestamp
) = incentivesController.getAssetData(reserveData.variableDebtTokenAddress);
}
@ -200,11 +200,21 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
}
}
IncentivesControllerData memory incentivesControllerData;
if (address(0) != address(incentivesController)) {
if (user != address(0)) {
incentivesControllerData.userUnclaimedRewards = incentivesController.getUserUnclaimedRewards(user);
}
incentivesControllerData.emissionEndTimestamp = incentivesController.DISTRIBUTION_END();
}
return (
reservesData,
userReservesData,
oracle.getAssetPrice(MOCK_USD_ADDRESS),
incentivesController.getUserUnclaimedRewards(user)
incentivesControllerData
);
}
}

View File

@ -68,6 +68,12 @@ interface IUiPoolDataProvider {
uint256 sTokenincentivesUserIndex;
}
struct IncentivesControllerData {
uint256 userUnclaimedRewards;
uint256 emissionEndTimestamp;
}
function getReservesData(ILendingPoolAddressesProvider provider, address user)
external
view
@ -75,6 +81,6 @@ interface IUiPoolDataProvider {
AggregatedReserveData[] memory,
UserReserveData[] memory,
uint256,
uint256
IncentivesControllerData memory
);
}

View File

@ -21,3 +21,5 @@ services:
ALCHEMY_KEY: ${ALCHEMY_KEY}
TENDERLY_FORK_ID: ${TENDERLY_FORK_ID}
TENDERLY_HEAD_ID: ${TENDERLY_HEAD_ID}
DEFENDER_API_KEY: ${DEFENDER_API_KEY}
DEFENDER_SECRET_KEY: ${DEFENDER_SECRET_KEY}

View File

@ -6,7 +6,7 @@ import {
ICommonConfiguration,
eNetwork,
} from './types';
import { getParamPerPool } from './contracts-helpers';
import { getEthersSignersAddresses, getParamPerPool } from './contracts-helpers';
import AaveConfig from '../markets/aave';
import MaticConfig from '../markets/matic';
import AmmConfig from '../markets/amm';
@ -66,9 +66,7 @@ export const getGenesisPoolAdmin = async (
if (targetAddress) {
return targetAddress;
}
const addressList = await Promise.all(
(await DRE.ethers.getSigners()).map((signer) => signer.getAddress())
);
const addressList = await getEthersSignersAddresses();
const addressIndex = config.PoolAdminIndex;
return addressList[addressIndex];
};
@ -81,9 +79,7 @@ export const getEmergencyAdmin = async (
if (targetAddress) {
return targetAddress;
}
const addressList = await Promise.all(
(await DRE.ethers.getSigners()).map((signer) => signer.getAddress())
);
const addressList = await getEthersSignersAddresses();
const addressIndex = config.EmergencyAdminIndex;
return addressList[addressIndex];
};

View File

@ -145,7 +145,9 @@ export const deployGenericLogic = async (reserveLogic: Contract, verify?: boolea
linkedGenericLogicByteCode
);
const genericLogic = await (await genericLogicFactory.deploy()).deployed();
const genericLogic = await (
await genericLogicFactory.connect(await getFirstSigner()).deploy()
).deployed();
return withSaveAndVerify(genericLogic, eContractid.GenericLogic, [], verify);
};
@ -166,7 +168,9 @@ export const deployValidationLogic = async (
linkedValidationLogicByteCode
);
const validationLogic = await (await validationLogicFactory.deploy()).deployed();
const validationLogic = await (
await validationLogicFactory.connect(await getFirstSigner()).deploy()
).deployed();
return withSaveAndVerify(validationLogic, eContractid.ValidationLogic, [], verify);
};

View File

@ -34,11 +34,11 @@ import {
RewardsTokenFactory,
} from '../types';
import { IERC20DetailedFactory } from '../types/IERC20DetailedFactory';
import { MockTokenMap } from './contracts-helpers';
import { getEthersSigners, MockTokenMap } from './contracts-helpers';
import { DRE, getDb, notFalsyOrZeroAddress } from './misc-utils';
import { eContractid, PoolConfiguration, tEthereumAddress, TokenContractId } from './types';
export const getFirstSigner = async () => (await DRE.ethers.getSigners())[0];
export const getFirstSigner = async () => (await getEthersSigners())[0];
export const getLendingPoolAddressesProvider = async (address?: tEthereumAddress) => {
return await LendingPoolAddressesProviderFactory.connect(

View File

@ -29,6 +29,7 @@ import { usingPolygon, verifyAtPolygon } from './polygon-utils';
import { ConfigNames, loadPoolConfig } from './configuration';
import { ZERO_ADDRESS } from './constants';
import { RewardsTokenFactory, RewardsATokenMockFactory } from '../types';
import { getDefenderRelaySigner, usingDefender } from './defender-utils';
export type MockTokenMap = { [symbol: string]: MintableERC20 };
@ -69,11 +70,18 @@ export const rawInsertContractAddressInDb = async (id: string, address: tEthereu
})
.write();
export const getEthersSigners = async (): Promise<Signer[]> =>
await Promise.all(await DRE.ethers.getSigners());
export const getEthersSigners = async (): Promise<Signer[]> => {
const ethersSigners = await Promise.all(await DRE.ethers.getSigners());
if (usingDefender()) {
const [, ...users] = ethersSigners;
return [await getDefenderRelaySigner(), ...users];
}
return ethersSigners;
};
export const getEthersSignersAddresses = async (): Promise<tEthereumAddress[]> =>
await Promise.all((await DRE.ethers.getSigners()).map((signer) => signer.getAddress()));
await Promise.all((await getEthersSigners()).map((signer) => signer.getAddress()));
export const getCurrentBlock = async () => {
return DRE.ethers.provider.getBlockNumber();
@ -86,9 +94,9 @@ export const deployContract = async <ContractType extends Contract>(
contractName: string,
args: any[]
): Promise<ContractType> => {
const contract = (await (await DRE.ethers.getContractFactory(contractName)).deploy(
...args
)) as ContractType;
const contract = (await (await DRE.ethers.getContractFactory(contractName))
.connect(await getFirstSigner())
.deploy(...args)) as ContractType;
await waitForTx(contract.deployTransaction);
await registerContractInJsonDb(<eContractid>contractName, contract);
return contract;

41
helpers/defender-utils.ts Normal file
View File

@ -0,0 +1,41 @@
import { formatEther } from '@ethersproject/units';
import { DefenderRelaySigner, DefenderRelayProvider } from 'defender-relay-client/lib/ethers';
import { Signer } from 'ethers';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DRE, impersonateAccountsHardhat } from './misc-utils';
import { usingTenderly } from './tenderly-utils';
export const usingDefender = () => process.env.DEFENDER === 'true';
export const getDefenderRelaySigner = async () => {
const { DEFENDER_API_KEY, DEFENDER_SECRET_KEY } = process.env;
let defenderSigner: Signer;
if (!DEFENDER_API_KEY || !DEFENDER_SECRET_KEY) {
throw new Error('Defender secrets required');
}
const credentials = { apiKey: DEFENDER_API_KEY, apiSecret: DEFENDER_SECRET_KEY };
defenderSigner = new DefenderRelaySigner(credentials, new DefenderRelayProvider(credentials), {
speed: 'fast',
});
const defenderAddress = await defenderSigner.getAddress();
console.log(' - Using Defender Relay: ', defenderAddress);
// Replace signer if FORK=main is active
if (process.env.FORK === 'main') {
console.log(' - Impersonating Defender Relay');
await impersonateAccountsHardhat([defenderAddress]);
defenderSigner = await (DRE as HardhatRuntimeEnvironment).ethers.getSigner(defenderAddress);
}
// Replace signer if Tenderly network is active
if (usingTenderly()) {
console.log(' - Impersonating Defender Relay via Tenderly');
defenderSigner = await (DRE as HardhatRuntimeEnvironment).ethers.getSigner(defenderAddress);
}
console.log(' - Balance: ', formatEther(await defenderSigner.getBalance()));
return defenderSigner;
};

View File

@ -129,3 +129,17 @@ export const impersonateAddress = async (address: tEthereumAddress): Promise<Sig
address,
};
};
export const impersonateAccountsHardhat = async (accounts: string[]) => {
if (process.env.TENDERLY === 'true') {
return;
}
// eslint-disable-next-line no-restricted-syntax
for (const account of accounts) {
// eslint-disable-next-line no-await-in-loop
await (DRE as HardhatRuntimeEnvironment).network.provider.request({
method: 'hardhat_impersonateAccount',
params: [account],
});
}
};

View File

@ -9,7 +9,7 @@ export const usingTenderly = () =>
export const verifyAtTenderly = async (id: string, instance: Contract) => {
console.log('\n- Doing Tenderly contract verification of', id);
await (DRE as any).tenderlyRPC.verify({
await (DRE as any).tenderlyNetwork.verify({
name: id,
address: instance.address,
});

1307
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -99,7 +99,7 @@
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-waffle": "^2.0.0",
"@openzeppelin/contracts": "3.1.0",
"@tenderly/hardhat-tenderly": "^1.1.0-beta.4",
"@tenderly/hardhat-tenderly": "1.1.0-beta.5",
"@typechain/ethers-v4": "1.0.0",
"@typechain/ethers-v5": "^2.0.0",
"@typechain/truffle-v4": "2.0.2",
@ -114,6 +114,7 @@
"chai": "4.2.0",
"chai-bignumber": "3.0.0",
"chai-bn": "^0.2.1",
"defender-relay-client": "^1.7.0",
"dotenv": "^8.2.0",
"eth-sig-util": "2.5.3",
"ethereum-waffle": "3.0.2",

View File

@ -25,7 +25,7 @@ task(`deploy-${eContractid.UiPoolDataProvider}`, `Deploys the UiPoolDataProvider
},
[ePolygonNetwork.matic]: {
incentivesController: '0x357D51124f59836DeD84c8a1730D72B749d8BC23',
aaveOracle: '0x21451bD7b528896B4AB2b9764b521D6ed641708d',
aaveOracle: '0x0229F777B0fAb107F9591a41d5F02E4e98dB6f2d',
},
[ePolygonNetwork.mumbai]: {
incentivesController: '0xd41aE58e803Edf4304334acCE4DC4Ec34a63C644',
@ -42,7 +42,7 @@ task(`deploy-${eContractid.UiPoolDataProvider}`, `Deploys the UiPoolDataProvider
}
const oracle = addressesByNetwork[network].aaveOracle;
const incentivesController = addressesByNetwork[network].aaveOracle;
const incentivesController = addressesByNetwork[network].incentivesController;
console.log(`\n- UiPoolDataProvider deployment`);

View File

@ -3,6 +3,7 @@ import {
deployLendingPoolAddressesProvider,
deployLendingPoolAddressesProviderRegistry,
} from '../../helpers/contracts-deployments';
import { getEthersSigners } from '../../helpers/contracts-helpers';
import { waitForTx } from '../../helpers/misc-utils';
import { AaveConfig } from '../../markets/aave';
@ -14,7 +15,7 @@ task(
.setAction(async ({ verify }, localBRE) => {
await localBRE.run('set-DRE');
const admin = await (await localBRE.ethers.getSigners())[0].getAddress();
const admin = await (await getEthersSigners())[0].getAddress();
const addressesProvider = await deployLendingPoolAddressesProvider(AaveConfig.MarketId, verify);
await waitForTx(await addressesProvider.setPoolAdmin(admin));

View File

@ -84,7 +84,7 @@ task('full:deploy-lending-pool', 'Deploy lending pool for dev enviroment')
if (DRE.network.name.includes('tenderly')) {
const transactionLink = `https://dashboard.tenderly.co/${DRE.config.tenderly.username}/${
DRE.config.tenderly.project
}/fork/${DRE.tenderlyRPC.getFork()}/simulation/${DRE.tenderlyRPC.getHead()}`;
}/fork/${DRE.tenderlyNetwork.getFork()}/simulation/${DRE.tenderlyNetwork.getHead()}`;
console.error('Check tx error:', transactionLink);
}
throw error;

View File

@ -84,7 +84,7 @@ task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
if (DRE.network.name.includes('tenderly')) {
const transactionLink = `https://dashboard.tenderly.co/${DRE.config.tenderly.username}/${
DRE.config.tenderly.project
}/fork/${DRE.tenderlyRPC.getFork()}/simulation/${DRE.tenderlyRPC.getHead()}`;
}/fork/${DRE.tenderlyNetwork.getFork()}/simulation/${DRE.tenderlyNetwork.getHead()}`;
console.error('Check tx error:', transactionLink);
}
throw error;

View File

@ -46,8 +46,8 @@ task('aave:mainnet', 'Deploy development enviroment')
}
if (usingTenderly()) {
const postDeployHead = DRE.tenderlyRPC.getHead();
const postDeployFork = DRE.tenderlyRPC.getFork();
const postDeployHead = DRE.tenderlyNetwork.getHead();
const postDeployFork = DRE.tenderlyNetwork.getFork();
console.log('Tenderly Info');
console.log('- Head', postDeployHead);
console.log('- Fork', postDeployFork);

View File

@ -46,8 +46,8 @@ task('amm:mainnet', 'Deploy development enviroment')
}
if (usingTenderly()) {
const postDeployHead = DRE.tenderlyRPC.getHead();
const postDeployFork = DRE.tenderlyRPC.getFork();
const postDeployHead = DRE.tenderlyNetwork.getHead();
const postDeployFork = DRE.tenderlyNetwork.getFork();
console.log('Tenderly Info');
console.log('- Head', postDeployHead);
console.log('- Fork', postDeployFork);

View File

@ -49,8 +49,8 @@ task('sidechain:mainnet', 'Deploy market at sidechain')
}
if (usingTenderly()) {
const postDeployHead = DRE.tenderlyRPC.getHead();
const postDeployFork = DRE.tenderlyRPC.getFork();
const postDeployHead = DRE.tenderlyNetwork.getHead();
const postDeployFork = DRE.tenderlyNetwork.getFork();
console.log('Tenderly Info');
console.log('- Head', postDeployHead);
console.log('- Fork', postDeployFork);

View File

@ -1,12 +1,6 @@
import { task } from 'hardhat/config';
import { DRE, setDRE } from '../../helpers/misc-utils';
import { EthereumNetworkNames } from '../../helpers/types';
import { usingTenderly } from '../../helpers/tenderly-utils';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { getFirstSigner } from '../../helpers/contracts-getters';
import { formatEther } from 'ethers/lib/utils';
import { fork } from 'child_process';
import { env } from 'process';
task(`set-DRE`, `Inits the DRE, to have access to all the plugins' objects`).setAction(
async (_, _DRE) => {
@ -18,24 +12,21 @@ task(`set-DRE`, `Inits the DRE, to have access to all the plugins' objects`).set
process.env.TENDERLY === 'true'
) {
console.log('- Setting up Tenderly provider');
const net = _DRE.tenderly.network();
if (process.env.TENDERLY_FORK_ID && process.env.TENDERLY_HEAD_ID) {
console.log('- Connecting to a Tenderly Fork');
_DRE.tenderlyRPC.setFork(process.env.TENDERLY_FORK_ID);
_DRE.tenderlyRPC.setHead(process.env.TENDERLY_HEAD_ID);
await net.setFork(process.env.TENDERLY_FORK_ID);
await net.setHead(process.env.TENDERLY_HEAD_ID);
} else {
console.log('- Creating a new Tenderly Fork');
await _DRE.tenderlyRPC.initializeFork();
await net.initializeFork();
}
const provider = new _DRE.ethers.providers.Web3Provider(_DRE.tenderlyRPC as any);
const provider = new _DRE.ethers.providers.Web3Provider(net);
_DRE.ethers.provider = provider;
console.log('- Initialized Tenderly fork:');
console.log(' - Fork: ', _DRE.tenderlyRPC.getFork());
console.log(' - Head: ', _DRE.tenderlyRPC.getHead());
console.log(' - First account:', await (await _DRE.ethers.getSigners())[0].getAddress());
console.log(
' - Balance:',
formatEther(await (await _DRE.ethers.getSigners())[0].getBalance())
);
console.log(' - Fork: ', net.getFork());
console.log(' - Head: ', net.getHead());
}
console.log('- Enviroment');
@ -50,6 +41,7 @@ task(`set-DRE`, `Inits the DRE, to have access to all the plugins' objects`).set
}
}
console.log(' - Network :', _DRE.network.name);
setDRE(_DRE);
return _DRE;
}

View File

@ -4,6 +4,7 @@ import {
insertContractAddressInDb,
getEthersSigners,
registerContractInJsonDb,
getEthersSignersAddresses,
} from '../../helpers/contracts-helpers';
import {
deployLendingPoolAddressesProvider,
@ -109,9 +110,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
await waitForTx(await addressesProvider.setPoolAdmin(aaveAdmin));
//setting users[1] as emergency admin, which is in position 2 in the DRE addresses list
const addressList = await Promise.all(
(await DRE.ethers.getSigners()).map((signer) => signer.getAddress())
);
const addressList = await getEthersSignersAddresses();
await waitForTx(await addressesProvider.setEmergencyAdmin(addressList[2]));

View File

@ -172,7 +172,7 @@ export async function initializeMakeSuite() {
const setSnapshot = async () => {
const hre = DRE as HardhatRuntimeEnvironment;
if (usingTenderly()) {
setBuidlerevmSnapshotId((await hre.tenderlyRPC.getHead()) || '0x1');
setBuidlerevmSnapshotId((await hre.tenderlyNetwork.getHead()) || '0x1');
return;
}
setBuidlerevmSnapshotId(await evmSnapshot());
@ -181,7 +181,7 @@ const setSnapshot = async () => {
const revertHead = async () => {
const hre = DRE as HardhatRuntimeEnvironment;
if (usingTenderly()) {
await hre.tenderlyRPC.setHead(buidlerevmSnapshotId);
await hre.tenderlyNetwork.setHead(buidlerevmSnapshotId);
return;
}
await evmRevert(buidlerevmSnapshotId);

View File

@ -4,6 +4,7 @@ import {
insertContractAddressInDb,
getEthersSigners,
registerContractInJsonDb,
getEthersSignersAddresses,
} from '../../helpers/contracts-helpers';
import {
deployLendingPoolAddressesProvider,
@ -110,9 +111,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
await waitForTx(await addressesProvider.setPoolAdmin(aaveAdmin));
//setting users[1] as emergency admin, which is in position 2 in the DRE addresses list
const addressList = await Promise.all(
(await DRE.ethers.getSigners()).map((signer) => signer.getAddress())
);
const addressList = await getEthersSignersAddresses();
await waitForTx(await addressesProvider.setEmergencyAdmin(addressList[2]));

View File

@ -163,7 +163,7 @@ export async function initializeMakeSuite() {
const setSnapshot = async () => {
const hre = DRE as HardhatRuntimeEnvironment;
if (usingTenderly()) {
setBuidlerevmSnapshotId((await hre.tenderlyRPC.getHead()) || '0x1');
setBuidlerevmSnapshotId((await hre.tenderlyNetwork.getHead()) || '0x1');
return;
}
setBuidlerevmSnapshotId(await evmSnapshot());
@ -172,7 +172,7 @@ const setSnapshot = async () => {
const revertHead = async () => {
const hre = DRE as HardhatRuntimeEnvironment;
if (usingTenderly()) {
await hre.tenderlyRPC.setHead(buidlerevmSnapshotId);
await hre.tenderlyNetwork.setHead(buidlerevmSnapshotId);
return;
}
await evmRevert(buidlerevmSnapshotId);