Skip to content
Open
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
122 changes: 122 additions & 0 deletions src/api/MinersDashboardApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { useApiQuery } from './ApiUtils';
import { SSE_FALLBACK_INTERVAL } from './constants';
import type {
ActiveSwap,
CrownHistoryRow,
CrownRateHistoryRow,
CurrentCrownMap,
DiagnosticRow,
Direction,
HaltState,
LeaderboardRow,
MinerRateHistoryRow,
MinerStats,
NetworkOverview,
Range,
} from './models';

const CROWN_REFRESH_MS = 12_000;

export const useCurrentCrown = () =>
useApiQuery<CurrentCrownMap>('crown', '/crown', CROWN_REFRESH_MS);

export const useCrownHistory = (params: {
direction: Direction;
fromBlock?: number;
toBlock?: number;
}) =>
useApiQuery<CrownHistoryRow[]>(
'crown-history',
'/crown/history',
CROWN_REFRESH_MS,
{
direction: params.direction,
fromBlock: params.fromBlock,
toBlock: params.toBlock,
},
);

export const useCrownRateHistory = (params: {
direction: Direction;
fromBlock?: number;
toBlock?: number;
}) =>
useApiQuery<CrownRateHistoryRow[]>(
'crown-rate-history',
'/crown/rate-history',
CROWN_REFRESH_MS,
{
direction: params.direction,
fromBlock: params.fromBlock,
toBlock: params.toBlock,
},
);

export const useMinerLeaderboard = (range: Range = '30d') =>
useApiQuery<LeaderboardRow[]>(
'miners-leaderboard',
'/miners/leaderboard',
SSE_FALLBACK_INTERVAL,
{
range,
},
);

export const useMinerStats = (hotkey: string, range: Range = '30d') =>
useApiQuery<MinerStats>(
'miner-stats',
`/miners/${hotkey}/stats`,
SSE_FALLBACK_INTERVAL,
{ range },
!!hotkey,
);

export const useMinerDiagnostic = (hotkey: string) =>
useApiQuery<DiagnosticRow[]>(
'miner-diagnostic',
`/miners/${hotkey}/diagnostic`,
SSE_FALLBACK_INTERVAL,
undefined,
!!hotkey,
);

export const useMinerSwaps = (
hotkey: string,
params: { limit?: number; offset?: number; status?: string } = {},
) =>
useApiQuery<{ rows: ActiveSwap[]; totalCount: number }>(
'miner-swaps',
`/miners/${hotkey}/swaps`,
SSE_FALLBACK_INTERVAL,
params,
!!hotkey,
);

export const useMinerRateHistory = (
hotkey: string,
params: { fromBlock?: number; toBlock?: number } = {},
) =>
useApiQuery<MinerRateHistoryRow[]>(
'miner-rate-history',
`/miners/${hotkey}/rate-history`,
SSE_FALLBACK_INTERVAL,
params,
!!hotkey,
);

export const useNetworkOverview = (range: Range = '30d') =>
useApiQuery<NetworkOverview>(
'network-overview',
'/network/overview',
SSE_FALLBACK_INTERVAL,
{
range,
},
);

export const useHaltState = () =>
useApiQuery<HaltState>(
'network-halt-state',
'/network/halt-state',
CROWN_REFRESH_MS,
);
1 change: 1 addition & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './ApiUtils';
export * from './EventsApi';
export * from './MinersApi';
export * from './MinersDashboardApi';
export * from './ProtocolApi';
export * from './ReservationsApi';
export * from './StatsApi';
Expand Down
86 changes: 86 additions & 0 deletions src/api/models/MinersDashboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
export type Direction = 'BTC-TAO' | 'TAO-BTC';
export type Range = '24h' | '7d' | '30d' | '90d' | 'all';

export type CurrentCrown = {
uid: number | null;
hotkey: string | null;
rate: number | null;
sinceBlock: number | null;
};

export type CurrentCrownMap = Record<Direction, CurrentCrown>;

export type CrownHistoryRow = {
block: number;
hotkey: string;
uid: number | null;
rate: number;
credit: number;
};

export type CrownRateHistoryRow = {
block: number;
rate: number;
holderHotkey: string;
holderUid: number | null;
};

export type LeaderboardRow = {
uid: number;
hotkey: string;
crownShare: number;
successRate: number;
completedSwaps: number;
timedOutSwaps: number;
volumeTao: string;
isActive: boolean;
currentCrownDirections: Direction[];
};

export type MinerStats = {
successRate: number;
totalSwaps: number;
completedSwaps: number;
timedOutSwaps: number;
volumeTao: string;
avgFulfillSec: number | null;
avgCompleteSec: number | null;
crownShare: number;
isActive: boolean;
collateralRao: string;
activatedAt: number | null;
};

export type DiagnosticAction = {
kind: 'cli-command' | 'link';
label: string;
value: string;
};

export type DiagnosticRow = {
severity: 'fail' | 'warn' | 'ok';
code: string;
headline: string;
detail: string;
action?: DiagnosticAction;
};

export type MinerRateHistoryRow = {
block: number;
rate: number;
fromChain: string;
toChain: string;
};

export type PairMix = { pair: string; pct: number };

export type NetworkOverview = {
volumeTao: string;
totalSwaps: number;
networkSuccessRate: number;
activeMiners: number;
registeredMiners: number;
pairMix: PairMix[];
};

export type HaltState = { halted: boolean; asOfBlock: number };
1 change: 1 addition & 0 deletions src/api/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './Events';
export * from './Miners';
export * from './MinersDashboard';
export * from './Protocol';
export * from './Reservations';
export * from './Stats';
Expand Down
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export * from './nav';
export * from './animated';
export * from './landing';
export * from './agents';
export * from './miners';
export * from './swap';
Loading