Skip to content
Merged
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
8 changes: 4 additions & 4 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ ALCHEMY_API_KEY=
# used for getting block
ETHERSCAN_API_KEY=

# ==================== Monarch API ====================
# Monarch monitoring API for trending markets
MONARCH_API_ENDPOINT=http://localhost:3000
MONARCH_API_KEY=
# ==================== External Data API ====================
# Required in production now that Vercel data-route fallbacks are removed.
# Single required base URL for both metrics and token metadata.
NEXT_PUBLIC_DATA_API_BASE_URL=
Comment thread
antoncoding marked this conversation as resolved.

# ==================== Oracle Metadata ====================
# Base URL for oracle metadata Gist (without trailing slash)
Expand Down
48 changes: 0 additions & 48 deletions app/api/monarch/metrics/route.ts

This file was deleted.

38 changes: 0 additions & 38 deletions app/api/monarch/utils.ts

This file was deleted.

35 changes: 0 additions & 35 deletions app/api/token-metadata/route.ts

This file was deleted.

6 changes: 3 additions & 3 deletions docs/TECHNICAL_OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Market detail participants/activity + admin stats transactions:
↓ (for market-detail fallback only)
Morpho API / Subgraph

Market metrics: Monarch metrics API via `/api/monarch/metrics`
Market metrics: external data API via `/v1/markets/metrics`
Comment thread
antoncoding marked this conversation as resolved.
```

**Morpho API Supported Chains:** Mainnet, Base, Unichain, Polygon, Arbitrum, HyperEVM, Monad
Expand Down Expand Up @@ -275,7 +275,7 @@ Hooks omitted from this matrix are local-state hooks or pure view/composition he
| `useUserBalancesQuery` | ERC20 wallet balances across chains | Pure RPC multicall via wagmi | No Envio gap |
| `useTokensQuery` | Token metadata lookup for app UI | Local token registry + Pendle assets API | Not part of Monarch migration |
| `useOracleMetadata` / `useAllOracleMetadata` | Oracle classification and feed metadata | Scanner gist JSON | Not part of Monarch migration |
| `useMarketMetricsQuery` | Enhanced market metrics, flows, trending, scores | Monarch metrics API via `/api/monarch/metrics` | Already Monarch-backed |
| `useMarketMetricsQuery` | Enhanced market metrics, flows, trending, scores | External data API via `/v1/markets/metrics` | Already Monarch-backed |
| `useUserRewardsQuery` | Claimable rewards and distributions | Morpho rewards REST + Merkl API | Outside Monarch/Envio scope today |
| `useMerklCampaignsQuery` / `useMerklHoldIncentivesQuery` | Campaign and HOLD incentive enrichment | Merkl API + hardcoded opportunity mapping | Outside Monarch/Envio scope today |

Expand Down Expand Up @@ -432,7 +432,7 @@ Fallback Strategy:
|---------|----------|---------|
| Morpho API | `https://blue-api.morpho.org/graphql` | Markets, vaults, positions |
| Monarch GraphQL | `https://api.monarchlend.xyz/graphql` | Autovault metadata, market live state, historical charts, market detail/activity, admin transactions |
| Monarch Metrics | `/api/monarch/metrics` → external Monarch metrics API | Market metrics and admin stats |
| Monarch Metrics | External data API `/v1/markets/metrics` | Market metrics and admin stats |
| The Graph | Per-chain subgraph URLs | Fallback data, suppliers, borrowers |
| Merkl API | `https://api.merkl.xyz` | Reward campaigns |
| Velora API | `https://api.paraswap.io` | Swap quotes and executable tx payloads |
Expand Down
4 changes: 0 additions & 4 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ const nextConfig = {
protocol: 'https',
hostname: 'api.dicebear.com',
},
{
protocol: 'https',
hostname: '**',
},
],
},
// temp fix for reown package issue: https://github.com/MetaMask/metamask-sdk/issues/1376
Expand Down
24 changes: 20 additions & 4 deletions src/hooks/queries/useMarketMetricsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useMemo } from 'react';
import { useQuery } from '@tanstack/react-query';
import { monarchGraphqlFetcher } from '@/data-sources/monarch-api/fetchers';
import { useMarketPreferences, type CustomTagConfig, type FlowTimeWindow } from '@/stores/useMarketPreferences';
import { DATA_API_BASE_URL } from '@/utils/urls';

// Re-export types for convenience
export type { FlowTimeWindow } from '@/stores/useMarketPreferences';
Expand Down Expand Up @@ -78,6 +79,21 @@ type MarketMetricsParams = {
};

const PAGE_SIZE = 1000;
const MARKET_METRICS_REFRESH_MS = 15 * 60 * 1000;

const getMarketMetricsClientUrl = (searchParams?: URLSearchParams): string => {
if (!DATA_API_BASE_URL) {
throw new Error('NEXT_PUBLIC_DATA_API_BASE_URL is required.');
}

const baseUrl = `${DATA_API_BASE_URL}/v1/markets/metrics`;
if (!searchParams || searchParams.size === 0) {
return baseUrl;
}

return `${baseUrl}?${searchParams.toString()}`;
};

const MARKET_LIQUIDATION_PRESENCE_QUERY = `
query MarketLiquidationPresence($chainId: Int!, $marketId: String!) {
Morpho_Liquidate(
Expand Down Expand Up @@ -105,7 +121,7 @@ const fetchMarketMetricsPage = async (params: MarketMetricsParams, limit: number
searchParams.set('limit', String(limit));
searchParams.set('offset', String(offset));

const response = await fetch(`/api/monarch/metrics?${searchParams.toString()}`);
const response = await fetch(getMarketMetricsClientUrl(searchParams));

if (!response.ok) {
throw new Error('Failed to fetch market metrics');
Expand Down Expand Up @@ -163,7 +179,7 @@ const fetchMarketLiquidationPresence = async (chainId: number, marketId: string)

/**
* Fetches enhanced market metrics from the Monarch monitoring API.
* Pre-fetched and cached for 5 minutes.
* Pre-fetched and cached for 15 minutes.
*
* Returns rich metadata including:
* - Flow data (1h, 24h, 7d, 30d) for supply/borrow
Expand All @@ -178,8 +194,8 @@ export const useMarketMetricsQuery = (params: MarketMetricsParams = {}) => {
return useQuery({
queryKey: ['market-metrics', { chainId, sortBy, sortOrder }],
queryFn: () => fetchAllMarketMetrics({ chainId, sortBy, sortOrder }),
staleTime: 5 * 60 * 1000, // 5 minutes - matches API update frequency
refetchInterval: 5 * 60 * 1000, // Match staleTime - no point refetching more often
staleTime: MARKET_METRICS_REFRESH_MS,
refetchInterval: MARKET_METRICS_REFRESH_MS,
refetchOnWindowFocus: false, // Don't refetch on focus since data is slow-changing
enabled,
});
Expand Down
55 changes: 0 additions & 55 deletions src/server/token-metadata-cache.ts

This file was deleted.

Loading