-
+ |
{status && }
{status === VaultStatus.ACTIVE && }
diff --git a/src/components/Earn/Farm/VaultTable.tsx b/src/components/Earn/Farm/VaultTable.tsx
index 08c98bea..5c8867e6 100644
--- a/src/components/Earn/Farm/VaultTable.tsx
+++ b/src/components/Earn/Farm/VaultTable.tsx
@@ -182,6 +182,7 @@ export const VaultTable = (props: Props) => {
accessorKey: 'ltv.max',
header: 'Max LTV',
cell: ({ row }) => {
+ if (props.isLoading) return
return {formatPercent(row.original.ltv.max)}
},
},
@@ -189,6 +190,7 @@ export const VaultTable = (props: Props) => {
accessorKey: 'ltv.liq',
header: 'Liq. LTV',
cell: ({ row }) => {
+ if (props.isLoading) return
return {formatPercent(row.original.ltv.liq)}
},
},
diff --git a/src/components/Header/DesktopHeader.tsx b/src/components/Header/DesktopHeader.tsx
index 0c329c15..bb67c799 100644
--- a/src/components/Header/DesktopHeader.tsx
+++ b/src/components/Header/DesktopHeader.tsx
@@ -9,11 +9,11 @@ import Settings from 'components/Settings'
import Wallet from 'components/Wallet'
import useStore from 'store'
-export const menuTree: { page: Page; label: string }[] = [
- { page: 'trade', label: 'Trade' },
- { page: 'lend', label: 'Earn' },
- { page: 'borrow', label: 'Borrow' },
- { page: 'portfolio', label: 'Portfolio' },
+export const menuTree: { pages: Page[]; label: string }[] = [
+ { pages: ['trade'], label: 'Trade' },
+ { pages: ['lend', 'farm'], label: 'Earn' },
+ { pages: ['borrow'], label: 'Borrow' },
+ { pages: ['portfolio'], label: 'Portfolio' },
]
export default function DesktopHeader() {
diff --git a/src/components/Modals/BorrowModal.tsx b/src/components/Modals/BorrowModal.tsx
index 141abc58..95807e92 100644
--- a/src/components/Modals/BorrowModal.tsx
+++ b/src/components/Modals/BorrowModal.tsx
@@ -207,7 +207,7 @@ function BorrowModal(props: Props) {
asset.denom,
modal.marketData?.liquidity?.amount ?? BN_ZERO,
)}
- parantheses
+ parentheses
/>
diff --git a/src/components/Modals/FundWithdraw/FundAccount.tsx b/src/components/Modals/FundWithdraw/FundAccount.tsx
index c937eeee..4d34c148 100644
--- a/src/components/Modals/FundWithdraw/FundAccount.tsx
+++ b/src/components/Modals/FundWithdraw/FundAccount.tsx
@@ -1,6 +1,7 @@
-import { useCallback, useEffect, useMemo, useState } from 'react'
+import React, { useCallback, useEffect, useMemo, useState } from 'react'
import Button from 'components/Button'
+import DepositCapMessage from 'components/DepositCapMessage'
import { ArrowRight, Plus } from 'components/Icons'
import SwitchAutoLend from 'components/Switch/SwitchAutoLend'
import Text from 'components/Text'
@@ -8,6 +9,7 @@ import TokenInputWithSlider from 'components/TokenInput/TokenInputWithSlider'
import WalletBridges from 'components/Wallet/WalletBridges'
import { BN_ZERO } from 'constants/math'
import useAutoLendEnabledAccountIds from 'hooks/useAutoLendEnabledAccountIds'
+import useMarketAssets from 'hooks/useMarketAssets'
import useToggle from 'hooks/useToggle'
import { useUpdatedAccount } from 'hooks/useUpdatedAccount'
import useWalletBalances from 'hooks/useWalletBalances'
@@ -16,6 +18,7 @@ import { BNCoin } from 'types/classes/BNCoin'
import { byDenom } from 'utils/array'
import { getAssetByDenom, getBaseAsset } from 'utils/assets'
import { defaultFee } from 'utils/constants'
+import { getCapLeftWithBuffer } from 'utils/generic'
import { BN } from 'utils/helpers'
interface Props {
@@ -38,7 +41,7 @@ export default function FundAccount(props: Props) {
const { autoLendEnabledAccountIds } = useAutoLendEnabledAccountIds()
const isAutoLendEnabled = autoLendEnabledAccountIds.includes(accountId)
const { simulateDeposits } = useUpdatedAccount(account)
-
+ const { data: marketAssets } = useMarketAssets()
const baseBalance = useMemo(
() => walletBalances.find(byDenom(baseAsset.denom))?.amount ?? '0',
[walletBalances, baseAsset],
@@ -87,16 +90,15 @@ export default function FundAccount(props: Props) {
setFundingAssets(newFundingAssets)
}, [selectedDenoms, fundingAssets])
- const updateFundingAssets = useCallback(
- (amount: BigNumber, denom: string) => {
- const assetToUpdate = fundingAssets.find(byDenom(denom))
- if (assetToUpdate) {
- assetToUpdate.amount = amount
- setFundingAssets([...fundingAssets.filter((a) => a.denom !== denom), assetToUpdate])
- }
- },
- [fundingAssets],
- )
+ const updateFundingAssets = useCallback((amount: BigNumber, denom: string) => {
+ setFundingAssets((fundingAssets) => {
+ const updateIdx = fundingAssets.findIndex(byDenom(denom))
+ if (updateIdx === -1) return fundingAssets
+
+ fundingAssets[updateIdx].amount = amount
+ return [...fundingAssets]
+ })
+ }, [])
useEffect(() => {
simulateDeposits(isAutoLendEnabled ? 'lend' : 'deposit', fundingAssets)
@@ -108,6 +110,21 @@ export default function FundAccount(props: Props) {
}
}, [baseBalance])
+ const depositCapReachedCoins = useMemo(() => {
+ const depositCapReachedCoins: BNCoin[] = []
+ fundingAssets.forEach((asset) => {
+ const marketAsset = marketAssets.find(byDenom(asset.denom))
+ if (!marketAsset) return
+
+ const capLeft = getCapLeftWithBuffer(marketAsset.cap)
+
+ if (asset.amount.isLessThanOrEqualTo(capLeft)) return
+
+ depositCapReachedCoins.push(BNCoin.fromDenomAndBigNumber(asset.denom, capLeft))
+ })
+ return depositCapReachedCoins
+ }, [fundingAssets, marketAssets])
+
return (
<>
@@ -139,6 +156,12 @@ export default function FundAccount(props: Props) {
onClick={handleSelectAssetsClick}
disabled={isFunding}
/>
+
}
- disabled={!hasFundingAssets}
+ disabled={!hasFundingAssets || depositCapReachedCoins.length > 0}
showProgressIndicator={isFunding}
onClick={handleClick}
/>
diff --git a/src/components/Modals/Vault/VaultBorrowings.tsx b/src/components/Modals/Vault/VaultBorrowings.tsx
index a3b269b5..9215e0fb 100644
--- a/src/components/Modals/Vault/VaultBorrowings.tsx
+++ b/src/components/Modals/Vault/VaultBorrowings.tsx
@@ -2,6 +2,7 @@ import BigNumber from 'bignumber.js'
import React, { useEffect, useMemo, useState } from 'react'
import Button from 'components/Button'
+import DepositCapMessage from 'components/DepositCapMessage'
import DisplayCurrency from 'components/DisplayCurrency'
import Divider from 'components/Divider'
import { ArrowRight, ExclamationMarkCircled } from 'components/Icons'
@@ -27,6 +28,7 @@ export interface VaultBorrowingsProps {
vault: Vault
depositActions: Action[]
onChangeBorrowings: (borrowings: BNCoin[]) => void
+ depositCapReachedCoins: BNCoin[]
}
export default function VaultBorrowings(props: VaultBorrowingsProps) {
@@ -187,12 +189,21 @@ export default function VaultBorrowings(props: VaultBorrowingsProps) {
)}
+
+
+
+
@@ -221,7 +232,7 @@ export default function VaultBorrowings(props: VaultBorrowingsProps) {
text='Deposit'
rightIcon={ }
showProgressIndicator={isConfirming}
- disabled={!props.depositActions.length}
+ disabled={!props.depositActions.length || props.depositCapReachedCoins.length > 0}
/>
)
diff --git a/src/components/Modals/Vault/VaultDeposits.tsx b/src/components/Modals/Vault/VaultDeposits.tsx
index 0aaa2aa8..35e0e71f 100644
--- a/src/components/Modals/Vault/VaultDeposits.tsx
+++ b/src/components/Modals/Vault/VaultDeposits.tsx
@@ -1,7 +1,7 @@
import BigNumber from 'bignumber.js'
-import { useMemo, useState } from 'react'
import Button from 'components/Button'
+import DepositCapMessage from 'components/DepositCapMessage'
import DisplayCurrency from 'components/DisplayCurrency'
import Divider from 'components/Divider'
import { Gauge } from 'components/Gauge'
@@ -12,6 +12,7 @@ import Text from 'components/Text'
import TokenInput from 'components/TokenInput'
import { BN_ZERO } from 'constants/math'
import usePrice from 'hooks/usePrice'
+import { useMemo, useState } from 'react'
import useStore from 'store'
import { BNCoin } from 'types/classes/BNCoin'
import { accumulateAmounts } from 'utils/accounts'
@@ -27,6 +28,7 @@ interface Props {
onChangeDeposits: (deposits: BNCoin[]) => void
onChangeIsCustomRatio: (isCustomRatio: boolean) => void
toggleOpen: (index: number) => void
+ depositCapReachedCoins: BNCoin[]
}
export default function VaultDeposit(props: Props) {
@@ -158,7 +160,7 @@ export default function VaultDeposit(props: Props) {
return (
-
+
+
+
+
{disableInput ? (
@@ -240,4 +250,4 @@ export default function VaultDeposit(props: Props) {
)
-}
+}
\ No newline at end of file
diff --git a/src/components/Modals/Vault/VaultModalContent.tsx b/src/components/Modals/Vault/VaultModalContent.tsx
index 1aabb11e..d2511a01 100644
--- a/src/components/Modals/Vault/VaultModalContent.tsx
+++ b/src/components/Modals/Vault/VaultModalContent.tsx
@@ -1,4 +1,4 @@
-import { useCallback, useEffect, useState } from 'react'
+import { useCallback, useEffect, useMemo, useState } from 'react'
import Accordion from 'components/Accordion'
import AccountSummary from 'components/Account/AccountSummary'
@@ -8,10 +8,14 @@ import VaultDeposit from 'components/Modals/Vault/VaultDeposits'
import VaultDepositSubTitle from 'components/Modals/Vault/VaultDepositsSubTitle'
import { BN_ZERO } from 'constants/math'
import useDepositVault from 'hooks/broadcast/useDepositVault'
+import useDisplayAsset from 'hooks/useDisplayAsset'
import useIsOpenArray from 'hooks/useIsOpenArray'
+import usePrices from 'hooks/usePrices'
import { useUpdatedAccount } from 'hooks/useUpdatedAccount'
import { BNCoin } from 'types/classes/BNCoin'
import { byDenom } from 'utils/array'
+import { convertToDisplayAmount, magnify } from 'utils/formatters'
+import { getCapLeftWithBuffer } from 'utils/generic'
interface Props {
vault: Vault | DepositedVault
@@ -29,14 +33,14 @@ export default function VaultModalContent(props: Props) {
removedDeposits,
removedLends,
removeLends,
- updatedAccount,
addVaultValues,
} = useUpdatedAccount(props.account)
+ const { data: prices } = usePrices()
const [isOpen, toggleOpen] = useIsOpenArray(2, false)
const [isCustomRatio, setIsCustomRatio] = useState(false)
const [selectedCoins, setSelectedCoins] = useState ([])
-
+ const displayAsset = useDisplayAsset()
const { actions: depositActions, totalValue } = useDepositVault({
vault: props.vault,
reclaims: removedLends,
@@ -44,6 +48,24 @@ export default function VaultModalContent(props: Props) {
borrowings: addedDebts,
})
+ const depositCapReachedCoins = useMemo(() => {
+ const capLeft = getCapLeftWithBuffer(props.vault.cap)
+
+ if (totalValue.isGreaterThan(capLeft)) {
+ const amount = magnify(
+ convertToDisplayAmount(
+ BNCoin.fromDenomAndBigNumber(props.vault.cap.denom, capLeft),
+ displayAsset.denom,
+ prices,
+ ).toString(),
+ displayAsset,
+ )
+
+ return [BNCoin.fromDenomAndBigNumber(displayAsset.denom, amount)]
+ }
+ return []
+ }, [displayAsset, prices, props.vault.cap, totalValue])
+
const handleDepositSelect = useCallback(
(selectedCoins: BNCoin[]) => {
const reclaims: BNCoin[] = []
@@ -134,6 +156,7 @@ export default function VaultModalContent(props: Props) {
toggleOpen={toggleOpen}
isCustomRatio={isCustomRatio}
onChangeIsCustomRatio={onChangeIsCustomRatio}
+ depositCapReachedCoins={depositCapReachedCoins}
/>
),
title: 'Deposit',
@@ -151,6 +174,7 @@ export default function VaultModalContent(props: Props) {
onChangeBorrowings={addDebts}
vault={props.vault}
depositActions={depositActions}
+ depositCapReachedCoins={depositCapReachedCoins}
/>
),
title: 'Borrow',
diff --git a/src/components/Navigation/DesktopNavigation.tsx b/src/components/Navigation/DesktopNavigation.tsx
index f618aecf..18bb58f1 100644
--- a/src/components/Navigation/DesktopNavigation.tsx
+++ b/src/components/Navigation/DesktopNavigation.tsx
@@ -1,5 +1,5 @@
-import { useParams } from 'react-router-dom'
import classNames from 'classnames'
+import { useParams } from 'react-router-dom'
import { menuTree } from 'components/Header/DesktopHeader'
import { Logo } from 'components/Icons'
@@ -11,8 +11,8 @@ export default function DesktopNavigation() {
const { address, accountId } = useParams()
const focusComponent = useStore((s) => s.focusComponent)
- function getIsActive(href: string) {
- return location.pathname.includes(href)
+ function getIsActive(pages: string[]) {
+ return pages.some((page) => location.pathname.includes(page))
}
return (
@@ -31,8 +31,8 @@ export default function DesktopNavigation() {
{menuTree.map((item, index) => (
{item.label}
diff --git a/src/components/Navigation/NavLink.tsx b/src/components/Navigation/NavLink.tsx
index e8378344..234dd3b3 100644
--- a/src/components/Navigation/NavLink.tsx
+++ b/src/components/Navigation/NavLink.tsx
@@ -12,12 +12,10 @@ export const NavLink = (props: Props) => {
return (
- classNames(
- 'text-sm font-semibold hover:text-white active:text-white',
- isActive ? 'pointer-events-none text-white' : 'text-white/60',
- )
- }
+ className={classNames(
+ 'text-sm font-semibold hover:text-white active:text-white',
+ props.isActive ? 'pointer-events-none text-white' : 'text-white/60',
+ )}
>
{props.children}
diff --git a/src/components/Trade/TradeModule/AssetSelector/AssetItem.tsx b/src/components/Trade/TradeModule/AssetSelector/AssetItem.tsx
index 816415f5..7883b99c 100644
--- a/src/components/Trade/TradeModule/AssetSelector/AssetItem.tsx
+++ b/src/components/Trade/TradeModule/AssetSelector/AssetItem.tsx
@@ -10,6 +10,7 @@ import { BNCoin } from 'types/classes/BNCoin'
interface Props {
asset: Asset
onSelectAsset: (asset: Asset) => void
+ depositCap?: DepositCap
}
export default function AssetItem(props: Props) {
@@ -40,11 +41,24 @@ export default function AssetItem(props: Props) {
{asset.isFavorite ? : }
-
- {asset.name}
-
-
- {asset.symbol}
+
+
+
+ {asset.name}
+
+
+ {asset.symbol}
+
+
+ {props.depositCap && (
+
+ Cap Left:
+
+
+ )}
))}
diff --git a/src/components/Trade/TradeModule/SwapForm/OrderTypeSelector/index.tsx b/src/components/Trade/TradeModule/SwapForm/OrderTypeSelector/index.tsx
index 387c55bc..dac4c81b 100644
--- a/src/components/Trade/TradeModule/SwapForm/OrderTypeSelector/index.tsx
+++ b/src/components/Trade/TradeModule/SwapForm/OrderTypeSelector/index.tsx
@@ -4,8 +4,8 @@ import { InfoCircle } from 'components/Icons'
import Text from 'components/Text'
import { Tooltip } from 'components/Tooltip'
import { ORDER_TYPE_TABS } from 'components/Trade/TradeModule/SwapForm/OrderTypeSelector/constants'
-import ConditionalWrapper from 'hocs/ConditionalWrapper'
import { AvailableOrderType } from 'components/Trade/TradeModule/SwapForm/OrderTypeSelector/types'
+import ConditionalWrapper from 'hocs/ConditionalWrapper'
interface Props {
selected: AvailableOrderType
@@ -46,9 +46,9 @@ export default function OrderTypeSelector(props: Props) {
}
const className = {
- wrapper: 'flex flex-1 flex-row px-3 pt-3',
+ wrapper: 'flex flex-1 flex-row px-3 pt-4',
tab: 'mr-4 pb-2 cursor-pointer select-none flex flex-row',
selectedTab: 'border-b-2 border-pink border-solid',
- disabledTab: 'opacity-50 pointer-events-none',
+ disabledTab: 'opacity-20 pointer-events-none',
infoCircle: 'w-4 h-4 ml-2 mt-1',
}
diff --git a/src/components/Trade/TradeModule/SwapForm/index.tsx b/src/components/Trade/TradeModule/SwapForm/index.tsx
index 82a2a6e7..8ae945e9 100644
--- a/src/components/Trade/TradeModule/SwapForm/index.tsx
+++ b/src/components/Trade/TradeModule/SwapForm/index.tsx
@@ -2,6 +2,7 @@ import debounce from 'lodash.debounce'
import { useCallback, useEffect, useMemo, useState } from 'react'
import estimateExactIn from 'api/swap/estimateExactIn'
+import DepositCapMessage from 'components/DepositCapMessage'
import Divider from 'components/Divider'
import RangeInput from 'components/RangeInput'
import AssetAmountInput from 'components/Trade/TradeModule/SwapForm/AssetAmountInput'
@@ -16,6 +17,7 @@ import useAutoLendEnabledAccountIds from 'hooks/useAutoLendEnabledAccountIds'
import useCurrentAccount from 'hooks/useCurrentAccount'
import useHealthComputer from 'hooks/useHealthComputer'
import useLocalStorage from 'hooks/useLocalStorage'
+import useMarketAssets from 'hooks/useMarketAssets'
import useMarketBorrowings from 'hooks/useMarketBorrowings'
import usePrices from 'hooks/usePrices'
import useToggle from 'hooks/useToggle'
@@ -24,6 +26,7 @@ import useStore from 'store'
import { BNCoin } from 'types/classes/BNCoin'
import { byDenom } from 'utils/array'
import { defaultFee } from 'utils/constants'
+import { getCapLeftWithBuffer } from 'utils/generic'
import { asyncThrottle, BN } from 'utils/helpers'
interface Props {
@@ -39,6 +42,7 @@ export default function SwapForm(props: Props) {
const [slippage] = useLocalStorage(SLIPPAGE_KEY, DEFAULT_SETTINGS.slippage)
const { computeMaxSwapAmount } = useHealthComputer(account)
const { data: borrowAssets } = useMarketBorrowings()
+ const { data: marketAssets } = useMarketAssets()
const [isMarginChecked, setMarginChecked] = useToggle()
const [buyAssetAmount, setBuyAssetAmount] = useState(BN_ZERO)
@@ -58,6 +62,19 @@ export default function SwapForm(props: Props) {
[borrowAssets, sellAsset.denom],
)
+ const depositCapReachedCoins: BNCoin[] = useMemo(() => {
+ const buyMarketAsset = marketAssets.find(byDenom(buyAsset.denom))
+
+ if (!buyMarketAsset) return []
+
+ const depositCapLeft = getCapLeftWithBuffer(buyMarketAsset.cap)
+ if (buyAssetAmount.isGreaterThan(depositCapLeft)) {
+ return [BNCoin.fromDenomAndBigNumber(buyAsset.denom, depositCapLeft)]
+ }
+
+ return []
+ }, [marketAssets, buyAsset.denom, buyAssetAmount])
+
const onChangeSellAmount = useCallback(
(amount: BigNumber) => {
setSellAssetAmount(amount)
@@ -233,59 +250,59 @@ export default function SwapForm(props: Props) {
/>
-
+
+
-
+
-
+
-
+
+
+ 0}
+ showProgressIndicator={isConfirming}
+ isMargin={isMarginChecked}
+ borrowAmount={
+ sellAssetAmount.isGreaterThan(sellSideMarginThreshold)
+ ? sellAssetAmount.minus(sellSideMarginThreshold)
+ : BN_ZERO
+ }
+ estimatedFee={estimatedFee}
+ />
+
>
)
}
diff --git a/src/hooks/useDisplayAsset.tsx b/src/hooks/useDisplayAsset.tsx
new file mode 100644
index 00000000..e8eee0a8
--- /dev/null
+++ b/src/hooks/useDisplayAsset.tsx
@@ -0,0 +1,14 @@
+import { ASSETS } from 'constants/assets'
+import { DEFAULT_SETTINGS } from 'constants/defaultSettings'
+import { DISPLAY_CURRENCY_KEY } from 'constants/localStore'
+import useLocalStorage from 'hooks/useLocalStorage'
+import { byDenom } from 'utils/array'
+
+export default function useDisplayAsset() {
+ const [displayCurrency] = useLocalStorage(
+ DISPLAY_CURRENCY_KEY,
+ DEFAULT_SETTINGS.displayCurrency,
+ )
+
+ return ASSETS.find(byDenom(displayCurrency)) ?? ASSETS[0]
+}
diff --git a/src/hooks/useHealthComputer.tsx b/src/hooks/useHealthComputer.tsx
index c2eac166..44ac0141 100644
--- a/src/hooks/useHealthComputer.tsx
+++ b/src/hooks/useHealthComputer.tsx
@@ -15,6 +15,7 @@ import {
HealthComputer,
} from 'types/generated/mars-rover-health-computer/MarsRoverHealthComputer.types'
import { convertAccountToPositions } from 'utils/accounts'
+import { LTV_BUFFER } from 'utils/constants'
import {
BorrowTarget,
compute_health_js,
@@ -24,7 +25,6 @@ import {
SwapKind,
} from 'utils/health_computer'
import { BN } from 'utils/helpers'
-import { LTV_BUFFER } from 'utils/constants'
export default function useHealthComputer(account?: Account) {
const { data: prices } = usePrices()
diff --git a/src/hooks/useLendingMarketAssetsTableData.ts b/src/hooks/useLendingMarketAssetsTableData.ts
index f0a5bede..2333d090 100644
--- a/src/hooks/useLendingMarketAssetsTableData.ts
+++ b/src/hooks/useLendingMarketAssetsTableData.ts
@@ -23,7 +23,7 @@ function useLendingMarketAssetsTableData(): {
const accountLentAssets: LendingMarketTableData[] = [],
availableAssets: LendingMarketTableData[] = []
- markets.forEach(({ denom, depositCap, liquidityRate, liquidationThreshold, maxLtv }) => {
+ markets.forEach(({ denom, cap, liquidityRate, liquidationThreshold, maxLtv }) => {
const asset = getAssetByDenom(denom) as Asset
const marketDepositAmount = BN(marketDeposits.find(byDenom(denom))?.amount ?? 0)
const marketLiquidityAmount = BN(marketLiquidities.find(byDenom(denom))?.amount ?? 0)
@@ -38,7 +38,7 @@ function useLendingMarketAssetsTableData(): {
accountLentValue,
accountLentAmount,
marketLiquidityAmount,
- marketDepositCap: BN(depositCap),
+ marketDepositCap: cap.max,
marketLiquidityRate: liquidityRate,
marketLiquidationThreshold: liquidationThreshold,
marketMaxLtv: maxLtv,
diff --git a/src/types/interfaces/asset.d.ts b/src/types/interfaces/asset.d.ts
index 4607252a..98cab30c 100644
--- a/src/types/interfaces/asset.d.ts
+++ b/src/types/interfaces/asset.d.ts
@@ -49,10 +49,6 @@ interface PseudoAsset {
symbol: string
}
-interface OtherAsset extends Omit {
- symbol: 'MARS'
-}
-
interface BorrowAsset extends Asset {
borrowRate: number | null
liquidity: {
diff --git a/src/types/interfaces/market.d.ts b/src/types/interfaces/market.d.ts
index e158f412..d6e5523b 100644
--- a/src/types/interfaces/market.d.ts
+++ b/src/types/interfaces/market.d.ts
@@ -5,7 +5,7 @@ interface Market {
collateralTotalScaled: string
depositEnabled: boolean
borrowEnabled: boolean
- depositCap: string
+ cap: DepositCap
maxLtv: number
liquidityRate: number
liquidationThreshold: number
diff --git a/src/types/interfaces/vaults.d.ts b/src/types/interfaces/vaults.d.ts
index d98416b2..c8ed0f5a 100644
--- a/src/types/interfaces/vaults.d.ts
+++ b/src/types/interfaces/vaults.d.ts
@@ -26,11 +26,7 @@ interface VaultInfo {
max: number
liq: number
}
- cap: {
- denom: string
- used: BigNumber
- max: BigNumber
- }
+ cap: DepositCap
}
interface VaultConfig extends VaultMetaData, VaultInfo {}
@@ -74,3 +70,9 @@ interface VaultPositionFlatAmounts {
unlocking: BigNumber
unlocked: BigNumber
}
+
+interface DepositCap {
+ denom: string
+ used: BigNumber
+ max: BigNumber
+}
diff --git a/src/utils/constants.ts b/src/utils/constants.ts
index 7b82e94d..45708df4 100644
--- a/src/utils/constants.ts
+++ b/src/utils/constants.ts
@@ -11,3 +11,5 @@ export const defaultFee: StdFee = {
export const SECONDS_IN_A_YEAR = 31540000
export const LTV_BUFFER = 0.01
+
+export const DEPOSIT_CAP_BUFFER = 0.999
diff --git a/src/utils/generic.ts b/src/utils/generic.ts
new file mode 100644
index 00000000..682a4033
--- /dev/null
+++ b/src/utils/generic.ts
@@ -0,0 +1,5 @@
+import { DEPOSIT_CAP_BUFFER } from 'utils/constants'
+
+export function getCapLeftWithBuffer(cap: DepositCap) {
+ return cap.max.minus(cap.used).times(DEPOSIT_CAP_BUFFER).integerValue()
+}
diff --git a/src/utils/resolvers.ts b/src/utils/resolvers.ts
index 5a69b2e8..cdb7e9c8 100644
--- a/src/utils/resolvers.ts
+++ b/src/utils/resolvers.ts
@@ -1,9 +1,14 @@
+import {
+ AssetParamsBaseForAddr as AssetParams,
+ TotalDepositResponse,
+} from 'types/generated/mars-params/MarsParams.types'
import { Market as RedBankMarket } from 'types/generated/mars-red-bank/MarsRedBank.types'
-import { AssetParamsBaseForAddr as AssetParams } from 'types/generated/mars-params/MarsParams.types'
+import { BN } from 'utils/helpers'
export function resolveMarketResponse(
marketResponse: RedBankMarket,
assetParamsResponse: AssetParams,
+ assetCapResponse: TotalDepositResponse,
): Market {
return {
denom: marketResponse.denom,
@@ -12,7 +17,11 @@ export function resolveMarketResponse(
collateralTotalScaled: marketResponse.collateral_total_scaled,
depositEnabled: assetParamsResponse.red_bank.deposit_enabled,
borrowEnabled: assetParamsResponse.red_bank.borrow_enabled,
- depositCap: assetParamsResponse.deposit_cap,
+ cap: {
+ denom: assetCapResponse.denom,
+ used: BN(assetCapResponse.amount),
+ max: BN(assetParamsResponse.deposit_cap),
+ },
maxLtv: Number(assetParamsResponse.max_loan_to_value),
liquidityRate: Number(marketResponse.liquidity_rate),
liquidationThreshold: Number(assetParamsResponse.liquidation_threshold),
|