@drift-labs/sdk 2.12.0-beta.2 → 2.12.0-beta.3

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 (52) hide show
  1. package/lib/accounts/bulkAccountLoader.js +3 -3
  2. package/lib/accounts/fetch.js +2 -2
  3. package/lib/accounts/pollingDriftClientAccountSubscriber.js +7 -7
  4. package/lib/accounts/pollingTokenAccountSubscriber.js +2 -2
  5. package/lib/accounts/pollingUserAccountSubscriber.js +2 -2
  6. package/lib/accounts/pollingUserStatsAccountSubscriber.js +2 -2
  7. package/lib/accounts/webSocketAccountSubscriber.js +1 -1
  8. package/lib/accounts/webSocketDriftClientAccountSubscriber.js +3 -3
  9. package/lib/addresses/marketAddresses.js +1 -1
  10. package/lib/addresses/pda.js +1 -5
  11. package/lib/adminClient.js +57 -61
  12. package/lib/dlob/DLOB.js +67 -67
  13. package/lib/dlob/DLOBNode.js +7 -7
  14. package/lib/dlob/NodeList.js +2 -2
  15. package/lib/driftClient.d.ts +3 -3
  16. package/lib/driftClient.js +83 -87
  17. package/lib/events/eventSubscriber.js +2 -2
  18. package/lib/events/pollingLogProvider.js +1 -1
  19. package/lib/examples/makeTradeExample.js +9 -9
  20. package/lib/factory/bigNum.js +9 -9
  21. package/lib/factory/oracleClient.js +2 -2
  22. package/lib/idl/drift.json +1 -1
  23. package/lib/index.js +1 -5
  24. package/lib/math/amm.js +23 -23
  25. package/lib/math/auction.js +6 -6
  26. package/lib/math/exchangeStatus.js +2 -2
  27. package/lib/math/funding.js +2 -2
  28. package/lib/math/margin.js +5 -5
  29. package/lib/math/market.js +12 -12
  30. package/lib/math/oracles.js +1 -1
  31. package/lib/math/orders.js +23 -23
  32. package/lib/math/position.js +5 -5
  33. package/lib/math/repeg.js +1 -1
  34. package/lib/math/spotBalance.js +7 -7
  35. package/lib/math/spotPosition.js +3 -3
  36. package/lib/math/trade.js +34 -34
  37. package/lib/oracles/oracleClientCache.js +1 -1
  38. package/lib/oracles/pythClient.js +1 -1
  39. package/lib/tokenFaucet.js +1 -5
  40. package/lib/tx/retryTxSender.js +1 -1
  41. package/lib/tx/utils.d.ts +1 -1
  42. package/lib/tx/utils.js +7 -4
  43. package/lib/types.d.ts +4 -0
  44. package/lib/user.js +47 -47
  45. package/lib/userMap/userMap.js +1 -1
  46. package/lib/userMap/userStatsMap.js +3 -3
  47. package/lib/userStats.js +2 -2
  48. package/package.json +1 -1
  49. package/src/driftClient.ts +11 -4
  50. package/src/idl/drift.json +1 -1
  51. package/src/tx/utils.ts +11 -3
  52. package/src/types.ts +5 -0
package/lib/dlob/DLOB.js CHANGED
@@ -78,10 +78,10 @@ class DLOB {
78
78
  this.insertOrder(record.order, record.user);
79
79
  }
80
80
  handleOrderActionRecord(record) {
81
- if ((0, __1.isOneOfVariant)(record.action, ['place', 'expire'])) {
81
+ if (__1.isOneOfVariant(record.action, ['place', 'expire'])) {
82
82
  return;
83
83
  }
84
- if ((0, __1.isVariant)(record.action, 'trigger')) {
84
+ if (__1.isVariant(record.action, 'trigger')) {
85
85
  if (record.taker !== null) {
86
86
  const takerOrder = this.getOrder(record.takerOrderId, record.taker);
87
87
  if (takerOrder) {
@@ -95,7 +95,7 @@ class DLOB {
95
95
  }
96
96
  }
97
97
  }
98
- else if ((0, __1.isVariant)(record.action, 'fill')) {
98
+ else if (__1.isVariant(record.action, 'fill')) {
99
99
  if (record.taker !== null) {
100
100
  const takerOrder = this.getOrder(record.takerOrderId, record.taker);
101
101
  if (takerOrder) {
@@ -109,7 +109,7 @@ class DLOB {
109
109
  }
110
110
  }
111
111
  }
112
- else if ((0, __1.isVariant)(record.action, 'cancel')) {
112
+ else if (__1.isVariant(record.action, 'cancel')) {
113
113
  if (record.taker !== null) {
114
114
  const takerOrder = this.getOrder(record.takerOrderId, record.taker);
115
115
  if (takerOrder) {
@@ -126,20 +126,20 @@ class DLOB {
126
126
  }
127
127
  insertOrder(order, userAccount, onInsert) {
128
128
  var _a;
129
- if ((0, __1.isVariant)(order.status, 'init')) {
129
+ if (__1.isVariant(order.status, 'init')) {
130
130
  return;
131
131
  }
132
- if (!(0, __1.isOneOfVariant)(order.orderType, SUPPORTED_ORDER_TYPES)) {
132
+ if (!__1.isOneOfVariant(order.orderType, SUPPORTED_ORDER_TYPES)) {
133
133
  return;
134
134
  }
135
- const marketType = (0, __1.getVariant)(order.marketType);
135
+ const marketType = __1.getVariant(order.marketType);
136
136
  if (!this.orderLists.get(marketType).has(order.marketIndex)) {
137
137
  this.addOrderList(marketType, order.marketIndex);
138
138
  }
139
- if ((0, __1.isVariant)(order.status, 'open')) {
139
+ if (__1.isVariant(order.status, 'open')) {
140
140
  this.openOrders
141
141
  .get(marketType)
142
- .add((0, NodeList_1.getOrderSignature)(order.orderId, userAccount));
142
+ .add(NodeList_1.getOrderSignature(order.orderId, userAccount));
143
143
  }
144
144
  (_a = this.getListForOrder(order)) === null || _a === void 0 ? void 0 : _a.insert(order, marketType, userAccount);
145
145
  if (onInsert) {
@@ -186,15 +186,15 @@ class DLOB {
186
186
  }
187
187
  trigger(order, userAccount, onTrigger) {
188
188
  var _a;
189
- if ((0, __1.isVariant)(order.status, 'init')) {
189
+ if (__1.isVariant(order.status, 'init')) {
190
190
  return;
191
191
  }
192
- if ((0, __1.isTriggered)(order)) {
192
+ if (__1.isTriggered(order)) {
193
193
  return;
194
194
  }
195
- const marketType = (0, __1.getVariant)(order.marketType);
195
+ const marketType = __1.getVariant(order.marketType);
196
196
  const triggerList = this.orderLists.get(marketType).get(order.marketIndex)
197
- .trigger[(0, __1.isVariant)(order.triggerCondition, 'above') ? 'above' : 'below'];
197
+ .trigger[__1.isVariant(order.triggerCondition, 'above') ? 'above' : 'below'];
198
198
  triggerList.remove(order, userAccount);
199
199
  (_a = this.getListForOrder(order)) === null || _a === void 0 ? void 0 : _a.insert(order, marketType, userAccount);
200
200
  if (onTrigger) {
@@ -203,7 +203,7 @@ class DLOB {
203
203
  }
204
204
  delete(order, userAccount, onDelete) {
205
205
  var _a;
206
- if ((0, __1.isVariant)(order.status, 'init')) {
206
+ if (__1.isVariant(order.status, 'init')) {
207
207
  return;
208
208
  }
209
209
  (_a = this.getListForOrder(order)) === null || _a === void 0 ? void 0 : _a.remove(order, userAccount);
@@ -212,12 +212,12 @@ class DLOB {
212
212
  }
213
213
  }
214
214
  getListForOrder(order) {
215
- const isInactiveTriggerOrder = (0, __1.mustBeTriggered)(order) && !(0, __1.isTriggered)(order);
215
+ const isInactiveTriggerOrder = __1.mustBeTriggered(order) && !__1.isTriggered(order);
216
216
  let type;
217
217
  if (isInactiveTriggerOrder) {
218
218
  type = 'trigger';
219
219
  }
220
- else if ((0, __1.isOneOfVariant)(order.orderType, ['market', 'triggerMarket', 'oracle'])) {
220
+ else if (__1.isOneOfVariant(order.orderType, ['market', 'triggerMarket', 'oracle'])) {
221
221
  type = 'market';
222
222
  }
223
223
  else if (order.oraclePriceOffset !== 0) {
@@ -228,12 +228,12 @@ class DLOB {
228
228
  }
229
229
  let subType;
230
230
  if (isInactiveTriggerOrder) {
231
- subType = (0, __1.isVariant)(order.triggerCondition, 'above') ? 'above' : 'below';
231
+ subType = __1.isVariant(order.triggerCondition, 'above') ? 'above' : 'below';
232
232
  }
233
233
  else {
234
- subType = (0, __1.isVariant)(order.direction, 'long') ? 'bid' : 'ask';
234
+ subType = __1.isVariant(order.direction, 'long') ? 'bid' : 'ask';
235
235
  }
236
- const marketType = (0, __1.getVariant)(order.marketType);
236
+ const marketType = __1.getVariant(order.marketType);
237
237
  if (!this.orderLists.has(marketType)) {
238
238
  return undefined;
239
239
  }
@@ -249,10 +249,10 @@ class DLOB {
249
249
  return undefined;
250
250
  }
251
251
  findNodesToFill(marketIndex, fallbackBid, fallbackAsk, slot, ts, marketType, oraclePriceData, stateAccount, marketAccount) {
252
- if ((0, exchangeStatus_1.fillPaused)(stateAccount, marketAccount)) {
252
+ if (exchangeStatus_1.fillPaused(stateAccount, marketAccount)) {
253
253
  return [];
254
254
  }
255
- const isAmmPaused = (0, exchangeStatus_1.ammPaused)(stateAccount, marketAccount);
255
+ const isAmmPaused = exchangeStatus_1.ammPaused(stateAccount, marketAccount);
256
256
  const marketOrderNodesToFill = this.findMarketNodesToFill(marketIndex, slot, marketType, oraclePriceData, isAmmPaused, fallbackAsk, fallbackBid);
257
257
  const limitOrderNodesToFill = this.findLimitOrderNodesToFill(marketIndex, slot, marketType, oraclePriceData, isAmmPaused, fallbackAsk, fallbackBid);
258
258
  // get expired market nodes
@@ -369,15 +369,15 @@ class DLOB {
369
369
  let nextNode = nodeGenerator.next();
370
370
  while (!nextNode.done) {
371
371
  const node = nextNode.value;
372
- if ((0, __1.isVariant)(marketType, 'spot') && ((_a = node.order) === null || _a === void 0 ? void 0 : _a.postOnly)) {
372
+ if (__1.isVariant(marketType, 'spot') && ((_a = node.order) === null || _a === void 0 ? void 0 : _a.postOnly)) {
373
373
  nextNode = nodeGenerator.next();
374
374
  continue;
375
375
  }
376
- const nodePrice = (0, __1.getLimitPrice)(node.order, oraclePriceData, slot);
376
+ const nodePrice = __1.getLimitPrice(node.order, oraclePriceData, slot);
377
377
  // order crosses if there is no limit price or it crosses fallback price
378
378
  const crosses = doesCross(nodePrice, fallbackPrice);
379
379
  // fallback is available if auction is complete or it's a spot order
380
- const fallbackAvailable = (0, __1.isVariant)(marketType, 'spot') || (0, __1.isAuctionComplete)(node.order, slot);
380
+ const fallbackAvailable = __1.isVariant(marketType, 'spot') || __1.isAuctionComplete(node.order, slot);
381
381
  if (crosses && fallbackAvailable) {
382
382
  nodesToFill.push({
383
383
  node: node,
@@ -390,7 +390,7 @@ class DLOB {
390
390
  }
391
391
  findExpiredNodesToFill(marketIndex, ts, marketType) {
392
392
  const nodesToFill = new Array();
393
- const marketTypeStr = (0, __1.getVariant)(marketType);
393
+ const marketTypeStr = __1.getVariant(marketType);
394
394
  const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
395
395
  if (!nodeLists) {
396
396
  return nodesToFill;
@@ -408,7 +408,7 @@ class DLOB {
408
408
  ];
409
409
  for (const bidGenerator of bidGenerators) {
410
410
  for (const bid of bidGenerator) {
411
- if ((0, __1.isOrderExpired)(bid.order, ts)) {
411
+ if (__1.isOrderExpired(bid.order, ts)) {
412
412
  nodesToFill.push({
413
413
  node: bid,
414
414
  });
@@ -417,7 +417,7 @@ class DLOB {
417
417
  }
418
418
  for (const askGenerator of askGenerators) {
419
419
  for (const ask of askGenerator) {
420
- if ((0, __1.isOrderExpired)(ask.order, ts)) {
420
+ if (__1.isOrderExpired(ask.order, ts)) {
421
421
  nodesToFill.push({
422
422
  node: ask,
423
423
  });
@@ -430,14 +430,14 @@ class DLOB {
430
430
  const nodesToFill = new Array();
431
431
  // Then see if there are orders still in JIT auction
432
432
  for (const marketBid of this.getMarketBids(marketIndex, marketType)) {
433
- if (!(0, __1.isAuctionComplete)(marketBid.order, slot)) {
433
+ if (!__1.isAuctionComplete(marketBid.order, slot)) {
434
434
  nodesToFill.push({
435
435
  node: marketBid,
436
436
  });
437
437
  }
438
438
  }
439
439
  for (const marketAsk of this.getMarketAsks(marketIndex, marketType)) {
440
- if (!(0, __1.isAuctionComplete)(marketAsk.order, slot)) {
440
+ if (!__1.isAuctionComplete(marketAsk.order, slot)) {
441
441
  nodesToFill.push({
442
442
  node: marketAsk,
443
443
  });
@@ -446,7 +446,7 @@ class DLOB {
446
446
  return nodesToFill;
447
447
  }
448
448
  *getMarketBids(marketIndex, marketType) {
449
- const marketTypeStr = (0, __1.getVariant)(marketType);
449
+ const marketTypeStr = __1.getVariant(marketType);
450
450
  const orderLists = this.orderLists.get(marketTypeStr).get(marketIndex);
451
451
  if (!orderLists) {
452
452
  return;
@@ -460,7 +460,7 @@ class DLOB {
460
460
  }
461
461
  }
462
462
  *getMarketAsks(marketIndex, marketType) {
463
- const marketTypeStr = (0, __1.getVariant)(marketType);
463
+ const marketTypeStr = __1.getVariant(marketType);
464
464
  const orderLists = this.orderLists.get(marketTypeStr).get(marketIndex);
465
465
  if (!orderLists) {
466
466
  return;
@@ -492,10 +492,10 @@ class DLOB {
492
492
  const bestValue = bestGenerator.next.value;
493
493
  const currentValue = currentGenerator.next.value;
494
494
  // always return the market orders first
495
- if (bestValue.order && (0, __1.isMarketOrder)(bestValue.order)) {
495
+ if (bestValue.order && __1.isMarketOrder(bestValue.order)) {
496
496
  return bestGenerator;
497
497
  }
498
- if (currentValue.order && (0, __1.isMarketOrder)(currentValue.order)) {
498
+ if (currentValue.order && __1.isMarketOrder(currentValue.order)) {
499
499
  return currentGenerator;
500
500
  }
501
501
  const bestPrice = bestValue.getPrice(oraclePriceData, slot);
@@ -519,10 +519,10 @@ class DLOB {
519
519
  }
520
520
  }
521
521
  *getLimitAsks(marketIndex, slot, marketType, oraclePriceData) {
522
- if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) {
522
+ if (__1.isVariant(marketType, 'spot') && !oraclePriceData) {
523
523
  throw new Error('Must provide OraclePriceData to get spot asks');
524
524
  }
525
- const marketTypeStr = (0, __1.getVariant)(marketType);
525
+ const marketTypeStr = __1.getVariant(marketType);
526
526
  const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
527
527
  if (!nodeLists) {
528
528
  return;
@@ -553,10 +553,10 @@ class DLOB {
553
553
  new __1.BN(slot).sub(order.slot).gte(new __1.BN(minPerpAuctionDuration * 1.5)));
554
554
  }
555
555
  *getLimitBids(marketIndex, slot, marketType, oraclePriceData) {
556
- if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) {
556
+ if (__1.isVariant(marketType, 'spot') && !oraclePriceData) {
557
557
  throw new Error('Must provide OraclePriceData to get spot bids');
558
558
  }
559
- const marketTypeStr = (0, __1.getVariant)(marketType);
559
+ const marketTypeStr = __1.getVariant(marketType);
560
560
  const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
561
561
  if (!nodeLists) {
562
562
  return;
@@ -583,32 +583,32 @@ class DLOB {
583
583
  }
584
584
  }
585
585
  *getAsks(marketIndex, fallbackAsk, slot, marketType, oraclePriceData) {
586
- if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) {
586
+ if (__1.isVariant(marketType, 'spot') && !oraclePriceData) {
587
587
  throw new Error('Must provide OraclePriceData to get spot asks');
588
588
  }
589
589
  const generatorList = [
590
590
  this.getMarketAsks(marketIndex, marketType),
591
591
  this.getLimitAsks(marketIndex, slot, marketType, oraclePriceData),
592
592
  ];
593
- const marketTypeStr = (0, __1.getVariant)(marketType);
593
+ const marketTypeStr = __1.getVariant(marketType);
594
594
  if (marketTypeStr === 'perp' && fallbackAsk) {
595
- generatorList.push((0, NodeList_1.getVammNodeGenerator)(fallbackAsk));
595
+ generatorList.push(NodeList_1.getVammNodeGenerator(fallbackAsk));
596
596
  }
597
597
  yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestPrice, currentPrice) => {
598
598
  return bestPrice.lt(currentPrice);
599
599
  });
600
600
  }
601
601
  *getBids(marketIndex, fallbackBid, slot, marketType, oraclePriceData) {
602
- if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) {
602
+ if (__1.isVariant(marketType, 'spot') && !oraclePriceData) {
603
603
  throw new Error('Must provide OraclePriceData to get spot bids');
604
604
  }
605
605
  const generatorList = [
606
606
  this.getMarketBids(marketIndex, marketType),
607
607
  this.getLimitBids(marketIndex, slot, marketType, oraclePriceData),
608
608
  ];
609
- const marketTypeStr = (0, __1.getVariant)(marketType);
609
+ const marketTypeStr = __1.getVariant(marketType);
610
610
  if (marketTypeStr === 'perp' && fallbackBid) {
611
- generatorList.push((0, NodeList_1.getVammNodeGenerator)(fallbackBid));
611
+ generatorList.push(NodeList_1.getVammNodeGenerator(fallbackBid));
612
612
  }
613
613
  yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestPrice, currentPrice) => {
614
614
  return bestPrice.gt(currentPrice);
@@ -633,10 +633,10 @@ class DLOB {
633
633
  }
634
634
  const { takerNode, makerNode } = this.determineMakerAndTaker(askNode, bidNode);
635
635
  // extra guard against bad fills for limit orders where auction is incomplete
636
- if (!(0, __1.isAuctionComplete)(takerNode.order, slot)) {
636
+ if (!__1.isAuctionComplete(takerNode.order, slot)) {
637
637
  let bidPrice;
638
638
  let askPrice;
639
- if ((0, __1.isVariant)(takerNode.order.direction, 'long')) {
639
+ if (__1.isVariant(takerNode.order.direction, 'long')) {
640
640
  bidPrice = __1.BN.min(takerNode.getPrice(oraclePriceData, slot), fallbackAsk || __1.BN_MAX);
641
641
  askPrice = makerNode.getPrice(oraclePriceData, slot);
642
642
  }
@@ -708,11 +708,11 @@ class DLOB {
708
708
  .value.getPrice(oraclePriceData, slot);
709
709
  }
710
710
  findNodesToTrigger(marketIndex, slot, oraclePrice, marketType, stateAccount) {
711
- if ((0, exchangeStatus_1.exchangePaused)(stateAccount)) {
711
+ if (exchangeStatus_1.exchangePaused(stateAccount)) {
712
712
  return [];
713
713
  }
714
714
  const nodesToTrigger = [];
715
- const marketTypeStr = (0, __1.getVariant)(marketType);
715
+ const marketTypeStr = __1.getVariant(marketType);
716
716
  const marketNodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
717
717
  const triggerAboveList = marketNodeLists
718
718
  ? marketNodeLists.trigger.above
@@ -720,7 +720,7 @@ class DLOB {
720
720
  if (triggerAboveList) {
721
721
  for (const node of triggerAboveList.getGenerator()) {
722
722
  if (oraclePrice.gt(node.order.triggerPrice)) {
723
- if ((0, __1.isAuctionComplete)(node.order, slot)) {
723
+ if (__1.isAuctionComplete(node.order, slot)) {
724
724
  nodesToTrigger.push({
725
725
  node: node,
726
726
  });
@@ -737,7 +737,7 @@ class DLOB {
737
737
  if (triggerBelowList) {
738
738
  for (const node of triggerBelowList.getGenerator()) {
739
739
  if (oraclePrice.lt(node.order.triggerPrice)) {
740
- if ((0, __1.isAuctionComplete)(node.order, slot)) {
740
+ if (__1.isAuctionComplete(node.order, slot)) {
741
741
  nodesToTrigger.push({
742
742
  node: node,
743
743
  });
@@ -751,46 +751,46 @@ class DLOB {
751
751
  return nodesToTrigger;
752
752
  }
753
753
  printTopOfOrderLists(sdkConfig, driftClient, slotSubscriber, marketIndex, marketType) {
754
- if ((0, __1.isVariant)(marketType, 'perp')) {
754
+ if (__1.isVariant(marketType, 'perp')) {
755
755
  const market = driftClient.getPerpMarketAccount(marketIndex);
756
756
  const slot = slotSubscriber.getSlot();
757
757
  const oraclePriceData = driftClient.getOracleDataForPerpMarket(marketIndex);
758
- const fallbackAsk = (0, __1.calculateAskPrice)(market, oraclePriceData);
759
- const fallbackBid = (0, __1.calculateBidPrice)(market, oraclePriceData);
758
+ const fallbackAsk = __1.calculateAskPrice(market, oraclePriceData);
759
+ const fallbackBid = __1.calculateBidPrice(market, oraclePriceData);
760
760
  const bestAsk = this.getBestAsk(marketIndex, fallbackAsk, slot, marketType, oraclePriceData);
761
761
  const bestBid = this.getBestBid(marketIndex, fallbackBid, slot, marketType, oraclePriceData);
762
762
  const mid = bestAsk.add(bestBid).div(new __1.BN(2));
763
- const bidSpread = ((0, __1.convertToNumber)(bestBid, __1.PRICE_PRECISION) /
764
- (0, __1.convertToNumber)(oraclePriceData.price, __1.PRICE_PRECISION) -
763
+ const bidSpread = (__1.convertToNumber(bestBid, __1.PRICE_PRECISION) /
764
+ __1.convertToNumber(oraclePriceData.price, __1.PRICE_PRECISION) -
765
765
  1) *
766
766
  100.0;
767
- const askSpread = ((0, __1.convertToNumber)(bestAsk, __1.PRICE_PRECISION) /
768
- (0, __1.convertToNumber)(oraclePriceData.price, __1.PRICE_PRECISION) -
767
+ const askSpread = (__1.convertToNumber(bestAsk, __1.PRICE_PRECISION) /
768
+ __1.convertToNumber(oraclePriceData.price, __1.PRICE_PRECISION) -
769
769
  1) *
770
770
  100.0;
771
771
  console.log(`Market ${sdkConfig.MARKETS[marketIndex].symbol} Orders`);
772
- console.log(` Ask`, (0, __1.convertToNumber)(bestAsk, __1.PRICE_PRECISION).toFixed(3), `(${askSpread.toFixed(4)}%)`);
773
- console.log(` Mid`, (0, __1.convertToNumber)(mid, __1.PRICE_PRECISION).toFixed(3));
774
- console.log(` Bid`, (0, __1.convertToNumber)(bestBid, __1.PRICE_PRECISION).toFixed(3), `(${bidSpread.toFixed(4)}%)`);
772
+ console.log(` Ask`, __1.convertToNumber(bestAsk, __1.PRICE_PRECISION).toFixed(3), `(${askSpread.toFixed(4)}%)`);
773
+ console.log(` Mid`, __1.convertToNumber(mid, __1.PRICE_PRECISION).toFixed(3));
774
+ console.log(` Bid`, __1.convertToNumber(bestBid, __1.PRICE_PRECISION).toFixed(3), `(${bidSpread.toFixed(4)}%)`);
775
775
  }
776
- else if ((0, __1.isVariant)(marketType, 'spot')) {
776
+ else if (__1.isVariant(marketType, 'spot')) {
777
777
  const slot = slotSubscriber.getSlot();
778
778
  const oraclePriceData = driftClient.getOracleDataForPerpMarket(marketIndex);
779
779
  const bestAsk = this.getBestAsk(marketIndex, undefined, slot, marketType, oraclePriceData);
780
780
  const bestBid = this.getBestBid(marketIndex, undefined, slot, marketType, oraclePriceData);
781
781
  const mid = bestAsk.add(bestBid).div(new __1.BN(2));
782
- const bidSpread = ((0, __1.convertToNumber)(bestBid, __1.PRICE_PRECISION) /
783
- (0, __1.convertToNumber)(oraclePriceData.price, __1.PRICE_PRECISION) -
782
+ const bidSpread = (__1.convertToNumber(bestBid, __1.PRICE_PRECISION) /
783
+ __1.convertToNumber(oraclePriceData.price, __1.PRICE_PRECISION) -
784
784
  1) *
785
785
  100.0;
786
- const askSpread = ((0, __1.convertToNumber)(bestAsk, __1.PRICE_PRECISION) /
787
- (0, __1.convertToNumber)(oraclePriceData.price, __1.PRICE_PRECISION) -
786
+ const askSpread = (__1.convertToNumber(bestAsk, __1.PRICE_PRECISION) /
787
+ __1.convertToNumber(oraclePriceData.price, __1.PRICE_PRECISION) -
788
788
  1) *
789
789
  100.0;
790
790
  console.log(`Market ${sdkConfig.MARKETS[marketIndex].symbol} Orders`);
791
- console.log(` Ask`, (0, __1.convertToNumber)(bestAsk, __1.PRICE_PRECISION).toFixed(3), `(${askSpread.toFixed(4)}%)`);
792
- console.log(` Mid`, (0, __1.convertToNumber)(mid, __1.PRICE_PRECISION).toFixed(3));
793
- console.log(` Bid`, (0, __1.convertToNumber)(bestBid, __1.PRICE_PRECISION).toFixed(3), `(${bidSpread.toFixed(4)}%)`);
791
+ console.log(` Ask`, __1.convertToNumber(bestAsk, __1.PRICE_PRECISION).toFixed(3), `(${askSpread.toFixed(4)}%)`);
792
+ console.log(` Mid`, __1.convertToNumber(mid, __1.PRICE_PRECISION).toFixed(3));
793
+ console.log(` Bid`, __1.convertToNumber(bestBid, __1.PRICE_PRECISION).toFixed(3), `(${bidSpread.toFixed(4)}%)`);
794
794
  }
795
795
  }
796
796
  getDLOBOrders() {
@@ -13,20 +13,20 @@ class OrderNode {
13
13
  this.sortValue = this.getSortValue(order);
14
14
  }
15
15
  getLabel() {
16
- let msg = `Order ${(0, NodeList_1.getOrderSignature)(this.order.orderId, this.userAccount)}`;
17
- msg += ` ${(0, __1.isVariant)(this.order.direction, 'long') ? 'LONG' : 'SHORT'} `;
18
- msg += `${(0, __1.convertToNumber)(this.order.baseAssetAmount, __1.AMM_RESERVE_PRECISION).toFixed(3)}`;
16
+ let msg = `Order ${NodeList_1.getOrderSignature(this.order.orderId, this.userAccount)}`;
17
+ msg += ` ${__1.isVariant(this.order.direction, 'long') ? 'LONG' : 'SHORT'} `;
18
+ msg += `${__1.convertToNumber(this.order.baseAssetAmount, __1.AMM_RESERVE_PRECISION).toFixed(3)}`;
19
19
  if (this.order.price.gt(__1.ZERO)) {
20
- msg += ` @ ${(0, __1.convertToNumber)(this.order.price, __1.PRICE_PRECISION).toFixed(3)}`;
20
+ msg += ` @ ${__1.convertToNumber(this.order.price, __1.PRICE_PRECISION).toFixed(3)}`;
21
21
  }
22
22
  if (this.order.triggerPrice.gt(__1.ZERO)) {
23
- msg += ` ${(0, __1.isVariant)(this.order.triggerCondition, 'below') ? 'BELOW' : 'ABOVE'}`;
24
- msg += ` ${(0, __1.convertToNumber)(this.order.triggerPrice, __1.PRICE_PRECISION).toFixed(3)}`;
23
+ msg += ` ${__1.isVariant(this.order.triggerCondition, 'below') ? 'BELOW' : 'ABOVE'}`;
24
+ msg += ` ${__1.convertToNumber(this.order.triggerPrice, __1.PRICE_PRECISION).toFixed(3)}`;
25
25
  }
26
26
  return msg;
27
27
  }
28
28
  getPrice(oraclePriceData, slot) {
29
- return (0, __1.getLimitPrice)(this.order, oraclePriceData, slot);
29
+ return __1.getLimitPrice(this.order, oraclePriceData, slot);
30
30
  }
31
31
  isBaseFilled() {
32
32
  return this.order.baseAssetAmountFilled.eq(this.order.baseAssetAmount);
@@ -20,10 +20,10 @@ class NodeList {
20
20
  this.nodeMap.clear();
21
21
  }
22
22
  insert(order, marketType, userAccount) {
23
- if ((0, __1.isVariant)(order.status, 'init')) {
23
+ if (__1.isVariant(order.status, 'init')) {
24
24
  return;
25
25
  }
26
- const newNode = (0, DLOBNode_1.createNode)(this.nodeType, order, userAccount);
26
+ const newNode = DLOBNode_1.createNode(this.nodeType, order, userAccount);
27
27
  const orderSignature = getOrderSignature(order.orderId, userAccount);
28
28
  if (this.nodeMap.has(orderSignature)) {
29
29
  return;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="bn.js" />
3
3
  import { AnchorProvider, BN, Program } from '@project-serum/anchor';
4
- import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, SerumV3FulfillmentConfigAccount } from './types';
4
+ import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount } from './types';
5
5
  import * as anchor from '@project-serum/anchor';
6
6
  import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer } from '@solana/web3.js';
7
7
  import { TokenFaucet } from './tokenFaucet';
@@ -188,7 +188,7 @@ export declare class DriftClient {
188
188
  getFillPerpOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
189
189
  placeSpotOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
190
190
  getPlaceSpotOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
191
- fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
191
+ fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
192
192
  getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
193
193
  addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount): void;
194
194
  addSerumRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: SerumV3FulfillmentConfigAccount): void;
@@ -200,7 +200,7 @@ export declare class DriftClient {
200
200
  getPlaceAndTakePerpOrderIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
201
201
  placeAndMakePerpOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
202
202
  getPlaceAndMakePerpOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
203
- placeAndTakeSpotOrder(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
203
+ placeAndTakeSpotOrder(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
204
204
  getPlaceAndTakeSpotOrderIx(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
205
205
  placeAndMakeSpotOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
206
206
  getPlaceAndMakeSpotOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;