diff --git a/core/simulations/configs/onboardNewCollateral.ts b/core/simulations/configs/onboardNewCollateral.ts index 0764b68f4..f974c5607 100644 --- a/core/simulations/configs/onboardNewCollateral.ts +++ b/core/simulations/configs/onboardNewCollateral.ts @@ -10,7 +10,7 @@ import createVaultWithCollateral, { } from '../helpers/createVaultWithCollateral'; import deploySpell, { getAllSpellNames } from '../helpers/deploySpell'; import executeSpell from '../helpers/executeSpell'; -import { getCurrentOraclePriceByCollateralType } from '../../src/oracles'; +import { getOsmPrices } from '../../src/oracles'; import { overwriteCurrentOraclePrice } from '../../helpers/hardhat/overwrites'; import promptToSelectOneOption from '../helpers/promptToSelectOneOption'; @@ -52,8 +52,8 @@ const simulation: Simulation = { ); // overwrite oracle price await overwriteCurrentOraclePrice(TEST_NETWORK, collateralType, new BigNumber(1000)); - const oraclePrice = await getCurrentOraclePriceByCollateralType(TEST_NETWORK, collateralType); - console.info(`New ${collateralType} oracle price is ${oraclePrice.toFixed()} DAI`); + const oraclePrices = await getOsmPrices(TEST_NETWORK, collateralType); + console.info(`New ${collateralType} oracle price is ${oraclePrices.currentUnitPrice.toFixed()} DAI`); // create and liquidate vault const collateralOwned = await calculateMinCollateralAmountToOpenVault(collateralType); const vaultId = await createVaultWithCollateral(collateralType, collateralOwned); diff --git a/core/src/constants/COLLATERALS.ts b/core/src/constants/COLLATERALS.ts index db9f29795..bfc87412a 100644 --- a/core/src/constants/COLLATERALS.ts +++ b/core/src/constants/COLLATERALS.ts @@ -1,19 +1,29 @@ -import type { CollateralConfig, OracleCurrentAndNextPrices, OracleCurrentPriceOnly } from '../types'; +import type { CollateralConfig, ValueExtractionConfig } from '../types'; -export const CONFIG_WITH_NEXT_PRICE: OracleCurrentAndNextPrices = { - type: 'CurrentAndNextPrice', - currentPriceSlotAddress: '0x3', - nextPriceSlotAddress: '0x4', - hasDelay: true, - slotPriceValueBeginsAtPosition: 34, -}; -export const CONFIG_WITHOUT_NEXT_PRICE: OracleCurrentPriceOnly = { - type: 'CurrentPriceOnly', - currentPriceSlotAddress: '0x2', - hasDelay: false, - currentPriceValiditySlotAndOffset: { slot: '0x1', offset: 25 }, - slotPriceValueBeginsAtPosition: 0, -}; +const DEFAULT_ORACLE_CONFIG: ValueExtractionConfig[] = [ + { + slotAddress: '0x3', + abiCoderFormat: ['bool isCurrentUnitPriceValid', 'uint128 currentUnitPrice'], + wordSize: 16, + }, + { + slotAddress: '0x4', + abiCoderFormat: ['bool isNextUnitPriceValid', 'uint128 nextUnitPrice'], + wordSize: 16, + }, +]; +const STABLECOIN_ORACLE_CONFIG: ValueExtractionConfig[] = [ + { + slotAddress: '0x1', + abiCoderFormat: ['bool isCurrentUnitPriceValid'], + wordSize: 32, + }, + { + slotAddress: '0x2', + abiCoderFormat: ['uint128 currentUnitPrice'], + wordSize: 32, + }, +]; const COLLATERALS: Record = { 'AAVE-A': { @@ -31,7 +41,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'BAL-A': { title: 'Balancer', @@ -48,7 +58,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'BAT-A': { title: 'Basic Attention Token', @@ -65,7 +75,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'COMP-A': { title: 'Compound', @@ -82,7 +92,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'ETH-A': { title: 'Ether', @@ -99,7 +109,7 @@ const COLLATERALS: Record = { route: [], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'ETH-B': { title: 'Ether', @@ -116,7 +126,7 @@ const COLLATERALS: Record = { route: [], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'ETH-C': { title: 'Ether', @@ -133,7 +143,7 @@ const COLLATERALS: Record = { route: [], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'GUSD-A': { title: 'Gemini Dollar', @@ -150,7 +160,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITHOUT_NEXT_PRICE, + oracle: STABLECOIN_ORACLE_CONFIG, }, 'KNC-A': { title: 'Kyber Network Crystal', @@ -167,7 +177,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'LINK-A': { title: 'Chainlink', @@ -184,7 +194,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'LRC-A': { title: 'Loopring', @@ -201,7 +211,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'MANA-A': { title: 'Decentraland', @@ -218,7 +228,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'PAXUSD-A': { title: 'Paxos Standard', @@ -236,7 +246,7 @@ const COLLATERALS: Record = { }, }, - oracle: CONFIG_WITHOUT_NEXT_PRICE, + oracle: STABLECOIN_ORACLE_CONFIG, }, 'RENBTC-A': { title: 'renBTC', @@ -253,7 +263,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'TUSD-A': { title: 'True USD', @@ -270,7 +280,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITHOUT_NEXT_PRICE, + oracle: STABLECOIN_ORACLE_CONFIG, }, 'UNI-A': { title: 'Uniswap', @@ -287,7 +297,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'USDC-A': { title: 'USD Coin', @@ -304,7 +314,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITHOUT_NEXT_PRICE, + oracle: STABLECOIN_ORACLE_CONFIG, }, 'USDC-B': { title: 'USD Coin', @@ -321,7 +331,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITHOUT_NEXT_PRICE, + oracle: STABLECOIN_ORACLE_CONFIG, }, 'USDT-A': { title: 'Tether USD', @@ -338,7 +348,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'WBTC-A': { title: 'Wrapped Bitcoin', @@ -355,7 +365,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'WBTC-B': { title: 'Wrapped BTC', @@ -372,7 +382,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'WBTC-C': { title: 'Wrapped BTC', @@ -389,7 +399,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'YFI-A': { title: 'yearn.finance', @@ -406,7 +416,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'ZRX-A': { title: '0x', @@ -423,7 +433,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'MATIC-A': { title: 'Matic', @@ -440,7 +450,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'WSTETH-A': { title: 'Lido wstETH', @@ -453,7 +463,7 @@ const COLLATERALS: Record = { route: [], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'WSTETH-B': { title: 'Lido wstETH', @@ -466,7 +476,7 @@ const COLLATERALS: Record = { route: [], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'CRVV1ETHSTETH-A': { title: 'Curve stETH', @@ -479,7 +489,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'UNIV2DAIETH-A': { title: 'UNIV2DAIETH LP', @@ -493,7 +503,7 @@ const COLLATERALS: Record = { token1: 'ETH', }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'UNIV2USDCETH-A': { title: 'UNIV2USDCETH LP', @@ -507,7 +517,7 @@ const COLLATERALS: Record = { token1: 'ETH', }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'UNIV2ETHUSDT-A': { title: 'UNIV2ETHUSDT LP', @@ -521,7 +531,7 @@ const COLLATERALS: Record = { token1: 'USDT', }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'UNIV2WBTCDAI-A': { title: 'UNIV2WBTCDAI LP', @@ -535,7 +545,7 @@ const COLLATERALS: Record = { token1: 'DAI', }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'UNIV2WBTCETH-A': { title: 'UNIV2WBTCETH LP', @@ -549,7 +559,7 @@ const COLLATERALS: Record = { token1: 'ETH', }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'UNIV2LINKETH-A': { title: 'UNIV2LINKETH LP', @@ -563,7 +573,7 @@ const COLLATERALS: Record = { token1: 'ETH', }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'UNIV2UNIETH-A': { title: 'UNIV2UNIETH LP', @@ -577,7 +587,7 @@ const COLLATERALS: Record = { token1: 'ETH', }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'UNIV2AAVEETH-A': { title: 'UNIV2AAVEETH LP', @@ -591,7 +601,7 @@ const COLLATERALS: Record = { token1: 'ETH', }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'UNIV2DAIUSDT-A': { title: 'UNIV2DAIUSDT LP', @@ -605,7 +615,7 @@ const COLLATERALS: Record = { token1: 'USDT', }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'UNIV2DAIUSDC-A': { title: 'UNIV2DAIUSDC LP', @@ -619,7 +629,7 @@ const COLLATERALS: Record = { token1: 'USDC', }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, 'RETH-A': { title: 'Rocket Pool ETH', @@ -632,7 +642,7 @@ const COLLATERALS: Record = { route: ['ETH'], }, }, - oracle: CONFIG_WITH_NEXT_PRICE, + oracle: DEFAULT_ORACLE_CONFIG, }, }; diff --git a/core/src/helpers/createStructCoder.ts b/core/src/helpers/createStructCoder.ts index a660e041b..8a267a403 100644 --- a/core/src/helpers/createStructCoder.ts +++ b/core/src/helpers/createStructCoder.ts @@ -1,8 +1,8 @@ import { ethers } from 'ethers'; -const createStructCoder = function (length = 16) { +const createStructCoder = function (wordSize = 16) { const coder = new ethers.utils.AbiCoder(); - coder._getWordSize = () => length; + coder._getWordSize = () => wordSize; return coder; }; diff --git a/core/src/oracles.ts b/core/src/oracles.ts index 47cc79941..52bdf75eb 100644 --- a/core/src/oracles.ts +++ b/core/src/oracles.ts @@ -1,153 +1,71 @@ +import { ethers } from 'ethers'; +import memoizee from 'memoizee'; import { getContractAddressByName, getContractInterfaceByName } from './contracts'; import getProvider from './provider'; -import { - CollateralConfig, - CollateralPriceSourceConfig, - OraclePrices, - OracleCurrentPriceOnly, - OracleCurrentAndNextPrices, - CollateralType, -} from './types'; +import { OraclePrices, ValueExtractionConfig } from './types'; import BigNumber from './bignumber'; -import { ethers } from 'ethers'; import { DAI_NUMBER_OF_DIGITS } from './constants/UNITS'; -import memoizee from 'memoizee'; import { getCollateralConfigByType } from './constants/COLLATERALS'; +import createStructCoder from './helpers/createStructCoder'; -const CACHE_EXPIRY_MS = 60 * 1000; +const CACHE_EXPIRY_MS = 30 * 1000; export const getOracleAddressByCollateralType = async function (network: string, collateralType: string) { const collateralConfig = getCollateralConfigByType(collateralType); return await getContractAddressByName(network, `PIP_${collateralConfig.symbol}`); }; -const getOraclePriceSameSlotValidity = async ( - slot: string, - slotPriceValueBeginsAtPosition: number, - provider: ethers.providers.JsonRpcProvider, - oracleAddress: string -) => { - /** - * Fetch the price by direct memory access (via slot address) - * The price is stored in the same slot as a validity marker: - * - split the received value into validity marker part and price part - * If the price is valid - return it, otherwise provide a NaN - **/ - const priceAndValidityHex = await provider.getStorageAt(oracleAddress, slot); - const isPriceValid = priceAndValidityHex.substring(0, slotPriceValueBeginsAtPosition); - if (parseInt(isPriceValid, 16) === 1) { - return new BigNumber(`0x${priceAndValidityHex.substring(slotPriceValueBeginsAtPosition)}`).shiftedBy( - -DAI_NUMBER_OF_DIGITS - ); +const getNextOraclePriceChange = async (network: string, collateralType: string) => { + const provider = await getProvider(network); + const oracleAddress = await getOracleAddressByCollateralType(network, collateralType); + const osmContractInterface = await getContractInterfaceByName('OSM'); + const osmContract = new ethers.Contract(oracleAddress, osmContractInterface, provider); + const lastPriceUpdateTimestampInSeconds = parseInt((await osmContract.zzz())._hex, 16); + if (!lastPriceUpdateTimestampInSeconds) { + new Date(NaN); } - return new BigNumber(NaN); -}; - -const getNextOraclePrice = async ( - oracle: CollateralPriceSourceConfig, - provider: ethers.providers.JsonRpcProvider, - oracleAddress: string -): Promise => { - // Determine if the next price can be fetched from the contract. - if (oracle.type !== 'CurrentAndNextPrice') { - return new BigNumber(NaN); + const priceUpdateFrequencyInSeconds = await osmContract.hop(); + if (!priceUpdateFrequencyInSeconds) { + new Date(NaN); } - return await getOraclePriceSameSlotValidity( - oracle.nextPriceSlotAddress, - oracle.slotPriceValueBeginsAtPosition, - provider, - oracleAddress - ); + return new Date((lastPriceUpdateTimestampInSeconds + priceUpdateFrequencyInSeconds) * 1000); }; -const currentPriceExtractors: Record = { - CurrentPriceOnly: async ( - oracle: OracleCurrentPriceOnly, - provider: ethers.providers.JsonRpcProvider, - oracleAddress: string - ) => { - /** - * Get current price from the contract via direct memory access (slot address) - * The price is stored in separate slot as a validity marker: - * - the marker might be stored in the same slot as some other irrelevent value - * - extract the byte that contains validity marker only - * If the price is valid - return it, otherwise provide a NaN - **/ - const currentPriceFeed = await provider.getStorageAt(oracleAddress, oracle.currentPriceSlotAddress); - const slotPriceValueBeginsAtPosition = oracle.slotPriceValueBeginsAtPosition; - const priceValiditySlotValue = await provider.getStorageAt( - oracleAddress, - oracle.currentPriceValiditySlotAndOffset.slot - ); - const isPriceValid = - parseInt(priceValiditySlotValue[oracle.currentPriceValiditySlotAndOffset.offset], 16) === 1; - return isPriceValid - ? new BigNumber(`0x${currentPriceFeed.substring(slotPriceValueBeginsAtPosition)}`).shiftedBy( - -DAI_NUMBER_OF_DIGITS - ) - : new BigNumber(NaN); - }, - CurrentAndNextPrice: async ( - oracle: OracleCurrentAndNextPrices, - provider: ethers.providers.JsonRpcProvider, - oracleAddress: string - ) => { - return await getOraclePriceSameSlotValidity( - oracle.currentPriceSlotAddress, - oracle.slotPriceValueBeginsAtPosition, - provider, - oracleAddress - ); - }, -}; -export const getCurrentOraclePrice = async ( - oracle: CollateralPriceSourceConfig, - provider: ethers.providers.JsonRpcProvider, - oracleAddress: string -) => { - return currentPriceExtractors[oracle.type](oracle, provider, oracleAddress); -}; - -const getNextOraclePriceChange = async ( - collateralConfig: CollateralConfig, - provider: ethers.providers.JsonRpcProvider, - oracleAddress: string -) => { - let nextPriceChange: Date = new Date(NaN); - if (collateralConfig.oracle.hasDelay) { - const osmContractInterface = await getContractInterfaceByName('OSM'); - const osmContract = new ethers.Contract(oracleAddress, osmContractInterface, provider); - const lastPriceUpdateAsHex = (await osmContract.zzz())._hex; - const priceUpdateFrequencyInSeconds = await osmContract.hop(); - const lastPriceUpdateTimestampInSeconds = new BigNumber(lastPriceUpdateAsHex).toNumber(); - nextPriceChange = new Date((lastPriceUpdateTimestampInSeconds + priceUpdateFrequencyInSeconds) * 1000); +const extractValuesFromAddress = async function ( + network: string, + contractAddress: string, + extractionConfigs: ValueExtractionConfig[] +) { + const provider = await getProvider(network); + let values = {} as any; + for (const extractionConfig of extractionConfigs) { + const hexValues = await provider.getStorageAt(contractAddress, extractionConfig.slotAddress); + values = { + ...values, + ...createStructCoder(extractionConfig.wordSize).decode(extractionConfig.abiCoderFormat, hexValues), + }; } - return nextPriceChange; + return values; }; -export const getCurrentOraclePriceByCollateralType = async function (network: string, collateralType: string) { +const _getOsmPrices = async (network: string, collateralType: string): Promise => { const collateralConfig = getCollateralConfigByType(collateralType); - const provider = await getProvider(network); const oracleAddress = await getOracleAddressByCollateralType(network, collateralType); - const oraclePrice = await getCurrentOraclePrice(collateralConfig.oracle, provider, oracleAddress); - return oraclePrice; -}; - -const _getOsmPrices = async ( - network: string, - oracleAddress: string, - collateralType: CollateralType -): Promise => { - const provider = await getProvider(network); - const collateralConfig = getCollateralConfigByType(collateralType); + const prices = await extractValuesFromAddress(network, oracleAddress, collateralConfig.oracle); - const nextUnitCollateralPrice = await getNextOraclePrice(collateralConfig.oracle, provider, oracleAddress); - const currentUnitCollateralPrice = await getCurrentOraclePrice(collateralConfig.oracle, provider, oracleAddress); - const nextPriceChange = await getNextOraclePriceChange(collateralConfig, provider, oracleAddress); + const currentUnitPrice = prices.isCurrentUnitPriceValid + ? new BigNumber(prices.currentUnitPrice?._hex).shiftedBy(-DAI_NUMBER_OF_DIGITS) + : new BigNumber(NaN); + const nextUnitPrice = prices.isNextUnitPriceValid + ? new BigNumber(prices.nextUnitPrice?._hex).shiftedBy(-DAI_NUMBER_OF_DIGITS) + : new BigNumber(NaN); + const nextPriceChange = !nextUnitPrice.isNaN() + ? await getNextOraclePriceChange(network, collateralType) + : new Date(NaN); return { - currentUnitPrice: currentUnitCollateralPrice, - nextUnitPrice: nextUnitCollateralPrice, + currentUnitPrice, + nextUnitPrice, nextPriceChange, }; }; @@ -155,5 +73,5 @@ const _getOsmPrices = async ( export const getOsmPrices = memoizee(_getOsmPrices, { maxAge: CACHE_EXPIRY_MS, promise: true, - length: 3, + length: 2, }); diff --git a/core/src/types.ts b/core/src/types.ts index 160d10df8..5070619f4 100644 --- a/core/src/types.ts +++ b/core/src/types.ts @@ -119,33 +119,21 @@ export declare interface ValueSlotAddressAndOffset { offset: number; } +export declare interface ValueExtractionConfig { + slotAddress: string; + abiCoderFormat: string[]; + wordSize?: number; +} + export declare interface CollateralConfig { title: string; ilk: string; symbol: string; decimals: number; exchanges: Record; - oracle: CollateralPriceSourceConfig; + oracle: ValueExtractionConfig[]; } -interface OracleConfigBase { - hasDelay: boolean; - slotPriceValueBeginsAtPosition: number; - currentPriceSlotAddress: string; -} - -export declare interface OracleCurrentAndNextPrices extends OracleConfigBase { - type: 'CurrentAndNextPrice'; - nextPriceSlotAddress: string; -} - -export declare interface OracleCurrentPriceOnly extends OracleConfigBase { - type: 'CurrentPriceOnly'; - currentPriceValiditySlotAndOffset: ValueSlotAddressAndOffset; -} - -export type CollateralPriceSourceConfig = OracleCurrentAndNextPrices | OracleCurrentPriceOnly; - export declare interface NetworkConfig { chainId: string; type: string; diff --git a/core/src/vaults.ts b/core/src/vaults.ts index 6b6df3770..06f4cfab6 100644 --- a/core/src/vaults.ts +++ b/core/src/vaults.ts @@ -310,10 +310,7 @@ const enrichVaultWithTransactonInformation = async ( const { liquidatiorContractAddress, liquidationPenaltyRatio } = await fetchCollateralLiquidationLimitsAndLiquidatorAddress(network, vault.collateralType); - const { liquidationRatio, oracleAddress } = await fetchLiquidationRatioAndOracleAddress( - network, - vault.collateralType - ); + const { liquidationRatio } = await fetchLiquidationRatioAndOracleAddress(network, vault.collateralType); const collateralizationRatio = vault.collateralAmount .multipliedBy(vault.minUnitPrice) .multipliedBy(liquidationRatio) @@ -322,11 +319,7 @@ const enrichVaultWithTransactonInformation = async ( const { transactionFeeLiquidationEth, transactionFeeLiquidationDai } = await getApproximateLiquidationFees( network ); - const { nextUnitPrice, nextPriceChange, currentUnitPrice } = await getOsmPrices( - network, - oracleAddress, - vault.collateralType - ); + const { nextUnitPrice, nextPriceChange, currentUnitPrice } = await getOsmPrices(network, vault.collateralType); const { auctionedAmountDai, state } = getAuctionedDaiAndAuctionState(proximityToLiquidation, vault); const { incentiveCombinedDai, incentiveConstantDai, incentiveRelativeDai } = await fetchVaultLiquidationIncentive( network, diff --git a/core/test/vault-test.ts b/core/test/vault-test.ts index b28bf16ad..6c6d1c37c 100644 --- a/core/test/vault-test.ts +++ b/core/test/vault-test.ts @@ -1,3 +1,5 @@ +import chai, { expect } from 'chai'; +import deepEqualInAnyOrder from 'deep-equal-in-any-order'; import { collectStabilityFees, fetchLiquidationRatioAndOracleAddress, @@ -9,12 +11,9 @@ import { getOsmPrices } from '../src/oracles'; import { createWalletForRpc, resetNetwork, warpTime } from '../helpers/hardhat/network'; import { setupRpcUrlAndGetNetworks } from '../src/rpc'; import { HARDHAT_PRIVATE_KEY, HARDHAT_PUBLIC_KEY, LOCAL_RPC_URL, TEST_NETWORK } from '../helpers/constants'; -import { expect } from 'chai'; import { VaultTransactionLiquidated, VaultTransactionNotLiquidated, Vault, CollateralType } from '../src/types'; import BigNumber from '../src/bignumber'; import { createWalletFromPrivateKey } from '../src/signer'; -import deepEqualInAnyOrder from 'deep-equal-in-any-order'; -import chai from 'chai'; import { fetchAuctionByCollateralTypeAndAuctionIndex } from '../src/fetch'; import { fetchVATbalanceDAI } from '../src/wallet'; import createVaultWithCollateral, { @@ -231,9 +230,9 @@ describe('Sound values are extracted', () => { nextPriceChange: new Date('2022-01-23T22:00:00.000Z'), }, 'ETH-A': { - nextUnitPrice: '1712.2106886', - currentUnitPrice: '1712.2106886', - nextPriceChange: new Date('2022-09-09T10:00:00.000Z'), + nextUnitPrice: '1602.1803800999999', + currentUnitPrice: '1602.1803800999999', + nextPriceChange: new Date('2022-09-14T13:00:00.000Z'), }, 'ETH-B': { nextUnitPrice: '1602.1803800999999', @@ -241,9 +240,9 @@ describe('Sound values are extracted', () => { nextPriceChange: new Date('2022-09-14T13:00:00.000Z'), }, 'ETH-C': { - nextUnitPrice: '1208.0159951', - currentUnitPrice: '1227.067888375', - nextPriceChange: new Date('2022-06-13T11:00:00.000Z'), + nextUnitPrice: '1602.1803800999999', + currentUnitPrice: '1602.1803800999999', + nextPriceChange: new Date('2022-09-14T13:00:00.000Z'), }, 'GUSD-A': { nextUnitPrice: 'NaN', @@ -405,7 +404,7 @@ describe('Sound values are extracted', () => { it(`can reach ${type} oracle`, async () => { const liquidationRatioAndAddress = await fetchLiquidationRatioAndOracleAddress(TEST_NETWORK, type); expect(liquidationRatioAndAddress.oracleAddress).not.to.eq(NULL_ADDRESS); - const prices = await getOsmPrices(TEST_NETWORK, liquidationRatioAndAddress.oracleAddress, type); + const prices = await getOsmPrices(TEST_NETWORK, type); expect(expectedReturn[type].currentUnitPrice).to.eq(prices.currentUnitPrice.toFixed()); if (expectedReturn[type].nextPriceChange.getTime()) { expect(expectedReturn[type].nextPriceChange.toISOString()).to.eq(prices.nextPriceChange.toISOString());