@drift-labs/sdk 2.104.0-beta.11 → 2.104.0-beta.13

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 (3) hide show
  1. package/VERSION +1 -1
  2. package/package.json +27 -27
  3. package/tests/dlob/test.ts +13 -184
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.104.0-beta.11
1
+ 2.104.0-beta.13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.104.0-beta.11",
3
+ "version": "2.104.0-beta.13",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "browser": "./lib/browser/index.js",
@@ -36,50 +36,50 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "@coral-xyz/anchor": "0.29.0",
39
+ "@coral-xyz/anchor": "0.28.0",
40
40
  "@coral-xyz/anchor-30": "npm:@coral-xyz/anchor@0.30.1",
41
- "@ellipsis-labs/phoenix-sdk": "1.4.5",
42
- "@grpc/grpc-js": "1.12.2",
41
+ "@ellipsis-labs/phoenix-sdk": "^1.4.2",
42
+ "@grpc/grpc-js": "^1.8.0",
43
43
  "@openbook-dex/openbook-v2": "0.2.10",
44
- "@project-serum/serum": "0.13.65",
44
+ "@project-serum/serum": "^0.13.38",
45
45
  "@pythnetwork/client": "2.5.3",
46
- "@pythnetwork/price-service-sdk": "1.7.1",
47
- "@pythnetwork/pyth-solana-receiver": "0.7.0",
46
+ "@pythnetwork/price-service-sdk": "^1.7.1",
47
+ "@pythnetwork/pyth-solana-receiver": "^0.7.0",
48
48
  "@solana/spl-token": "0.3.7",
49
49
  "@solana/web3.js": "1.92.3",
50
50
  "@switchboard-xyz/on-demand": "1.2.42",
51
51
  "@triton-one/yellowstone-grpc": "1.3.0",
52
- "anchor-bankrun": "0.3.0",
53
- "node-cache": "5.1.2",
52
+ "anchor-bankrun": "^0.3.0",
53
+ "node-cache": "^5.1.2",
54
54
  "rpc-websockets": "7.5.1",
55
- "solana-bankrun": "0.3.1",
56
- "strict-event-emitter-types": "2.0.0",
55
+ "solana-bankrun": "^0.3.0",
56
+ "strict-event-emitter-types": "^2.0.0",
57
57
  "tweetnacl": "1.0.3",
58
- "uuid": "8.3.2",
59
- "yargs": "17.7.2",
60
- "zstddec": "0.1.0"
58
+ "uuid": "^8.3.2",
59
+ "yargs": "^17.7.2",
60
+ "zstddec": "^0.1.0"
61
61
  },
62
62
  "devDependencies": {
63
- "@types/big.js": "6.2.2",
63
+ "@types/big.js": "^6.2.0",
64
64
  "@types/bn.js": "5.1.6",
65
- "@types/bs58": "4.0.4",
66
- "@types/chai": "4.3.20",
67
- "@types/jest": "28.1.8",
68
- "@types/mocha": "9.1.1",
65
+ "@types/bs58": "^4.0.4",
66
+ "@types/chai": "^4.3.1",
67
+ "@types/jest": "^28.1.3",
68
+ "@types/mocha": "^9.1.1",
69
69
  "@typescript-eslint/eslint-plugin": "4.28.0",
70
70
  "@typescript-eslint/parser": "4.28.0",
71
- "chai": "4.5.0",
72
- "encoding": "0.1.13",
71
+ "chai": "^4.3.6",
72
+ "encoding": "^0.1.13",
73
73
  "eslint": "7.29.0",
74
74
  "eslint-config-prettier": "8.3.0",
75
75
  "eslint-plugin-prettier": "3.4.0",
76
- "lodash": "4.17.21",
77
- "mocha": "10.7.3",
78
- "object-sizeof": "2.6.5",
76
+ "lodash": "^4.17.21",
77
+ "mocha": "^10.0.0",
78
+ "object-sizeof": "^2.6.3",
79
79
  "prettier": "3.0.1",
80
- "sinon": "18.0.1",
81
- "ts-node": "10.9.2",
82
- "typescript": "4.9.5"
80
+ "sinon": "^18.0.0",
81
+ "ts-node": "^10.8.0",
82
+ "typescript": "^4.9.5"
83
83
  },
84
84
  "description": "SDK for Drift Protocol",
85
85
  "engines": {
@@ -22,13 +22,12 @@ import {
22
22
  ZERO,
23
23
  convertToNumber,
24
24
  QUOTE_PRECISION,
25
- isVariant,
25
+ //isVariant,
26
26
  uncrossL2,
27
27
  L2Level,
28
28
  } from '../../src';
29
29
 
30
30
  import { mockPerpMarkets, mockSpotMarkets, mockStateAccount } from './helpers';
31
- import { DLOBOrdersCoder } from '../../src/dlob/DLOBOrders';
32
31
 
33
32
  // Returns true if asks are sorted ascending
34
33
  const asksAreSortedAsc = (asks: L2Level[]) => {
@@ -97,7 +96,8 @@ function insertOrderToDLOB(
97
96
  maxTs,
98
97
  },
99
98
  userAccount.toString(),
100
- slot.toNumber()
99
+ slot.toNumber(),
100
+ false
101
101
  );
102
102
  }
103
103
 
@@ -148,7 +148,8 @@ function insertTriggerOrderToDLOB(
148
148
  maxTs,
149
149
  },
150
150
  userAccount.toString(),
151
- slot.toNumber()
151
+ slot.toNumber(),
152
+ false
152
153
  );
153
154
  }
154
155
 
@@ -158,16 +159,11 @@ function printOrderNode(
158
159
  slot: number | undefined
159
160
  ) {
160
161
  console.log(
161
- ` . vAMMNode? ${node.isVammNode()},\t${
162
- node.order ? getVariant(node.order?.orderType) : '~'
163
- } ${node.order ? getVariant(node.order?.direction) : '~'}\t, slot: ${
164
- node.order?.slot.toString() || '~'
165
- }, orderId: ${node.order?.orderId.toString() || '~'},\tnode.getPrice: ${
166
- oracle ? node.getPrice(oracle, slot!) : '~'
167
- }, node.price: ${node.order?.price.toString() || '~'}, priceOffset: ${
168
- node.order?.oraclePriceOffset.toString() || '~'
169
- } quantity: ${node.order?.baseAssetAmountFilled.toString() || '~'}/${
170
- node.order?.baseAssetAmount.toString() || '~'
162
+ ` . vAMMNode? ${node.isVammNode()},\t${node.order ? getVariant(node.order?.orderType) : '~'
163
+ } ${node.order ? getVariant(node.order?.direction) : '~'}\t, slot: ${node.order?.slot.toString() || '~'
164
+ }, orderId: ${node.order?.orderId.toString() || '~'},\tnode.getPrice: ${oracle ? node.getPrice(oracle, slot!) : '~'
165
+ }, node.price: ${node.order?.price.toString() || '~'}, priceOffset: ${node.order?.oraclePriceOffset.toString() || '~'
166
+ } quantity: ${node.order?.baseAssetAmountFilled.toString() || '~'}/${node.order?.baseAssetAmount.toString() || '~'
171
167
  }`
172
168
  );
173
169
  }
@@ -214,8 +210,7 @@ function printBookState(
214
210
 
215
211
  function printCrossedNodes(n: NodeToFill, slot: number) {
216
212
  console.log(
217
- `Cross Found, takerExists: ${n.node.order !== undefined}, makerExists: ${
218
- n.makerNodes !== undefined
213
+ `Cross Found, takerExists: ${n.node.order !== undefined}, makerExists: ${n.makerNodes !== undefined
219
214
  }`
220
215
  );
221
216
  console.log(
@@ -237,10 +232,8 @@ function printCrossedNodes(n: NodeToFill, slot: number) {
237
232
  console.log(
238
233
  ` orderId: ${o.orderId}, ${getVariant(o.orderType)}, ${getVariant(
239
234
  o.direction
240
- )},\texpired: ${isOrderExpired(o, slot)}, postOnly: ${
241
- o.postOnly
242
- }, reduceOnly: ${
243
- o.reduceOnly
235
+ )},\texpired: ${isOrderExpired(o, slot)}, postOnly: ${o.postOnly
236
+ }, reduceOnly: ${o.reduceOnly
244
237
  }, price: ${o.price.toString()}, priceOffset: ${o.oraclePriceOffset.toString()}, baseAmtFileld: ${o.baseAssetAmountFilled.toString()}/${o.baseAssetAmount.toString()}`
245
238
  );
246
239
  };
@@ -413,170 +406,6 @@ describe('DLOB Tests', () => {
413
406
  expect(bids1.next().done, 'bid generator should be done').to.equal(true);
414
407
  });
415
408
 
416
- it('DLOB orders', () => {
417
- const vAsk = new BN(15);
418
- const vBid = new BN(10);
419
-
420
- const user0 = Keypair.generate();
421
- const user1 = Keypair.generate();
422
- const user2 = Keypair.generate();
423
- const user3 = Keypair.generate();
424
- const user4 = Keypair.generate();
425
-
426
- const dlob = new DLOB();
427
- const marketIndex = 0;
428
-
429
- insertOrderToDLOB(
430
- dlob,
431
- user0.publicKey,
432
- OrderType.LIMIT,
433
- MarketType.PERP,
434
- 1, // orderId
435
- marketIndex,
436
- new BN(11), // price
437
- BASE_PRECISION, // quantity
438
- PositionDirection.LONG,
439
- vBid,
440
- vAsk
441
- );
442
- insertOrderToDLOB(
443
- dlob,
444
- user1.publicKey,
445
- OrderType.LIMIT,
446
- MarketType.PERP,
447
- 2, // orderId
448
- marketIndex,
449
- new BN(12), // price
450
- BASE_PRECISION, // quantity
451
- PositionDirection.LONG,
452
- vBid,
453
- vAsk
454
- );
455
- insertOrderToDLOB(
456
- dlob,
457
- user2.publicKey,
458
- OrderType.LIMIT,
459
- MarketType.PERP,
460
- 3, // orderId
461
- marketIndex,
462
- new BN(13), // price
463
- BASE_PRECISION, // quantity
464
- PositionDirection.LONG,
465
- vBid,
466
- vAsk
467
- );
468
-
469
- insertOrderToDLOB(
470
- dlob,
471
- user3.publicKey,
472
- OrderType.MARKET,
473
- MarketType.PERP,
474
- 4, // orderId
475
- marketIndex,
476
- new BN(12), // price
477
- new BN(1).mul(BASE_PRECISION), // quantity
478
- PositionDirection.SHORT,
479
- vBid,
480
- vAsk
481
- );
482
- insertOrderToDLOB(
483
- dlob,
484
- user4.publicKey,
485
- OrderType.MARKET,
486
- MarketType.PERP,
487
- 5, // orderId
488
- marketIndex,
489
- new BN(12), // price
490
- new BN(1).mul(BASE_PRECISION), // quantity
491
- PositionDirection.SHORT,
492
- vBid,
493
- vAsk
494
- );
495
- // insert some limit buys above vamm bid, below ask
496
- insertOrderToDLOB(
497
- dlob,
498
- user0.publicKey,
499
- OrderType.LIMIT,
500
- MarketType.SPOT,
501
- 6, // orderId
502
- marketIndex,
503
- new BN(11), // price
504
- BASE_PRECISION, // quantity
505
- PositionDirection.LONG,
506
- vBid,
507
- vAsk
508
- );
509
- insertOrderToDLOB(
510
- dlob,
511
- user1.publicKey,
512
- OrderType.LIMIT,
513
- MarketType.SPOT,
514
- 7, // orderId
515
- marketIndex,
516
- new BN(12), // price
517
- BASE_PRECISION, // quantity
518
- PositionDirection.LONG,
519
- vBid,
520
- vAsk
521
- );
522
- insertOrderToDLOB(
523
- dlob,
524
- user2.publicKey,
525
- OrderType.LIMIT,
526
- MarketType.SPOT,
527
- 8, // orderId
528
- marketIndex,
529
- new BN(13), // price
530
- BASE_PRECISION, // quantity
531
- PositionDirection.LONG,
532
- vBid,
533
- vAsk
534
- );
535
-
536
- insertOrderToDLOB(
537
- dlob,
538
- user3.publicKey,
539
- OrderType.MARKET,
540
- MarketType.SPOT,
541
- 9, // orderId
542
- marketIndex,
543
- new BN(12), // price
544
- new BN(1).mul(BASE_PRECISION), // quantity
545
- PositionDirection.SHORT,
546
- vBid,
547
- vAsk
548
- );
549
- insertOrderToDLOB(
550
- dlob,
551
- user4.publicKey,
552
- OrderType.MARKET,
553
- MarketType.SPOT,
554
- 10, // orderId
555
- marketIndex,
556
- new BN(12), // price
557
- new BN(1).mul(BASE_PRECISION), // quantity
558
- PositionDirection.SHORT,
559
- vBid,
560
- vAsk
561
- );
562
-
563
- const dlobOrders = dlob.getDLOBOrders();
564
- expect(dlobOrders.length).to.equal(10);
565
- expect(isVariant(dlobOrders[0].order.marketType, 'perp')).to.equal(true);
566
- expect(isVariant(dlobOrders[5].order.marketType, 'spot')).to.equal(true);
567
-
568
- const coder = DLOBOrdersCoder.create();
569
- const encodedOrders = coder.encode(dlobOrders);
570
- const decodedDLOBOrders = coder.decode(encodedOrders);
571
- expect(decodedDLOBOrders.length).to.equal(10);
572
- expect(isVariant(decodedDLOBOrders[0].order.marketType, 'perp')).to.equal(
573
- true
574
- );
575
- expect(isVariant(decodedDLOBOrders[5].order.marketType, 'spot')).to.equal(
576
- true
577
- );
578
- });
579
-
580
409
  it('DLOB update resting limit orders bids', () => {
581
410
  const vAsk = new BN(15);
582
411
  const vBid = new BN(10);