@drift-labs/sdk 2.18.0 → 2.19.1

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 (86) hide show
  1. package/lib/accounts/bulkAccountLoader.d.ts +2 -1
  2. package/lib/accounts/bulkAccountLoader.js +3 -3
  3. package/lib/accounts/fetch.js +2 -2
  4. package/lib/accounts/pollingDriftClientAccountSubscriber.js +7 -7
  5. package/lib/accounts/pollingTokenAccountSubscriber.js +2 -2
  6. package/lib/accounts/pollingUserAccountSubscriber.js +2 -2
  7. package/lib/accounts/pollingUserStatsAccountSubscriber.js +2 -2
  8. package/lib/accounts/types.d.ts +5 -4
  9. package/lib/accounts/webSocketAccountSubscriber.js +1 -1
  10. package/lib/accounts/webSocketDriftClientAccountSubscriber.js +3 -3
  11. package/lib/addresses/marketAddresses.js +1 -1
  12. package/lib/addresses/pda.js +5 -1
  13. package/lib/adminClient.js +61 -57
  14. package/lib/config.d.ts +2 -2
  15. package/lib/constants/perpMarkets.d.ts +1 -1
  16. package/lib/constants/perpMarkets.js +33 -3
  17. package/lib/constants/spotMarkets.d.ts +1 -1
  18. package/lib/dlob/DLOB.d.ts +4 -4
  19. package/lib/dlob/DLOB.js +89 -76
  20. package/lib/dlob/DLOBNode.d.ts +2 -2
  21. package/lib/dlob/DLOBNode.js +7 -7
  22. package/lib/dlob/DLOBOrders.d.ts +2 -2
  23. package/lib/dlob/NodeList.d.ts +2 -2
  24. package/lib/dlob/NodeList.js +4 -4
  25. package/lib/driftClient.d.ts +1 -1
  26. package/lib/driftClient.js +99 -95
  27. package/lib/driftClientConfig.d.ts +3 -3
  28. package/lib/events/eventSubscriber.js +2 -2
  29. package/lib/events/fetchLogs.d.ts +2 -2
  30. package/lib/events/pollingLogProvider.js +1 -1
  31. package/lib/events/types.d.ts +14 -14
  32. package/lib/examples/loadDlob.js +2 -2
  33. package/lib/examples/makeTradeExample.js +9 -9
  34. package/lib/factory/bigNum.js +13 -13
  35. package/lib/factory/oracleClient.js +6 -3
  36. package/lib/idl/drift.json +7 -4
  37. package/lib/index.js +5 -1
  38. package/lib/math/amm.d.ts +1 -1
  39. package/lib/math/amm.js +33 -38
  40. package/lib/math/auction.js +6 -6
  41. package/lib/math/exchangeStatus.js +2 -2
  42. package/lib/math/funding.js +2 -2
  43. package/lib/math/margin.js +4 -4
  44. package/lib/math/market.js +15 -15
  45. package/lib/math/oracles.js +1 -1
  46. package/lib/math/orders.js +24 -24
  47. package/lib/math/position.js +5 -5
  48. package/lib/math/repeg.js +1 -1
  49. package/lib/math/spotBalance.js +9 -9
  50. package/lib/math/spotMarket.js +3 -3
  51. package/lib/math/spotPosition.js +3 -3
  52. package/lib/math/trade.d.ts +1 -1
  53. package/lib/math/trade.js +43 -43
  54. package/lib/math/utils.js +1 -1
  55. package/lib/oracles/oracleClientCache.js +1 -1
  56. package/lib/oracles/pythClient.js +1 -1
  57. package/lib/oracles/types.d.ts +2 -2
  58. package/lib/serum/serumSubscriber.d.ts +4 -3
  59. package/lib/serum/serumSubscriber.js +40 -11
  60. package/lib/serum/types.d.ts +3 -1
  61. package/lib/slot/SlotSubscriber.d.ts +1 -1
  62. package/lib/tokenFaucet.js +5 -1
  63. package/lib/tx/retryTxSender.d.ts +1 -1
  64. package/lib/tx/retryTxSender.js +1 -1
  65. package/lib/tx/types.d.ts +1 -1
  66. package/lib/types.d.ts +49 -46
  67. package/lib/types.js +2 -1
  68. package/lib/user.js +63 -63
  69. package/lib/userConfig.d.ts +2 -2
  70. package/lib/userMap/userMap.js +1 -1
  71. package/lib/userMap/userStatsMap.js +3 -3
  72. package/lib/userStats.js +2 -2
  73. package/lib/userStatsConfig.d.ts +2 -2
  74. package/package.json +1 -1
  75. package/src/constants/perpMarkets.ts +33 -3
  76. package/src/dlob/DLOB.ts +17 -5
  77. package/src/dlob/NodeList.ts +2 -5
  78. package/src/factory/oracleClient.ts +5 -1
  79. package/src/idl/drift.json +7 -4
  80. package/src/math/amm.ts +22 -23
  81. package/src/math/trade.ts +1 -1
  82. package/src/serum/serumSubscriber.ts +62 -20
  83. package/src/serum/types.ts +9 -5
  84. package/src/types.ts +2 -1
  85. package/tests/amm/test.ts +177 -5
  86. package/tests/dlob/test.ts +2 -1
package/lib/types.d.ts CHANGED
@@ -130,8 +130,11 @@ export declare class OracleSource {
130
130
  static readonly PYTH: {
131
131
  pyth: {};
132
132
  };
133
- static readonly PYTH_1000: {
134
- pyth1000: {};
133
+ static readonly PYTH_1K: {
134
+ pyth1K: {};
135
+ };
136
+ static readonly PYTH_1M: {
137
+ pyth1M: {};
135
138
  };
136
139
  static readonly QUOTE_ASSET: {
137
140
  quoteAsset: {};
@@ -305,8 +308,8 @@ export declare enum TradeSide {
305
308
  Buy = 1,
306
309
  Sell = 2
307
310
  }
308
- export declare type CandleResolution = '1' | '5' | '15' | '60' | '240' | 'D' | 'W' | 'M';
309
- export declare type NewUserRecord = {
311
+ export type CandleResolution = '1' | '5' | '15' | '60' | '240' | 'D' | 'W' | 'M';
312
+ export type NewUserRecord = {
310
313
  ts: BN;
311
314
  userAuthority: PublicKey;
312
315
  user: PublicKey;
@@ -314,7 +317,7 @@ export declare type NewUserRecord = {
314
317
  name: number[];
315
318
  referrer: PublicKey;
316
319
  };
317
- export declare type DepositRecord = {
320
+ export type DepositRecord = {
318
321
  ts: BN;
319
322
  userAuthority: PublicKey;
320
323
  user: PublicKey;
@@ -335,7 +338,7 @@ export declare type DepositRecord = {
335
338
  explanation: DepositExplanation;
336
339
  transferUser?: PublicKey;
337
340
  };
338
- export declare type SpotInterestRecord = {
341
+ export type SpotInterestRecord = {
339
342
  ts: BN;
340
343
  marketIndex: number;
341
344
  depositBalance: BN;
@@ -346,7 +349,7 @@ export declare type SpotInterestRecord = {
346
349
  optimalBorrowRate: number;
347
350
  maxBorrowRate: number;
348
351
  };
349
- export declare type CurveRecord = {
352
+ export type CurveRecord = {
350
353
  ts: BN;
351
354
  recordId: BN;
352
355
  marketIndex: number;
@@ -394,7 +397,7 @@ export declare type InsuranceFundStakeRecord = {
394
397
  userIfSharesAfter: BN;
395
398
  totalIfSharesAfter: BN;
396
399
  };
397
- export declare type LPRecord = {
400
+ export type LPRecord = {
398
401
  ts: BN;
399
402
  user: PublicKey;
400
403
  action: LPAction;
@@ -415,7 +418,7 @@ export declare class LPAction {
415
418
  settleLiquidity: {};
416
419
  };
417
420
  }
418
- export declare type FundingRateRecord = {
421
+ export type FundingRateRecord = {
419
422
  ts: BN;
420
423
  recordId: BN;
421
424
  marketIndex: number;
@@ -430,7 +433,7 @@ export declare type FundingRateRecord = {
430
433
  baseAssetAmountWithAmm: BN;
431
434
  baseAssetAmountWithUnsettledLp: BN;
432
435
  };
433
- export declare type FundingPaymentRecord = {
436
+ export type FundingPaymentRecord = {
434
437
  ts: BN;
435
438
  userAuthority: PublicKey;
436
439
  user: PublicKey;
@@ -441,7 +444,7 @@ export declare type FundingPaymentRecord = {
441
444
  ammCumulativeFundingLong: BN;
442
445
  ammCumulativeFundingShort: BN;
443
446
  };
444
- export declare type LiquidationRecord = {
447
+ export type LiquidationRecord = {
445
448
  ts: BN;
446
449
  user: PublicKey;
447
450
  liquidator: PublicKey;
@@ -479,7 +482,7 @@ export declare class LiquidationType {
479
482
  liquidateSpot: {};
480
483
  };
481
484
  }
482
- export declare type LiquidatePerpRecord = {
485
+ export type LiquidatePerpRecord = {
483
486
  marketIndex: number;
484
487
  oraclePrice: BN;
485
488
  baseAssetAmount: BN;
@@ -491,7 +494,7 @@ export declare type LiquidatePerpRecord = {
491
494
  liquidatorFee: BN;
492
495
  ifFee: BN;
493
496
  };
494
- export declare type LiquidateSpotRecord = {
497
+ export type LiquidateSpotRecord = {
495
498
  assetMarketIndex: number;
496
499
  assetPrice: BN;
497
500
  assetTransfer: BN;
@@ -500,7 +503,7 @@ export declare type LiquidateSpotRecord = {
500
503
  liabilityTransfer: BN;
501
504
  ifFee: BN;
502
505
  };
503
- export declare type LiquidateBorrowForPerpPnlRecord = {
506
+ export type LiquidateBorrowForPerpPnlRecord = {
504
507
  perpMarketIndex: number;
505
508
  marketOraclePrice: BN;
506
509
  pnlTransfer: BN;
@@ -508,7 +511,7 @@ export declare type LiquidateBorrowForPerpPnlRecord = {
508
511
  liabilityPrice: BN;
509
512
  liabilityTransfer: BN;
510
513
  };
511
- export declare type LiquidatePerpPnlForDepositRecord = {
514
+ export type LiquidatePerpPnlForDepositRecord = {
512
515
  perpMarketIndex: number;
513
516
  marketOraclePrice: BN;
514
517
  pnlTransfer: BN;
@@ -516,7 +519,7 @@ export declare type LiquidatePerpPnlForDepositRecord = {
516
519
  assetPrice: BN;
517
520
  assetTransfer: BN;
518
521
  };
519
- export declare type PerpBankruptcyRecord = {
522
+ export type PerpBankruptcyRecord = {
520
523
  marketIndex: number;
521
524
  pnl: BN;
522
525
  ifPayment: BN;
@@ -524,13 +527,13 @@ export declare type PerpBankruptcyRecord = {
524
527
  clawbackUserPayment: BN | null;
525
528
  cumulativeFundingRateDelta: BN;
526
529
  };
527
- export declare type SpotBankruptcyRecord = {
530
+ export type SpotBankruptcyRecord = {
528
531
  marketIndex: number;
529
532
  borrowAmount: BN;
530
533
  cumulativeDepositInterestDelta: BN;
531
534
  ifPayment: BN;
532
535
  };
533
- export declare type SettlePnlRecord = {
536
+ export type SettlePnlRecord = {
534
537
  ts: BN;
535
538
  user: PublicKey;
536
539
  marketIndex: number;
@@ -541,12 +544,12 @@ export declare type SettlePnlRecord = {
541
544
  settlePrice: BN;
542
545
  explanation: SettlePnlExplanation;
543
546
  };
544
- export declare type OrderRecord = {
547
+ export type OrderRecord = {
545
548
  ts: BN;
546
549
  user: PublicKey;
547
550
  order: Order;
548
551
  };
549
- export declare type OrderActionRecord = {
552
+ export type OrderActionRecord = {
550
553
  ts: BN;
551
554
  action: OrderAction;
552
555
  actionExplanation: OrderActionExplanation;
@@ -576,7 +579,7 @@ export declare type OrderActionRecord = {
576
579
  makerOrderCumulativeQuoteAssetAmountFilled: BN | null;
577
580
  oraclePrice: BN;
578
581
  };
579
- export declare type StateAccount = {
582
+ export type StateAccount = {
580
583
  admin: PublicKey;
581
584
  exchangeStatus: number;
582
585
  whitelistMint: PublicKey;
@@ -600,7 +603,7 @@ export declare type StateAccount = {
600
603
  initialPctToLiquidate: number;
601
604
  liquidationDuration: number;
602
605
  };
603
- export declare type PerpMarketAccount = {
606
+ export type PerpMarketAccount = {
604
607
  status: MarketStatus;
605
608
  contractType: ContractType;
606
609
  contractTier: ContractTier;
@@ -633,7 +636,7 @@ export declare type PerpMarketAccount = {
633
636
  quoteMaxInsurance: BN;
634
637
  };
635
638
  };
636
- export declare type HistoricalOracleData = {
639
+ export type HistoricalOracleData = {
637
640
  lastOraclePrice: BN;
638
641
  lastOracleDelay: BN;
639
642
  lastOracleConf: BN;
@@ -641,14 +644,14 @@ export declare type HistoricalOracleData = {
641
644
  lastOraclePriceTwap5Min: BN;
642
645
  lastOraclePriceTwapTs: BN;
643
646
  };
644
- export declare type HistoricalIndexData = {
647
+ export type HistoricalIndexData = {
645
648
  lastIndexBidPrice: BN;
646
649
  lastIndexAskPrice: BN;
647
650
  lastIndexPriceTwap: BN;
648
651
  lastIndexPriceTwap5Min: BN;
649
652
  lastIndexPriceTwapTs: BN;
650
653
  };
651
- export declare type SpotMarketAccount = {
654
+ export type SpotMarketAccount = {
652
655
  status: MarketStatus;
653
656
  assetTier: AssetTier;
654
657
  marketIndex: number;
@@ -703,11 +706,11 @@ export declare type SpotMarketAccount = {
703
706
  totalSpotFee: BN;
704
707
  ordersEnabled: boolean;
705
708
  };
706
- export declare type PoolBalance = {
709
+ export type PoolBalance = {
707
710
  scaledBalance: BN;
708
711
  marketIndex: number;
709
712
  };
710
- export declare type AMM = {
713
+ export type AMM = {
711
714
  baseAssetReserve: BN;
712
715
  sqrtK: BN;
713
716
  cumulativeFundingRate: BN;
@@ -785,7 +788,7 @@ export declare type AMM = {
785
788
  askBaseAssetReserve: BN;
786
789
  askQuoteAssetReserve: BN;
787
790
  };
788
- export declare type PerpPosition = {
791
+ export type PerpPosition = {
789
792
  baseAssetAmount: BN;
790
793
  lastCumulativeFundingRate: BN;
791
794
  marketIndex: number;
@@ -801,7 +804,7 @@ export declare type PerpPosition = {
801
804
  lastBaseAssetAmountPerLp: BN;
802
805
  lastQuoteAssetAmountPerLp: BN;
803
806
  };
804
- export declare type UserStatsAccount = {
807
+ export type UserStatsAccount = {
805
808
  numberOfSubAccounts: number;
806
809
  numberOfSubAccountsCreated: number;
807
810
  makerVolume30D: BN;
@@ -823,7 +826,7 @@ export declare type UserStatsAccount = {
823
826
  authority: PublicKey;
824
827
  ifStakedQuoteAssetAmount: BN;
825
828
  };
826
- export declare type UserAccount = {
829
+ export type UserAccount = {
827
830
  authority: PublicKey;
828
831
  delegate: PublicKey;
829
832
  name: number[];
@@ -845,7 +848,7 @@ export declare type UserAccount = {
845
848
  liquidationStartSlot: BN;
846
849
  isMarginTradingEnabled: boolean;
847
850
  };
848
- export declare type SpotPosition = {
851
+ export type SpotPosition = {
849
852
  marketIndex: number;
850
853
  balanceType: SpotBalanceType;
851
854
  scaledBalance: BN;
@@ -854,7 +857,7 @@ export declare type SpotPosition = {
854
857
  openAsks: BN;
855
858
  cumulativeDeposits: BN;
856
859
  };
857
- export declare type Order = {
860
+ export type Order = {
858
861
  status: OrderStatus;
859
862
  orderType: OrderType;
860
863
  marketType: MarketType;
@@ -880,7 +883,7 @@ export declare type Order = {
880
883
  auctionEndPrice: BN;
881
884
  maxTs: BN;
882
885
  };
883
- export declare type OrderParams = {
886
+ export type OrderParams = {
884
887
  orderType: OrderType;
885
888
  marketType: MarketType;
886
889
  userOrderId: number;
@@ -911,33 +914,33 @@ export declare class PostOnlyParams {
911
914
  tryPostOnly: {};
912
915
  };
913
916
  }
914
- export declare type NecessaryOrderParams = {
917
+ export type NecessaryOrderParams = {
915
918
  orderType: OrderType;
916
919
  marketIndex: number;
917
920
  baseAssetAmount: BN;
918
921
  direction: PositionDirection;
919
922
  };
920
- export declare type OptionalOrderParams = {
923
+ export type OptionalOrderParams = {
921
924
  [Property in keyof OrderParams]?: OrderParams[Property];
922
925
  } & NecessaryOrderParams;
923
926
  export declare const DefaultOrderParams: OrderParams;
924
- export declare type MakerInfo = {
927
+ export type MakerInfo = {
925
928
  maker: PublicKey;
926
929
  makerStats: PublicKey;
927
930
  makerUserAccount: UserAccount;
928
931
  order: Order;
929
932
  };
930
- export declare type TakerInfo = {
933
+ export type TakerInfo = {
931
934
  taker: PublicKey;
932
935
  takerStats: PublicKey;
933
936
  takerUserAccount: UserAccount;
934
937
  order: Order;
935
938
  };
936
- export declare type ReferrerInfo = {
939
+ export type ReferrerInfo = {
937
940
  referrer: PublicKey;
938
941
  referrerStats: PublicKey;
939
942
  };
940
- export declare type TxParams = {
943
+ export type TxParams = {
941
944
  computeUnits?: number;
942
945
  computeUnitsPrice?: number;
943
946
  };
@@ -946,7 +949,7 @@ export interface IWallet {
946
949
  signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
947
950
  publicKey: PublicKey;
948
951
  }
949
- export declare type FeeStructure = {
952
+ export type FeeStructure = {
950
953
  feeTiers: FeeTier[];
951
954
  makerRebateNumerator: BN;
952
955
  makerRebateDenominator: BN;
@@ -954,7 +957,7 @@ export declare type FeeStructure = {
954
957
  flatFillerFee: BN;
955
958
  referrerRewardEpochUpperBound: BN;
956
959
  };
957
- export declare type FeeTier = {
960
+ export type FeeTier = {
958
961
  feeNumerator: number;
959
962
  feeDenominator: number;
960
963
  makerRebateNumerator: number;
@@ -964,12 +967,12 @@ export declare type FeeTier = {
964
967
  refereeFeeNumerator: number;
965
968
  refereeFeeDenominator: number;
966
969
  };
967
- export declare type OrderFillerRewardStructure = {
970
+ export type OrderFillerRewardStructure = {
968
971
  rewardNumerator: BN;
969
972
  rewardDenominator: BN;
970
973
  timeBasedRewardLowerBound: BN;
971
974
  };
972
- export declare type OracleGuardRails = {
975
+ export type OracleGuardRails = {
973
976
  priceDivergence: {
974
977
  markOracleDivergenceNumerator: BN;
975
978
  markOracleDivergenceDenominator: BN;
@@ -981,8 +984,8 @@ export declare type OracleGuardRails = {
981
984
  tooVolatileRatio: BN;
982
985
  };
983
986
  };
984
- export declare type MarginCategory = 'Initial' | 'Maintenance';
985
- export declare type InsuranceFundStake = {
987
+ export type MarginCategory = 'Initial' | 'Maintenance';
988
+ export type InsuranceFundStake = {
986
989
  marketIndex: number;
987
990
  authority: PublicKey;
988
991
  ifShares: BN;
@@ -991,7 +994,7 @@ export declare type InsuranceFundStake = {
991
994
  lastWithdrawRequestValue: BN;
992
995
  lastWithdrawRequestTs: BN;
993
996
  };
994
- export declare type SerumV3FulfillmentConfigAccount = {
997
+ export type SerumV3FulfillmentConfigAccount = {
995
998
  fulfillmentType: SpotFulfillmentType;
996
999
  status: SpotFulfillmentStatus;
997
1000
  pubkey: PublicKey;
package/lib/types.js CHANGED
@@ -78,7 +78,8 @@ class OracleSource {
78
78
  }
79
79
  exports.OracleSource = OracleSource;
80
80
  OracleSource.PYTH = { pyth: {} };
81
- OracleSource.PYTH_1000 = { pyth1000: {} };
81
+ OracleSource.PYTH_1K = { pyth1K: {} };
82
+ OracleSource.PYTH_1M = { pyth1M: {} };
82
83
  // static readonly SWITCHBOARD = { switchboard: {} };
83
84
  OracleSource.QUOTE_ASSET = { quoteAsset: {} };
84
85
  class OrderType {