aave-protocol-v2/helpers/oracles-helpers.ts

100 lines
3.5 KiB
TypeScript
Raw Normal View History

import {
tEthereumAddress,
iMultiPoolsAssets,
IMarketRates,
iAssetBase,
iAssetAggregatorBase,
2020-08-21 11:07:32 +00:00
eContractid,
2020-08-25 12:15:35 +00:00
SymbolMap,
} from './types';
import {LendingRateOracle} from '../types/LendingRateOracle';
import {PriceOracle} from '../types/PriceOracle';
import {MockAggregator} from '../types/MockAggregator';
2020-08-25 12:15:35 +00:00
import {deployMockAggregator, getContract, MockTokenMap} from './contracts-helpers';
import {waitForTx} from './misc-utils';
2020-08-21 11:07:32 +00:00
import {verifyContract} from './etherscan-verification';
export const setInitialMarketRatesInRatesOracle = async (
marketRates: iMultiPoolsAssets<IMarketRates>,
assetsAddresses: {[x: string]: tEthereumAddress},
lendingRateOracleInstance: LendingRateOracle
) => {
for (const [assetSymbol, {borrowRate}] of Object.entries(marketRates) as [
string,
IMarketRates
][]) {
const assetAddressIndex = Object.keys(assetsAddresses).findIndex(
(value) => value === assetSymbol
);
const [, assetAddress] = (Object.entries(assetsAddresses) as [string, string][])[
assetAddressIndex
];
2020-10-21 09:42:27 +00:00
await waitForTx(await lendingRateOracleInstance.setMarketBorrowRate(assetAddress, borrowRate));
2020-09-24 15:48:29 +00:00
console.log('added Market Borrow Rate for: ', assetSymbol);
}
};
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) => {
const aggregators: {[tokenSymbol: string]: MockAggregator} = {};
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
) => {
const aggregators: {[tokenSymbol: string]: MockAggregator} = {};
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);
}
}
return aggregators;
};