-
-
+ cell: ({ row }) => {
+ if (props.isLoading) return
+
+ return (
+
-
- ),
+ )
+ },
},
- ],
- [],
- )
+ ]
+ }, [baseCurrency.denom, props.data, props.isLoading])
const table = useReactTable({
data: props.data,
- columns,
+ columns: columns,
state: {
sorting,
},
@@ -122,7 +164,7 @@ export const VaultTable = (props: Props) => {
diff --git a/src/components/Earn/vault/Vaults.tsx b/src/components/Earn/vault/Vaults.tsx
new file mode 100644
index 00000000..9d299349
--- /dev/null
+++ b/src/components/Earn/vault/Vaults.tsx
@@ -0,0 +1,78 @@
+import { Suspense, useMemo } from 'react'
+import { useParams } from 'react-router-dom'
+
+import Card from 'components/Card'
+import { VaultTable } from 'components/Earn/vault/VaultTable'
+import { IS_TESTNET } from 'constants/env'
+import { TESTNET_VAULTS_META_DATA, VAULTS_META_DATA } from 'constants/vaults'
+import useVaults from 'hooks/useVaults'
+import useDepositedVaults from 'hooks/useDepositedVaults'
+import { BN } from 'utils/helpers'
+
+interface Props {
+ type: 'available' | 'deposited'
+}
+
+function Content(props: Props) {
+ const { accountId } = useParams()
+ const { data: vaults } = useVaults()
+ const { data: depositedVaults } = useDepositedVaults(accountId || '')
+
+ const vaultsMetaData = IS_TESTNET ? TESTNET_VAULTS_META_DATA : VAULTS_META_DATA
+
+ const { deposited, available } = useMemo(() => {
+ return vaultsMetaData.reduce(
+ (prev: { deposited: DepositedVault[]; available: Vault[] }, curr) => {
+ const vault = vaults.find((vault) => vault.address === curr.address)
+ const depositedVault = depositedVaults?.find((vault) => vault.address === curr.address)
+
+ if (depositedVault) {
+ prev.deposited.push(depositedVault)
+ } else if (vault) {
+ prev.available.push(vault)
+ }
+
+ return prev
+ },
+ { deposited: [], available: [] },
+ )
+ }, [vaults, depositedVaults, vaultsMetaData])
+
+ const vaultsToDisplay = props.type === 'available' ? available : deposited
+
+ if (!vaultsToDisplay.length) return null
+
+ return
+}
+
+export default function Vaults(props: Props) {
+ return (
+
+ : null}>
+
+
+
+ )
+}
+
+function Fallback() {
+ const vaults = IS_TESTNET ? TESTNET_VAULTS_META_DATA : VAULTS_META_DATA
+ const mockVaults: Vault[] = vaults.map((vault) => ({
+ ...vault,
+ apy: null,
+ ltv: {
+ max: 0,
+ liq: 0,
+ },
+ cap: {
+ denom: 'denom',
+ used: BN(0),
+ max: BN(0),
+ },
+ }))
+
+ return
+}
diff --git a/src/components/Modals/LendAndReclaim/DetailsHeader.tsx b/src/components/Modals/LendAndReclaim/DetailsHeader.tsx
index dd771ce5..ee700da5 100644
--- a/src/components/Modals/LendAndReclaim/DetailsHeader.tsx
+++ b/src/components/Modals/LendAndReclaim/DetailsHeader.tsx
@@ -3,6 +3,7 @@ import TitleAndSubCell from 'components/TitleAndSubCell'
import { FormattedNumber } from 'components/FormattedNumber'
import useAssetIncentivesApy from 'hooks/useAssetIncentiveApy'
import useCurrentWalletBalance from 'hooks/useCurrentWalletBalance'
+import { BNCoin } from 'types/classes/BNCoin'
interface Props {
data: LendingMarketTableData
@@ -36,7 +37,11 @@ function DetailsHeader({ data }: Props) {
{accountLentAmount && (
<>
}
+ title={
+
+ }
sub={'Deposited'}
/>
@@ -44,13 +49,18 @@ function DetailsHeader({ data }: Props) {
)}
{balanceInWallet && (
<>
-
} sub={'In Wallet'} />
+
}
+ sub={'In Wallet'}
+ />
>
)}
+
}
sub={'Deposit Cap'}
/>
diff --git a/src/components/Modals/Vault/VaultBorrowings.tsx b/src/components/Modals/Vault/VaultBorrowings.tsx
index 64efdb96..c5c068c5 100644
--- a/src/components/Modals/Vault/VaultBorrowings.tsx
+++ b/src/components/Modals/Vault/VaultBorrowings.tsx
@@ -43,8 +43,8 @@ export default function VaultBorrowings(props: VaultBorrowingsProps) {
const { actions: depositActions, fee: depositFee } = useDepositVault({
vault: props.vault,
- deposits: props.deposits.filter((borrowing) => borrowing.amount.gt(0)),
- borrowings: props.borrowings.filter((borrowing) => borrowing.amount.gt(0)),
+ deposits: props.deposits,
+ borrowings: props.borrowings,
})
const primaryValue = useMemo(
@@ -189,7 +189,9 @@ export default function VaultBorrowings(props: VaultBorrowingsProps) {
{`${props.primaryAsset.symbol}-${props.secondaryAsset.symbol} Position Value`}
-
+
{props.borrowings.map((coin) => {
const asset = getAssetByDenom(coin.denom)
diff --git a/src/components/Modals/Vault/VaultBorrowingsSubTitle.tsx b/src/components/Modals/Vault/VaultBorrowingsSubTitle.tsx
index ff347dc5..d2e17286 100644
--- a/src/components/Modals/Vault/VaultBorrowingsSubTitle.tsx
+++ b/src/components/Modals/Vault/VaultBorrowingsSubTitle.tsx
@@ -40,7 +40,7 @@ export default function VaultDepositSubTitle(props: Props) {
<>
{` = `}
>
)}
diff --git a/src/components/Modals/Vault/VaultDeposits.tsx b/src/components/Modals/Vault/VaultDeposits.tsx
index 77b097ac..6386cbb4 100644
--- a/src/components/Modals/Vault/VaultDeposits.tsx
+++ b/src/components/Modals/Vault/VaultDeposits.tsx
@@ -14,6 +14,7 @@ import { getAmount } from 'utils/accounts'
import { BN } from 'utils/helpers'
import { Gauge } from 'components/Gauge'
import useStore from 'store'
+import { BNCoin } from 'types/classes/BNCoin'
interface Props {
primaryAmount: BigNumber
@@ -204,7 +205,9 @@ export default function VaultDeposit(props: Props) {
{`${props.primaryAsset.symbol}-${props.secondaryAsset.symbol} Deposit Value`}
-
+
)
diff --git a/src/components/TitleAndSubCell.tsx b/src/components/TitleAndSubCell.tsx
index 0ce5d78d..29834a58 100644
--- a/src/components/TitleAndSubCell.tsx
+++ b/src/components/TitleAndSubCell.tsx
@@ -12,10 +12,10 @@ interface Props {
export default function TitleAndSubCell(props: Props) {
return (
-
+
{props.title}
-
+
{props.sub}
diff --git a/src/components/Wallet/ConnectedButton.tsx b/src/components/Wallet/ConnectedButton.tsx
index 0ee1c4b4..de234544 100644
--- a/src/components/Wallet/ConnectedButton.tsx
+++ b/src/components/Wallet/ConnectedButton.tsx
@@ -72,7 +72,7 @@ export default function ConnectedButton() {
const assetDenoms = marketAssets.map((asset) => asset.denom)
const balances = walletBalances.filter((coin) => assetDenoms.includes(coin.denom))
useStore.setState({ balances })
- }, [walletBalances, baseAsset.denom, baseAsset.decimals, marketAssets])
+ }, [walletBalances, baseAsset.denom, baseAsset.decimals, marketAssets, walletAmount])
return (
diff --git a/src/hooks/broadcast/useDepositVault.ts b/src/hooks/broadcast/useDepositVault.ts
index 018d1678..9580a24b 100644
--- a/src/hooks/broadcast/useDepositVault.ts
+++ b/src/hooks/broadcast/useDepositVault.ts
@@ -27,7 +27,13 @@ export default function useDepositVault(props: Props): { actions: Action[]; fee:
const debouncedGetMinLpToReceive = useMemo(() => debounce(getMinLpToReceive, 500), [])
const { primaryCoin, secondaryCoin, totalValue } = useMemo(
- () => getVaultDepositCoinsAndValue(props.vault, props.deposits, props.borrowings, prices),
+ () =>
+ getVaultDepositCoinsAndValue(
+ props.vault,
+ props.deposits.filter((borrowing) => borrowing.amount.gt(0)),
+ props.borrowings.filter((borrowing) => borrowing.amount.gt(0)),
+ prices,
+ ),
[props.deposits, props.borrowings, props.vault, prices],
)
@@ -41,8 +47,8 @@ export default function useDepositVault(props: Props): { actions: Action[]; fee:
() =>
getVaultSwapActions(
props.vault,
- props.deposits,
- props.borrowings,
+ props.deposits.filter((borrowing) => borrowing.amount.gt(0)),
+ props.borrowings.filter((borrowing) => borrowing.amount.gt(0)),
prices,
slippage,
totalValue,
@@ -56,9 +62,10 @@ export default function useDepositVault(props: Props): { actions: Action[]; fee:
const lpAmount = await debouncedGetMinLpToReceive(
[secondaryCoin.toCoin(), primaryCoin.toCoin()],
props.vault.denoms.lp,
+ slippage,
)
- if (!lpAmount || lpAmount === minLpToReceive) return
+ if (!lpAmount || lpAmount.eq(minLpToReceive)) return
setMinLpToReceive(lpAmount)
}, [
primaryCoin,
@@ -66,6 +73,7 @@ export default function useDepositVault(props: Props): { actions: Action[]; fee:
props.vault.denoms.lp,
debouncedGetMinLpToReceive,
minLpToReceive,
+ slippage,
])
const enterVaultActions: Action[] = useMemo(() => {
diff --git a/src/hooks/useMinLpToReceive.tsx b/src/hooks/useMinLpToReceive.tsx
deleted file mode 100644
index 05f4cdd3..00000000
--- a/src/hooks/useMinLpToReceive.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import useSWR from 'swr'
-
-import getMinLpToReceive from 'api/vaults/getMinLpToReceive'
-import { BN } from 'utils/helpers'
-
-export default function useMinLpToReceive(coins: Coin[], lpDenom: string) {
- return useSWR(
- `minLpToReceive-${JSON.stringify(coins)}`,
- () => getMinLpToReceive(coins, lpDenom),
- {
- fallbackData: BN(0),
- },
- )
-}
diff --git a/src/hooks/usePrices.tsx b/src/hooks/usePrices.tsx
index 0352e5d6..fd3b422c 100644
--- a/src/hooks/usePrices.tsx
+++ b/src/hooks/usePrices.tsx
@@ -1,12 +1,10 @@
import useSWR from 'swr'
import getPrices from 'api/prices/getPrices'
-import useStore from 'store'
export default function usePrices() {
return useSWR('prices', getPrices, {
fallbackData: [],
refreshInterval: 30000,
- onSuccess: (prices) => useStore.setState({ prices }),
})
}
diff --git a/src/pages/FarmPage.tsx b/src/pages/FarmPage.tsx
index 909dc0f2..51bab381 100644
--- a/src/pages/FarmPage.tsx
+++ b/src/pages/FarmPage.tsx
@@ -1,13 +1,13 @@
-import AvailableVaults from 'components/Earn/vault/AvailableVaults'
-import FeaturedVaults from 'components/Earn/vault/FeaturedVaults'
import Tab from 'components/Earn/Tab'
+import Vaults from 'components/Earn/vault/Vaults'
export default function FarmPage() {
return (
<>
-
-
+ {/*
*/}
+
+
>
)
}
diff --git a/src/store/slices/broadcast.ts b/src/store/slices/broadcast.ts
index f9db9a59..a79a8ddf 100644
--- a/src/store/slices/broadcast.ts
+++ b/src/store/slices/broadcast.ts
@@ -136,20 +136,8 @@ export default function createBroadcastSlice(
},
}
const response = await get().executeMsg({ msg, fee: options.fee })
- if (response.result) {
- set({
- toast: {
- message: `Deposited into vault`,
- },
- })
- } else {
- set({
- toast: {
- message: response.error ?? `Transaction failed: ${response.error}`,
- isError: true,
- },
- })
- }
+
+ handleResponseMessages(response, `Deposited into vault`)
return !!response.result
},
withdraw: async (options: { fee: StdFee; accountId: string; coin: Coin }) => {
diff --git a/src/store/slices/currency.ts b/src/store/slices/currency.ts
index adc30e51..a083c967 100644
--- a/src/store/slices/currency.ts
+++ b/src/store/slices/currency.ts
@@ -9,6 +9,5 @@ export default function createCurrencySlice(
return {
baseCurrency: ASSETS[0],
displayCurrency: ASSETS.find((asset) => asset.denom === ASSETS[0].denom)!,
- prices: [],
}
}
diff --git a/src/types/interfaces/store/currency.d.ts b/src/types/interfaces/store/currency.d.ts
index 3bdad516..42a4f260 100644
--- a/src/types/interfaces/store/currency.d.ts
+++ b/src/types/interfaces/store/currency.d.ts
@@ -1,5 +1,4 @@
interface CurrencySlice {
baseCurrency: Asset
displayCurrency: Asset
- prices: Coin[]
}
diff --git a/src/types/interfaces/vaults.d.ts b/src/types/interfaces/vaults.d.ts
index 098c1e0b..6dc4e884 100644
--- a/src/types/interfaces/vaults.d.ts
+++ b/src/types/interfaces/vaults.d.ts
@@ -27,8 +27,8 @@ interface VaultInfo {
}
cap: {
denom: string
- used: number
- max: number
+ used: BigNumber
+ max: BigNumber
}
}
diff --git a/src/utils/constants.ts b/src/utils/constants.ts
index 493820fa..3819e4cb 100644
--- a/src/utils/constants.ts
+++ b/src/utils/constants.ts
@@ -7,7 +7,7 @@ export const hardcodedFee = {
amount: '100000',
},
],
- gas: '5000000',
+ gas: '10000000',
}
export const SECONDS_IN_A_YEAR = 31540000
diff --git a/src/utils/formatters.ts b/src/utils/formatters.ts
index 62818f85..1bf7df5e 100644
--- a/src/utils/formatters.ts
+++ b/src/utils/formatters.ts
@@ -156,11 +156,7 @@ export function demagnify(amount: number | string | BigNumber, asset: Asset) {
return value.isZero() ? 0 : value.shiftedBy(-1 * asset.decimals).toNumber()
}
-export function convertToDisplayAmount(
- coin: BNCoin | Coin,
- displayCurrency: Asset,
- prices: Coin[],
-) {
+export function convertToDisplayAmount(coin: BNCoin, displayCurrency: Asset, prices: Coin[]) {
const price = prices.find((price) => price.denom === coin.denom)
const asset = getEnabledMarketAssets().find((asset) => asset.denom === coin.denom)
const displayPrice = prices.find((price) => price.denom === displayCurrency.denom)
diff --git a/src/utils/resolvers.ts b/src/utils/resolvers.ts
index e2ac99bc..047d724b 100644
--- a/src/utils/resolvers.ts
+++ b/src/utils/resolvers.ts
@@ -1,3 +1,4 @@
+import { BNCoin } from 'types/classes/BNCoin'
import { Positions as CreditManagerPosition } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
import { Market as RedBankMarket } from 'types/generated/mars-mock-red-bank/MarsMockRedBank.types'
@@ -8,9 +9,9 @@ export function resolvePositionResponses(responses: CreditManagerPosition[]): Ac
export function resolvePositionResponse(response: CreditManagerPosition): Account {
return {
id: response.account_id,
- deposits: response.deposits,
- debts: response.debts,
- lends: response.lends,
+ debts: response.debts.map((debt) => new BNCoin(debt)),
+ lends: response.lends.map((lend) => new BNCoin(lend)),
+ deposits: response.deposits.map((deposit) => new BNCoin(deposit)),
vaults: response.vaults,
}
}
diff --git a/src/utils/vaults.ts b/src/utils/vaults.ts
index 7cb79352..b958fe35 100644
--- a/src/utils/vaults.ts
+++ b/src/utils/vaults.ts
@@ -49,14 +49,14 @@ export function getVaultDepositCoinsAndValue(
return prev.plus(bnCoin.amount.times(price))
}, BN(0))
- const primaryDepositAmount = getTokenPrice(vault.denoms.primary, prices)
- .times(totalValue)
- .div(2)
+ const halfValue = totalValue.div(2)
+
+ const primaryDepositAmount = halfValue
+ .div(getTokenPrice(vault.denoms.primary, prices))
.integerValue()
- const secondaryDepositAmount = getTokenPrice(vault.denoms.secondary, prices)
- .times(totalValue)
- .div(2)
+ const secondaryDepositAmount = halfValue
+ .div(getTokenPrice(vault.denoms.secondary, prices))
.integerValue()
return {