Merge branch '155-use-the-delegationawareatoken-for-the-uni-deployment' into 'master'

Support custom aToken implementation via ReserveConfig.ATokenImpl

Closes #155

See merge request aave-tech/protocol-v2!174
This commit is contained in:
Ernesto Boado 2020-11-23 14:53:28 +00:00
commit 13ce62ebe4
6 changed files with 119 additions and 11 deletions

View File

@ -363,7 +363,7 @@ export const deployDelegationAwareAToken = async (
] = [poolAddress, underlyingAssetAddress, ZERO_ADDRESS, name, symbol, incentivesController]; ] = [poolAddress, underlyingAssetAddress, ZERO_ADDRESS, name, symbol, incentivesController];
return withSaveAndVerify( return withSaveAndVerify(
await new DelegationAwareATokenFactory(await getFirstSigner()).deploy(...args), await new DelegationAwareATokenFactory(await getFirstSigner()).deploy(...args),
eContractid.AToken, eContractid.DelegationAwareAToken,
args, args,
verify verify
); );

View File

@ -1,4 +1,4 @@
import { iMultiPoolsAssets, IReserveParams, tEthereumAddress } from './types'; import { eContractid, iMultiPoolsAssets, IReserveParams, tEthereumAddress } from './types';
import { AaveProtocolDataProvider } from '../types/AaveProtocolDataProvider'; import { AaveProtocolDataProvider } from '../types/AaveProtocolDataProvider';
import { chunk, waitForTx } from './misc-utils'; import { chunk, waitForTx } from './misc-utils';
import { import {
@ -8,17 +8,38 @@ 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,
deployGenericAToken,
deployStableDebtToken,
deployVariableDebtToken,
} from './contracts-deployments';
import { ZERO_ADDRESS } from './constants';
const chooseATokenDeployment = (id: eContractid) => {
switch (id) {
case eContractid.AToken:
return deployGenericAToken;
case eContractid.DelegationAwareAToken:
return deployDelegationAwareAToken;
default:
throw Error(`Missing aToken deployment script for: ${id}`);
}
};
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));
@ -27,9 +48,11 @@ export const initReservesByHelper = async (
const tokensChunks = 4; const tokensChunks = 4;
const initChunks = 6; const initChunks = 6;
// Deploy tokens and rates in chunks // Deploy tokens and rates that uses common aToken in chunks
const reservesChunks = chunk( const reservesChunks = chunk(
Object.entries(reservesParams) as [string, IReserveParams][], Object.entries(reservesParams).filter(
([_, { aTokenImpl }]) => aTokenImpl === eContractid.AToken
) as [string, IReserveParams][],
tokensChunks tokensChunks
); );
// Initialize variables for future reserves initialization // Initialize variables for future reserves initialization
@ -39,6 +62,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 ${
@ -129,6 +153,75 @@ 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 delegated aware reserves tokens
const delegatedAwareReserves = Object.entries(reservesParams).filter(
([_, { aTokenImpl }]) => aTokenImpl === eContractid.DelegationAwareAToken
) as [string, IReserveParams][];
for (let [symbol, params] of delegatedAwareReserves) {
console.log(` - Deploy ${symbol} delegation await aToken, debts tokens, and strategy`);
const {
optimalUtilizationRate,
baseVariableBorrowRate,
variableRateSlope1,
variableRateSlope2,
stableRateSlope1,
stableRateSlope2,
} = params;
const deployCustomAToken = chooseATokenDeployment(params.aTokenImpl);
const aToken = await deployCustomAToken(
[
poolAddress,
tokenAddresses[symbol],
`Aave interest bearing ${symbol}`,
`a${symbol}`,
ZERO_ADDRESS,
],
verify
);
const stableDebt = await deployStableDebtToken(
[
poolAddress,
tokenAddresses[symbol],
`Aave stable debt bearing ${symbol}`,
`stableDebt${symbol}`,
ZERO_ADDRESS,
],
verify
);
const variableDebt = await deployVariableDebtToken(
[
poolAddress,
tokenAddresses[symbol],
`Aave variable debt bearing ${symbol}`,
`variableDebt${symbol}`,
ZERO_ADDRESS,
],
verify
);
const rates = await deployDefaultReserveInterestRateStrategy(
[
tokenAddresses[symbol],
optimalUtilizationRate,
baseVariableBorrowRate,
variableRateSlope1,
variableRateSlope2,
stableRateSlope1,
stableRateSlope2,
],
verify
);
deployedStableTokens.push(stableDebt.address);
deployedVariableTokens.push(variableDebt.address);
deployedATokens.push(aToken.address);
deployedRates.push(rates.address);
reserveInitDecimals.push(params.reserveDecimals);
reserveTokens.push(tokenAddresses[symbol]);
reserveSymbols.push(symbol);
} }
// Deploy init reserves per chunks // Deploy init reserves per chunks
@ -137,7 +230,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

@ -260,7 +260,9 @@ export enum TokenContractId {
ENJ = 'ENJ', ENJ = 'ENJ',
} }
export interface IReserveParams extends IReserveBorrowParams, IReserveCollateralParams {} export interface IReserveParams extends IReserveBorrowParams, IReserveCollateralParams {
aTokenImpl: eContractid;
}
export interface IReserveBorrowParams { export interface IReserveBorrowParams {
optimalUtilizationRate: string; optimalUtilizationRate: string;

View File

@ -1,6 +1,6 @@
import BigNumber from 'bignumber.js'; import BigNumber from 'bignumber.js';
import {oneRay} from '../../helpers/constants'; import { oneRay } from '../../helpers/constants';
import {IReserveParams} from '../../helpers/types'; import { eContractid, IReserveParams } from '../../helpers/types';
export const strategyBase: IReserveParams = { export const strategyBase: IReserveParams = {
optimalUtilizationRate: new BigNumber(0.8).multipliedBy(oneRay).toFixed(), optimalUtilizationRate: new BigNumber(0.8).multipliedBy(oneRay).toFixed(),
@ -15,6 +15,7 @@ export const strategyBase: IReserveParams = {
borrowingEnabled: true, borrowingEnabled: true,
stableBorrowRateEnabled: true, stableBorrowRateEnabled: true,
reserveDecimals: '18', reserveDecimals: '18',
aTokenImpl: eContractid.AToken,
}; };
export const stablecoinStrategyBase: IReserveParams = { export const stablecoinStrategyBase: IReserveParams = {
@ -30,6 +31,7 @@ export const stablecoinStrategyBase: IReserveParams = {
borrowingEnabled: true, borrowingEnabled: true,
stableBorrowRateEnabled: true, stableBorrowRateEnabled: true,
reserveDecimals: '18', reserveDecimals: '18',
aTokenImpl: eContractid.AToken,
}; };
export const stablecoinStrategyCentralized: IReserveParams = { export const stablecoinStrategyCentralized: IReserveParams = {
@ -45,6 +47,7 @@ export const stablecoinStrategyCentralized: IReserveParams = {
borrowingEnabled: true, borrowingEnabled: true,
stableBorrowRateEnabled: true, stableBorrowRateEnabled: true,
reserveDecimals: '6', reserveDecimals: '6',
aTokenImpl: eContractid.AToken,
}; };
export const strategyGovernanceTokens: IReserveParams = { export const strategyGovernanceTokens: IReserveParams = {
@ -132,6 +135,7 @@ export const stablecoinStrategySUSD: IReserveParams = {
borrowingEnabled: true, borrowingEnabled: true,
stableBorrowRateEnabled: false, stableBorrowRateEnabled: false,
reserveDecimals: '18', reserveDecimals: '18',
aTokenImpl: eContractid.AToken,
}; };
export const strategySNX: IReserveParams = { export const strategySNX: IReserveParams = {
@ -159,6 +163,7 @@ export const stablecoinStrategyTUSD: IReserveParams = {
export const strategyUNI: IReserveParams = { export const strategyUNI: IReserveParams = {
...strategyGovernanceTokens, ...strategyGovernanceTokens,
stableBorrowRateEnabled: false, stableBorrowRateEnabled: false,
aTokenImpl: eContractid.DelegationAwareAToken,
}; };
export const stablecoinStrategyUSDC: IReserveParams = { export const stablecoinStrategyUSDC: IReserveParams = {
@ -190,6 +195,7 @@ export const strategyWBTC: IReserveParams = {
borrowingEnabled: true, borrowingEnabled: true,
stableBorrowRateEnabled: true, stableBorrowRateEnabled: true,
reserveDecimals: '8', reserveDecimals: '8',
aTokenImpl: eContractid.AToken,
}; };
export const strategyWETH: IReserveParams = { export const strategyWETH: IReserveParams = {
@ -205,6 +211,7 @@ export const strategyWETH: IReserveParams = {
borrowingEnabled: true, borrowingEnabled: true,
stableBorrowRateEnabled: true, stableBorrowRateEnabled: true,
reserveDecimals: '18', reserveDecimals: '18',
aTokenImpl: eContractid.AToken,
}; };
export const strategyYFI: IReserveParams = { export const strategyYFI: IReserveParams = {

View File

@ -50,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

@ -42,7 +42,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);