@drift-labs/sdk 2.42.0-beta.8 → 2.43.0-beta.0

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 (71) hide show
  1. package/VERSION +1 -1
  2. package/bun.lockb +0 -0
  3. package/lib/accounts/bulkAccountLoader.d.ts +1 -2
  4. package/lib/addresses/pda.d.ts +1 -0
  5. package/lib/adminClient.d.ts +1 -0
  6. package/lib/config.d.ts +1 -0
  7. package/lib/config.js +1 -0
  8. package/lib/constants/numericConstants.d.ts +62 -60
  9. package/lib/constants/perpMarkets.js +42 -2
  10. package/lib/constants/spotMarkets.d.ts +1 -0
  11. package/lib/dlob/DLOB.d.ts +10 -16
  12. package/lib/dlob/DLOB.js +9 -39
  13. package/lib/dlob/DLOBNode.d.ts +1 -0
  14. package/lib/dlob/NodeList.d.ts +1 -0
  15. package/lib/dlob/orderBookLevels.d.ts +2 -1
  16. package/lib/driftClient.d.ts +10 -2
  17. package/lib/driftClient.js +20 -18
  18. package/lib/events/fetchLogs.js +2 -0
  19. package/lib/factory/bigNum.d.ts +8 -7
  20. package/lib/idl/drift.json +251 -239
  21. package/lib/index.d.ts +3 -0
  22. package/lib/index.js +3 -0
  23. package/lib/jupiter/jupiterClient.d.ts +1 -0
  24. package/lib/marinade/index.d.ts +1 -0
  25. package/lib/math/amm.d.ts +2 -1
  26. package/lib/math/auction.d.ts +1 -0
  27. package/lib/math/conversion.d.ts +2 -1
  28. package/lib/math/funding.d.ts +1 -0
  29. package/lib/math/funding.js +1 -1
  30. package/lib/math/insurance.d.ts +1 -0
  31. package/lib/math/margin.d.ts +1 -0
  32. package/lib/math/market.d.ts +1 -0
  33. package/lib/math/oracles.d.ts +1 -0
  34. package/lib/math/orders.d.ts +1 -0
  35. package/lib/math/position.d.ts +1 -0
  36. package/lib/math/repeg.d.ts +1 -0
  37. package/lib/math/spotBalance.d.ts +3 -2
  38. package/lib/math/spotMarket.d.ts +1 -0
  39. package/lib/math/spotPosition.d.ts +1 -0
  40. package/lib/math/superStake.d.ts +1 -0
  41. package/lib/math/trade.d.ts +1 -0
  42. package/lib/math/utils.d.ts +1 -0
  43. package/lib/oracles/pythClient.d.ts +2 -1
  44. package/lib/oracles/strictOraclePrice.d.ts +1 -0
  45. package/lib/oracles/types.d.ts +1 -0
  46. package/lib/orderParams.d.ts +1 -0
  47. package/lib/orderSubscriber/PollingSubscription.d.ts +1 -2
  48. package/lib/phoenix/phoenixSubscriber.d.ts +1 -0
  49. package/lib/priorityFee/priorityFeeSubscriber.d.ts +1 -2
  50. package/lib/serum/serumSubscriber.d.ts +1 -0
  51. package/lib/tokenFaucet.d.ts +1 -0
  52. package/lib/types.d.ts +6 -14
  53. package/lib/types.js +6 -7
  54. package/lib/user.d.ts +6 -5
  55. package/lib/user.js +17 -11
  56. package/package.json +2 -1
  57. package/src/accounts/bulkAccountLoader.ts +1 -1
  58. package/src/config.ts +2 -0
  59. package/src/constants/perpMarkets.ts +42 -2
  60. package/src/dlob/DLOB.ts +23 -67
  61. package/src/driftClient.ts +41 -27
  62. package/src/events/fetchLogs.ts +3 -0
  63. package/src/events/pollingLogProvider.ts +1 -1
  64. package/src/idl/drift.json +251 -239
  65. package/src/index.ts +3 -0
  66. package/src/math/funding.ts +1 -1
  67. package/src/orderSubscriber/PollingSubscription.ts +1 -1
  68. package/src/priorityFee/priorityFeeSubscriber.ts +1 -1
  69. package/src/types.ts +5 -6
  70. package/src/user.ts +49 -42
  71. package/tests/user/helpers.ts +1 -2
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.41.0",
2
+ "version": "2.42.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -5890,9 +5890,7 @@
5890
5890
  "docs": [
5891
5891
  "Whether the user is active, being liquidated or bankrupt"
5892
5892
  ],
5893
- "type": {
5894
- "defined": "UserStatus"
5895
- }
5893
+ "type": "u8"
5896
5894
  },
5897
5895
  {
5898
5896
  "name": "isMarginTradingEnabled",
@@ -6106,204 +6104,6 @@
6106
6104
  }
6107
6105
  ],
6108
6106
  "types": [
6109
- {
6110
- "name": "OrderParams",
6111
- "type": {
6112
- "kind": "struct",
6113
- "fields": [
6114
- {
6115
- "name": "orderType",
6116
- "type": {
6117
- "defined": "OrderType"
6118
- }
6119
- },
6120
- {
6121
- "name": "marketType",
6122
- "type": {
6123
- "defined": "MarketType"
6124
- }
6125
- },
6126
- {
6127
- "name": "direction",
6128
- "type": {
6129
- "defined": "PositionDirection"
6130
- }
6131
- },
6132
- {
6133
- "name": "userOrderId",
6134
- "type": "u8"
6135
- },
6136
- {
6137
- "name": "baseAssetAmount",
6138
- "type": "u64"
6139
- },
6140
- {
6141
- "name": "price",
6142
- "type": "u64"
6143
- },
6144
- {
6145
- "name": "marketIndex",
6146
- "type": "u16"
6147
- },
6148
- {
6149
- "name": "reduceOnly",
6150
- "type": "bool"
6151
- },
6152
- {
6153
- "name": "postOnly",
6154
- "type": {
6155
- "defined": "PostOnlyParam"
6156
- }
6157
- },
6158
- {
6159
- "name": "immediateOrCancel",
6160
- "type": "bool"
6161
- },
6162
- {
6163
- "name": "maxTs",
6164
- "type": {
6165
- "option": "i64"
6166
- }
6167
- },
6168
- {
6169
- "name": "triggerPrice",
6170
- "type": {
6171
- "option": "u64"
6172
- }
6173
- },
6174
- {
6175
- "name": "triggerCondition",
6176
- "type": {
6177
- "defined": "OrderTriggerCondition"
6178
- }
6179
- },
6180
- {
6181
- "name": "oraclePriceOffset",
6182
- "type": {
6183
- "option": "i32"
6184
- }
6185
- },
6186
- {
6187
- "name": "auctionDuration",
6188
- "type": {
6189
- "option": "u8"
6190
- }
6191
- },
6192
- {
6193
- "name": "auctionStartPrice",
6194
- "type": {
6195
- "option": "i64"
6196
- }
6197
- },
6198
- {
6199
- "name": "auctionEndPrice",
6200
- "type": {
6201
- "option": "i64"
6202
- }
6203
- }
6204
- ]
6205
- }
6206
- },
6207
- {
6208
- "name": "ModifyOrderParams",
6209
- "type": {
6210
- "kind": "struct",
6211
- "fields": [
6212
- {
6213
- "name": "direction",
6214
- "type": {
6215
- "option": {
6216
- "defined": "PositionDirection"
6217
- }
6218
- }
6219
- },
6220
- {
6221
- "name": "baseAssetAmount",
6222
- "type": {
6223
- "option": "u64"
6224
- }
6225
- },
6226
- {
6227
- "name": "price",
6228
- "type": {
6229
- "option": "u64"
6230
- }
6231
- },
6232
- {
6233
- "name": "reduceOnly",
6234
- "type": {
6235
- "option": "bool"
6236
- }
6237
- },
6238
- {
6239
- "name": "postOnly",
6240
- "type": {
6241
- "option": {
6242
- "defined": "PostOnlyParam"
6243
- }
6244
- }
6245
- },
6246
- {
6247
- "name": "immediateOrCancel",
6248
- "type": {
6249
- "option": "bool"
6250
- }
6251
- },
6252
- {
6253
- "name": "maxTs",
6254
- "type": {
6255
- "option": "i64"
6256
- }
6257
- },
6258
- {
6259
- "name": "triggerPrice",
6260
- "type": {
6261
- "option": "u64"
6262
- }
6263
- },
6264
- {
6265
- "name": "triggerCondition",
6266
- "type": {
6267
- "option": {
6268
- "defined": "OrderTriggerCondition"
6269
- }
6270
- }
6271
- },
6272
- {
6273
- "name": "oraclePriceOffset",
6274
- "type": {
6275
- "option": "i32"
6276
- }
6277
- },
6278
- {
6279
- "name": "auctionDuration",
6280
- "type": {
6281
- "option": "u8"
6282
- }
6283
- },
6284
- {
6285
- "name": "auctionStartPrice",
6286
- "type": {
6287
- "option": "i64"
6288
- }
6289
- },
6290
- {
6291
- "name": "auctionEndPrice",
6292
- "type": {
6293
- "option": "i64"
6294
- }
6295
- },
6296
- {
6297
- "name": "policy",
6298
- "type": {
6299
- "option": {
6300
- "defined": "ModifyOrderPolicy"
6301
- }
6302
- }
6303
- }
6304
- ]
6305
- }
6306
- },
6307
6107
  {
6308
6108
  "name": "LiquidatePerpRecord",
6309
6109
  "type": {
@@ -6614,6 +6414,204 @@
6614
6414
  ]
6615
6415
  }
6616
6416
  },
6417
+ {
6418
+ "name": "OrderParams",
6419
+ "type": {
6420
+ "kind": "struct",
6421
+ "fields": [
6422
+ {
6423
+ "name": "orderType",
6424
+ "type": {
6425
+ "defined": "OrderType"
6426
+ }
6427
+ },
6428
+ {
6429
+ "name": "marketType",
6430
+ "type": {
6431
+ "defined": "MarketType"
6432
+ }
6433
+ },
6434
+ {
6435
+ "name": "direction",
6436
+ "type": {
6437
+ "defined": "PositionDirection"
6438
+ }
6439
+ },
6440
+ {
6441
+ "name": "userOrderId",
6442
+ "type": "u8"
6443
+ },
6444
+ {
6445
+ "name": "baseAssetAmount",
6446
+ "type": "u64"
6447
+ },
6448
+ {
6449
+ "name": "price",
6450
+ "type": "u64"
6451
+ },
6452
+ {
6453
+ "name": "marketIndex",
6454
+ "type": "u16"
6455
+ },
6456
+ {
6457
+ "name": "reduceOnly",
6458
+ "type": "bool"
6459
+ },
6460
+ {
6461
+ "name": "postOnly",
6462
+ "type": {
6463
+ "defined": "PostOnlyParam"
6464
+ }
6465
+ },
6466
+ {
6467
+ "name": "immediateOrCancel",
6468
+ "type": "bool"
6469
+ },
6470
+ {
6471
+ "name": "maxTs",
6472
+ "type": {
6473
+ "option": "i64"
6474
+ }
6475
+ },
6476
+ {
6477
+ "name": "triggerPrice",
6478
+ "type": {
6479
+ "option": "u64"
6480
+ }
6481
+ },
6482
+ {
6483
+ "name": "triggerCondition",
6484
+ "type": {
6485
+ "defined": "OrderTriggerCondition"
6486
+ }
6487
+ },
6488
+ {
6489
+ "name": "oraclePriceOffset",
6490
+ "type": {
6491
+ "option": "i32"
6492
+ }
6493
+ },
6494
+ {
6495
+ "name": "auctionDuration",
6496
+ "type": {
6497
+ "option": "u8"
6498
+ }
6499
+ },
6500
+ {
6501
+ "name": "auctionStartPrice",
6502
+ "type": {
6503
+ "option": "i64"
6504
+ }
6505
+ },
6506
+ {
6507
+ "name": "auctionEndPrice",
6508
+ "type": {
6509
+ "option": "i64"
6510
+ }
6511
+ }
6512
+ ]
6513
+ }
6514
+ },
6515
+ {
6516
+ "name": "ModifyOrderParams",
6517
+ "type": {
6518
+ "kind": "struct",
6519
+ "fields": [
6520
+ {
6521
+ "name": "direction",
6522
+ "type": {
6523
+ "option": {
6524
+ "defined": "PositionDirection"
6525
+ }
6526
+ }
6527
+ },
6528
+ {
6529
+ "name": "baseAssetAmount",
6530
+ "type": {
6531
+ "option": "u64"
6532
+ }
6533
+ },
6534
+ {
6535
+ "name": "price",
6536
+ "type": {
6537
+ "option": "u64"
6538
+ }
6539
+ },
6540
+ {
6541
+ "name": "reduceOnly",
6542
+ "type": {
6543
+ "option": "bool"
6544
+ }
6545
+ },
6546
+ {
6547
+ "name": "postOnly",
6548
+ "type": {
6549
+ "option": {
6550
+ "defined": "PostOnlyParam"
6551
+ }
6552
+ }
6553
+ },
6554
+ {
6555
+ "name": "immediateOrCancel",
6556
+ "type": {
6557
+ "option": "bool"
6558
+ }
6559
+ },
6560
+ {
6561
+ "name": "maxTs",
6562
+ "type": {
6563
+ "option": "i64"
6564
+ }
6565
+ },
6566
+ {
6567
+ "name": "triggerPrice",
6568
+ "type": {
6569
+ "option": "u64"
6570
+ }
6571
+ },
6572
+ {
6573
+ "name": "triggerCondition",
6574
+ "type": {
6575
+ "option": {
6576
+ "defined": "OrderTriggerCondition"
6577
+ }
6578
+ }
6579
+ },
6580
+ {
6581
+ "name": "oraclePriceOffset",
6582
+ "type": {
6583
+ "option": "i32"
6584
+ }
6585
+ },
6586
+ {
6587
+ "name": "auctionDuration",
6588
+ "type": {
6589
+ "option": "u8"
6590
+ }
6591
+ },
6592
+ {
6593
+ "name": "auctionStartPrice",
6594
+ "type": {
6595
+ "option": "i64"
6596
+ }
6597
+ },
6598
+ {
6599
+ "name": "auctionEndPrice",
6600
+ "type": {
6601
+ "option": "i64"
6602
+ }
6603
+ },
6604
+ {
6605
+ "name": "policy",
6606
+ "type": {
6607
+ "option": {
6608
+ "defined": "ModifyOrderPolicy"
6609
+ }
6610
+ }
6611
+ }
6612
+ ]
6613
+ }
6614
+ },
6617
6615
  {
6618
6616
  "name": "InsuranceClaim",
6619
6617
  "type": {
@@ -8007,40 +8005,6 @@
8007
8005
  ]
8008
8006
  }
8009
8007
  },
8010
- {
8011
- "name": "PostOnlyParam",
8012
- "type": {
8013
- "kind": "enum",
8014
- "variants": [
8015
- {
8016
- "name": "None"
8017
- },
8018
- {
8019
- "name": "MustPostOnly"
8020
- },
8021
- {
8022
- "name": "TryPostOnly"
8023
- },
8024
- {
8025
- "name": "Slide"
8026
- }
8027
- ]
8028
- }
8029
- },
8030
- {
8031
- "name": "ModifyOrderPolicy",
8032
- "type": {
8033
- "kind": "enum",
8034
- "variants": [
8035
- {
8036
- "name": "TryModify"
8037
- },
8038
- {
8039
- "name": "MustModify"
8040
- }
8041
- ]
8042
- }
8043
- },
8044
8008
  {
8045
8009
  "name": "SwapReduceOnly",
8046
8010
  "type": {
@@ -8383,6 +8347,23 @@
8383
8347
  ]
8384
8348
  }
8385
8349
  },
8350
+ {
8351
+ "name": "FillMode",
8352
+ "type": {
8353
+ "kind": "enum",
8354
+ "variants": [
8355
+ {
8356
+ "name": "Fill"
8357
+ },
8358
+ {
8359
+ "name": "PlaceAndMake"
8360
+ },
8361
+ {
8362
+ "name": "PlaceAndTake"
8363
+ }
8364
+ ]
8365
+ }
8366
+ },
8386
8367
  {
8387
8368
  "name": "PerpFulfillmentMethod",
8388
8369
  "type": {
@@ -8474,6 +8455,40 @@
8474
8455
  ]
8475
8456
  }
8476
8457
  },
8458
+ {
8459
+ "name": "PostOnlyParam",
8460
+ "type": {
8461
+ "kind": "enum",
8462
+ "variants": [
8463
+ {
8464
+ "name": "None"
8465
+ },
8466
+ {
8467
+ "name": "MustPostOnly"
8468
+ },
8469
+ {
8470
+ "name": "TryPostOnly"
8471
+ },
8472
+ {
8473
+ "name": "Slide"
8474
+ }
8475
+ ]
8476
+ }
8477
+ },
8478
+ {
8479
+ "name": "ModifyOrderPolicy",
8480
+ "type": {
8481
+ "kind": "enum",
8482
+ "variants": [
8483
+ {
8484
+ "name": "TryModify"
8485
+ },
8486
+ {
8487
+ "name": "MustModify"
8488
+ }
8489
+ ]
8490
+ }
8491
+ },
8477
8492
  {
8478
8493
  "name": "MarketStatus",
8479
8494
  "type": {
@@ -8648,9 +8663,6 @@
8648
8663
  "type": {
8649
8664
  "kind": "enum",
8650
8665
  "variants": [
8651
- {
8652
- "name": "Active"
8653
- },
8654
8666
  {
8655
8667
  "name": "BeingLiquidated"
8656
8668
  },
package/lib/index.d.ts CHANGED
@@ -33,6 +33,9 @@ export * from './factory/bigNum';
33
33
  export * from './events/types';
34
34
  export * from './events/eventSubscriber';
35
35
  export * from './events/fetchLogs';
36
+ export * from './events/txEventCache';
37
+ export * from './events/webSocketLogProvider';
38
+ export * from './events/pollingLogProvider';
36
39
  export * from './jupiter/jupiterClient';
37
40
  export * from './math/auction';
38
41
  export * from './math/spotMarket';
package/lib/index.js CHANGED
@@ -56,6 +56,9 @@ __exportStar(require("./factory/bigNum"), exports);
56
56
  __exportStar(require("./events/types"), exports);
57
57
  __exportStar(require("./events/eventSubscriber"), exports);
58
58
  __exportStar(require("./events/fetchLogs"), exports);
59
+ __exportStar(require("./events/txEventCache"), exports);
60
+ __exportStar(require("./events/webSocketLogProvider"), exports);
61
+ __exportStar(require("./events/pollingLogProvider"), exports);
59
62
  __exportStar(require("./jupiter/jupiterClient"), exports);
60
63
  __exportStar(require("./math/auction"), exports);
61
64
  __exportStar(require("./math/spotMarket"), exports);
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { AddressLookupTableAccount, Connection, PublicKey, TransactionInstruction, TransactionMessage, VersionedTransaction } from '@solana/web3.js';
2
3
  import { BN } from '@coral-xyz/anchor';
3
4
  export type SwapMode = 'ExactIn' | 'ExactOut';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { AnchorProvider, BN, Program } from '@coral-xyz/anchor';
2
3
  import { MarinadeFinance } from './types';
3
4
  import { PublicKey, TransactionInstruction } from '@solana/web3.js';
package/lib/math/amm.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN } from '@coral-xyz/anchor';
2
3
  import { AMM, PositionDirection, SwapDirection, PerpMarketAccount } from '../types';
3
4
  import { OraclePriceData } from '../oracles/types';
@@ -86,7 +87,7 @@ export declare function getSwapDirection(inputAssetType: AssetType, positionDire
86
87
  * @param market
87
88
  * @returns cost : Precision PRICE_PRECISION
88
89
  */
89
- export declare function calculateTerminalPrice(market: PerpMarketAccount): any;
90
+ export declare function calculateTerminalPrice(market: PerpMarketAccount): BN;
90
91
  export declare function calculateMaxBaseAssetAmountToTrade(amm: AMM, limit_price: BN, direction: PositionDirection, oraclePriceData?: OraclePriceData, now?: BN): [BN, PositionDirection];
91
92
  export declare function calculateQuoteAssetAmountSwapped(quoteAssetReserves: BN, pegMultiplier: BN, swapDirection: SwapDirection): BN;
92
93
  export declare function calculateMaxBaseAssetAmountFillable(amm: AMM, orderDirection: PositionDirection): BN;
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { Order, PositionDirection } from '../types';
2
3
  import { BN } from '../.';
3
4
  export declare function isAuctionComplete(order: Order, slot: number): boolean;
@@ -1 +1,2 @@
1
- export declare const convertToNumber: (bigNumber: BN, precision?: BN) => any;
1
+ import { BN } from '../';
2
+ export declare const convertToNumber: (bigNumber: BN, precision?: BN) => number;
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN } from '@coral-xyz/anchor';
2
3
  import { PerpMarketAccount } from '../types';
3
4
  import { OraclePriceData } from '../oracles/types';
@@ -72,7 +72,7 @@ async function calculateAllEstimatedFundingRate(market, oraclePriceData, markPri
72
72
  // console.log('shrink orac:', liveOracleTwap.toString(), '->', oracleTwap.toString());
73
73
  // }
74
74
  const twapSpread = markTwap.sub(oracleTwap);
75
- const twapSpreadWithOffset = twapSpread.add(anchor_1.BN.abs(oracleTwap).div(numericConstants_1.FUNDING_RATE_OFFSET_DENOMINATOR));
75
+ const twapSpreadWithOffset = twapSpread.add(oracleTwap.abs().div(numericConstants_1.FUNDING_RATE_OFFSET_DENOMINATOR));
76
76
  const twapSpreadPct = twapSpreadWithOffset
77
77
  .mul(numericConstants_1.PRICE_PRECISION)
78
78
  .mul(new anchor_1.BN(100))
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN } from '../index';
2
3
  export declare function stakeAmountToShares(amount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
3
4
  export declare function unstakeSharesToAmount(nShares: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN } from '@coral-xyz/anchor';
2
3
  import { OraclePriceData } from '../oracles/types';
3
4
  import { PerpMarketAccount, PerpPosition } from '..';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN } from '@coral-xyz/anchor';
2
3
  import { PerpMarketAccount, PositionDirection, MarginCategory, SpotMarketAccount } from '../types';
3
4
  import { OraclePriceData } from '../oracles/types';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { AMM, OracleGuardRails } from '../types';
2
3
  import { OraclePriceData } from '../oracles/types';
3
4
  import { BN, HistoricalOracleData, PerpMarketAccount } from '../index';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { User } from '../user';
2
3
  import { PerpMarketAccount, AMM, Order, PositionDirection } from '../types';
3
4
  import { BN } from '@coral-xyz/anchor';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN, SpotMarketAccount } from '../';
2
3
  import { OraclePriceData } from '../oracles/types';
3
4
  import { PerpMarketAccount, PositionDirection, PerpPosition } from '../types';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN } from '@coral-xyz/anchor';
2
3
  import { AMM } from '../types';
3
4
  /**