Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/angry-experts-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@venusprotocol/evm": minor
---

Add Stats page - Markets tab
4 changes: 4 additions & 0 deletions apps/evm/src/clients/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ export * from './queries/getTradeReduceSwapQuotes/useGetTradeReduceSwapQuotes';

export * from './queries/getRiskDashboardMarketAggregates';
export * from './queries/getRiskDashboardMarketAggregates/useGetRiskDashboardMarketAggregates';
export * from './queries/getRiskDashboardMarkets';
export * from './queries/getRiskDashboardMarkets/useGetRiskDashboardMarkets';
export * from './queries/getRiskDashboardEModePools';
export * from './queries/getRiskDashboardEModePools/useGetRiskDashboardEModePools';
export * from './queries/getRiskDashboardMarketSnapshots';
export * from './queries/getRiskDashboardMarketSnapshots/useGetRiskDashboardMarketSnapshots';
export * from './queries/getRiskDashboardWalletAggregates';
Expand Down
35 changes: 35 additions & 0 deletions apps/evm/src/clients/api/queries/fetchRiskDashboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { VError } from 'libs/errors';
import type { ChainId } from 'types';
import { restService } from 'utilities';

export async function fetchRiskDashboard<T extends object>({
endpoint,
chainId,
params,
}: {
endpoint: string;
chainId: ChainId;
params?: Record<string, unknown>;
}) {
const response = await restService<T>({
endpoint,
method: 'GET',
params: { chainId, ...params },
});

const payload = response.data;

if (payload && 'error' in payload) {
throw new VError({
type: 'unexpected',
code: 'somethingWentWrong',
data: { exception: payload.error },
});
}

if (!payload) {
throw new VError({ type: 'unexpected', code: 'somethingWentWrong' });
}

return payload;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { ChainId } from 'types';
import type { Address } from 'viem';
import { fetchRiskDashboard } from '../fetchRiskDashboard';

export interface ApiRiskDashboardEModeSetting {
poolId: string;
label: string;
isActive: boolean;
marketAddress: Address;
collateralFactorMantissa: string;
liquidationThresholdMantissa: string;
liquidationIncentiveMantissa: string;
canBeCollateral: boolean;
isBorrowable: boolean;
}

export interface GetRiskDashboardEModePoolsResponse {
chainId: string;
settings: ApiRiskDashboardEModeSetting[];
}

export const getRiskDashboardEModePools = ({ chainId }: { chainId: ChainId }) =>
fetchRiskDashboard<GetRiskDashboardEModePoolsResponse>({
endpoint: '/risk-dashboard/emode-pools',
chainId,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { type QueryObserverOptions, useQuery } from '@tanstack/react-query';

import FunctionKey from 'constants/functionKey';
import { useChainId } from 'libs/wallet';
import type { ChainId } from 'types';
import { type GetRiskDashboardEModePoolsResponse, getRiskDashboardEModePools } from '.';

export type UseGetRiskDashboardEModePoolsQueryKey = [
FunctionKey.GET_RISK_DASHBOARD_EMODE_POOLS,
{ chainId: ChainId },
];

type Options = QueryObserverOptions<
GetRiskDashboardEModePoolsResponse,
Error,
GetRiskDashboardEModePoolsResponse,
GetRiskDashboardEModePoolsResponse,
UseGetRiskDashboardEModePoolsQueryKey
>;

export const useGetRiskDashboardEModePools = (options?: Partial<Options>) => {
const { chainId } = useChainId();

return useQuery({
queryKey: [FunctionKey.GET_RISK_DASHBOARD_EMODE_POOLS, { chainId }],
queryFn: () => getRiskDashboardEModePools({ chainId }),
...options,
});
};
63 changes: 63 additions & 0 deletions apps/evm/src/clients/api/queries/getRiskDashboardMarkets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { VError } from 'libs/errors';
import type { ChainId } from 'types';
import { restService } from 'utilities';
import type { Address } from 'viem';
import type { ApiRiskDashboardAsOf } from '../getRiskDashboardMarketAggregates';

export interface ApiRiskDashboardMarket {
marketAddress: Address;
underlyingAddress: Address | null;
vTokenDecimals: number;
totalSupplyUsdCents: string;
totalBorrowsUsdCents: string;
liquidityUsdCents: string;
supplyCapUsdCents: string | null;
borrowCapUsdCents: string | null;
priceMantissa: string;
supplyRatePerBlockMantissa: string;
borrowRatePerBlockMantissa: string;
collateralFactorMantissa: string;
reserveFactorMantissa: string;
liquidationThresholdMantissa: string;
liquidationIncentiveMantissa: string;
topSupplierUsdCents: string | null;
topBorrowerUsdCents: string | null;
totalDebtAgainstUsdCents: string | null;
stablecoinDebtUsdCents: string | null;
bnbDebtUsdCents: string | null;
otherDebtUsdCents: string | null;
}

export interface GetRiskDashboardMarketsInput {
chainId: ChainId;
}

export interface GetRiskDashboardMarketsResponse {
chainId: string;
asOf: ApiRiskDashboardAsOf | null;
markets: ApiRiskDashboardMarket[];
}

export async function getRiskDashboardMarkets({ chainId }: GetRiskDashboardMarketsInput) {
const response = await restService<GetRiskDashboardMarketsResponse>({
endpoint: '/risk-dashboard/markets',
method: 'GET',
params: { chainId },
});

const payload = response.data;

if (payload && 'error' in payload) {
throw new VError({
type: 'unexpected',
code: 'somethingWentWrong',
data: { exception: payload.error },
});
}

if (!payload) {
throw new VError({ type: 'unexpected', code: 'somethingWentWrong' });
}

return payload;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { type QueryObserverOptions, useQuery } from '@tanstack/react-query';

import FunctionKey from 'constants/functionKey';
import { useChainId } from 'libs/wallet';
import type { ChainId } from 'types';
import { type GetRiskDashboardMarketsResponse, getRiskDashboardMarkets } from '.';

export type UseGetRiskDashboardMarketsQueryKey = [
FunctionKey.GET_RISK_DASHBOARD_MARKETS,
{ chainId: ChainId },
];

type Options = QueryObserverOptions<
GetRiskDashboardMarketsResponse,
Error,
GetRiskDashboardMarketsResponse,
GetRiskDashboardMarketsResponse,
UseGetRiskDashboardMarketsQueryKey
>;

export const useGetRiskDashboardMarkets = (options?: Partial<Options>) => {
const { chainId } = useChainId();

return useQuery({
queryKey: [FunctionKey.GET_RISK_DASHBOARD_MARKETS, { chainId }],
queryFn: () => getRiskDashboardMarkets({ chainId }),
...options,
});
};
2 changes: 2 additions & 0 deletions apps/evm/src/constants/functionKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ enum FunctionKey {
GET_TOKEN_PAIR_K_LINE_CANDLES = 'GET_TOKEN_PAIR_K_LINE_CANDLES',
GET_TRADE_REDUCE_SWAP_QUOTES = 'GET_TRADE_REDUCE_SWAP_QUOTES',
GET_RISK_DASHBOARD_MARKET_AGGREGATES = 'GET_RISK_DASHBOARD_MARKET_AGGREGATES',
GET_RISK_DASHBOARD_MARKETS = 'GET_RISK_DASHBOARD_MARKETS',
GET_RISK_DASHBOARD_EMODE_POOLS = 'GET_RISK_DASHBOARD_EMODE_POOLS',
GET_RISK_DASHBOARD_MARKET_SNAPSHOTS = 'GET_RISK_DASHBOARD_MARKET_SNAPSHOTS',
GET_RISK_DASHBOARD_WALLET_AGGREGATES = 'GET_RISK_DASHBOARD_WALLET_AGGREGATES',
GET_RISK_DASHBOARD_TOP_WALLETS = 'GET_RISK_DASHBOARD_TOP_WALLETS',
Expand Down
56 changes: 56 additions & 0 deletions apps/evm/src/libs/translations/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,62 @@
"unavailable": "Market data unavailable.",
"utilization": "Utilization"
},
"marketsTable": {
"columns": {
"asset": "Asset",
"bnbDebt": "BNB Debt",
"borrowApy": "Borrow APY",
"borrowCap": "Borrow Cap",
"borrowCapFilled": "Borrow Cap %",
"liquidity": "Liquidity",
"otherDebt": "Other Debt",
"stablecoinDebt": "Stablecoin Debt",
"supplyApy": "Supply APY",
"supplyCap": "Supply Cap",
"supplyCapFilled": "Supply Cap %",
"topBorrowerShare": "Top Borrower %",
"topSupplierShare": "Top Supplier %",
"totalBorrows": "Total Borrows",
"totalDebtAgainst": "Total Debt Against",
"totalSupply": "Total Supply",
"utilization": "Utilization"
},
"noData": "No market snapshot yet.",
"title": "Markets",
"unavailable": "Markets data unavailable."
},
"riskParametersTable": {
"columns": {
"asset": "Asset",
"borrowCap": "Borrow Cap",
"collateralFactor": "Collateral Factor",
"liquidationIncentive": "Liquidation Incentive",
"liquidationThreshold": "Liquidation Threshold",
"price": "Price",
"reserveFactor": "Reserve Factor",
"supplyCap": "Supply Cap",
"utilization": "Utilization"
},
"noData": "No market snapshot yet.",
"title": "Risk Parameters by Market",
"unavailable": "Risk parameters unavailable."
},
"eModeTable": {
"columns": {
"asset": "Asset",
"borrowable": "Borrowable",
"collateral": "Collateral",
"collateralFactor": "Collateral Factor",
"group": "E-Mode Group",
"liquidationIncentive": "Liquidation Incentive",
"liquidationThreshold": "Liquidation Threshold"
},
"no": "No",
"noData": "No E-Mode groups configured.",
"title": "E-Mode Groups",
"unavailable": "E-Mode data unavailable.",
"yes": "Yes"
},
"historicalDominance": {
"borrows": {
"noData": "No historical snapshots yet.",
Expand Down
Loading
Loading