🐛change BUFFER to slippage for Vault enter value (#476)

This commit is contained in:
Bob van der Helm 2023-09-15 11:03:42 +02:00 committed by GitHub
parent b12f5d3583
commit 1d5595d687
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -43,8 +43,9 @@ export default function useDepositVault(props: Props): {
) )
const { primaryCoin, secondaryCoin, totalValue } = useMemo( 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(() => { const reclaimActions: Action[] = useMemo(() => {

View File

@ -5,7 +5,6 @@ import { TESTNET_VAULTS_META_DATA, VAULTS_META_DATA } from 'constants/vaults'
import { BNCoin } from 'types/classes/BNCoin' import { BNCoin } from 'types/classes/BNCoin'
import { Action, Uint128 } from 'types/generated/mars-credit-manager/MarsCreditManager.types' import { Action, Uint128 } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
import { getAssetByDenom } from 'utils/assets' import { getAssetByDenom } from 'utils/assets'
import { VAULT_DEPOSIT_BUFFER } from 'utils/constants'
import { getCoinAmount, getCoinValue } from 'utils/formatters' import { getCoinAmount, getCoinValue } from 'utils/formatters'
import { getValueFromBNCoins, mergeBNCoinArrays } from 'utils/helpers' import { getValueFromBNCoins, mergeBNCoinArrays } from 'utils/helpers'
import { getTokenPrice } from 'utils/tokens' import { getTokenPrice } from 'utils/tokens'
@ -25,14 +24,15 @@ export function getVaultDepositCoinsAndValue(
borrowings: BNCoin[], borrowings: BNCoin[],
reclaims: BNCoin[], reclaims: BNCoin[],
prices: BNCoin[], prices: BNCoin[],
slippage: number,
) { ) {
const depositsAndReclaims = mergeBNCoinArrays(deposits, reclaims) const depositsAndReclaims = mergeBNCoinArrays(deposits, reclaims)
const borrowingsAndDepositsAndReclaims = mergeBNCoinArrays(borrowings, depositsAndReclaims) 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. // into the vaults than there are funds available.
const totalValue = getValueFromBNCoins(borrowingsAndDepositsAndReclaims, prices).times( const totalValue = getValueFromBNCoins(borrowingsAndDepositsAndReclaims, prices).times(
VAULT_DEPOSIT_BUFFER, 1 - slippage,
) )
const halfValue = totalValue.dividedBy(2) const halfValue = totalValue.dividedBy(2)