@nadohq/indexer-client 0.14.0 → 0.17.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.
Files changed (155) hide show
  1. package/dist/CandlestickPeriod-1DtcEiOb.d.ts +15 -0
  2. package/dist/CandlestickPeriod-1DtcEiOb.d.ts.map +1 -0
  3. package/dist/CandlestickPeriod-D3_IoSev.d.cts +15 -0
  4. package/dist/CandlestickPeriod-D3_IoSev.d.cts.map +1 -0
  5. package/dist/IndexerBaseClient-3KfzA2ph.cjs +639 -0
  6. package/dist/IndexerBaseClient-3KfzA2ph.cjs.map +1 -0
  7. package/dist/IndexerBaseClient.cjs +3 -788
  8. package/dist/IndexerBaseClient.d.cts +223 -229
  9. package/dist/IndexerBaseClient.d.cts.map +1 -0
  10. package/dist/IndexerBaseClient.d.ts +223 -229
  11. package/dist/IndexerBaseClient.d.ts.map +1 -0
  12. package/dist/IndexerBaseClient.js +601 -783
  13. package/dist/IndexerBaseClient.js.map +1 -1
  14. package/dist/IndexerClient.cjs +275 -381
  15. package/dist/IndexerClient.cjs.map +1 -1
  16. package/dist/IndexerClient.d.cts +32 -43
  17. package/dist/IndexerClient.d.cts.map +1 -0
  18. package/dist/IndexerClient.d.ts +32 -43
  19. package/dist/IndexerClient.d.ts.map +1 -0
  20. package/dist/IndexerClient.js +273 -362
  21. package/dist/IndexerClient.js.map +1 -1
  22. package/dist/IndexerEventType-B-uXsf-a.d.cts +5 -0
  23. package/dist/IndexerEventType-B-uXsf-a.d.cts.map +1 -0
  24. package/dist/IndexerEventType-DCLkSlgR.d.ts +5 -0
  25. package/dist/IndexerEventType-DCLkSlgR.d.ts.map +1 -0
  26. package/dist/IndexerLeaderboardType-Ck12QVWR.d.cts +13 -0
  27. package/dist/IndexerLeaderboardType-Ck12QVWR.d.cts.map +1 -0
  28. package/dist/IndexerLeaderboardType-DAKw2tfI.d.ts +13 -0
  29. package/dist/IndexerLeaderboardType-DAKw2tfI.d.ts.map +1 -0
  30. package/dist/NadoTx-CWCklgY4.d.ts +50 -0
  31. package/dist/NadoTx-CWCklgY4.d.ts.map +1 -0
  32. package/dist/NadoTx-MYNIlXyq.d.cts +50 -0
  33. package/dist/NadoTx-MYNIlXyq.d.cts.map +1 -0
  34. package/dist/clientTypes-BpxOUu1q.d.ts +709 -0
  35. package/dist/clientTypes-BpxOUu1q.d.ts.map +1 -0
  36. package/dist/clientTypes-BsJ2yIC4.d.cts +709 -0
  37. package/dist/clientTypes-BsJ2yIC4.d.cts.map +1 -0
  38. package/dist/collateralEventType-CzH_2iTV.d.ts +5 -0
  39. package/dist/collateralEventType-CzH_2iTV.d.ts.map +1 -0
  40. package/dist/collateralEventType-DIm6Te7F.d.cts +5 -0
  41. package/dist/collateralEventType-DIm6Te7F.d.cts.map +1 -0
  42. package/dist/dataMappers.cjs +269 -346
  43. package/dist/dataMappers.cjs.map +1 -1
  44. package/dist/dataMappers.d.cts +7 -12
  45. package/dist/dataMappers.d.cts.map +1 -0
  46. package/dist/dataMappers.d.ts +7 -12
  47. package/dist/dataMappers.d.ts.map +1 -0
  48. package/dist/dataMappers.js +248 -314
  49. package/dist/dataMappers.js.map +1 -1
  50. package/dist/endpoints.cjs +8 -32
  51. package/dist/endpoints.cjs.map +1 -1
  52. package/dist/endpoints.d.cts +4 -2
  53. package/dist/endpoints.d.cts.map +1 -0
  54. package/dist/endpoints.d.ts +4 -2
  55. package/dist/endpoints.d.ts.map +1 -0
  56. package/dist/endpoints.js +8 -8
  57. package/dist/endpoints.js.map +1 -1
  58. package/dist/index-D6CnpA_r.d.cts +1 -0
  59. package/dist/index-DhI2LvVQ.d.ts +1 -0
  60. package/dist/index.cjs +15 -33
  61. package/dist/index.d.cts +14 -18
  62. package/dist/index.d.ts +14 -18
  63. package/dist/index.js +8 -7
  64. package/dist/indexerBalanceValue-4AuNuTAc.d.cts +32 -0
  65. package/dist/indexerBalanceValue-4AuNuTAc.d.cts.map +1 -0
  66. package/dist/indexerBalanceValue-B0OggI67.d.ts +32 -0
  67. package/dist/indexerBalanceValue-B0OggI67.d.ts.map +1 -0
  68. package/dist/paginatedEventsTypes-DtGDU-kI.d.cts +110 -0
  69. package/dist/paginatedEventsTypes-DtGDU-kI.d.cts.map +1 -0
  70. package/dist/paginatedEventsTypes-RwXoQrEa.d.ts +110 -0
  71. package/dist/paginatedEventsTypes-RwXoQrEa.d.ts.map +1 -0
  72. package/dist/serverModelTypes-CM2g040o.d.cts +262 -0
  73. package/dist/serverModelTypes-CM2g040o.d.cts.map +1 -0
  74. package/dist/serverModelTypes-DPHMUSZe.d.ts +262 -0
  75. package/dist/serverModelTypes-DPHMUSZe.d.ts.map +1 -0
  76. package/dist/serverTypes-BMSNh2GK.d.cts +452 -0
  77. package/dist/serverTypes-BMSNh2GK.d.cts.map +1 -0
  78. package/dist/serverTypes-c8IABU73.d.ts +452 -0
  79. package/dist/serverTypes-c8IABU73.d.ts.map +1 -0
  80. package/dist/types/CandlestickPeriod.cjs +16 -40
  81. package/dist/types/CandlestickPeriod.cjs.map +1 -1
  82. package/dist/types/CandlestickPeriod.d.cts +2 -13
  83. package/dist/types/CandlestickPeriod.d.ts +2 -13
  84. package/dist/types/CandlestickPeriod.js +16 -16
  85. package/dist/types/CandlestickPeriod.js.map +1 -1
  86. package/dist/types/IndexerEventType.cjs +0 -19
  87. package/dist/types/IndexerEventType.d.cts +2 -3
  88. package/dist/types/IndexerEventType.d.ts +2 -3
  89. package/dist/types/IndexerEventType.js +1 -1
  90. package/dist/types/IndexerLeaderboardType.cjs +0 -19
  91. package/dist/types/IndexerLeaderboardType.d.cts +2 -11
  92. package/dist/types/IndexerLeaderboardType.d.ts +2 -11
  93. package/dist/types/IndexerLeaderboardType.js +1 -1
  94. package/dist/types/NadoTx.cjs +0 -19
  95. package/dist/types/NadoTx.d.cts +2 -48
  96. package/dist/types/NadoTx.d.ts +2 -48
  97. package/dist/types/NadoTx.js +1 -1
  98. package/dist/types/clientTypes.cjs +0 -19
  99. package/dist/types/clientTypes.d.cts +2 -709
  100. package/dist/types/clientTypes.d.ts +2 -709
  101. package/dist/types/clientTypes.js +1 -1
  102. package/dist/types/collateralEventType.cjs +0 -19
  103. package/dist/types/collateralEventType.d.cts +2 -3
  104. package/dist/types/collateralEventType.d.ts +2 -3
  105. package/dist/types/collateralEventType.js +1 -1
  106. package/dist/types/index.cjs +3 -41
  107. package/dist/types/index.d.cts +10 -13
  108. package/dist/types/index.d.ts +10 -13
  109. package/dist/types/index.js +2 -11
  110. package/dist/types/paginatedEventsTypes.cjs +0 -19
  111. package/dist/types/paginatedEventsTypes.d.cts +2 -115
  112. package/dist/types/paginatedEventsTypes.d.ts +2 -115
  113. package/dist/types/paginatedEventsTypes.js +1 -1
  114. package/dist/types/serverModelTypes.cjs +0 -19
  115. package/dist/types/serverModelTypes.d.cts +2 -260
  116. package/dist/types/serverModelTypes.d.ts +2 -260
  117. package/dist/types/serverModelTypes.js +1 -1
  118. package/dist/types/serverTypes.cjs +0 -19
  119. package/dist/types/serverTypes.d.cts +2 -451
  120. package/dist/types/serverTypes.d.ts +2 -451
  121. package/dist/types/serverTypes.js +1 -1
  122. package/dist/utils/index.cjs +5 -25
  123. package/dist/utils/index.d.cts +2 -12
  124. package/dist/utils/index.d.ts +2 -12
  125. package/dist/utils/index.js +2 -3
  126. package/dist/utils/indexerBalanceValue.cjs +32 -36
  127. package/dist/utils/indexerBalanceValue.cjs.map +1 -1
  128. package/dist/utils/indexerBalanceValue.d.cts +2 -39
  129. package/dist/utils/indexerBalanceValue.d.ts +2 -39
  130. package/dist/utils/indexerBalanceValue.js +29 -9
  131. package/dist/utils/indexerBalanceValue.js.map +1 -1
  132. package/package.json +10 -10
  133. package/dist/IndexerBaseClient.cjs.map +0 -1
  134. package/dist/index.cjs.map +0 -1
  135. package/dist/index.js.map +0 -1
  136. package/dist/types/IndexerEventType.cjs.map +0 -1
  137. package/dist/types/IndexerEventType.js.map +0 -1
  138. package/dist/types/IndexerLeaderboardType.cjs.map +0 -1
  139. package/dist/types/IndexerLeaderboardType.js.map +0 -1
  140. package/dist/types/NadoTx.cjs.map +0 -1
  141. package/dist/types/NadoTx.js.map +0 -1
  142. package/dist/types/clientTypes.cjs.map +0 -1
  143. package/dist/types/clientTypes.js.map +0 -1
  144. package/dist/types/collateralEventType.cjs.map +0 -1
  145. package/dist/types/collateralEventType.js.map +0 -1
  146. package/dist/types/index.cjs.map +0 -1
  147. package/dist/types/index.js.map +0 -1
  148. package/dist/types/paginatedEventsTypes.cjs.map +0 -1
  149. package/dist/types/paginatedEventsTypes.js.map +0 -1
  150. package/dist/types/serverModelTypes.cjs.map +0 -1
  151. package/dist/types/serverModelTypes.js.map +0 -1
  152. package/dist/types/serverTypes.cjs.map +0 -1
  153. package/dist/types/serverTypes.js.map +0 -1
  154. package/dist/utils/index.cjs.map +0 -1
  155. package/dist/utils/index.js.map +0 -1
@@ -1,787 +1,605 @@
1
- // src/IndexerBaseClient.ts
2
- import {
3
- getDefaultRecvTime,
4
- getNadoEIP712Values,
5
- getSignedTransactionRequest,
6
- getValidatedAddress,
7
- getValidatedHex,
8
- mapValues,
9
- nowInSeconds,
10
- removeDecimals,
11
- subaccountFromHex,
12
- subaccountToHex,
13
- toBigInt,
14
- toBigNumber,
15
- toIntegerString,
16
- WalletNotProvidedError
17
- } from "@nadohq/shared";
1
+ import { mapIndexerCandlesticks, mapIndexerEvent, mapIndexerEventWithTx, mapIndexerFundingRate, mapIndexerLeaderboardContest, mapIndexerLeaderboardPosition, mapIndexerLeaderboardRegistration, mapIndexerMakerStatistics, mapIndexerMarketSnapshot, mapIndexerMatchEventBalances, mapIndexerNlpSnapshot, mapIndexerOrder, mapIndexerPerpPrices, mapIndexerProductPayment, mapIndexerServerProduct, mapIndexerV2Symbols, mapIndexerV2Ticker, mapSnapshotsIntervalToServerParams } from "./dataMappers.js";
2
+ import { WalletNotProvidedError, getDefaultRecvTime, getNadoEIP712Values, getSignedTransactionRequest, getValidatedAddress, getValidatedHex, mapValues, nowInSeconds, removeDecimals, subaccountFromHex, subaccountToHex, toBigInt, toBigNumber, toIntegerString } from "@nadohq/shared";
18
3
  import axios from "axios";
19
- import {
20
- mapIndexerCandlesticks,
21
- mapIndexerEvent,
22
- mapIndexerEventWithTx,
23
- mapIndexerFundingRate,
24
- mapIndexerLeaderboardContest,
25
- mapIndexerLeaderboardPosition,
26
- mapIndexerLeaderboardRegistration,
27
- mapIndexerMakerStatistics,
28
- mapIndexerMarketSnapshot,
29
- mapIndexerMatchEventBalances,
30
- mapIndexerNlpSnapshot,
31
- mapIndexerOrder,
32
- mapIndexerPerpPrices,
33
- mapIndexerProductPayment,
34
- mapIndexerServerProduct,
35
- mapIndexerV2Symbols,
36
- mapIndexerV2Ticker,
37
- mapSnapshotsIntervalToServerParams
38
- } from "./dataMappers.js";
4
+ //#region src/IndexerBaseClient.ts
5
+ /**
6
+ * Base client for all indexer requests
7
+ */
39
8
  var IndexerBaseClient = class {
40
- constructor(opts) {
41
- this.opts = opts;
42
- this.axiosInstance = axios.create({
43
- withCredentials: true,
44
- // We have custom logic to validate response status and create an appropriate error
45
- validateStatus: () => true
46
- });
47
- this.v2Url = opts.v2Url ? opts.v2Url : opts.url.replace("v1", "v2");
48
- }
49
- /**
50
- * Sets the linked signer for execute requests
51
- *
52
- * @param linkedSignerWalletClient The linkedSigner to use for all signatures. Set to null to revert to the chain signer
53
- */
54
- setLinkedSigner(linkedSignerWalletClient) {
55
- this.opts.linkedSignerWalletClient = linkedSignerWalletClient ?? void 0;
56
- }
57
- /**
58
- * List all subaccounts
59
- *
60
- * @param params
61
- */
62
- async listSubaccounts(params) {
63
- const baseResponse = await this.query("subaccounts", params);
64
- return baseResponse.subaccounts.map((item) => {
65
- const subaccount = subaccountFromHex(item.subaccount);
66
- return {
67
- hexId: item.subaccount,
68
- createdAt: Number(item.created_at),
69
- isolated: item.isolated,
70
- ...subaccount
71
- };
72
- });
73
- }
74
- /**
75
- * Retrieve snapshots of multiple subaccounts at multiple points in time.
76
- * Each snapshot is a view of the subaccount's balances at this point in time, with tracked variables for interest, funding, etc.
77
- *
78
- * @param params
79
- */
80
- async getMultiSubaccountSnapshots(params) {
81
- const subaccountHexIds = params.subaccounts.map(
82
- ({ subaccountOwner, subaccountName }) => subaccountToHex({
83
- subaccountOwner,
84
- subaccountName
85
- })
86
- );
87
- const baseResponse = await this.query("account_snapshots", {
88
- subaccounts: subaccountHexIds,
89
- timestamps: params.timestamps,
90
- isolated: params.isolated
91
- });
92
- const snapshotsBySubaccount = mapValues(
93
- baseResponse.snapshots,
94
- (balanceSnapshots) => {
95
- const snapshotByTimestamp = {};
96
- Object.entries(balanceSnapshots).forEach(([timestamp, events]) => {
97
- const balances = events.map(mapIndexerEvent);
98
- snapshotByTimestamp[timestamp] = {
99
- timestamp: toBigNumber(timestamp),
100
- balances
101
- };
102
- });
103
- return snapshotByTimestamp;
104
- }
105
- );
106
- return {
107
- subaccountHexIds,
108
- snapshots: snapshotsBySubaccount
109
- };
110
- }
111
- /**
112
- * Retrieves referral code for an address
113
- *
114
- * @param params
115
- */
116
- async getReferralCode(params) {
117
- const baseResponse = await this.query("referral_code", {
118
- subaccount: subaccountToHex({
119
- subaccountOwner: params.subaccount.subaccountOwner,
120
- subaccountName: params.subaccount.subaccountName
121
- })
122
- });
123
- return {
124
- referralCode: baseResponse.referral_code
125
- };
126
- }
127
- /**
128
- * Retrieves funding rate for a product, where 1 = 100%
129
- * @param params
130
- */
131
- async getFundingRate(params) {
132
- const baseResponse = await this.query("funding_rate", {
133
- product_id: params.productId
134
- });
135
- return mapIndexerFundingRate(baseResponse);
136
- }
137
- /**
138
- * Retrieves funding rate for multiple products, where 1 = 100%
139
- * @param params
140
- */
141
- async getMultiProductFundingRates(params) {
142
- const baseResponse = await this.query("funding_rates", {
143
- product_ids: params.productIds
144
- });
145
- return mapValues(baseResponse, mapIndexerFundingRate);
146
- }
147
- /**
148
- * Retrieves latest mark/index price for a perp product
149
- * @param params
150
- */
151
- async getPerpPrices(params) {
152
- const baseResponse = await this.query("price", {
153
- product_id: params.productId
154
- });
155
- return mapIndexerPerpPrices(baseResponse);
156
- }
157
- /**
158
- * Retrieves latest mark/index price for multiple perp products
159
- * @param params
160
- */
161
- async getMultiProductPerpPrices(params) {
162
- const baseResponse = await this.query("perp_prices", {
163
- product_ids: params.productIds
164
- });
165
- return mapValues(baseResponse, mapIndexerPerpPrices);
166
- }
167
- /**
168
- * Retrieves latest oracle prices for provided products
169
- * @param params
170
- */
171
- async getOraclePrices(params) {
172
- const baseResponse = await this.query("oracle_price", {
173
- product_ids: params.productIds
174
- });
175
- return baseResponse.prices.map((price) => {
176
- return {
177
- oraclePrice: removeDecimals(price.oracle_price_x18),
178
- updateTime: toBigNumber(price.update_time),
179
- productId: price.product_id
180
- };
181
- });
182
- }
183
- /**
184
- * Retrieves candlesticks for a product
185
- * @param params
186
- */
187
- async getCandlesticks(params) {
188
- const baseResponse = await this.query("candlesticks", {
189
- product_id: params.productId,
190
- max_time: params.maxTimeInclusive,
191
- limit: params.limit,
192
- granularity: params.period
193
- });
194
- return baseResponse.candlesticks.map(mapIndexerCandlesticks);
195
- }
196
- /**
197
- * Retrieves candlesticks for a product from Edge
198
- * @param params
199
- */
200
- async getEdgeCandlesticks(params) {
201
- const baseResponse = await this.query("edge_candlesticks", {
202
- product_id: params.productId,
203
- max_time: params.maxTimeInclusive,
204
- limit: params.limit,
205
- granularity: params.period
206
- });
207
- return baseResponse.candlesticks.map(mapIndexerCandlesticks);
208
- }
209
- /**
210
- * Retrieves historical snapshots for a product
211
- * @param params
212
- */
213
- async getProductSnapshots(params) {
214
- const baseResponse = await this.query("products", {
215
- product_id: params.productId,
216
- max_time: params.maxTimestampInclusive,
217
- limit: params.limit,
218
- idx: params.startCursor
219
- });
220
- return baseResponse.products.map((product) => {
221
- return {
222
- ...mapIndexerServerProduct(product.product),
223
- submissionIndex: product.submission_idx
224
- };
225
- });
226
- }
227
- /**
228
- * Retrieves historical snapshots for multiple products
229
- * @param params
230
- */
231
- async getMultiProductSnapshots(params) {
232
- const timestampToProductsMap = await this.query("product_snapshots", {
233
- product_ids: params.productIds,
234
- max_time: params.maxTimestampInclusive ?? [nowInSeconds()]
235
- });
236
- return mapValues(timestampToProductsMap, (productIdToProduct) => {
237
- return mapValues(productIdToProduct, (indexerProduct) => {
238
- return {
239
- ...mapIndexerServerProduct(indexerProduct.product),
240
- submissionIndex: indexerProduct.submission_idx
241
- };
242
- });
243
- });
244
- }
245
- /**
246
- * Retrieves historical events
247
- *
248
- * @param params
249
- */
250
- async getEvents(params) {
251
- const serverLimit = (() => {
252
- if (!params.limit) {
253
- return;
254
- }
255
- if (params.limit.type === "events") {
256
- return {
257
- raw: params.limit.value
258
- };
259
- }
260
- return {
261
- txs: params.limit.value
262
- };
263
- })();
264
- const baseResponse = await this.query("events", {
265
- subaccounts: params.subaccounts?.map(
266
- (subaccount) => subaccountToHex({
267
- subaccountOwner: subaccount.subaccountOwner,
268
- subaccountName: subaccount.subaccountName
269
- })
270
- ),
271
- product_ids: params.productIds,
272
- isolated: params.isolated,
273
- event_types: params.eventTypes,
274
- max_time: params.maxTimestampInclusive,
275
- desc: params.desc,
276
- limit: serverLimit,
277
- idx: params.startCursor
278
- });
279
- let lastTxIdx = 0;
280
- return baseResponse.events.map((event) => {
281
- if (baseResponse.txs[lastTxIdx].submission_idx !== event.submission_idx) {
282
- lastTxIdx += 1;
283
- }
284
- const tx = baseResponse.txs[lastTxIdx];
285
- return mapIndexerEventWithTx(event, tx);
286
- });
287
- }
288
- /**
289
- * Retrieves historical orders
290
- * @param params
291
- */
292
- async getOrders(params) {
293
- const baseResponse = await this.query("orders", {
294
- subaccounts: params?.subaccounts?.map(
295
- (subaccount) => subaccountToHex({
296
- subaccountOwner: subaccount.subaccountOwner,
297
- subaccountName: subaccount.subaccountName
298
- })
299
- ),
300
- product_ids: params.productIds,
301
- trigger_types: params.triggerTypes,
302
- isolated: params.isolated,
303
- digests: params.digests,
304
- max_time: params.maxTimestampInclusive,
305
- limit: params.limit,
306
- idx: params.startCursor
307
- });
308
- return baseResponse.orders.map(mapIndexerOrder);
309
- }
310
- /**
311
- * Gets match order events, this will return the same events as the events query, but with additional information
312
- * to identify the order that was matched
313
- *
314
- * @param params
315
- */
316
- async getMatchEvents(params) {
317
- const baseResponse = await this.query("matches", {
318
- subaccounts: params?.subaccounts?.map(
319
- (subaccount) => subaccountToHex({
320
- subaccountOwner: subaccount.subaccountOwner,
321
- subaccountName: subaccount.subaccountName
322
- })
323
- ),
324
- product_ids: params.productIds,
325
- isolated: params.isolated,
326
- max_time: params.maxTimestampInclusive,
327
- limit: params.limit,
328
- idx: params.startCursor
329
- });
330
- let lastTxIdx = 0;
331
- return baseResponse.matches.map((matchEvent) => {
332
- if (baseResponse.txs[lastTxIdx].submission_idx !== matchEvent.submission_idx) {
333
- lastTxIdx += 1;
334
- }
335
- const { tx, timestamp } = baseResponse.txs[lastTxIdx];
336
- const postBalances = mapIndexerMatchEventBalances(
337
- matchEvent.post_balance
338
- );
339
- return {
340
- productId: postBalances.base.productId,
341
- isolated: matchEvent.isolated,
342
- totalFee: toBigNumber(matchEvent.fee),
343
- sequencerFee: toBigNumber(matchEvent.sequencer_fee),
344
- builderFee: toBigNumber(matchEvent.builder_fee),
345
- baseFilled: toBigNumber(matchEvent.base_filled),
346
- quoteFilled: toBigNumber(matchEvent.quote_filled),
347
- cumulativeFee: toBigNumber(matchEvent.cumulative_fee),
348
- cumulativeBaseFilled: toBigNumber(matchEvent.cumulative_base_filled),
349
- cumulativeQuoteFilled: toBigNumber(matchEvent.cumulative_quote_filled),
350
- digest: matchEvent.digest,
351
- order: matchEvent.order,
352
- submissionIndex: matchEvent.submission_idx,
353
- timestamp: toBigNumber(timestamp),
354
- preEventTrackedVars: {
355
- netEntryUnrealized: toBigNumber(matchEvent.net_entry_unrealized),
356
- netEntryCumulative: toBigNumber(matchEvent.net_entry_cumulative)
357
- },
358
- preBalances: mapIndexerMatchEventBalances(matchEvent.pre_balance),
359
- postBalances,
360
- tx,
361
- isTaker: matchEvent.is_taker,
362
- realizedPnl: toBigNumber(matchEvent.realized_pnl),
363
- closedAmount: toBigNumber(matchEvent.closed_amount),
364
- closedNetEntry: toBigNumber(matchEvent.closed_net_entry),
365
- margin: matchEvent.margin ? toBigNumber(matchEvent.margin) : null,
366
- ...subaccountFromHex(matchEvent.order.sender)
367
- };
368
- });
369
- }
370
- /**
371
- * Retrieves historical funding & interest payments.
372
- * NOTE: `limit` is an upperbound. If a user changes position size such that his position is 0 during each funding/interest tick,
373
- * then the indexer will return fewer than `limit` results per page. However, more events can be present. This means that
374
- * there isn't a reliable way to determine whether there is a next page. We just need to keep paginating until the next cursor is null.
375
- *
376
- * @param params
377
- */
378
- async getInterestFundingPayments(params) {
379
- const baseResponse = await this.query("interest_and_funding", {
380
- subaccount: subaccountToHex({
381
- subaccountOwner: params.subaccount.subaccountOwner,
382
- subaccountName: params.subaccount.subaccountName
383
- }),
384
- product_ids: params.productIds,
385
- max_time: params.maxTimestampInclusive,
386
- limit: params.limit,
387
- max_idx: params.startCursor
388
- });
389
- return {
390
- fundingPayments: baseResponse.funding_payments.map(
391
- mapIndexerProductPayment
392
- ),
393
- interestPayments: baseResponse.interest_payments.map(
394
- mapIndexerProductPayment
395
- ),
396
- nextCursor: baseResponse.next_idx
397
- };
398
- }
399
- /**
400
- * Gets quote (USDT) price in terms of USD
401
- */
402
- async getQuotePrice() {
403
- const baseResponse = await this.query("quote_price", {});
404
- return {
405
- price: removeDecimals(baseResponse.price_x18)
406
- };
407
- }
408
- /**
409
- * Fetches currently registered linked signer with the remaining txs allowed for the subaccount
410
- */
411
- async getLinkedSignerWithRateLimit(params) {
412
- const baseResponse = await this.query("linked_signer_rate_limit", {
413
- subaccount: subaccountToHex(params.subaccount)
414
- });
415
- return {
416
- totalTxLimit: toBigNumber(baseResponse.total_tx_limit),
417
- remainingTxs: toBigNumber(baseResponse.remaining_tx),
418
- signer: baseResponse.signer,
419
- waitTimeUntilNextTx: toBigNumber(baseResponse.wait_time)
420
- };
421
- }
422
- /**
423
- * Retrieve historical market snapshots
424
- * @param params
425
- */
426
- async getMarketSnapshots(params) {
427
- const baseResponse = await this.query("market_snapshots", {
428
- interval: mapSnapshotsIntervalToServerParams(params),
429
- product_ids: params.productIds
430
- });
431
- return baseResponse.snapshots.map(mapIndexerMarketSnapshot);
432
- }
433
- /**
434
- * Retrieve historical market snapshots from Edge
435
- * @param params
436
- */
437
- async getEdgeMarketSnapshots(params) {
438
- const baseResponse = await this.query("edge_market_snapshots", {
439
- interval: mapSnapshotsIntervalToServerParams(params)
440
- });
441
- return mapValues(
442
- baseResponse.snapshots,
443
- (snapshots) => snapshots.map(mapIndexerMarketSnapshot)
444
- );
445
- }
446
- /**
447
- * Retrieve maker statistics for a given epoch
448
- *
449
- * @param params
450
- */
451
- async getMakerStatistics(params) {
452
- const baseResponse = await this.query("maker_statistics", {
453
- product_id: params.productId,
454
- epoch: params.epoch,
455
- interval: params.interval
456
- });
457
- return {
458
- rewardCoefficient: toBigNumber(baseResponse.reward_coefficient),
459
- makers: baseResponse.makers.map(mapIndexerMakerStatistics)
460
- };
461
- }
462
- /**
463
- * Retrieve leaderboard stats for a given contest
464
- *
465
- * @param params
466
- */
467
- async getLeaderboard(params) {
468
- const baseResponse = await this.query("leaderboard", {
469
- contest_id: params.contestId,
470
- rank_type: params.rankType,
471
- start: params.startCursor,
472
- limit: params.limit,
473
- order: params.order
474
- });
475
- return {
476
- participants: baseResponse.positions.map(mapIndexerLeaderboardPosition)
477
- };
478
- }
479
- /**
480
- * Retrieve leaderboard ranking of a subaccount on a given contest
481
- *
482
- * @param params
483
- */
484
- async getLeaderboardParticipant(params) {
485
- const baseResponse = await this.query("leaderboard_rank", {
486
- subaccount: subaccountToHex(params.subaccount),
487
- contest_ids: params.contestIds
488
- });
489
- return {
490
- participant: mapValues(
491
- baseResponse.positions,
492
- (position) => mapIndexerLeaderboardPosition(position)
493
- )
494
- };
495
- }
496
- /**
497
- * Registers a subaccount for one or more contests. Requires EIP-712 signing.
498
- *
499
- * @param params - Registration parameters including contest IDs and signing config.
500
- */
501
- async registerLeaderboard(params) {
502
- const signatureParams = {
503
- expiration: toIntegerString(params.recvTime ?? getDefaultRecvTime()),
504
- subaccountName: params.subaccountName,
505
- subaccountOwner: params.subaccountOwner,
506
- contestIds: params.contestIds
507
- };
508
- const tx = getNadoEIP712Values(
509
- "leaderboard_authentication",
510
- signatureParams
511
- );
512
- const signature = await this.sign(
513
- "leaderboard_authentication",
514
- params.verifyingAddr,
515
- params.chainId,
516
- signatureParams
517
- );
518
- const updateRegistrationTx = {
519
- tx,
520
- signature
521
- };
522
- const baseResponse = await this.query("leaderboard_register", {
523
- update_registration: updateRegistrationTx
524
- });
525
- return {
526
- registrations: baseResponse.registrations.map(
527
- mapIndexerLeaderboardRegistration
528
- )
529
- };
530
- }
531
- /**
532
- * Retrieves contest registrations for a subaccount. Supports batch lookup
533
- * across multiple contests with an optional active filter.
534
- *
535
- * @param params - Query parameters including subaccount and contest IDs.
536
- */
537
- async getLeaderboardRegistrations(params) {
538
- const baseResponse = await this.query("leaderboard_registrations", {
539
- subaccount: subaccountToHex(params.subaccount),
540
- contest_ids: params.contestIds,
541
- active: params.active
542
- });
543
- return {
544
- registrations: baseResponse.registrations.map(
545
- mapIndexerLeaderboardRegistration
546
- )
547
- };
548
- }
549
- /**
550
- * Retrieve metadata of provided leaderboard contests
551
- *
552
- * @param params
553
- */
554
- async getLeaderboardContests(params) {
555
- const baseResponse = await this.query("leaderboard_contests", {
556
- contest_ids: params.contestIds,
557
- active: params.active
558
- });
559
- return {
560
- contests: baseResponse.contests.map(mapIndexerLeaderboardContest)
561
- };
562
- }
563
- /**
564
- * Retrieve signature and tx to submit a fast withdrawal
565
- *
566
- * @param params
567
- */
568
- async getFastWithdrawalSignature(params) {
569
- const baseResponse = await this.query("fast_withdrawal_signature", params);
570
- return {
571
- idx: toBigInt(baseResponse.idx),
572
- tx: baseResponse.tx,
573
- txBytes: getValidatedHex(baseResponse.tx_bytes),
574
- signatures: baseResponse.signatures.map(getValidatedHex)
575
- };
576
- }
577
- async getNlpSnapshots(params) {
578
- const baseResponse = await this.query("nlp_snapshots", {
579
- interval: {
580
- count: params.limit,
581
- max_time: params.maxTimeInclusive ? toIntegerString(params.maxTimeInclusive) : void 0,
582
- granularity: params.granularity
583
- }
584
- });
585
- return {
586
- snapshots: baseResponse.snapshots.map(mapIndexerNlpSnapshot)
587
- };
588
- }
589
- /**
590
- * Retrieves the subaccount's DDA (Direct Deposit Address)
591
- * @param params
592
- */
593
- async getSubaccountDDA(params) {
594
- const baseResponse = await this.query("direct_deposit_address", {
595
- subaccount: subaccountToHex(params.subaccount)
596
- });
597
- return {
598
- address: getValidatedAddress(baseResponse.v1_address)
599
- };
600
- }
601
- async getSequencerBacklog() {
602
- const baseResponse = await this.query("backlog", {});
603
- return {
604
- totalTxs: toBigNumber(baseResponse.total_txs),
605
- totalSubmissions: toBigNumber(baseResponse.total_submissions),
606
- backlogSize: toBigNumber(baseResponse.backlog_size),
607
- updatedAt: toBigNumber(baseResponse.updated_at),
608
- backlogEtaInSeconds: baseResponse.backlog_eta_in_seconds ? toBigNumber(baseResponse.backlog_eta_in_seconds) : null,
609
- txsPerSecond: baseResponse.txs_per_second ? toBigNumber(baseResponse.txs_per_second) : null
610
- };
611
- }
612
- /**
613
- * Retrieves private alpha choice information for a given address
614
- * @param params
615
- */
616
- async getPrivateAlphaChoice(params) {
617
- const baseResponse = await this.query("private_alpha_choice", {
618
- address: params.address
619
- });
620
- return {
621
- points: toBigNumber(baseResponse.points),
622
- feeRefund: toBigNumber(baseResponse.fee_refund),
623
- nftEligibility: baseResponse.nft_eligibility
624
- };
625
- }
626
- /**
627
- * Retrieves points information for a given address, including points per epoch and all-time points
628
- * @param params
629
- */
630
- async getPoints(params) {
631
- const baseResponse = await this.query("nado_points", {
632
- address: params.address
633
- });
634
- return {
635
- pointsPerEpoch: baseResponse.points_per_epoch.map((epoch) => ({
636
- epoch: epoch.epoch,
637
- description: epoch.description,
638
- startTime: toBigNumber(epoch.start_time),
639
- endTime: toBigNumber(epoch.end_time),
640
- totalPoints: toBigNumber(epoch.total_points),
641
- points: toBigNumber(epoch.points),
642
- rank: epoch.rank,
643
- tier: epoch.tier
644
- })),
645
- allTimePoints: {
646
- points: toBigNumber(baseResponse.all_time_points.points),
647
- rank: baseResponse.all_time_points.rank,
648
- tier: baseResponse.all_time_points.tier
649
- }
650
- };
651
- }
652
- /**
653
- * Initiates a social account connection flow. Returns a URL the user must visit to complete the OAuth flow.
654
- * Requires EIP-712 signing.
655
- *
656
- * @param params - Connection parameters including provider and signing config.
657
- */
658
- async connectSocialAccount(params) {
659
- const signatureParams = {
660
- expiration: toIntegerString(params.recvTime ?? getDefaultRecvTime()),
661
- subaccountName: params.subaccountName,
662
- subaccountOwner: params.subaccountOwner,
663
- provider: params.provider
664
- };
665
- const tx = getNadoEIP712Values("social_authentication", signatureParams);
666
- const signature = await this.sign(
667
- "social_authentication",
668
- params.verifyingAddr,
669
- params.chainId,
670
- signatureParams
671
- );
672
- const baseResponse = await this.query("social_connect", {
673
- update_social_account: { tx, signature }
674
- });
675
- return { url: baseResponse.url };
676
- }
677
- /**
678
- * Lists linked social accounts for a given address.
679
- *
680
- * @param params - Query parameters including the wallet address.
681
- */
682
- async listSocialAccounts(params) {
683
- const baseResponse = await this.query("list_social_accounts", {
684
- address: params.address
685
- });
686
- return {
687
- accounts: baseResponse.accounts.map((a) => ({
688
- provider: a.provider,
689
- username: a.username,
690
- displayName: a.display_name,
691
- profileImageUrl: a.profile_image_url
692
- }))
693
- };
694
- }
695
- /**
696
- * Revokes a linked social account. Requires EIP-712 signing.
697
- *
698
- * @param params - Revocation parameters including provider and signing config.
699
- */
700
- async revokeSocialAccount(params) {
701
- const signatureParams = {
702
- expiration: toIntegerString(params.recvTime ?? getDefaultRecvTime()),
703
- subaccountName: params.subaccountName,
704
- subaccountOwner: params.subaccountOwner,
705
- provider: params.provider
706
- };
707
- const tx = getNadoEIP712Values("social_authentication", signatureParams);
708
- const signature = await this.sign(
709
- "social_authentication",
710
- params.verifyingAddr,
711
- params.chainId,
712
- signatureParams
713
- );
714
- const baseResponse = await this.query("revoke_social_account", {
715
- update_social_account: { tx, signature }
716
- });
717
- return {
718
- accounts: baseResponse.accounts.map((a) => ({
719
- provider: a.provider,
720
- username: a.username,
721
- displayName: a.display_name,
722
- profileImageUrl: a.profile_image_url
723
- }))
724
- };
725
- }
726
- /**
727
- * Get tickers from the v2 indexer endpoint
728
- * @param params
729
- */
730
- async getV2Tickers(params) {
731
- const response = await this.axiosInstance.get(
732
- `${this.v2Url}/tickers`,
733
- { params }
734
- );
735
- this.checkResponseStatus(response);
736
- return mapValues(response.data, mapIndexerV2Ticker);
737
- }
738
- /**
739
- * Get symbols with market hours from the v2 indexer endpoint
740
- * @param params
741
- */
742
- async getV2Symbols(params) {
743
- const response = await this.axiosInstance.get(
744
- `${this.v2Url}/symbols`,
745
- {
746
- params: {
747
- product_type: params?.productType,
748
- product_ids: params?.productIds
749
- }
750
- }
751
- );
752
- this.checkResponseStatus(response);
753
- return mapValues(response.data, mapIndexerV2Symbols);
754
- }
755
- async query(requestType, params) {
756
- const reqBody = {
757
- [requestType]: params
758
- };
759
- const response = await this.axiosInstance.post(this.opts.url, reqBody);
760
- this.checkResponseStatus(response);
761
- return response.data;
762
- }
763
- async sign(requestType, verifyingContract, chainId, params) {
764
- const walletClient = this.opts.linkedSignerWalletClient ?? this.opts.walletClient;
765
- if (!walletClient) {
766
- throw new WalletNotProvidedError();
767
- }
768
- return getSignedTransactionRequest({
769
- chainId,
770
- requestParams: params,
771
- requestType,
772
- walletClient,
773
- verifyingContract
774
- });
775
- }
776
- checkResponseStatus(response) {
777
- if (response.status !== 200 || !response.data) {
778
- throw Error(
779
- `Unexpected response from server: ${response.status} ${response.statusText}`
780
- );
781
- }
782
- }
783
- };
784
- export {
785
- IndexerBaseClient
9
+ constructor(opts) {
10
+ this.opts = opts;
11
+ this.axiosInstance = axios.create({
12
+ withCredentials: true,
13
+ validateStatus: () => true
14
+ });
15
+ this.v2Url = opts.v2Url ? opts.v2Url : opts.url.replace("v1", "v2");
16
+ }
17
+ /**
18
+ * Sets the linked signer for execute requests
19
+ *
20
+ * @param linkedSignerWalletClient The linkedSigner to use for all signatures. Set to null to revert to the chain signer
21
+ */
22
+ setLinkedSigner(linkedSignerWalletClient) {
23
+ this.opts.linkedSignerWalletClient = linkedSignerWalletClient ?? void 0;
24
+ }
25
+ /**
26
+ * List all subaccounts
27
+ *
28
+ * @param params
29
+ */
30
+ async listSubaccounts(params) {
31
+ return (await this.query("subaccounts", params)).subaccounts.map((item) => {
32
+ const subaccount = subaccountFromHex(item.subaccount);
33
+ return {
34
+ hexId: item.subaccount,
35
+ createdAt: Number(item.created_at),
36
+ isolated: item.isolated,
37
+ ...subaccount
38
+ };
39
+ });
40
+ }
41
+ /**
42
+ * Retrieve snapshots of multiple subaccounts at multiple points in time.
43
+ * Each snapshot is a view of the subaccount's balances at this point in time, with tracked variables for interest, funding, etc.
44
+ *
45
+ * @param params
46
+ */
47
+ async getMultiSubaccountSnapshots(params) {
48
+ const subaccountHexIds = params.subaccounts.map(({ subaccountOwner, subaccountName }) => subaccountToHex({
49
+ subaccountOwner,
50
+ subaccountName
51
+ }));
52
+ return {
53
+ subaccountHexIds,
54
+ snapshots: mapValues((await this.query("account_snapshots", {
55
+ subaccounts: subaccountHexIds,
56
+ timestamps: params.timestamps,
57
+ isolated: params.isolated
58
+ })).snapshots, (balanceSnapshots) => {
59
+ const snapshotByTimestamp = {};
60
+ Object.entries(balanceSnapshots).forEach(([timestamp, events]) => {
61
+ const balances = events.map(mapIndexerEvent);
62
+ snapshotByTimestamp[timestamp] = {
63
+ timestamp: toBigNumber(timestamp),
64
+ balances
65
+ };
66
+ });
67
+ return snapshotByTimestamp;
68
+ })
69
+ };
70
+ }
71
+ /**
72
+ * Retrieves referral code for an address
73
+ *
74
+ * @param params
75
+ */
76
+ async getReferralCode(params) {
77
+ return { referralCode: (await this.query("referral_code", { subaccount: subaccountToHex({
78
+ subaccountOwner: params.subaccount.subaccountOwner,
79
+ subaccountName: params.subaccount.subaccountName
80
+ }) })).referral_code };
81
+ }
82
+ /**
83
+ * Retrieves funding rate for a product, where 1 = 100%
84
+ * @param params
85
+ */
86
+ async getFundingRate(params) {
87
+ return mapIndexerFundingRate(await this.query("funding_rate", { product_id: params.productId }));
88
+ }
89
+ /**
90
+ * Retrieves funding rate for multiple products, where 1 = 100%
91
+ * @param params
92
+ */
93
+ async getMultiProductFundingRates(params) {
94
+ return mapValues(await this.query("funding_rates", { product_ids: params.productIds }), mapIndexerFundingRate);
95
+ }
96
+ /**
97
+ * Retrieves latest mark/index price for a perp product
98
+ * @param params
99
+ */
100
+ async getPerpPrices(params) {
101
+ return mapIndexerPerpPrices(await this.query("price", { product_id: params.productId }));
102
+ }
103
+ /**
104
+ * Retrieves latest mark/index price for multiple perp products
105
+ * @param params
106
+ */
107
+ async getMultiProductPerpPrices(params) {
108
+ return mapValues(await this.query("perp_prices", { product_ids: params.productIds }), mapIndexerPerpPrices);
109
+ }
110
+ /**
111
+ * Retrieves latest oracle prices for provided products
112
+ * @param params
113
+ */
114
+ async getOraclePrices(params) {
115
+ return (await this.query("oracle_price", { product_ids: params.productIds })).prices.map((price) => {
116
+ return {
117
+ oraclePrice: removeDecimals(price.oracle_price_x18),
118
+ updateTime: toBigNumber(price.update_time),
119
+ productId: price.product_id
120
+ };
121
+ });
122
+ }
123
+ /**
124
+ * Retrieves candlesticks for a product
125
+ * @param params
126
+ */
127
+ async getCandlesticks(params) {
128
+ return (await this.query("candlesticks", {
129
+ product_id: params.productId,
130
+ max_time: params.maxTimeInclusive,
131
+ limit: params.limit,
132
+ granularity: params.period
133
+ })).candlesticks.map(mapIndexerCandlesticks);
134
+ }
135
+ /**
136
+ * Retrieves candlesticks for a product from Edge
137
+ * @param params
138
+ */
139
+ async getEdgeCandlesticks(params) {
140
+ return (await this.query("edge_candlesticks", {
141
+ product_id: params.productId,
142
+ max_time: params.maxTimeInclusive,
143
+ limit: params.limit,
144
+ granularity: params.period
145
+ })).candlesticks.map(mapIndexerCandlesticks);
146
+ }
147
+ /**
148
+ * Retrieves historical snapshots for a product
149
+ * @param params
150
+ */
151
+ async getProductSnapshots(params) {
152
+ return (await this.query("products", {
153
+ product_id: params.productId,
154
+ max_time: params.maxTimestampInclusive,
155
+ limit: params.limit,
156
+ idx: params.startCursor
157
+ })).products.map((product) => {
158
+ return {
159
+ ...mapIndexerServerProduct(product.product),
160
+ submissionIndex: product.submission_idx
161
+ };
162
+ });
163
+ }
164
+ /**
165
+ * Retrieves historical snapshots for multiple products
166
+ * @param params
167
+ */
168
+ async getMultiProductSnapshots(params) {
169
+ return mapValues(await this.query("product_snapshots", {
170
+ product_ids: params.productIds,
171
+ max_time: params.maxTimestampInclusive ?? [nowInSeconds()]
172
+ }), (productIdToProduct) => {
173
+ return mapValues(productIdToProduct, (indexerProduct) => {
174
+ return {
175
+ ...mapIndexerServerProduct(indexerProduct.product),
176
+ submissionIndex: indexerProduct.submission_idx
177
+ };
178
+ });
179
+ });
180
+ }
181
+ /**
182
+ * Retrieves historical events
183
+ *
184
+ * @param params
185
+ */
186
+ async getEvents(params) {
187
+ const serverLimit = (() => {
188
+ if (!params.limit) return;
189
+ if (params.limit.type === "events") return { raw: params.limit.value };
190
+ return { txs: params.limit.value };
191
+ })();
192
+ const baseResponse = await this.query("events", {
193
+ subaccounts: params.subaccounts?.map((subaccount) => subaccountToHex({
194
+ subaccountOwner: subaccount.subaccountOwner,
195
+ subaccountName: subaccount.subaccountName
196
+ })),
197
+ product_ids: params.productIds,
198
+ isolated: params.isolated,
199
+ event_types: params.eventTypes,
200
+ max_time: params.maxTimestampInclusive,
201
+ desc: params.desc,
202
+ limit: serverLimit,
203
+ idx: params.startCursor
204
+ });
205
+ let lastTxIdx = 0;
206
+ return baseResponse.events.map((event) => {
207
+ if (baseResponse.txs[lastTxIdx].submission_idx !== event.submission_idx) lastTxIdx += 1;
208
+ const tx = baseResponse.txs[lastTxIdx];
209
+ return mapIndexerEventWithTx(event, tx);
210
+ });
211
+ }
212
+ /**
213
+ * Retrieves historical orders
214
+ * @param params
215
+ */
216
+ async getOrders(params) {
217
+ return (await this.query("orders", {
218
+ subaccounts: params?.subaccounts?.map((subaccount) => subaccountToHex({
219
+ subaccountOwner: subaccount.subaccountOwner,
220
+ subaccountName: subaccount.subaccountName
221
+ })),
222
+ product_ids: params.productIds,
223
+ trigger_types: params.triggerTypes,
224
+ isolated: params.isolated,
225
+ digests: params.digests,
226
+ max_time: params.maxTimestampInclusive,
227
+ limit: params.limit,
228
+ idx: params.startCursor
229
+ })).orders.map(mapIndexerOrder);
230
+ }
231
+ /**
232
+ * Gets match order events, this will return the same events as the events query, but with additional information
233
+ * to identify the order that was matched
234
+ *
235
+ * @param params
236
+ */
237
+ async getMatchEvents(params) {
238
+ const baseResponse = await this.query("matches", {
239
+ subaccounts: params?.subaccounts?.map((subaccount) => subaccountToHex({
240
+ subaccountOwner: subaccount.subaccountOwner,
241
+ subaccountName: subaccount.subaccountName
242
+ })),
243
+ product_ids: params.productIds,
244
+ isolated: params.isolated,
245
+ max_time: params.maxTimestampInclusive,
246
+ limit: params.limit,
247
+ idx: params.startCursor
248
+ });
249
+ let lastTxIdx = 0;
250
+ return baseResponse.matches.map((matchEvent) => {
251
+ if (baseResponse.txs[lastTxIdx].submission_idx !== matchEvent.submission_idx) lastTxIdx += 1;
252
+ const { tx, timestamp } = baseResponse.txs[lastTxIdx];
253
+ const postBalances = mapIndexerMatchEventBalances(matchEvent.post_balance);
254
+ return {
255
+ productId: postBalances.base.productId,
256
+ isolated: matchEvent.isolated,
257
+ totalFee: toBigNumber(matchEvent.fee),
258
+ sequencerFee: toBigNumber(matchEvent.sequencer_fee),
259
+ builderFee: toBigNumber(matchEvent.builder_fee),
260
+ baseFilled: toBigNumber(matchEvent.base_filled),
261
+ quoteFilled: toBigNumber(matchEvent.quote_filled),
262
+ cumulativeFee: toBigNumber(matchEvent.cumulative_fee),
263
+ cumulativeBaseFilled: toBigNumber(matchEvent.cumulative_base_filled),
264
+ cumulativeQuoteFilled: toBigNumber(matchEvent.cumulative_quote_filled),
265
+ digest: matchEvent.digest,
266
+ order: matchEvent.order,
267
+ submissionIndex: matchEvent.submission_idx,
268
+ timestamp: toBigNumber(timestamp),
269
+ preEventTrackedVars: {
270
+ netEntryUnrealized: toBigNumber(matchEvent.net_entry_unrealized),
271
+ netEntryCumulative: toBigNumber(matchEvent.net_entry_cumulative)
272
+ },
273
+ preBalances: mapIndexerMatchEventBalances(matchEvent.pre_balance),
274
+ postBalances,
275
+ tx,
276
+ isTaker: matchEvent.is_taker,
277
+ realizedPnl: toBigNumber(matchEvent.realized_pnl),
278
+ closedAmount: toBigNumber(matchEvent.closed_amount),
279
+ closedNetEntry: toBigNumber(matchEvent.closed_net_entry),
280
+ margin: matchEvent.margin ? toBigNumber(matchEvent.margin) : null,
281
+ ...subaccountFromHex(matchEvent.order.sender)
282
+ };
283
+ });
284
+ }
285
+ /**
286
+ * Retrieves historical funding & interest payments.
287
+ * NOTE: `limit` is an upperbound. If a user changes position size such that his position is 0 during each funding/interest tick,
288
+ * then the indexer will return fewer than `limit` results per page. However, more events can be present. This means that
289
+ * there isn't a reliable way to determine whether there is a next page. We just need to keep paginating until the next cursor is null.
290
+ *
291
+ * @param params
292
+ */
293
+ async getInterestFundingPayments(params) {
294
+ const baseResponse = await this.query("interest_and_funding", {
295
+ subaccount: subaccountToHex({
296
+ subaccountOwner: params.subaccount.subaccountOwner,
297
+ subaccountName: params.subaccount.subaccountName
298
+ }),
299
+ product_ids: params.productIds,
300
+ max_time: params.maxTimestampInclusive,
301
+ limit: params.limit,
302
+ max_idx: params.startCursor
303
+ });
304
+ return {
305
+ fundingPayments: baseResponse.funding_payments.map(mapIndexerProductPayment),
306
+ interestPayments: baseResponse.interest_payments.map(mapIndexerProductPayment),
307
+ nextCursor: baseResponse.next_idx
308
+ };
309
+ }
310
+ /**
311
+ * Gets quote (USDT) price in terms of USD
312
+ */
313
+ async getQuotePrice() {
314
+ return { price: removeDecimals((await this.query("quote_price", {})).price_x18) };
315
+ }
316
+ /**
317
+ * Fetches currently registered linked signer with the remaining txs allowed for the subaccount
318
+ */
319
+ async getLinkedSignerWithRateLimit(params) {
320
+ const baseResponse = await this.query("linked_signer_rate_limit", { subaccount: subaccountToHex(params.subaccount) });
321
+ return {
322
+ totalTxLimit: toBigNumber(baseResponse.total_tx_limit),
323
+ remainingTxs: toBigNumber(baseResponse.remaining_tx),
324
+ signer: baseResponse.signer,
325
+ waitTimeUntilNextTx: toBigNumber(baseResponse.wait_time)
326
+ };
327
+ }
328
+ /**
329
+ * Retrieve historical market snapshots
330
+ * @param params
331
+ */
332
+ async getMarketSnapshots(params) {
333
+ return (await this.query("market_snapshots", {
334
+ interval: mapSnapshotsIntervalToServerParams(params),
335
+ product_ids: params.productIds
336
+ })).snapshots.map(mapIndexerMarketSnapshot);
337
+ }
338
+ /**
339
+ * Retrieve historical market snapshots from Edge
340
+ * @param params
341
+ */
342
+ async getEdgeMarketSnapshots(params) {
343
+ return mapValues((await this.query("edge_market_snapshots", { interval: mapSnapshotsIntervalToServerParams(params) })).snapshots, (snapshots) => snapshots.map(mapIndexerMarketSnapshot));
344
+ }
345
+ /**
346
+ * Retrieve maker statistics for a given epoch
347
+ *
348
+ * @param params
349
+ */
350
+ async getMakerStatistics(params) {
351
+ const baseResponse = await this.query("maker_statistics", {
352
+ product_id: params.productId,
353
+ epoch: params.epoch,
354
+ interval: params.interval
355
+ });
356
+ return {
357
+ rewardCoefficient: toBigNumber(baseResponse.reward_coefficient),
358
+ makers: baseResponse.makers.map(mapIndexerMakerStatistics)
359
+ };
360
+ }
361
+ /**
362
+ * Retrieve leaderboard stats for a given contest
363
+ *
364
+ * @param params
365
+ */
366
+ async getLeaderboard(params) {
367
+ return { participants: (await this.query("leaderboard", {
368
+ contest_id: params.contestId,
369
+ rank_type: params.rankType,
370
+ start: params.startCursor,
371
+ limit: params.limit,
372
+ order: params.order
373
+ })).positions.map(mapIndexerLeaderboardPosition) };
374
+ }
375
+ /**
376
+ * Retrieve leaderboard ranking of a subaccount on a given contest
377
+ *
378
+ * @param params
379
+ */
380
+ async getLeaderboardParticipant(params) {
381
+ return { participant: mapValues((await this.query("leaderboard_rank", {
382
+ subaccount: subaccountToHex(params.subaccount),
383
+ contest_ids: params.contestIds
384
+ })).positions, (position) => mapIndexerLeaderboardPosition(position)) };
385
+ }
386
+ /**
387
+ * Registers a subaccount for one or more contests. Requires EIP-712 signing.
388
+ *
389
+ * @param params - Registration parameters including contest IDs and signing config.
390
+ */
391
+ async registerLeaderboard(params) {
392
+ const signatureParams = {
393
+ expiration: toIntegerString(params.recvTime ?? getDefaultRecvTime()),
394
+ subaccountName: params.subaccountName,
395
+ subaccountOwner: params.subaccountOwner,
396
+ contestIds: params.contestIds
397
+ };
398
+ const updateRegistrationTx = {
399
+ tx: getNadoEIP712Values("leaderboard_authentication", signatureParams),
400
+ signature: await this.sign("leaderboard_authentication", params.verifyingAddr, params.chainId, signatureParams)
401
+ };
402
+ return { registrations: (await this.query("leaderboard_register", { update_registration: updateRegistrationTx })).registrations.map(mapIndexerLeaderboardRegistration) };
403
+ }
404
+ /**
405
+ * Retrieves contest registrations for a subaccount. Supports batch lookup
406
+ * across multiple contests with an optional active filter.
407
+ *
408
+ * @param params - Query parameters including subaccount and contest IDs.
409
+ */
410
+ async getLeaderboardRegistrations(params) {
411
+ return { registrations: (await this.query("leaderboard_registrations", {
412
+ subaccount: subaccountToHex(params.subaccount),
413
+ contest_ids: params.contestIds,
414
+ active: params.active
415
+ })).registrations.map(mapIndexerLeaderboardRegistration) };
416
+ }
417
+ /**
418
+ * Retrieve metadata of provided leaderboard contests
419
+ *
420
+ * @param params
421
+ */
422
+ async getLeaderboardContests(params) {
423
+ return { contests: (await this.query("leaderboard_contests", {
424
+ contest_ids: params.contestIds,
425
+ active: params.active
426
+ })).contests.map(mapIndexerLeaderboardContest) };
427
+ }
428
+ /**
429
+ * Retrieve signature and tx to submit a fast withdrawal
430
+ *
431
+ * @param params
432
+ */
433
+ async getFastWithdrawalSignature(params) {
434
+ const baseResponse = await this.query("fast_withdrawal_signature", params);
435
+ return {
436
+ idx: toBigInt(baseResponse.idx),
437
+ tx: baseResponse.tx,
438
+ txBytes: getValidatedHex(baseResponse.tx_bytes),
439
+ signatures: baseResponse.signatures.map(getValidatedHex)
440
+ };
441
+ }
442
+ async getNlpSnapshots(params) {
443
+ return { snapshots: (await this.query("nlp_snapshots", { interval: {
444
+ count: params.limit,
445
+ max_time: params.maxTimeInclusive ? toIntegerString(params.maxTimeInclusive) : void 0,
446
+ granularity: params.granularity
447
+ } })).snapshots.map(mapIndexerNlpSnapshot) };
448
+ }
449
+ /**
450
+ * Retrieves the subaccount's DDA (Direct Deposit Address)
451
+ * @param params
452
+ */
453
+ async getSubaccountDDA(params) {
454
+ return { address: getValidatedAddress((await this.query("direct_deposit_address", { subaccount: subaccountToHex(params.subaccount) })).v1_address) };
455
+ }
456
+ async getSequencerBacklog() {
457
+ const baseResponse = await this.query("backlog", {});
458
+ return {
459
+ totalTxs: toBigNumber(baseResponse.total_txs),
460
+ totalSubmissions: toBigNumber(baseResponse.total_submissions),
461
+ backlogSize: toBigNumber(baseResponse.backlog_size),
462
+ updatedAt: toBigNumber(baseResponse.updated_at),
463
+ backlogEtaInSeconds: baseResponse.backlog_eta_in_seconds ? toBigNumber(baseResponse.backlog_eta_in_seconds) : null,
464
+ txsPerSecond: baseResponse.txs_per_second ? toBigNumber(baseResponse.txs_per_second) : null
465
+ };
466
+ }
467
+ /**
468
+ * Retrieves private alpha choice information for a given address
469
+ * @param params
470
+ */
471
+ async getPrivateAlphaChoice(params) {
472
+ const baseResponse = await this.query("private_alpha_choice", { address: params.address });
473
+ return {
474
+ points: toBigNumber(baseResponse.points),
475
+ feeRefund: toBigNumber(baseResponse.fee_refund),
476
+ nftEligibility: baseResponse.nft_eligibility
477
+ };
478
+ }
479
+ /**
480
+ * Retrieves points information for a given address, including points per epoch and all-time points
481
+ * @param params
482
+ */
483
+ async getPoints(params) {
484
+ const baseResponse = await this.query("nado_points", { address: params.address });
485
+ return {
486
+ pointsPerEpoch: baseResponse.points_per_epoch.map((epoch) => ({
487
+ epoch: epoch.epoch,
488
+ description: epoch.description,
489
+ startTime: toBigNumber(epoch.start_time),
490
+ endTime: toBigNumber(epoch.end_time),
491
+ totalPoints: toBigNumber(epoch.total_points),
492
+ points: toBigNumber(epoch.points),
493
+ rank: epoch.rank,
494
+ tier: epoch.tier
495
+ })),
496
+ allTimePoints: {
497
+ points: toBigNumber(baseResponse.all_time_points.points),
498
+ rank: baseResponse.all_time_points.rank,
499
+ tier: baseResponse.all_time_points.tier
500
+ }
501
+ };
502
+ }
503
+ /**
504
+ * Initiates a social account connection flow. Returns a URL the user must visit to complete the OAuth flow.
505
+ * Requires EIP-712 signing.
506
+ *
507
+ * @param params - Connection parameters including provider and signing config.
508
+ */
509
+ async connectSocialAccount(params) {
510
+ const signatureParams = {
511
+ expiration: toIntegerString(params.recvTime ?? getDefaultRecvTime()),
512
+ subaccountName: params.subaccountName,
513
+ subaccountOwner: params.subaccountOwner,
514
+ provider: params.provider
515
+ };
516
+ const tx = getNadoEIP712Values("social_authentication", signatureParams);
517
+ const signature = await this.sign("social_authentication", params.verifyingAddr, params.chainId, signatureParams);
518
+ return { url: (await this.query("social_connect", { update_social_account: {
519
+ tx,
520
+ signature
521
+ } })).url };
522
+ }
523
+ /**
524
+ * Lists linked social accounts for a given address.
525
+ *
526
+ * @param params - Query parameters including the wallet address.
527
+ */
528
+ async listSocialAccounts(params) {
529
+ return { accounts: (await this.query("list_social_accounts", { address: params.address })).accounts.map((a) => ({
530
+ provider: a.provider,
531
+ username: a.username,
532
+ displayName: a.display_name,
533
+ profileImageUrl: a.profile_image_url
534
+ })) };
535
+ }
536
+ /**
537
+ * Revokes a linked social account. Requires EIP-712 signing.
538
+ *
539
+ * @param params - Revocation parameters including provider and signing config.
540
+ */
541
+ async revokeSocialAccount(params) {
542
+ const signatureParams = {
543
+ expiration: toIntegerString(params.recvTime ?? getDefaultRecvTime()),
544
+ subaccountName: params.subaccountName,
545
+ subaccountOwner: params.subaccountOwner,
546
+ provider: params.provider
547
+ };
548
+ const tx = getNadoEIP712Values("social_authentication", signatureParams);
549
+ const signature = await this.sign("social_authentication", params.verifyingAddr, params.chainId, signatureParams);
550
+ return { accounts: (await this.query("revoke_social_account", { update_social_account: {
551
+ tx,
552
+ signature
553
+ } })).accounts.map((a) => ({
554
+ provider: a.provider,
555
+ username: a.username,
556
+ displayName: a.display_name,
557
+ profileImageUrl: a.profile_image_url
558
+ })) };
559
+ }
560
+ /**
561
+ * Get tickers from the v2 indexer endpoint
562
+ * @param params
563
+ */
564
+ async getV2Tickers(params) {
565
+ const response = await this.axiosInstance.get(`${this.v2Url}/tickers`, { params });
566
+ this.checkResponseStatus(response);
567
+ return mapValues(response.data, mapIndexerV2Ticker);
568
+ }
569
+ /**
570
+ * Get symbols with market hours from the v2 indexer endpoint
571
+ * @param params
572
+ */
573
+ async getV2Symbols(params) {
574
+ const response = await this.axiosInstance.get(`${this.v2Url}/symbols`, { params: {
575
+ product_type: params?.productType,
576
+ product_ids: params?.productIds
577
+ } });
578
+ this.checkResponseStatus(response);
579
+ return mapValues(response.data, mapIndexerV2Symbols);
580
+ }
581
+ async query(requestType, params) {
582
+ const reqBody = { [requestType]: params };
583
+ const response = await this.axiosInstance.post(this.opts.url, reqBody);
584
+ this.checkResponseStatus(response);
585
+ return response.data;
586
+ }
587
+ async sign(requestType, verifyingContract, chainId, params) {
588
+ const walletClient = this.opts.linkedSignerWalletClient ?? this.opts.walletClient;
589
+ if (!walletClient) throw new WalletNotProvidedError();
590
+ return getSignedTransactionRequest({
591
+ chainId,
592
+ requestParams: params,
593
+ requestType,
594
+ walletClient,
595
+ verifyingContract
596
+ });
597
+ }
598
+ checkResponseStatus(response) {
599
+ if (response.status !== 200 || !response.data) throw Error(`Unexpected response from server: ${response.status} ${response.statusText}`);
600
+ }
786
601
  };
602
+ //#endregion
603
+ export { IndexerBaseClient };
604
+
787
605
  //# sourceMappingURL=IndexerBaseClient.js.map