@drift-labs/sdk 0.2.0-master.40 → 0.2.0-master.42

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.
package/lib/types.d.ts CHANGED
@@ -5,19 +5,19 @@ export declare class ExchangeStatus {
5
5
  static readonly ACTIVE: {
6
6
  active: {};
7
7
  };
8
- static readonly FUNDINGPAUSED: {
8
+ static readonly FUNDING_PAUSED: {
9
9
  fundingPaused: {};
10
10
  };
11
- static readonly AMMPAUSED: {
11
+ static readonly AMM_PAUSED: {
12
12
  ammPaused: {};
13
13
  };
14
- static readonly FILLPAUSED: {
14
+ static readonly FILL_PAUSED: {
15
15
  fillPaused: {};
16
16
  };
17
- static readonly LIQPAUSED: {
17
+ static readonly LIQ_PAUSED: {
18
18
  liqPaused: {};
19
19
  };
20
- static readonly WITHDRAWPAUSED: {
20
+ static readonly WITHDRAW_PAUSED: {
21
21
  withdrawPaused: {};
22
22
  };
23
23
  static readonly PAUSED: {
@@ -31,19 +31,19 @@ export declare class MarketStatus {
31
31
  static readonly ACTIVE: {
32
32
  active: {};
33
33
  };
34
- static readonly FUNDINGPAUSED: {
34
+ static readonly FUNDING_PAUSED: {
35
35
  fundingPaused: {};
36
36
  };
37
- static readonly AMMPAUSED: {
37
+ static readonly AMM_PAUSED: {
38
38
  ammPaused: {};
39
39
  };
40
- static readonly FILLPAUSED: {
40
+ static readonly FILL_PAUSED: {
41
41
  fillPaused: {};
42
42
  };
43
- static readonly WITHDRAWPAUSED: {
43
+ static readonly WITHDRAW_PAUSED: {
44
44
  withdrawPaused: {};
45
45
  };
46
- static readonly REDUCEONLY: {
46
+ static readonly REDUCE_ONLY: {
47
47
  reduceOnly: {};
48
48
  };
49
49
  static readonly SETTLEMENT: {
@@ -53,6 +53,17 @@ export declare class MarketStatus {
53
53
  delisted: {};
54
54
  };
55
55
  }
56
+ export declare class UserStatus {
57
+ static readonly ACTIVE: {
58
+ active: {};
59
+ };
60
+ static readonly BEING_LIQUIDATED: {
61
+ beingLiquidated: {};
62
+ };
63
+ static readonly BANKRUPT: {
64
+ bankrupt: {};
65
+ };
66
+ }
56
67
  export declare class ContractType {
57
68
  static readonly PERPETUAL: {
58
69
  perpetual: {};
@@ -169,23 +180,6 @@ export declare class OrderStatus {
169
180
  open: {};
170
181
  };
171
182
  }
172
- export declare class OrderDiscountTier {
173
- static readonly NONE: {
174
- none: {};
175
- };
176
- static readonly FIRST: {
177
- first: {};
178
- };
179
- static readonly SECOND: {
180
- second: {};
181
- };
182
- static readonly THIRD: {
183
- third: {};
184
- };
185
- static readonly FOURTH: {
186
- fourth: {};
187
- };
188
- }
189
183
  export declare class OrderAction {
190
184
  static readonly PLACE: {
191
185
  place: {};
@@ -207,17 +201,38 @@ export declare class OrderActionExplanation {
207
201
  static readonly NONE: {
208
202
  none: {};
209
203
  };
204
+ static readonly INSUFFICIENT_FREE_COLLATERAL: {
205
+ insufficientFreeCollateral: {};
206
+ };
210
207
  static readonly ORACLE_PRICE_BREACHED_LIMIT_PRICE: {
211
208
  oraclePriceBreachedLimitPrice: {};
212
209
  };
213
210
  static readonly MARKET_ORDER_FILLED_TO_LIMIT_PRICE: {
214
211
  marketOrderFilledToLimitPrice: {};
215
212
  };
216
- static readonly CANCELED_FOR_LIQUIDATION: {
217
- canceledForLiquidation: {};
213
+ static readonly ORDER_EXPIRED: {
214
+ orderExpired: {};
215
+ };
216
+ static readonly LIQUIDATION: {
217
+ liquidation: {};
218
+ };
219
+ static readonly ORDER_FILLED_WITH_AMM: {
220
+ orderFilledWithAMM: {};
221
+ };
222
+ static readonly ORDER_FILLED_WITH_AMM_JIT: {
223
+ orderFilledWithAMMJit: {};
224
+ };
225
+ static readonly ORDER_FILLED_WITH_MATCH: {
226
+ orderFilledWithMatch: {};
227
+ };
228
+ static readonly MARKET_EXPIRED: {
229
+ marketExpired: {};
218
230
  };
219
- static readonly MARKET_ORDER_AUCTION_EXPIRED: {
220
- marketOrderAuctionExpired: {};
231
+ static readonly RISK_INCREASING_ORDER: {
232
+ riskingIncreasingOrder: {};
233
+ };
234
+ static readonly ORDER_FILLED_WITH_SERUM: {
235
+ orderFillWithSerum: {};
221
236
  };
222
237
  }
223
238
  export declare class OrderTriggerCondition {
@@ -227,6 +242,12 @@ export declare class OrderTriggerCondition {
227
242
  static readonly BELOW: {
228
243
  below: {};
229
244
  };
245
+ static readonly TRIGGERED_ABOVE: {
246
+ triggeredAbove: {};
247
+ };
248
+ static readonly TRIGGERED_BELOW: {
249
+ triggeredBelow: {};
250
+ };
230
251
  }
231
252
  export declare class SpotFulfillmentType {
232
253
  static readonly SERUM_v3: {
@@ -241,6 +262,36 @@ export declare class SpotFulfillmentStatus {
241
262
  disabled: {};
242
263
  };
243
264
  }
265
+ export declare class DepositExplanation {
266
+ static readonly NONE: {
267
+ none: {};
268
+ };
269
+ static readonly TRANSFER: {
270
+ transfer: {};
271
+ };
272
+ }
273
+ export declare class SettlePnlExplanation {
274
+ static readonly NONE: {
275
+ none: {};
276
+ };
277
+ static readonly EXPIRED_POSITION: {
278
+ expiredPosition: {};
279
+ };
280
+ }
281
+ export declare class StakeAction {
282
+ static readonly STAKE: {
283
+ stake: {};
284
+ };
285
+ static readonly UNSTAKE_REQUEST: {
286
+ unstakeRequest: {};
287
+ };
288
+ static readonly UNSTAKE_CANCEL_REQUEST: {
289
+ unstakeCancelRequest: {};
290
+ };
291
+ static readonly UNSTAKE: {
292
+ unstake: {};
293
+ };
294
+ }
244
295
  export declare function isVariant(object: unknown, type: string): boolean;
245
296
  export declare function isOneOfVariant(object: unknown, types: string[]): boolean;
246
297
  export declare function getVariant(object: unknown): string;
@@ -273,7 +324,10 @@ export declare type DepositRecord = {
273
324
  marketWithdrawBalance: BN;
274
325
  marketCumulativeDepositInterest: BN;
275
326
  marketCumulativeBorrowInterest: BN;
327
+ totalDepositsAfter: BN;
328
+ totalWithdrawsAfter: BN;
276
329
  depositRecordId: BN;
330
+ explanation: DepositExplanation;
277
331
  transferUser?: PublicKey;
278
332
  };
279
333
  export declare type SpotInterestRecord = {
@@ -301,21 +355,38 @@ export declare type CurveRecord = {
301
355
  sqrtKAfter: BN;
302
356
  baseAssetAmountLong: BN;
303
357
  baseAssetAmountShort: BN;
304
- baseAssetAmount: BN;
305
- openInterest: BN;
358
+ baseAssetAmountWithAmm: BN;
359
+ totalFee: BN;
360
+ totalFeeMinusDistributions: BN;
361
+ adjustmentCost: BN;
362
+ numberOfUsers: BN;
306
363
  oraclePrice: BN;
307
- tradeId: BN;
364
+ fillRecord: BN;
308
365
  };
309
366
  export declare type InsuranceFundRecord = {
310
367
  ts: BN;
311
- bankIndex: BN;
312
- marketIndex: number;
368
+ spotMarketIndex: number;
369
+ perpMarketIndex: number;
313
370
  userIfFactor: number;
314
371
  totalIfFactor: number;
315
372
  vaultAmountBefore: BN;
316
373
  insuranceVaultAmountBefore: BN;
374
+ totalIfSharesBefore: BN;
375
+ totalIfSharesAfter: BN;
317
376
  amount: BN;
377
+ };
378
+ export declare type InsuranceFundStakeRecord = {
379
+ ts: BN;
380
+ userAuthority: PublicKey;
381
+ action: StakeAction;
382
+ amount: BN;
383
+ marketIndex: number;
384
+ insuranceVaultAmountBefore: BN;
385
+ ifSharesBefore: BN;
386
+ userIfSharesBefore: BN;
318
387
  totalIfSharesBefore: BN;
388
+ ifSharesAfter: BN;
389
+ userIfSharesAfter: BN;
319
390
  totalIfSharesAfter: BN;
320
391
  };
321
392
  export declare type LPRecord = {
@@ -372,7 +443,9 @@ export declare type LiquidationRecord = {
372
443
  liquidationType: LiquidationType;
373
444
  marginRequirement: BN;
374
445
  totalCollateral: BN;
446
+ marginFreed: BN;
375
447
  liquidationId: number;
448
+ bankrupt: boolean;
376
449
  canceledOrderIds: BN[];
377
450
  liquidatePerp: LiquidatePerpRecord;
378
451
  liquidateSpot: LiquidateSpotRecord;
@@ -410,6 +483,7 @@ export declare type LiquidatePerpRecord = {
410
483
  userOrderId: BN;
411
484
  liquidatorOrderId: BN;
412
485
  fillRecordId: BN;
486
+ liquidatorFee: BN;
413
487
  ifFee: BN;
414
488
  };
415
489
  export declare type LiquidateSpotRecord = {
@@ -460,6 +534,7 @@ export declare type SettlePnlRecord = {
460
534
  quoteAssetAmountAfter: BN;
461
535
  quoteEntryAmount: BN;
462
536
  settlePrice: BN;
537
+ explanation: SettlePnlExplanation;
463
538
  };
464
539
  export declare type OrderRecord = {
465
540
  ts: BN;
@@ -481,13 +556,13 @@ export declare type OrderActionRecord = {
481
556
  makerFee: BN | null;
482
557
  referrerReward: number | null;
483
558
  quoteAssetAmountSurplus: BN | null;
559
+ spotFulfillmentMethodFee: BN | null;
484
560
  taker: PublicKey | null;
485
561
  takerOrderId: number | null;
486
562
  takerOrderDirection: PositionDirection | null;
487
563
  takerOrderBaseAssetAmount: BN | null;
488
564
  takerOrderCumulativeBaseAssetAmountFilled: BN | null;
489
565
  takerOrderCumulativeQuoteAssetAmountFilled: BN | null;
490
- takerOrderFee: BN | null;
491
566
  maker: PublicKey | null;
492
567
  makerOrderId: number | null;
493
568
  makerOrderDirection: PositionDirection | null;
@@ -502,6 +577,8 @@ export declare type StateAccount = {
502
577
  whitelistMint: PublicKey;
503
578
  discountMint: PublicKey;
504
579
  oracleGuardRails: OracleGuardRails;
580
+ numberOfAuthorities: BN;
581
+ numberOfSubAccounts: BN;
505
582
  numberOfMarkets: number;
506
583
  numberOfSpotMarkets: number;
507
584
  minPerpAuctionDuration: number;
@@ -554,14 +631,14 @@ export declare type HistoricalOracleData = {
554
631
  lastOracleDelay: BN;
555
632
  lastOracleConf: BN;
556
633
  lastOraclePriceTwap: BN;
557
- lastOraclePriceTwap5min: BN;
634
+ lastOraclePriceTwap5Min: BN;
558
635
  lastOraclePriceTwapTs: BN;
559
636
  };
560
637
  export declare type HistoricalIndexData = {
561
638
  lastIndexBidPrice: BN;
562
639
  lastIndexAskPrice: BN;
563
640
  lastIndexPriceTwap: BN;
564
- lastIndexPriceTwap5min: BN;
641
+ lastIndexPriceTwap5Min: BN;
565
642
  lastIndexPriceTwapTs: BN;
566
643
  };
567
644
  export declare type SpotMarketAccount = {
@@ -594,6 +671,8 @@ export declare type SpotMarketAccount = {
594
671
  maxBorrowRate: number;
595
672
  cumulativeDepositInterest: BN;
596
673
  cumulativeBorrowInterest: BN;
674
+ totalSocialLoss: BN;
675
+ totalQuoteSocialLoss: BN;
597
676
  depositBalance: BN;
598
677
  borrowBalance: BN;
599
678
  maxTokenDeposits: BN;
@@ -628,7 +707,7 @@ export declare type AMM = {
628
707
  lastFundingRate: BN;
629
708
  lastFundingRateTs: BN;
630
709
  lastMarkPriceTwap: BN;
631
- lastMarkPriceTwap5min: BN;
710
+ lastMarkPriceTwap5Min: BN;
632
711
  lastMarkPriceTwapTs: BN;
633
712
  lastTradeTs: BN;
634
713
  oracle: PublicKey;
@@ -680,17 +759,18 @@ export declare type AMM = {
680
759
  maxOpenInterest: BN;
681
760
  maxBaseAssetReserve: BN;
682
761
  minBaseAssetReserve: BN;
683
- cumulativeSocialLoss: BN;
762
+ totalSocialLoss: BN;
684
763
  quoteBreakEvenAmountLong: BN;
685
764
  quoteBreakEvenAmountShort: BN;
686
765
  quoteEntryAmountLong: BN;
687
766
  quoteEntryAmountShort: BN;
688
767
  markStd: BN;
768
+ oracleStd: BN;
689
769
  longIntensityCount: number;
690
770
  longIntensityVolume: BN;
691
771
  shortIntensityCount: number;
692
772
  shortIntensityVolume: BN;
693
- volume24h: BN;
773
+ volume24H: BN;
694
774
  minOrderSize: BN;
695
775
  maxPositionSize: BN;
696
776
  bidBaseAssetReserve: BN;
@@ -716,7 +796,7 @@ export declare type PerpPosition = {
716
796
  };
717
797
  export declare type UserStatsAccount = {
718
798
  numberOfSubAccounts: number;
719
- maxSubAccountId: number;
799
+ numberOfSubAccountsCreated: number;
720
800
  makerVolume30D: BN;
721
801
  takerVolume30D: BN;
722
802
  fillerVolume30D: BN;
@@ -744,8 +824,7 @@ export declare type UserAccount = {
744
824
  spotPositions: SpotPosition[];
745
825
  perpPositions: PerpPosition[];
746
826
  orders: Order[];
747
- isBeingLiquidated: boolean;
748
- isBankrupt: boolean;
827
+ status: UserStatus;
749
828
  nextLiquidationId: number;
750
829
  nextOrderId: number;
751
830
  maxMarginRatio: number;
@@ -753,6 +832,7 @@ export declare type UserAccount = {
753
832
  settledPerpPnl: BN;
754
833
  totalDeposits: BN;
755
834
  totalWithdraws: BN;
835
+ totalSocialLoss: BN;
756
836
  cumulativePerpFunding: BN;
757
837
  };
758
838
  export declare type SpotPosition = {
@@ -781,7 +861,6 @@ export declare type Order = {
781
861
  reduceOnly: boolean;
782
862
  triggerPrice: BN;
783
863
  triggerCondition: OrderTriggerCondition;
784
- triggered: boolean;
785
864
  existingPositionDirection: PositionDirection;
786
865
  postOnly: boolean;
787
866
  immediateOrCancel: boolean;
package/lib/types.js CHANGED
@@ -1,30 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultOrderParams = exports.LiquidationType = exports.LPAction = exports.TradeSide = exports.getVariant = exports.isOneOfVariant = exports.isVariant = exports.SpotFulfillmentStatus = exports.SpotFulfillmentType = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderDiscountTier = exports.OrderStatus = exports.MarketType = exports.OrderType = exports.OracleSource = exports.DepositDirection = exports.PositionDirection = exports.SpotBalanceType = exports.SwapDirection = exports.AssetTier = exports.ContractTier = exports.ContractType = exports.MarketStatus = exports.ExchangeStatus = void 0;
3
+ exports.DefaultOrderParams = exports.LiquidationType = exports.LPAction = exports.TradeSide = exports.getVariant = exports.isOneOfVariant = exports.isVariant = exports.StakeAction = exports.SettlePnlExplanation = exports.DepositExplanation = exports.SpotFulfillmentStatus = exports.SpotFulfillmentType = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderStatus = exports.MarketType = exports.OrderType = exports.OracleSource = exports.DepositDirection = exports.PositionDirection = exports.SpotBalanceType = exports.SwapDirection = exports.AssetTier = exports.ContractTier = exports.ContractType = exports.UserStatus = exports.MarketStatus = exports.ExchangeStatus = void 0;
4
4
  const _1 = require(".");
5
5
  // # Utility Types / Enums / Constants
6
6
  class ExchangeStatus {
7
7
  }
8
8
  exports.ExchangeStatus = ExchangeStatus;
9
9
  ExchangeStatus.ACTIVE = { active: {} };
10
- ExchangeStatus.FUNDINGPAUSED = { fundingPaused: {} };
11
- ExchangeStatus.AMMPAUSED = { ammPaused: {} };
12
- ExchangeStatus.FILLPAUSED = { fillPaused: {} };
13
- ExchangeStatus.LIQPAUSED = { liqPaused: {} };
14
- ExchangeStatus.WITHDRAWPAUSED = { withdrawPaused: {} };
10
+ ExchangeStatus.FUNDING_PAUSED = { fundingPaused: {} };
11
+ ExchangeStatus.AMM_PAUSED = { ammPaused: {} };
12
+ ExchangeStatus.FILL_PAUSED = { fillPaused: {} };
13
+ ExchangeStatus.LIQ_PAUSED = { liqPaused: {} };
14
+ ExchangeStatus.WITHDRAW_PAUSED = { withdrawPaused: {} };
15
15
  ExchangeStatus.PAUSED = { paused: {} };
16
16
  class MarketStatus {
17
17
  }
18
18
  exports.MarketStatus = MarketStatus;
19
19
  MarketStatus.INITIALIZED = { initialized: {} };
20
20
  MarketStatus.ACTIVE = { active: {} };
21
- MarketStatus.FUNDINGPAUSED = { fundingPaused: {} };
22
- MarketStatus.AMMPAUSED = { ammPaused: {} };
23
- MarketStatus.FILLPAUSED = { fillPaused: {} };
24
- MarketStatus.WITHDRAWPAUSED = { withdrawPaused: {} };
25
- MarketStatus.REDUCEONLY = { reduceOnly: {} };
21
+ MarketStatus.FUNDING_PAUSED = { fundingPaused: {} };
22
+ MarketStatus.AMM_PAUSED = { ammPaused: {} };
23
+ MarketStatus.FILL_PAUSED = { fillPaused: {} };
24
+ MarketStatus.WITHDRAW_PAUSED = { withdrawPaused: {} };
25
+ MarketStatus.REDUCE_ONLY = { reduceOnly: {} };
26
26
  MarketStatus.SETTLEMENT = { settlement: {} };
27
27
  MarketStatus.DELISTED = { delisted: {} };
28
+ class UserStatus {
29
+ }
30
+ exports.UserStatus = UserStatus;
31
+ UserStatus.ACTIVE = { active: {} };
32
+ UserStatus.BEING_LIQUIDATED = { beingLiquidated: {} };
33
+ UserStatus.BANKRUPT = { bankrupt: {} };
28
34
  class ContractType {
29
35
  }
30
36
  exports.ContractType = ContractType;
@@ -89,14 +95,6 @@ class OrderStatus {
89
95
  exports.OrderStatus = OrderStatus;
90
96
  OrderStatus.INIT = { init: {} };
91
97
  OrderStatus.OPEN = { open: {} };
92
- class OrderDiscountTier {
93
- }
94
- exports.OrderDiscountTier = OrderDiscountTier;
95
- OrderDiscountTier.NONE = { none: {} };
96
- OrderDiscountTier.FIRST = { first: {} };
97
- OrderDiscountTier.SECOND = { second: {} };
98
- OrderDiscountTier.THIRD = { third: {} };
99
- OrderDiscountTier.FOURTH = { fourth: {} };
100
98
  class OrderAction {
101
99
  }
102
100
  exports.OrderAction = OrderAction;
@@ -109,23 +107,46 @@ class OrderActionExplanation {
109
107
  }
110
108
  exports.OrderActionExplanation = OrderActionExplanation;
111
109
  OrderActionExplanation.NONE = { none: {} };
110
+ OrderActionExplanation.INSUFFICIENT_FREE_COLLATERAL = {
111
+ insufficientFreeCollateral: {},
112
+ };
112
113
  OrderActionExplanation.ORACLE_PRICE_BREACHED_LIMIT_PRICE = {
113
114
  oraclePriceBreachedLimitPrice: {},
114
115
  };
115
116
  OrderActionExplanation.MARKET_ORDER_FILLED_TO_LIMIT_PRICE = {
116
117
  marketOrderFilledToLimitPrice: {},
117
118
  };
118
- OrderActionExplanation.CANCELED_FOR_LIQUIDATION = {
119
- canceledForLiquidation: {},
119
+ OrderActionExplanation.ORDER_EXPIRED = {
120
+ orderExpired: {},
121
+ };
122
+ OrderActionExplanation.LIQUIDATION = {
123
+ liquidation: {},
124
+ };
125
+ OrderActionExplanation.ORDER_FILLED_WITH_AMM = {
126
+ orderFilledWithAMM: {},
127
+ };
128
+ OrderActionExplanation.ORDER_FILLED_WITH_AMM_JIT = {
129
+ orderFilledWithAMMJit: {},
130
+ };
131
+ OrderActionExplanation.ORDER_FILLED_WITH_MATCH = {
132
+ orderFilledWithMatch: {},
133
+ };
134
+ OrderActionExplanation.MARKET_EXPIRED = {
135
+ marketExpired: {},
136
+ };
137
+ OrderActionExplanation.RISK_INCREASING_ORDER = {
138
+ riskingIncreasingOrder: {},
120
139
  };
121
- OrderActionExplanation.MARKET_ORDER_AUCTION_EXPIRED = {
122
- marketOrderAuctionExpired: {},
140
+ OrderActionExplanation.ORDER_FILLED_WITH_SERUM = {
141
+ orderFillWithSerum: {},
123
142
  };
124
143
  class OrderTriggerCondition {
125
144
  }
126
145
  exports.OrderTriggerCondition = OrderTriggerCondition;
127
146
  OrderTriggerCondition.ABOVE = { above: {} };
128
147
  OrderTriggerCondition.BELOW = { below: {} };
148
+ OrderTriggerCondition.TRIGGERED_ABOVE = { triggeredAbove: {} }; // above condition has been triggered
149
+ OrderTriggerCondition.TRIGGERED_BELOW = { triggeredBelow: {} }; // below condition has been triggered
129
150
  class SpotFulfillmentType {
130
151
  }
131
152
  exports.SpotFulfillmentType = SpotFulfillmentType;
@@ -135,6 +156,23 @@ class SpotFulfillmentStatus {
135
156
  exports.SpotFulfillmentStatus = SpotFulfillmentStatus;
136
157
  SpotFulfillmentStatus.ENABLED = { enabled: {} };
137
158
  SpotFulfillmentStatus.DISABLED = { disabled: {} };
159
+ class DepositExplanation {
160
+ }
161
+ exports.DepositExplanation = DepositExplanation;
162
+ DepositExplanation.NONE = { none: {} };
163
+ DepositExplanation.TRANSFER = { transfer: {} };
164
+ class SettlePnlExplanation {
165
+ }
166
+ exports.SettlePnlExplanation = SettlePnlExplanation;
167
+ SettlePnlExplanation.NONE = { none: {} };
168
+ SettlePnlExplanation.EXPIRED_POSITION = { expiredPosition: {} };
169
+ class StakeAction {
170
+ }
171
+ exports.StakeAction = StakeAction;
172
+ StakeAction.STAKE = { stake: {} };
173
+ StakeAction.UNSTAKE_REQUEST = { unstakeRequest: {} };
174
+ StakeAction.UNSTAKE_CANCEL_REQUEST = { unstakeCancelRequest: {} };
175
+ StakeAction.UNSTAKE = { unstake: {} };
138
176
  function isVariant(object, type) {
139
177
  return object.hasOwnProperty(type);
140
178
  }
package/lib/user.d.ts CHANGED
@@ -152,6 +152,8 @@ export declare class User {
152
152
  */
153
153
  getMarginRatio(): BN;
154
154
  canBeLiquidated(): boolean;
155
+ isBeingLiquidated(): boolean;
156
+ isBankrupt(): boolean;
155
157
  /**
156
158
  * Checks if any user position cumulative funding differs from respective market cumulative funding
157
159
  * @returns
package/lib/user.js CHANGED
@@ -605,12 +605,22 @@ class User {
605
605
  const totalCollateral = this.getTotalCollateral();
606
606
  // if user being liq'd, can continue to be liq'd until total collateral above the margin requirement plus buffer
607
607
  let liquidationBuffer = undefined;
608
- if (this.getUserAccount().isBeingLiquidated) {
608
+ const isBeingLiquidated = (0, types_1.isVariant)(this.getUserAccount().status, 'beingLiquidated');
609
+ if (isBeingLiquidated) {
609
610
  liquidationBuffer = new _1.BN(this.driftClient.getStateAccount().liquidationMarginBufferRatio);
610
611
  }
611
612
  const maintenanceRequirement = this.getMaintenanceMarginRequirement(liquidationBuffer);
612
613
  return totalCollateral.lt(maintenanceRequirement);
613
614
  }
615
+ isBeingLiquidated() {
616
+ return (0, types_1.isOneOfVariant)(this.getUserAccount().status, [
617
+ 'beingLiquidated',
618
+ 'bankrupt',
619
+ ]);
620
+ }
621
+ isBankrupt() {
622
+ return (0, types_1.isVariant)(this.getUserAccount().status, 'bankrupt');
623
+ }
614
624
  /**
615
625
  * Checks if any user position cumulative funding differs from respective market cumulative funding
616
626
  * @returns
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "0.2.0-master.40",
3
+ "version": "0.2.0-master.42",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -37,7 +37,7 @@
37
37
  "@project-serum/serum": "^0.13.38",
38
38
  "@pythnetwork/client": "2.5.3",
39
39
  "@solana/spl-token": "^0.1.6",
40
- "@solana/web3.js": "1.41.0",
40
+ "@solana/web3.js": "1.66.2",
41
41
  "@switchboard-xyz/switchboard-v2": "^0.0.67",
42
42
  "async-mutex": "^0.4.0",
43
43
  "strict-event-emitter-types": "^2.0.0",
@@ -44,20 +44,13 @@ export class PollingUserAccountSubscriber implements UserAccountSubscriber {
44
44
 
45
45
  await this.addToAccountLoader();
46
46
 
47
- let subscriptionSucceeded = false;
48
- let retries = 0;
49
- while (!subscriptionSucceeded && retries < 5) {
50
- await this.fetchIfUnloaded();
51
- subscriptionSucceeded = this.didSubscriptionSucceed();
52
- retries++;
53
- }
54
-
55
- if (subscriptionSucceeded) {
47
+ await this.fetchIfUnloaded();
48
+ if (this.doAccountsExist()) {
56
49
  this.eventEmitter.emit('update');
57
50
  }
58
51
 
59
- this.isSubscribed = subscriptionSucceeded;
60
- return subscriptionSucceeded;
52
+ this.isSubscribed = true;
53
+ return true;
61
54
  }
62
55
 
63
56
  async addToAccountLoader(): Promise<void> {
@@ -124,7 +117,7 @@ export class PollingUserAccountSubscriber implements UserAccountSubscriber {
124
117
  }
125
118
  }
126
119
 
127
- didSubscriptionSucceed(): boolean {
120
+ doAccountsExist(): boolean {
128
121
  let success = true;
129
122
  for (const [_, accountToPoll] of this.accountsToPoll) {
130
123
  if (!this[accountToPoll.key]) {
@@ -46,20 +46,14 @@ export class PollingUserStatsAccountSubscriber
46
46
 
47
47
  await this.addToAccountLoader();
48
48
 
49
- let subscriptionSucceeded = false;
50
- let retries = 0;
51
- while (!subscriptionSucceeded && retries < 5) {
52
- await this.fetchIfUnloaded();
53
- subscriptionSucceeded = this.didSubscriptionSucceed();
54
- retries++;
55
- }
49
+ await this.fetchIfUnloaded();
56
50
 
57
- if (subscriptionSucceeded) {
51
+ if (this.doAccountsExist()) {
58
52
  this.eventEmitter.emit('update');
59
53
  }
60
54
 
61
- this.isSubscribed = subscriptionSucceeded;
62
- return subscriptionSucceeded;
55
+ this.isSubscribed = true;
56
+ return true;
63
57
  }
64
58
 
65
59
  async addToAccountLoader(): Promise<void> {
@@ -126,7 +120,7 @@ export class PollingUserStatsAccountSubscriber
126
120
  }
127
121
  }
128
122
 
129
- didSubscriptionSucceed(): boolean {
123
+ doAccountsExist(): boolean {
130
124
  let success = true;
131
125
  for (const [_, accountToPoll] of this.accountsToPoll) {
132
126
  if (!this[accountToPoll.key]) {
package/src/config.ts CHANGED
@@ -29,7 +29,7 @@ export const configs: { [key in DriftEnv]: DriftConfig } = {
29
29
  devnet: {
30
30
  ENV: 'devnet',
31
31
  PYTH_ORACLE_MAPPING_ADDRESS: 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2',
32
- CLEARING_HOUSE_PROGRAM_ID: 'H4G1xzAoqSW8n1Edmeowqsgc895tSNCeDPafYjv4Md7i',
32
+ CLEARING_HOUSE_PROGRAM_ID: '4PzAUP84r19y2whicgTysCiqxw5aHabLHyDh3oJiAtqe',
33
33
  USDC_MINT_ADDRESS: '8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2',
34
34
  SERUM_V3: 'DESVgJVGajEgKGXhb6XmqDHGz3VjdgP7rEVESBgxmroY',
35
35
  V2_ALPHA_TICKET_MINT_ADDRESS: