From 4034c755361143388c752961215870664a36269b Mon Sep 17 00:00:00 2001 From: David Racero Date: Fri, 20 Nov 2020 12:11:57 +0100 Subject: [PATCH] Support custom aToken deployments --- helpers/contracts-deployments.ts | 2 +- helpers/init-helpers.ts | 87 ++++++++++++++++++++------------ helpers/types.ts | 4 +- markets/aave/reservesConfigs.ts | 11 +++- 4 files changed, 68 insertions(+), 36 deletions(-) diff --git a/helpers/contracts-deployments.ts b/helpers/contracts-deployments.ts index 1244a6fa..40a8c660 100644 --- a/helpers/contracts-deployments.ts +++ b/helpers/contracts-deployments.ts @@ -288,7 +288,7 @@ export const deployMintableDelegationERC20 = async ( verify ); export const deployDefaultReserveInterestRateStrategy = async ( - args: [tEthereumAddress, string, string, string, string, string], + args: [tEthereumAddress, string, string, string, string, string, string], verify: boolean ) => withSaveAndVerify( diff --git a/helpers/init-helpers.ts b/helpers/init-helpers.ts index 494c6e3f..a426274c 100644 --- a/helpers/init-helpers.ts +++ b/helpers/init-helpers.ts @@ -1,4 +1,4 @@ -import { iMultiPoolsAssets, IReserveParams, tEthereumAddress } from './types'; +import { eContractid, iMultiPoolsAssets, IReserveParams, tEthereumAddress } from './types'; import { AaveProtocolDataProvider } from '../types/AaveProtocolDataProvider'; import { chunk, waitForTx } from './misc-utils'; import { @@ -11,11 +11,23 @@ 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 ( reservesParams: iMultiPoolsAssets, tokenAddresses: { [symbol: string]: tEthereumAddress }, @@ -36,9 +48,11 @@ export const initReservesByHelper = async ( const tokensChunks = 4; const initChunks = 6; - // Deploy tokens and rates in chunks + // Deploy tokens and rates that uses common aToken in chunks const reservesChunks = chunk( - Object.entries(reservesParams) as [string, IReserveParams][], + Object.entries(reservesParams).filter( + ([_, { aTokenImpl }]) => aTokenImpl === eContractid.AToken + ) as [string, IReserveParams][], tokensChunks ); // Initialize variables for future reserves initialization @@ -70,10 +84,6 @@ 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 ); @@ -146,43 +156,56 @@ export const initReservesByHelper = async ( reserveSymbols = [...reserveSymbols, ...symbols]; } - // Deploy UNI token due is delegated aToken - if (tokenAddresses.UNI) { - console.log(' - Deploy UNI delegated aToken, debts tokens, and strategy'); + // 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, - } = reservesParams.UNI; - const aTokenUNI = await deployDelegationAwareAToken( - [poolAddress, tokenAddresses.UNI, 'Aave interest bearing UNI', 'aUNI', ZERO_ADDRESS], - verify - ); - const stableDebtUNI = await deployStableDebtToken( + } = params; + const deployCustomAToken = chooseATokenDeployment(params.aTokenImpl); + const aToken = await deployCustomAToken( [ poolAddress, - tokenAddresses.UNI, - 'Aave stable debt bearing UNI', - 'stableDebtUNI', + tokenAddresses[symbol], + `Aave interest bearing ${symbol}`, + `a${symbol}`, ZERO_ADDRESS, ], verify ); - const variableDebtUNI = await deployVariableDebtToken( + const stableDebt = await deployStableDebtToken( [ poolAddress, - tokenAddresses.UNI, - 'Aave variable debt bearing UNI', - 'variableDebtUNI', + tokenAddresses[symbol], + `Aave stable debt bearing ${symbol}`, + `stableDebt${symbol}`, ZERO_ADDRESS, ], verify ); - const ratesUNI = await deployDefaultReserveInterestRateStrategy( + const variableDebt = await deployVariableDebtToken( [ - tokenAddresses.UNI, + poolAddress, + tokenAddresses[symbol], + `Aave variable debt bearing ${symbol}`, + `variableDebt${symbol}`, + ZERO_ADDRESS, + ], + verify + ); + const rates = await deployDefaultReserveInterestRateStrategy( + [ + tokenAddresses[symbol], + optimalUtilizationRate, baseVariableBorrowRate, variableRateSlope1, variableRateSlope2, @@ -192,13 +215,13 @@ export const initReservesByHelper = async ( 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'); + 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 diff --git a/helpers/types.ts b/helpers/types.ts index 6f30622c..5467cb94 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -260,7 +260,9 @@ export enum TokenContractId { ENJ = 'ENJ', } -export interface IReserveParams extends IReserveBorrowParams, IReserveCollateralParams {} +export interface IReserveParams extends IReserveBorrowParams, IReserveCollateralParams { + aTokenImpl: eContractid; +} export interface IReserveBorrowParams { optimalUtilizationRate: string; diff --git a/markets/aave/reservesConfigs.ts b/markets/aave/reservesConfigs.ts index e8a86c13..7b0cf988 100644 --- a/markets/aave/reservesConfigs.ts +++ b/markets/aave/reservesConfigs.ts @@ -1,6 +1,6 @@ import BigNumber from 'bignumber.js'; -import {oneRay} from '../../helpers/constants'; -import {IReserveParams} from '../../helpers/types'; +import { oneRay } from '../../helpers/constants'; +import { eContractid, IReserveParams } from '../../helpers/types'; export const strategyBase: IReserveParams = { optimalUtilizationRate: new BigNumber(0.8).multipliedBy(oneRay).toFixed(), @@ -15,6 +15,7 @@ export const strategyBase: IReserveParams = { borrowingEnabled: true, stableBorrowRateEnabled: true, reserveDecimals: '18', + aTokenImpl: eContractid.AToken, }; export const stablecoinStrategyBase: IReserveParams = { @@ -30,6 +31,7 @@ export const stablecoinStrategyBase: IReserveParams = { borrowingEnabled: true, stableBorrowRateEnabled: true, reserveDecimals: '18', + aTokenImpl: eContractid.AToken, }; export const stablecoinStrategyCentralized: IReserveParams = { @@ -45,6 +47,7 @@ export const stablecoinStrategyCentralized: IReserveParams = { borrowingEnabled: true, stableBorrowRateEnabled: true, reserveDecimals: '6', + aTokenImpl: eContractid.AToken, }; export const strategyGovernanceTokens: IReserveParams = { @@ -132,6 +135,7 @@ export const stablecoinStrategySUSD: IReserveParams = { borrowingEnabled: true, stableBorrowRateEnabled: false, reserveDecimals: '18', + aTokenImpl: eContractid.AToken, }; export const strategySNX: IReserveParams = { @@ -159,6 +163,7 @@ export const stablecoinStrategyTUSD: IReserveParams = { export const strategyUNI: IReserveParams = { ...strategyGovernanceTokens, stableBorrowRateEnabled: false, + aTokenImpl: eContractid.DelegationAwareAToken, }; export const stablecoinStrategyUSDC: IReserveParams = { @@ -190,6 +195,7 @@ export const strategyWBTC: IReserveParams = { borrowingEnabled: true, stableBorrowRateEnabled: true, reserveDecimals: '8', + aTokenImpl: eContractid.AToken, }; export const strategyWETH: IReserveParams = { @@ -205,6 +211,7 @@ export const strategyWETH: IReserveParams = { borrowingEnabled: true, stableBorrowRateEnabled: true, reserveDecimals: '18', + aTokenImpl: eContractid.AToken, }; export const strategyYFI: IReserveParams = {