🐛vault deposit: add buffer to prevent over providing (#459)

This commit is contained in:
Bob van der Helm 2023-09-12 15:57:56 +02:00 committed by GitHub
parent 00da894375
commit ccde9dbe1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -13,3 +13,4 @@ export const SECONDS_IN_A_YEAR = 31540000
export const LTV_BUFFER = 0.01
export const DEPOSIT_CAP_BUFFER = 0.999
export const VAULT_DEPOSIT_BUFFER = 0.9999

View File

@ -5,6 +5,7 @@ import { TESTNET_VAULTS_META_DATA, VAULTS_META_DATA } from 'constants/vaults'
import { BNCoin } from 'types/classes/BNCoin'
import { Action } 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'
@ -27,7 +28,12 @@ export function getVaultDepositCoinsAndValue(
) {
const depositsAndReclaims = mergeBNCoinArrays(deposits, reclaims)
const borrowingsAndDepositsAndReclaims = mergeBNCoinArrays(borrowings, depositsAndReclaims)
const totalValue = getValueFromBNCoins(borrowingsAndDepositsAndReclaims, prices)
// The BUFFER 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,
)
const halfValue = totalValue.dividedBy(2)
const primaryAsset = getAssetByDenom(vault.denoms.primary) ?? ASSETS[0]
@ -180,4 +186,4 @@ function getSwapAction(denomIn: string, denomOut: string, amount: BigNumber, sli
slippage: slippage.toString(),
},
}
}
}