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(improve-price) #23

Merged
merged 1 commit into from
Aug 5, 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
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