🐛fix prices passed to HC and formatting (#473)

This commit is contained in:
Bob van der Helm 2023-09-14 15:00:56 +02:00 committed by GitHub
parent 8a87329c90
commit d7b91f4115
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 15 additions and 8 deletions

View File

@ -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 },