2020-10-15 11:57:03 +00:00
|
|
|
import {
|
|
|
|
AaveProtocolTestHelpersFactory,
|
|
|
|
ATokenFactory,
|
2020-10-27 09:58:51 +00:00
|
|
|
ATokensAndRatesHelperFactory,
|
2020-10-15 11:57:03 +00:00
|
|
|
DefaultReserveInterestRateStrategyFactory,
|
2020-10-15 17:19:02 +00:00
|
|
|
GenericLogicFactory,
|
2020-10-15 11:57:03 +00:00
|
|
|
LendingPoolAddressesProviderFactory,
|
|
|
|
LendingPoolAddressesProviderRegistryFactory,
|
|
|
|
LendingPoolConfiguratorFactory,
|
|
|
|
LendingPoolFactory,
|
|
|
|
LendingRateOracleFactory,
|
|
|
|
MintableErc20Factory,
|
2020-10-30 12:40:06 +00:00
|
|
|
MockATokenFactory,
|
2020-10-15 11:57:03 +00:00
|
|
|
MockFlashLoanReceiverFactory,
|
2020-10-30 12:40:06 +00:00
|
|
|
MockStableDebtTokenFactory,
|
|
|
|
MockVariableDebtTokenFactory,
|
2020-10-15 11:57:03 +00:00
|
|
|
PriceOracleFactory,
|
2020-10-15 17:19:02 +00:00
|
|
|
ReserveLogicFactory,
|
2020-10-27 09:58:51 +00:00
|
|
|
StableAndVariableTokensHelperFactory,
|
2020-10-15 11:57:03 +00:00
|
|
|
StableDebtTokenFactory,
|
|
|
|
VariableDebtTokenFactory,
|
|
|
|
} from '../types';
|
|
|
|
import {Ierc20DetailedFactory} from '../types/Ierc20DetailedFactory';
|
2020-10-26 16:43:10 +00:00
|
|
|
import {MockTokenMap} from './contracts-helpers';
|
2020-10-15 11:57:03 +00:00
|
|
|
import {BRE, getDb} from './misc-utils';
|
|
|
|
import {eContractid, PoolConfiguration, tEthereumAddress, TokenContractId} from './types';
|
|
|
|
|
2020-10-15 17:19:02 +00:00
|
|
|
export const getFirstSigner = async () => (await BRE.ethers.getSigners())[0];
|
|
|
|
|
2020-10-15 11:57:03 +00:00
|
|
|
export const getLendingPoolAddressesProvider = async (address?: tEthereumAddress) =>
|
|
|
|
await LendingPoolAddressesProviderFactory.connect(
|
|
|
|
address ||
|
|
|
|
(await getDb().get(`${eContractid.LendingPoolAddressesProvider}.${BRE.network.name}`).value())
|
|
|
|
.address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
2020-10-15 11:57:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getLendingPoolConfiguratorProxy = async (address?: tEthereumAddress) => {
|
|
|
|
return await LendingPoolConfiguratorFactory.connect(
|
|
|
|
address ||
|
|
|
|
(await getDb().get(`${eContractid.LendingPoolConfigurator}.${BRE.network.name}`).value())
|
|
|
|
.address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
2020-10-15 11:57:03 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getLendingPool = async (address?: tEthereumAddress) =>
|
|
|
|
await LendingPoolFactory.connect(
|
|
|
|
address ||
|
|
|
|
(await getDb().get(`${eContractid.LendingPool}.${BRE.network.name}`).value()).address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
2020-10-15 11:57:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getPriceOracle = async (address?: tEthereumAddress) =>
|
|
|
|
await PriceOracleFactory.connect(
|
|
|
|
address ||
|
|
|
|
(await getDb().get(`${eContractid.PriceOracle}.${BRE.network.name}`).value()).address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
2020-10-15 11:57:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getAToken = async (address?: tEthereumAddress) =>
|
|
|
|
await ATokenFactory.connect(
|
|
|
|
address || (await getDb().get(`${eContractid.AToken}.${BRE.network.name}`).value()).address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
2020-10-15 11:57:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getStableDebtToken = async (address?: tEthereumAddress) =>
|
|
|
|
await StableDebtTokenFactory.connect(
|
|
|
|
address ||
|
|
|
|
(await getDb().get(`${eContractid.StableDebtToken}.${BRE.network.name}`).value()).address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
2020-10-15 11:57:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getVariableDebtToken = async (address?: tEthereumAddress) =>
|
|
|
|
await VariableDebtTokenFactory.connect(
|
|
|
|
address ||
|
|
|
|
(await getDb().get(`${eContractid.VariableDebtToken}.${BRE.network.name}`).value()).address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
2020-10-15 11:57:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getMintableErc20 = async (address: tEthereumAddress) =>
|
|
|
|
await MintableErc20Factory.connect(
|
|
|
|
address ||
|
|
|
|
(await getDb().get(`${eContractid.MintableERC20}.${BRE.network.name}`).value()).address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
2020-10-15 11:57:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getIErc20Detailed = async (address: tEthereumAddress) =>
|
|
|
|
await Ierc20DetailedFactory.connect(
|
|
|
|
address ||
|
|
|
|
(await getDb().get(`${eContractid.IERC20Detailed}.${BRE.network.name}`).value()).address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
2020-10-15 11:57:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getAaveProtocolTestHelpers = async (address?: tEthereumAddress) =>
|
|
|
|
await AaveProtocolTestHelpersFactory.connect(
|
|
|
|
address ||
|
|
|
|
(await getDb().get(`${eContractid.AaveProtocolTestHelpers}.${BRE.network.name}`).value())
|
|
|
|
.address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
2020-10-15 11:57:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getInterestRateStrategy = async (address?: tEthereumAddress) =>
|
|
|
|
await DefaultReserveInterestRateStrategyFactory.connect(
|
|
|
|
address ||
|
|
|
|
(
|
|
|
|
await getDb()
|
|
|
|
.get(`${eContractid.DefaultReserveInterestRateStrategy}.${BRE.network.name}`)
|
|
|
|
.value()
|
|
|
|
).address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
2020-10-15 11:57:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getMockFlashLoanReceiver = async (address?: tEthereumAddress) =>
|
|
|
|
await MockFlashLoanReceiverFactory.connect(
|
|
|
|
address ||
|
|
|
|
(await getDb().get(`${eContractid.MockFlashLoanReceiver}.${BRE.network.name}`).value())
|
|
|
|
.address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
2020-10-15 11:57:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getLendingRateOracle = async (address?: tEthereumAddress) =>
|
|
|
|
await LendingRateOracleFactory.connect(
|
|
|
|
address ||
|
|
|
|
(await getDb().get(`${eContractid.LendingRateOracle}.${BRE.network.name}`).value()).address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
2020-10-15 11:57:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getMockedTokens = async (config: PoolConfiguration) => {
|
|
|
|
const tokenSymbols = config.ReserveSymbols;
|
|
|
|
const db = getDb();
|
|
|
|
const tokens: MockTokenMap = await tokenSymbols.reduce<Promise<MockTokenMap>>(
|
|
|
|
async (acc, tokenSymbol) => {
|
|
|
|
const accumulator = await acc;
|
|
|
|
const address = db.get(`${tokenSymbol.toUpperCase()}.${BRE.network.name}`).value().address;
|
|
|
|
accumulator[tokenSymbol] = await getMintableErc20(address);
|
|
|
|
return Promise.resolve(acc);
|
|
|
|
},
|
|
|
|
Promise.resolve({})
|
|
|
|
);
|
|
|
|
return tokens;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getAllMockedTokens = async () => {
|
|
|
|
const db = getDb();
|
|
|
|
const tokens: MockTokenMap = await Object.keys(TokenContractId).reduce<Promise<MockTokenMap>>(
|
|
|
|
async (acc, tokenSymbol) => {
|
|
|
|
const accumulator = await acc;
|
|
|
|
const address = db.get(`${tokenSymbol.toUpperCase()}.${BRE.network.name}`).value().address;
|
|
|
|
accumulator[tokenSymbol] = await getMintableErc20(address);
|
|
|
|
return Promise.resolve(acc);
|
|
|
|
},
|
|
|
|
Promise.resolve({})
|
|
|
|
);
|
|
|
|
return tokens;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getPairsTokenAggregator = (
|
|
|
|
allAssetsAddresses: {
|
|
|
|
[tokenSymbol: string]: tEthereumAddress;
|
|
|
|
},
|
|
|
|
aggregatorsAddresses: {[tokenSymbol: string]: tEthereumAddress}
|
|
|
|
): [string[], string[]] => {
|
|
|
|
const {ETH, USD, WETH, ...assetsAddressesWithoutEth} = allAssetsAddresses;
|
|
|
|
|
|
|
|
const pairs = Object.entries(assetsAddressesWithoutEth).map(([tokenSymbol, tokenAddress]) => {
|
|
|
|
if (tokenSymbol !== 'WETH' && tokenSymbol !== 'ETH') {
|
|
|
|
const aggregatorAddressIndex = Object.keys(aggregatorsAddresses).findIndex(
|
|
|
|
(value) => value === tokenSymbol
|
|
|
|
);
|
|
|
|
const [, aggregatorAddress] = (Object.entries(aggregatorsAddresses) as [
|
|
|
|
string,
|
|
|
|
tEthereumAddress
|
|
|
|
][])[aggregatorAddressIndex];
|
|
|
|
return [tokenAddress, aggregatorAddress];
|
|
|
|
}
|
|
|
|
}) as [string, string][];
|
|
|
|
|
|
|
|
const mappedPairs = pairs.map(([asset]) => asset);
|
|
|
|
const mappedAggregators = pairs.map(([, source]) => source);
|
|
|
|
|
|
|
|
return [mappedPairs, mappedAggregators];
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getLendingPoolAddressesProviderRegistry = async (address?: tEthereumAddress) =>
|
|
|
|
await LendingPoolAddressesProviderRegistryFactory.connect(
|
|
|
|
address ||
|
|
|
|
(
|
|
|
|
await getDb()
|
|
|
|
.get(`${eContractid.LendingPoolAddressesProviderRegistry}.${BRE.network.name}`)
|
|
|
|
.value()
|
|
|
|
).address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
|
|
|
);
|
|
|
|
|
2020-10-16 09:27:09 +00:00
|
|
|
export const getReserveLogic = async (address?: tEthereumAddress) =>
|
2020-10-15 17:19:02 +00:00
|
|
|
await ReserveLogicFactory.connect(
|
|
|
|
address ||
|
2020-10-16 09:27:09 +00:00
|
|
|
(await getDb().get(`${eContractid.ReserveLogic}.${BRE.network.name}`).value()).address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
|
|
|
);
|
|
|
|
|
|
|
|
export const getGenericLogic = async (address?: tEthereumAddress) =>
|
|
|
|
await GenericLogicFactory.connect(
|
|
|
|
address ||
|
2020-10-16 09:27:09 +00:00
|
|
|
(await getDb().get(`${eContractid.GenericLogic}.${BRE.network.name}`).value()).address,
|
2020-10-15 17:19:02 +00:00
|
|
|
await getFirstSigner()
|
2020-10-15 11:57:03 +00:00
|
|
|
);
|
2020-10-26 16:43:10 +00:00
|
|
|
|
|
|
|
export const getStableAndVariableTokensHelper = async (address?: tEthereumAddress) =>
|
2020-10-27 09:58:51 +00:00
|
|
|
await StableAndVariableTokensHelperFactory.connect(
|
2020-10-26 16:43:10 +00:00
|
|
|
address ||
|
|
|
|
(
|
|
|
|
await getDb()
|
|
|
|
.get(`${eContractid.StableAndVariableTokensHelper}.${BRE.network.name}`)
|
|
|
|
.value()
|
|
|
|
).address,
|
|
|
|
await getFirstSigner()
|
|
|
|
);
|
|
|
|
|
|
|
|
export const getATokensAndRatesHelper = async (address?: tEthereumAddress) =>
|
2020-10-27 09:58:51 +00:00
|
|
|
await ATokensAndRatesHelperFactory.connect(
|
2020-10-26 16:43:10 +00:00
|
|
|
address ||
|
|
|
|
(await getDb().get(`${eContractid.ATokensAndRatesHelper}.${BRE.network.name}`).value())
|
|
|
|
.address,
|
|
|
|
await getFirstSigner()
|
|
|
|
);
|
2020-10-30 12:40:06 +00:00
|
|
|
|
|
|
|
export const getMockAToken = async (address?: tEthereumAddress) =>
|
|
|
|
await MockATokenFactory.connect(
|
|
|
|
address || (await getDb().get(`${eContractid.MockAToken}.${BRE.network.name}`).value()).address,
|
|
|
|
await getFirstSigner()
|
|
|
|
);
|
|
|
|
|
|
|
|
export const getMockVariableDebtToken = async (address?: tEthereumAddress) =>
|
|
|
|
await MockVariableDebtTokenFactory.connect(
|
|
|
|
address ||
|
|
|
|
(await getDb().get(`${eContractid.MockVariableDebtToken}.${BRE.network.name}`).value())
|
|
|
|
.address,
|
|
|
|
await getFirstSigner()
|
|
|
|
);
|
|
|
|
export const getMockStableDebtToken = async (address?: tEthereumAddress) =>
|
|
|
|
await MockStableDebtTokenFactory.connect(
|
|
|
|
address ||
|
|
|
|
(await getDb().get(`${eContractid.MockStableDebtToken}.${BRE.network.name}`).value()).address,
|
|
|
|
await getFirstSigner()
|
|
|
|
);
|