@drift-labs/sdk 2.12.0-beta.1 → 2.12.0-beta.2

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.12.0-beta.1",
2
+ "version": "2.12.0-beta.2",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -3705,9 +3705,7 @@
3705
3705
  "args": [
3706
3706
  {
3707
3707
  "name": "exchangeStatus",
3708
- "type": {
3709
- "defined": "ExchangeStatus"
3710
- }
3708
+ "type": "u8"
3711
3709
  }
3712
3710
  ]
3713
3711
  },
@@ -4384,9 +4382,7 @@
4384
4382
  },
4385
4383
  {
4386
4384
  "name": "exchangeStatus",
4387
- "type": {
4388
- "defined": "ExchangeStatus"
4389
- }
4385
+ "type": "u8"
4390
4386
  },
4391
4387
  {
4392
4388
  "name": "liquidationDuration",
@@ -6360,10 +6356,10 @@
6360
6356
  "kind": "enum",
6361
6357
  "variants": [
6362
6358
  {
6363
- "name": "Active"
6359
+ "name": "DepositPaused"
6364
6360
  },
6365
6361
  {
6366
- "name": "FundingPaused"
6362
+ "name": "WithdrawPaused"
6367
6363
  },
6368
6364
  {
6369
6365
  "name": "AmmPaused"
@@ -6375,10 +6371,10 @@
6375
6371
  "name": "LiqPaused"
6376
6372
  },
6377
6373
  {
6378
- "name": "WithdrawPaused"
6374
+ "name": "FundingPaused"
6379
6375
  },
6380
6376
  {
6381
- "name": "Paused"
6377
+ "name": "SettlePnlPaused"
6382
6378
  }
6383
6379
  ]
6384
6380
  }
@@ -3,16 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ammPaused = exports.fillPaused = exports.exchangePaused = void 0;
4
4
  const types_1 = require("../types");
5
5
  function exchangePaused(state) {
6
- return (0, types_1.isVariant)(state.exchangeStatus, 'paused');
6
+ return state.exchangeStatus !== types_1.ExchangeStatus.ACTIVE;
7
7
  }
8
8
  exports.exchangePaused = exchangePaused;
9
9
  function fillPaused(state, market) {
10
- return ((0, types_1.isOneOfVariant)(state.exchangeStatus, ['paused', 'fillPaused']) ||
10
+ return ((state.exchangeStatus & types_1.ExchangeStatus.FILL_PAUSED) ===
11
+ types_1.ExchangeStatus.FILL_PAUSED ||
11
12
  (0, types_1.isOneOfVariant)(market.status, ['paused', 'fillPaused']));
12
13
  }
13
14
  exports.fillPaused = fillPaused;
14
15
  function ammPaused(state, market) {
15
- return ((0, types_1.isOneOfVariant)(state.exchangeStatus, ['paused', 'ammPaused']) ||
16
+ return ((state.exchangeStatus & types_1.ExchangeStatus.AMM_PAUSED) ===
17
+ types_1.ExchangeStatus.AMM_PAUSED ||
16
18
  (0, types_1.isOneOfVariant)(market.status, ['paused', 'ammPaused']));
17
19
  }
18
20
  exports.ammPaused = ammPaused;
package/lib/types.d.ts CHANGED
@@ -1,28 +1,16 @@
1
1
  /// <reference types="bn.js" />
2
2
  import { PublicKey, Transaction } from '@solana/web3.js';
3
3
  import { BN } from '.';
4
- export declare class ExchangeStatus {
5
- static readonly ACTIVE: {
6
- active: {};
7
- };
8
- static readonly FUNDING_PAUSED: {
9
- fundingPaused: {};
10
- };
11
- static readonly AMM_PAUSED: {
12
- ammPaused: {};
13
- };
14
- static readonly FILL_PAUSED: {
15
- fillPaused: {};
16
- };
17
- static readonly LIQ_PAUSED: {
18
- liqPaused: {};
19
- };
20
- static readonly WITHDRAW_PAUSED: {
21
- withdrawPaused: {};
22
- };
23
- static readonly PAUSED: {
24
- paused: {};
25
- };
4
+ export declare enum ExchangeStatus {
5
+ ACTIVE = 0,
6
+ DEPOSIT_PAUSED = 1,
7
+ WITHDRAW_PAUSED = 2,
8
+ AMM_PAUSED = 4,
9
+ FILL_PAUSED = 8,
10
+ LIQ_PAUSED = 16,
11
+ FUNDING_PAUSED = 32,
12
+ SETTLE_PNL_PAUSED = 64,
13
+ PAUSED = 127
26
14
  }
27
15
  export declare class MarketStatus {
28
16
  static readonly INITIALIZED: {
@@ -587,7 +575,7 @@ export declare type OrderActionRecord = {
587
575
  };
588
576
  export declare type StateAccount = {
589
577
  admin: PublicKey;
590
- exchangeStatus: ExchangeStatus;
578
+ exchangeStatus: number;
591
579
  whitelistMint: PublicKey;
592
580
  discountMint: PublicKey;
593
581
  oracleGuardRails: OracleGuardRails;
package/lib/types.js CHANGED
@@ -3,16 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DefaultOrderParams = exports.LiquidationType = exports.LPAction = exports.TradeSide = exports.getVariant = exports.isOneOfVariant = exports.isVariant = exports.StakeAction = exports.SpotFulfillmentConfigStatus = 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
- class ExchangeStatus {
7
- }
8
- exports.ExchangeStatus = ExchangeStatus;
9
- ExchangeStatus.ACTIVE = { active: {} };
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
- ExchangeStatus.PAUSED = { paused: {} };
6
+ var ExchangeStatus;
7
+ (function (ExchangeStatus) {
8
+ ExchangeStatus[ExchangeStatus["ACTIVE"] = 0] = "ACTIVE";
9
+ ExchangeStatus[ExchangeStatus["DEPOSIT_PAUSED"] = 1] = "DEPOSIT_PAUSED";
10
+ ExchangeStatus[ExchangeStatus["WITHDRAW_PAUSED"] = 2] = "WITHDRAW_PAUSED";
11
+ ExchangeStatus[ExchangeStatus["AMM_PAUSED"] = 4] = "AMM_PAUSED";
12
+ ExchangeStatus[ExchangeStatus["FILL_PAUSED"] = 8] = "FILL_PAUSED";
13
+ ExchangeStatus[ExchangeStatus["LIQ_PAUSED"] = 16] = "LIQ_PAUSED";
14
+ ExchangeStatus[ExchangeStatus["FUNDING_PAUSED"] = 32] = "FUNDING_PAUSED";
15
+ ExchangeStatus[ExchangeStatus["SETTLE_PNL_PAUSED"] = 64] = "SETTLE_PNL_PAUSED";
16
+ ExchangeStatus[ExchangeStatus["PAUSED"] = 127] = "PAUSED";
17
+ })(ExchangeStatus = exports.ExchangeStatus || (exports.ExchangeStatus = {}));
16
18
  class MarketStatus {
17
19
  }
18
20
  exports.MarketStatus = MarketStatus;
package/lib/user.js CHANGED
@@ -797,7 +797,7 @@ class User {
797
797
  const freeCollateralExcludingTargetMarket = totalCollateral.sub(marginRequirementExcludingTargetMarket);
798
798
  // if the position value after the trade is less than free collateral, there is no liq price
799
799
  if (totalPositionValueAfterTrade.lte(freeCollateralExcludingTargetMarket) &&
800
- proposedPerpPosition.baseAssetAmount.abs().gt(numericConstants_1.ZERO)) {
800
+ proposedPerpPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
801
801
  return new _1.BN(-1);
802
802
  }
803
803
  const marginRequirementAfterTrade = marginRequirementExcludingTargetMarket.add(proposedPerpPositionValue
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.12.0-beta.1",
3
+ "version": "2.12.0-beta.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.12.0-beta.1",
2
+ "version": "2.12.0-beta.2",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -3705,9 +3705,7 @@
3705
3705
  "args": [
3706
3706
  {
3707
3707
  "name": "exchangeStatus",
3708
- "type": {
3709
- "defined": "ExchangeStatus"
3710
- }
3708
+ "type": "u8"
3711
3709
  }
3712
3710
  ]
3713
3711
  },
@@ -4384,9 +4382,7 @@
4384
4382
  },
4385
4383
  {
4386
4384
  "name": "exchangeStatus",
4387
- "type": {
4388
- "defined": "ExchangeStatus"
4389
- }
4385
+ "type": "u8"
4390
4386
  },
4391
4387
  {
4392
4388
  "name": "liquidationDuration",
@@ -6360,10 +6356,10 @@
6360
6356
  "kind": "enum",
6361
6357
  "variants": [
6362
6358
  {
6363
- "name": "Active"
6359
+ "name": "DepositPaused"
6364
6360
  },
6365
6361
  {
6366
- "name": "FundingPaused"
6362
+ "name": "WithdrawPaused"
6367
6363
  },
6368
6364
  {
6369
6365
  "name": "AmmPaused"
@@ -6375,10 +6371,10 @@
6375
6371
  "name": "LiqPaused"
6376
6372
  },
6377
6373
  {
6378
- "name": "WithdrawPaused"
6374
+ "name": "FundingPaused"
6379
6375
  },
6380
6376
  {
6381
- "name": "Paused"
6377
+ "name": "SettlePnlPaused"
6382
6378
  }
6383
6379
  ]
6384
6380
  }
@@ -1,13 +1,13 @@
1
1
  import {
2
+ ExchangeStatus,
2
3
  isOneOfVariant,
3
- isVariant,
4
4
  PerpMarketAccount,
5
5
  SpotMarketAccount,
6
6
  StateAccount,
7
7
  } from '../types';
8
8
 
9
9
  export function exchangePaused(state: StateAccount): boolean {
10
- return isVariant(state.exchangeStatus, 'paused');
10
+ return state.exchangeStatus !== ExchangeStatus.ACTIVE;
11
11
  }
12
12
 
13
13
  export function fillPaused(
@@ -15,7 +15,8 @@ export function fillPaused(
15
15
  market: PerpMarketAccount | SpotMarketAccount
16
16
  ): boolean {
17
17
  return (
18
- isOneOfVariant(state.exchangeStatus, ['paused', 'fillPaused']) ||
18
+ (state.exchangeStatus & ExchangeStatus.FILL_PAUSED) ===
19
+ ExchangeStatus.FILL_PAUSED ||
19
20
  isOneOfVariant(market.status, ['paused', 'fillPaused'])
20
21
  );
21
22
  }
@@ -25,7 +26,8 @@ export function ammPaused(
25
26
  market: PerpMarketAccount | SpotMarketAccount
26
27
  ): boolean {
27
28
  return (
28
- isOneOfVariant(state.exchangeStatus, ['paused', 'ammPaused']) ||
29
+ (state.exchangeStatus & ExchangeStatus.AMM_PAUSED) ===
30
+ ExchangeStatus.AMM_PAUSED ||
29
31
  isOneOfVariant(market.status, ['paused', 'ammPaused'])
30
32
  );
31
33
  }
package/src/types.ts CHANGED
@@ -3,14 +3,16 @@ import { BN, ZERO } from '.';
3
3
 
4
4
  // # Utility Types / Enums / Constants
5
5
 
6
- export class ExchangeStatus {
7
- static readonly ACTIVE = { active: {} };
8
- static readonly FUNDING_PAUSED = { fundingPaused: {} };
9
- static readonly AMM_PAUSED = { ammPaused: {} };
10
- static readonly FILL_PAUSED = { fillPaused: {} };
11
- static readonly LIQ_PAUSED = { liqPaused: {} };
12
- static readonly WITHDRAW_PAUSED = { withdrawPaused: {} };
13
- static readonly PAUSED = { paused: {} };
6
+ export enum ExchangeStatus {
7
+ ACTIVE = 0,
8
+ DEPOSIT_PAUSED = 1,
9
+ WITHDRAW_PAUSED = 2,
10
+ AMM_PAUSED = 4,
11
+ FILL_PAUSED = 8,
12
+ LIQ_PAUSED = 16,
13
+ FUNDING_PAUSED = 32,
14
+ SETTLE_PNL_PAUSED = 64,
15
+ PAUSED = 127,
14
16
  }
15
17
 
16
18
  export class MarketStatus {
@@ -501,7 +503,7 @@ export type OrderActionRecord = {
501
503
 
502
504
  export type StateAccount = {
503
505
  admin: PublicKey;
504
- exchangeStatus: ExchangeStatus;
506
+ exchangeStatus: number;
505
507
  whitelistMint: PublicKey;
506
508
  discountMint: PublicKey;
507
509
  oracleGuardRails: OracleGuardRails;
package/src/user.ts CHANGED
@@ -1335,7 +1335,7 @@ export class User {
1335
1335
  // if the position value after the trade is less than free collateral, there is no liq price
1336
1336
  if (
1337
1337
  totalPositionValueAfterTrade.lte(freeCollateralExcludingTargetMarket) &&
1338
- proposedPerpPosition.baseAssetAmount.abs().gt(ZERO)
1338
+ proposedPerpPosition.baseAssetAmount.gt(ZERO)
1339
1339
  ) {
1340
1340
  return new BN(-1);
1341
1341
  }
@@ -19,7 +19,6 @@ import {
19
19
  UserMapInterface,
20
20
  Wallet,
21
21
  OrderRecord,
22
- ExchangeStatus,
23
22
  ZERO,
24
23
  ContractTier,
25
24
  } from '../../src';
@@ -478,7 +477,7 @@ export const mockStateAccount: StateAccount = {
478
477
  defaultMarketOrderTimeInForce: 0,
479
478
  defaultSpotAuctionDuration: 0,
480
479
  discountMint: PublicKey.default,
481
- exchangeStatus: ExchangeStatus.ACTIVE,
480
+ exchangeStatus: 0,
482
481
  liquidationMarginBufferRatio: 0,
483
482
  lpCooldownTime: new BN(0),
484
483
  minPerpAuctionDuration: 0,