import { Subaccount } from '@nadohq/shared'; import BigNumber from 'bignumber.js'; import { GetIndexerInterestFundingPaymentsParams, GetIndexerInterestFundingPaymentsResponse, GetIndexerLeaderboardParams, GetIndexerLeaderboardResponse, GetIndexerMatchEventsParams, GetIndexerOrdersParams, IndexerEventBalanceStateSnapshot, IndexerEventPerpStateSnapshot, IndexerEventSpotStateSnapshot, IndexerEventWithTx, IndexerMatchEvent, IndexerOrder, } from './clientTypes'; import { CollateralEventType } from './collateralEventType'; import { NadoTx } from './NadoTx'; export interface IndexerPaginationParams { limit: number; // Retrieves events inclusive of this start cursor startCursor?: string; } export interface IndexerPaginationMeta { hasMore: boolean; nextCursor?: string; } export type WithPaginationMeta = { meta: IndexerPaginationMeta }; type BaseSubaccountPaginationParams = Subaccount & IndexerPaginationParams & { /** * If provided, only events with a timestamp in seconds <= this value will be returned * Specifying `startCursor` will supercede this value */ maxTimestampInclusive?: number; }; export interface BaseIndexerPaginatedEvent extends Subaccount { timestamp: BigNumber; submissionIndex: string; tx: NadoTx; } export interface PaginatedIndexerEventsResponse< T extends BaseIndexerPaginatedEvent, > extends WithPaginationMeta { events: T[]; } /** * Collateral */ export interface GetIndexerSubaccountCollateralEventsParams extends BaseSubaccountPaginationParams { eventTypes?: CollateralEventType[]; // If not given, will return both isolated & non-iso events isolated?: boolean; } export interface IndexerCollateralEvent extends BaseIndexerPaginatedEvent { eventType: CollateralEventType; // Positive for deposits, negative for withdrawals amount: BigNumber; // The collateral balance after the event newAmount: BigNumber; snapshot: IndexerEventSpotStateSnapshot; } export type GetIndexerSubaccountCollateralEventsResponse = PaginatedIndexerEventsResponse; /** * NLP */ export type GetIndexerSubaccountNlpEventsParams = BaseSubaccountPaginationParams; export interface IndexerNlpEvent extends BaseIndexerPaginatedEvent { nlpDelta: BigNumber; primaryQuoteDelta: BigNumber; } export type GetIndexerSubaccountNlpEventsResponse = PaginatedIndexerEventsResponse; /** * Match events */ export type GetIndexerSubaccountMatchEventParams = BaseSubaccountPaginationParams & Pick; export type GetIndexerSubaccountMatchEventsResponse = PaginatedIndexerEventsResponse; /** * Orders */ export type GetIndexerPaginatedOrdersParams = BaseSubaccountPaginationParams & Pick; export interface GetIndexerPaginatedOrdersResponse { orders: IndexerOrder[]; meta: IndexerPaginationMeta; } /** * Liquidations */ export type GetIndexerSubaccountLiquidationEventsParams = BaseSubaccountPaginationParams & Pick; type WithIndexerEvent< TData, TStateType extends IndexerEventBalanceStateSnapshot, > = TData & { indexerEvent: IndexerEventWithTx; }; export interface IndexerLiquidationEvent extends BaseIndexerPaginatedEvent { // Either spot or perp will then be liquidated if the subaccount maint. health is below 0 // Both spot & perp can be liquidated in the same event from a spread liquidation spot?: WithIndexerEvent< { // The original balance that was liquidated // ex. if it was originally a short, amount is negative, but the net delta from the liquidation is positive amountLiquidated: BigNumber; }, IndexerEventSpotStateSnapshot >; perp?: WithIndexerEvent< { // The original balance that was liquidated // ex. if it was originally a short, amount is negative, but the net delta from the liquidation is positive amountLiquidated: BigNumber; }, IndexerEventPerpStateSnapshot >; // Quote delta for the subaccount // Only the SPOT QUOTE payment made for the liquidation. Does not include the perp vQuote balance change quote: WithIndexerEvent< { balanceDelta: BigNumber; }, IndexerEventSpotStateSnapshot >; } export type GetIndexerSubaccountLiquidationEventsResponse = PaginatedIndexerEventsResponse; /** * Settlement */ export type GetIndexerSubaccountSettlementEventsParams = BaseSubaccountPaginationParams; export interface IndexerSettlementEvent extends BaseIndexerPaginatedEvent { // Quote delta for the subaccount being settled quoteDelta: BigNumber; snapshot: IndexerEventPerpStateSnapshot; isolated: boolean; } export type GetIndexerSubaccountSettlementEventsResponse = PaginatedIndexerEventsResponse; /** * Interest / Funding */ export type GetIndexerSubaccountInterestFundingPaymentsParams = BaseSubaccountPaginationParams & Pick; export interface GetIndexerPaginatedInterestFundingPaymentsResponse extends GetIndexerInterestFundingPaymentsResponse { meta: IndexerPaginationMeta; } export type GetIndexerPaginatedLeaderboardParams = IndexerPaginationParams & Pick; export type GetIndexerPaginatedLeaderboardResponse = WithPaginationMeta & GetIndexerLeaderboardResponse;