@@ -7,27 +7,31 @@ import { SMALL_POOL_TVL } from '@ui-kit/features/user-profile/store'
77const LendingChains = [ 'ethereum' , 'fraxtal' , 'arbitrum' ] as const
88export type Chain = ( typeof LendingChains ) [ number ]
99
10+ // keep the general pool TVL below the special HighTVL row to guarantee ordering in tests
1011const oneLargeTvl = ( ) => oneFloat ( SMALL_POOL_TVL , MAX_USD_VALUE )
1112const oneSmallTvl = ( ) => oneFloat ( SMALL_POOL_TVL )
1213
1314const oneLendingPool = (
1415 chain : Chain ,
15- { utilization, tvl = oneLargeTvl ( ) } : { utilization : number ; tvl ?: number } ,
16+ { utilization = oneFloat ( 0.99 ) , tvl = oneLargeTvl ( ) } : { utilization ? : number ; tvl ?: number } ,
1617) : GetMarketsResponse [ 'data' ] [ number ] => {
1718 const collateral = oneToken ( chain )
1819 const borrowed = oneToken ( chain )
19- const collateralBalance = oneFloat ( )
2020 const borrowedPrice = borrowed . usdPrice ?? onePrice ( )
2121 const collateralPrice = collateral . usdPrice ?? onePrice ( )
22- const totalAssets = onePrice ( MAX_USD_VALUE / collateralPrice )
23- const totalAssetsUsd = totalAssets * collateralPrice
24- const totalDebtUsd = utilization * totalAssetsUsd
22+ const liquidityUsd = Math . max ( 0 , oneFloat ( 0 , tvl ) ) // portion of TVL represented by (assets - debt)
23+ const totalAssetsUsd = liquidityUsd / ( 1 - utilization )
24+ const totalDebtUsd = totalAssetsUsd * utilization
25+ const totalAssets = totalAssetsUsd / collateralPrice
26+ const totalDebt = totalDebtUsd / borrowedPrice
2527 const minBand = oneInt ( )
2628 const minted = onePrice ( )
2729 const redeemed = onePrice ( minted )
28- const collateralBalanceUsd = collateralBalance * collateralPrice
29- const borrowedBalanceUsd = tvl + totalDebtUsd - collateralBalanceUsd - totalAssetsUsd
30- const borrowedBalance = borrowedBalanceUsd * borrowedPrice
30+ const remainderUsd = Math . max ( tvl - liquidityUsd , 0 ) // portion of TVL not covered by liquidity
31+ const collateralBalanceUsd = remainderUsd === 0 ? 0 : oneFloat ( 0 , remainderUsd )
32+ const borrowedBalanceUsd = remainderUsd - collateralBalanceUsd
33+ const collateralBalance = collateralBalanceUsd / collateralPrice
34+ const borrowedBalance = borrowedBalanceUsd / borrowedPrice
3135 return {
3236 name : [ collateral . symbol , borrowed . symbol ] . join ( '-' ) ,
3337 controller : oneAddress ( ) ,
@@ -46,7 +50,7 @@ const oneLendingPool = (
4650 price_oracle : onePrice ( ) ,
4751 amm_price : onePrice ( ) ,
4852 base_price : onePrice ( ) ,
49- total_debt : totalDebtUsd / borrowedPrice ,
53+ total_debt : totalDebt ,
5054 total_assets : totalAssets ,
5155 total_debt_usd : totalDebtUsd ,
5256 total_assets_usd : totalAssetsUsd ,
@@ -89,7 +93,7 @@ function oneLendingVaultResponse(chain: Chain): GetMarketsResponse {
8993 } ,
9094 {
9195 // largest TVL to test the sorting
92- ...oneLendingPool ( chain , { utilization : oneFloat ( ) , tvl : MAX_USD_VALUE } ) ,
96+ ...oneLendingPool ( chain , { utilization : oneFloat ( 0.4 , 0.8 ) , tvl : MAX_USD_VALUE * 2 } ) ,
9397 address : HighTVLAddress ,
9498 vault : HighTVLAddress ,
9599 controller : HighTVLAddress ,
@@ -102,12 +106,8 @@ function oneLendingVaultResponse(chain: Chain): GetMarketsResponse {
102106 controller : HighUtilizationAddress ,
103107 } ,
104108 {
105- // 0 TVL (below 10k) to test the slider filter
106- ...oneLendingPool ( chain , { utilization : oneFloat ( ) } ) ,
107- total_assets_usd : 0 ,
108- total_debt_usd : 0 ,
109- collateral_balance_usd : 0 ,
110- borrowed_balance_usd : 0 ,
109+ // small TVL to test the slider filter
110+ ...oneLendingPool ( chain , { tvl : SMALL_POOL_TVL / 2 } ) ,
111111 } ,
112112 ] as GetMarketsResponse [ 'data' ] )
113113 : [ ] ) ,
0 commit comments