2020-08-20 15:35:05 +00:00
|
|
|
import {
|
|
|
|
tEthereumAddress,
|
|
|
|
iMultiPoolsAssets,
|
|
|
|
IMarketRates,
|
|
|
|
iAssetBase,
|
|
|
|
iAssetAggregatorBase,
|
2020-08-25 12:15:35 +00:00
|
|
|
SymbolMap,
|
2020-08-20 15:35:05 +00:00
|
|
|
} from './types';
|
|
|
|
|
2021-02-06 02:51:12 +00:00
|
|
|
import { LendingRateOracle } from '../types/LendingRateOracle';
|
|
|
|
import { PriceOracle } from '../types/PriceOracle';
|
|
|
|
import { MockAggregator } from '../types/MockAggregator';
|
|
|
|
import { deployMockAggregator } from './contracts-deployments';
|
|
|
|
import { chunk, waitForTx } from './misc-utils';
|
|
|
|
import { getStableAndVariableTokensHelper } from './contracts-getters';
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-10-27 09:58:51 +00:00
|
|
|
export const setInitialMarketRatesInRatesOracleByHelper = async (
|
2020-08-20 15:35:05 +00:00
|
|
|
marketRates: iMultiPoolsAssets<IMarketRates>,
|
2021-01-27 14:43:34 +00:00
|
|
|
assetsAddresses: { [x: string]: tEthereumAddress },
|
2020-10-27 09:58:51 +00:00
|
|
|
lendingRateOracleInstance: LendingRateOracle,
|
|
|
|
admin: tEthereumAddress
|
2020-08-20 15:35:05 +00:00
|
|
|
) => {
|
2020-10-27 09:58:51 +00:00
|
|
|
const stableAndVariableTokenHelper = await getStableAndVariableTokensHelper();
|
|
|
|
const assetAddresses: string[] = [];
|
|
|
|
const borrowRates: string[] = [];
|
|
|
|
const symbols: string[] = [];
|
2021-01-27 14:43:34 +00:00
|
|
|
for (const [assetSymbol, { borrowRate }] of Object.entries(marketRates) as [
|
2020-08-20 15:35:05 +00:00
|
|
|
string,
|
|
|
|
IMarketRates
|
|
|
|
][]) {
|
|
|
|
const assetAddressIndex = Object.keys(assetsAddresses).findIndex(
|
|
|
|
(value) => value === assetSymbol
|
|
|
|
);
|
|
|
|
const [, assetAddress] = (Object.entries(assetsAddresses) as [string, string][])[
|
|
|
|
assetAddressIndex
|
|
|
|
];
|
2020-10-27 09:58:51 +00:00
|
|
|
assetAddresses.push(assetAddress);
|
|
|
|
borrowRates.push(borrowRate);
|
|
|
|
symbols.push(assetSymbol);
|
2020-08-20 15:35:05 +00:00
|
|
|
}
|
2020-10-27 09:58:51 +00:00
|
|
|
// Set borrow rates per chunks
|
|
|
|
const ratesChunks = 20;
|
|
|
|
const chunkedTokens = chunk(assetAddresses, ratesChunks);
|
|
|
|
const chunkedRates = chunk(borrowRates, ratesChunks);
|
|
|
|
const chunkedSymbols = chunk(symbols, ratesChunks);
|
|
|
|
|
|
|
|
// Set helper as owner
|
|
|
|
await waitForTx(
|
|
|
|
await lendingRateOracleInstance.transferOwnership(stableAndVariableTokenHelper.address)
|
|
|
|
);
|
|
|
|
|
|
|
|
console.log(`- Oracle borrow initalization in ${chunkedTokens.length} txs`);
|
|
|
|
for (let chunkIndex = 0; chunkIndex < chunkedTokens.length; chunkIndex++) {
|
|
|
|
const tx3 = await waitForTx(
|
|
|
|
await stableAndVariableTokenHelper.setOracleBorrowRates(
|
|
|
|
chunkedTokens[chunkIndex],
|
|
|
|
chunkedRates[chunkIndex],
|
|
|
|
lendingRateOracleInstance.address
|
|
|
|
)
|
|
|
|
);
|
|
|
|
console.log(` - Setted Oracle Borrow Rates for: ${chunkedSymbols[chunkIndex].join(', ')}`);
|
|
|
|
}
|
|
|
|
// Set back ownership
|
|
|
|
await waitForTx(
|
|
|
|
await stableAndVariableTokenHelper.setOracleOwnership(lendingRateOracleInstance.address, admin)
|
|
|
|
);
|
2020-08-20 15:35:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const setInitialAssetPricesInOracle = async (
|
|
|
|
prices: iAssetBase<tEthereumAddress>,
|
|
|
|
assetsAddresses: iAssetBase<tEthereumAddress>,
|
|
|
|
priceOracleInstance: PriceOracle
|
|
|
|
) => {
|
|
|
|
for (const [assetSymbol, price] of Object.entries(prices) as [string, string][]) {
|
|
|
|
const assetAddressIndex = Object.keys(assetsAddresses).findIndex(
|
|
|
|
(value) => value === assetSymbol
|
|
|
|
);
|
|
|
|
const [, assetAddress] = (Object.entries(assetsAddresses) as [string, string][])[
|
|
|
|
assetAddressIndex
|
|
|
|
];
|
|
|
|
await waitForTx(await priceOracleInstance.setAssetPrice(assetAddress, price));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-08-25 12:15:35 +00:00
|
|
|
export const setAssetPricesInOracle = async (
|
|
|
|
prices: SymbolMap<string>,
|
|
|
|
assetsAddresses: SymbolMap<tEthereumAddress>,
|
|
|
|
priceOracleInstance: PriceOracle
|
|
|
|
) => {
|
|
|
|
for (const [assetSymbol, price] of Object.entries(prices) as [string, string][]) {
|
|
|
|
const assetAddressIndex = Object.keys(assetsAddresses).findIndex(
|
|
|
|
(value) => value === assetSymbol
|
|
|
|
);
|
|
|
|
const [, assetAddress] = (Object.entries(assetsAddresses) as [string, string][])[
|
|
|
|
assetAddressIndex
|
|
|
|
];
|
|
|
|
await waitForTx(await priceOracleInstance.setAssetPrice(assetAddress, price));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const deployMockAggregators = async (initialPrices: SymbolMap<string>, verify?: boolean) => {
|
2021-01-27 14:43:34 +00:00
|
|
|
const aggregators: { [tokenSymbol: string]: MockAggregator } = {};
|
2020-08-25 12:15:35 +00:00
|
|
|
for (const tokenContractName of Object.keys(initialPrices)) {
|
|
|
|
if (tokenContractName !== 'ETH') {
|
|
|
|
const priceIndex = Object.keys(initialPrices).findIndex(
|
|
|
|
(value) => value === tokenContractName
|
|
|
|
);
|
|
|
|
const [, price] = (Object.entries(initialPrices) as [string, string][])[priceIndex];
|
|
|
|
aggregators[tokenContractName] = await deployMockAggregator(price, verify);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aggregators;
|
|
|
|
};
|
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
export const deployAllMockAggregators = async (
|
|
|
|
initialPrices: iAssetAggregatorBase<string>,
|
|
|
|
verify?: boolean
|
|
|
|
) => {
|
2021-01-27 14:43:34 +00:00
|
|
|
const aggregators: { [tokenSymbol: string]: MockAggregator } = {};
|
2020-08-20 15:35:05 +00:00
|
|
|
for (const tokenContractName of Object.keys(initialPrices)) {
|
|
|
|
if (tokenContractName !== 'ETH') {
|
|
|
|
const priceIndex = Object.keys(initialPrices).findIndex(
|
|
|
|
(value) => value === tokenContractName
|
|
|
|
);
|
|
|
|
const [, price] = (Object.entries(initialPrices) as [string, string][])[priceIndex];
|
2020-08-21 11:07:32 +00:00
|
|
|
aggregators[tokenContractName] = await deployMockAggregator(price, verify);
|
2020-08-20 15:35:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return aggregators;
|
|
|
|
};
|