@drift-labs/sdk 0.2.0-master.30 → 0.2.0-master.32

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 (60) hide show
  1. package/lib/admin.d.ts +11 -7
  2. package/lib/admin.js +50 -12
  3. package/lib/clearingHouse.d.ts +26 -23
  4. package/lib/clearingHouse.js +290 -652
  5. package/lib/clearingHouseUser.d.ts +1 -1
  6. package/lib/clearingHouseUser.js +9 -12
  7. package/lib/config.js +1 -1
  8. package/lib/constants/numericConstants.d.ts +7 -0
  9. package/lib/constants/numericConstants.js +8 -1
  10. package/lib/constants/spotMarkets.js +4 -4
  11. package/lib/dlob/DLOB.d.ts +7 -5
  12. package/lib/dlob/DLOB.js +159 -88
  13. package/lib/dlob/DLOBNode.d.ts +2 -0
  14. package/lib/dlob/DLOBNode.js +3 -0
  15. package/lib/dlob/NodeList.d.ts +2 -1
  16. package/lib/dlob/NodeList.js +10 -4
  17. package/lib/events/types.d.ts +2 -1
  18. package/lib/events/types.js +1 -0
  19. package/lib/factory/bigNum.d.ts +1 -0
  20. package/lib/factory/bigNum.js +14 -0
  21. package/lib/idl/clearing_house.json +1091 -611
  22. package/lib/math/amm.d.ts +2 -2
  23. package/lib/math/amm.js +31 -28
  24. package/lib/math/market.d.ts +1 -1
  25. package/lib/math/market.js +6 -6
  26. package/lib/math/spotBalance.js +7 -8
  27. package/lib/math/trade.js +11 -11
  28. package/lib/types.d.ts +118 -41
  29. package/lib/types.js +34 -4
  30. package/package.json +4 -2
  31. package/src/admin.ts +129 -29
  32. package/src/clearingHouse.ts +380 -787
  33. package/src/clearingHouseUser.ts +11 -14
  34. package/src/config.ts +1 -1
  35. package/src/constants/numericConstants.ts +7 -0
  36. package/src/constants/spotMarkets.ts +5 -4
  37. package/src/dlob/DLOB.ts +221 -103
  38. package/src/dlob/DLOBNode.ts +5 -0
  39. package/src/dlob/NodeList.ts +15 -5
  40. package/src/events/types.ts +3 -0
  41. package/src/factory/bigNum.ts +23 -0
  42. package/src/idl/clearing_house.json +1091 -611
  43. package/src/math/amm.ts +42 -29
  44. package/src/math/market.ts +9 -4
  45. package/src/math/spotBalance.ts +11 -8
  46. package/src/math/trade.ts +11 -11
  47. package/src/types.ts +82 -41
  48. package/tests/bn/test.ts +13 -8
  49. package/tests/dlob/helpers.ts +56 -33
  50. package/tests/dlob/test.ts +1397 -495
  51. package/src/assert/assert.js +0 -9
  52. package/src/events/eventList.js +0 -77
  53. package/src/examples/makeTradeExample.js +0 -157
  54. package/src/token/index.js +0 -38
  55. package/src/tx/types.js +0 -2
  56. package/src/tx/utils.js +0 -17
  57. package/src/util/computeUnits.js +0 -27
  58. package/src/util/getTokenAddress.js +0 -9
  59. package/src/util/promiseTimeout.js +0 -14
  60. package/src/util/tps.js +0 -27
@@ -10,6 +10,7 @@ import {
10
10
  SettlePnlRecord,
11
11
  LPRecord,
12
12
  InsuranceFundRecord,
13
+ SpotInterestRecord,
13
14
  } from '../index';
14
15
 
15
16
  export type EventSubscriptionOptions = {
@@ -37,6 +38,7 @@ export const DefaultEventSubscriptionOptions: EventSubscriptionOptions = {
37
38
  'SettlePnlRecord',
38
39
  'LPRecord',
39
40
  'InsuranceFundRecord',
41
+ 'SpotInterestRecord',
40
42
  ],
41
43
  maxEventsPerType: 4096,
42
44
  orderBy: 'blockchain',
@@ -74,6 +76,7 @@ export type EventMap = {
74
76
  NewUserRecord: Event<NewUserRecord>;
75
77
  LPRecord: Event<LPRecord>;
76
78
  InsuranceFundRecord: Event<InsuranceFundRecord>;
79
+ SpotInterestRecord: Event<SpotInterestRecord>;
77
80
  };
78
81
 
79
82
  export type EventType = keyof EventMap;
@@ -290,6 +290,8 @@ export class BigNum {
290
290
  ? this.toTradePrecision()
291
291
  : this.print();
292
292
 
293
+ if (!printVal.includes(BigNum.delim)) return printVal;
294
+
293
295
  return printVal.replace(/0+$/g, '').replace(/\.$/, '').replace(/,$/, '');
294
296
  }
295
297
 
@@ -319,6 +321,10 @@ export class BigNum {
319
321
  return `${leftSide}${BigNum.delim}${filledRightSide}`;
320
322
  }
321
323
 
324
+ private getZeroes(count: number) {
325
+ return new Array(count).fill('0').join('');
326
+ }
327
+
322
328
  /**
323
329
  * Pretty print to the specified number of significant figures
324
330
  * @param fixedPrecision
@@ -329,6 +335,19 @@ export class BigNum {
329
335
 
330
336
  let precisionPrintString = printString.slice(0, fixedPrecision + 1);
331
337
 
338
+ const thisString = this.toString();
339
+
340
+ if (
341
+ !printString.includes(BigNum.delim) &&
342
+ thisString.length < fixedPrecision
343
+ ) {
344
+ const precisionMismatch = fixedPrecision - thisString.length;
345
+ return BigNum.from(
346
+ thisString + this.getZeroes(precisionMismatch),
347
+ precisionMismatch
348
+ ).toPrecision(fixedPrecision, trailingZeroes);
349
+ }
350
+
332
351
  if (
333
352
  !precisionPrintString.includes(BigNum.delim) ||
334
353
  precisionPrintString[precisionPrintString.length - 1] === BigNum.delim
@@ -438,6 +457,10 @@ export class BigNum {
438
457
  return this.shift(new BN(precision)).toPrecision(precision, true);
439
458
  }
440
459
 
460
+ if (leftSide.length <= precision) {
461
+ return this.toPrecision(precision);
462
+ }
463
+
441
464
  if (leftSide.length <= 3) {
442
465
  return this.shift(new BN(precision)).toPrecision(precision, true);
443
466
  }