mirror of
				https://github.com/Instadapp/aave-protocol-v2.git
				synced 2024-07-29 21:47:30 +00:00 
			
		
		
		
	Merge branch 'master' into feat/153-improve-docs
This commit is contained in:
		
						commit
						4629dcd194
					
				|  | @ -363,7 +363,7 @@ export const deployDelegationAwareAToken = async ( | |||
|   ] = [poolAddress, underlyingAssetAddress, ZERO_ADDRESS, name, symbol, incentivesController]; | ||||
|   return withSaveAndVerify( | ||||
|     await new DelegationAwareATokenFactory(await getFirstSigner()).deploy(...args), | ||||
|     eContractid.AToken, | ||||
|     eContractid.DelegationAwareAToken, | ||||
|     args, | ||||
|     verify | ||||
|   ); | ||||
|  |  | |||
|  | @ -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 { | ||||
|  | @ -8,17 +8,38 @@ import { | |||
| } from './contracts-getters'; | ||||
| import { rawInsertContractAddressInDb } from './contracts-helpers'; | ||||
| 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<IReserveParams>, | ||||
|   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)); | ||||
|  | @ -27,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
 | ||||
|  | @ -39,6 +62,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 ${ | ||||
|  | @ -129,6 +153,75 @@ export const initReservesByHelper = async ( | |||
|     deployedRates = [...deployedRates, ...strategies]; | ||||
|     reserveInitDecimals = [...reserveInitDecimals, ...reservesDecimals]; | ||||
|     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
 | ||||
|  | @ -137,7 +230,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++) { | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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 = { | ||||
|  |  | |||
|  | @ -50,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, | ||||
|  |  | |||
|  | @ -42,7 +42,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); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 eboado
						eboado