diff --git a/README.md b/README.md index d59473e7..fd702b9d 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,80 @@ docker-compose exec contracts-env bash 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 You can deploy Aave Protocol v2 in a forked Mainnet chain using Hardhat built-in fork feature: diff --git a/helpers/contracts-getters.ts b/helpers/contracts-getters.ts index b6ec5de1..e72c6754 100644 --- a/helpers/contracts-getters.ts +++ b/helpers/contracts-getters.ts @@ -29,6 +29,7 @@ import { WalletBalanceProviderFactory, WETH9MockedFactory, WETHGatewayFactory, + PermissionedWETHGatewayFactory, FlashLiquidationAdapterFactory, PermissionManagerFactory, } from '../types'; @@ -42,16 +43,18 @@ export const getFirstSigner = async () => (await getEthersSigners())[0]; export const getLendingPoolAddressesProvider = async (address?: tEthereumAddress) => { return await LendingPoolAddressesProviderFactory.connect( address || - (await getDb().get(`${eContractid.LendingPoolAddressesProvider}.${DRE.network.name}`).value()) - .address, + ( + await getDb().get(`${eContractid.LendingPoolAddressesProvider}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); }; export const getLendingPoolConfiguratorProxy = async (address?: tEthereumAddress) => { return await LendingPoolConfiguratorFactory.connect( address || - (await getDb().get(`${eContractid.LendingPoolConfigurator}.${DRE.network.name}`).value()) - .address, + ( + await getDb().get(`${eContractid.LendingPoolConfigurator}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); }; @@ -59,14 +62,18 @@ export const getLendingPoolConfiguratorProxy = async (address?: tEthereumAddress export const getLendingPool = async (address?: tEthereumAddress) => await LendingPoolFactory.connect( address || - (await getDb().get(`${eContractid.LendingPool}.${DRE.network.name}`).value()).address, + ( + await getDb().get(`${eContractid.LendingPool}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getPriceOracle = async (address?: tEthereumAddress) => await PriceOracleFactory.connect( address || - (await getDb().get(`${eContractid.PriceOracle}.${DRE.network.name}`).value()).address, + ( + await getDb().get(`${eContractid.PriceOracle}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); @@ -79,36 +86,45 @@ export const getAToken = async (address?: tEthereumAddress) => export const getStableDebtToken = async (address?: tEthereumAddress) => await StableDebtTokenFactory.connect( address || - (await getDb().get(`${eContractid.StableDebtToken}.${DRE.network.name}`).value()).address, + ( + await getDb().get(`${eContractid.StableDebtToken}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getVariableDebtToken = async (address?: tEthereumAddress) => await VariableDebtTokenFactory.connect( address || - (await getDb().get(`${eContractid.VariableDebtToken}.${DRE.network.name}`).value()).address, + ( + await getDb().get(`${eContractid.VariableDebtToken}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getMintableERC20 = async (address: tEthereumAddress) => await MintableERC20Factory.connect( address || - (await getDb().get(`${eContractid.MintableERC20}.${DRE.network.name}`).value()).address, + ( + await getDb().get(`${eContractid.MintableERC20}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getIErc20Detailed = async (address: tEthereumAddress) => await IERC20DetailedFactory.connect( address || - (await getDb().get(`${eContractid.IERC20Detailed}.${DRE.network.name}`).value()).address, + ( + await getDb().get(`${eContractid.IERC20Detailed}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getAaveProtocolDataProvider = async (address?: tEthereumAddress) => await AaveProtocolDataProviderFactory.connect( address || - (await getDb().get(`${eContractid.AaveProtocolDataProvider}.${DRE.network.name}`).value()) - .address, + ( + await getDb().get(`${eContractid.AaveProtocolDataProvider}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); @@ -126,15 +142,18 @@ export const getInterestRateStrategy = async (address?: tEthereumAddress) => export const getMockFlashLoanReceiver = async (address?: tEthereumAddress) => await MockFlashLoanReceiverFactory.connect( address || - (await getDb().get(`${eContractid.MockFlashLoanReceiver}.${DRE.network.name}`).value()) - .address, + ( + await getDb().get(`${eContractid.MockFlashLoanReceiver}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getLendingRateOracle = async (address?: tEthereumAddress) => await LendingRateOracleFactory.connect( address || - (await getDb().get(`${eContractid.LendingRateOracle}.${DRE.network.name}`).value()).address, + ( + await getDb().get(`${eContractid.LendingRateOracle}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); @@ -180,10 +199,9 @@ export const getPairsTokenAggregator = ( const aggregatorAddressIndex = Object.keys(aggregatorsAddresses).findIndex( (value) => value === tokenSymbol ); - const [, aggregatorAddress] = (Object.entries(aggregatorsAddresses) as [ - string, - tEthereumAddress - ][])[aggregatorAddressIndex]; + const [, aggregatorAddress] = ( + Object.entries(aggregatorsAddresses) as [string, tEthereumAddress][] + )[aggregatorAddressIndex]; return [tokenAddress, aggregatorAddress]; //} }) as [string, string][]; @@ -209,14 +227,18 @@ export const getLendingPoolAddressesProviderRegistry = async (address?: tEthereu export const getReserveLogic = async (address?: tEthereumAddress) => await ReserveLogicFactory.connect( address || - (await getDb().get(`${eContractid.ReserveLogic}.${DRE.network.name}`).value()).address, + ( + await getDb().get(`${eContractid.ReserveLogic}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getGenericLogic = async (address?: tEthereumAddress) => await GenericLogicFactory.connect( address || - (await getDb().get(`${eContractid.GenericLogic}.${DRE.network.name}`).value()).address, + ( + await getDb().get(`${eContractid.GenericLogic}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); @@ -234,15 +256,27 @@ export const getStableAndVariableTokensHelper = async (address?: tEthereumAddres export const getATokensAndRatesHelper = async (address?: tEthereumAddress) => await ATokensAndRatesHelperFactory.connect( address || - (await getDb().get(`${eContractid.ATokensAndRatesHelper}.${DRE.network.name}`).value()) - .address, + ( + await getDb().get(`${eContractid.ATokensAndRatesHelper}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getWETHGateway = async (address?: tEthereumAddress) => await WETHGatewayFactory.connect( 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() ); @@ -261,23 +295,27 @@ export const getMockAToken = async (address?: tEthereumAddress) => export const getMockVariableDebtToken = async (address?: tEthereumAddress) => await MockVariableDebtTokenFactory.connect( address || - (await getDb().get(`${eContractid.MockVariableDebtToken}.${DRE.network.name}`).value()) - .address, + ( + await getDb().get(`${eContractid.MockVariableDebtToken}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getMockStableDebtToken = async (address?: tEthereumAddress) => await MockStableDebtTokenFactory.connect( address || - (await getDb().get(`${eContractid.MockStableDebtToken}.${DRE.network.name}`).value()).address, + ( + await getDb().get(`${eContractid.MockStableDebtToken}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getSelfdestructTransferMock = async (address?: tEthereumAddress) => await SelfdestructTransferFactory.connect( address || - (await getDb().get(`${eContractid.SelfdestructTransferMock}.${DRE.network.name}`).value()) - .address, + ( + await getDb().get(`${eContractid.SelfdestructTransferMock}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); @@ -287,15 +325,18 @@ export const getProxy = async (address: tEthereumAddress) => export const getLendingPoolImpl = async (address?: tEthereumAddress) => await LendingPoolFactory.connect( address || - (await getDb().get(`${eContractid.LendingPoolImpl}.${DRE.network.name}`).value()).address, + ( + await getDb().get(`${eContractid.LendingPoolImpl}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getLendingPoolConfiguratorImpl = async (address?: tEthereumAddress) => await LendingPoolConfiguratorFactory.connect( address || - (await getDb().get(`${eContractid.LendingPoolConfiguratorImpl}.${DRE.network.name}`).value()) - .address, + ( + await getDb().get(`${eContractid.LendingPoolConfiguratorImpl}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); @@ -313,16 +354,18 @@ export const getLendingPoolCollateralManagerImpl = async (address?: tEthereumAdd export const getWalletProvider = async (address?: tEthereumAddress) => await WalletBalanceProviderFactory.connect( address || - (await getDb().get(`${eContractid.WalletBalanceProvider}.${DRE.network.name}`).value()) - .address, + ( + await getDb().get(`${eContractid.WalletBalanceProvider}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getLendingPoolCollateralManager = async (address?: tEthereumAddress) => await LendingPoolCollateralManagerFactory.connect( address || - (await getDb().get(`${eContractid.LendingPoolCollateralManager}.${DRE.network.name}`).value()) - .address, + ( + await getDb().get(`${eContractid.LendingPoolCollateralManager}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); @@ -338,38 +381,44 @@ export const getAaveOracle = async (address?: tEthereumAddress) => export const getMockUniswapRouter = async (address?: tEthereumAddress) => await MockUniswapV2Router02Factory.connect( address || - (await getDb().get(`${eContractid.MockUniswapV2Router02}.${DRE.network.name}`).value()) - .address, + ( + await getDb().get(`${eContractid.MockUniswapV2Router02}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getUniswapLiquiditySwapAdapter = async (address?: tEthereumAddress) => await UniswapLiquiditySwapAdapterFactory.connect( address || - (await getDb().get(`${eContractid.UniswapLiquiditySwapAdapter}.${DRE.network.name}`).value()) - .address, + ( + await getDb().get(`${eContractid.UniswapLiquiditySwapAdapter}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getUniswapRepayAdapter = async (address?: tEthereumAddress) => await UniswapRepayAdapterFactory.connect( address || - (await getDb().get(`${eContractid.UniswapRepayAdapter}.${DRE.network.name}`).value()).address, + ( + await getDb().get(`${eContractid.UniswapRepayAdapter}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getFlashLiquidationAdapter = async (address?: tEthereumAddress) => await FlashLiquidationAdapterFactory.connect( address || - (await getDb().get(`${eContractid.FlashLiquidationAdapter}.${DRE.network.name}`).value()) - .address, + ( + await getDb().get(`${eContractid.FlashLiquidationAdapter}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); export const getPermissionManager = async (address?: tEthereumAddress) => await PermissionManagerFactory.connect( address || - (await getDb().get(`${eContractid.PermissionManager}.${DRE.network.name}`).value()).address, + ( + await getDb().get(`${eContractid.PermissionManager}.${DRE.network.name}`).value() + ).address, await getFirstSigner() ); - diff --git a/package.json b/package.json index 7c677356..f1a087c4 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "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", "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", "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'", diff --git a/tasks/deployments/add-market-to-registry.ts b/tasks/deployments/add-market-to-registry.ts index 0e1d4b68..c21c7280 100644 --- a/tasks/deployments/add-market-to-registry.ts +++ b/tasks/deployments/add-market-to-registry.ts @@ -40,7 +40,7 @@ task('add-market-to-registry', 'Adds address provider to 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; providerRegistryOwner = await (await getFirstSigner()).getAddress(); diff --git a/tasks/full/6-initialize.ts b/tasks/full/6-initialize.ts index bfe2925e..fdc6df00 100644 --- a/tasks/full/6-initialize.ts +++ b/tasks/full/6-initialize.ts @@ -12,7 +12,7 @@ import { getWethAddress, getTreasuryAddress, } from '../../helpers/configuration'; -import { getWETHGateway } from '../../helpers/contracts-getters'; +import { getPermissionedWETHGateway, getWETHGateway } from '../../helpers/contracts-getters'; import { eNetwork, ICommonConfiguration } from '../../helpers/types'; import { notFalsyOrZeroAddress, waitForTx } from '../../helpers/misc-utils'; 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); if (!notFalsyOrZeroAddress(gateWay)) { - gateWay = (await getWETHGateway()).address; + if (pool === ConfigNames.AavePro) { + gateWay = (await getPermissionedWETHGateway()).address; + } else { + gateWay = (await getWETHGateway()).address; + } } console.log('GATEWAY', gateWay); await authorizeWETHGateway(gateWay, lendingPoolAddress); diff --git a/tasks/permissioned/deploy-permission-manager.ts b/tasks/permissioned/deploy-permission-manager.ts index d00138cd..eb667673 100644 --- a/tasks/permissioned/deploy-permission-manager.ts +++ b/tasks/permissioned/deploy-permission-manager.ts @@ -27,13 +27,19 @@ task(`deploy-permission-manager`, `Deploys the PermissionManager contract`) await permissionManagerInstance.deployTransaction.wait(); 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 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 await insertContractAddressInDb(