Merge branch 'feat/permissioned-market' of github.com:aave/protocol-v2 into feat/permissioned-market

This commit is contained in:
The3D 2021-06-25 14:04:54 +02:00
commit 0d7982d9a1
6 changed files with 185 additions and 51 deletions

View File

@ -138,6 +138,80 @@ docker-compose exec contracts-env bash
npm run aave:kovan:full:migration npm run aave:kovan:full:migration
``` ```
### Kovan Aave Pro Deployment
You can deploy aave-pro with default configuration on kovan.
In `markets/aave-pro/commons.ts` make following changes:
- Configure `ProviderRegistryOwner` and `ReserveFactorTreasuryAddress`
Set owner to your deployer address with kovan funds.
Set `ReserveFactorTreasuryAddress` to your team's wallet
**Notet:** Script uses first address generated, from `MNEMONIC` provided in `.env` file, as the deployer.
```
ProviderRegistryOwner: {
[eEthereumNetwork.kovan]: '0xYourDeployerAddress',
// Other network settings. You can leave them empty or same
},
ReserveFactorTreasuryAddress: {
[eEthereumNetwork.kovan]: '0xYourDeployerAddress,
// Other network settings. You can leave them empty or same
},
```
- Configure to deploy new `ProviderRegistry` and `LendingPoolCollateralManager`
Set registry and collateral manager address to empty string to deploy new registry.
```
ProviderRegistry: {
[eEthereumNetwork.kovan]: '',
// Other network settings. You can leave them empty or same
},
LendingPoolCollateralManager: {
[eEthereumNetwork.kovan]: '',
}
```
- Configure to deploy/initialize `PermissionedWethGateWay`
Set gateway address to empty string to deploy new.
```
WethGateway: {
[eEthereumNetwork.kovan]: '',
// Other network settings. You can leave them empty or same
},
```
**Note:** To configure aave pro market you can update `markets/aave-pro/`
#### Deploy Market
**Using Docker**
```
# In one terminal
docker-compose up
# Open another tab or terminal
docker-compose exec contracts-env bash
# A new Bash terminal is prompted, connected to the container
npm run pro:kovan:full:migration
```
**Without Docker**
```
npm run pro:kovan:full:migration
```
### Mainnet fork deployment ### Mainnet fork deployment
You can deploy Aave Protocol v2 in a forked Mainnet chain using Hardhat built-in fork feature: You can deploy Aave Protocol v2 in a forked Mainnet chain using Hardhat built-in fork feature:

View File

@ -29,6 +29,7 @@ import {
WalletBalanceProviderFactory, WalletBalanceProviderFactory,
WETH9MockedFactory, WETH9MockedFactory,
WETHGatewayFactory, WETHGatewayFactory,
PermissionedWETHGatewayFactory,
FlashLiquidationAdapterFactory, FlashLiquidationAdapterFactory,
PermissionManagerFactory, PermissionManagerFactory,
} from '../types'; } from '../types';
@ -42,16 +43,18 @@ export const getFirstSigner = async () => (await getEthersSigners())[0];
export const getLendingPoolAddressesProvider = async (address?: tEthereumAddress) => { export const getLendingPoolAddressesProvider = async (address?: tEthereumAddress) => {
return await LendingPoolAddressesProviderFactory.connect( return await LendingPoolAddressesProviderFactory.connect(
address || address ||
(await getDb().get(`${eContractid.LendingPoolAddressesProvider}.${DRE.network.name}`).value()) (
.address, await getDb().get(`${eContractid.LendingPoolAddressesProvider}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
}; };
export const getLendingPoolConfiguratorProxy = async (address?: tEthereumAddress) => { export const getLendingPoolConfiguratorProxy = async (address?: tEthereumAddress) => {
return await LendingPoolConfiguratorFactory.connect( return await LendingPoolConfiguratorFactory.connect(
address || address ||
(await getDb().get(`${eContractid.LendingPoolConfigurator}.${DRE.network.name}`).value()) (
.address, await getDb().get(`${eContractid.LendingPoolConfigurator}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
}; };
@ -59,14 +62,18 @@ export const getLendingPoolConfiguratorProxy = async (address?: tEthereumAddress
export const getLendingPool = async (address?: tEthereumAddress) => export const getLendingPool = async (address?: tEthereumAddress) =>
await LendingPoolFactory.connect( await LendingPoolFactory.connect(
address || address ||
(await getDb().get(`${eContractid.LendingPool}.${DRE.network.name}`).value()).address, (
await getDb().get(`${eContractid.LendingPool}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getPriceOracle = async (address?: tEthereumAddress) => export const getPriceOracle = async (address?: tEthereumAddress) =>
await PriceOracleFactory.connect( await PriceOracleFactory.connect(
address || address ||
(await getDb().get(`${eContractid.PriceOracle}.${DRE.network.name}`).value()).address, (
await getDb().get(`${eContractid.PriceOracle}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
@ -79,36 +86,45 @@ export const getAToken = async (address?: tEthereumAddress) =>
export const getStableDebtToken = async (address?: tEthereumAddress) => export const getStableDebtToken = async (address?: tEthereumAddress) =>
await StableDebtTokenFactory.connect( await StableDebtTokenFactory.connect(
address || address ||
(await getDb().get(`${eContractid.StableDebtToken}.${DRE.network.name}`).value()).address, (
await getDb().get(`${eContractid.StableDebtToken}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getVariableDebtToken = async (address?: tEthereumAddress) => export const getVariableDebtToken = async (address?: tEthereumAddress) =>
await VariableDebtTokenFactory.connect( await VariableDebtTokenFactory.connect(
address || address ||
(await getDb().get(`${eContractid.VariableDebtToken}.${DRE.network.name}`).value()).address, (
await getDb().get(`${eContractid.VariableDebtToken}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getMintableERC20 = async (address: tEthereumAddress) => export const getMintableERC20 = async (address: tEthereumAddress) =>
await MintableERC20Factory.connect( await MintableERC20Factory.connect(
address || address ||
(await getDb().get(`${eContractid.MintableERC20}.${DRE.network.name}`).value()).address, (
await getDb().get(`${eContractid.MintableERC20}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getIErc20Detailed = async (address: tEthereumAddress) => export const getIErc20Detailed = async (address: tEthereumAddress) =>
await IERC20DetailedFactory.connect( await IERC20DetailedFactory.connect(
address || address ||
(await getDb().get(`${eContractid.IERC20Detailed}.${DRE.network.name}`).value()).address, (
await getDb().get(`${eContractid.IERC20Detailed}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getAaveProtocolDataProvider = async (address?: tEthereumAddress) => export const getAaveProtocolDataProvider = async (address?: tEthereumAddress) =>
await AaveProtocolDataProviderFactory.connect( await AaveProtocolDataProviderFactory.connect(
address || address ||
(await getDb().get(`${eContractid.AaveProtocolDataProvider}.${DRE.network.name}`).value()) (
.address, await getDb().get(`${eContractid.AaveProtocolDataProvider}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
@ -126,15 +142,18 @@ export const getInterestRateStrategy = async (address?: tEthereumAddress) =>
export const getMockFlashLoanReceiver = async (address?: tEthereumAddress) => export const getMockFlashLoanReceiver = async (address?: tEthereumAddress) =>
await MockFlashLoanReceiverFactory.connect( await MockFlashLoanReceiverFactory.connect(
address || address ||
(await getDb().get(`${eContractid.MockFlashLoanReceiver}.${DRE.network.name}`).value()) (
.address, await getDb().get(`${eContractid.MockFlashLoanReceiver}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getLendingRateOracle = async (address?: tEthereumAddress) => export const getLendingRateOracle = async (address?: tEthereumAddress) =>
await LendingRateOracleFactory.connect( await LendingRateOracleFactory.connect(
address || address ||
(await getDb().get(`${eContractid.LendingRateOracle}.${DRE.network.name}`).value()).address, (
await getDb().get(`${eContractid.LendingRateOracle}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
@ -180,10 +199,9 @@ export const getPairsTokenAggregator = (
const aggregatorAddressIndex = Object.keys(aggregatorsAddresses).findIndex( const aggregatorAddressIndex = Object.keys(aggregatorsAddresses).findIndex(
(value) => value === tokenSymbol (value) => value === tokenSymbol
); );
const [, aggregatorAddress] = (Object.entries(aggregatorsAddresses) as [ const [, aggregatorAddress] = (
string, Object.entries(aggregatorsAddresses) as [string, tEthereumAddress][]
tEthereumAddress )[aggregatorAddressIndex];
][])[aggregatorAddressIndex];
return [tokenAddress, aggregatorAddress]; return [tokenAddress, aggregatorAddress];
//} //}
}) as [string, string][]; }) as [string, string][];
@ -209,14 +227,18 @@ export const getLendingPoolAddressesProviderRegistry = async (address?: tEthereu
export const getReserveLogic = async (address?: tEthereumAddress) => export const getReserveLogic = async (address?: tEthereumAddress) =>
await ReserveLogicFactory.connect( await ReserveLogicFactory.connect(
address || address ||
(await getDb().get(`${eContractid.ReserveLogic}.${DRE.network.name}`).value()).address, (
await getDb().get(`${eContractid.ReserveLogic}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getGenericLogic = async (address?: tEthereumAddress) => export const getGenericLogic = async (address?: tEthereumAddress) =>
await GenericLogicFactory.connect( await GenericLogicFactory.connect(
address || address ||
(await getDb().get(`${eContractid.GenericLogic}.${DRE.network.name}`).value()).address, (
await getDb().get(`${eContractid.GenericLogic}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
@ -234,15 +256,27 @@ export const getStableAndVariableTokensHelper = async (address?: tEthereumAddres
export const getATokensAndRatesHelper = async (address?: tEthereumAddress) => export const getATokensAndRatesHelper = async (address?: tEthereumAddress) =>
await ATokensAndRatesHelperFactory.connect( await ATokensAndRatesHelperFactory.connect(
address || address ||
(await getDb().get(`${eContractid.ATokensAndRatesHelper}.${DRE.network.name}`).value()) (
.address, await getDb().get(`${eContractid.ATokensAndRatesHelper}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getWETHGateway = async (address?: tEthereumAddress) => export const getWETHGateway = async (address?: tEthereumAddress) =>
await WETHGatewayFactory.connect( await WETHGatewayFactory.connect(
address || address ||
(await getDb().get(`${eContractid.WETHGateway}.${DRE.network.name}`).value()).address, (
await getDb().get(`${eContractid.WETHGateway}.${DRE.network.name}`).value()
).address,
await getFirstSigner()
);
export const getPermissionedWETHGateway = async (address?: tEthereumAddress) =>
await PermissionedWETHGatewayFactory.connect(
address ||
(
await getDb().get(`${eContractid.PermissionedWETHGateway}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
@ -261,23 +295,27 @@ export const getMockAToken = async (address?: tEthereumAddress) =>
export const getMockVariableDebtToken = async (address?: tEthereumAddress) => export const getMockVariableDebtToken = async (address?: tEthereumAddress) =>
await MockVariableDebtTokenFactory.connect( await MockVariableDebtTokenFactory.connect(
address || address ||
(await getDb().get(`${eContractid.MockVariableDebtToken}.${DRE.network.name}`).value()) (
.address, await getDb().get(`${eContractid.MockVariableDebtToken}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getMockStableDebtToken = async (address?: tEthereumAddress) => export const getMockStableDebtToken = async (address?: tEthereumAddress) =>
await MockStableDebtTokenFactory.connect( await MockStableDebtTokenFactory.connect(
address || address ||
(await getDb().get(`${eContractid.MockStableDebtToken}.${DRE.network.name}`).value()).address, (
await getDb().get(`${eContractid.MockStableDebtToken}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getSelfdestructTransferMock = async (address?: tEthereumAddress) => export const getSelfdestructTransferMock = async (address?: tEthereumAddress) =>
await SelfdestructTransferFactory.connect( await SelfdestructTransferFactory.connect(
address || address ||
(await getDb().get(`${eContractid.SelfdestructTransferMock}.${DRE.network.name}`).value()) (
.address, await getDb().get(`${eContractid.SelfdestructTransferMock}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
@ -287,15 +325,18 @@ export const getProxy = async (address: tEthereumAddress) =>
export const getLendingPoolImpl = async (address?: tEthereumAddress) => export const getLendingPoolImpl = async (address?: tEthereumAddress) =>
await LendingPoolFactory.connect( await LendingPoolFactory.connect(
address || address ||
(await getDb().get(`${eContractid.LendingPoolImpl}.${DRE.network.name}`).value()).address, (
await getDb().get(`${eContractid.LendingPoolImpl}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getLendingPoolConfiguratorImpl = async (address?: tEthereumAddress) => export const getLendingPoolConfiguratorImpl = async (address?: tEthereumAddress) =>
await LendingPoolConfiguratorFactory.connect( await LendingPoolConfiguratorFactory.connect(
address || address ||
(await getDb().get(`${eContractid.LendingPoolConfiguratorImpl}.${DRE.network.name}`).value()) (
.address, await getDb().get(`${eContractid.LendingPoolConfiguratorImpl}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
@ -313,16 +354,18 @@ export const getLendingPoolCollateralManagerImpl = async (address?: tEthereumAdd
export const getWalletProvider = async (address?: tEthereumAddress) => export const getWalletProvider = async (address?: tEthereumAddress) =>
await WalletBalanceProviderFactory.connect( await WalletBalanceProviderFactory.connect(
address || address ||
(await getDb().get(`${eContractid.WalletBalanceProvider}.${DRE.network.name}`).value()) (
.address, await getDb().get(`${eContractid.WalletBalanceProvider}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getLendingPoolCollateralManager = async (address?: tEthereumAddress) => export const getLendingPoolCollateralManager = async (address?: tEthereumAddress) =>
await LendingPoolCollateralManagerFactory.connect( await LendingPoolCollateralManagerFactory.connect(
address || address ||
(await getDb().get(`${eContractid.LendingPoolCollateralManager}.${DRE.network.name}`).value()) (
.address, await getDb().get(`${eContractid.LendingPoolCollateralManager}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
@ -338,38 +381,44 @@ export const getAaveOracle = async (address?: tEthereumAddress) =>
export const getMockUniswapRouter = async (address?: tEthereumAddress) => export const getMockUniswapRouter = async (address?: tEthereumAddress) =>
await MockUniswapV2Router02Factory.connect( await MockUniswapV2Router02Factory.connect(
address || address ||
(await getDb().get(`${eContractid.MockUniswapV2Router02}.${DRE.network.name}`).value()) (
.address, await getDb().get(`${eContractid.MockUniswapV2Router02}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getUniswapLiquiditySwapAdapter = async (address?: tEthereumAddress) => export const getUniswapLiquiditySwapAdapter = async (address?: tEthereumAddress) =>
await UniswapLiquiditySwapAdapterFactory.connect( await UniswapLiquiditySwapAdapterFactory.connect(
address || address ||
(await getDb().get(`${eContractid.UniswapLiquiditySwapAdapter}.${DRE.network.name}`).value()) (
.address, await getDb().get(`${eContractid.UniswapLiquiditySwapAdapter}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getUniswapRepayAdapter = async (address?: tEthereumAddress) => export const getUniswapRepayAdapter = async (address?: tEthereumAddress) =>
await UniswapRepayAdapterFactory.connect( await UniswapRepayAdapterFactory.connect(
address || address ||
(await getDb().get(`${eContractid.UniswapRepayAdapter}.${DRE.network.name}`).value()).address, (
await getDb().get(`${eContractid.UniswapRepayAdapter}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getFlashLiquidationAdapter = async (address?: tEthereumAddress) => export const getFlashLiquidationAdapter = async (address?: tEthereumAddress) =>
await FlashLiquidationAdapterFactory.connect( await FlashLiquidationAdapterFactory.connect(
address || address ||
(await getDb().get(`${eContractid.FlashLiquidationAdapter}.${DRE.network.name}`).value()) (
.address, await getDb().get(`${eContractid.FlashLiquidationAdapter}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );
export const getPermissionManager = async (address?: tEthereumAddress) => export const getPermissionManager = async (address?: tEthereumAddress) =>
await PermissionManagerFactory.connect( await PermissionManagerFactory.connect(
address || address ||
(await getDb().get(`${eContractid.PermissionManager}.${DRE.network.name}`).value()).address, (
await getDb().get(`${eContractid.PermissionManager}.${DRE.network.name}`).value()
).address,
await getFirstSigner() await getFirstSigner()
); );

View File

@ -59,6 +59,7 @@
"aave:main:full:migration": "npm run compile && npm run hardhat:main -- aave:mainnet --verify", "aave:main:full:migration": "npm run compile && npm run hardhat:main -- aave:mainnet --verify",
"aave:main:full:initialize": "npm run compile && FORK=main full:initialize-tokens --pool Aave", "aave:main:full:initialize": "npm run compile && FORK=main full:initialize-tokens --pool Aave",
"amm:main:full:migration": "npm run compile && npm run hardhat:main -- amm:mainnet --verify", "amm:main:full:migration": "npm run compile && npm run hardhat:main -- amm:mainnet --verify",
"pro:fork:kovan": "npm run compile && FORK=kovan hardhat pro:mainnet",
"pro:kovan:full:migration": "npm run compile && npm run hardhat:kovan -- pro:mainnet --verify", "pro:kovan:full:migration": "npm run compile && npm run hardhat:kovan -- pro:mainnet --verify",
"prettier:check": "npx prettier -c 'tasks/**/*.ts' 'contracts/**/*.sol' 'helpers/**/*.ts' 'test-suites/test-aave/**/*.ts'", "prettier:check": "npx prettier -c 'tasks/**/*.ts' 'contracts/**/*.sol' 'helpers/**/*.ts' 'test-suites/test-aave/**/*.ts'",
"prettier:write": "prettier --write 'tasks/**/*.ts' 'contracts/**/*.sol' 'helpers/**/*.ts' 'test-suites/test-aave/**/*.ts'", "prettier:write": "prettier --write 'tasks/**/*.ts' 'contracts/**/*.sol' 'helpers/**/*.ts' 'test-suites/test-aave/**/*.ts'",

View File

@ -40,7 +40,7 @@ task('add-market-to-registry', 'Adds address provider to registry')
) { ) {
console.log('- Deploying a new Address Providers Registry:'); console.log('- Deploying a new Address Providers Registry:');
await DRE.run('full:deploy-address-provider-registry', { verify }); await DRE.run('full:deploy-address-provider-registry', { pool, verify });
providerRegistryAddress = (await getLendingPoolAddressesProviderRegistry()).address; providerRegistryAddress = (await getLendingPoolAddressesProviderRegistry()).address;
providerRegistryOwner = await (await getFirstSigner()).getAddress(); providerRegistryOwner = await (await getFirstSigner()).getAddress();

View File

@ -12,7 +12,7 @@ import {
getWethAddress, getWethAddress,
getTreasuryAddress, getTreasuryAddress,
} from '../../helpers/configuration'; } from '../../helpers/configuration';
import { getWETHGateway } from '../../helpers/contracts-getters'; import { getPermissionedWETHGateway, getWETHGateway } from '../../helpers/contracts-getters';
import { eNetwork, ICommonConfiguration } from '../../helpers/types'; import { eNetwork, ICommonConfiguration } from '../../helpers/types';
import { notFalsyOrZeroAddress, waitForTx } from '../../helpers/misc-utils'; import { notFalsyOrZeroAddress, waitForTx } from '../../helpers/misc-utils';
import { initReservesByHelper, configureReservesByHelper } from '../../helpers/init-helpers'; import { initReservesByHelper, configureReservesByHelper } from '../../helpers/init-helpers';
@ -106,7 +106,11 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.')
let gateWay = getParamPerNetwork(WethGateway, network); let gateWay = getParamPerNetwork(WethGateway, network);
if (!notFalsyOrZeroAddress(gateWay)) { if (!notFalsyOrZeroAddress(gateWay)) {
gateWay = (await getWETHGateway()).address; if (pool === ConfigNames.AavePro) {
gateWay = (await getPermissionedWETHGateway()).address;
} else {
gateWay = (await getWETHGateway()).address;
}
} }
console.log('GATEWAY', gateWay); console.log('GATEWAY', gateWay);
await authorizeWETHGateway(gateWay, lendingPoolAddress); await authorizeWETHGateway(gateWay, lendingPoolAddress);

View File

@ -27,13 +27,19 @@ task(`deploy-permission-manager`, `Deploys the PermissionManager contract`)
await permissionManagerInstance.deployTransaction.wait(); await permissionManagerInstance.deployTransaction.wait();
console.log('Permission manager address', permissionManagerInstance.address); console.log('Permission manager address', permissionManagerInstance.address);
await verifyContract(eContractid.PermissionManager, permissionManagerInstance, []); if (verify) {
await verifyContract(eContractid.PermissionManager, permissionManagerInstance, []);
}
// register the permission manager in the addresses provider // register the permission manager in the addresses provider
const addressesProvider = await getLendingPoolAddressesProvider(); const addressesProvider = await getLendingPoolAddressesProvider();
const permissionManagerHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes("PERMISSION_MANAGER")); const permissionManagerHash = ethers.utils.keccak256(
ethers.utils.toUtf8Bytes('PERMISSION_MANAGER')
);
await waitForTx(await addressesProvider.setAddress(permissionManagerHash, permissionManagerInstance.address)); await waitForTx(
await addressesProvider.setAddress(permissionManagerHash, permissionManagerInstance.address)
);
// store the permission manager contract in the DB // store the permission manager contract in the DB
await insertContractAddressInDb( await insertContractAddressInDb(