@nadohq/indexer-client 0.1.0-alpha.1
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/README.md +2 -0
- package/dist/IndexerBaseClient.cjs +608 -0
- package/dist/IndexerBaseClient.cjs.map +1 -0
- package/dist/IndexerBaseClient.d.cts +183 -0
- package/dist/IndexerBaseClient.d.ts +183 -0
- package/dist/IndexerBaseClient.js +605 -0
- package/dist/IndexerBaseClient.js.map +1 -0
- package/dist/IndexerClient.cjs +368 -0
- package/dist/IndexerClient.cjs.map +1 -0
- package/dist/IndexerClient.d.cts +50 -0
- package/dist/IndexerClient.d.ts +50 -0
- package/dist/IndexerClient.js +348 -0
- package/dist/IndexerClient.js.map +1 -0
- package/dist/dataMappers.cjs +324 -0
- package/dist/dataMappers.cjs.map +1 -0
- package/dist/dataMappers.d.cts +31 -0
- package/dist/dataMappers.d.ts +31 -0
- package/dist/dataMappers.js +296 -0
- package/dist/dataMappers.js.map +1 -0
- package/dist/endpoints.cjs +35 -0
- package/dist/endpoints.cjs.map +1 -0
- package/dist/endpoints.d.cts +5 -0
- package/dist/endpoints.d.ts +5 -0
- package/dist/endpoints.js +10 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/index.cjs +31 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/types/CandlestickPeriod.cjs +42 -0
- package/dist/types/CandlestickPeriod.cjs.map +1 -0
- package/dist/types/CandlestickPeriod.d.cts +13 -0
- package/dist/types/CandlestickPeriod.d.ts +13 -0
- package/dist/types/CandlestickPeriod.js +17 -0
- package/dist/types/CandlestickPeriod.js.map +1 -0
- package/dist/types/IndexerEventType.cjs +19 -0
- package/dist/types/IndexerEventType.cjs.map +1 -0
- package/dist/types/IndexerEventType.d.cts +3 -0
- package/dist/types/IndexerEventType.d.ts +3 -0
- package/dist/types/IndexerEventType.js +1 -0
- package/dist/types/IndexerEventType.js.map +1 -0
- package/dist/types/IndexerLeaderboardType.cjs +19 -0
- package/dist/types/IndexerLeaderboardType.cjs.map +1 -0
- package/dist/types/IndexerLeaderboardType.d.cts +3 -0
- package/dist/types/IndexerLeaderboardType.d.ts +3 -0
- package/dist/types/IndexerLeaderboardType.js +1 -0
- package/dist/types/IndexerLeaderboardType.js.map +1 -0
- package/dist/types/NadoTx.cjs +19 -0
- package/dist/types/NadoTx.cjs.map +1 -0
- package/dist/types/NadoTx.d.cts +49 -0
- package/dist/types/NadoTx.d.ts +49 -0
- package/dist/types/NadoTx.js +1 -0
- package/dist/types/NadoTx.js.map +1 -0
- package/dist/types/clientTypes.cjs +19 -0
- package/dist/types/clientTypes.cjs.map +1 -0
- package/dist/types/clientTypes.d.cts +467 -0
- package/dist/types/clientTypes.d.ts +467 -0
- package/dist/types/clientTypes.js +1 -0
- package/dist/types/clientTypes.js.map +1 -0
- package/dist/types/collateralEventType.cjs +19 -0
- package/dist/types/collateralEventType.cjs.map +1 -0
- package/dist/types/collateralEventType.d.cts +3 -0
- package/dist/types/collateralEventType.d.ts +3 -0
- package/dist/types/collateralEventType.js +1 -0
- package/dist/types/collateralEventType.js.map +1 -0
- package/dist/types/index.cjs +41 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +13 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/paginatedEventsTypes.cjs +19 -0
- package/dist/types/paginatedEventsTypes.cjs.map +1 -0
- package/dist/types/paginatedEventsTypes.d.cts +115 -0
- package/dist/types/paginatedEventsTypes.d.ts +115 -0
- package/dist/types/paginatedEventsTypes.js +1 -0
- package/dist/types/paginatedEventsTypes.js.map +1 -0
- package/dist/types/serverModelTypes.cjs +19 -0
- package/dist/types/serverModelTypes.cjs.map +1 -0
- package/dist/types/serverModelTypes.d.cts +224 -0
- package/dist/types/serverModelTypes.d.ts +224 -0
- package/dist/types/serverModelTypes.js +1 -0
- package/dist/types/serverModelTypes.js.map +1 -0
- package/dist/types/serverTypes.cjs +19 -0
- package/dist/types/serverTypes.cjs.map +1 -0
- package/dist/types/serverTypes.d.cts +304 -0
- package/dist/types/serverTypes.d.ts +304 -0
- package/dist/types/serverTypes.js +1 -0
- package/dist/types/serverTypes.js.map +1 -0
- package/dist/utils/index.cjs +25 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +12 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/indexerBalanceValue.cjs +43 -0
- package/dist/utils/indexerBalanceValue.cjs.map +1 -0
- package/dist/utils/indexerBalanceValue.d.cts +39 -0
- package/dist/utils/indexerBalanceValue.d.ts +39 -0
- package/dist/utils/indexerBalanceValue.js +16 -0
- package/dist/utils/indexerBalanceValue.js.map +1 -0
- package/package.json +53 -0
- package/src/IndexerBaseClient.ts +851 -0
- package/src/IndexerClient.ts +468 -0
- package/src/dataMappers.ts +362 -0
- package/src/endpoints.ts +7 -0
- package/src/index.ts +4 -0
- package/src/types/CandlestickPeriod.ts +11 -0
- package/src/types/IndexerEventType.ts +9 -0
- package/src/types/IndexerLeaderboardType.ts +2 -0
- package/src/types/NadoTx.ts +63 -0
- package/src/types/clientTypes.ts +679 -0
- package/src/types/collateralEventType.ts +4 -0
- package/src/types/index.ts +9 -0
- package/src/types/paginatedEventsTypes.ts +194 -0
- package/src/types/serverModelTypes.ts +271 -0
- package/src/types/serverTypes.ts +427 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/indexerBalanceValue.ts +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/IndexerBaseClient.ts
|
|
31
|
+
var IndexerBaseClient_exports = {};
|
|
32
|
+
__export(IndexerBaseClient_exports, {
|
|
33
|
+
IndexerBaseClient: () => IndexerBaseClient
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(IndexerBaseClient_exports);
|
|
36
|
+
var import_contracts = require("@nadohq/contracts");
|
|
37
|
+
var import_utils = require("@nadohq/utils");
|
|
38
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
39
|
+
var import_dataMappers = require("./dataMappers.cjs");
|
|
40
|
+
var IndexerBaseClient = class {
|
|
41
|
+
constructor(opts) {
|
|
42
|
+
this.opts = opts;
|
|
43
|
+
this.axiosInstance = import_axios.default.create({
|
|
44
|
+
withCredentials: true
|
|
45
|
+
});
|
|
46
|
+
this.v2Url = opts.v2Url ? opts.v2Url : opts.url.replace("v1", "v2");
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* List all subaccounts
|
|
50
|
+
*
|
|
51
|
+
* @param params
|
|
52
|
+
*/
|
|
53
|
+
async listSubaccounts(params) {
|
|
54
|
+
const baseResponse = await this.query("subaccounts", params);
|
|
55
|
+
return baseResponse.subaccounts.map((item) => {
|
|
56
|
+
const subaccount = (0, import_contracts.subaccountFromHex)(item.subaccount);
|
|
57
|
+
return {
|
|
58
|
+
hexId: item.subaccount,
|
|
59
|
+
...subaccount
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Retrieve snapshots of multiple subaccounts at multiple points in time.
|
|
65
|
+
* Each snapshot is a view of the subaccount's balances at this point in time, with tracked variables for interest, funding, etc.
|
|
66
|
+
*
|
|
67
|
+
* @param params
|
|
68
|
+
*/
|
|
69
|
+
async getMultiSubaccountSnapshots(params) {
|
|
70
|
+
const subaccountHexIds = params.subaccounts.map(
|
|
71
|
+
({ subaccountOwner, subaccountName }) => (0, import_contracts.subaccountToHex)({
|
|
72
|
+
subaccountOwner,
|
|
73
|
+
subaccountName
|
|
74
|
+
})
|
|
75
|
+
);
|
|
76
|
+
const baseResponse = await this.query("account_snapshots", {
|
|
77
|
+
subaccounts: subaccountHexIds,
|
|
78
|
+
timestamps: params.timestamps,
|
|
79
|
+
isolated: params.isolated
|
|
80
|
+
});
|
|
81
|
+
const snapshotsBySubaccount = (0, import_utils.mapValues)(
|
|
82
|
+
baseResponse.snapshots,
|
|
83
|
+
(balanceSnapshots) => {
|
|
84
|
+
const snapshotByTimestamp = {};
|
|
85
|
+
Object.entries(balanceSnapshots).forEach(([timestamp, events]) => {
|
|
86
|
+
const balances = events.map(import_dataMappers.mapIndexerEvent);
|
|
87
|
+
snapshotByTimestamp[timestamp] = {
|
|
88
|
+
timestamp: (0, import_utils.toBigDecimal)(timestamp),
|
|
89
|
+
balances
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
return snapshotByTimestamp;
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
return {
|
|
96
|
+
subaccountHexIds,
|
|
97
|
+
snapshots: snapshotsBySubaccount
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Retrieves referral code for an address
|
|
102
|
+
*
|
|
103
|
+
* @param params
|
|
104
|
+
*/
|
|
105
|
+
async getReferralCode(params) {
|
|
106
|
+
const baseResponse = await this.query("referral_code", {
|
|
107
|
+
subaccount: (0, import_contracts.subaccountToHex)({
|
|
108
|
+
subaccountOwner: params.subaccount.subaccountOwner,
|
|
109
|
+
subaccountName: params.subaccount.subaccountName
|
|
110
|
+
})
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
referralCode: baseResponse.referral_code
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Retrieves funding rate for a product, where 1 = 100%
|
|
118
|
+
* @param params
|
|
119
|
+
*/
|
|
120
|
+
async getFundingRate(params) {
|
|
121
|
+
const baseResponse = await this.query("funding_rate", {
|
|
122
|
+
product_id: params.productId
|
|
123
|
+
});
|
|
124
|
+
return (0, import_dataMappers.mapIndexerFundingRate)(baseResponse);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Retrieves funding rate for multiple products, where 1 = 100%
|
|
128
|
+
* @param params
|
|
129
|
+
*/
|
|
130
|
+
async getMultiProductFundingRates(params) {
|
|
131
|
+
const baseResponse = await this.query("funding_rates", {
|
|
132
|
+
product_ids: params.productIds
|
|
133
|
+
});
|
|
134
|
+
return (0, import_utils.mapValues)(baseResponse, import_dataMappers.mapIndexerFundingRate);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Retrieves latest mark/index price for a perp product
|
|
138
|
+
* @param params
|
|
139
|
+
*/
|
|
140
|
+
async getPerpPrices(params) {
|
|
141
|
+
const baseResponse = await this.query("price", {
|
|
142
|
+
product_id: params.productId
|
|
143
|
+
});
|
|
144
|
+
return (0, import_dataMappers.mapIndexerPerpPrices)(baseResponse);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Retrieves latest mark/index price for multiple perp products
|
|
148
|
+
* @param params
|
|
149
|
+
*/
|
|
150
|
+
async getMultiProductPerpPrices(params) {
|
|
151
|
+
const baseResponse = await this.query("perp_prices", {
|
|
152
|
+
product_ids: params.productIds
|
|
153
|
+
});
|
|
154
|
+
return (0, import_utils.mapValues)(baseResponse, import_dataMappers.mapIndexerPerpPrices);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Retrieves latest oracle prices for provided products
|
|
158
|
+
* @param params
|
|
159
|
+
*/
|
|
160
|
+
async getOraclePrices(params) {
|
|
161
|
+
const baseResponse = await this.query("oracle_price", {
|
|
162
|
+
product_ids: params.productIds
|
|
163
|
+
});
|
|
164
|
+
return baseResponse.prices.map((price) => {
|
|
165
|
+
return {
|
|
166
|
+
oraclePrice: (0, import_utils.removeDecimals)(price.oracle_price_x18),
|
|
167
|
+
updateTime: (0, import_utils.toBigDecimal)(price.update_time),
|
|
168
|
+
productId: price.product_id
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Retrieves candlesticks for a product
|
|
174
|
+
* @param params
|
|
175
|
+
*/
|
|
176
|
+
async getCandlesticks(params) {
|
|
177
|
+
const baseResponse = await this.query("candlesticks", {
|
|
178
|
+
product_id: params.productId,
|
|
179
|
+
max_time: params.maxTimeInclusive,
|
|
180
|
+
limit: params.limit,
|
|
181
|
+
granularity: params.period
|
|
182
|
+
});
|
|
183
|
+
return baseResponse.candlesticks.map(import_dataMappers.mapIndexerCandlesticks);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Retrieves candlesticks for a product from Edge
|
|
187
|
+
* @param params
|
|
188
|
+
*/
|
|
189
|
+
async getEdgeCandlesticks(params) {
|
|
190
|
+
const baseResponse = await this.query("edge_candlesticks", {
|
|
191
|
+
product_id: params.productId,
|
|
192
|
+
max_time: params.maxTimeInclusive,
|
|
193
|
+
limit: params.limit,
|
|
194
|
+
granularity: params.period
|
|
195
|
+
});
|
|
196
|
+
return baseResponse.candlesticks.map(import_dataMappers.mapIndexerCandlesticks);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Retrieves historical snapshots for a product
|
|
200
|
+
* @param params
|
|
201
|
+
*/
|
|
202
|
+
async getProductSnapshots(params) {
|
|
203
|
+
const baseResponse = await this.query("products", {
|
|
204
|
+
product_id: params.productId,
|
|
205
|
+
max_time: params.maxTimestampInclusive,
|
|
206
|
+
limit: params.limit,
|
|
207
|
+
idx: params.startCursor
|
|
208
|
+
});
|
|
209
|
+
return baseResponse.products.map((product) => {
|
|
210
|
+
return {
|
|
211
|
+
...(0, import_dataMappers.mapIndexerServerProduct)(product.product),
|
|
212
|
+
submissionIndex: product.submission_idx
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Retrieves historical snapshots for multiple products
|
|
218
|
+
* @param params
|
|
219
|
+
*/
|
|
220
|
+
async getMultiProductSnapshots(params) {
|
|
221
|
+
const timestampToProductsMap = await this.query("product_snapshots", {
|
|
222
|
+
product_ids: params.productIds,
|
|
223
|
+
max_time: params.maxTimestampInclusive ?? [(0, import_utils.nowInSeconds)()]
|
|
224
|
+
});
|
|
225
|
+
return (0, import_utils.mapValues)(timestampToProductsMap, (productIdToProduct) => {
|
|
226
|
+
return (0, import_utils.mapValues)(productIdToProduct, (indexerProduct) => {
|
|
227
|
+
return {
|
|
228
|
+
...(0, import_dataMappers.mapIndexerServerProduct)(indexerProduct.product),
|
|
229
|
+
submissionIndex: indexerProduct.submission_idx
|
|
230
|
+
};
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Retrieves historical events
|
|
236
|
+
*
|
|
237
|
+
* @param params
|
|
238
|
+
*/
|
|
239
|
+
async getEvents(params) {
|
|
240
|
+
const serverLimit = (() => {
|
|
241
|
+
if (!params.limit) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (params.limit.type === "events") {
|
|
245
|
+
return {
|
|
246
|
+
raw: params.limit.value
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
txs: params.limit.value
|
|
251
|
+
};
|
|
252
|
+
})();
|
|
253
|
+
const baseResponse = await this.query("events", {
|
|
254
|
+
subaccount: params.subaccount ? (0, import_contracts.subaccountToHex)({
|
|
255
|
+
subaccountOwner: params.subaccount.subaccountOwner,
|
|
256
|
+
subaccountName: params.subaccount.subaccountName
|
|
257
|
+
}) : void 0,
|
|
258
|
+
product_ids: params.productIds,
|
|
259
|
+
isolated: params.isolated,
|
|
260
|
+
event_types: params.eventTypes,
|
|
261
|
+
max_time: params.maxTimestampInclusive,
|
|
262
|
+
desc: params.desc,
|
|
263
|
+
limit: serverLimit,
|
|
264
|
+
idx: params.startCursor
|
|
265
|
+
});
|
|
266
|
+
let lastTxIdx = 0;
|
|
267
|
+
return baseResponse.events.map((event) => {
|
|
268
|
+
if (baseResponse.txs[lastTxIdx].submission_idx !== event.submission_idx) {
|
|
269
|
+
lastTxIdx += 1;
|
|
270
|
+
}
|
|
271
|
+
const tx = baseResponse.txs[lastTxIdx];
|
|
272
|
+
return (0, import_dataMappers.mapIndexerEventWithTx)(event, tx);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Retrieves historical orders
|
|
277
|
+
* @param params
|
|
278
|
+
*/
|
|
279
|
+
async getOrders(params) {
|
|
280
|
+
const baseResponse = await this.query("orders", {
|
|
281
|
+
subaccount: params.subaccount ? (0, import_contracts.subaccountToHex)({
|
|
282
|
+
subaccountOwner: params.subaccount.subaccountOwner,
|
|
283
|
+
subaccountName: params.subaccount.subaccountName
|
|
284
|
+
}) : void 0,
|
|
285
|
+
product_ids: params.productIds,
|
|
286
|
+
isolated: params.isolated,
|
|
287
|
+
digests: params.digests,
|
|
288
|
+
max_time: params.maxTimestampInclusive,
|
|
289
|
+
limit: params.limit,
|
|
290
|
+
idx: params.startCursor
|
|
291
|
+
});
|
|
292
|
+
return baseResponse.orders.map(import_dataMappers.mapIndexerOrder);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Gets match order events, this will return the same events as the events query, but with additional information
|
|
296
|
+
* to identify the order that was matched
|
|
297
|
+
*
|
|
298
|
+
* @param params
|
|
299
|
+
*/
|
|
300
|
+
async getMatchEvents(params) {
|
|
301
|
+
const baseResponse = await this.query("matches", {
|
|
302
|
+
subaccount: params.subaccount ? (0, import_contracts.subaccountToHex)({
|
|
303
|
+
subaccountOwner: params.subaccount.subaccountOwner,
|
|
304
|
+
subaccountName: params.subaccount.subaccountName
|
|
305
|
+
}) : void 0,
|
|
306
|
+
product_ids: params.productIds,
|
|
307
|
+
isolated: params.isolated,
|
|
308
|
+
max_time: params.maxTimestampInclusive,
|
|
309
|
+
limit: params.limit,
|
|
310
|
+
idx: params.startCursor
|
|
311
|
+
});
|
|
312
|
+
let lastTxIdx = 0;
|
|
313
|
+
return baseResponse.matches.map((matchEvent) => {
|
|
314
|
+
if (baseResponse.txs[lastTxIdx].submission_idx !== matchEvent.submission_idx) {
|
|
315
|
+
lastTxIdx += 1;
|
|
316
|
+
}
|
|
317
|
+
const { tx, timestamp } = baseResponse.txs[lastTxIdx];
|
|
318
|
+
const postBalances = (0, import_dataMappers.mapIndexerMatchEventBalances)(
|
|
319
|
+
matchEvent.post_balance
|
|
320
|
+
);
|
|
321
|
+
return {
|
|
322
|
+
productId: postBalances.base.productId,
|
|
323
|
+
isolated: matchEvent.isolated,
|
|
324
|
+
totalFee: (0, import_utils.toBigDecimal)(matchEvent.fee),
|
|
325
|
+
sequencerFee: (0, import_utils.toBigDecimal)(matchEvent.sequencer_fee),
|
|
326
|
+
baseFilled: (0, import_utils.toBigDecimal)(matchEvent.base_filled),
|
|
327
|
+
quoteFilled: (0, import_utils.toBigDecimal)(matchEvent.quote_filled),
|
|
328
|
+
cumulativeFee: (0, import_utils.toBigDecimal)(matchEvent.cumulative_fee),
|
|
329
|
+
cumulativeBaseFilled: (0, import_utils.toBigDecimal)(matchEvent.cumulative_base_filled),
|
|
330
|
+
cumulativeQuoteFilled: (0, import_utils.toBigDecimal)(matchEvent.cumulative_quote_filled),
|
|
331
|
+
digest: matchEvent.digest,
|
|
332
|
+
order: matchEvent.order,
|
|
333
|
+
submissionIndex: matchEvent.submission_idx,
|
|
334
|
+
timestamp: (0, import_utils.toBigDecimal)(timestamp),
|
|
335
|
+
preEventTrackedVars: {
|
|
336
|
+
netEntryUnrealized: (0, import_utils.toBigDecimal)(matchEvent.net_entry_unrealized),
|
|
337
|
+
netEntryCumulative: (0, import_utils.toBigDecimal)(matchEvent.net_entry_cumulative)
|
|
338
|
+
},
|
|
339
|
+
preBalances: (0, import_dataMappers.mapIndexerMatchEventBalances)(matchEvent.pre_balance),
|
|
340
|
+
postBalances,
|
|
341
|
+
tx,
|
|
342
|
+
...(0, import_contracts.subaccountFromHex)(matchEvent.order.sender)
|
|
343
|
+
};
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Retrieves historical funding & interest payments.
|
|
348
|
+
* NOTE: `limit` is an upperbound. If a user changes position size such that his position is 0 during each funding/interest tick,
|
|
349
|
+
* then the indexer will return fewer than `limit` results per page. However, more events can be present. This means that
|
|
350
|
+
* 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.
|
|
351
|
+
*
|
|
352
|
+
* @param params
|
|
353
|
+
*/
|
|
354
|
+
async getInterestFundingPayments(params) {
|
|
355
|
+
const baseResponse = await this.query("interest_and_funding", {
|
|
356
|
+
subaccount: (0, import_contracts.subaccountToHex)({
|
|
357
|
+
subaccountOwner: params.subaccount.subaccountOwner,
|
|
358
|
+
subaccountName: params.subaccount.subaccountName
|
|
359
|
+
}),
|
|
360
|
+
product_ids: params.productIds,
|
|
361
|
+
max_time: params.maxTimestampInclusive,
|
|
362
|
+
limit: params.limit,
|
|
363
|
+
max_idx: params.startCursor
|
|
364
|
+
});
|
|
365
|
+
return {
|
|
366
|
+
fundingPayments: baseResponse.funding_payments.map(
|
|
367
|
+
import_dataMappers.mapIndexerProductPayment
|
|
368
|
+
),
|
|
369
|
+
interestPayments: baseResponse.interest_payments.map(
|
|
370
|
+
import_dataMappers.mapIndexerProductPayment
|
|
371
|
+
),
|
|
372
|
+
nextCursor: baseResponse.next_idx
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Gets quote (USDC) price in terms of USD
|
|
377
|
+
*/
|
|
378
|
+
async getQuotePrice() {
|
|
379
|
+
const baseResponse = await this.query("usdc_price", {});
|
|
380
|
+
return {
|
|
381
|
+
price: (0, import_utils.removeDecimals)(baseResponse.price_x18)
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Fetches currently registered linked signer with the remaining txs allowed for the subaccount
|
|
386
|
+
*/
|
|
387
|
+
async getLinkedSignerWithRateLimit(params) {
|
|
388
|
+
const baseResponse = await this.query("linked_signer_rate_limit", {
|
|
389
|
+
subaccount: (0, import_contracts.subaccountToHex)(params.subaccount)
|
|
390
|
+
});
|
|
391
|
+
return {
|
|
392
|
+
totalTxLimit: (0, import_utils.toBigDecimal)(baseResponse.total_tx_limit),
|
|
393
|
+
remainingTxs: (0, import_utils.toBigDecimal)(baseResponse.remaining_tx),
|
|
394
|
+
signer: baseResponse.signer,
|
|
395
|
+
waitTimeUntilNextTx: (0, import_utils.toBigDecimal)(baseResponse.wait_time)
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Retrieve historical market snapshots
|
|
400
|
+
* @param params
|
|
401
|
+
*/
|
|
402
|
+
async getMarketSnapshots(params) {
|
|
403
|
+
const baseResponse = await this.query("market_snapshots", {
|
|
404
|
+
interval: (0, import_dataMappers.mapSnapshotsIntervalToServerParams)(params),
|
|
405
|
+
product_ids: params.productIds
|
|
406
|
+
});
|
|
407
|
+
return baseResponse.snapshots.map(import_dataMappers.mapIndexerMarketSnapshot);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Retrieve historical market snapshots from Edge
|
|
411
|
+
* @param params
|
|
412
|
+
*/
|
|
413
|
+
async getEdgeMarketSnapshots(params) {
|
|
414
|
+
const baseResponse = await this.query("edge_market_snapshots", {
|
|
415
|
+
interval: (0, import_dataMappers.mapSnapshotsIntervalToServerParams)(params)
|
|
416
|
+
});
|
|
417
|
+
return (0, import_utils.mapValues)(
|
|
418
|
+
baseResponse.snapshots,
|
|
419
|
+
(snapshots) => snapshots.map(import_dataMappers.mapIndexerMarketSnapshot)
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Retrieve maker statistics for a given epoch
|
|
424
|
+
*
|
|
425
|
+
* @param params
|
|
426
|
+
*/
|
|
427
|
+
async getMakerStatistics(params) {
|
|
428
|
+
const baseResponse = await this.query("maker_statistics", {
|
|
429
|
+
product_id: params.productId,
|
|
430
|
+
epoch: params.epoch,
|
|
431
|
+
interval: params.interval
|
|
432
|
+
});
|
|
433
|
+
return {
|
|
434
|
+
rewardCoefficient: (0, import_utils.toBigDecimal)(baseResponse.reward_coefficient),
|
|
435
|
+
makers: baseResponse.makers.map(import_dataMappers.mapIndexerMakerStatistics)
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Retrieve leaderboard stats for a given contest
|
|
440
|
+
*
|
|
441
|
+
* @param params
|
|
442
|
+
*/
|
|
443
|
+
async getLeaderboard(params) {
|
|
444
|
+
const baseResponse = await this.query("leaderboard", {
|
|
445
|
+
contest_id: params.contestId,
|
|
446
|
+
rank_type: params.rankType,
|
|
447
|
+
start: params.startCursor,
|
|
448
|
+
limit: params.limit
|
|
449
|
+
});
|
|
450
|
+
return {
|
|
451
|
+
participants: baseResponse.positions.map(import_dataMappers.mapIndexerLeaderboardPosition)
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Retrieve leaderboard ranking of a subaccount on a given contest
|
|
456
|
+
*
|
|
457
|
+
* @param params
|
|
458
|
+
*/
|
|
459
|
+
async getLeaderboardParticipant(params) {
|
|
460
|
+
const baseResponse = await this.query("leaderboard_rank", {
|
|
461
|
+
subaccount: (0, import_contracts.subaccountToHex)(params.subaccount),
|
|
462
|
+
contest_ids: params.contestIds
|
|
463
|
+
});
|
|
464
|
+
return {
|
|
465
|
+
participant: (0, import_utils.mapValues)(
|
|
466
|
+
baseResponse.positions,
|
|
467
|
+
(position) => (0, import_dataMappers.mapIndexerLeaderboardPosition)(position)
|
|
468
|
+
)
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Attempts to update a user's registration to the provided `contestId`. This requires signing.
|
|
473
|
+
* @param params
|
|
474
|
+
*/
|
|
475
|
+
async updateLeaderboardRegistration(params) {
|
|
476
|
+
const signatureParams = {
|
|
477
|
+
// Default to 90 seconds from now if no recvTime is provided
|
|
478
|
+
expiration: (0, import_utils.toIntegerString)(params.recvTime ?? (0, import_contracts.getDefaultRecvTime)()),
|
|
479
|
+
subaccountName: params.subaccountName,
|
|
480
|
+
subaccountOwner: params.subaccountOwner
|
|
481
|
+
};
|
|
482
|
+
const tx = (0, import_contracts.getNadoEIP712Values)(
|
|
483
|
+
"leaderboard_authentication",
|
|
484
|
+
signatureParams
|
|
485
|
+
);
|
|
486
|
+
const signature = await this.sign(
|
|
487
|
+
"leaderboard_authentication",
|
|
488
|
+
params.updateRegistration.verifyingAddr,
|
|
489
|
+
params.updateRegistration.chainId,
|
|
490
|
+
signatureParams
|
|
491
|
+
);
|
|
492
|
+
const updateRegistrationTx = {
|
|
493
|
+
tx,
|
|
494
|
+
signature
|
|
495
|
+
};
|
|
496
|
+
const baseResponse = await this.query("leaderboard_registration", {
|
|
497
|
+
subaccount: (0, import_contracts.subaccountToHex)({
|
|
498
|
+
subaccountOwner: params.subaccountOwner,
|
|
499
|
+
subaccountName: params.subaccountName
|
|
500
|
+
}),
|
|
501
|
+
contest_id: params.contestId,
|
|
502
|
+
update_registration: updateRegistrationTx
|
|
503
|
+
});
|
|
504
|
+
return {
|
|
505
|
+
registration: baseResponse.registration ? (0, import_dataMappers.mapIndexerLeaderboardRegistration)(baseResponse.registration) : null
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Retrieves the registration status for a leaderboard participant for provided `contestId`.
|
|
510
|
+
* @param params
|
|
511
|
+
*/
|
|
512
|
+
async getLeaderboardRegistration(params) {
|
|
513
|
+
const baseResponse = await this.query("leaderboard_registration", {
|
|
514
|
+
subaccount: (0, import_contracts.subaccountToHex)({
|
|
515
|
+
subaccountOwner: params.subaccountOwner,
|
|
516
|
+
subaccountName: params.subaccountName
|
|
517
|
+
}),
|
|
518
|
+
contest_id: params.contestId,
|
|
519
|
+
update_registration: null
|
|
520
|
+
});
|
|
521
|
+
return {
|
|
522
|
+
registration: baseResponse.registration ? (0, import_dataMappers.mapIndexerLeaderboardRegistration)(baseResponse.registration) : null
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Retrieve metadata of provided leaderboard contests
|
|
527
|
+
*
|
|
528
|
+
* @param params
|
|
529
|
+
*/
|
|
530
|
+
async getLeaderboardContests(params) {
|
|
531
|
+
const baseResponse = await this.query("leaderboard_contests", {
|
|
532
|
+
contest_ids: params.contestIds
|
|
533
|
+
});
|
|
534
|
+
return {
|
|
535
|
+
contests: baseResponse.contests.map(import_dataMappers.mapIndexerLeaderboardContest)
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Retrieve signature and tx to submit a fast withdrawal
|
|
540
|
+
*
|
|
541
|
+
* @param params
|
|
542
|
+
*/
|
|
543
|
+
async getFastWithdrawalSignature(params) {
|
|
544
|
+
const baseResponse = await this.query("fast_withdrawal_signature", params);
|
|
545
|
+
return {
|
|
546
|
+
idx: (0, import_utils.toBigInt)(baseResponse.idx),
|
|
547
|
+
tx: baseResponse.tx,
|
|
548
|
+
txBytes: (0, import_utils.getValidatedHex)(baseResponse.tx_bytes),
|
|
549
|
+
signatures: baseResponse.signatures.map(import_utils.getValidatedHex)
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
async getVlpSnapshots(params) {
|
|
553
|
+
const baseResponse = await this.query("vlp_snapshots", {
|
|
554
|
+
interval: {
|
|
555
|
+
count: params.limit,
|
|
556
|
+
max_time: params.maxTimeInclusive ? (0, import_utils.toIntegerString)(params.maxTimeInclusive) : void 0,
|
|
557
|
+
granularity: params.granularity
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
return {
|
|
561
|
+
snapshots: baseResponse.snapshots.map(import_dataMappers.mapIndexerVlpSnapshot)
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
async getSequencerBacklog() {
|
|
565
|
+
const baseResponse = await this.query("backlog", {});
|
|
566
|
+
return {
|
|
567
|
+
totalTxs: (0, import_utils.toBigDecimal)(baseResponse.total_txs),
|
|
568
|
+
totalSubmissions: (0, import_utils.toBigDecimal)(baseResponse.total_submissions),
|
|
569
|
+
backlogSize: (0, import_utils.toBigDecimal)(baseResponse.backlog_size),
|
|
570
|
+
updatedAt: (0, import_utils.toBigDecimal)(baseResponse.updated_at),
|
|
571
|
+
backlogEtaInSeconds: baseResponse.backlog_eta_in_seconds ? (0, import_utils.toBigDecimal)(baseResponse.backlog_eta_in_seconds) : null,
|
|
572
|
+
txsPerSecond: baseResponse.txs_per_second ? (0, import_utils.toBigDecimal)(baseResponse.txs_per_second) : null
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
async query(requestType, params) {
|
|
576
|
+
const reqBody = {
|
|
577
|
+
[requestType]: params
|
|
578
|
+
};
|
|
579
|
+
const response = await this.axiosInstance.post(this.opts.url, reqBody);
|
|
580
|
+
this.checkResponseStatus(response);
|
|
581
|
+
return response.data;
|
|
582
|
+
}
|
|
583
|
+
async sign(requestType, verifyingContract, chainId, params) {
|
|
584
|
+
const walletClient = this.opts.walletClient;
|
|
585
|
+
if (!walletClient) {
|
|
586
|
+
throw new import_utils.WalletNotProvidedError();
|
|
587
|
+
}
|
|
588
|
+
return (0, import_contracts.getSignedTransactionRequest)({
|
|
589
|
+
chainId,
|
|
590
|
+
requestParams: params,
|
|
591
|
+
requestType,
|
|
592
|
+
walletClient,
|
|
593
|
+
verifyingContract
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
checkResponseStatus(response) {
|
|
597
|
+
if (response.status !== 200 || !response.data) {
|
|
598
|
+
throw Error(
|
|
599
|
+
`Unexpected response from server: ${response.status} ${response.statusText}`
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
605
|
+
0 && (module.exports = {
|
|
606
|
+
IndexerBaseClient
|
|
607
|
+
});
|
|
608
|
+
//# sourceMappingURL=IndexerBaseClient.cjs.map
|