2020-08-25 12:15:35 +00:00
|
|
|
import {
|
|
|
|
AavePools,
|
|
|
|
iMultiPoolsAssets,
|
|
|
|
IReserveParams,
|
2020-08-25 15:15:27 +00:00
|
|
|
PoolConfiguration,
|
2020-09-15 15:24:50 +00:00
|
|
|
ICommonConfiguration,
|
|
|
|
eEthereumNetwork,
|
2020-08-25 12:15:35 +00:00
|
|
|
} from './types';
|
2020-11-18 18:18:02 +00:00
|
|
|
import { getParamPerPool } from './contracts-helpers';
|
2020-11-17 08:33:45 +00:00
|
|
|
import AaveConfig from '../markets/aave';
|
2021-02-08 16:05:10 +00:00
|
|
|
import LpConfig from '../markets/lp';
|
2021-02-19 23:50:24 +00:00
|
|
|
import MaticConfig from '../markets/matic'
|
2020-11-18 18:18:02 +00:00
|
|
|
import { CommonsConfig } from '../markets/aave/commons';
|
|
|
|
import { DRE, filterMapBy } from './misc-utils';
|
|
|
|
import { tEthereumAddress } from './types';
|
|
|
|
import { getParamPerNetwork } from './contracts-helpers';
|
|
|
|
import { deployWETHMocked } from './contracts-deployments';
|
2020-08-25 12:15:35 +00:00
|
|
|
|
2020-08-25 15:15:27 +00:00
|
|
|
export enum ConfigNames {
|
|
|
|
Commons = 'Commons',
|
|
|
|
Aave = 'Aave',
|
2021-02-08 16:05:10 +00:00
|
|
|
Lp = 'Lp',
|
2021-02-19 23:50:24 +00:00
|
|
|
Matic = 'Matic',
|
2020-08-25 15:15:27 +00:00
|
|
|
}
|
2020-08-25 12:15:35 +00:00
|
|
|
|
2020-08-25 15:15:27 +00:00
|
|
|
export const loadPoolConfig = (configName: ConfigNames): PoolConfiguration => {
|
|
|
|
switch (configName) {
|
|
|
|
case ConfigNames.Aave:
|
|
|
|
return AaveConfig;
|
2021-02-08 16:05:10 +00:00
|
|
|
case ConfigNames.Lp:
|
|
|
|
return LpConfig;
|
2021-02-19 23:50:24 +00:00
|
|
|
case ConfigNames.Matic:
|
|
|
|
return MaticConfig;
|
2020-09-15 15:24:50 +00:00
|
|
|
case ConfigNames.Commons:
|
|
|
|
return CommonsConfig;
|
2020-08-25 15:15:27 +00:00
|
|
|
default:
|
|
|
|
throw new Error(`Unsupported pool configuration: ${Object.values(ConfigNames)}`);
|
|
|
|
}
|
|
|
|
};
|
2020-08-25 12:15:35 +00:00
|
|
|
|
|
|
|
// ----------------
|
|
|
|
// PROTOCOL PARAMS PER POOL
|
|
|
|
// ----------------
|
|
|
|
|
|
|
|
export const getReservesConfigByPool = (pool: AavePools): iMultiPoolsAssets<IReserveParams> =>
|
|
|
|
getParamPerPool<iMultiPoolsAssets<IReserveParams>>(
|
|
|
|
{
|
|
|
|
[AavePools.proto]: {
|
|
|
|
...AaveConfig.ReservesConfig,
|
|
|
|
},
|
2021-02-08 16:05:10 +00:00
|
|
|
[AavePools.lp]: {
|
|
|
|
...LpConfig.ReservesConfig,
|
2020-12-25 05:47:30 +00:00
|
|
|
},
|
2021-02-19 23:50:24 +00:00
|
|
|
[AavePools.matic] : {
|
|
|
|
...MaticConfig.ReservesConfig,
|
|
|
|
},
|
2020-08-25 12:15:35 +00:00
|
|
|
},
|
|
|
|
pool
|
|
|
|
);
|
|
|
|
|
2020-11-10 12:11:33 +00:00
|
|
|
export const getGenesisPoolAdmin = async (
|
|
|
|
config: ICommonConfiguration
|
|
|
|
): Promise<tEthereumAddress> => {
|
2020-11-18 18:18:02 +00:00
|
|
|
const currentNetwork = process.env.MAINNET_FORK === 'true' ? 'main' : DRE.network.name;
|
2020-11-05 11:35:50 +00:00
|
|
|
const targetAddress = getParamPerNetwork(config.PoolAdmin, <eEthereumNetwork>currentNetwork);
|
2020-09-15 15:24:50 +00:00
|
|
|
if (targetAddress) {
|
|
|
|
return targetAddress;
|
|
|
|
}
|
|
|
|
const addressList = await Promise.all(
|
2020-11-06 11:19:08 +00:00
|
|
|
(await DRE.ethers.getSigners()).map((signer) => signer.getAddress())
|
2020-09-15 15:24:50 +00:00
|
|
|
);
|
2020-11-05 11:35:50 +00:00
|
|
|
const addressIndex = config.PoolAdminIndex;
|
|
|
|
return addressList[addressIndex];
|
|
|
|
};
|
|
|
|
|
2020-11-10 12:11:33 +00:00
|
|
|
export const getEmergencyAdmin = async (
|
|
|
|
config: ICommonConfiguration
|
|
|
|
): Promise<tEthereumAddress> => {
|
2020-11-18 18:18:02 +00:00
|
|
|
const currentNetwork = process.env.MAINNET_FORK === 'true' ? 'main' : DRE.network.name;
|
2020-11-05 11:35:50 +00:00
|
|
|
const targetAddress = getParamPerNetwork(config.EmergencyAdmin, <eEthereumNetwork>currentNetwork);
|
|
|
|
if (targetAddress) {
|
|
|
|
return targetAddress;
|
|
|
|
}
|
|
|
|
const addressList = await Promise.all(
|
2020-11-06 11:19:08 +00:00
|
|
|
(await DRE.ethers.getSigners()).map((signer) => signer.getAddress())
|
2020-11-05 11:35:50 +00:00
|
|
|
);
|
|
|
|
const addressIndex = config.EmergencyAdminIndex;
|
2020-09-15 15:24:50 +00:00
|
|
|
return addressList[addressIndex];
|
|
|
|
};
|
|
|
|
|
2020-11-27 15:40:00 +00:00
|
|
|
export const getTreasuryAddress = async (
|
|
|
|
config: ICommonConfiguration
|
|
|
|
): Promise<tEthereumAddress> => {
|
|
|
|
const currentNetwork = process.env.MAINNET_FORK === 'true' ? 'main' : DRE.network.name;
|
|
|
|
return getParamPerNetwork(config.ReserveFactorTreasuryAddress, <eEthereumNetwork>currentNetwork);
|
|
|
|
};
|
|
|
|
|
2020-09-15 15:24:50 +00:00
|
|
|
export const getATokenDomainSeparatorPerNetwork = (
|
|
|
|
network: eEthereumNetwork,
|
|
|
|
config: ICommonConfiguration
|
|
|
|
): tEthereumAddress => getParamPerNetwork<tEthereumAddress>(config.ATokenDomainSeparator, network);
|
2020-10-28 17:06:24 +00:00
|
|
|
|
|
|
|
export const getWethAddress = async (config: ICommonConfiguration) => {
|
2020-11-18 18:18:02 +00:00
|
|
|
const currentNetwork = process.env.MAINNET_FORK === 'true' ? 'main' : DRE.network.name;
|
2020-10-28 17:06:24 +00:00
|
|
|
const wethAddress = getParamPerNetwork(config.WETH, <eEthereumNetwork>currentNetwork);
|
|
|
|
if (wethAddress) {
|
|
|
|
return wethAddress;
|
|
|
|
}
|
2020-11-02 16:51:54 +00:00
|
|
|
if (currentNetwork.includes('main')) {
|
|
|
|
throw new Error('WETH not set at mainnet configuration.');
|
|
|
|
}
|
|
|
|
const weth = await deployWETHMocked();
|
2020-10-28 17:06:24 +00:00
|
|
|
return weth.address;
|
|
|
|
};
|
2020-11-16 15:08:07 +00:00
|
|
|
|
|
|
|
export const getLendingRateOracles = (poolConfig: ICommonConfiguration) => {
|
|
|
|
const {
|
2020-11-18 18:18:02 +00:00
|
|
|
ProtocolGlobalParams: { UsdAddress },
|
2020-11-16 15:08:07 +00:00
|
|
|
LendingRateOracleRatesCommon,
|
|
|
|
ReserveAssets,
|
|
|
|
} = poolConfig;
|
|
|
|
|
2020-11-16 18:22:22 +00:00
|
|
|
const MAINNET_FORK = process.env.MAINNET_FORK === 'true';
|
2020-11-16 15:08:07 +00:00
|
|
|
const network = MAINNET_FORK ? 'main' : DRE.network.name;
|
|
|
|
return filterMapBy(LendingRateOracleRatesCommon, (key) =>
|
|
|
|
Object.keys(ReserveAssets[network]).includes(key)
|
|
|
|
);
|
|
|
|
};
|