From 1c26eeef877f3b7d3f6044f1da96d2577657fcaf Mon Sep 17 00:00:00 2001 From: David Racero Date: Thu, 19 Nov 2020 17:46:23 +0100 Subject: [PATCH] Add UNI aDelegatedToken --- helpers/init-helpers.ts | 74 ++++++++++++++++++++++++++++++++++++-- tasks/dev/5_initialize.ts | 29 +++++++++------ tasks/full/5_initialize.ts | 22 ++++++------ 3 files changed, 102 insertions(+), 23 deletions(-) diff --git a/helpers/init-helpers.ts b/helpers/init-helpers.ts index 35de7ac9..2f04d30a 100644 --- a/helpers/init-helpers.ts +++ b/helpers/init-helpers.ts @@ -8,17 +8,26 @@ import { } from './contracts-getters'; import { rawInsertContractAddressInDb } from './contracts-helpers'; import { BigNumberish } from 'ethers'; +import { + deployDefaultReserveInterestRateStrategy, + deployDelegationAwareAToken, + deployStableDebtToken, + deployVariableDebtToken, +} from './contracts-deployments'; +import { ZERO_ADDRESS } from './constants'; export const initReservesByHelper = async ( reservesParams: iMultiPoolsAssets, tokenAddresses: { [symbol: string]: tEthereumAddress }, admin: tEthereumAddress, - incentivesController: tEthereumAddress + incentivesController: tEthereumAddress, + verify: boolean ) => { const stableAndVariableDeployer = await getStableAndVariableTokensHelper(); const atokenAndRatesDeployer = await getATokensAndRatesHelper(); const addressProvider = await getLendingPoolAddressesProvider(); + const poolAddress = await addressProvider.getLendingPool(); // Set aTokenAndRatesDeployer as temporal admin await waitForTx(await addressProvider.setPoolAdmin(atokenAndRatesDeployer.address)); @@ -39,6 +48,7 @@ export const initReservesByHelper = async ( let deployedRates: string[] = []; let reserveTokens: string[] = []; let reserveInitDecimals: string[] = []; + let reserveSymbols: string[] = []; console.log( `- Token deployments in ${reservesChunks.length * 2} txs instead of ${ @@ -59,6 +69,10 @@ export const initReservesByHelper = async ( const reservesDecimals: string[] = []; for (let [assetSymbol, { reserveDecimals }] of reservesChunk) { + // Skip UNI due is aDelegatedToken + if (assetSymbol === 'UNI') { + continue; + } const assetAddressIndex = Object.keys(tokenAddresses).findIndex( (value) => value === assetSymbol ); @@ -126,6 +140,62 @@ export const initReservesByHelper = async ( deployedRates = [...deployedRates, ...strategies]; reserveInitDecimals = [...reserveInitDecimals, ...reservesDecimals]; reserveTokens = [...reserveTokens, ...tokens]; + reserveSymbols = [...reserveSymbols, ...symbols]; + } + + // Deploy UNI token due is delegated aToken + if (tokenAddresses.UNI) { + console.log(' - Deploy UNI delegated aToken, debts tokens, and strategy'); + const { + baseVariableBorrowRate, + variableRateSlope1, + variableRateSlope2, + stableRateSlope1, + stableRateSlope2, + } = reservesParams.UNI; + const aTokenUNI = await deployDelegationAwareAToken( + [poolAddress, tokenAddresses.UNI, 'Aave interest bearing ', 'aUNI', ZERO_ADDRESS], + verify + ); + const stableDebtUNI = await deployStableDebtToken( + [ + poolAddress, + tokenAddresses.UNI, + 'Aave stable debt bearing UNI', + 'stableDebtUNI', + ZERO_ADDRESS, + ], + verify + ); + const variableDebtUNI = await deployVariableDebtToken( + [ + poolAddress, + tokenAddresses.UNI, + 'Aave variable debt bearing UNI', + 'variableDebtUNI', + ZERO_ADDRESS, + ], + verify + ); + const ratesUNI = await deployDefaultReserveInterestRateStrategy( + [ + tokenAddresses.UNI, + baseVariableBorrowRate, + variableRateSlope1, + variableRateSlope2, + stableRateSlope1, + stableRateSlope2, + ], + verify + ); + + deployedStableTokens.push(stableDebtUNI.address); + deployedVariableTokens.push(variableDebtUNI.address); + deployedATokens.push(aTokenUNI.address); + deployedRates.push(ratesUNI.address); + reserveInitDecimals.push(reservesParams.UNI.reserveDecimals); + reserveTokens.push(tokenAddresses.UNI); + reserveSymbols.push('UNI'); } // Deploy init reserves per chunks @@ -134,7 +204,7 @@ export const initReservesByHelper = async ( const chunkedAtokens = chunk(deployedATokens, initChunks); const chunkedRates = chunk(deployedRates, initChunks); const chunkedDecimals = chunk(reserveInitDecimals, initChunks); - const chunkedSymbols = chunk(Object.keys(tokenAddresses), initChunks); + const chunkedSymbols = chunk(reserveSymbols, initChunks); console.log(`- Reserves initialization in ${chunkedStableTokens.length} txs`); for (let chunkIndex = 0; chunkIndex < chunkedDecimals.length; chunkIndex++) { diff --git a/tasks/dev/5_initialize.ts b/tasks/dev/5_initialize.ts index 11d25729..806ac13e 100644 --- a/tasks/dev/5_initialize.ts +++ b/tasks/dev/5_initialize.ts @@ -1,4 +1,4 @@ -import {task} from 'hardhat/config'; +import { task } from 'hardhat/config'; import { deployLendingPoolCollateralManager, deployMockFlashLoanReceiver, @@ -13,22 +13,25 @@ import { loadPoolConfig, } from '../../helpers/configuration'; -import {tEthereumAddress, AavePools, eContractid} from '../../helpers/types'; -import {waitForTx, filterMapBy} from '../../helpers/misc-utils'; +import { tEthereumAddress, AavePools, eContractid } from '../../helpers/types'; +import { waitForTx, filterMapBy } from '../../helpers/misc-utils'; import { enableReservesToBorrowByHelper, enableReservesAsCollateralByHelper, initReservesByHelper, } from '../../helpers/init-helpers'; -import {getAllTokenAddresses} from '../../helpers/mock-helpers'; -import {ZERO_ADDRESS} from '../../helpers/constants'; -import {getAllMockedTokens, getLendingPoolAddressesProvider} from '../../helpers/contracts-getters'; -import {insertContractAddressInDb} from '../../helpers/contracts-helpers'; +import { getAllTokenAddresses } from '../../helpers/mock-helpers'; +import { ZERO_ADDRESS } from '../../helpers/constants'; +import { + getAllMockedTokens, + getLendingPoolAddressesProvider, +} from '../../helpers/contracts-getters'; +import { insertContractAddressInDb } from '../../helpers/contracts-helpers'; task('dev:initialize-lending-pool', 'Initialize lending pool configuration.') .addFlag('verify', 'Verify contracts at Etherscan') .addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`) - .setAction(async ({verify, pool}, localBRE) => { + .setAction(async ({ verify, pool }, localBRE) => { await localBRE.run('set-DRE'); const poolConfig = loadPoolConfig(pool); @@ -37,7 +40,7 @@ task('dev:initialize-lending-pool', 'Initialize lending pool configuration.') const addressesProvider = await getLendingPoolAddressesProvider(); - const protoPoolReservesAddresses = <{[symbol: string]: tEthereumAddress}>( + const protoPoolReservesAddresses = <{ [symbol: string]: tEthereumAddress }>( filterMapBy(allTokenAddresses, (key: string) => !key.includes('UNI_')) ); @@ -47,7 +50,13 @@ task('dev:initialize-lending-pool', 'Initialize lending pool configuration.') const admin = await addressesProvider.getPoolAdmin(); - await initReservesByHelper(reservesParams, protoPoolReservesAddresses, admin, ZERO_ADDRESS); + await initReservesByHelper( + reservesParams, + protoPoolReservesAddresses, + admin, + ZERO_ADDRESS, + verify + ); await enableReservesToBorrowByHelper( reservesParams, protoPoolReservesAddresses, diff --git a/tasks/full/5_initialize.ts b/tasks/full/5_initialize.ts index 99b55f15..64307500 100644 --- a/tasks/full/5_initialize.ts +++ b/tasks/full/5_initialize.ts @@ -1,32 +1,32 @@ -import {task} from 'hardhat/config'; -import {getParamPerNetwork} from '../../helpers/contracts-helpers'; +import { task } from 'hardhat/config'; +import { getParamPerNetwork } from '../../helpers/contracts-helpers'; import { deployLendingPoolCollateralManager, deployWalletBalancerProvider, deployAaveProtocolDataProvider, deployWETHGateway, } from '../../helpers/contracts-deployments'; -import {loadPoolConfig, ConfigNames, getWethAddress} from '../../helpers/configuration'; -import {eEthereumNetwork, ICommonConfiguration} from '../../helpers/types'; -import {waitForTx} from '../../helpers/misc-utils'; +import { loadPoolConfig, ConfigNames, getWethAddress } from '../../helpers/configuration'; +import { eEthereumNetwork, ICommonConfiguration } from '../../helpers/types'; +import { waitForTx } from '../../helpers/misc-utils'; import { initReservesByHelper, enableReservesToBorrowByHelper, enableReservesAsCollateralByHelper, } from '../../helpers/init-helpers'; -import {exit} from 'process'; -import {getLendingPoolAddressesProvider} from '../../helpers/contracts-getters'; -import {ZERO_ADDRESS} from '../../helpers/constants'; +import { exit } from 'process'; +import { getLendingPoolAddressesProvider } from '../../helpers/contracts-getters'; +import { ZERO_ADDRESS } from '../../helpers/constants'; task('full:initialize-lending-pool', 'Initialize lending pool configuration.') .addFlag('verify', 'Verify contracts at Etherscan') .addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`) - .setAction(async ({verify, pool}, localBRE) => { + .setAction(async ({ verify, pool }, localBRE) => { try { await localBRE.run('set-DRE'); const network = localBRE.network.name; const poolConfig = loadPoolConfig(pool); - const {ReserveAssets, ReservesConfig} = poolConfig as ICommonConfiguration; + const { ReserveAssets, ReservesConfig } = poolConfig as ICommonConfiguration; const reserveAssets = await getParamPerNetwork(ReserveAssets, network); @@ -39,7 +39,7 @@ 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); + await initReservesByHelper(ReservesConfig, reserveAssets, admin, ZERO_ADDRESS, verify); await enableReservesToBorrowByHelper(ReservesConfig, reserveAssets, testHelpers, admin); await enableReservesAsCollateralByHelper(ReservesConfig, reserveAssets, testHelpers, admin);