2020-08-25 12:15:35 +00:00
|
|
|
import {
|
|
|
|
AavePools,
|
|
|
|
iMultiPoolsAssets,
|
|
|
|
IReserveParams,
|
2020-08-25 15:15:27 +00:00
|
|
|
PoolConfiguration,
|
2020-08-25 12:15:35 +00:00
|
|
|
iBasicDistributionParams,
|
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 '../config/aave';
|
|
|
|
import {UniswapConfig} from '../config/uniswap';
|
2020-09-15 15:24:50 +00:00
|
|
|
import {CommonsConfig} from '../config/commons';
|
2020-08-25 12:15:35 +00:00
|
|
|
import {ZERO_ADDRESS} from './constants';
|
2020-09-15 15:24:50 +00:00
|
|
|
import {BRE} from './misc-utils';
|
|
|
|
import {tEthereumAddress} from './types';
|
|
|
|
import {getParamPerNetwork} from './contracts-helpers';
|
2020-11-02 16:51:54 +00:00
|
|
|
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',
|
|
|
|
Uniswap = 'Uniswap',
|
|
|
|
}
|
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;
|
|
|
|
case ConfigNames.Uniswap:
|
|
|
|
return UniswapConfig;
|
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,
|
|
|
|
},
|
|
|
|
[AavePools.secondary]: {
|
|
|
|
...UniswapConfig.ReservesConfig,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
pool
|
|
|
|
);
|
|
|
|
|
|
|
|
export const getFeeDistributionParamsCommon = (
|
|
|
|
receiver: tEthereumAddress
|
|
|
|
): iBasicDistributionParams => {
|
|
|
|
const receivers = [receiver, ZERO_ADDRESS];
|
|
|
|
const percentages = ['2000', '8000'];
|
|
|
|
return {
|
|
|
|
receivers,
|
|
|
|
percentages,
|
|
|
|
};
|
|
|
|
};
|
2020-09-15 15:24:50 +00:00
|
|
|
|
2020-11-05 11:35:50 +00:00
|
|
|
export const getGenesisPoolAdmin = async (config: ICommonConfiguration) => {
|
2020-09-15 15:24:50 +00:00
|
|
|
const currentNetwork = BRE.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(
|
|
|
|
(await BRE.ethers.getSigners()).map((signer) => signer.getAddress())
|
|
|
|
);
|
2020-11-05 11:35:50 +00:00
|
|
|
const addressIndex = config.PoolAdminIndex;
|
|
|
|
return addressList[addressIndex];
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getEmergencyAdmin = async (config: ICommonConfiguration) => {
|
|
|
|
const currentNetwork = BRE.network.name;
|
|
|
|
const targetAddress = getParamPerNetwork(config.EmergencyAdmin, <eEthereumNetwork>currentNetwork);
|
|
|
|
if (targetAddress) {
|
|
|
|
return targetAddress;
|
|
|
|
}
|
|
|
|
const addressList = await Promise.all(
|
|
|
|
(await BRE.ethers.getSigners()).map((signer) => signer.getAddress())
|
|
|
|
);
|
|
|
|
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);
|
2020-10-28 17:06:24 +00:00
|
|
|
|
|
|
|
export const getWethAddress = async (config: ICommonConfiguration) => {
|
|
|
|
const currentNetwork = BRE.network.name;
|
|
|
|
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;
|
|
|
|
};
|