Skip to content

Commit

Permalink
Merge pull request #23 from tomrpl/feat/improving-price
Browse files Browse the repository at this point in the history
feat(improve-price)
  • Loading branch information
tomrpl authored Aug 5, 2024
2 parents 1be3981 + e705109 commit 158258a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
17 changes: 11 additions & 6 deletions src/component/OracleDecoder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
45 changes: 25 additions & 20 deletions src/component/OracleTestor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/hooks/testor/useOraclePriceCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 158258a

Please sign in to comment.