update health computer + fix comments
This commit is contained in:
parent
6389155b5a
commit
fb701d871b
@ -152,7 +152,9 @@ export default function useHealthComputer(account?: Account) {
|
|||||||
if (!healthComputer) return
|
if (!healthComputer) return
|
||||||
try {
|
try {
|
||||||
setHealthFactor(Number(compute_health_js(healthComputer).max_ltv_health_factor) || 10)
|
setHealthFactor(Number(compute_health_js(healthComputer).max_ltv_health_factor) || 10)
|
||||||
} catch (err) {}
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
}, [healthComputer])
|
}, [healthComputer])
|
||||||
|
|
||||||
const computeMaxBorrowAmount = useCallback(
|
const computeMaxBorrowAmount = useCallback(
|
||||||
|
@ -23,7 +23,7 @@ export class BNCoin {
|
|||||||
toCoin(): Coin {
|
toCoin(): Coin {
|
||||||
return {
|
return {
|
||||||
denom: this.denom,
|
denom: this.denom,
|
||||||
amount: this.amount.toString(),
|
amount: this.amount.integerValue().toString(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ export class BNCoin {
|
|||||||
amount: max
|
amount: max
|
||||||
? 'account_balance'
|
? 'account_balance'
|
||||||
: {
|
: {
|
||||||
exact: this.amount.toString(),
|
exact: this.amount.integerValue().toString(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ export class BNCoin {
|
|||||||
toSignedCoin(): any {
|
toSignedCoin(): any {
|
||||||
return {
|
return {
|
||||||
denom: this.denom,
|
denom: this.denom,
|
||||||
size: this.amount.toString(),
|
size: this.amount.integerValue().toString(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ export class BNCoin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
loss: this.toCoin(),
|
loss: this.abs().toCoin(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,12 +4,11 @@ import { BN_ZERO } from 'constants/math'
|
|||||||
import { ORACLE_DENOM } from 'constants/oracle'
|
import { ORACLE_DENOM } from 'constants/oracle'
|
||||||
import { BNCoin } from 'types/classes/BNCoin'
|
import { BNCoin } from 'types/classes/BNCoin'
|
||||||
import { VaultPosition } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
import { VaultPosition } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
||||||
|
import { Positions } from 'types/generated/mars-rover-health-computer/MarsRoverHealthComputer.types'
|
||||||
import { byDenom } from 'utils/array'
|
import { byDenom } from 'utils/array'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
import { convertApyToApr } from 'utils/parsers'
|
import { convertApyToApr } from 'utils/parsers'
|
||||||
|
|
||||||
import { Positions } from '../types/generated/mars-rover-health-computer/MarsRoverHealthComputer.types'
|
|
||||||
|
|
||||||
export const calculateAccountBalanceValue = (
|
export const calculateAccountBalanceValue = (
|
||||||
account: Account | AccountChange,
|
account: Account | AccountChange,
|
||||||
prices: BNCoin[],
|
prices: BNCoin[],
|
||||||
@ -210,24 +209,34 @@ export function convertAccountToPositions(account: Account, prices: BNCoin[]): P
|
|||||||
size: perpPosition.amount.toString() as any,
|
size: perpPosition.amount.toString() as any,
|
||||||
unrealised_pnl: {
|
unrealised_pnl: {
|
||||||
coins: {
|
coins: {
|
||||||
closing_fee: perpPosition.pnl.unrealized.fees.toCoin(),
|
closing_fee: perpPosition.pnl.unrealized.fees.abs().toCoin(),
|
||||||
// Used
|
// Used
|
||||||
pnl: perpPosition.pnl.unrealized.net.toPnLCoin(), // Used
|
pnl: perpPosition.pnl.unrealized.net.toPnLCoin(), // Used
|
||||||
},
|
},
|
||||||
amounts: {
|
amounts: {
|
||||||
// CHeck if these are correct
|
// CHeck if these are correct
|
||||||
accrued_funding: perpPosition.pnl.unrealized.funding.amount.toString() as any,
|
accrued_funding: perpPosition.pnl.unrealized.funding.amount
|
||||||
opening_fee: perpPosition.pnl.unrealized.fees.amount.toString() as any, // Add openning fee for modifying position
|
.integerValue()
|
||||||
closing_fee: perpPosition.pnl.unrealized.fees.amount.toString() as any, // Add closing fee for modifying position
|
.toString() as any,
|
||||||
pnl: perpPosition.pnl.unrealized.net.amount.toString() as any,
|
opening_fee: perpPosition.pnl.unrealized.fees.amount
|
||||||
price_pnl: perpPosition.pnl.unrealized.price.amount.toString() as any,
|
.abs()
|
||||||
|
.integerValue()
|
||||||
|
.toString() as any, // Add openning fee for modifying position
|
||||||
|
closing_fee: perpPosition.pnl.unrealized.fees.amount
|
||||||
|
.abs()
|
||||||
|
.integerValue()
|
||||||
|
.toString() as any, // Add closing fee for modifying position
|
||||||
|
pnl: perpPosition.pnl.unrealized.net.amount.integerValue().toString() as any,
|
||||||
|
price_pnl: perpPosition.pnl.unrealized.price.amount.integerValue().toString() as any,
|
||||||
},
|
},
|
||||||
values: {
|
values: {
|
||||||
// This does not matter for health calculation
|
// This does not matter for health calculation
|
||||||
accrued_funding: perpPosition.pnl.unrealized.funding.amount.toString() as any,
|
accrued_funding: perpPosition.pnl.unrealized.funding.amount
|
||||||
closing_fee: perpPosition.pnl.unrealized.fees.amount.toString() as any,
|
.integerValue()
|
||||||
pnl: perpPosition.pnl.unrealized.net.amount.toString() as any,
|
.toString() as any,
|
||||||
price_pnl: perpPosition.pnl.unrealized.price.amount.toString() as any,
|
closing_fee: perpPosition.pnl.unrealized.fees.amount.integerValue().toString() as any,
|
||||||
|
pnl: perpPosition.pnl.unrealized.net.amount.integerValue().toString() as any,
|
||||||
|
price_pnl: perpPosition.pnl.unrealized.price.amount.integerValue().toString() as any,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
realised_pnl: {
|
realised_pnl: {
|
||||||
|
@ -296,9 +296,7 @@ async function __wbg_load(module, imports) {
|
|||||||
function __wbg_get_imports() {
|
function __wbg_get_imports() {
|
||||||
const imports = {}
|
const imports = {}
|
||||||
imports.wbg = {}
|
imports.wbg = {}
|
||||||
imports.wbg.__wbg_log_117d9799fa4f6287 = function (arg0, arg1, arg2, arg3) {
|
imports.wbg.__wbg_log_117d9799fa4f6287 = function (arg0, arg1, arg2, arg3) {}
|
||||||
console.log(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3))
|
|
||||||
}
|
|
||||||
imports.wbg.__wbindgen_object_clone_ref = function (arg0) {
|
imports.wbg.__wbindgen_object_clone_ref = function (arg0) {
|
||||||
const ret = getObject(arg0)
|
const ret = getObject(arg0)
|
||||||
return addHeapObject(ret)
|
return addHeapObject(ret)
|
||||||
|
Loading…
Reference in New Issue
Block a user