@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
@@ -1,5 +1,5 @@
1
1
  import { Commitment, TransactionSignature } from '@solana/web3.js';
2
- import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord } from '../index';
2
+ import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord } from '../index';
3
3
  export declare type EventSubscriptionOptions = {
4
4
  eventTypes?: EventType[];
5
5
  maxEventsPerType?: number;
@@ -32,6 +32,7 @@ export declare type EventMap = {
32
32
  NewUserRecord: Event<NewUserRecord>;
33
33
  LPRecord: Event<LPRecord>;
34
34
  InsuranceFundRecord: Event<InsuranceFundRecord>;
35
+ SpotInterestRecord: Event<SpotInterestRecord>;
35
36
  };
36
37
  export declare type EventType = keyof EventMap;
37
38
  export interface EventSubscriberEvents {
@@ -13,6 +13,7 @@ exports.DefaultEventSubscriptionOptions = {
13
13
  'SettlePnlRecord',
14
14
  'LPRecord',
15
15
  'InsuranceFundRecord',
16
+ 'SpotInterestRecord',
16
17
  ],
17
18
  maxEventsPerType: 4096,
18
19
  orderBy: 'blockchain',
@@ -69,6 +69,7 @@ export declare class BigNum {
69
69
  * @returns
70
70
  */
71
71
  toFixed(fixedPrecision: number): string;
72
+ private getZeroes;
72
73
  /**
73
74
  * Pretty print to the specified number of significant figures
74
75
  * @param fixedPrecision
@@ -189,6 +189,8 @@ class BigNum {
189
189
  : useTradePrecision
190
190
  ? this.toTradePrecision()
191
191
  : this.print();
192
+ if (!printVal.includes(BigNum.delim))
193
+ return printVal;
192
194
  return printVal.replace(/0+$/g, '').replace(/\.$/, '').replace(/,$/, '');
193
195
  }
194
196
  debug() {
@@ -210,6 +212,9 @@ class BigNum {
210
212
  .join('');
211
213
  return `${leftSide}${BigNum.delim}${filledRightSide}`;
212
214
  }
215
+ getZeroes(count) {
216
+ return new Array(count).fill('0').join('');
217
+ }
213
218
  /**
214
219
  * Pretty print to the specified number of significant figures
215
220
  * @param fixedPrecision
@@ -218,6 +223,12 @@ class BigNum {
218
223
  toPrecision(fixedPrecision, trailingZeroes = false) {
219
224
  const printString = this.print();
220
225
  let precisionPrintString = printString.slice(0, fixedPrecision + 1);
226
+ const thisString = this.toString();
227
+ if (!printString.includes(BigNum.delim) &&
228
+ thisString.length < fixedPrecision) {
229
+ const precisionMismatch = fixedPrecision - thisString.length;
230
+ return BigNum.from(thisString + this.getZeroes(precisionMismatch), precisionMismatch).toPrecision(fixedPrecision, trailingZeroes);
231
+ }
221
232
  if (!precisionPrintString.includes(BigNum.delim) ||
222
233
  precisionPrintString[precisionPrintString.length - 1] === BigNum.delim) {
223
234
  precisionPrintString = printString.slice(0, fixedPrecision);
@@ -297,6 +308,9 @@ class BigNum {
297
308
  if (!leftSide) {
298
309
  return this.shift(new anchor_1.BN(precision)).toPrecision(precision, true);
299
310
  }
311
+ if (leftSide.length <= precision) {
312
+ return this.toPrecision(precision);
313
+ }
300
314
  if (leftSide.length <= 3) {
301
315
  return this.shift(new anchor_1.BN(precision)).toPrecision(precision, true);
302
316
  }