🐛change BUFFER to slippage for Vault enter value (#476)
This commit is contained in:
parent
b12f5d3583
commit
1d5595d687
@ -43,8 +43,9 @@ export default function useDepositVault(props: Props): {
|
||||
)
|
||||
|
||||
const { primaryCoin, secondaryCoin, totalValue } = useMemo(
|
||||
() => getVaultDepositCoinsAndValue(props.vault, deposits, borrowings, reclaims, prices),
|
||||
[reclaims, deposits, borrowings, props.vault, prices],
|
||||
() =>
|
||||
getVaultDepositCoinsAndValue(props.vault, deposits, borrowings, reclaims, prices, slippage),
|
||||
[props.vault, deposits, borrowings, reclaims, prices, slippage],
|
||||
)
|
||||
|
||||
const reclaimActions: Action[] = useMemo(() => {
|
||||
|
@ -5,7 +5,6 @@ import { TESTNET_VAULTS_META_DATA, VAULTS_META_DATA } from 'constants/vaults'
|
||||
import { BNCoin } from 'types/classes/BNCoin'
|
||||
import { Action, Uint128 } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
||||
import { getAssetByDenom } from 'utils/assets'
|
||||
import { VAULT_DEPOSIT_BUFFER } from 'utils/constants'
|
||||
import { getCoinAmount, getCoinValue } from 'utils/formatters'
|
||||
import { getValueFromBNCoins, mergeBNCoinArrays } from 'utils/helpers'
|
||||
import { getTokenPrice } from 'utils/tokens'
|
||||
@ -25,14 +24,15 @@ export function getVaultDepositCoinsAndValue(
|
||||
borrowings: BNCoin[],
|
||||
reclaims: BNCoin[],
|
||||
prices: BNCoin[],
|
||||
slippage: number,
|
||||
) {
|
||||
const depositsAndReclaims = mergeBNCoinArrays(deposits, reclaims)
|
||||
const borrowingsAndDepositsAndReclaims = mergeBNCoinArrays(borrowings, depositsAndReclaims)
|
||||
|
||||
// The BUFFER is to account for rounding errors. Otherwise, it might happen we try to deposit more value
|
||||
// The slippage is to account for rounding errors. Otherwise, it might happen we try to deposit more value
|
||||
// into the vaults than there are funds available.
|
||||
const totalValue = getValueFromBNCoins(borrowingsAndDepositsAndReclaims, prices).times(
|
||||
VAULT_DEPOSIT_BUFFER,
|
||||
1 - slippage,
|
||||
)
|
||||
const halfValue = totalValue.dividedBy(2)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user