fix: vault calculation of assets (#486)
This commit is contained in:
parent
50fd39e926
commit
9ced4ab6c9
@ -28,13 +28,11 @@ interface Props {
|
||||
onChangeDeposits: (deposits: BNCoin[]) => void
|
||||
onChangeIsCustomRatio: (isCustomRatio: boolean) => void
|
||||
toggleOpen: (index: number) => void
|
||||
displayCurrency: string
|
||||
depositCapReachedCoins: BNCoin[]
|
||||
}
|
||||
|
||||
export default function VaultDeposit(props: Props) {
|
||||
const { deposits, primaryAsset, secondaryAsset, account, onChangeDeposits, displayCurrency } =
|
||||
props
|
||||
const { deposits, primaryAsset, secondaryAsset, account, onChangeDeposits } = props
|
||||
const [availablePrimaryAmount, availableSecondaryAmount] = useMemo(
|
||||
() => [
|
||||
accumulateAmounts(primaryAsset.denom, [...account.deposits, ...account.lends]),
|
||||
@ -80,26 +78,55 @@ export default function VaultDeposit(props: Props) {
|
||||
() =>
|
||||
BN(
|
||||
Math.min(
|
||||
availablePrimaryAmount.multipliedBy(primaryPrice).toNumber(),
|
||||
availableSecondaryAmount.multipliedBy(secondaryPrice).toNumber(),
|
||||
availablePrimaryAmount
|
||||
.shiftedBy(-primaryAsset.decimals)
|
||||
.multipliedBy(primaryPrice)
|
||||
.toNumber(),
|
||||
availableSecondaryAmount
|
||||
.shiftedBy(-secondaryAsset.decimals)
|
||||
.multipliedBy(secondaryPrice)
|
||||
.toNumber(),
|
||||
),
|
||||
),
|
||||
[availablePrimaryAmount, primaryPrice, availableSecondaryAmount, secondaryPrice],
|
||||
[
|
||||
availablePrimaryAmount,
|
||||
availableSecondaryAmount,
|
||||
primaryAsset,
|
||||
primaryPrice,
|
||||
secondaryAsset,
|
||||
secondaryPrice,
|
||||
],
|
||||
)
|
||||
const primaryMax = useMemo(
|
||||
() =>
|
||||
props.isCustomRatio
|
||||
? availablePrimaryAmount
|
||||
: maxAssetValueNonCustom.dividedBy(primaryPrice).integerValue(),
|
||||
[props.isCustomRatio, availablePrimaryAmount, primaryPrice, maxAssetValueNonCustom],
|
||||
)
|
||||
const secondaryMax = useMemo(
|
||||
() =>
|
||||
props.isCustomRatio
|
||||
? availableSecondaryAmount
|
||||
: maxAssetValueNonCustom.dividedBy(secondaryPrice).decimalPlaces(0),
|
||||
[props.isCustomRatio, availableSecondaryAmount, secondaryPrice, maxAssetValueNonCustom],
|
||||
: maxAssetValueNonCustom
|
||||
.dividedBy(primaryPrice)
|
||||
.shiftedBy(primaryAsset.decimals)
|
||||
.integerValue(),
|
||||
[
|
||||
props.isCustomRatio,
|
||||
availablePrimaryAmount,
|
||||
primaryPrice,
|
||||
primaryAsset,
|
||||
maxAssetValueNonCustom,
|
||||
],
|
||||
)
|
||||
const secondaryMax = useMemo(() => {
|
||||
return props.isCustomRatio
|
||||
? availableSecondaryAmount
|
||||
: maxAssetValueNonCustom
|
||||
.dividedBy(secondaryPrice)
|
||||
.shiftedBy(secondaryAsset.decimals)
|
||||
.integerValue()
|
||||
}, [
|
||||
props.isCustomRatio,
|
||||
availableSecondaryAmount,
|
||||
secondaryPrice,
|
||||
secondaryAsset,
|
||||
maxAssetValueNonCustom,
|
||||
])
|
||||
|
||||
const [percentage, setPercentage] = useState(
|
||||
primaryValue.dividedBy(maxAssetValueNonCustom).multipliedBy(100).decimalPlaces(0).toNumber() ||
|
||||
|
@ -148,7 +148,6 @@ export default function VaultModalContent(props: Props) {
|
||||
toggleOpen={toggleOpen}
|
||||
isCustomRatio={isCustomRatio}
|
||||
onChangeIsCustomRatio={onChangeIsCustomRatio}
|
||||
displayCurrency={displayCurrency}
|
||||
depositCapReachedCoins={depositCapReachedCoins}
|
||||
/>
|
||||
),
|
||||
|
@ -201,7 +201,7 @@ export default function SwapForm(props: Props) {
|
||||
BNCoin.fromDenomAndBigNumber(sellAsset.denom, BN_ZERO),
|
||||
isAutoLendEnabled ? 'lend' : 'deposit',
|
||||
)
|
||||
}, [buyAsset.denom, sellAsset.denom, simulateTrade, isAutoLendEnabled])
|
||||
}, [buyAsset.denom, sellAsset.denom, simulateTrade, isAutoLendEnabled, setMarginChecked])
|
||||
|
||||
useEffect(() => {
|
||||
const removeDepositAmount = sellAssetAmount.isGreaterThanOrEqualTo(sellSideMarginThreshold)
|
||||
|
Loading…
Reference in New Issue
Block a user