+
{props.title}
diff --git a/src/hocs/ConditionalWrapper.tsx b/src/hocs/ConditionalWrapper.tsx
new file mode 100644
index 00000000..a80edad4
--- /dev/null
+++ b/src/hocs/ConditionalWrapper.tsx
@@ -0,0 +1,10 @@
+interface Props {
+ condition: boolean
+ wrapper: (children: JSX.Element) => JSX.Element
+ children: JSX.Element
+}
+
+const ConditionalWrapper = ({ condition, wrapper, children }: Props) =>
+ condition ? wrapper(children) : children
+
+export default ConditionalWrapper
diff --git a/src/hooks/useCurrentAccountDeposits.ts b/src/hooks/useCurrentAccountDeposits.ts
new file mode 100644
index 00000000..1b8c5c24
--- /dev/null
+++ b/src/hooks/useCurrentAccountDeposits.ts
@@ -0,0 +1,6 @@
+import useCurrentAccount from 'hooks/useCurrentAccount'
+
+export default function useCurrentAccountDeposits() {
+ const account = useCurrentAccount()
+ return account?.deposits ?? []
+}
diff --git a/src/hooks/useDepositEnabledMarkets.ts b/src/hooks/useDepositEnabledMarkets.ts
new file mode 100644
index 00000000..6a6a7522
--- /dev/null
+++ b/src/hooks/useDepositEnabledMarkets.ts
@@ -0,0 +1,6 @@
+import useMarketAssets from 'hooks/useMarketAssets'
+
+export default function useDepositEnabledMarkets() {
+ const { data: markets } = useMarketAssets()
+ return markets.filter((market) => market.depositEnabled)
+}
diff --git a/src/hooks/useDisplayCurrencyPrice.ts b/src/hooks/useDisplayCurrencyPrice.ts
new file mode 100644
index 00000000..e18465d6
--- /dev/null
+++ b/src/hooks/useDisplayCurrencyPrice.ts
@@ -0,0 +1,39 @@
+import { useCallback } from 'react'
+
+import useStore from 'store'
+import { BN } from 'utils/helpers'
+import { byDenom } from 'utils/array'
+import usePrices from 'hooks/usePrices'
+
+function useDisplayCurrencyPrice() {
+ const { data: prices } = usePrices()
+ const displayCurrency = useStore((s) => s.displayCurrency)
+
+ const getConversionRate = useCallback(
+ (denom: string) => {
+ const assetPrice = prices.find(byDenom(denom))
+ const displayCurrencyPrice = prices.find(byDenom(displayCurrency.denom))
+
+ if (assetPrice && displayCurrencyPrice) {
+ return BN(assetPrice.amount).div(displayCurrencyPrice.amount)
+ } else {
+ throw 'Given denom or display currency price has not found'
+ }
+ },
+ [prices, displayCurrency],
+ )
+
+ const convertAmount = useCallback(
+ (asset: Asset, amount: string | number | BigNumber) =>
+ getConversionRate(asset.denom).multipliedBy(BN(amount).shiftedBy(-asset.decimals)),
+ [getConversionRate],
+ )
+
+ return {
+ getConversionRate,
+ convertAmount,
+ symbol: displayCurrency.symbol,
+ }
+}
+
+export default useDisplayCurrencyPrice
diff --git a/src/hooks/useLendingMarketAssetsTableData.ts b/src/hooks/useLendingMarketAssetsTableData.ts
new file mode 100644
index 00000000..400e23ef
--- /dev/null
+++ b/src/hooks/useLendingMarketAssetsTableData.ts
@@ -0,0 +1,56 @@
+import { useMemo } from 'react'
+
+import { BN } from 'utils/helpers'
+import { byDenom } from 'utils/array'
+import { getAssetByDenom } from 'utils/assets'
+import useMarketDeposits from 'hooks/useMarketDeposits'
+import useMarketLiquidities from 'hooks/useMarketLiquidities'
+import useDisplayCurrencyPrice from 'hooks/useDisplayCurrencyPrice'
+import useDepositEnabledMarkets from 'hooks/useDepositEnabledMarkets'
+import useCurrentAccountDeposits from 'hooks/useCurrentAccountDeposits'
+
+function useLendingMarketAssetsTableData(): {
+ lentAssets: LendingMarketTableData[]
+ availableAssets: LendingMarketTableData[]
+} {
+ const markets = useDepositEnabledMarkets()
+ const accountDeposits = useCurrentAccountDeposits()
+ // TODO: replace market deposits with account.lends when credit manager contract has lend feature
+ const { data: marketDeposits } = useMarketDeposits()
+ const { data: marketLiquidities } = useMarketLiquidities()
+ const { convertAmount } = useDisplayCurrencyPrice()
+
+ return useMemo(() => {
+ const lentAssets: LendingMarketTableData[] = [],
+ availableAssets: LendingMarketTableData[] = []
+
+ markets.forEach(({ denom, depositCap, 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)
+ const accountDepositAmount = accountDeposits.find(byDenom(denom))?.amount
+ const accountDepositValue = accountDepositAmount
+ ? convertAmount(asset, accountDepositAmount)
+ : undefined
+
+ const lendingMarketAsset: LendingMarketTableData = {
+ asset,
+ marketDepositAmount,
+ accountDepositValue,
+ marketLiquidityAmount,
+ marketDepositCap: BN(depositCap),
+ marketLiquidityRate: liquidityRate,
+ marketLiquidationThreshold: liquidationThreshold,
+ marketMaxLtv: maxLtv,
+ }
+
+ ;(lendingMarketAsset.accountDepositValue ? lentAssets : availableAssets).push(
+ lendingMarketAsset,
+ )
+ })
+
+ return { lentAssets, availableAssets }
+ }, [markets, marketDeposits, marketLiquidities, accountDeposits, convertAmount])
+}
+
+export default useLendingMarketAssetsTableData
diff --git a/src/hooks/useMarketAssets.tsx b/src/hooks/useMarketAssets.ts
similarity index 100%
rename from src/hooks/useMarketAssets.tsx
rename to src/hooks/useMarketAssets.ts
diff --git a/src/hooks/useMarketDeposits.ts b/src/hooks/useMarketDeposits.ts
new file mode 100644
index 00000000..1d4a021d
--- /dev/null
+++ b/src/hooks/useMarketDeposits.ts
@@ -0,0 +1,10 @@
+import useSWR from 'swr'
+
+import getMarketDeposits from 'api/markets/getMarketDeposits'
+
+export default function useMarketDeposits() {
+ return useSWR(`marketDeposits`, getMarketDeposits, {
+ suspense: true,
+ fallbackData: [],
+ })
+}
diff --git a/src/hooks/useMarketLiquidities.ts b/src/hooks/useMarketLiquidities.ts
new file mode 100644
index 00000000..d6d2bdca
--- /dev/null
+++ b/src/hooks/useMarketLiquidities.ts
@@ -0,0 +1,10 @@
+import useSWR from 'swr'
+
+import getMarketLiquidities from 'api/markets/getMarketLiquidities'
+
+export default function useMarketLiquidities() {
+ return useSWR(`marketLiquidities`, getMarketLiquidities, {
+ suspense: true,
+ fallbackData: [],
+ })
+}
diff --git a/src/pages/LendPage.tsx b/src/pages/LendPage.tsx
index 95f7a6da..08b87294 100644
--- a/src/pages/LendPage.tsx
+++ b/src/pages/LendPage.tsx
@@ -1,13 +1,15 @@
-import Card from 'components/Card'
import Tab from 'components/Earn/Tab'
+import LendingMarketsTable from 'components/Earn/Lend/LendingMarketsTable'
+import useLendingMarketAssetsTableData from 'hooks/useLendingMarketAssetsTableData'
export default function LendPage() {
+ const { lentAssets, availableAssets } = useLendingMarketAssetsTableData()
+
return (
<>
-
- <>>
-
+
+
>
)
}
diff --git a/src/types/interfaces/asset.d.ts b/src/types/interfaces/asset.d.ts
index 1040863e..1a8085a6 100644
--- a/src/types/interfaces/asset.d.ts
+++ b/src/types/interfaces/asset.d.ts
@@ -36,3 +36,14 @@ interface BigNumberCoin {
denom: string
amount: BigNumber
}
+
+interface LendingMarketTableData {
+ asset: Asset
+ marketMaxLtv: number
+ marketLiquidityRate: number
+ marketDepositCap: BigNumber
+ marketDepositAmount: BigNumber
+ accountDepositValue?: BigNumber
+ marketLiquidityAmount: BigNumber
+ marketLiquidationThreshold: number
+}
diff --git a/src/types/interfaces/market.d.ts b/src/types/interfaces/market.d.ts
index 0907b921..e158f412 100644
--- a/src/types/interfaces/market.d.ts
+++ b/src/types/interfaces/market.d.ts
@@ -7,4 +7,6 @@ interface Market {
borrowEnabled: boolean
depositCap: string
maxLtv: number
+ liquidityRate: number
+ liquidationThreshold: number
}
diff --git a/src/utils/array.ts b/src/utils/array.ts
new file mode 100644
index 00000000..2b45107a
--- /dev/null
+++ b/src/utils/array.ts
@@ -0,0 +1 @@
+export const byDenom = (denom: string) => (entity: any) => entity.denom === denom
diff --git a/src/utils/formatters.ts b/src/utils/formatters.ts
index ffd2bee4..7b64f450 100644
--- a/src/utils/formatters.ts
+++ b/src/utils/formatters.ts
@@ -168,3 +168,8 @@ export function convertToDisplayAmount(coin: Coin, displayCurrency: Asset, price
.div(displayPrice.amount)
.toNumber()
}
+
+export function convertLiquidityRateToAPR(rate: number) {
+ const rateMulHundred = rate * 100
+ return rateMulHundred >= 0.01 ? rateMulHundred : 0.0
+}
diff --git a/src/utils/resolvers.ts b/src/utils/resolvers.ts
index 0f791eda..e99be0e9 100644
--- a/src/utils/resolvers.ts
+++ b/src/utils/resolvers.ts
@@ -22,5 +22,7 @@ export function resolveMarketResponses(responses: MarketResponse[]): Market[] {
borrowEnabled: response.borrow_enabled,
depositCap: response.deposit_cap,
maxLtv: Number(response.max_loan_to_value),
+ liquidityRate: Number(response.liquidity_rate),
+ liquidationThreshold: Number(response.liquidation_threshold),
}))
}