From d7b91f4115a869f603d6eb4509be0b286b8dbee5 Mon Sep 17 00:00:00 2001 From: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com> Date: Thu, 14 Sep 2023 15:00:56 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9Bfix=20prices=20passed=20to=20HC=20a?= =?UTF-8?q?nd=20formatting=20(#473)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/params/getAssetParams.ts | 2 +- src/components/Earn/Lend/LendingMarketsTable.tsx | 2 +- .../Trade/TradeChart/OsmosisTheGraphDataFeed.ts | 2 +- src/constants/assets.ts | 2 +- src/hooks/broadcast/useDepositVault.ts | 2 +- src/hooks/useHealthComputer.tsx | 9 ++++++++- src/hooks/useLendingMarketAssetsTableData.ts | 2 +- src/types/interfaces/asset.d.ts | 2 +- 8 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/api/params/getAssetParams.ts b/src/api/params/getAssetParams.ts index dbc8bf4e..e7228005 100644 --- a/src/api/params/getAssetParams.ts +++ b/src/api/params/getAssetParams.ts @@ -9,4 +9,4 @@ export default async function getAssetParams(): Promise -} \ No newline at end of file +} diff --git a/src/components/Trade/TradeChart/OsmosisTheGraphDataFeed.ts b/src/components/Trade/TradeChart/OsmosisTheGraphDataFeed.ts index d30f0d6c..c255f3b0 100644 --- a/src/components/Trade/TradeChart/OsmosisTheGraphDataFeed.ts +++ b/src/components/Trade/TradeChart/OsmosisTheGraphDataFeed.ts @@ -269,4 +269,4 @@ export class OsmosisTheGraphDataFeed implements IDatafeedChartApi { unsubscribeBars(listenerGuid: string): void { // TheGraph doesn't support websockets yet } -} \ No newline at end of file +} diff --git a/src/constants/assets.ts b/src/constants/assets.ts index 9fa301b5..dbf30715 100644 --- a/src/constants/assets.ts +++ b/src/constants/assets.ts @@ -229,4 +229,4 @@ export const ASSETS: Asset[] = [ hasOraclePrice: !IS_TESTNET, forceFetchPrice: !IS_TESTNET, }, -] \ No newline at end of file +] diff --git a/src/hooks/broadcast/useDepositVault.ts b/src/hooks/broadcast/useDepositVault.ts index acb577cd..d9dd817e 100644 --- a/src/hooks/broadcast/useDepositVault.ts +++ b/src/hooks/broadcast/useDepositVault.ts @@ -102,4 +102,4 @@ export default function useDepositVault(props: Props): { actions, totalValue, } -} \ No newline at end of file +} diff --git a/src/hooks/useHealthComputer.tsx b/src/hooks/useHealthComputer.tsx index cef7ee56..304d5bc1 100644 --- a/src/hooks/useHealthComputer.tsx +++ b/src/hooks/useHealthComputer.tsx @@ -14,6 +14,7 @@ import { HealthComputer, } from 'types/generated/mars-rover-health-computer/MarsRoverHealthComputer.types' import { convertAccountToPositions } from 'utils/accounts' +import { getAssetByDenom } from 'utils/assets' import { LTV_BUFFER } from 'utils/constants' import { BorrowTarget, @@ -70,7 +71,13 @@ export default function useHealthComputer(account?: Account) { const priceData = useMemo(() => { return prices.reduce( (prev, curr) => { - prev[curr.denom] = curr.amount.shiftedBy(VALUE_SCALE_FACTOR).toString() + const decimals = getAssetByDenom(curr.denom)?.decimals || 6 + + // The HealthComputer needs prices expressed per 1 amount. So we need to correct here for any additional decimals. + prev[curr.denom] = curr.amount + .shiftedBy(VALUE_SCALE_FACTOR) + .shiftedBy(-decimals + 6) + .toString() return prev }, {} as { [key: string]: string }, diff --git a/src/hooks/useLendingMarketAssetsTableData.ts b/src/hooks/useLendingMarketAssetsTableData.ts index 47efbf38..0a8a8ae1 100644 --- a/src/hooks/useLendingMarketAssetsTableData.ts +++ b/src/hooks/useLendingMarketAssetsTableData.ts @@ -56,4 +56,4 @@ function useLendingMarketAssetsTableData(): { }, [markets, marketDeposits, marketLiquidities, accountLentAmounts, convertAmount]) } -export default useLendingMarketAssetsTableData \ No newline at end of file +export default useLendingMarketAssetsTableData diff --git a/src/types/interfaces/asset.d.ts b/src/types/interfaces/asset.d.ts index dad074a1..ae3de69f 100644 --- a/src/types/interfaces/asset.d.ts +++ b/src/types/interfaces/asset.d.ts @@ -96,4 +96,4 @@ interface MarketTableData { marketLiquidityRate: number marketLiquidityAmount: BigNumber marketLiquidationThreshold: number -} \ No newline at end of file +}