From e705109b4c6a1def8ab892e66d632d8cc80d85ad Mon Sep 17 00:00:00 2001 From: Reppelin Tom Date: Mon, 5 Aug 2024 14:18:59 +0200 Subject: [PATCH] feat(improve-price) --- src/component/OracleDecoder.tsx | 17 ++++++---- src/component/OracleTestor.tsx | 45 ++++++++++++++----------- src/hooks/testor/useOraclePriceCheck.ts | 2 -- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/component/OracleDecoder.tsx b/src/component/OracleDecoder.tsx index 35f26cb..a92fe2e 100644 --- a/src/component/OracleDecoder.tsx +++ b/src/component/OracleDecoder.tsx @@ -131,12 +131,17 @@ const OracleDecoder = () => { const fetchAssets = async () => { try { const assets = await queryAsset(selectedNetwork.value); - const formattedAssets = assets.map((asset: any) => ({ - value: asset.address, - label: asset.symbol, - decimals: asset.decimals, - priceUsd: asset.priceUsd, - })); + const formattedAssets = assets + .filter( + (asset: any) => + asset.address !== "0xcbfb9B444d9735C345Df3A0F66cd89bD741692E9" // remove old usdc + ) + .map((asset: any) => ({ + value: asset.address, + label: asset.symbol, + decimals: asset.decimals, + priceUsd: asset.priceUsd, + })); setAssets(formattedAssets); } catch (error) { console.error("Error fetching assets:", error); diff --git a/src/component/OracleTestor.tsx b/src/component/OracleTestor.tsx index 7b161e2..a6d2eb5 100644 --- a/src/component/OracleTestor.tsx +++ b/src/component/OracleTestor.tsx @@ -132,28 +132,33 @@ const OracleTestor = () => { const fetchAssets = async () => { try { const assets = await queryAsset(selectedNetwork.value); - const formattedAssets = assets.map((asset: any) => { - const formattedAsset: Asset = { - value: asset.address, - label: asset.symbol, - decimals: asset.decimals, - priceUsd: asset.priceUsd ?? 0, // Provide a default value of 0 when priceUsd is null - }; - - if (asset.vault) { - formattedAsset.vault = { - address: asset.vault.address, - name: asset.vault.name, - asset: { - symbol: asset.vault.asset.symbol, - address: asset.vault.asset.address, - decimals: asset.vault.asset.decimals, - }, + const formattedAssets = assets + .filter( + (asset: any) => + asset.address !== "0xcbfb9B444d9735C345Df3A0F66cd89bD741692E9" + ) + .map((asset: any) => { + const formattedAsset: Asset = { + value: asset.address, + label: asset.symbol, + decimals: asset.decimals, + priceUsd: asset.priceUsd ?? 0, // Provide a default value of 0 when priceUsd is null }; - } - return formattedAsset; - }); + if (asset.vault) { + formattedAsset.vault = { + address: asset.vault.address, + name: asset.vault.name, + asset: { + symbol: asset.vault.asset.symbol, + address: asset.vault.asset.address, + decimals: asset.vault.asset.decimals, + }, + }; + } + + return formattedAsset; + }); setAssets(formattedAssets); } catch (error) { console.error("Error fetching assets:", error); diff --git a/src/hooks/testor/useOraclePriceCheck.ts b/src/hooks/testor/useOraclePriceCheck.ts index 574fb82..ce5bbc2 100644 --- a/src/hooks/testor/useOraclePriceCheck.ts +++ b/src/hooks/testor/useOraclePriceCheck.ts @@ -184,7 +184,6 @@ const useOraclePriceCheck = ( (asset) => asset.value === collateralAsset ); const loan = assets.find((asset) => asset.value === loanAsset); - // Helper function to convert a number to BigInt with high precision const toBigIntWithPrecision = (value: number) => { return BigInt(Math.round(value * Number(PRECISION))); @@ -224,7 +223,6 @@ const useOraclePriceCheck = ( } const collateralDecimals = BigInt(collateral?.decimals ?? 18); const loanDecimals = BigInt(loan?.decimals ?? 18); - // allowing us to not suffer of a div by zero error. const ratioUsdPrice = collateralPriceUsd.wadDiv(loanPriceUsd) + BigInt(1); // Calculate oracle price equivalent with high precision