🐛vault deposit: add buffer to prevent over providing (#459)
This commit is contained in:
parent
00da894375
commit
ccde9dbe1e
@ -13,3 +13,4 @@ export const SECONDS_IN_A_YEAR = 31540000
|
|||||||
export const LTV_BUFFER = 0.01
|
export const LTV_BUFFER = 0.01
|
||||||
|
|
||||||
export const DEPOSIT_CAP_BUFFER = 0.999
|
export const DEPOSIT_CAP_BUFFER = 0.999
|
||||||
|
export const VAULT_DEPOSIT_BUFFER = 0.9999
|
@ -5,6 +5,7 @@ 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 } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
import { Action } 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'
|
||||||
@ -27,7 +28,12 @@ export function getVaultDepositCoinsAndValue(
|
|||||||
) {
|
) {
|
||||||
const depositsAndReclaims = mergeBNCoinArrays(deposits, reclaims)
|
const depositsAndReclaims = mergeBNCoinArrays(deposits, reclaims)
|
||||||
const borrowingsAndDepositsAndReclaims = mergeBNCoinArrays(borrowings, depositsAndReclaims)
|
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 halfValue = totalValue.dividedBy(2)
|
||||||
|
|
||||||
const primaryAsset = getAssetByDenom(vault.denoms.primary) ?? ASSETS[0]
|
const primaryAsset = getAssetByDenom(vault.denoms.primary) ?? ASSETS[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user