aave-protocol-v2/helpers/configuration.ts

109 lines
3.3 KiB
TypeScript
Raw Normal View History

2020-08-25 12:15:35 +00:00
import {
AavePools,
iMultiPoolsAssets,
IReserveParams,
PoolConfiguration,
2020-09-15 15:24:50 +00:00
ICommonConfiguration,
eEthereumNetwork,
2020-08-25 12:15:35 +00:00
} from './types';
import {getParamPerPool} from './contracts-helpers';
import AaveConfig from '../markets/aave';
import {CommonsConfig} from '../markets/aave/commons';
import {DRE, filterMapBy} from './misc-utils';
2020-09-15 15:24:50 +00:00
import {tEthereumAddress} from './types';
import {getParamPerNetwork} from './contracts-helpers';
import {deployWETHMocked} from './contracts-deployments';
2020-08-25 12:15:35 +00:00
export enum ConfigNames {
Commons = 'Commons',
Aave = 'Aave',
Uniswap = 'Uniswap',
}
2020-08-25 12:15:35 +00:00
export const loadPoolConfig = (configName: ConfigNames): PoolConfiguration => {
switch (configName) {
case ConfigNames.Aave:
return AaveConfig;
2020-09-15 15:24:50 +00:00
case ConfigNames.Commons:
return CommonsConfig;
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,
},
},
pool
);
export const getGenesisPoolAdmin = async (
config: ICommonConfiguration
): Promise<tEthereumAddress> => {
2020-11-06 11:19:08 +00:00
const currentNetwork = 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];
};
export const getEmergencyAdmin = async (
config: ICommonConfiguration
): Promise<tEthereumAddress> => {
2020-11-06 11:19:08 +00:00
const currentNetwork = 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];
};
export const getATokenDomainSeparatorPerNetwork = (
network: eEthereumNetwork,
config: ICommonConfiguration
): tEthereumAddress => getParamPerNetwork<tEthereumAddress>(config.ATokenDomainSeparator, network);
export const getWethAddress = async (config: ICommonConfiguration) => {
2020-11-06 11:19:08 +00:00
const currentNetwork = DRE.network.name;
const wethAddress = getParamPerNetwork(config.WETH, <eEthereumNetwork>currentNetwork);
if (wethAddress) {
return wethAddress;
}
if (currentNetwork.includes('main')) {
throw new Error('WETH not set at mainnet configuration.');
}
const weth = await deployWETHMocked();
return weth.address;
};
export const getLendingRateOracles = (poolConfig: ICommonConfiguration) => {
const {
ProtocolGlobalParams: {UsdAddress},
LendingRateOracleRatesCommon,
ReserveAssets,
} = poolConfig;
const MAINNET_FORK = process.env.MAINNET_FORK === 'true';
const network = MAINNET_FORK ? 'main' : DRE.network.name;
return filterMapBy(LendingRateOracleRatesCommon, (key) =>
Object.keys(ReserveAssets[network]).includes(key)
);
};