@drift-labs/sdk 2.10.0 → 2.11.0-beta.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.
@@ -3,15 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getOracleClient = void 0;
4
4
  const types_1 = require("../types");
5
5
  const pythClient_1 = require("../oracles/pythClient");
6
- const switchboardClient_1 = require("../oracles/switchboardClient");
6
+ // import { SwitchboardClient } from '../oracles/switchboardClient';
7
7
  const quoteAssetOracleClient_1 = require("../oracles/quoteAssetOracleClient");
8
8
  function getOracleClient(oracleSource, connection) {
9
9
  if ((0, types_1.isVariant)(oracleSource, 'pyth')) {
10
10
  return new pythClient_1.PythClient(connection);
11
11
  }
12
- if ((0, types_1.isVariant)(oracleSource, 'switchboard')) {
13
- return new switchboardClient_1.SwitchboardClient(connection);
14
- }
12
+ // if (isVariant(oracleSource, 'switchboard')) {
13
+ // return new SwitchboardClient(connection);
14
+ // }
15
15
  if ((0, types_1.isVariant)(oracleSource, 'quoteAsset')) {
16
16
  return new quoteAssetOracleClient_1.QuoteAssetOracleClient();
17
17
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.10.0",
2
+ "version": "2.11.0-beta.1",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -6190,7 +6190,12 @@
6190
6190
  ]
6191
6191
  },
6192
6192
  {
6193
- "name": "Match"
6193
+ "name": "Match",
6194
+ "fields": [
6195
+ {
6196
+ "defined": "usize"
6197
+ }
6198
+ ]
6194
6199
  }
6195
6200
  ]
6196
6201
  }
@@ -8558,6 +8563,11 @@
8558
8563
  "code": 6223,
8559
8564
  "name": "FailedUnwrap",
8560
8565
  "msg": "Failed Unwrap"
8566
+ },
8567
+ {
8568
+ "code": 6224,
8569
+ "name": "MaxNumberOfUsers",
8570
+ "msg": "Max Number Of Users"
8561
8571
  }
8562
8572
  ]
8563
8573
  }
package/lib/index.d.ts CHANGED
@@ -4,7 +4,6 @@ import pyth from '@pythnetwork/client';
4
4
  export * from './tokenFaucet';
5
5
  export * from './oracles/types';
6
6
  export * from './oracles/pythClient';
7
- export * from './oracles/switchboardClient';
8
7
  export * from './types';
9
8
  export * from './constants/perpMarkets';
10
9
  export * from './accounts/fetch';
package/lib/index.js CHANGED
@@ -27,7 +27,7 @@ exports.pyth = client_1.default;
27
27
  __exportStar(require("./tokenFaucet"), exports);
28
28
  __exportStar(require("./oracles/types"), exports);
29
29
  __exportStar(require("./oracles/pythClient"), exports);
30
- __exportStar(require("./oracles/switchboardClient"), exports);
30
+ // export * from './oracles/switchboardClient';
31
31
  __exportStar(require("./types"), exports);
32
32
  __exportStar(require("./constants/perpMarkets"), exports);
33
33
  __exportStar(require("./accounts/fetch"), exports);
package/lib/types.d.ts CHANGED
@@ -142,9 +142,6 @@ export declare class OracleSource {
142
142
  static readonly PYTH: {
143
143
  pyth: {};
144
144
  };
145
- static readonly SWITCHBOARD: {
146
- switchboard: {};
147
- };
148
145
  static readonly QUOTE_ASSET: {
149
146
  quoteAsset: {};
150
147
  };
package/lib/types.js CHANGED
@@ -76,7 +76,7 @@ class OracleSource {
76
76
  }
77
77
  exports.OracleSource = OracleSource;
78
78
  OracleSource.PYTH = { pyth: {} };
79
- OracleSource.SWITCHBOARD = { switchboard: {} };
79
+ // static readonly SWITCHBOARD = { switchboard: {} };
80
80
  OracleSource.QUOTE_ASSET = { quoteAsset: {} };
81
81
  class OrderType {
82
82
  }
package/lib/user.js CHANGED
@@ -291,6 +291,9 @@ class User {
291
291
  .reduce((unrealizedPnl, perpPosition) => {
292
292
  const market = this.driftClient.getPerpMarketAccount(perpPosition.marketIndex);
293
293
  const oraclePriceData = this.getOracleDataForPerpMarket(market.marketIndex);
294
+ if (perpPosition.lpShares.gt(numericConstants_1.ZERO)) {
295
+ perpPosition = this.getSettledLPPosition(perpPosition.marketIndex)[0];
296
+ }
294
297
  let positionUnrealizedPnl = (0, _1.calculatePositionPNL)(market, perpPosition, withFunding, oraclePriceData);
295
298
  if (withWeightMarginCategory !== undefined) {
296
299
  if (positionUnrealizedPnl.gt(numericConstants_1.ZERO)) {
@@ -698,6 +701,9 @@ class User {
698
701
  */
699
702
  spotLiquidationPrice(spotPosition) {
700
703
  const currentSpotPosition = this.getSpotPosition(spotPosition.marketIndex);
704
+ if (!currentSpotPosition) {
705
+ return new _1.BN(-1);
706
+ }
701
707
  const mtc = this.getTotalCollateral('Maintenance');
702
708
  const mmr = this.getMaintenanceMarginRequirement();
703
709
  const deltaValueToLiq = mtc.sub(mmr); // QUOTE_PRECISION
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.10.0",
3
+ "version": "2.11.0-beta.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -38,7 +38,6 @@
38
38
  "@pythnetwork/client": "2.5.3",
39
39
  "@solana/spl-token": "^0.1.6",
40
40
  "@solana/web3.js": "1.66.2",
41
- "@switchboard-xyz/switchboard-v2": "^0.0.67",
42
41
  "strict-event-emitter-types": "^2.0.0",
43
42
  "uuid": "^8.3.2"
44
43
  },
@@ -2,7 +2,7 @@ import { isVariant, OracleSource } from '../types';
2
2
  import { Connection } from '@solana/web3.js';
3
3
  import { OracleClient } from '../oracles/types';
4
4
  import { PythClient } from '../oracles/pythClient';
5
- import { SwitchboardClient } from '../oracles/switchboardClient';
5
+ // import { SwitchboardClient } from '../oracles/switchboardClient';
6
6
  import { QuoteAssetOracleClient } from '../oracles/quoteAssetOracleClient';
7
7
 
8
8
  export function getOracleClient(
@@ -13,9 +13,9 @@ export function getOracleClient(
13
13
  return new PythClient(connection);
14
14
  }
15
15
 
16
- if (isVariant(oracleSource, 'switchboard')) {
17
- return new SwitchboardClient(connection);
18
- }
16
+ // if (isVariant(oracleSource, 'switchboard')) {
17
+ // return new SwitchboardClient(connection);
18
+ // }
19
19
 
20
20
  if (isVariant(oracleSource, 'quoteAsset')) {
21
21
  return new QuoteAssetOracleClient();
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.10.0",
2
+ "version": "2.11.0-beta.1",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -6190,7 +6190,12 @@
6190
6190
  ]
6191
6191
  },
6192
6192
  {
6193
- "name": "Match"
6193
+ "name": "Match",
6194
+ "fields": [
6195
+ {
6196
+ "defined": "usize"
6197
+ }
6198
+ ]
6194
6199
  }
6195
6200
  ]
6196
6201
  }
@@ -8558,6 +8563,11 @@
8558
8563
  "code": 6223,
8559
8564
  "name": "FailedUnwrap",
8560
8565
  "msg": "Failed Unwrap"
8566
+ },
8567
+ {
8568
+ "code": 6224,
8569
+ "name": "MaxNumberOfUsers",
8570
+ "msg": "Max Number Of Users"
8561
8571
  }
8562
8572
  ]
8563
8573
  }
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@ import pyth from '@pythnetwork/client';
5
5
  export * from './tokenFaucet';
6
6
  export * from './oracles/types';
7
7
  export * from './oracles/pythClient';
8
- export * from './oracles/switchboardClient';
8
+ // export * from './oracles/switchboardClient';
9
9
  export * from './types';
10
10
  export * from './constants/perpMarkets';
11
11
  export * from './accounts/fetch';
package/src/types.ts CHANGED
@@ -74,7 +74,7 @@ export class DepositDirection {
74
74
 
75
75
  export class OracleSource {
76
76
  static readonly PYTH = { pyth: {} };
77
- static readonly SWITCHBOARD = { switchboard: {} };
77
+ // static readonly SWITCHBOARD = { switchboard: {} };
78
78
  static readonly QUOTE_ASSET = { quoteAsset: {} };
79
79
  }
80
80
 
package/src/user.ts CHANGED
@@ -447,6 +447,10 @@ export class User {
447
447
  market.marketIndex
448
448
  );
449
449
 
450
+ if (perpPosition.lpShares.gt(ZERO)) {
451
+ perpPosition = this.getSettledLPPosition(perpPosition.marketIndex)[0];
452
+ }
453
+
450
454
  let positionUnrealizedPnl = calculatePositionPNL(
451
455
  market,
452
456
  perpPosition,
@@ -1169,6 +1173,10 @@ export class User {
1169
1173
  ): BN {
1170
1174
  const currentSpotPosition = this.getSpotPosition(spotPosition.marketIndex);
1171
1175
 
1176
+ if (!currentSpotPosition) {
1177
+ return new BN(-1);
1178
+ }
1179
+
1172
1180
  const mtc = this.getTotalCollateral('Maintenance');
1173
1181
  const mmr = this.getMaintenanceMarginRequirement();
1174
1182