@drift-labs/sdk 2.35.1-beta.6 → 2.35.1-beta.7

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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.35.1-beta.6
1
+ 2.35.1-beta.7
package/lib/dlob/DLOB.js CHANGED
@@ -491,11 +491,21 @@ class DLOB {
491
491
  }
492
492
  // All bids/asks that can expire
493
493
  // dont try to expire limit orders with tif as its inefficient use of blockspace
494
- const bidGenerators = [nodeLists.market.bid.getGenerator()];
495
- const askGenerators = [nodeLists.market.ask.getGenerator()];
494
+ const bidGenerators = [
495
+ nodeLists.takingLimit.bid.getGenerator(),
496
+ nodeLists.restingLimit.bid.getGenerator(),
497
+ nodeLists.floatingLimit.bid.getGenerator(),
498
+ nodeLists.market.bid.getGenerator(),
499
+ ];
500
+ const askGenerators = [
501
+ nodeLists.takingLimit.ask.getGenerator(),
502
+ nodeLists.restingLimit.ask.getGenerator(),
503
+ nodeLists.floatingLimit.ask.getGenerator(),
504
+ nodeLists.market.ask.getGenerator(),
505
+ ];
496
506
  for (const bidGenerator of bidGenerators) {
497
507
  for (const bid of bidGenerator) {
498
- if ((0, __1.isOrderExpired)(bid.order, ts)) {
508
+ if ((0, __1.isOrderExpired)(bid.order, ts, true)) {
499
509
  nodesToFill.push({
500
510
  node: bid,
501
511
  makerNodes: [],
@@ -505,7 +515,7 @@ class DLOB {
505
515
  }
506
516
  for (const askGenerator of askGenerators) {
507
517
  for (const ask of askGenerator) {
508
- if ((0, __1.isOrderExpired)(ask.order, ts)) {
518
+ if ((0, __1.isOrderExpired)(ask.order, ts, true)) {
509
519
  nodesToFill.push({
510
520
  node: ask,
511
521
  makerNodes: [],
@@ -13,7 +13,7 @@ export declare function hasAuctionPrice(order: Order, slot: number): boolean;
13
13
  export declare function isFillableByVAMM(order: Order, market: PerpMarketAccount, oraclePriceData: OraclePriceData, slot: number, ts: number): boolean;
14
14
  export declare function calculateBaseAssetAmountForAmmToFulfill(order: Order, market: PerpMarketAccount, oraclePriceData: OraclePriceData, slot: number): BN;
15
15
  export declare function calculateBaseAssetAmountToFillUpToLimitPrice(order: Order, amm: AMM, limitPrice: BN, oraclePriceData: OraclePriceData): BN;
16
- export declare function isOrderExpired(order: Order, ts: number): boolean;
16
+ export declare function isOrderExpired(order: Order, ts: number, enforceBuffer?: boolean): boolean;
17
17
  export declare function isMarketOrder(order: Order): boolean;
18
18
  export declare function isLimitOrder(order: Order): boolean;
19
19
  export declare function mustBeTriggered(order: Order): boolean;
@@ -168,13 +168,20 @@ function isSameDirection(firstDirection, secondDirection) {
168
168
  return (((0, types_1.isVariant)(firstDirection, 'long') && (0, types_1.isVariant)(secondDirection, 'long')) ||
169
169
  ((0, types_1.isVariant)(firstDirection, 'short') && (0, types_1.isVariant)(secondDirection, 'short')));
170
170
  }
171
- function isOrderExpired(order, ts) {
171
+ function isOrderExpired(order, ts, enforceBuffer = false) {
172
172
  if (mustBeTriggered(order) ||
173
173
  !(0, types_1.isVariant)(order.status, 'open') ||
174
174
  order.maxTs.eq(numericConstants_1.ZERO)) {
175
175
  return false;
176
176
  }
177
- return new anchor_1.BN(ts).gt(order.maxTs);
177
+ let maxTs;
178
+ if (enforceBuffer && isLimitOrder(order)) {
179
+ maxTs = order.maxTs.addn(15);
180
+ }
181
+ else {
182
+ maxTs = order.maxTs;
183
+ }
184
+ return new anchor_1.BN(ts).gt(maxTs);
178
185
  }
179
186
  exports.isOrderExpired = isOrderExpired;
180
187
  function isMarketOrder(order) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.35.1-beta.6",
3
+ "version": "2.35.1-beta.7",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
package/src/dlob/DLOB.ts CHANGED
@@ -931,12 +931,22 @@ export class DLOB {
931
931
 
932
932
  // All bids/asks that can expire
933
933
  // dont try to expire limit orders with tif as its inefficient use of blockspace
934
- const bidGenerators = [nodeLists.market.bid.getGenerator()];
935
- const askGenerators = [nodeLists.market.ask.getGenerator()];
934
+ const bidGenerators = [
935
+ nodeLists.takingLimit.bid.getGenerator(),
936
+ nodeLists.restingLimit.bid.getGenerator(),
937
+ nodeLists.floatingLimit.bid.getGenerator(),
938
+ nodeLists.market.bid.getGenerator(),
939
+ ];
940
+ const askGenerators = [
941
+ nodeLists.takingLimit.ask.getGenerator(),
942
+ nodeLists.restingLimit.ask.getGenerator(),
943
+ nodeLists.floatingLimit.ask.getGenerator(),
944
+ nodeLists.market.ask.getGenerator(),
945
+ ];
936
946
 
937
947
  for (const bidGenerator of bidGenerators) {
938
948
  for (const bid of bidGenerator) {
939
- if (isOrderExpired(bid.order, ts)) {
949
+ if (isOrderExpired(bid.order, ts, true)) {
940
950
  nodesToFill.push({
941
951
  node: bid,
942
952
  makerNodes: [],
@@ -947,7 +957,7 @@ export class DLOB {
947
957
 
948
958
  for (const askGenerator of askGenerators) {
949
959
  for (const ask of askGenerator) {
950
- if (isOrderExpired(ask.order, ts)) {
960
+ if (isOrderExpired(ask.order, ts, true)) {
951
961
  nodesToFill.push({
952
962
  node: ask,
953
963
  makerNodes: [],
@@ -279,7 +279,11 @@ function isSameDirection(
279
279
  );
280
280
  }
281
281
 
282
- export function isOrderExpired(order: Order, ts: number): boolean {
282
+ export function isOrderExpired(
283
+ order: Order,
284
+ ts: number,
285
+ enforceBuffer = false
286
+ ): boolean {
283
287
  if (
284
288
  mustBeTriggered(order) ||
285
289
  !isVariant(order.status, 'open') ||
@@ -288,7 +292,14 @@ export function isOrderExpired(order: Order, ts: number): boolean {
288
292
  return false;
289
293
  }
290
294
 
291
- return new BN(ts).gt(order.maxTs);
295
+ let maxTs;
296
+ if (enforceBuffer && isLimitOrder(order)) {
297
+ maxTs = order.maxTs.addn(15);
298
+ } else {
299
+ maxTs = order.maxTs;
300
+ }
301
+
302
+ return new BN(ts).gt(maxTs);
292
303
  }
293
304
 
294
305
  export function isMarketOrder(order: Order): boolean {