Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(handling a new error): testing #15

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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