@0xarchive/sdk 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -132,6 +132,18 @@ interface Trade {
132
132
  makerAddress?: string;
133
133
  /** Taker's wallet address (for market-level WebSocket trades) */
134
134
  takerAddress?: string;
135
+ /** Builder address that routed this order. Present only when the order was placed through a builder. */
136
+ builderAddress?: string;
137
+ /** Builder fee charged on this fill, paid to the builder (in quote currency, typically USDC). Present only when builderAddress is set. */
138
+ builderFee?: string;
139
+ /** HIP-3 deployer fee share on this fill (in quote currency). Negative for the maker side (rebate), positive for the taker side. Present only on HIP-3 fills. */
140
+ deployerFee?: string;
141
+ /** Priority fee burned in HYPE (not USDC) for write priority on the Hyperliquid validator queue. Independent of builderFee and deployerFee — paid to the network, not to a builder or deployer. Present only when the order paid for priority. */
142
+ priorityGas?: number;
143
+ /** Client order ID */
144
+ cloid?: string;
145
+ /** TWAP execution ID */
146
+ twapId?: number;
135
147
  }
136
148
  /**
137
149
  * Cursor-based pagination parameters (recommended)
@@ -2288,6 +2300,49 @@ declare class L4OrderBookResource {
2288
2300
  history(symbol: string, params: CursorPaginationParams): Promise<CursorResponse<any[]>>;
2289
2301
  }
2290
2302
 
2303
+ interface L2OrderBookParams {
2304
+ timestamp?: number | string;
2305
+ depth?: number;
2306
+ }
2307
+ /**
2308
+ * L2 Full-Depth Order Book API resource (derived from L4 data)
2309
+ *
2310
+ * Access aggregated price-level orderbook snapshots, history, and tick-level diffs.
2311
+ * Data available from March 10, 2026.
2312
+ *
2313
+ * @example
2314
+ * ```typescript
2315
+ * // Get current full-depth L2 orderbook
2316
+ * const orderbook = await client.hyperliquid.l2Orderbook.get('BTC');
2317
+ *
2318
+ * // Get L2 orderbook at a historical timestamp
2319
+ * const historical = await client.hyperliquid.l2Orderbook.get('BTC', {
2320
+ * timestamp: 1711900800000
2321
+ * });
2322
+ *
2323
+ * // Get L2 orderbook history
2324
+ * const history = await client.hyperliquid.l2Orderbook.history('BTC', {
2325
+ * start: Date.now() - 86400000,
2326
+ * end: Date.now(),
2327
+ * limit: 100
2328
+ * });
2329
+ * ```
2330
+ */
2331
+ declare class L2OrderBookResource {
2332
+ private http;
2333
+ private basePath;
2334
+ private coinTransform;
2335
+ constructor(http: HttpClient, basePath?: string, coinTransform?: (s: string) => string);
2336
+ /** Get full-depth L2 order book snapshot. */
2337
+ get(symbol: string, params?: L2OrderBookParams): Promise<any>;
2338
+ /** Get paginated L2 full-depth history. */
2339
+ history(symbol: string, params: CursorPaginationParams & {
2340
+ depth?: number;
2341
+ }): Promise<CursorResponse<any[]>>;
2342
+ /** Get tick-level L2 order book diffs. */
2343
+ diffs(symbol: string, params: CursorPaginationParams): Promise<CursorResponse<any[]>>;
2344
+ }
2345
+
2291
2346
  interface L3OrderBookParams {
2292
2347
  timestamp?: number | string;
2293
2348
  depth?: number;
@@ -2382,6 +2437,10 @@ declare class HyperliquidClient {
2382
2437
  * L4 order book (snapshots, diffs, history)
2383
2438
  */
2384
2439
  readonly l4Orderbook: L4OrderBookResource;
2440
+ /**
2441
+ * L2 full-depth order book (derived from L4)
2442
+ */
2443
+ readonly l2Orderbook: L2OrderBookResource;
2385
2444
  /**
2386
2445
  * HIP-3 builder-deployed perpetuals (February 2026+)
2387
2446
  */
@@ -2461,6 +2520,10 @@ declare class Hip3Client {
2461
2520
  * L4 order book (snapshots, diffs, history)
2462
2521
  */
2463
2522
  readonly l4Orderbook: L4OrderBookResource;
2523
+ /**
2524
+ * L2 full-depth order book (derived from L4)
2525
+ */
2526
+ readonly l2Orderbook: L2OrderBookResource;
2464
2527
  private http;
2465
2528
  constructor(http: HttpClient);
2466
2529
  /**
@@ -3003,6 +3066,109 @@ declare class OxArchiveWs {
3003
3066
  private handleMessage;
3004
3067
  }
3005
3068
 
3069
+ /**
3070
+ * L4 order book reconstructor with matching engine.
3071
+ *
3072
+ * Reconstructs Hyperliquid and HIP-3 L4 order books from checkpoints and diffs.
3073
+ * The same class works for both exchanges — the diff format is identical.
3074
+ *
3075
+ * When a new order crosses the spread, the matching engine filled opposite-side
3076
+ * orders at crossing prices. Without removing them, the reconstructed book will
3077
+ * be "crossed" (best bid > best ask).
3078
+ *
3079
+ * Ref: https://github.com/hyperliquid-dex/order_book_server
3080
+ */
3081
+ interface L4Order {
3082
+ oid: number;
3083
+ userAddress: string;
3084
+ side: 'B' | 'A';
3085
+ price: number;
3086
+ size: number;
3087
+ }
3088
+ interface L2Level {
3089
+ px: number;
3090
+ sz: number;
3091
+ n: number;
3092
+ }
3093
+ interface L4Diff {
3094
+ diff_type?: 'new' | 'update' | 'remove';
3095
+ diffType?: 'new' | 'update' | 'remove';
3096
+ oid: number;
3097
+ side: 'B' | 'A';
3098
+ price: number;
3099
+ new_size?: number | null;
3100
+ newSize?: number | null;
3101
+ user_address?: string;
3102
+ userAddress?: string;
3103
+ block_number?: number;
3104
+ blockNumber?: number;
3105
+ }
3106
+ interface L4Checkpoint {
3107
+ bids: Array<{
3108
+ oid: number;
3109
+ user_address?: string;
3110
+ userAddress?: string;
3111
+ side: string;
3112
+ price: number;
3113
+ size: number;
3114
+ }>;
3115
+ asks: Array<{
3116
+ oid: number;
3117
+ user_address?: string;
3118
+ userAddress?: string;
3119
+ side: string;
3120
+ price: number;
3121
+ size: number;
3122
+ }>;
3123
+ }
3124
+ /**
3125
+ * L4 orderbook reconstructor with matching engine.
3126
+ *
3127
+ * Works identically for Hyperliquid and HIP-3 — same diff format,
3128
+ * same checkpoint format, same crossing logic.
3129
+ *
3130
+ * @example
3131
+ * ```typescript
3132
+ * const book = new L4OrderBookReconstructor();
3133
+ * book.loadCheckpoint(checkpoint);
3134
+ *
3135
+ * // Group diffs by block, apply in order
3136
+ * for (const bn of sortedBlockNumbers) {
3137
+ * const nr = nonRestingByBlock.get(bn);
3138
+ * for (const diff of blocks.get(bn)!) {
3139
+ * book.applyDiff(diff, nr);
3140
+ * }
3141
+ * }
3142
+ *
3143
+ * console.log(book.isCrossed()); // false
3144
+ * const { bids: l2Bids, asks: l2Asks } = book.deriveL2();
3145
+ * ```
3146
+ */
3147
+ declare class L4OrderBookReconstructor {
3148
+ private orders;
3149
+ private bidPrices;
3150
+ private askPrices;
3151
+ /** Initialize from an L4 checkpoint. */
3152
+ loadCheckpoint(checkpoint: L4Checkpoint): void;
3153
+ /** Apply a single L4 diff with matching engine. */
3154
+ applyDiff(diff: L4Diff, nonRestingOids?: Set<number>): void;
3155
+ /** Return bids sorted by price descending. */
3156
+ bids(): L4Order[];
3157
+ /** Return asks sorted by price ascending. */
3158
+ asks(): L4Order[];
3159
+ bestBid(): number | null;
3160
+ bestAsk(): number | null;
3161
+ /** Check if the book is crossed. Should be false after correct reconstruction. */
3162
+ isCrossed(): boolean;
3163
+ get bidCount(): number;
3164
+ get askCount(): number;
3165
+ /** Aggregate L4 orders into L2 price levels. */
3166
+ deriveL2(): {
3167
+ bids: L2Level[];
3168
+ asks: L2Level[];
3169
+ };
3170
+ }
3171
+
3006
3172
  /**
3007
3173
  * Zod schemas for runtime validation of API responses
3008
3174
  *
@@ -3180,6 +3346,12 @@ declare const TradeSchema: z.ZodObject<{
3180
3346
  userAddress: z.ZodOptional<z.ZodString>;
3181
3347
  makerAddress: z.ZodOptional<z.ZodString>;
3182
3348
  takerAddress: z.ZodOptional<z.ZodString>;
3349
+ builderAddress: z.ZodOptional<z.ZodString>;
3350
+ builderFee: z.ZodOptional<z.ZodString>;
3351
+ deployerFee: z.ZodOptional<z.ZodString>;
3352
+ priorityGas: z.ZodOptional<z.ZodNumber>;
3353
+ cloid: z.ZodOptional<z.ZodString>;
3354
+ twapId: z.ZodOptional<z.ZodNumber>;
3183
3355
  }, "strip", z.ZodTypeAny, {
3184
3356
  coin: string;
3185
3357
  timestamp: string;
@@ -3198,6 +3370,12 @@ declare const TradeSchema: z.ZodObject<{
3198
3370
  userAddress?: string | undefined;
3199
3371
  makerAddress?: string | undefined;
3200
3372
  takerAddress?: string | undefined;
3373
+ builderAddress?: string | undefined;
3374
+ builderFee?: string | undefined;
3375
+ deployerFee?: string | undefined;
3376
+ priorityGas?: number | undefined;
3377
+ cloid?: string | undefined;
3378
+ twapId?: number | undefined;
3201
3379
  }, {
3202
3380
  coin: string;
3203
3381
  timestamp: string;
@@ -3216,6 +3394,12 @@ declare const TradeSchema: z.ZodObject<{
3216
3394
  userAddress?: string | undefined;
3217
3395
  makerAddress?: string | undefined;
3218
3396
  takerAddress?: string | undefined;
3397
+ builderAddress?: string | undefined;
3398
+ builderFee?: string | undefined;
3399
+ deployerFee?: string | undefined;
3400
+ priorityGas?: number | undefined;
3401
+ cloid?: string | undefined;
3402
+ twapId?: number | undefined;
3219
3403
  }>;
3220
3404
  declare const InstrumentTypeSchema: z.ZodEnum<["perp", "spot"]>;
3221
3405
  declare const InstrumentSchema: z.ZodObject<{
@@ -4130,6 +4314,12 @@ declare const TradeArrayResponseSchema: z.ZodObject<{
4130
4314
  userAddress: z.ZodOptional<z.ZodString>;
4131
4315
  makerAddress: z.ZodOptional<z.ZodString>;
4132
4316
  takerAddress: z.ZodOptional<z.ZodString>;
4317
+ builderAddress: z.ZodOptional<z.ZodString>;
4318
+ builderFee: z.ZodOptional<z.ZodString>;
4319
+ deployerFee: z.ZodOptional<z.ZodString>;
4320
+ priorityGas: z.ZodOptional<z.ZodNumber>;
4321
+ cloid: z.ZodOptional<z.ZodString>;
4322
+ twapId: z.ZodOptional<z.ZodNumber>;
4133
4323
  }, "strip", z.ZodTypeAny, {
4134
4324
  coin: string;
4135
4325
  timestamp: string;
@@ -4148,6 +4338,12 @@ declare const TradeArrayResponseSchema: z.ZodObject<{
4148
4338
  userAddress?: string | undefined;
4149
4339
  makerAddress?: string | undefined;
4150
4340
  takerAddress?: string | undefined;
4341
+ builderAddress?: string | undefined;
4342
+ builderFee?: string | undefined;
4343
+ deployerFee?: string | undefined;
4344
+ priorityGas?: number | undefined;
4345
+ cloid?: string | undefined;
4346
+ twapId?: number | undefined;
4151
4347
  }, {
4152
4348
  coin: string;
4153
4349
  timestamp: string;
@@ -4166,6 +4362,12 @@ declare const TradeArrayResponseSchema: z.ZodObject<{
4166
4362
  userAddress?: string | undefined;
4167
4363
  makerAddress?: string | undefined;
4168
4364
  takerAddress?: string | undefined;
4365
+ builderAddress?: string | undefined;
4366
+ builderFee?: string | undefined;
4367
+ deployerFee?: string | undefined;
4368
+ priorityGas?: number | undefined;
4369
+ cloid?: string | undefined;
4370
+ twapId?: number | undefined;
4169
4371
  }>, "many">;
4170
4372
  meta: z.ZodObject<{
4171
4373
  count: z.ZodNumber;
@@ -4199,6 +4401,12 @@ declare const TradeArrayResponseSchema: z.ZodObject<{
4199
4401
  userAddress?: string | undefined;
4200
4402
  makerAddress?: string | undefined;
4201
4403
  takerAddress?: string | undefined;
4404
+ builderAddress?: string | undefined;
4405
+ builderFee?: string | undefined;
4406
+ deployerFee?: string | undefined;
4407
+ priorityGas?: number | undefined;
4408
+ cloid?: string | undefined;
4409
+ twapId?: number | undefined;
4202
4410
  }[];
4203
4411
  success: boolean;
4204
4412
  meta: {
@@ -4225,6 +4433,12 @@ declare const TradeArrayResponseSchema: z.ZodObject<{
4225
4433
  userAddress?: string | undefined;
4226
4434
  makerAddress?: string | undefined;
4227
4435
  takerAddress?: string | undefined;
4436
+ builderAddress?: string | undefined;
4437
+ builderFee?: string | undefined;
4438
+ deployerFee?: string | undefined;
4439
+ priorityGas?: number | undefined;
4440
+ cloid?: string | undefined;
4441
+ twapId?: number | undefined;
4228
4442
  }[];
4229
4443
  success: boolean;
4230
4444
  meta: {
@@ -5462,4 +5676,4 @@ type ValidatedCandle = z.infer<typeof CandleSchema>;
5462
5676
  type ValidatedLiquidation = z.infer<typeof LiquidationSchema>;
5463
5677
  type ValidatedWsServerMessage = z.infer<typeof WsServerMessageSchema>;
5464
5678
 
5465
- export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type Candle, CandleArrayResponseSchema, type CandleHistoryParams, type CandleInterval, CandleIntervalSchema, CandleSchema, type ClientOptions, type CoinFreshness, CoinFreshnessResponseSchema, CoinFreshnessSchema, type CoinSummary, CoinSummaryResponseSchema, CoinSummarySchema, type CompletenessMetrics, type CoverageGap, type CoverageResponse, type CursorResponse, type DataCadence, type DataFreshness, type DataTypeCoverage, type DataTypeFreshnessInfo, DataTypeFreshnessInfoSchema, type DataTypeStatus, type ExchangeCoverage, type ExchangeLatency, type ExchangeStatus, type FundingHistoryParams, type FundingRate, FundingRateArrayResponseSchema, FundingRateResponseSchema, FundingRateSchema, type GetOrderBookParams, type GetTradesCursorParams, Hip3Client, type Hip3Instrument, HyperliquidClient, type Incident, type IncidentSeverityValue, type IncidentStatusValue, type IncidentsResponse, type Instrument, InstrumentArrayResponseSchema, InstrumentResponseSchema, InstrumentSchema, type InstrumentType, InstrumentTypeSchema, type LatencyResponse, LighterClient, type LighterGranularity, type LighterInstrument, type Liquidation, LiquidationArrayResponseSchema, type LiquidationHistoryParams, LiquidationSchema, LiquidationSideSchema, type LiquidationVolume, LiquidationVolumeArrayResponseSchema, type LiquidationVolumeParams, LiquidationVolumeSchema, type LiquidationsByUserParams, type ListIncidentsParams, type OiFundingInterval, type OpenInterest, OpenInterestArrayResponseSchema, type OpenInterestHistoryParams, OpenInterestResponseSchema, OpenInterestSchema, type OrderBook, OrderBookArrayResponseSchema, type OrderBookHistoryParams, OrderBookReconstructor, OrderBookResponseSchema, OrderBookSchema, type OrderbookDelta, OxArchive, OxArchiveError, OxArchiveWs, type Pagination, type PriceHistoryParams, type PriceLevel, PriceLevelSchema, type PriceSnapshot, PriceSnapshotArrayResponseSchema, PriceSnapshotSchema, type ReconstructOptions, type ReconstructedOrderBook, type RestApiLatency, type SiweChallenge, type SlaActual, type SlaParams, type SlaResponse, type SlaTargets, type StatusResponse, type SymbolCoverageOptions, type SymbolCoverageResponse, type SymbolDataTypeCoverage, type SystemStatusValue, type TickData, type TickHistoryParams, type Timestamp, type TimestampedRecord, TimestampedRecordSchema, type Trade, TradeArrayResponseSchema, type TradeDirection, TradeDirectionSchema, TradeSchema, type TradeSide, TradeSideSchema, type ValidatedApiMeta, type ValidatedCandle, type ValidatedFundingRate, type ValidatedInstrument, type ValidatedLiquidation, type ValidatedOpenInterest, type ValidatedOrderBook, type ValidatedPriceLevel, type ValidatedTrade, type ValidatedWsServerMessage, type Web3ApiKey, type Web3KeysList, type Web3PaymentRequired, type Web3RevokeResult, type Web3SignupResult, type Web3SubscribeResult, type WebSocketLatency, type WsChannel, WsChannelSchema, type WsClientMessage, type WsConnectionState, WsConnectionStateSchema, type WsData, WsDataSchema, type WsError, WsErrorSchema, type WsEventHandlers, type WsGapDetected, type WsHistoricalBatch, WsHistoricalBatchSchema, type WsHistoricalData, WsHistoricalDataSchema, type WsHistoricalTickData, type WsL4Batch, type WsL4Snapshot, type WsOptions, type WsPing, type WsPong, WsPongSchema, type WsReplay, type WsReplayCompleted, WsReplayCompletedSchema, type WsReplayPause, type WsReplayPaused, WsReplayPausedSchema, type WsReplayResume, type WsReplayResumed, WsReplayResumedSchema, type WsReplaySeek, type WsReplaySnapshot, WsReplaySnapshotSchema, type WsReplayStarted, WsReplayStartedSchema, type WsReplayStop, type WsReplayStopped, WsReplayStoppedSchema, type WsServerMessage, WsServerMessageSchema, type WsStream, type WsStreamCompleted, WsStreamCompletedSchema, type WsStreamProgress, WsStreamProgressSchema, type WsStreamStarted, WsStreamStartedSchema, type WsStreamStop, type WsStreamStopped, WsStreamStoppedSchema, type WsSubscribe, type WsSubscribed, WsSubscribedSchema, type WsUnsubscribe, type WsUnsubscribed, WsUnsubscribedSchema, OxArchive as default, reconstructFinal, reconstructOrderBook };
5679
+ export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type Candle, CandleArrayResponseSchema, type CandleHistoryParams, type CandleInterval, CandleIntervalSchema, CandleSchema, type ClientOptions, type CoinFreshness, CoinFreshnessResponseSchema, CoinFreshnessSchema, type CoinSummary, CoinSummaryResponseSchema, CoinSummarySchema, type CompletenessMetrics, type CoverageGap, type CoverageResponse, type CursorResponse, type DataCadence, type DataFreshness, type DataTypeCoverage, type DataTypeFreshnessInfo, DataTypeFreshnessInfoSchema, type DataTypeStatus, type ExchangeCoverage, type ExchangeLatency, type ExchangeStatus, type FundingHistoryParams, type FundingRate, FundingRateArrayResponseSchema, FundingRateResponseSchema, FundingRateSchema, type GetOrderBookParams, type GetTradesCursorParams, Hip3Client, type Hip3Instrument, HyperliquidClient, type Incident, type IncidentSeverityValue, type IncidentStatusValue, type IncidentsResponse, type Instrument, InstrumentArrayResponseSchema, InstrumentResponseSchema, InstrumentSchema, type InstrumentType, InstrumentTypeSchema, type L2Level, type L2OrderBookParams, L2OrderBookResource, type L4Checkpoint, type L4Diff, type L4Order, L4OrderBookReconstructor, type LatencyResponse, LighterClient, type LighterGranularity, type LighterInstrument, type Liquidation, LiquidationArrayResponseSchema, type LiquidationHistoryParams, LiquidationSchema, LiquidationSideSchema, type LiquidationVolume, LiquidationVolumeArrayResponseSchema, type LiquidationVolumeParams, LiquidationVolumeSchema, type LiquidationsByUserParams, type ListIncidentsParams, type OiFundingInterval, type OpenInterest, OpenInterestArrayResponseSchema, type OpenInterestHistoryParams, OpenInterestResponseSchema, OpenInterestSchema, type OrderBook, OrderBookArrayResponseSchema, type OrderBookHistoryParams, OrderBookReconstructor, OrderBookResponseSchema, OrderBookSchema, type OrderbookDelta, OxArchive, OxArchiveError, OxArchiveWs, type Pagination, type PriceHistoryParams, type PriceLevel, PriceLevelSchema, type PriceSnapshot, PriceSnapshotArrayResponseSchema, PriceSnapshotSchema, type ReconstructOptions, type ReconstructedOrderBook, type RestApiLatency, type SiweChallenge, type SlaActual, type SlaParams, type SlaResponse, type SlaTargets, type StatusResponse, type SymbolCoverageOptions, type SymbolCoverageResponse, type SymbolDataTypeCoverage, type SystemStatusValue, type TickData, type TickHistoryParams, type Timestamp, type TimestampedRecord, TimestampedRecordSchema, type Trade, TradeArrayResponseSchema, type TradeDirection, TradeDirectionSchema, TradeSchema, type TradeSide, TradeSideSchema, type ValidatedApiMeta, type ValidatedCandle, type ValidatedFundingRate, type ValidatedInstrument, type ValidatedLiquidation, type ValidatedOpenInterest, type ValidatedOrderBook, type ValidatedPriceLevel, type ValidatedTrade, type ValidatedWsServerMessage, type Web3ApiKey, type Web3KeysList, type Web3PaymentRequired, type Web3RevokeResult, type Web3SignupResult, type Web3SubscribeResult, type WebSocketLatency, type WsChannel, WsChannelSchema, type WsClientMessage, type WsConnectionState, WsConnectionStateSchema, type WsData, WsDataSchema, type WsError, WsErrorSchema, type WsEventHandlers, type WsGapDetected, type WsHistoricalBatch, WsHistoricalBatchSchema, type WsHistoricalData, WsHistoricalDataSchema, type WsHistoricalTickData, type WsL4Batch, type WsL4Snapshot, type WsOptions, type WsPing, type WsPong, WsPongSchema, type WsReplay, type WsReplayCompleted, WsReplayCompletedSchema, type WsReplayPause, type WsReplayPaused, WsReplayPausedSchema, type WsReplayResume, type WsReplayResumed, WsReplayResumedSchema, type WsReplaySeek, type WsReplaySnapshot, WsReplaySnapshotSchema, type WsReplayStarted, WsReplayStartedSchema, type WsReplayStop, type WsReplayStopped, WsReplayStoppedSchema, type WsServerMessage, WsServerMessageSchema, type WsStream, type WsStreamCompleted, WsStreamCompletedSchema, type WsStreamProgress, WsStreamProgressSchema, type WsStreamStarted, WsStreamStartedSchema, type WsStreamStop, type WsStreamStopped, WsStreamStoppedSchema, type WsSubscribe, type WsSubscribed, WsSubscribedSchema, type WsUnsubscribe, type WsUnsubscribed, WsUnsubscribedSchema, OxArchive as default, reconstructFinal, reconstructOrderBook };
package/dist/index.js CHANGED
@@ -39,6 +39,8 @@ __export(index_exports, {
39
39
  InstrumentResponseSchema: () => InstrumentResponseSchema,
40
40
  InstrumentSchema: () => InstrumentSchema,
41
41
  InstrumentTypeSchema: () => InstrumentTypeSchema,
42
+ L2OrderBookResource: () => L2OrderBookResource,
43
+ L4OrderBookReconstructor: () => L4OrderBookReconstructor,
42
44
  LighterClient: () => LighterClient,
43
45
  LiquidationArrayResponseSchema: () => LiquidationArrayResponseSchema,
44
46
  LiquidationSchema: () => LiquidationSchema,
@@ -321,7 +323,13 @@ var TradeSchema = import_zod.z.object({
321
323
  startPosition: import_zod.z.string().optional(),
322
324
  userAddress: import_zod.z.string().optional(),
323
325
  makerAddress: import_zod.z.string().optional(),
324
- takerAddress: import_zod.z.string().optional()
326
+ takerAddress: import_zod.z.string().optional(),
327
+ builderAddress: import_zod.z.string().optional(),
328
+ builderFee: import_zod.z.string().optional(),
329
+ deployerFee: import_zod.z.string().optional(),
330
+ priorityGas: import_zod.z.number().optional(),
331
+ cloid: import_zod.z.string().optional(),
332
+ twapId: import_zod.z.number().optional()
325
333
  });
326
334
  var InstrumentTypeSchema = import_zod.z.enum(["perp", "spot"]);
327
335
  var InstrumentSchema = import_zod.z.object({
@@ -1789,6 +1797,51 @@ var L4OrderBookResource = class {
1789
1797
  }
1790
1798
  };
1791
1799
 
1800
+ // src/resources/l2-orderbook.ts
1801
+ var L2OrderBookResource = class {
1802
+ constructor(http, basePath = "/v1", coinTransform = (c) => c.toUpperCase()) {
1803
+ this.http = http;
1804
+ this.basePath = basePath;
1805
+ this.coinTransform = coinTransform;
1806
+ }
1807
+ /** Get full-depth L2 order book snapshot. */
1808
+ async get(symbol, params) {
1809
+ const coin = this.coinTransform(symbol);
1810
+ const query = {};
1811
+ if (params?.timestamp != null) query.timestamp = params.timestamp;
1812
+ if (params?.depth != null) query.depth = params.depth;
1813
+ const resp = await this.http.get(
1814
+ `${this.basePath}/orderbook/${encodeURIComponent(coin)}/l2`,
1815
+ query
1816
+ );
1817
+ return resp.data;
1818
+ }
1819
+ /** Get paginated L2 full-depth history. */
1820
+ async history(symbol, params) {
1821
+ const coin = this.coinTransform(symbol);
1822
+ const resp = await this.http.get(
1823
+ `${this.basePath}/orderbook/${encodeURIComponent(coin)}/l2/history`,
1824
+ params
1825
+ );
1826
+ return {
1827
+ data: resp.data,
1828
+ nextCursor: resp.meta?.next_cursor ?? void 0
1829
+ };
1830
+ }
1831
+ /** Get tick-level L2 order book diffs. */
1832
+ async diffs(symbol, params) {
1833
+ const coin = this.coinTransform(symbol);
1834
+ const resp = await this.http.get(
1835
+ `${this.basePath}/orderbook/${encodeURIComponent(coin)}/l2/diffs`,
1836
+ params
1837
+ );
1838
+ return {
1839
+ data: resp.data,
1840
+ nextCursor: resp.meta?.next_cursor ?? void 0
1841
+ };
1842
+ }
1843
+ };
1844
+
1792
1845
  // src/resources/l3-orderbook.ts
1793
1846
  var L3OrderBookResource = class {
1794
1847
  constructor(http, basePath = "/v1", coinTransform = (c) => c.toUpperCase()) {
@@ -1864,6 +1917,10 @@ var HyperliquidClient = class {
1864
1917
  * L4 order book (snapshots, diffs, history)
1865
1918
  */
1866
1919
  l4Orderbook;
1920
+ /**
1921
+ * L2 full-depth order book (derived from L4)
1922
+ */
1923
+ l2Orderbook;
1867
1924
  /**
1868
1925
  * HIP-3 builder-deployed perpetuals (February 2026+)
1869
1926
  */
@@ -1881,6 +1938,7 @@ var HyperliquidClient = class {
1881
1938
  this.liquidations = new LiquidationsResource(http, basePath);
1882
1939
  this.orders = new OrdersResource(http, basePath);
1883
1940
  this.l4Orderbook = new L4OrderBookResource(http, basePath);
1941
+ this.l2Orderbook = new L2OrderBookResource(http, basePath);
1884
1942
  this.hip3 = new Hip3Client(http);
1885
1943
  }
1886
1944
  /**
@@ -1967,6 +2025,10 @@ var Hip3Client = class {
1967
2025
  * L4 order book (snapshots, diffs, history)
1968
2026
  */
1969
2027
  l4Orderbook;
2028
+ /**
2029
+ * L2 full-depth order book (derived from L4)
2030
+ */
2031
+ l2Orderbook;
1970
2032
  http;
1971
2033
  constructor(http) {
1972
2034
  this.http = http;
@@ -1981,6 +2043,7 @@ var Hip3Client = class {
1981
2043
  this.liquidations = new LiquidationsResource(http, basePath, coinTransform);
1982
2044
  this.orders = new OrdersResource(http, basePath, coinTransform);
1983
2045
  this.l4Orderbook = new L4OrderBookResource(http, basePath, coinTransform);
2046
+ this.l2Orderbook = new L2OrderBookResource(http, basePath, coinTransform);
1984
2047
  }
1985
2048
  /**
1986
2049
  * Get per-symbol data freshness across all data types
@@ -2860,6 +2923,136 @@ var OxArchiveWs = class {
2860
2923
  }
2861
2924
  }
2862
2925
  };
2926
+
2927
+ // src/l4-reconstructor.ts
2928
+ var L4OrderBookReconstructor = class {
2929
+ orders = /* @__PURE__ */ new Map();
2930
+ bidPrices = /* @__PURE__ */ new Map();
2931
+ askPrices = /* @__PURE__ */ new Map();
2932
+ /** Initialize from an L4 checkpoint. */
2933
+ loadCheckpoint(checkpoint) {
2934
+ this.orders.clear();
2935
+ this.bidPrices.clear();
2936
+ this.askPrices.clear();
2937
+ for (const order of [...checkpoint.bids, ...checkpoint.asks]) {
2938
+ const oid = order.oid;
2939
+ const price = Number(order.price);
2940
+ const size = Number(order.size);
2941
+ const side = order.side;
2942
+ this.orders.set(oid, {
2943
+ oid,
2944
+ userAddress: order.user_address ?? order.userAddress ?? "",
2945
+ side,
2946
+ price,
2947
+ size
2948
+ });
2949
+ const priceMap = side === "B" ? this.bidPrices : this.askPrices;
2950
+ if (!priceMap.has(price)) priceMap.set(price, /* @__PURE__ */ new Set());
2951
+ priceMap.get(price).add(oid);
2952
+ }
2953
+ }
2954
+ /** Apply a single L4 diff with matching engine. */
2955
+ applyDiff(diff, nonRestingOids) {
2956
+ const dt = diff.diff_type ?? diff.diffType;
2957
+ const oid = diff.oid;
2958
+ if (dt === "new") {
2959
+ if (nonRestingOids?.has(oid)) return;
2960
+ const newSize = diff.new_size ?? diff.newSize;
2961
+ if (newSize == null || newSize <= 0) return;
2962
+ const { side, price } = diff;
2963
+ const sz = newSize;
2964
+ if (side === "B") {
2965
+ for (const [askPx, oids] of this.askPrices) {
2966
+ if (askPx <= price) {
2967
+ for (const crossedOid of oids) this.orders.delete(crossedOid);
2968
+ this.askPrices.delete(askPx);
2969
+ }
2970
+ }
2971
+ } else {
2972
+ for (const [bidPx, oids] of this.bidPrices) {
2973
+ if (bidPx >= price) {
2974
+ for (const crossedOid of oids) this.orders.delete(crossedOid);
2975
+ this.bidPrices.delete(bidPx);
2976
+ }
2977
+ }
2978
+ }
2979
+ this.orders.set(oid, {
2980
+ oid,
2981
+ userAddress: diff.user_address ?? diff.userAddress ?? "",
2982
+ side,
2983
+ price,
2984
+ size: sz
2985
+ });
2986
+ const priceMap = side === "B" ? this.bidPrices : this.askPrices;
2987
+ if (!priceMap.has(price)) priceMap.set(price, /* @__PURE__ */ new Set());
2988
+ priceMap.get(price).add(oid);
2989
+ } else if (dt === "update") {
2990
+ const order = this.orders.get(oid);
2991
+ const updSize = diff.new_size ?? diff.newSize;
2992
+ if (order && updSize != null) {
2993
+ order.size = updSize;
2994
+ }
2995
+ } else if (dt === "remove") {
2996
+ const order = this.orders.get(oid);
2997
+ if (order) {
2998
+ this.orders.delete(oid);
2999
+ const priceMap = order.side === "B" ? this.bidPrices : this.askPrices;
3000
+ const oids = priceMap.get(order.price);
3001
+ if (oids) {
3002
+ oids.delete(oid);
3003
+ if (oids.size === 0) priceMap.delete(order.price);
3004
+ }
3005
+ }
3006
+ }
3007
+ }
3008
+ /** Return bids sorted by price descending. */
3009
+ bids() {
3010
+ return [...this.orders.values()].filter((o) => o.side === "B" && o.size > 0).sort((a, b) => b.price - a.price);
3011
+ }
3012
+ /** Return asks sorted by price ascending. */
3013
+ asks() {
3014
+ return [...this.orders.values()].filter((o) => o.side === "A" && o.size > 0).sort((a, b) => a.price - b.price);
3015
+ }
3016
+ bestBid() {
3017
+ const b = this.bids();
3018
+ return b.length > 0 ? b[0].price : null;
3019
+ }
3020
+ bestAsk() {
3021
+ const a = this.asks();
3022
+ return a.length > 0 ? a[0].price : null;
3023
+ }
3024
+ /** Check if the book is crossed. Should be false after correct reconstruction. */
3025
+ isCrossed() {
3026
+ const bb = this.bestBid();
3027
+ const ba = this.bestAsk();
3028
+ return bb != null && ba != null && bb >= ba;
3029
+ }
3030
+ get bidCount() {
3031
+ return [...this.orders.values()].filter((o) => o.side === "B" && o.size > 0).length;
3032
+ }
3033
+ get askCount() {
3034
+ return [...this.orders.values()].filter((o) => o.side === "A" && o.size > 0).length;
3035
+ }
3036
+ /** Aggregate L4 orders into L2 price levels. */
3037
+ deriveL2() {
3038
+ const bidAgg = /* @__PURE__ */ new Map();
3039
+ const askAgg = /* @__PURE__ */ new Map();
3040
+ for (const o of this.orders.values()) {
3041
+ if (o.size <= 0) continue;
3042
+ const agg = o.side === "B" ? bidAgg : askAgg;
3043
+ const existing = agg.get(o.price);
3044
+ if (existing) {
3045
+ existing.sz += o.size;
3046
+ existing.n += 1;
3047
+ } else {
3048
+ agg.set(o.price, { sz: o.size, n: 1 });
3049
+ }
3050
+ }
3051
+ const bids = [...bidAgg.entries()].sort(([a], [b]) => b - a).map(([px, v]) => ({ px, sz: v.sz, n: v.n }));
3052
+ const asks = [...askAgg.entries()].sort(([a], [b]) => a - b).map(([px, v]) => ({ px, sz: v.sz, n: v.n }));
3053
+ return { bids, asks };
3054
+ }
3055
+ };
2863
3056
  // Annotate the CommonJS export names for ESM import in node:
2864
3057
  0 && (module.exports = {
2865
3058
  ApiMetaSchema,
@@ -2881,6 +3074,8 @@ var OxArchiveWs = class {
2881
3074
  InstrumentResponseSchema,
2882
3075
  InstrumentSchema,
2883
3076
  InstrumentTypeSchema,
3077
+ L2OrderBookResource,
3078
+ L4OrderBookReconstructor,
2884
3079
  LighterClient,
2885
3080
  LiquidationArrayResponseSchema,
2886
3081
  LiquidationSchema,