From 8cff75f7e3e7af24dab14ba0b896a252623d60d9 Mon Sep 17 00:00:00 2001 From: The3D Date: Fri, 27 Nov 2020 16:40:00 +0100 Subject: [PATCH] Migration scripts updated --- .../deployments/ATokensAndRatesHelper.sol | 3 ++- helpers/configuration.ts | 8 ++++++++ helpers/contracts-deployments.ts | 19 +++++++++++-------- helpers/init-helpers.ts | 12 +++++++++++- markets/aave/commons.ts | 14 +++++++------- tasks/dev/5_initialize.ts | 4 ++++ tasks/full/5_initialize.ts | 6 ++++-- test/__setup.spec.ts | 9 +++++++-- 8 files changed, 54 insertions(+), 21 deletions(-) diff --git a/contracts/deployments/ATokensAndRatesHelper.sol b/contracts/deployments/ATokensAndRatesHelper.sol index 37b8353b..17de5463 100644 --- a/contracts/deployments/ATokensAndRatesHelper.sol +++ b/contracts/deployments/ATokensAndRatesHelper.sol @@ -34,6 +34,7 @@ contract ATokensAndRatesHelper is Ownable { address[] calldata tokens, string[] calldata symbols, uint256[6][] calldata rates, + address treasuryAddress, address incentivesController ) external onlyOwner { require(tokens.length == symbols.length, 't Arrays not same length'); @@ -44,7 +45,7 @@ contract ATokensAndRatesHelper is Ownable { new AToken( LendingPool(pool), tokens[i], - address(0), + treasuryAddress, StringLib.concat('Aave interest bearing ', symbols[i]), StringLib.concat('a', symbols[i]), incentivesController diff --git a/helpers/configuration.ts b/helpers/configuration.ts index 9f285c6e..14867c65 100644 --- a/helpers/configuration.ts +++ b/helpers/configuration.ts @@ -75,6 +75,14 @@ export const getEmergencyAdmin = async ( return addressList[addressIndex]; }; +export const getTreasuryAddress = async ( + config: ICommonConfiguration +): Promise => { + const currentNetwork = process.env.MAINNET_FORK === 'true' ? 'main' : DRE.network.name; + return getParamPerNetwork(config.ReserveFactorTreasuryAddress, currentNetwork); +}; + + export const getATokenDomainSeparatorPerNetwork = ( network: eEthereumNetwork, config: ICommonConfiguration diff --git a/helpers/contracts-deployments.ts b/helpers/contracts-deployments.ts index a813d293..0fa3daa3 100644 --- a/helpers/contracts-deployments.ts +++ b/helpers/contracts-deployments.ts @@ -318,11 +318,12 @@ export const deployVariableDebtToken = async ( ); export const deployGenericAToken = async ( - [poolAddress, underlyingAssetAddress, name, symbol, incentivesController]: [ + [poolAddress, underlyingAssetAddress, name, symbol, treasuryAddress, incentivesController]: [ tEthereumAddress, tEthereumAddress, string, string, + tEthereumAddress, tEthereumAddress ], verify: boolean @@ -330,11 +331,12 @@ export const deployGenericAToken = async ( const args: [ tEthereumAddress, tEthereumAddress, + string, + string, tEthereumAddress, - string, - string, tEthereumAddress - ] = [poolAddress, underlyingAssetAddress, ZERO_ADDRESS, name, symbol, incentivesController]; + + ] = [poolAddress, underlyingAssetAddress, name, symbol, treasuryAddress, incentivesController]; return withSaveAndVerify( await new ATokenFactory(await getFirstSigner()).deploy(...args), eContractid.AToken, @@ -344,11 +346,12 @@ export const deployGenericAToken = async ( }; export const deployDelegationAwareAToken = async ( - [poolAddress, underlyingAssetAddress, name, symbol, incentivesController]: [ + [poolAddress, underlyingAssetAddress, name, symbol, treasuryAddress, incentivesController]: [ tEthereumAddress, tEthereumAddress, string, string, + tEthereumAddress, tEthereumAddress ], verify: boolean @@ -356,11 +359,11 @@ export const deployDelegationAwareAToken = async ( const args: [ tEthereumAddress, tEthereumAddress, + string, + string, tEthereumAddress, - string, - string, tEthereumAddress - ] = [poolAddress, underlyingAssetAddress, ZERO_ADDRESS, name, symbol, incentivesController]; + ] = [poolAddress, underlyingAssetAddress, name, symbol, treasuryAddress, incentivesController]; return withSaveAndVerify( await new DelegationAwareATokenFactory(await getFirstSigner()).deploy(...args), eContractid.DelegationAwareAToken, diff --git a/helpers/init-helpers.ts b/helpers/init-helpers.ts index a426274c..266569b7 100644 --- a/helpers/init-helpers.ts +++ b/helpers/init-helpers.ts @@ -32,9 +32,11 @@ export const initReservesByHelper = async ( reservesParams: iMultiPoolsAssets, tokenAddresses: { [symbol: string]: tEthereumAddress }, admin: tEthereumAddress, + treasuryAddress: tEthereumAddress, incentivesController: tEthereumAddress, verify: boolean ) => { + const stableAndVariableDeployer = await getStableAndVariableTokensHelper(); const atokenAndRatesDeployer = await getATokensAndRatesHelper(); @@ -121,18 +123,25 @@ export const initReservesByHelper = async ( // Deploy stable and variable deployers and save implementations const tx1 = await waitForTx( - await stableAndVariableDeployer.initDeployment(tokens, symbols, incentivesController) + await stableAndVariableDeployer.initDeployment( + tokens, + symbols, + incentivesController + ) ); tx1.events?.forEach((event, index) => { rawInsertContractAddressInDb(`stableDebt${symbols[index]}`, event?.args?.stableToken); rawInsertContractAddressInDb(`variableDebt${symbols[index]}`, event?.args?.variableToken); }); + + // Deploy atokens and rate strategies and save implementations const tx2 = await waitForTx( await atokenAndRatesDeployer.initDeployment( tokens, symbols, strategyRates, + treasuryAddress, incentivesController ) ); @@ -178,6 +187,7 @@ export const initReservesByHelper = async ( tokenAddresses[symbol], `Aave interest bearing ${symbol}`, `a${symbol}`, + treasuryAddress, ZERO_ADDRESS, ], verify diff --git a/markets/aave/commons.ts b/markets/aave/commons.ts index 9eb71c48..17f7db14 100644 --- a/markets/aave/commons.ts +++ b/markets/aave/commons.ts @@ -306,12 +306,12 @@ export const CommonsConfig: ICommonConfiguration = { [eEthereumNetwork.tenderlyMain]: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', }, ReserveFactorTreasuryAddress: { - [eEthereumNetwork.coverage]: '', - [eEthereumNetwork.hardhat]: '', - [eEthereumNetwork.buidlerevm]: '', - [eEthereumNetwork.kovan]: '', - [eEthereumNetwork.ropsten]: '', - [eEthereumNetwork.main]: '', - [eEthereumNetwork.tenderlyMain]: '', + [eEthereumNetwork.coverage]: '0x464c71f6c2f760dda6093dcb91c24c39e5d6e18c', + [eEthereumNetwork.hardhat]: '0x464c71f6c2f760dda6093dcb91c24c39e5d6e18c', + [eEthereumNetwork.buidlerevm]: '0x464c71f6c2f760dda6093dcb91c24c39e5d6e18c', + [eEthereumNetwork.kovan]: '0x464c71f6c2f760dda6093dcb91c24c39e5d6e18c', + [eEthereumNetwork.ropsten]: '0x464c71f6c2f760dda6093dcb91c24c39e5d6e18c', + [eEthereumNetwork.main]: '0x464c71f6c2f760dda6093dcb91c24c39e5d6e18c', + [eEthereumNetwork.tenderlyMain]: '0x464c71f6c2f760dda6093dcb91c24c39e5d6e18c', }, }; diff --git a/tasks/dev/5_initialize.ts b/tasks/dev/5_initialize.ts index b4da760f..4d622e30 100644 --- a/tasks/dev/5_initialize.ts +++ b/tasks/dev/5_initialize.ts @@ -9,6 +9,7 @@ import { import { ConfigNames, getReservesConfigByPool, + getTreasuryAddress, getWethAddress, loadPoolConfig, } from '../../helpers/configuration'; @@ -50,10 +51,13 @@ task('dev:initialize-lending-pool', 'Initialize lending pool configuration.') const admin = await addressesProvider.getPoolAdmin(); + const treasuryAddress = await getTreasuryAddress(poolConfig); + await initReservesByHelper( reservesParams, protoPoolReservesAddresses, admin, + treasuryAddress, ZERO_ADDRESS, verify ); diff --git a/tasks/full/5_initialize.ts b/tasks/full/5_initialize.ts index e852c72e..7809dc6e 100644 --- a/tasks/full/5_initialize.ts +++ b/tasks/full/5_initialize.ts @@ -6,7 +6,7 @@ import { deployAaveProtocolDataProvider, deployWETHGateway, } from '../../helpers/contracts-deployments'; -import { loadPoolConfig, ConfigNames, getWethAddress } from '../../helpers/configuration'; +import { loadPoolConfig, ConfigNames, getWethAddress, getTreasuryAddress } from '../../helpers/configuration'; import { eEthereumNetwork, ICommonConfiguration } from '../../helpers/types'; import { waitForTx } from '../../helpers/misc-utils'; import { @@ -42,7 +42,9 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.') throw 'Reserve assets is undefined. Check ReserveAssets configuration at config directory'; } - await initReservesByHelper(ReservesConfig, reserveAssets, admin, ZERO_ADDRESS, verify); + const treasuryAddress = await getTreasuryAddress(poolConfig); + + await initReservesByHelper(ReservesConfig, reserveAssets, admin, treasuryAddress, ZERO_ADDRESS, verify); await enableReservesToBorrowByHelper(ReservesConfig, reserveAssets, testHelpers, admin); await enableReservesAsCollateralByHelper(ReservesConfig, reserveAssets, testHelpers, admin); diff --git a/test/__setup.spec.ts b/test/__setup.spec.ts index ad9f9388..6b43b0d3 100644 --- a/test/__setup.spec.ts +++ b/test/__setup.spec.ts @@ -26,7 +26,7 @@ import { import { Signer } from 'ethers'; import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../helpers/types'; import { MintableERC20 } from '../types/MintableERC20'; -import { getReservesConfigByPool } from '../helpers/configuration'; +import { ConfigNames, getReservesConfigByPool, getTreasuryAddress, loadPoolConfig } from '../helpers/configuration'; import { initializeMakeSuite } from './helpers/make-suite'; import { @@ -209,7 +209,12 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { const admin = await deployer.getAddress(); console.log('Initialize configuration'); - await initReservesByHelper(reservesParams, allReservesAddresses, admin, ZERO_ADDRESS); + + const config = loadPoolConfig(ConfigNames.Aave); + + const treasuryAddress = await getTreasuryAddress(config); + + await initReservesByHelper(reservesParams, allReservesAddresses, admin, treasuryAddress, ZERO_ADDRESS, false); await enableReservesToBorrowByHelper(reservesParams, allReservesAddresses, testHelpers, admin); await enableReservesAsCollateralByHelper( reservesParams,