diff --git a/src/hooks/testor/useOraclePriceCheck.ts b/src/hooks/testor/useOraclePriceCheck.ts index c730680..580d17a 100644 --- a/src/hooks/testor/useOraclePriceCheck.ts +++ b/src/hooks/testor/useOraclePriceCheck.ts @@ -197,12 +197,35 @@ const useOraclePriceCheck = ( const loanPriceUsd = loan ? toBigIntWithPrecision(loan.priceUsd) : BigInt(0); - + if (loanPriceUsd === BigInt(0)) { + setErrors((prevErrors) => [ + ...prevErrors, + ErrorTypes.LOAN_ASSET_ZERO_PRICE, + ]); + setResult({ + scaleFactor: scaleFactor.toString(), + price: price.toString(), + priceUnscaledInCollateralTokenDecimals: formatUnits( + price, + Number( + 36 - + Number(collateral?.decimals ?? 18) + + Number(loan?.decimals ?? 18) + ) + ), + collateralPriceUsd: formatUnits(collateralPriceUsd), + loanPriceUsd: "0", + ratioUsdPrice: "N/A", + oraclePriceEquivalent: "N/A", + percentageDifference: "N/A", + isVerified: false, + }); + return; + } const collateralDecimals = BigInt(collateral?.decimals ?? 18); const loanDecimals = BigInt(loan?.decimals ?? 18); const ratioUsdPrice = collateralPriceUsd.wadDiv(loanPriceUsd); - // Calculate oracle price equivalent with high precision const oraclePriceEquivalent = (price * PRECISION) / diff --git a/src/services/errorTypes.ts b/src/services/errorTypes.ts index 5b1b94f..9bc5b9d 100644 --- a/src/services/errorTypes.ts +++ b/src/services/errorTypes.ts @@ -24,6 +24,7 @@ export enum ErrorTypes { NO_VALID_PATH = "NO_VALID_PATH", BASE_MATCH_ERROR = "BASE_MATCH_ERROR", QUOTE_MATCH_ERROR = "QUOTE_MATCH_ERROR", + LOAN_ASSET_ZERO_PRICE = "LOAN_ASSET_ZERO_PRICE", } export const ErrorMessages: { [key in ErrorTypes]: string } = { @@ -63,6 +64,8 @@ export const ErrorMessages: { [key in ErrorTypes]: string } = { "Base token does not match. Is there any harcoded oracle price?", [ErrorTypes.QUOTE_MATCH_ERROR]: "Quote token does not match. Is there any harcoded oracle price?", + [ErrorTypes.LOAN_ASSET_ZERO_PRICE]: + "Can't fetch the USD value of the loan asset. The Morpho-Blue API seems to not be pricing it.", }; export enum LoadingStates {