Add UNI aDelegatedToken

This commit is contained in:
David Racero 2020-11-19 17:46:23 +01:00
parent 56d25e81cb
commit 1c26eeef87
3 changed files with 102 additions and 23 deletions

View File

@ -8,17 +8,26 @@ import {
} from './contracts-getters'; } from './contracts-getters';
import { rawInsertContractAddressInDb } from './contracts-helpers'; import { rawInsertContractAddressInDb } from './contracts-helpers';
import { BigNumberish } from 'ethers'; import { BigNumberish } from 'ethers';
import {
deployDefaultReserveInterestRateStrategy,
deployDelegationAwareAToken,
deployStableDebtToken,
deployVariableDebtToken,
} from './contracts-deployments';
import { ZERO_ADDRESS } from './constants';
export const initReservesByHelper = async ( export const initReservesByHelper = async (
reservesParams: iMultiPoolsAssets<IReserveParams>, reservesParams: iMultiPoolsAssets<IReserveParams>,
tokenAddresses: { [symbol: string]: tEthereumAddress }, tokenAddresses: { [symbol: string]: tEthereumAddress },
admin: tEthereumAddress, admin: tEthereumAddress,
incentivesController: tEthereumAddress incentivesController: tEthereumAddress,
verify: boolean
) => { ) => {
const stableAndVariableDeployer = await getStableAndVariableTokensHelper(); const stableAndVariableDeployer = await getStableAndVariableTokensHelper();
const atokenAndRatesDeployer = await getATokensAndRatesHelper(); const atokenAndRatesDeployer = await getATokensAndRatesHelper();
const addressProvider = await getLendingPoolAddressesProvider(); const addressProvider = await getLendingPoolAddressesProvider();
const poolAddress = await addressProvider.getLendingPool();
// Set aTokenAndRatesDeployer as temporal admin // Set aTokenAndRatesDeployer as temporal admin
await waitForTx(await addressProvider.setPoolAdmin(atokenAndRatesDeployer.address)); await waitForTx(await addressProvider.setPoolAdmin(atokenAndRatesDeployer.address));
@ -39,6 +48,7 @@ export const initReservesByHelper = async (
let deployedRates: string[] = []; let deployedRates: string[] = [];
let reserveTokens: string[] = []; let reserveTokens: string[] = [];
let reserveInitDecimals: string[] = []; let reserveInitDecimals: string[] = [];
let reserveSymbols: string[] = [];
console.log( console.log(
`- Token deployments in ${reservesChunks.length * 2} txs instead of ${ `- Token deployments in ${reservesChunks.length * 2} txs instead of ${
@ -59,6 +69,10 @@ export const initReservesByHelper = async (
const reservesDecimals: string[] = []; const reservesDecimals: string[] = [];
for (let [assetSymbol, { reserveDecimals }] of reservesChunk) { for (let [assetSymbol, { reserveDecimals }] of reservesChunk) {
// Skip UNI due is aDelegatedToken
if (assetSymbol === 'UNI') {
continue;
}
const assetAddressIndex = Object.keys(tokenAddresses).findIndex( const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
(value) => value === assetSymbol (value) => value === assetSymbol
); );
@ -126,6 +140,62 @@ export const initReservesByHelper = async (
deployedRates = [...deployedRates, ...strategies]; deployedRates = [...deployedRates, ...strategies];
reserveInitDecimals = [...reserveInitDecimals, ...reservesDecimals]; reserveInitDecimals = [...reserveInitDecimals, ...reservesDecimals];
reserveTokens = [...reserveTokens, ...tokens]; 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 // Deploy init reserves per chunks
@ -134,7 +204,7 @@ export const initReservesByHelper = async (
const chunkedAtokens = chunk(deployedATokens, initChunks); const chunkedAtokens = chunk(deployedATokens, initChunks);
const chunkedRates = chunk(deployedRates, initChunks); const chunkedRates = chunk(deployedRates, initChunks);
const chunkedDecimals = chunk(reserveInitDecimals, 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`); console.log(`- Reserves initialization in ${chunkedStableTokens.length} txs`);
for (let chunkIndex = 0; chunkIndex < chunkedDecimals.length; chunkIndex++) { for (let chunkIndex = 0; chunkIndex < chunkedDecimals.length; chunkIndex++) {

View File

@ -22,7 +22,10 @@ import {
} from '../../helpers/init-helpers'; } from '../../helpers/init-helpers';
import { getAllTokenAddresses } from '../../helpers/mock-helpers'; import { getAllTokenAddresses } from '../../helpers/mock-helpers';
import { ZERO_ADDRESS } from '../../helpers/constants'; import { ZERO_ADDRESS } from '../../helpers/constants';
import {getAllMockedTokens, getLendingPoolAddressesProvider} from '../../helpers/contracts-getters'; import {
getAllMockedTokens,
getLendingPoolAddressesProvider,
} from '../../helpers/contracts-getters';
import { insertContractAddressInDb } from '../../helpers/contracts-helpers'; import { insertContractAddressInDb } from '../../helpers/contracts-helpers';
task('dev:initialize-lending-pool', 'Initialize lending pool configuration.') task('dev:initialize-lending-pool', 'Initialize lending pool configuration.')
@ -47,7 +50,13 @@ task('dev:initialize-lending-pool', 'Initialize lending pool configuration.')
const admin = await addressesProvider.getPoolAdmin(); const admin = await addressesProvider.getPoolAdmin();
await initReservesByHelper(reservesParams, protoPoolReservesAddresses, admin, ZERO_ADDRESS); await initReservesByHelper(
reservesParams,
protoPoolReservesAddresses,
admin,
ZERO_ADDRESS,
verify
);
await enableReservesToBorrowByHelper( await enableReservesToBorrowByHelper(
reservesParams, reservesParams,
protoPoolReservesAddresses, protoPoolReservesAddresses,

View File

@ -39,7 +39,7 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.')
throw 'Reserve assets is undefined. Check ReserveAssets configuration at config directory'; 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 enableReservesToBorrowByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
await enableReservesAsCollateralByHelper(ReservesConfig, reserveAssets, testHelpers, admin); await enableReservesAsCollateralByHelper(ReservesConfig, reserveAssets, testHelpers, admin);