[bugfix] fix leverage and implement buffer for health (#374)

* [bugfix] fix leverage and implement buffer for health

* [bugfix] properly remove council page from nav

* [bugfix] ensure integer values for HC

* [bugfix] infinite rerender withdraw + negative values
This commit is contained in:
Bob van der Helm 2023-08-15 10:34:01 -03:00 committed by GitHub
parent de185bf823
commit 9712573b00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 40 deletions

View File

@ -61,7 +61,7 @@ function AccountDetails(props: Props) {
options={{ maxDecimals: 0, minDecimals: 0, suffix: '%' }}
animate
/>
{updatedHealth && health !== updatedHealth && (
{updatedHealth > 0 && health !== updatedHealth && (
<>
<ArrowRight
width={16}

View File

@ -1,34 +0,0 @@
import { Suspense } from 'react'
import { useParams } from 'react-router-dom'
import Card from 'components/Card'
import Loading from 'components/Loading'
import Text from 'components/Text'
function Content() {
const address = useParams().address || ''
return address ? (
<Text size='sm'>{`Council page for ${address}`}</Text>
) : (
<Text size='sm'>Council view only</Text>
)
}
function Fallback() {
return <Loading className='h-4 w-50' />
}
export default function Overview() {
return (
<Card
className='h-fit w-full justify-center bg-white/5'
title='Council'
contentClassName='px-4 py-6'
>
<Suspense fallback={<Fallback />}>
<Content />
</Suspense>
</Card>
)
}

View File

@ -13,7 +13,6 @@ export const menuTree: { page: Page; label: string }[] = [
{ page: 'lend', label: 'Earn' },
{ page: 'borrow', label: 'Borrow' },
{ page: 'portfolio', label: 'Portfolio' },
{ page: 'council', label: 'Council' },
]
export default function DesktopHeader() {

View File

@ -24,6 +24,7 @@ import {
import useStore from 'store'
import { BN_ZERO } from 'constants/math'
import { BN } from 'utils/helpers'
import { HEALTH_BUFFER } from 'utils/constants'
export default function useHealthComputer(account?: Account) {
const { data: prices } = usePrices()
@ -41,7 +42,6 @@ export default function useHealthComputer(account?: Account) {
[prices, baseCurrency.denom],
)
const vaultPositionValues = useMemo(() => {
if (!account?.vaults) return null
return account.vaults.reduce(
@ -141,6 +141,8 @@ export default function useHealthComputer(account?: Account) {
(denom: string, target: BorrowTarget) => {
if (!healthComputer) return BN_ZERO
return BN(max_borrow_estimate_js(healthComputer, denom, target))
.times(1 - HEALTH_BUFFER)
.integerValue()
},
[healthComputer],
)
@ -149,6 +151,8 @@ export default function useHealthComputer(account?: Account) {
(denom: string) => {
if (!healthComputer) return BN_ZERO
return BN(max_withdraw_estimate_js(healthComputer, denom))
.times(1 - HEALTH_BUFFER)
.integerValue()
},
[healthComputer],
)
@ -158,6 +162,8 @@ export default function useHealthComputer(account?: Account) {
if (!healthComputer) return BN_ZERO
try {
return BN(max_swap_estimate_js(healthComputer, from, to, kind))
.times(1 - HEALTH_BUFFER)
.integerValue()
} catch {
return BN_ZERO
}

View File

@ -24,11 +24,17 @@ export function useUpdatedAccount(account?: Account) {
(denom: string) => {
if (!account) return
const deposit = account.deposits.find((deposit) => deposit.denom === denom)
if (deposit) {
removeDeposits([...removedDeposits, deposit])
removeDeposits((prevRemovedDeposits) => {
return [
...prevRemovedDeposits.filter((removedDeposit) => removedDeposit.denom !== denom),
deposit,
]
})
}
},
[account, removedDeposits],
[account, removeDeposits],
)
useEffect(() => {

View File

@ -79,7 +79,8 @@ export const calculateAccountBorrowRate = (
export function calculateAccountLeverage(account: Account, prices: BNCoin[]) {
const [deposits, lends, debts, vaults] = getAccountPositionValues(account, prices)
return debts.dividedBy(deposits.plus(lends).plus(vaults)).plus(1)
const netValue = deposits.plus(lends).plus(vaults).minus(debts)
return debts.dividedBy(netValue).plus(1)
}
export function getAmount(denom: string, coins: Coin[]): BigNumber {

View File

@ -9,3 +9,5 @@ export const defaultFee: StdFee = {
}
export const SECONDS_IN_A_YEAR = 31540000
export const HEALTH_BUFFER = 0.01