import { EngineServerPerpBalance, EngineServerPerpProduct, EngineServerSpotBalance, EngineServerSpotProduct, } from '@nadohq/engine-client'; import { EIP712OrderValues } from '@nadohq/shared'; import { IndexerEventType } from './IndexerEventType'; import { IndexerLeaderboardRankType } from './IndexerLeaderboardType'; import { NadoTx } from './NadoTx'; export interface IndexerServerSnapshotsInterval { count: number; // Currently accepts any granularity, time distance (in seconds) between data points granularity: number; max_time?: string; } export type IndexerServerProduct = | { spot: EngineServerSpotProduct; } | { perp: EngineServerPerpProduct; }; export type IndexerServerBalance = | { spot: EngineServerSpotBalance; } | { perp: EngineServerPerpBalance; }; /** * Candlesticks */ export interface IndexerServerCandlestick { product_id: number; granularity: string; submission_idx: string; timestamp: string; open_x18: string; high_x18: string; low_x18: string; close_x18: string; volume: string; } /** * Product snapshots */ export interface IndexerServerProductSnapshot { product_id: number; submission_idx: string; product: IndexerServerProduct; } /** * Base Events */ export interface IndexerServerEvent { subaccount: string; isolated: boolean; // The product ID associated with the isolated perp market. This is only used when product_id === QUOTE_PRODUCT_ID and isolated === true isolated_product_id: number | null; product_id: number; submission_idx: string; event_type: IndexerEventType; pre_balance: IndexerServerBalance; post_balance: IndexerServerBalance; product: IndexerServerProduct; net_interest_unrealized: string; net_interest_cumulative: string; net_funding_unrealized: string; net_funding_cumulative: string; net_entry_unrealized: string; net_entry_cumulative: string; /** * Total traded volume in terms of the primary quote (i.e in terms of USDT) for this product */ quote_volume_cumulative: string; /** * Total number of fills for this subaccount + product, as an integer string. * Events indexed before this field existed report `0`. */ cumulative_trade_count: string; } export interface IndexerServerTx { submission_idx: string; timestamp: string; tx: NadoTx; } /** * Orders */ export interface IndexerServerOrder { digest: string; subaccount: string; product_id: number; submission_idx: string; last_fill_submission_idx: string; amount: string; price_x18: string; expiration: string; appendix: string; nonce: string; isolated: boolean; base_filled: string; // Includes fee quote_filled: string; // Includes sequencer fee fee: string; builder_fee: string; realized_pnl: string; closed_amount: string; // Cumulative realized entry price for the closed amount (x18) closed_net_entry: string; // Total isolated margin on the position before the close (x18). Only present for isolated margin orders; null for cross-margin orders closed_margin: string | null; // Unix timestamp (seconds) of the first fill on the order first_fill_timestamp: string; // Unix timestamp (seconds) of the last fill on the order last_fill_timestamp: string; pre_balance: IndexerServerMatchEventBalances; post_balance: IndexerServerMatchEventBalances; } /** * Match events */ export interface IndexerServerMatchEvent { digest: string; isolated: boolean; order: EIP712OrderValues; base_filled: string; // Includes fee quote_filled: string; // Includes sequencer fee fee: string; sequencer_fee: string; builder_fee: string; cumulative_fee: string; cumulative_base_filled: string; cumulative_quote_filled: string; submission_idx: string; net_entry_unrealized: string; net_entry_cumulative: string; pre_balance: IndexerServerMatchEventBalances; post_balance: IndexerServerMatchEventBalances; is_taker: boolean; realized_pnl: string; closed_amount: string; // Realized entry price for the closed amount on this match (x18). Represents the total quote value at which the closed portion of the position was originally entered. closed_net_entry: string; // Margin allocated to the closed amount on this match (x18). Only present for isolated margin orders; null for cross-margin orders. margin: string | null; } export interface IndexerServerMatchEventBalances { base: IndexerServerBalance; // Quote is defined if 0 is included in `product_ids` and the match event is a spot event quote?: IndexerServerBalance; } /** * Positions */ /** * A single historical position. All amount fields are absolute values; the side of the * position is given by `direction`. */ export interface IndexerServerPosition { subaccount: string; product_id: number; isolated: boolean; // true for long, false for short direction: boolean; // submission_idx of the transaction that opened the position open_id: string; // submission_idx of the transaction that closed the position; -1 if still open close_id: string; // submission_idx of the last transaction that updated the position submission_idx: string; // Current size of the position; 0 once the position is closed amount: string; // Peak size reached by the position max_amount: string; total_open_amount: string; total_close_amount: string; // Volume-weighted average entry price (x18) average_entry_price: string; // Volume-weighted average exit price (x18) average_exit_price: string; // Total amount closed by liquidations on this position liquidated_amount: string; // Peak leverage reached by the isolated position; 0 for cross positions. // Set to i128::MAX when the position's equity is below zero max_isolated_leverage_x18: string; // Total fees paid on fills that increased the position open_fee: string; // Total fees paid on fills that decreased the position close_fee: string; realized_pnl: string; // Unix epoch in seconds of when the position was opened open_timestamp: string; // Unix epoch in seconds of when the position was last updated update_timestamp: string; // The transaction type that opened the position, e.g. `match_orders` open_reason: IndexerEventType; // The transaction type that closed the position; null if still open close_reason: IndexerEventType | null; // Net funding payment on this position. Only for perp positions net_funding_payment: string; // Net interest payment on this position. Only for spot positions net_interest_payment: string; // Digest of the order that opened the position; null if not opened by a match open_digest: string | null; // Digest of the order that closed the position; null if not closed by a match or still open close_digest: string | null; net_entry_unrealized: string; } /** * Oracle price */ export interface IndexerServerOraclePrice { product_id: number; oracle_price_x18: string; update_time: number; } /** * Market snapshots */ export interface IndexerServerMarketSnapshotInterval { count: number; // Currently accepts any granularity, time distance (in seconds) between data points granularity: number; max_time?: string; } export interface IndexerServerMarketSnapshot { timestamp: string; cumulative_users: string; daily_active_users: string; tvl: string; // Keyed by product ID -> decimal value in string (i.e. no decimal adjustment) necessary // Backend serializes hashmaps with string keys cumulative_volumes: Record; cumulative_taker_fees: Record; cumulative_sequencer_fees: Record; cumulative_maker_fees: Record; cumulative_trades: Record; cumulative_liquidation_amounts: Record; open_interests: Record; total_deposits: Record; total_borrows: Record; funding_rates: Record; deposit_rates: Record; borrow_rates: Record; cumulative_trade_sizes: Record; cumulative_inflows: Record; cumulative_outflows: Record; oracle_prices: Record; } /** * Interest / funding */ export interface IndexerServerProductPayment { product_id: number; idx: string; timestamp: string; amount: string; balance_amount: string; rate_x18: string; oracle_price_x18: string; isolated: boolean; isolated_product_id: number | null; } /** * Maker stats */ export interface IndexerServerMakerData { timestamp: string; maker_fee: string; uptime: string; sum_q_min: string; q_score: string; maker_share: string; expected_maker_reward: string; } export interface IndexerServerMaker { address: string; data: IndexerServerMakerData[]; } /** * Leaderboard */ export interface IndexerServerSocialAccount { provider: 'twitter'; username: string; display_name: string; profile_image_url: string; } export interface IndexerServerLeaderboardTrackPosition { value: string; rank: string; qualification_status: | 'qualified' | 'insufficient_account_value' | 'insufficient_volume' | 'insufficient_account_value_and_volume'; } export interface IndexerServerLeaderboardContestTrack { track_id: number; rank_type: IndexerLeaderboardRankType; sort_order: 'ASC' | 'DESC'; threshold: string; volume_threshold: string; } export interface IndexerServerLeaderboardPosition { subaccount: string; contest_id: number; account_value: string; update_time: string; tracks: Partial< Record >; social_accounts: IndexerServerSocialAccount[]; } export interface IndexerServerLeaderboardContest { contest_id: number; start_time: string; end_time: string; count: string; last_updated: string; product_ids: number[]; active: boolean; title: string; description: string; tracks: IndexerServerLeaderboardContestTrack[]; } export interface IndexerServerLeaderboardRegistration { subaccount: string; contest_id: number; update_time: string; } /** * NLP */ export interface IndexerServerNlpSnapshot { cumulative_burn_quote: string; cumulative_mint_quote: string; cumulative_pnl: string; cumulative_trades: string; cumulative_volume: string; depositors: string; oracle_price_x18: string; submission_idx: string; timestamp: string; tvl: string; }