Skip to content

Commit

Permalink
Merge pull request #15 from tomrpl/feat/fixing-warning-return-error
Browse files Browse the repository at this point in the history
feat(handling a new error): testing
  • Loading branch information
tomrpl authored Jul 30, 2024
2 parents 0825418 + 89a83b9 commit d36f1af
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/hooks/testor/useOraclePriceCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) /
Expand Down
3 changes: 3 additions & 0 deletions src/services/errorTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } = {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d36f1af

Please sign in to comment.