From 1d5595d687edfe463275ba39defd1e2fb3eb120c Mon Sep 17 00:00:00 2001 From: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:03:42 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9Bchange=20BUFFER=20to=20slippage=20f?= =?UTF-8?q?or=20Vault=20enter=20value=20(#476)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/broadcast/useDepositVault.ts | 5 +++-- src/utils/vaults.ts | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hooks/broadcast/useDepositVault.ts b/src/hooks/broadcast/useDepositVault.ts index d9dd817e..d406786c 100644 --- a/src/hooks/broadcast/useDepositVault.ts +++ b/src/hooks/broadcast/useDepositVault.ts @@ -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(() => { diff --git a/src/utils/vaults.ts b/src/utils/vaults.ts index b7541f1a..d7d31d34 100644 --- a/src/utils/vaults.ts +++ b/src/utils/vaults.ts @@ -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)