@drift-labs/common 1.0.13 → 1.0.16

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 (81) hide show
  1. package/lib/clients/DlobWebsocketClient.d.ts +82 -0
  2. package/lib/clients/DlobWebsocketClient.js +226 -0
  3. package/lib/clients/DlobWebsocketClient.js.map +1 -0
  4. package/lib/clients/swiftClient.js +1 -0
  5. package/lib/clients/swiftClient.js.map +1 -1
  6. package/lib/common-ui-utils/commonUiUtils.d.ts +22 -3
  7. package/lib/common-ui-utils/commonUiUtils.js +15 -8
  8. package/lib/common-ui-utils/commonUiUtils.js.map +1 -1
  9. package/lib/common-ui-utils/market.d.ts +5 -0
  10. package/lib/common-ui-utils/market.js +19 -11
  11. package/lib/common-ui-utils/market.js.map +1 -1
  12. package/lib/common-ui-utils/order.d.ts +8 -1
  13. package/lib/common-ui-utils/order.js +3 -2
  14. package/lib/common-ui-utils/order.js.map +1 -1
  15. package/lib/common-ui-utils/user.d.ts +5 -0
  16. package/lib/common-ui-utils/user.js +58 -3
  17. package/lib/common-ui-utils/user.js.map +1 -1
  18. package/lib/constants/markets.d.ts +4 -0
  19. package/lib/constants/markets.js +5 -1
  20. package/lib/constants/markets.js.map +1 -1
  21. package/lib/constants/superstake.js.map +1 -1
  22. package/lib/drift/Drift/clients/AuthorityDrift/DriftL2OrderbookManager.d.ts +1 -1
  23. package/lib/drift/Drift/clients/AuthorityDrift/DriftL2OrderbookManager.js.map +1 -1
  24. package/lib/drift/Drift/clients/AuthorityDrift/index.d.ts +1 -1
  25. package/lib/drift/Drift/clients/AuthorityDrift/index.js.map +1 -1
  26. package/lib/drift/Drift/clients/CentralServerDrift/index.d.ts +3 -2
  27. package/lib/drift/Drift/clients/CentralServerDrift/index.js +52 -49
  28. package/lib/drift/Drift/clients/CentralServerDrift/index.js.map +1 -1
  29. package/lib/drift/Drift/data/PollingDlob.d.ts +1 -1
  30. package/lib/drift/Drift/data/PollingDlob.js.map +1 -1
  31. package/lib/drift/base/actions/trade/editOrder.d.ts +3 -0
  32. package/lib/drift/base/actions/trade/editOrder.js.map +1 -1
  33. package/lib/drift/base/actions/trade/index.d.ts +1 -0
  34. package/lib/drift/base/actions/trade/index.js +1 -0
  35. package/lib/drift/base/actions/trade/index.js.map +1 -1
  36. package/lib/drift/base/actions/trade/margin.d.ts +24 -0
  37. package/lib/drift/base/actions/trade/margin.js +48 -0
  38. package/lib/drift/base/actions/trade/margin.js.map +1 -0
  39. package/lib/drift/base/actions/trade/openPerpOrder/auction.d.ts +3 -1
  40. package/lib/drift/base/actions/trade/openPerpOrder/auction.js +2 -2
  41. package/lib/drift/base/actions/trade/openPerpOrder/auction.js.map +1 -1
  42. package/lib/drift/base/actions/trade/openPerpOrder/dlobServer/index.d.ts +2 -6
  43. package/lib/drift/base/actions/trade/openPerpOrder/dlobServer/index.js.map +1 -1
  44. package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.d.ts +6 -3
  45. package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js +6 -6
  46. package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js.map +1 -1
  47. package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.d.ts +2 -0
  48. package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js +3 -2
  49. package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js.map +1 -1
  50. package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js +2 -1
  51. package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js.map +1 -1
  52. package/lib/drift/base/actions/trade/swap.d.ts +18 -11
  53. package/lib/drift/base/actions/trade/swap.js +40 -17
  54. package/lib/drift/base/actions/trade/swap.js.map +1 -1
  55. package/lib/index.d.ts +1 -0
  56. package/lib/index.js +1 -0
  57. package/lib/index.js.map +1 -1
  58. package/lib/utils/MultiplexWebSocket.d.ts +4 -2
  59. package/lib/utils/MultiplexWebSocket.js +18 -9
  60. package/lib/utils/MultiplexWebSocket.js.map +1 -1
  61. package/lib/utils/ResultSlotIncrementer.d.ts +31 -0
  62. package/lib/utils/ResultSlotIncrementer.js +83 -0
  63. package/lib/utils/ResultSlotIncrementer.js.map +1 -0
  64. package/lib/utils/index.d.ts +3 -1
  65. package/lib/utils/index.js +7 -1
  66. package/lib/utils/index.js.map +1 -1
  67. package/lib/utils/math.js +1 -1
  68. package/lib/utils/math.js.map +1 -1
  69. package/lib/utils/orderbook/constants.d.ts +2 -0
  70. package/lib/utils/orderbook/constants.js +5 -0
  71. package/lib/utils/orderbook/constants.js.map +1 -0
  72. package/lib/utils/orderbook/index.d.ts +38 -59
  73. package/lib/utils/orderbook/index.js +285 -1
  74. package/lib/utils/orderbook/index.js.map +1 -1
  75. package/lib/utils/orderbook/types.d.ts +101 -0
  76. package/lib/utils/orderbook/types.js +9 -0
  77. package/lib/utils/orderbook/types.js.map +1 -0
  78. package/lib/utils/signedMsgs.d.ts +1 -0
  79. package/lib/utils/signedMsgs.js +10 -0
  80. package/lib/utils/signedMsgs.js.map +1 -0
  81. package/package.json +1 -1
@@ -1,8 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateDynamicSlippageFromL2 = exports.convertToL2OrderBook = exports.deserializeL2Response = void 0;
17
+ exports.getEmptyFilledBidsAsks = exports.l2ToDisplayBidsAndAsks = exports.formatL2ToDisplay = exports.getCategorisedLiquidityForLevel = exports.getZeroPaddingForGroupingSize = exports.mergeBidsAndAsksForGroupsize = exports.getBucketForUserLiquidity = exports.getBucketAnchorPrice = exports.getUserLiquidityForPrice = exports.getBucketFloorForPrice = exports.getLiquidityPcts = exports.getFormattedSize = exports.calculateDynamicSlippageFromL2 = exports.convertToL2OrderBook = exports.deserializeL2Response = void 0;
4
18
  const sdk_1 = require("@drift-labs/sdk");
5
19
  const math_1 = require("../math");
20
+ const types_1 = require("./types");
21
+ const __1 = require("..");
22
+ const constants_1 = require("./constants");
23
+ __exportStar(require("./types"), exports);
24
+ __exportStar(require("./constants"), exports);
6
25
  /**
7
26
  * Helper function to deserialize the response from the dlob server. (See https://drift-labs.github.io/v2-teacher/#get-l2-l3)
8
27
  * @param serializedOrderbook
@@ -144,4 +163,269 @@ const calculateDynamicSlippageFromL2 = ({ l2Data, marketId, startPrice, worstPri
144
163
  return Math.round(finalSlippage * 1000000) / 1000000;
145
164
  };
146
165
  exports.calculateDynamicSlippageFromL2 = calculateDynamicSlippageFromL2;
166
+ const getFormattedSize = (sizesObject, price, currency, displayDecimals) => {
167
+ const sizeSum = Object.values(sizesObject || {}).reduce((acc, curr) => acc + curr, 0);
168
+ const displayValue = currency === types_1.CUMULATIVE_SIZE_CURRENCY.USD && price
169
+ ? sizeSum * price
170
+ : sizeSum;
171
+ return sdk_1.BigNum.fromPrint(displayValue.toFixed(displayDecimals), new sdk_1.BN(displayDecimals)).toMillified(3);
172
+ };
173
+ exports.getFormattedSize = getFormattedSize;
174
+ const getLiquidityPcts = (totalSize, cumulativeSize = {}) => {
175
+ var _a, _b;
176
+ const totalCumulativeSize = Object.values(cumulativeSize).reduce((acc, curr) => acc + curr, 0);
177
+ const cumulativeSizePct = totalSize
178
+ ? (totalCumulativeSize / totalSize) * 100
179
+ : 0; // This is the portion of the total size of the orderbook that the cumulative size of the liquidity should be occupying.
180
+ const cumulativeRestingSize = totalCumulativeSize - ((_a = cumulativeSize === null || cumulativeSize === void 0 ? void 0 : cumulativeSize.indicative) !== null && _a !== void 0 ? _a : 0);
181
+ const cumulativeIndicativeSize = (_b = cumulativeSize === null || cumulativeSize === void 0 ? void 0 : cumulativeSize.indicative) !== null && _b !== void 0 ? _b : 0;
182
+ const restingLiquidityPct = (cumulativeRestingSize / totalCumulativeSize) * cumulativeSizePct; // This is the portion of the width of the orderbook that the resting liquidity should be occupying
183
+ const indicativeLiquidityPct = (cumulativeIndicativeSize / totalCumulativeSize) * cumulativeSizePct; // This is the portion of the width of the orderbook that the indicative liquidity should be occupying
184
+ return {
185
+ restingLiquidityPct,
186
+ indicativeLiquidityPct,
187
+ };
188
+ };
189
+ exports.getLiquidityPcts = getLiquidityPcts;
190
+ const roundForOrderbook = (num) => Number(num.toFixed(6));
191
+ const getBucketFloorForPrice = (price, groupingSize) => {
192
+ const priceIsNegative = price < 0;
193
+ const _groupingSize = groupingSize;
194
+ if (__1.COMMON_UTILS.dividesExactly(price, _groupingSize)) {
195
+ return roundForOrderbook(price);
196
+ }
197
+ const amountToDeduct = priceIsNegative
198
+ ? _groupingSize - (Math.abs(price) % _groupingSize)
199
+ : Math.abs(price) % _groupingSize;
200
+ const floorPrice = price - amountToDeduct;
201
+ return roundForOrderbook(floorPrice);
202
+ };
203
+ exports.getBucketFloorForPrice = getBucketFloorForPrice;
204
+ const getUserLiquidityForPrice = ({ price, side, groupingSizeValue, userAskPriceBucketLookup, userBidPriceBucketLookup, }) => {
205
+ let isCurrentUserLiquidity = false;
206
+ let currentUserLiquiditySize = 0;
207
+ const priceToUse = price;
208
+ const priceBucket = (0, exports.getBucketFloorForPrice)(priceToUse, groupingSizeValue);
209
+ const lookupBucket = side === 'bid' ? userBidPriceBucketLookup : userAskPriceBucketLookup;
210
+ const matchingUserBidAsk = lookupBucket.get(priceBucket);
211
+ if (matchingUserBidAsk) {
212
+ isCurrentUserLiquidity = true;
213
+ currentUserLiquiditySize = matchingUserBidAsk.size;
214
+ }
215
+ return { isCurrentUserLiquidity, currentUserLiquiditySize };
216
+ };
217
+ exports.getUserLiquidityForPrice = getUserLiquidityForPrice;
218
+ const getBucketCeilingForPrice = (price, groupingSize) => {
219
+ const _groupingSize = groupingSize;
220
+ return (0, exports.getBucketFloorForPrice)(price + _groupingSize, groupingSize);
221
+ };
222
+ const getBucketAnchorPrice = (type, price, groupingSize) => {
223
+ // If the grouping size matches exactly then the anchor price should be the same as the floor price regardless
224
+ if (__1.COMMON_UTILS.dividesExactly(price, groupingSize)) {
225
+ return (0, exports.getBucketFloorForPrice)(price, groupingSize);
226
+ }
227
+ if (type === 'bid') {
228
+ return (0, exports.getBucketFloorForPrice)(price, groupingSize);
229
+ }
230
+ else {
231
+ return getBucketCeilingForPrice(price, groupingSize);
232
+ }
233
+ };
234
+ exports.getBucketAnchorPrice = getBucketAnchorPrice;
235
+ const getBucketForUserLiquidity = (price, groupingSize, type) => (0, exports.getBucketAnchorPrice)(type, price, groupingSize);
236
+ exports.getBucketForUserLiquidity = getBucketForUserLiquidity;
237
+ const mergeBidsAndAsksForGroupsize = (type, bidsAsks, groupingSize) => {
238
+ const bidsAsksBucketLookup = new Map();
239
+ for (const bidAsk of bidsAsks) {
240
+ const anchorPrice = (0, exports.getBucketAnchorPrice)(type, bidAsk.price, groupingSize);
241
+ const existingBucket = bidsAsksBucketLookup.get(anchorPrice);
242
+ if (existingBucket) {
243
+ existingBucket.size += bidAsk.size;
244
+ }
245
+ else {
246
+ bidsAsksBucketLookup.set(anchorPrice, { ...bidAsk });
247
+ }
248
+ }
249
+ return Array.from(bidsAsksBucketLookup.values());
250
+ };
251
+ exports.mergeBidsAndAsksForGroupsize = mergeBidsAndAsksForGroupsize;
252
+ const getZeroPaddingForGroupingSize = (groupingSize) => {
253
+ const _groupingSize = groupingSize;
254
+ const precision = Math.floor(Math.log10(_groupingSize));
255
+ if (precision >= 0 || _groupingSize === 0)
256
+ return 0;
257
+ return Math.abs(precision);
258
+ };
259
+ exports.getZeroPaddingForGroupingSize = getZeroPaddingForGroupingSize;
260
+ const sizeToNum = (size, precision) => sdk_1.BigNum.from(size, precision).toNum();
261
+ const getCategorisedLiquidityForLevel = (level, basePrecision) => {
262
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
263
+ const dlobSize = sizeToNum((_b = (_a = level === null || level === void 0 ? void 0 : level.sources) === null || _a === void 0 ? void 0 : _a.dlob) !== null && _b !== void 0 ? _b : sdk_1.ZERO, basePrecision);
264
+ const vammSize = sizeToNum((_d = (_c = level === null || level === void 0 ? void 0 : level.sources) === null || _c === void 0 ? void 0 : _c.vamm) !== null && _d !== void 0 ? _d : sdk_1.ZERO, basePrecision);
265
+ const serumSize = sizeToNum((_f = (_e = level === null || level === void 0 ? void 0 : level.sources) === null || _e === void 0 ? void 0 : _e.serum) !== null && _f !== void 0 ? _f : sdk_1.ZERO, basePrecision);
266
+ const phoenixSize = sizeToNum((_h = (_g = level === null || level === void 0 ? void 0 : level.sources) === null || _g === void 0 ? void 0 : _g.phoenix) !== null && _h !== void 0 ? _h : sdk_1.ZERO, basePrecision);
267
+ const openbookSize = sizeToNum((_k = (_j = level === null || level === void 0 ? void 0 : level.sources) === null || _j === void 0 ? void 0 : _j.openbook) !== null && _k !== void 0 ? _k : sdk_1.ZERO, basePrecision);
268
+ const indicativeSize = sizeToNum((_m = (_l = level === null || level === void 0 ? void 0 : level.sources) === null || _l === void 0 ? void 0 : _l.indicative) !== null && _m !== void 0 ? _m : sdk_1.ZERO, basePrecision);
269
+ const categorisedLiquidity = {
270
+ dlob: dlobSize,
271
+ vamm: vammSize,
272
+ serum: serumSize,
273
+ phoenix: phoenixSize,
274
+ openbook: openbookSize,
275
+ indicative: indicativeSize,
276
+ };
277
+ return categorisedLiquidity;
278
+ };
279
+ exports.getCategorisedLiquidityForLevel = getCategorisedLiquidityForLevel;
280
+ const formatLevelsToDisplay = (levels, basePrecision, depth) => {
281
+ var _a, _b;
282
+ const relevantSources = new Set();
283
+ for (const level of levels) {
284
+ for (const source of Object.keys(level.sources)) {
285
+ relevantSources.add(source);
286
+ }
287
+ }
288
+ const cumulativeSizes = Array.from(relevantSources).reduce((acc, source) => {
289
+ acc[source] = 0;
290
+ return acc;
291
+ }, {});
292
+ let cumulativePriceSizeProduct = 0;
293
+ let cumulativeTotalSize = 0;
294
+ const formattedLevels = levels.map((level) => {
295
+ var _a;
296
+ const bucketSize = (0, exports.getCategorisedLiquidityForLevel)(level, basePrecision);
297
+ const price = sdk_1.BigNum.from(level.price, sdk_1.PRICE_PRECISION_EXP).toNum();
298
+ const totalSize = Object.values(bucketSize).reduce((sum, size) => sum + size, 0);
299
+ for (const source of relevantSources) {
300
+ const currentValue = cumulativeSizes[source];
301
+ if (currentValue !== undefined) {
302
+ cumulativeSizes[source] = currentValue + ((_a = bucketSize[source]) !== null && _a !== void 0 ? _a : 0);
303
+ }
304
+ }
305
+ cumulativePriceSizeProduct += price * totalSize;
306
+ cumulativeTotalSize += totalSize;
307
+ return {
308
+ price,
309
+ size: bucketSize,
310
+ cumulativeSize: { ...cumulativeSizes },
311
+ cumulativeAvgPrice: cumulativeTotalSize > 0
312
+ ? cumulativePriceSizeProduct / cumulativeTotalSize
313
+ : 0,
314
+ };
315
+ });
316
+ if (depth && depth > 0) {
317
+ const visibleLevels = formattedLevels.slice(0, depth);
318
+ const maxCumulativeSize = Math.max(0, ...visibleLevels.map((level) => Object.values(level.cumulativeSize).reduce((sum, size) => sum + size, 0)));
319
+ return {
320
+ formattedLevels: visibleLevels,
321
+ bestLevel: (_a = visibleLevels === null || visibleLevels === void 0 ? void 0 : visibleLevels[0]) === null || _a === void 0 ? void 0 : _a.price,
322
+ cumulativeSize: maxCumulativeSize,
323
+ };
324
+ }
325
+ const totalSizeToReturn = Object.values(cumulativeSizes).reduce((total, current) => total + current, 0);
326
+ return {
327
+ formattedLevels,
328
+ bestLevel: (_b = formattedLevels === null || formattedLevels === void 0 ? void 0 : formattedLevels[0]) === null || _b === void 0 ? void 0 : _b.price,
329
+ cumulativeSize: totalSizeToReturn,
330
+ };
331
+ };
332
+ const formatL2ToDisplay = (l2State, basePrecision, depth) => {
333
+ const formattedBids = formatLevelsToDisplay(l2State.bids, basePrecision, depth);
334
+ const formattedAsks = formatLevelsToDisplay(l2State.asks, basePrecision, depth);
335
+ return {
336
+ bids: formattedBids.formattedLevels,
337
+ asks: formattedAsks.formattedLevels,
338
+ bidTotalSize: formattedBids.cumulativeSize,
339
+ askTotalSize: formattedAsks.cumulativeSize,
340
+ };
341
+ };
342
+ exports.formatL2ToDisplay = formatL2ToDisplay;
343
+ const filterOutDisabledLiquidityTypes = (l2Levels, disabledLiquidityTypes) => l2Levels
344
+ .map((level) => {
345
+ var _a;
346
+ let totalDisabledSize = sdk_1.ZERO;
347
+ const disabledSourceObj = {};
348
+ for (const liquidityType of disabledLiquidityTypes) {
349
+ const disabledLiqSize = (_a = level.sources) === null || _a === void 0 ? void 0 : _a[liquidityType];
350
+ if (disabledLiqSize === null || disabledLiqSize === void 0 ? void 0 : disabledLiqSize.gt(sdk_1.ZERO)) {
351
+ totalDisabledSize = totalDisabledSize.add(disabledLiqSize);
352
+ disabledSourceObj[liquidityType] = sdk_1.ZERO;
353
+ }
354
+ }
355
+ return totalDisabledSize.gt(sdk_1.ZERO)
356
+ ? {
357
+ ...level,
358
+ size: level.size.sub(totalDisabledSize),
359
+ sources: {
360
+ ...level.sources,
361
+ ...disabledSourceObj,
362
+ },
363
+ }
364
+ : level;
365
+ })
366
+ .filter((level) => level.size.gt(sdk_1.ZERO));
367
+ const l2ToDisplayBidsAndAsks = (l2Orderbook, oraclePrice, tickSizeForMarket, groupSizeTickMultiplier, userBidsAndAsks, basePrecisionForMarket, disabledLiquidityTypes, maxDepth, depth // limit the number of visible rows to calculate totalSize from
368
+ ) => {
369
+ const filteredBids = disabledLiquidityTypes.length > 0
370
+ ? filterOutDisabledLiquidityTypes(l2Orderbook.bids, disabledLiquidityTypes)
371
+ : l2Orderbook.bids;
372
+ const filteredAsks = disabledLiquidityTypes.length > 0
373
+ ? filterOutDisabledLiquidityTypes(l2Orderbook.asks, disabledLiquidityTypes)
374
+ : l2Orderbook.asks;
375
+ // # Uncross the liquidity
376
+ const uncrossed = {
377
+ l2Orderbook,
378
+ bids: filteredBids,
379
+ asks: filteredAsks,
380
+ };
381
+ // Group the orderbook into levels based on the grouping size
382
+ const grouped = (0, sdk_1.groupL2)(uncrossed, tickSizeForMarket.muln(groupSizeTickMultiplier !== null && groupSizeTickMultiplier !== void 0 ? groupSizeTickMultiplier : 1), // one user had a weird error where .muln was throwing assertion failed error
383
+ maxDepth);
384
+ // # Convert to UI format
385
+ const formatted = (0, exports.formatL2ToDisplay)(grouped, basePrecisionForMarket, depth);
386
+ // Check that bids are in descending order
387
+ if (formatted.bids.some((bid, index) => {
388
+ if (index === 0)
389
+ return false;
390
+ return bid.price > formatted.bids[index - 1].price;
391
+ })) {
392
+ console.log('orderbook - bids_not_in_descending_order', {
393
+ l2Orderbook,
394
+ oraclePrice,
395
+ tickSizeForMarket,
396
+ userBidsAndAsks,
397
+ basePrecisionForMarket,
398
+ uncrossed,
399
+ formatted,
400
+ });
401
+ }
402
+ // Check that asks are in ascending order
403
+ if (formatted.asks.some((ask, index) => {
404
+ if (index === 0)
405
+ return false;
406
+ return ask.price < formatted.asks[index - 1].price;
407
+ })) {
408
+ console.log('orderbook - asks_not_in_ascending_order', {
409
+ l2Orderbook,
410
+ oraclePrice,
411
+ tickSizeForMarket,
412
+ userBidsAndAsks,
413
+ basePrecisionForMarket,
414
+ uncrossed,
415
+ formatted,
416
+ });
417
+ }
418
+ return formatted;
419
+ };
420
+ exports.l2ToDisplayBidsAndAsks = l2ToDisplayBidsAndAsks;
421
+ const getEmptyFilledBidsAsks = (bidsOrAsks, depth) => {
422
+ const result = Array(depth).fill(constants_1.EMPTY_ORDERBOOK_ROW);
423
+ bidsOrAsks.forEach((bidOrAsk, index) => {
424
+ if (index < depth) {
425
+ result[index] = bidOrAsk;
426
+ }
427
+ });
428
+ return result;
429
+ };
430
+ exports.getEmptyFilledBidsAsks = getEmptyFilledBidsAsks;
147
431
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/orderbook/index.ts"],"names":[],"mappings":";;;AAAA,yCAQyB;AAEzB,kCAAsC;AAgEtC;;;;GAIG;AACI,MAAM,qBAAqB,GAAG,CACpC,mBAAgC,EACJ,EAAE;;IAC9B,OAAO;QACN,IAAI,EAAE,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC5C,KAAK,EAAE,IAAI,QAAE,CAAC,GAAG,CAAC,KAAK,CAAC;YACxB,IAAI,EAAE,IAAI,QAAE,CAAC,GAAG,CAAC,IAAI,CAAC;YACtB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE;gBACpE,OAAO;oBACN,GAAG,QAAQ;oBACX,CAAC,GAAG,CAAC,EAAE,IAAI,QAAE,CAAC,GAAG,CAAC;iBAClB,CAAC;YACH,CAAC,EAAE,EAAE,CAAC;SACN,CAAC,CAAC;QACH,IAAI,EAAE,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC5C,KAAK,EAAE,IAAI,QAAE,CAAC,GAAG,CAAC,KAAK,CAAC;YACxB,IAAI,EAAE,IAAI,QAAE,CAAC,GAAG,CAAC,IAAI,CAAC;YACtB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,GAAG,EAA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IAAI,CAAC,GAAG,CAC7B,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,0BAA0B,CAAC,kBAAkB,CAAC,EACxE,0BAA0B,CAAC,kBAAkB,CAC7C,CAAC;IAEF,8EAA8E;IAC9E,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC;AACtD,CAAC,CAAC;AAhFW,QAAA,8BAA8B,kCAgFzC","sourcesContent":["import {\n\tMarketType,\n\tOraclePriceData,\n\tL2OrderBook,\n\tBN,\n\tMMOraclePriceData,\n\tBigNum,\n\tPERCENTAGE_PRECISION_EXP,\n} from '@drift-labs/sdk';\nimport { MarketId } from '../../types';\nimport { COMMON_MATH } from '../math';\n\nexport interface L2WithOracle extends L2OrderBook {\n\toracleData: OraclePriceData;\n\tmarkPrice: BN;\n\tbestBidPrice: BN;\n\tbestAskPrice: BN;\n\tspreadPct: BN;\n\tspreadQuote: BN;\n\tmmOracleData?: MMOraclePriceData;\n}\n\nexport interface L2WithOracleAndMarketData extends L2WithOracle {\n\tmarketSlot: number;\n\tmarketIndex: number;\n\tmarketName: string;\n\tmarketType?: MarketType;\n}\n\nexport type RawL2Output = {\n\tmarketIndex: number;\n\tmarketType: MarketType;\n\tmarketName: string;\n\tmarketSlot: number;\n\tasks: {\n\t\tprice: string;\n\t\tsize: string;\n\t\tsources: {\n\t\t\t[key: string]: string;\n\t\t};\n\t}[];\n\tbids: {\n\t\tprice: string;\n\t\tsize: string;\n\t\tsources: {\n\t\t\t[key: string]: string;\n\t\t};\n\t}[];\n\toracleData: {\n\t\tprice: string;\n\t\tslot: string;\n\t\tconfidence: string;\n\t\thasSufficientNumberOfDataPoints: boolean;\n\t\ttwap?: string;\n\t\ttwapConfidence?: string;\n\t\tmaxPrice?: string;\n\t};\n\tmmOracleData?: {\n\t\tprice: string;\n\t\tslot: string;\n\t\tconfidence: string;\n\t\thasSufficientNumberOfDataPoints: boolean;\n\t\tisMMOracleActive: boolean;\n\t};\n\tmarkPrice: string;\n\tbestBidPrice: string;\n\tbestAskPrice: string;\n\tspreadPct: string;\n\tspreadQuote: string;\n\tslot?: number;\n};\n\nexport type LiquidityType = 'vamm' | 'dlob' | 'serum' | 'phoenix' | 'openbook';\n\n/**\n * Helper function to deserialize the response from the dlob server. (See https://drift-labs.github.io/v2-teacher/#get-l2-l3)\n * @param serializedOrderbook\n * @returns\n */\nexport const deserializeL2Response = (\n\tserializedOrderbook: RawL2Output\n): L2WithOracleAndMarketData => {\n\treturn {\n\t\tasks: serializedOrderbook.asks.map((ask) => ({\n\t\t\tprice: new BN(ask.price),\n\t\t\tsize: new BN(ask.size),\n\t\t\tsources: Object.entries(ask.sources).reduce((previous, [key, val]) => {\n\t\t\t\treturn {\n\t\t\t\t\t...previous,\n\t\t\t\t\t[key]: new BN(val),\n\t\t\t\t};\n\t\t\t}, {}),\n\t\t})),\n\t\tbids: serializedOrderbook.bids.map((bid) => ({\n\t\t\tprice: new BN(bid.price),\n\t\t\tsize: new BN(bid.size),\n\t\t\tsources: Object.entries(bid.sources).reduce((previous, [key, val]) => {\n\t\t\t\treturn {\n\t\t\t\t\t...previous,\n\t\t\t\t\t[key]: new BN(val),\n\t\t\t\t};\n\t\t\t}, {}),\n\t\t})),\n\t\toracleData: {\n\t\t\tprice: serializedOrderbook.oracleData.price\n\t\t\t\t? new BN(serializedOrderbook.oracleData.price)\n\t\t\t\t: undefined,\n\t\t\tslot: serializedOrderbook.oracleData.slot\n\t\t\t\t? new BN(serializedOrderbook.oracleData.slot)\n\t\t\t\t: undefined,\n\t\t\tconfidence: serializedOrderbook.oracleData.confidence\n\t\t\t\t? new BN(serializedOrderbook.oracleData.confidence)\n\t\t\t\t: undefined,\n\t\t\thasSufficientNumberOfDataPoints:\n\t\t\t\tserializedOrderbook.oracleData.hasSufficientNumberOfDataPoints,\n\t\t\ttwap: serializedOrderbook.oracleData.twap\n\t\t\t\t? new BN(serializedOrderbook.oracleData.twap)\n\t\t\t\t: undefined,\n\t\t\ttwapConfidence: serializedOrderbook.oracleData.twapConfidence\n\t\t\t\t? new BN(serializedOrderbook.oracleData.twapConfidence)\n\t\t\t\t: undefined,\n\t\t\tmaxPrice: serializedOrderbook.oracleData.maxPrice\n\t\t\t\t? new BN(serializedOrderbook.oracleData.maxPrice)\n\t\t\t\t: undefined,\n\t\t},\n\t\tmmOracleData: {\n\t\t\tprice: serializedOrderbook.mmOracleData?.price\n\t\t\t\t? new BN(serializedOrderbook.mmOracleData.price)\n\t\t\t\t: undefined,\n\t\t\tslot: serializedOrderbook.mmOracleData?.slot\n\t\t\t\t? new BN(serializedOrderbook.mmOracleData.slot)\n\t\t\t\t: undefined,\n\t\t\tconfidence: serializedOrderbook.mmOracleData?.confidence\n\t\t\t\t? new BN(serializedOrderbook.mmOracleData.confidence)\n\t\t\t\t: undefined,\n\t\t\thasSufficientNumberOfDataPoints:\n\t\t\t\tserializedOrderbook.mmOracleData?.hasSufficientNumberOfDataPoints,\n\t\t\tisMMOracleActive:\n\t\t\t\tserializedOrderbook.mmOracleData?.isMMOracleActive ?? false,\n\t\t},\n\t\tslot: serializedOrderbook.slot,\n\t\tmarketSlot: serializedOrderbook.marketSlot,\n\t\tmarketType: serializedOrderbook.marketType,\n\t\tmarketIndex: serializedOrderbook.marketIndex,\n\t\tmarketName: serializedOrderbook.marketName,\n\t\tmarkPrice: new BN(serializedOrderbook.markPrice),\n\t\tbestBidPrice: new BN(serializedOrderbook.bestBidPrice),\n\t\tbestAskPrice: new BN(serializedOrderbook.bestAskPrice),\n\t\tspreadPct: new BN(serializedOrderbook.spreadPct),\n\t\tspreadQuote: new BN(serializedOrderbook.spreadQuote),\n\t};\n};\n\nexport const convertToL2OrderBook = (\n\tl2Data: L2WithOracleAndMarketData[]\n): L2OrderBook => {\n\t// Find the market data - there should be one entry for our market\n\tconst marketData = l2Data[0];\n\n\tif (!marketData) {\n\t\tthrow new Error('No L2 data available for market');\n\t}\n\n\t// L2WithOracleAndMarketData extends L2OrderBook, so we can use it directly\n\treturn {\n\t\tasks: marketData.asks,\n\t\tbids: marketData.bids,\n\t\tslot: marketData.slot,\n\t};\n};\n\nexport interface DynamicSlippageConfig {\n\tdynamicSlippageMin?: number;\n\tdynamicSlippageMax?: number;\n\tdynamicBaseSlippageMajor?: number;\n\tdynamicBaseSlippageNonMajor?: number;\n\tdynamicSlippageMultiplierMajor?: number;\n\tdynamicSlippageMultiplierNonMajor?: number;\n}\n\nconst DEFAULT_DYNAMIC_SLIPPAGE_CONFIG: DynamicSlippageConfig = {\n\tdynamicSlippageMin: 0.05,\n\tdynamicSlippageMax: 5,\n\tdynamicBaseSlippageMajor: 0,\n\tdynamicBaseSlippageNonMajor: 0.5,\n\tdynamicSlippageMultiplierMajor: 1.02,\n\tdynamicSlippageMultiplierNonMajor: 1.2,\n};\n\nexport const calculateDynamicSlippageFromL2 = ({\n\tl2Data,\n\tmarketId,\n\tstartPrice,\n\tworstPrice,\n\toraclePrice,\n\tdynamicSlippageConfig,\n}: {\n\tl2Data: L2OrderBook;\n\tmarketId: MarketId;\n\tstartPrice: BN;\n\tworstPrice: BN;\n\toraclePrice?: BN;\n\tdynamicSlippageConfig?: DynamicSlippageConfig;\n}): number => {\n\tconst dynamicSlippageConfigToUse = dynamicSlippageConfig\n\t\t? { ...DEFAULT_DYNAMIC_SLIPPAGE_CONFIG, ...dynamicSlippageConfig }\n\t\t: DEFAULT_DYNAMIC_SLIPPAGE_CONFIG;\n\n\t// Calculate spread information from L2 data using the oracle price\n\tconst spreadBidAskMark = COMMON_MATH.calculateSpreadBidAskMark(\n\t\tl2Data,\n\t\toraclePrice\n\t);\n\n\tconst bestAskNum = spreadBidAskMark.bestAskPrice?.toNumber?.() || 0;\n\tconst bestBidNum = spreadBidAskMark.bestBidPrice?.toNumber?.() || 0;\n\n\tconst spreadPctFromL2 = BigNum.from(\n\t\tspreadBidAskMark.spreadPct,\n\t\tPERCENTAGE_PRECISION_EXP\n\t).toNum();\n\n\t// Calculate spread percentage\n\tconst spreadPct =\n\t\tspreadPctFromL2 ||\n\t\t(Math.abs(bestAskNum - bestBidNum) / ((bestAskNum + bestBidNum) / 2)) * 100;\n\n\t// Default to 0.5% if we get invalid spread info\n\tif (isNaN(spreadPct) || spreadPct <= 0) {\n\t\treturn 0.5;\n\t}\n\n\t// Apply a buffer based on the tier of the contract\n\t// Currently no buffer for SOL/BTC/ETH perp and a +10% buffer for other markets\n\tconst isMajor = marketId.isPerp && marketId.marketIndex < 3;\n\n\tconst spreadBaseSlippage = spreadPct / 2;\n\n\tconst baseSlippage = isMajor\n\t\t? dynamicSlippageConfigToUse.dynamicBaseSlippageMajor\n\t\t: dynamicSlippageConfigToUse.dynamicBaseSlippageNonMajor;\n\tlet dynamicSlippage = baseSlippage + spreadBaseSlippage;\n\n\t// Use halfway to worst price as size adjusted slippage\n\tif (startPrice && worstPrice) {\n\t\tconst sizeAdjustedSlippage =\n\t\t\t(startPrice.sub(worstPrice).abs().toNumber() /\n\t\t\t\tBN.max(startPrice, worstPrice).toNumber() /\n\t\t\t\t2) *\n\t\t\t100;\n\n\t\tdynamicSlippage = Math.max(dynamicSlippage, sizeAdjustedSlippage);\n\t}\n\n\t// Apply multiplier from env var\n\tconst multiplier = isMajor\n\t\t? dynamicSlippageConfigToUse.dynamicSlippageMultiplierMajor\n\t\t: dynamicSlippageConfigToUse.dynamicSlippageMultiplierNonMajor;\n\n\tdynamicSlippage = dynamicSlippage * multiplier;\n\n\t// Enforce .05% minimum, 5% maximum, can change these in env vars\n\tconst finalSlippage = Math.min(\n\t\tMath.max(dynamicSlippage, dynamicSlippageConfigToUse.dynamicSlippageMin),\n\t\tdynamicSlippageConfigToUse.dynamicSlippageMax\n\t);\n\n\t// Round to avoid floating point precision issues, preserving 6 decimal places\n\treturn Math.round(finalSlippage * 1000000) / 1000000;\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/orderbook/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yCASyB;AA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E,CAAC;YACnB,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC;QAC1B,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAbW,QAAA,sBAAsB,0BAajC","sourcesContent":["import {\n\tL2OrderBook,\n\tBN,\n\tBigNum,\n\tPERCENTAGE_PRECISION_EXP,\n\tPRICE_PRECISION_EXP,\n\tL2Level,\n\tZERO,\n\tgroupL2,\n} from '@drift-labs/sdk';\nimport { MarketId } from '../../types';\nimport { COMMON_MATH } from '../math';\nimport {\n\tBidsAndAsks,\n\tCategorisedLiquidity,\n\tCUMULATIVE_SIZE_CURRENCY,\n\tEmptyRow,\n\tGroupingSizeQuoteValue,\n\tL2WithOracleAndMarketData,\n\tLiquidityType,\n\tOrderBookBidAsk,\n\tOrderBookDisplayStateBidAsk,\n\tRawL2Output,\n} from './types';\nimport { COMMON_UTILS } from '..';\nimport { EMPTY_ORDERBOOK_ROW } from './constants';\n\nexport * from './types';\nexport * from './constants';\n\n/**\n * Helper function to deserialize the response from the dlob server. (See https://drift-labs.github.io/v2-teacher/#get-l2-l3)\n * @param serializedOrderbook\n * @returns\n */\nexport const deserializeL2Response = (\n\tserializedOrderbook: RawL2Output\n): L2WithOracleAndMarketData => {\n\treturn {\n\t\tasks: serializedOrderbook.asks.map((ask) => ({\n\t\t\tprice: new BN(ask.price),\n\t\t\tsize: new BN(ask.size),\n\t\t\tsources: Object.entries(ask.sources).reduce((previous, [key, val]) => {\n\t\t\t\treturn {\n\t\t\t\t\t...previous,\n\t\t\t\t\t[key]: new BN(val),\n\t\t\t\t};\n\t\t\t}, {}),\n\t\t})),\n\t\tbids: serializedOrderbook.bids.map((bid) => ({\n\t\t\tprice: new BN(bid.price),\n\t\t\tsize: new BN(bid.size),\n\t\t\tsources: Object.entries(bid.sources).reduce((previous, [key, val]) => {\n\t\t\t\treturn {\n\t\t\t\t\t...previous,\n\t\t\t\t\t[key]: new BN(val),\n\t\t\t\t};\n\t\t\t}, {}),\n\t\t})),\n\t\toracleData: {\n\t\t\tprice: serializedOrderbook.oracleData.price\n\t\t\t\t? new BN(serializedOrderbook.oracleData.price)\n\t\t\t\t: undefined,\n\t\t\tslot: serializedOrderbook.oracleData.slot\n\t\t\t\t? new BN(serializedOrderbook.oracleData.slot)\n\t\t\t\t: undefined,\n\t\t\tconfidence: serializedOrderbook.oracleData.confidence\n\t\t\t\t? new BN(serializedOrderbook.oracleData.confidence)\n\t\t\t\t: undefined,\n\t\t\thasSufficientNumberOfDataPoints:\n\t\t\t\tserializedOrderbook.oracleData.hasSufficientNumberOfDataPoints,\n\t\t\ttwap: serializedOrderbook.oracleData.twap\n\t\t\t\t? new BN(serializedOrderbook.oracleData.twap)\n\t\t\t\t: undefined,\n\t\t\ttwapConfidence: serializedOrderbook.oracleData.twapConfidence\n\t\t\t\t? new BN(serializedOrderbook.oracleData.twapConfidence)\n\t\t\t\t: undefined,\n\t\t\tmaxPrice: serializedOrderbook.oracleData.maxPrice\n\t\t\t\t? new BN(serializedOrderbook.oracleData.maxPrice)\n\t\t\t\t: undefined,\n\t\t},\n\t\tmmOracleData: {\n\t\t\tprice: serializedOrderbook.mmOracleData?.price\n\t\t\t\t? new BN(serializedOrderbook.mmOracleData.price)\n\t\t\t\t: undefined,\n\t\t\tslot: serializedOrderbook.mmOracleData?.slot\n\t\t\t\t? new BN(serializedOrderbook.mmOracleData.slot)\n\t\t\t\t: undefined,\n\t\t\tconfidence: serializedOrderbook.mmOracleData?.confidence\n\t\t\t\t? new BN(serializedOrderbook.mmOracleData.confidence)\n\t\t\t\t: undefined,\n\t\t\thasSufficientNumberOfDataPoints:\n\t\t\t\tserializedOrderbook.mmOracleData?.hasSufficientNumberOfDataPoints,\n\t\t\tisMMOracleActive:\n\t\t\t\tserializedOrderbook.mmOracleData?.isMMOracleActive ?? false,\n\t\t},\n\t\tslot: serializedOrderbook.slot,\n\t\tmarketSlot: serializedOrderbook.marketSlot,\n\t\tmarketType: serializedOrderbook.marketType,\n\t\tmarketIndex: serializedOrderbook.marketIndex,\n\t\tmarketName: serializedOrderbook.marketName,\n\t\tmarkPrice: new BN(serializedOrderbook.markPrice),\n\t\tbestBidPrice: new BN(serializedOrderbook.bestBidPrice),\n\t\tbestAskPrice: new BN(serializedOrderbook.bestAskPrice),\n\t\tspreadPct: new BN(serializedOrderbook.spreadPct),\n\t\tspreadQuote: new BN(serializedOrderbook.spreadQuote),\n\t};\n};\n\nexport const convertToL2OrderBook = (\n\tl2Data: L2WithOracleAndMarketData[]\n): L2OrderBook => {\n\t// Find the market data - there should be one entry for our market\n\tconst marketData = l2Data[0];\n\n\tif (!marketData) {\n\t\tthrow new Error('No L2 data available for market');\n\t}\n\n\t// L2WithOracleAndMarketData extends L2OrderBook, so we can use it directly\n\treturn {\n\t\tasks: marketData.asks,\n\t\tbids: marketData.bids,\n\t\tslot: marketData.slot,\n\t};\n};\n\nexport interface DynamicSlippageConfig {\n\tdynamicSlippageMin?: number;\n\tdynamicSlippageMax?: number;\n\tdynamicBaseSlippageMajor?: number;\n\tdynamicBaseSlippageNonMajor?: number;\n\tdynamicSlippageMultiplierMajor?: number;\n\tdynamicSlippageMultiplierNonMajor?: number;\n}\n\nconst DEFAULT_DYNAMIC_SLIPPAGE_CONFIG: DynamicSlippageConfig = {\n\tdynamicSlippageMin: 0.05,\n\tdynamicSlippageMax: 5,\n\tdynamicBaseSlippageMajor: 0,\n\tdynamicBaseSlippageNonMajor: 0.5,\n\tdynamicSlippageMultiplierMajor: 1.02,\n\tdynamicSlippageMultiplierNonMajor: 1.2,\n};\n\nexport const calculateDynamicSlippageFromL2 = ({\n\tl2Data,\n\tmarketId,\n\tstartPrice,\n\tworstPrice,\n\toraclePrice,\n\tdynamicSlippageConfig,\n}: {\n\tl2Data: L2OrderBook;\n\tmarketId: MarketId;\n\tstartPrice: BN;\n\tworstPrice: BN;\n\toraclePrice?: BN;\n\tdynamicSlippageConfig?: DynamicSlippageConfig;\n}): number => {\n\tconst dynamicSlippageConfigToUse = dynamicSlippageConfig\n\t\t? { ...DEFAULT_DYNAMIC_SLIPPAGE_CONFIG, ...dynamicSlippageConfig }\n\t\t: DEFAULT_DYNAMIC_SLIPPAGE_CONFIG;\n\n\t// Calculate spread information from L2 data using the oracle price\n\tconst spreadBidAskMark = COMMON_MATH.calculateSpreadBidAskMark(\n\t\tl2Data,\n\t\toraclePrice\n\t);\n\n\tconst bestAskNum = spreadBidAskMark.bestAskPrice?.toNumber?.() || 0;\n\tconst bestBidNum = spreadBidAskMark.bestBidPrice?.toNumber?.() || 0;\n\n\tconst spreadPctFromL2 = BigNum.from(\n\t\tspreadBidAskMark.spreadPct,\n\t\tPERCENTAGE_PRECISION_EXP\n\t).toNum();\n\n\t// Calculate spread percentage\n\tconst spreadPct =\n\t\tspreadPctFromL2 ||\n\t\t(Math.abs(bestAskNum - bestBidNum) / ((bestAskNum + bestBidNum) / 2)) * 100;\n\n\t// Default to 0.5% if we get invalid spread info\n\tif (isNaN(spreadPct) || spreadPct <= 0) {\n\t\treturn 0.5;\n\t}\n\n\t// Apply a buffer based on the tier of the contract\n\t// Currently no buffer for SOL/BTC/ETH perp and a +10% buffer for other markets\n\tconst isMajor = marketId.isPerp && marketId.marketIndex < 3;\n\n\tconst spreadBaseSlippage = spreadPct / 2;\n\n\tconst baseSlippage = isMajor\n\t\t? dynamicSlippageConfigToUse.dynamicBaseSlippageMajor\n\t\t: dynamicSlippageConfigToUse.dynamicBaseSlippageNonMajor;\n\tlet dynamicSlippage = baseSlippage + spreadBaseSlippage;\n\n\t// Use halfway to worst price as size adjusted slippage\n\tif (startPrice && worstPrice) {\n\t\tconst sizeAdjustedSlippage =\n\t\t\t(startPrice.sub(worstPrice).abs().toNumber() /\n\t\t\t\tBN.max(startPrice, worstPrice).toNumber() /\n\t\t\t\t2) *\n\t\t\t100;\n\n\t\tdynamicSlippage = Math.max(dynamicSlippage, sizeAdjustedSlippage);\n\t}\n\n\t// Apply multiplier from env var\n\tconst multiplier = isMajor\n\t\t? dynamicSlippageConfigToUse.dynamicSlippageMultiplierMajor\n\t\t: dynamicSlippageConfigToUse.dynamicSlippageMultiplierNonMajor;\n\n\tdynamicSlippage = dynamicSlippage * multiplier;\n\n\t// Enforce .05% minimum, 5% maximum, can change these in env vars\n\tconst finalSlippage = Math.min(\n\t\tMath.max(dynamicSlippage, dynamicSlippageConfigToUse.dynamicSlippageMin),\n\t\tdynamicSlippageConfigToUse.dynamicSlippageMax\n\t);\n\n\t// Round to avoid floating point precision issues, preserving 6 decimal places\n\treturn Math.round(finalSlippage * 1000000) / 1000000;\n};\n\nexport const getFormattedSize = (\n\tsizesObject: Partial<Record<LiquidityType, number>>,\n\tprice: number,\n\tcurrency: CUMULATIVE_SIZE_CURRENCY,\n\tdisplayDecimals: number\n) => {\n\tconst sizeSum = Object.values(sizesObject || {}).reduce(\n\t\t(acc, curr) => acc + curr,\n\t\t0\n\t);\n\n\tconst displayValue =\n\t\tcurrency === CUMULATIVE_SIZE_CURRENCY.USD && price\n\t\t\t? sizeSum * price\n\t\t\t: sizeSum;\n\n\treturn BigNum.fromPrint(\n\t\tdisplayValue.toFixed(displayDecimals),\n\t\tnew BN(displayDecimals)\n\t).toMillified(3);\n};\n\nexport const getLiquidityPcts = (\n\ttotalSize: number,\n\tcumulativeSize: CategorisedLiquidity = {}\n) => {\n\tconst totalCumulativeSize = Object.values(cumulativeSize).reduce(\n\t\t(acc, curr) => acc + curr,\n\t\t0\n\t);\n\n\tconst cumulativeSizePct = totalSize\n\t\t? (totalCumulativeSize / totalSize) * 100\n\t\t: 0; // This is the portion of the total size of the orderbook that the cumulative size of the liquidity should be occupying.\n\n\tconst cumulativeRestingSize =\n\t\ttotalCumulativeSize - (cumulativeSize?.indicative ?? 0);\n\tconst cumulativeIndicativeSize = cumulativeSize?.indicative ?? 0;\n\n\tconst restingLiquidityPct =\n\t\t(cumulativeRestingSize / totalCumulativeSize) * cumulativeSizePct; // This is the portion of the width of the orderbook that the resting liquidity should be occupying\n\n\tconst indicativeLiquidityPct =\n\t\t(cumulativeIndicativeSize / totalCumulativeSize) * cumulativeSizePct; // This is the portion of the width of the orderbook that the indicative liquidity should be occupying\n\n\treturn {\n\t\trestingLiquidityPct,\n\t\tindicativeLiquidityPct,\n\t};\n};\n\nconst roundForOrderbook = (num: number) => Number(num.toFixed(6));\n\nexport const getBucketFloorForPrice = (\n\tprice: number,\n\tgroupingSize: GroupingSizeQuoteValue\n) => {\n\tconst priceIsNegative = price < 0;\n\n\tconst _groupingSize = groupingSize as unknown as number;\n\n\tif (COMMON_UTILS.dividesExactly(price, _groupingSize)) {\n\t\treturn roundForOrderbook(price);\n\t}\n\n\tconst amountToDeduct = priceIsNegative\n\t\t? _groupingSize - (Math.abs(price) % _groupingSize)\n\t\t: Math.abs(price) % _groupingSize;\n\n\tconst floorPrice = price - amountToDeduct;\n\n\treturn roundForOrderbook(floorPrice);\n};\n\nexport const getUserLiquidityForPrice = ({\n\tprice,\n\tside,\n\tgroupingSizeValue,\n\tuserAskPriceBucketLookup,\n\tuserBidPriceBucketLookup,\n}: {\n\tprice: number;\n\tside: 'bid' | 'ask';\n\tgroupingSizeValue: GroupingSizeQuoteValue;\n\tuserAskPriceBucketLookup: Map<number, OrderBookBidAsk>;\n\tuserBidPriceBucketLookup: Map<number, OrderBookBidAsk>;\n}) => {\n\tlet isCurrentUserLiquidity = false;\n\tlet currentUserLiquiditySize = 0;\n\n\tconst priceToUse = price;\n\tconst priceBucket = getBucketFloorForPrice(priceToUse, groupingSizeValue);\n\n\tconst lookupBucket =\n\t\tside === 'bid' ? userBidPriceBucketLookup : userAskPriceBucketLookup;\n\n\tconst matchingUserBidAsk = lookupBucket.get(priceBucket);\n\n\tif (matchingUserBidAsk) {\n\t\tisCurrentUserLiquidity = true;\n\t\tcurrentUserLiquiditySize = matchingUserBidAsk.size;\n\t}\n\n\treturn { isCurrentUserLiquidity, currentUserLiquiditySize };\n};\n\nconst getBucketCeilingForPrice = (\n\tprice: number,\n\tgroupingSize: GroupingSizeQuoteValue\n) => {\n\tconst _groupingSize = groupingSize as unknown as number;\n\treturn getBucketFloorForPrice(price + _groupingSize, groupingSize);\n};\n\nexport const getBucketAnchorPrice = (\n\ttype: 'bid' | 'ask',\n\tprice: number,\n\tgroupingSize: GroupingSizeQuoteValue\n) => {\n\t// If the grouping size matches exactly then the anchor price should be the same as the floor price regardless\n\tif (COMMON_UTILS.dividesExactly(price, groupingSize as unknown as number)) {\n\t\treturn getBucketFloorForPrice(price, groupingSize);\n\t}\n\n\tif (type === 'bid') {\n\t\treturn getBucketFloorForPrice(price, groupingSize);\n\t} else {\n\t\treturn getBucketCeilingForPrice(price, groupingSize);\n\t}\n};\n\nexport const getBucketForUserLiquidity = (\n\tprice: number,\n\tgroupingSize: GroupingSizeQuoteValue,\n\ttype: 'bid' | 'ask'\n) => getBucketAnchorPrice(type, price, groupingSize);\n\nexport const mergeBidsAndAsksForGroupsize = (\n\ttype: 'bid' | 'ask',\n\tbidsAsks: OrderBookBidAsk[],\n\tgroupingSize: GroupingSizeQuoteValue\n): OrderBookBidAsk[] => {\n\tconst bidsAsksBucketLookup = new Map<number, OrderBookBidAsk>();\n\n\tfor (const bidAsk of bidsAsks) {\n\t\tconst anchorPrice = getBucketAnchorPrice(type, bidAsk.price, groupingSize);\n\t\tconst existingBucket = bidsAsksBucketLookup.get(anchorPrice);\n\t\tif (existingBucket) {\n\t\t\texistingBucket.size += bidAsk.size;\n\t\t} else {\n\t\t\tbidsAsksBucketLookup.set(anchorPrice, { ...bidAsk });\n\t\t}\n\t}\n\n\treturn Array.from(bidsAsksBucketLookup.values());\n};\n\nexport const getZeroPaddingForGroupingSize = (\n\tgroupingSize: GroupingSizeQuoteValue\n) => {\n\tconst _groupingSize = groupingSize as unknown as number;\n\n\tconst precision = Math.floor(Math.log10(_groupingSize));\n\n\tif (precision >= 0 || _groupingSize === 0) return 0;\n\n\treturn Math.abs(precision);\n};\n\nconst sizeToNum = (size: BN, precision: BN) =>\n\tBigNum.from(size, precision).toNum();\n\nexport const getCategorisedLiquidityForLevel = (\n\tlevel: L2Level,\n\tbasePrecision: BN\n): CategorisedLiquidity => {\n\tconst dlobSize = sizeToNum(level?.sources?.dlob ?? ZERO, basePrecision);\n\tconst vammSize = sizeToNum(level?.sources?.vamm ?? ZERO, basePrecision);\n\tconst serumSize = sizeToNum(level?.sources?.serum ?? ZERO, basePrecision);\n\tconst phoenixSize = sizeToNum(level?.sources?.phoenix ?? ZERO, basePrecision);\n\tconst openbookSize = sizeToNum(\n\t\tlevel?.sources?.openbook ?? ZERO,\n\t\tbasePrecision\n\t);\n\tconst indicativeSize = sizeToNum(\n\t\tlevel?.sources?.indicative ?? ZERO,\n\t\tbasePrecision\n\t);\n\n\tconst categorisedLiquidity: CategorisedLiquidity = {\n\t\tdlob: dlobSize,\n\t\tvamm: vammSize,\n\t\tserum: serumSize,\n\t\tphoenix: phoenixSize,\n\t\topenbook: openbookSize,\n\t\tindicative: indicativeSize,\n\t};\n\n\treturn categorisedLiquidity;\n};\n\nconst formatLevelsToDisplay = (\n\tlevels: L2Level[],\n\tbasePrecision: BN,\n\tdepth?: number\n): {\n\tformattedLevels: OrderBookDisplayStateBidAsk[];\n\tbestLevel: number;\n\tcumulativeSize: number;\n} => {\n\tconst relevantSources: Set<LiquidityType> = new Set();\n\n\tfor (const level of levels) {\n\t\tfor (const source of Object.keys(level.sources)) {\n\t\t\trelevantSources.add(source as LiquidityType);\n\t\t}\n\t}\n\n\tconst cumulativeSizes: CategorisedLiquidity = Array.from(\n\t\trelevantSources\n\t).reduce((acc, source) => {\n\t\tacc[source] = 0;\n\t\treturn acc;\n\t}, {} as CategorisedLiquidity);\n\n\tlet cumulativePriceSizeProduct = 0;\n\tlet cumulativeTotalSize = 0;\n\n\tconst formattedLevels: OrderBookDisplayStateBidAsk[] = levels.map((level) => {\n\t\tconst bucketSize = getCategorisedLiquidityForLevel(level, basePrecision);\n\t\tconst price = BigNum.from(level.price, PRICE_PRECISION_EXP).toNum();\n\t\tconst totalSize = Object.values(bucketSize).reduce(\n\t\t\t(sum, size) => sum + size,\n\t\t\t0\n\t\t);\n\n\t\tfor (const source of relevantSources) {\n\t\t\tconst currentValue = cumulativeSizes[source];\n\t\t\tif (currentValue !== undefined) {\n\t\t\t\tcumulativeSizes[source] = currentValue + (bucketSize[source] ?? 0);\n\t\t\t}\n\t\t}\n\n\t\tcumulativePriceSizeProduct += price * totalSize;\n\t\tcumulativeTotalSize += totalSize;\n\n\t\treturn {\n\t\t\tprice,\n\t\t\tsize: bucketSize,\n\t\t\tcumulativeSize: { ...cumulativeSizes },\n\t\t\tcumulativeAvgPrice:\n\t\t\t\tcumulativeTotalSize > 0\n\t\t\t\t\t? cumulativePriceSizeProduct / cumulativeTotalSize\n\t\t\t\t\t: 0,\n\t\t};\n\t});\n\n\tif (depth && depth > 0) {\n\t\tconst visibleLevels = formattedLevels.slice(0, depth);\n\t\tconst maxCumulativeSize = Math.max(\n\t\t\t0,\n\t\t\t...visibleLevels.map((level) =>\n\t\t\t\tObject.values(level.cumulativeSize).reduce((sum, size) => sum + size, 0)\n\t\t\t)\n\t\t);\n\n\t\treturn {\n\t\t\tformattedLevels: visibleLevels,\n\t\t\tbestLevel: visibleLevels?.[0]?.price,\n\t\t\tcumulativeSize: maxCumulativeSize,\n\t\t};\n\t}\n\n\tconst totalSizeToReturn = Object.values(cumulativeSizes).reduce(\n\t\t(total, current) => total + current,\n\t\t0\n\t);\n\n\treturn {\n\t\tformattedLevels,\n\t\tbestLevel: formattedLevels?.[0]?.price,\n\t\tcumulativeSize: totalSizeToReturn,\n\t};\n};\n\nexport const formatL2ToDisplay = (\n\tl2State: L2OrderBook,\n\tbasePrecision: BN,\n\tdepth?: number\n) => {\n\tconst formattedBids = formatLevelsToDisplay(\n\t\tl2State.bids,\n\t\tbasePrecision,\n\t\tdepth\n\t);\n\tconst formattedAsks = formatLevelsToDisplay(\n\t\tl2State.asks,\n\t\tbasePrecision,\n\t\tdepth\n\t);\n\n\treturn {\n\t\tbids: formattedBids.formattedLevels,\n\t\tasks: formattedAsks.formattedLevels,\n\t\tbidTotalSize: formattedBids.cumulativeSize,\n\t\taskTotalSize: formattedAsks.cumulativeSize,\n\t};\n};\n\nconst filterOutDisabledLiquidityTypes = (\n\tl2Levels: L2Level[],\n\tdisabledLiquidityTypes: LiquidityType[]\n) =>\n\tl2Levels\n\t\t.map((level) => {\n\t\t\tlet totalDisabledSize = ZERO;\n\t\t\tconst disabledSourceObj: Record<LiquidityType, BN> = {} as Record<\n\t\t\t\tLiquidityType,\n\t\t\t\tBN\n\t\t\t>;\n\n\t\t\tfor (const liquidityType of disabledLiquidityTypes) {\n\t\t\t\tconst disabledLiqSize = level.sources?.[liquidityType];\n\t\t\t\tif (disabledLiqSize?.gt(ZERO)) {\n\t\t\t\t\ttotalDisabledSize = totalDisabledSize.add(disabledLiqSize);\n\t\t\t\t\tdisabledSourceObj[liquidityType] = ZERO;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn totalDisabledSize.gt(ZERO)\n\t\t\t\t? {\n\t\t\t\t\t\t...level,\n\t\t\t\t\t\tsize: level.size.sub(totalDisabledSize),\n\t\t\t\t\t\tsources: {\n\t\t\t\t\t\t\t...level.sources,\n\t\t\t\t\t\t\t...disabledSourceObj,\n\t\t\t\t\t\t},\n\t\t\t\t }\n\t\t\t\t: level;\n\t\t})\n\t\t.filter((level) => level.size.gt(ZERO));\n\nexport const l2ToDisplayBidsAndAsks = (\n\tl2Orderbook: L2OrderBook,\n\toraclePrice: BN,\n\ttickSizeForMarket: BN,\n\tgroupSizeTickMultiplier: number,\n\tuserBidsAndAsks: BidsAndAsks,\n\tbasePrecisionForMarket: BN,\n\tdisabledLiquidityTypes: LiquidityType[],\n\tmaxDepth: number,\n\tdepth?: number // limit the number of visible rows to calculate totalSize from\n) => {\n\tconst filteredBids =\n\t\tdisabledLiquidityTypes.length > 0\n\t\t\t? filterOutDisabledLiquidityTypes(\n\t\t\t\t\tl2Orderbook.bids,\n\t\t\t\t\tdisabledLiquidityTypes\n\t\t\t )\n\t\t\t: l2Orderbook.bids;\n\n\tconst filteredAsks =\n\t\tdisabledLiquidityTypes.length > 0\n\t\t\t? filterOutDisabledLiquidityTypes(\n\t\t\t\t\tl2Orderbook.asks,\n\t\t\t\t\tdisabledLiquidityTypes\n\t\t\t )\n\t\t\t: l2Orderbook.asks;\n\n\t// # Uncross the liquidity\n\tconst uncrossed = {\n\t\tl2Orderbook,\n\t\tbids: filteredBids,\n\t\tasks: filteredAsks,\n\t};\n\n\t// Group the orderbook into levels based on the grouping size\n\tconst grouped = groupL2(\n\t\tuncrossed,\n\t\ttickSizeForMarket.muln(groupSizeTickMultiplier ?? 1), // one user had a weird error where .muln was throwing assertion failed error\n\t\tmaxDepth\n\t);\n\n\t// # Convert to UI format\n\tconst formatted = formatL2ToDisplay(grouped, basePrecisionForMarket, depth);\n\n\t// Check that bids are in descending order\n\tif (\n\t\tformatted.bids.some((bid, index) => {\n\t\t\tif (index === 0) return false;\n\n\t\t\treturn bid.price > formatted.bids[index - 1].price;\n\t\t})\n\t) {\n\t\tconsole.log('orderbook - bids_not_in_descending_order', {\n\t\t\tl2Orderbook,\n\t\t\toraclePrice,\n\t\t\ttickSizeForMarket,\n\t\t\tuserBidsAndAsks,\n\t\t\tbasePrecisionForMarket,\n\t\t\tuncrossed,\n\t\t\tformatted,\n\t\t});\n\t}\n\n\t// Check that asks are in ascending order\n\tif (\n\t\tformatted.asks.some((ask, index) => {\n\t\t\tif (index === 0) return false;\n\n\t\t\treturn ask.price < formatted.asks[index - 1].price;\n\t\t})\n\t) {\n\t\tconsole.log('orderbook - asks_not_in_ascending_order', {\n\t\t\tl2Orderbook,\n\t\t\toraclePrice,\n\t\t\ttickSizeForMarket,\n\t\t\tuserBidsAndAsks,\n\t\t\tbasePrecisionForMarket,\n\t\t\tuncrossed,\n\t\t\tformatted,\n\t\t});\n\t}\n\n\treturn formatted;\n};\n\nexport const getEmptyFilledBidsAsks = (\n\tbidsOrAsks: OrderBookDisplayStateBidAsk[],\n\tdepth: number\n): (OrderBookDisplayStateBidAsk | EmptyRow)[] => {\n\tconst result = Array(depth).fill(EMPTY_ORDERBOOK_ROW);\n\n\tbidsOrAsks.forEach((bidOrAsk, index) => {\n\t\tif (index < depth) {\n\t\t\tresult[index] = bidOrAsk;\n\t\t}\n\t});\n\n\treturn result;\n};\n"]}
@@ -0,0 +1,101 @@
1
+ import { Opaque } from '../../types/utility';
2
+ import { MarketType, OraclePriceData, L2OrderBook, BN, MMOraclePriceData, L2Level, BigNum } from '@drift-labs/sdk';
3
+ export interface L2WithOracle extends L2OrderBook {
4
+ oracleData: OraclePriceData;
5
+ markPrice: BN;
6
+ bestBidPrice: BN;
7
+ bestAskPrice: BN;
8
+ spreadPct: BN;
9
+ spreadQuote: BN;
10
+ mmOracleData?: MMOraclePriceData;
11
+ }
12
+ export interface L2WithOracleAndMarketData extends L2WithOracle {
13
+ marketSlot: number;
14
+ marketIndex: number;
15
+ marketName: string;
16
+ marketType?: MarketType;
17
+ }
18
+ export type RawL2Output = {
19
+ marketIndex: number;
20
+ marketType: MarketType;
21
+ marketName: string;
22
+ marketSlot: number;
23
+ asks: {
24
+ price: string;
25
+ size: string;
26
+ sources: {
27
+ [key: string]: string;
28
+ };
29
+ }[];
30
+ bids: {
31
+ price: string;
32
+ size: string;
33
+ sources: {
34
+ [key: string]: string;
35
+ };
36
+ }[];
37
+ oracleData: {
38
+ price: string;
39
+ slot: string;
40
+ confidence: string;
41
+ hasSufficientNumberOfDataPoints: boolean;
42
+ twap?: string;
43
+ twapConfidence?: string;
44
+ maxPrice?: string;
45
+ };
46
+ mmOracleData?: {
47
+ price: string;
48
+ slot: string;
49
+ confidence: string;
50
+ hasSufficientNumberOfDataPoints: boolean;
51
+ isMMOracleActive: boolean;
52
+ };
53
+ markPrice: string;
54
+ bestBidPrice: string;
55
+ bestAskPrice: string;
56
+ spreadPct: string;
57
+ spreadQuote: string;
58
+ slot?: number;
59
+ };
60
+ export type LiquidityType = keyof L2Level['sources'];
61
+ export type OrderBookBidAsk = {
62
+ price: number;
63
+ size: number;
64
+ type: LiquidityType;
65
+ };
66
+ export type BidsAndAsks = {
67
+ bids: OrderBookBidAsk[];
68
+ asks: OrderBookBidAsk[];
69
+ };
70
+ export declare enum CUMULATIVE_SIZE_CURRENCY {
71
+ USD = 0,
72
+ BASE = 1
73
+ }
74
+ export type GroupingSizeQuoteValue = Opaque<number, 'GroupingSizeQuoteValue'>;
75
+ export type CategorisedLiquidity = Partial<Record<LiquidityType, number>>;
76
+ export type GroupingSizeSelectionState = {
77
+ options: number[];
78
+ selectionIndex: number;
79
+ updateSelectionIndex: (newVal: number | string) => void;
80
+ };
81
+ export type MarketPriceState = {
82
+ bestBid: BigNum;
83
+ bestAsk: BigNum;
84
+ markPrice: BigNum;
85
+ spreadPct: BigNum;
86
+ spreadQuote: BigNum;
87
+ slot?: number;
88
+ };
89
+ export type OrderBookDisplayStateBidAsk = {
90
+ price: number;
91
+ size: CategorisedLiquidity;
92
+ cumulativeSize: CategorisedLiquidity;
93
+ cumulativeAvgPrice: number;
94
+ };
95
+ export type OrderBookDisplayState = {
96
+ bids: OrderBookDisplayStateBidAsk[];
97
+ asks: OrderBookDisplayStateBidAsk[];
98
+ bidTotalSize: number;
99
+ askTotalSize: number;
100
+ };
101
+ export type EmptyRow = Opaque<'EmptyRow', string>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CUMULATIVE_SIZE_CURRENCY = void 0;
4
+ var CUMULATIVE_SIZE_CURRENCY;
5
+ (function (CUMULATIVE_SIZE_CURRENCY) {
6
+ CUMULATIVE_SIZE_CURRENCY[CUMULATIVE_SIZE_CURRENCY["USD"] = 0] = "USD";
7
+ CUMULATIVE_SIZE_CURRENCY[CUMULATIVE_SIZE_CURRENCY["BASE"] = 1] = "BASE";
8
+ })(CUMULATIVE_SIZE_CURRENCY || (exports.CUMULATIVE_SIZE_CURRENCY = CUMULATIVE_SIZE_CURRENCY = {}));
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/orderbook/types.ts"],"names":[],"mappings":";;;AAqFA,IAAY,wBAGX;AAHD,WAAY,wBAAwB;IACnC,qEAAG,CAAA;IACH,uEAAI,CAAA;AACL,CAAC,EAHW,wBAAwB,wCAAxB,wBAAwB,QAGnC","sourcesContent":["import { Opaque } from '../../types/utility';\n\nimport {\n\tMarketType,\n\tOraclePriceData,\n\tL2OrderBook,\n\tBN,\n\tMMOraclePriceData,\n\tL2Level,\n\tBigNum,\n} from '@drift-labs/sdk';\n\nexport interface L2WithOracle extends L2OrderBook {\n\toracleData: OraclePriceData;\n\tmarkPrice: BN;\n\tbestBidPrice: BN;\n\tbestAskPrice: BN;\n\tspreadPct: BN;\n\tspreadQuote: BN;\n\tmmOracleData?: MMOraclePriceData;\n}\n\nexport interface L2WithOracleAndMarketData extends L2WithOracle {\n\tmarketSlot: number;\n\tmarketIndex: number;\n\tmarketName: string;\n\tmarketType?: MarketType;\n}\n\nexport type RawL2Output = {\n\tmarketIndex: number;\n\tmarketType: MarketType;\n\tmarketName: string;\n\tmarketSlot: number;\n\tasks: {\n\t\tprice: string;\n\t\tsize: string;\n\t\tsources: {\n\t\t\t[key: string]: string;\n\t\t};\n\t}[];\n\tbids: {\n\t\tprice: string;\n\t\tsize: string;\n\t\tsources: {\n\t\t\t[key: string]: string;\n\t\t};\n\t}[];\n\toracleData: {\n\t\tprice: string;\n\t\tslot: string;\n\t\tconfidence: string;\n\t\thasSufficientNumberOfDataPoints: boolean;\n\t\ttwap?: string;\n\t\ttwapConfidence?: string;\n\t\tmaxPrice?: string;\n\t};\n\tmmOracleData?: {\n\t\tprice: string;\n\t\tslot: string;\n\t\tconfidence: string;\n\t\thasSufficientNumberOfDataPoints: boolean;\n\t\tisMMOracleActive: boolean;\n\t};\n\tmarkPrice: string;\n\tbestBidPrice: string;\n\tbestAskPrice: string;\n\tspreadPct: string;\n\tspreadQuote: string;\n\tslot?: number;\n};\n\nexport type LiquidityType = keyof L2Level['sources'];\n\nexport type OrderBookBidAsk = {\n\tprice: number;\n\tsize: number;\n\ttype: LiquidityType;\n};\n\nexport type BidsAndAsks = {\n\tbids: OrderBookBidAsk[];\n\tasks: OrderBookBidAsk[];\n};\n\nexport enum CUMULATIVE_SIZE_CURRENCY {\n\tUSD,\n\tBASE,\n}\n\nexport type GroupingSizeQuoteValue = Opaque<number, 'GroupingSizeQuoteValue'>;\n\nexport type CategorisedLiquidity = Partial<Record<LiquidityType, number>>;\n\nexport type GroupingSizeSelectionState = {\n\toptions: number[];\n\tselectionIndex: number;\n\tupdateSelectionIndex: (newVal: number | string) => void;\n};\n\nexport type MarketPriceState = {\n\tbestBid: BigNum;\n\tbestAsk: BigNum;\n\tmarkPrice: BigNum;\n\tspreadPct: BigNum;\n\tspreadQuote: BigNum;\n\tslot?: number;\n};\n\nexport type OrderBookDisplayStateBidAsk = {\n\tprice: number;\n\tsize: CategorisedLiquidity;\n\tcumulativeSize: CategorisedLiquidity;\n\tcumulativeAvgPrice: number;\n};\n\nexport type OrderBookDisplayState = {\n\tbids: OrderBookDisplayStateBidAsk[];\n\tasks: OrderBookDisplayStateBidAsk[];\n\tbidTotalSize: number;\n\taskTotalSize: number;\n};\n\nexport type EmptyRow = Opaque<'EmptyRow', string>;\n"]}
@@ -0,0 +1 @@
1
+ export declare function getSwiftConfirmationTimeoutMs(auctionDurationSlots: number, multiplier?: number): number;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSwiftConfirmationTimeoutMs = void 0;
4
+ const sdk_1 = require("@drift-labs/sdk");
5
+ function getSwiftConfirmationTimeoutMs(auctionDurationSlots, multiplier) {
6
+ const baseMs = ((auctionDurationSlots !== null && auctionDurationSlots !== void 0 ? auctionDurationSlots : 0) + 15) * sdk_1.SLOT_TIME_ESTIMATE_MS;
7
+ return baseMs * (multiplier !== null && multiplier !== void 0 ? multiplier : 1);
8
+ }
9
+ exports.getSwiftConfirmationTimeoutMs = getSwiftConfirmationTimeoutMs;
10
+ //# sourceMappingURL=signedMsgs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signedMsgs.js","sourceRoot":"","sources":["../../src/utils/signedMsgs.ts"],"names":[],"mappings":";;;AAAA,yCAAwD;AAExD,SAAgB,6BAA6B,CAC5C,oBAA4B,EAC5B,UAAmB;IAEnB,MAAM,MAAM,GAAG,CAAC,CAAC,oBAAoB,aAApB,oBAAoB,cAApB,oBAAoB,GAAI,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,2BAAqB,CAAC;IAC1E,OAAO,MAAM,GAAG,CAAC,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,CAAC,CAAC,CAAC;AACnC,CAAC;AAND,sEAMC","sourcesContent":["import { SLOT_TIME_ESTIMATE_MS } from '@drift-labs/sdk';\n\nexport function getSwiftConfirmationTimeoutMs(\n\tauctionDurationSlots: number,\n\tmultiplier?: number\n): number {\n\tconst baseMs = ((auctionDurationSlots ?? 0) + 15) * SLOT_TIME_ESTIMATE_MS;\n\treturn baseMs * (multiplier ?? 1);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/common",
3
- "version": "1.0.13",
3
+ "version": "1.0.16",
4
4
  "description": "Common functions for Drift",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",