11import { Contract } from 'ethers' ;
2- import { DRE } from './misc-utils' ;
2+ import { DRE , notFalsyOrZeroAddress } from './misc-utils' ;
33import {
44 tEthereumAddress ,
55 eContractid ,
@@ -13,9 +13,8 @@ import {
1313} from './types' ;
1414import { MintableERC20 } from '../types/MintableERC20' ;
1515import { MockContract } from 'ethereum-waffle' ;
16- import { getReservesConfigByPool } from './configuration' ;
16+ import { ConfigNames , getReservesConfigByPool , loadPoolConfig } from './configuration' ;
1717import { getFirstSigner } from './contracts-getters' ;
18- import { ZERO_ADDRESS } from './constants' ;
1918import {
2019 AaveProtocolDataProviderFactory ,
2120 ATokenFactory ,
@@ -57,13 +56,15 @@ import {
5756 insertContractAddressInDb ,
5857 deployContract ,
5958 verifyContract ,
59+ getOptionalParamAddressPerNetwork ,
6060} from './contracts-helpers' ;
6161import { StableAndVariableTokensHelperFactory } from '../types/StableAndVariableTokensHelperFactory' ;
6262import { MintableDelegationERC20 } from '../types/MintableDelegationERC20' ;
6363import { readArtifact as buidlerReadArtifact } from '@nomiclabs/buidler/plugins' ;
6464import { HardhatRuntimeEnvironment } from 'hardhat/types' ;
6565import { LendingPoolLibraryAddresses } from '../types/LendingPoolFactory' ;
6666import { UiPoolDataProvider } from '../types' ;
67+ import { eNetwork } from './types' ;
6768
6869export const deployUiPoolDataProvider = async (
6970 [ incentivesController , aaveOracle ] : [ tEthereumAddress , tEthereumAddress ] ,
@@ -223,7 +224,7 @@ export const deployMockAggregator = async (price: tStringTokenSmallUnits, verify
223224 ) ;
224225
225226export const deployAaveOracle = async (
226- args : [ tEthereumAddress [ ] , tEthereumAddress [ ] , tEthereumAddress , tEthereumAddress ] ,
227+ args : [ tEthereumAddress [ ] , tEthereumAddress [ ] , tEthereumAddress , tEthereumAddress , string ] ,
227228 verify ?: boolean
228229) =>
229230 withSaveAndVerify (
@@ -351,20 +352,20 @@ export const deployVariableDebtToken = async (
351352 return instance ;
352353} ;
353354
354- export const deployGenericStableDebtToken = async ( ) =>
355+ export const deployGenericStableDebtToken = async ( verify ?: boolean ) =>
355356 withSaveAndVerify (
356357 await new StableDebtTokenFactory ( await getFirstSigner ( ) ) . deploy ( ) ,
357358 eContractid . StableDebtToken ,
358359 [ ] ,
359- false
360+ verify
360361 ) ;
361362
362- export const deployGenericVariableDebtToken = async ( ) =>
363+ export const deployGenericVariableDebtToken = async ( verify ?: boolean ) =>
363364 withSaveAndVerify (
364365 await new VariableDebtTokenFactory ( await getFirstSigner ( ) ) . deploy ( ) ,
365366 eContractid . VariableDebtToken ,
366367 [ ] ,
367- false
368+ verify
368369 ) ;
369370
370371export const deployGenericAToken = async (
@@ -637,3 +638,75 @@ export const deployFlashLiquidationAdapter = async (
637638 args ,
638639 verify
639640 ) ;
641+
642+ export const chooseATokenDeployment = ( id : eContractid ) => {
643+ switch ( id ) {
644+ case eContractid . AToken :
645+ return deployGenericATokenImpl ;
646+ case eContractid . DelegationAwareAToken :
647+ return deployDelegationAwareATokenImpl ;
648+ default :
649+ throw Error ( `Missing aToken implementation deployment script for: ${ id } ` ) ;
650+ }
651+ } ;
652+
653+ export const deployATokenImplementations = async (
654+ pool : ConfigNames ,
655+ reservesConfig : { [ key : string ] : IReserveParams } ,
656+ verify = false
657+ ) => {
658+ const poolConfig = loadPoolConfig ( pool ) ;
659+ const network = < eNetwork > DRE . network . name ;
660+
661+ // Obtain the different AToken implementations of all reserves inside the Market config
662+ const aTokenImplementations = [
663+ ...Object . entries ( reservesConfig ) . reduce < Set < eContractid > > ( ( acc , [ , entry ] ) => {
664+ acc . add ( entry . aTokenImpl ) ;
665+ return acc ;
666+ } , new Set < eContractid > ( ) ) ,
667+ ] ;
668+
669+ console . log ( aTokenImplementations ) ;
670+
671+ for ( let x = 0 ; x < aTokenImplementations . length ; x ++ ) {
672+ const aTokenAddress = getOptionalParamAddressPerNetwork (
673+ poolConfig [ aTokenImplementations [ x ] . toString ( ) ] ,
674+ network
675+ ) ;
676+ if ( ! notFalsyOrZeroAddress ( aTokenAddress ) ) {
677+ const deployImplementationMethod = chooseATokenDeployment ( aTokenImplementations [ x ] ) ;
678+ console . log ( `Deploying implementation` , aTokenImplementations [ x ] ) ;
679+ await deployImplementationMethod ( verify ) ;
680+ }
681+ }
682+
683+ // Debt tokens, for now all Market configs follows same implementations
684+ const genericStableDebtTokenAddress = getOptionalParamAddressPerNetwork (
685+ poolConfig . StableDebtTokenImplementation ,
686+ network
687+ ) ;
688+ const geneticVariableDebtTokenAddress = getOptionalParamAddressPerNetwork (
689+ poolConfig . VariableDebtTokenImplementation ,
690+ network
691+ ) ;
692+
693+ if ( ! notFalsyOrZeroAddress ( genericStableDebtTokenAddress ) ) {
694+ await deployGenericStableDebtToken ( verify ) ;
695+ }
696+ if ( ! notFalsyOrZeroAddress ( geneticVariableDebtTokenAddress ) ) {
697+ await deployGenericVariableDebtToken ( verify ) ;
698+ }
699+ } ;
700+
701+ export const deployRateStrategy = async (
702+ strategyName : string ,
703+ args : [ tEthereumAddress , string , string , string , string , string , string ] ,
704+ verify : boolean
705+ ) : Promise < tEthereumAddress > => {
706+ switch ( strategyName ) {
707+ default :
708+ return await (
709+ await deployDefaultReserveInterestRateStrategy ( args , verify )
710+ ) . address ;
711+ }
712+ } ;
0 commit comments