Use latest client to fix rounding issues

This commit is contained in:
Tyler Shipe 2021-08-29 15:15:37 -04:00
parent dde1555b69
commit 7aa7feadb0
5 changed files with 45 additions and 94 deletions

View File

@ -97,7 +97,27 @@ export default function AccountInfo() {
return (
<FloatingElement showConnect>
<div className={!connected ? 'filter blur-sm' : undefined}>
<ElementTitle>Account</ElementTitle>
<Tooltip
content={
mangoAccount ? (
<div>
Init Health:{' '}
{mangoAccount
.getHealth(mangoGroup, mangoCache, 'Init')
.toString()}
<br />
Maint Health:{' '}
{mangoAccount
.getHealth(mangoGroup, mangoCache, 'Maint')
.toString()}
</div>
) : (
''
)
}
>
<ElementTitle>Account</ElementTitle>
</Tooltip>
<div>
<div>
<div className="flex justify-between pb-3">
@ -122,38 +142,6 @@ export default function AccountInfo() {
)}
</div>
</div>
{/* <div className={`flex justify-between pb-3`}>
<div className="font-normal text-th-fgd-3 leading-4">
Total Assets Value
</div>
<div className={`text-th-fgd-1`}>
{isLoading ? (
<DataLoader />
) : mangoAccount ? (
formatUsdValue(
+mangoAccount.getAssetsVal(mangoGroup, mangoCache)
)
) : (
'--'
)}
</div>
</div>
<div className={`flex justify-between pb-3`}>
<div className="font-normal text-th-fgd-3 leading-4">
Total Liabilities Value
</div>
<div className={`text-th-fgd-1`}>
{isLoading ? (
<DataLoader />
) : mangoAccount ? (
formatUsdValue(
+mangoAccount.getLiabsVal(mangoGroup, mangoCache)
)
) : (
'--'
)}
</div>
</div> */}
<div className={`flex justify-between pb-3`}>
<div className="font-normal text-th-fgd-3 leading-4">
Collateral Available

View File

@ -5,17 +5,13 @@ import { notify } from '../utils/notifications'
import { Table, Thead, Tbody, Tr, Th, Td } from 'react-super-responsive-table'
import { InformationCircleIcon } from '@heroicons/react/outline'
import Tooltip from './Tooltip'
import { ceilToDecimal, floorToDecimal, sleep } from '../utils'
import { sleep } from '../utils'
import { Market } from '@project-serum/serum'
import {
getTokenBySymbol,
ZERO_I80F48,
} from '@blockworks-foundation/mango-client'
import { ZERO_I80F48 } from '@blockworks-foundation/mango-client'
const BalancesTable = () => {
const balances = useBalances()
const actions = useMangoStore((s) => s.actions)
const mangoGroupConfig = useMangoStore((s) => s.selectedMangoGroup.config)
async function handleSettleAll() {
const mangoAccount = useMangoStore.getState().selectedMangoAccount.current
@ -131,10 +127,6 @@ const BalancesTable = () => {
</Thead>
<Tbody>
{filteredBalances.map((balance, index) => {
const tokenConfig = getTokenBySymbol(
mangoGroupConfig,
balance.symbol.toUpperCase()
)
return (
<Tr
key={`${index}`}
@ -158,18 +150,12 @@ const BalancesTable = () => {
<Td
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
>
{floorToDecimal(
parseFloat(balance.deposits.floor().toFixed()),
tokenConfig.decimals
)}
{balance.deposits.toFixed()}
</Td>
<Td
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
>
{ceilToDecimal(
parseFloat(balance.borrows.ceil().toFixed()),
tokenConfig.decimals
)}
{balance.borrows.toFixed()}
</Td>
<Td
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
@ -184,10 +170,7 @@ const BalancesTable = () => {
<Td
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
>
{floorToDecimal(
parseFloat(balance.net.toFixed()),
tokenConfig.decimals
)}
{balance.net.toFixed()}
</Td>
</Tr>
)

View File

@ -2,13 +2,7 @@ import { useCallback, useMemo, useState } from 'react'
import FloatingElement from './FloatingElement'
import { ElementTitle } from './styles'
import useMangoStore, { mangoClient } from '../stores/useMangoStore'
import {
ceilToDecimal,
floorToDecimal,
i80f48ToPercent,
formatUsdValue,
tokenPrecision,
} from '../utils/index'
import { i80f48ToPercent, formatUsdValue, tokenPrecision } from '../utils/index'
import Button, { LinkButton } from './Button'
import Tooltip from './Tooltip'
import SideBadge from './SideBadge'
@ -297,22 +291,18 @@ export default function MarketPosition() {
.map(({ symbol, mintKey }) => {
const tokenIndex = mangoGroup.getTokenIndex(mintKey)
const deposit = mangoAccount
? mangoAccount
.getUiDeposit(
mangoGroupCache.rootBankCache[tokenIndex],
mangoGroup,
tokenIndex
)
.toNumber()
? mangoAccount.getUiDeposit(
mangoGroupCache.rootBankCache[tokenIndex],
mangoGroup,
tokenIndex
)
: null
const borrow = mangoAccount
? mangoAccount
.getUiBorrow(
mangoGroupCache.rootBankCache[tokenIndex],
mangoGroup,
tokenIndex
)
.toNumber()
? mangoAccount.getUiBorrow(
mangoGroupCache.rootBankCache[tokenIndex],
mangoGroup,
tokenIndex
)
: null
return (
<div
@ -337,18 +327,10 @@ export default function MarketPosition() {
{isLoading ? (
<DataLoader />
) : mangoAccount ? (
deposit > 0 ? (
floorToDecimal(
deposit,
mangoGroup.tokens[tokenIndex].decimals
).toFixed(tokenPrecision[symbol])
) : borrow > 0 ? (
`-${ceilToDecimal(
borrow,
mangoGroup.tokens[tokenIndex].decimals
).toFixed(tokenPrecision[symbol])}`
deposit.gt(borrow) ? (
deposit.toFixed()
) : (
0
borrow.toFixed()
)
) : (
0

View File

@ -106,9 +106,7 @@ const WithdrawModal: FunctionComponent<WithdrawModalProps> = ({
}
if (maxWithdraw.gt(I80F48.fromNumber(0))) {
setMaxAmount(
floorToDecimal(parseFloat(maxWithdraw.toFixed()), token.decimals)
)
setMaxAmount(parseFloat(maxWithdraw.toFixed()))
} else {
setMaxAmount(0)
}

View File

@ -986,7 +986,7 @@
"@blockworks-foundation/mango-client@git+https://github.com/blockworks-foundation/mango-client-v3.git":
version "3.0.12"
resolved "git+https://github.com/blockworks-foundation/mango-client-v3.git#e5e5d559a072abd53b4a21b68d0abb52f68c6d9b"
resolved "git+https://github.com/blockworks-foundation/mango-client-v3.git#5f48bccbb4530a2e8ac7f075c33b90a71a44d224"
dependencies:
"@project-serum/serum" "0.13.55"
"@project-serum/sol-wallet-adapter" "^0.2.0"
@ -1893,9 +1893,9 @@
integrity sha512-/BHF5HAx3em7/KkzVKm3LrsD6HZAXuXO1AJZQ3cRRBZj4oHZDviWPYu0aEplAqDFNHZPW6d3G7KN+ONcCCC7pw==
"@types/node@*":
version "16.7.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.7.4.tgz#68a9384694af63ceab8848e95d76d9a3519e84b6"
integrity sha512-25QXpDsTiDnl2rZGUenagVMwO46way8dOUdvoC3R3p+6TrbpxeJBo/v87BEG1IHI31Jhaa8lPeSHcqwxsVBeYQ==
version "16.7.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.7.6.tgz#8666478db8095aa66e25b7e469f3e7b53ea2855e"
integrity sha512-VESVNFoa/ahYA62xnLBjo5ur6gPsgEE5cNRy8SrdnkZ2nwJSW0kJ4ufbFr2zuU9ALtHM8juY53VcRoTA7htXSg==
"@types/node@^12.12.54":
version "12.20.21"