@drift-labs/sdk 2.98.0-beta.0 → 2.98.0-beta.10

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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.98.0-beta.0
1
+ 2.98.0-beta.10
@@ -861,6 +861,17 @@ exports.MainnetPerpMarkets = [
861
861
  launchTs: 1729209600000,
862
862
  oracleSource: __1.OracleSource.Prelaunch,
863
863
  },
864
+ {
865
+ fullName: '1KMEW',
866
+ category: ['Meme'],
867
+ symbol: '1KMEW-PERP',
868
+ baseAssetSymbol: '1KMEW',
869
+ marketIndex: 51,
870
+ oracle: new web3_js_1.PublicKey('DKGwCUcwngwmgifGxnme7zVR695LCBGk2pnuksRnbhfD'),
871
+ launchTs: 1729702915000,
872
+ oracleSource: __1.OracleSource.PYTH_1K_PULL,
873
+ pythFeedId: '0x514aed52ca5294177f20187ae883cec4a018619772ddce41efcc36a6448f5d5d',
874
+ },
864
875
  ];
865
876
  exports.PerpMarkets = {
866
877
  devnet: exports.DevnetPerpMarkets,
@@ -9,8 +9,8 @@ exports.DevnetSpotMarkets = [
9
9
  {
10
10
  symbol: 'USDC',
11
11
  marketIndex: 0,
12
- oracle: new web3_js_1.PublicKey('5SSkXsEKQepHHAewytPVwdej4epN1nxgLVM84L4KXgy7'),
13
- oracleSource: __1.OracleSource.PYTH_STABLE_COIN,
12
+ oracle: new web3_js_1.PublicKey('En8hkHLkRe9d9DraYmBTrus518BvmVH448YcvmrFM6Ce'),
13
+ oracleSource: __1.OracleSource.PYTH_STABLE_COIN_PULL,
14
14
  mint: new web3_js_1.PublicKey('8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2'),
15
15
  precision: new __1.BN(10).pow(numericConstants_1.SIX),
16
16
  precisionExp: numericConstants_1.SIX,
@@ -253,8 +253,8 @@ exports.MainnetSpotMarkets = [
253
253
  {
254
254
  symbol: 'dSOL',
255
255
  marketIndex: 17,
256
- oracle: new web3_js_1.PublicKey('HJ9K9AamqVMp86j3uQgpA1tdJNRAwfVuL75FD9P3QBrn'),
257
- oracleSource: __1.OracleSource.SWITCHBOARD,
256
+ oracle: new web3_js_1.PublicKey('7QJ6e57t3yM8HYVg6bAnJiCiZ3wQQ5CSVsa6GA16nJuK'),
257
+ oracleSource: __1.OracleSource.SWITCHBOARD_ON_DEMAND,
258
258
  mint: new web3_js_1.PublicKey('Dso1bDeDjCQxTrWHqUUi63oBvV7Mdm6WaobLbQ7gnPQ'),
259
259
  precision: new __1.BN(10).pow(numericConstants_1.NINE),
260
260
  precisionExp: numericConstants_1.NINE,
@@ -798,9 +798,13 @@ export declare class DriftClient {
798
798
  postSwitchboardOnDemandUpdate(feed: PublicKey, numSignatures?: number): Promise<TransactionSignature>;
799
799
  private getBuildEncodedVaaIxs;
800
800
  enableUserHighLeverageMode(subAccountId: number, txParams?: TxParams): Promise<TransactionSignature>;
801
- getEnableHighLeverageModeIx(subAccountId: number): Promise<anchor.web3.TransactionInstruction>;
801
+ getEnableHighLeverageModeIx(subAccountId: number, depositToTradeArgs?: {
802
+ isMakingNewAccount: boolean;
803
+ depositMarketIndex: number;
804
+ orderMarketIndex: number;
805
+ }): Promise<TransactionInstruction>;
802
806
  disableUserHighLeverageMode(user: PublicKey, userAccount?: UserAccount, txParams?: TxParams): Promise<TransactionSignature>;
803
- getDisableHighLeverageModeIx(user: PublicKey, userAccount?: UserAccount): Promise<anchor.web3.TransactionInstruction>;
807
+ getDisableHighLeverageModeIx(user: PublicKey, userAccount?: UserAccount): Promise<TransactionInstruction>;
804
808
  fetchHighLeverageModeConfig(): Promise<HighLeverageModeConfig>;
805
809
  private handleSignedTransaction;
806
810
  private handlePreSignedTransaction;
@@ -69,6 +69,7 @@ const pyth_solana_receiver_json_1 = __importDefault(require("./idl/pyth_solana_r
69
69
  const on_demand_1 = require("@switchboard-xyz/on-demand");
70
70
  const grpcDriftClientAccountSubscriber_1 = require("./accounts/grpcDriftClientAccountSubscriber");
71
71
  const tweetnacl_1 = __importDefault(require("tweetnacl"));
72
+ const digest_1 = require("./util/digest");
72
73
  /**
73
74
  * # DriftClient
74
75
  * This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
@@ -477,8 +478,8 @@ class DriftClient {
477
478
  this.authority = authority !== null && authority !== void 0 ? authority : this.authority;
478
479
  this.userStatsAccountPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, this.authority);
479
480
  /* If changing the user authority ie switching from delegate to non-delegate account, need to re-subscribe to the user stats account */
480
- if (authorityChanged) {
481
- if (this.userStats && this.userStats.isSubscribed) {
481
+ if (authorityChanged && this.userStats) {
482
+ if (this.userStats.isSubscribed) {
482
483
  await this.userStats.unsubscribe();
483
484
  }
484
485
  this.userStats = new userStats_1.UserStats({
@@ -3006,11 +3007,11 @@ class DriftClient {
3006
3007
  };
3007
3008
  }
3008
3009
  signSwiftServerMessage(message) {
3009
- const swiftServerMessage = Uint8Array.from(this.encodeSwiftServerMessage(message));
3010
+ const swiftServerMessage = Uint8Array.from((0, digest_1.digest)(this.encodeSwiftServerMessage(message)));
3010
3011
  return this.signMessage(swiftServerMessage);
3011
3012
  }
3012
3013
  signSwiftOrderParamsMessage(orderParamsMessage) {
3013
- const takerOrderParamsMessage = Uint8Array.from(this.encodeSwiftOrderParamsMessage(orderParamsMessage));
3014
+ const takerOrderParamsMessage = Uint8Array.from((0, digest_1.digest)(this.encodeSwiftOrderParamsMessage(orderParamsMessage)));
3014
3015
  return this.signMessage(takerOrderParamsMessage);
3015
3016
  }
3016
3017
  encodeSwiftOrderParamsMessage(orderParamsMessage) {
@@ -3036,14 +3037,14 @@ class DriftClient {
3036
3037
  const swiftServerSignatureIx = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
3037
3038
  publicKey: new web3_js_1.PublicKey(this.swiftID).toBytes(),
3038
3039
  signature: Uint8Array.from(swiftSignature),
3039
- message: Uint8Array.from(encodedSwiftServerMessage),
3040
+ message: Uint8Array.from((0, digest_1.digest)(encodedSwiftServerMessage)),
3040
3041
  });
3041
3042
  const swiftOrderParamsSignatureIx = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
3042
3043
  publicKey: takerInfo.takerUserAccount.authority.toBytes(),
3043
3044
  signature: Uint8Array.from(swiftOrderParamsSignature),
3044
- message: Uint8Array.from(encodedSwiftOrderParamsMessage),
3045
+ message: Uint8Array.from((0, digest_1.digest)(encodedSwiftOrderParamsMessage)),
3045
3046
  });
3046
- const placeTakerSwiftPerpOrderIx = await this.program.instruction.placeSwiftTakerOrder(encodedSwiftServerMessage, encodedSwiftOrderParamsMessage, swiftSignature, {
3047
+ const placeTakerSwiftPerpOrderIx = await this.program.instruction.placeSwiftTakerOrder(encodedSwiftServerMessage, encodedSwiftOrderParamsMessage, {
3047
3048
  accounts: {
3048
3049
  state: await this.getStatePublicKey(),
3049
3050
  user: takerInfo.taker,
@@ -4372,9 +4373,17 @@ class DriftClient {
4372
4373
  const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getEnableHighLeverageModeIx(subAccountId), txParams), [], this.opts);
4373
4374
  return txSig;
4374
4375
  }
4375
- async getEnableHighLeverageModeIx(subAccountId) {
4376
+ async getEnableHighLeverageModeIx(subAccountId, depositToTradeArgs) {
4377
+ const isDepositToTradeTx = depositToTradeArgs !== undefined;
4376
4378
  const remainingAccounts = this.getRemainingAccounts({
4377
- userAccounts: [this.getUserAccount(subAccountId)],
4379
+ userAccounts: (depositToTradeArgs === null || depositToTradeArgs === void 0 ? void 0 : depositToTradeArgs.isMakingNewAccount)
4380
+ ? []
4381
+ : [this.getUserAccount(subAccountId)],
4382
+ useMarketLastSlotCache: false,
4383
+ readablePerpMarketIndex: depositToTradeArgs === null || depositToTradeArgs === void 0 ? void 0 : depositToTradeArgs.orderMarketIndex,
4384
+ readableSpotMarketIndexes: isDepositToTradeTx
4385
+ ? [depositToTradeArgs === null || depositToTradeArgs === void 0 ? void 0 : depositToTradeArgs.depositMarketIndex]
4386
+ : undefined,
4378
4387
  });
4379
4388
  const ix = await this.program.instruction.enableUserHighLeverageMode(subAccountId, {
4380
4389
  accounts: {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Commitment, PublicKey, TransactionSignature } from '@solana/web3.js';
3
- import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord } from '../index';
3
+ import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord, SwiftOrderRecord } from '../index';
4
4
  import { EventEmitter } from 'events';
5
5
  export type EventSubscriptionOptions = {
6
6
  address?: PublicKey;
@@ -41,9 +41,10 @@ export type EventMap = {
41
41
  CurveRecord: Event<CurveRecord>;
42
42
  SwapRecord: Event<SwapRecord>;
43
43
  SpotMarketVaultDepositRecord: Event<SpotMarketVaultDepositRecord>;
44
+ SwiftOrderRecord: Event<SwiftOrderRecord>;
44
45
  };
45
46
  export type EventType = keyof EventMap;
46
- export type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord> | Event<SwapRecord> | Event<SpotMarketVaultDepositRecord>;
47
+ export type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord> | Event<SwapRecord> | Event<SpotMarketVaultDepositRecord> | Event<SwiftOrderRecord>;
47
48
  export interface EventSubscriberEvents {
48
49
  newEvent: (event: WrappedEvent<EventType>) => void;
49
50
  }
@@ -18,6 +18,7 @@ exports.DefaultEventSubscriptionOptions = {
18
18
  'CurveRecord',
19
19
  'SwapRecord',
20
20
  'SpotMarketVaultDepositRecord',
21
+ 'SwiftOrderRecord',
21
22
  ],
22
23
  maxEventsPerType: 4096,
23
24
  orderBy: 'blockchain',
@@ -686,15 +686,6 @@
686
686
  {
687
687
  "name": "swiftOrderParamsMessageBytes",
688
688
  "type": "bytes"
689
- },
690
- {
691
- "name": "swiftMessageSignature",
692
- "type": {
693
- "array": [
694
- "u8",
695
- 64
696
- ]
697
- }
698
689
  }
699
690
  ]
700
691
  },
@@ -11529,6 +11520,38 @@
11529
11520
  }
11530
11521
  ]
11531
11522
  },
11523
+ {
11524
+ "name": "SwiftOrderRecord",
11525
+ "fields": [
11526
+ {
11527
+ "name": "user",
11528
+ "type": "publicKey",
11529
+ "index": false
11530
+ },
11531
+ {
11532
+ "name": "hash",
11533
+ "type": "string",
11534
+ "index": false
11535
+ },
11536
+ {
11537
+ "name": "matchingOrderParams",
11538
+ "type": {
11539
+ "defined": "OrderParams"
11540
+ },
11541
+ "index": false
11542
+ },
11543
+ {
11544
+ "name": "swiftOrderSlot",
11545
+ "type": "u64",
11546
+ "index": false
11547
+ },
11548
+ {
11549
+ "name": "userNextOrderId",
11550
+ "type": "u32",
11551
+ "index": false
11552
+ }
11553
+ ]
11554
+ },
11532
11555
  {
11533
11556
  "name": "OrderRecord",
11534
11557
  "fields": [
@@ -201,6 +201,12 @@ export interface QuoteResponse {
201
201
  * @memberof QuoteResponse
202
202
  */
203
203
  error?: string;
204
+ /**
205
+ *
206
+ * @type {string}
207
+ * @memberof QuoteResponse
208
+ */
209
+ errorCode?: string;
204
210
  }
205
211
  export declare class JupiterClient {
206
212
  url: string;
@@ -642,6 +642,14 @@ export type SettlePnlRecord = {
642
642
  settlePrice: BN;
643
643
  explanation: SettlePnlExplanation;
644
644
  };
645
+ export type SwiftOrderRecord = {
646
+ ts: BN;
647
+ user: PublicKey;
648
+ hash: string;
649
+ matchingOrderParams: OrderParams;
650
+ swiftOrderSlot: BN;
651
+ userNextOrderId: number;
652
+ };
645
653
  export type OrderRecord = {
646
654
  ts: BN;
647
655
  user: PublicKey;
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ export declare function digest(data: Buffer): Buffer;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.digest = void 0;
4
+ const crypto_1 = require("crypto");
5
+ function digest(data) {
6
+ const hash = (0, crypto_1.createHash)('sha256');
7
+ hash.update(data);
8
+ return hash.digest();
9
+ }
10
+ exports.digest = digest;
@@ -861,6 +861,17 @@ exports.MainnetPerpMarkets = [
861
861
  launchTs: 1729209600000,
862
862
  oracleSource: __1.OracleSource.Prelaunch,
863
863
  },
864
+ {
865
+ fullName: '1KMEW',
866
+ category: ['Meme'],
867
+ symbol: '1KMEW-PERP',
868
+ baseAssetSymbol: '1KMEW',
869
+ marketIndex: 51,
870
+ oracle: new web3_js_1.PublicKey('DKGwCUcwngwmgifGxnme7zVR695LCBGk2pnuksRnbhfD'),
871
+ launchTs: 1729702915000,
872
+ oracleSource: __1.OracleSource.PYTH_1K_PULL,
873
+ pythFeedId: '0x514aed52ca5294177f20187ae883cec4a018619772ddce41efcc36a6448f5d5d',
874
+ },
864
875
  ];
865
876
  exports.PerpMarkets = {
866
877
  devnet: exports.DevnetPerpMarkets,
@@ -9,8 +9,8 @@ exports.DevnetSpotMarkets = [
9
9
  {
10
10
  symbol: 'USDC',
11
11
  marketIndex: 0,
12
- oracle: new web3_js_1.PublicKey('5SSkXsEKQepHHAewytPVwdej4epN1nxgLVM84L4KXgy7'),
13
- oracleSource: __1.OracleSource.PYTH_STABLE_COIN,
12
+ oracle: new web3_js_1.PublicKey('En8hkHLkRe9d9DraYmBTrus518BvmVH448YcvmrFM6Ce'),
13
+ oracleSource: __1.OracleSource.PYTH_STABLE_COIN_PULL,
14
14
  mint: new web3_js_1.PublicKey('8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2'),
15
15
  precision: new __1.BN(10).pow(numericConstants_1.SIX),
16
16
  precisionExp: numericConstants_1.SIX,
@@ -253,8 +253,8 @@ exports.MainnetSpotMarkets = [
253
253
  {
254
254
  symbol: 'dSOL',
255
255
  marketIndex: 17,
256
- oracle: new web3_js_1.PublicKey('HJ9K9AamqVMp86j3uQgpA1tdJNRAwfVuL75FD9P3QBrn'),
257
- oracleSource: __1.OracleSource.SWITCHBOARD,
256
+ oracle: new web3_js_1.PublicKey('7QJ6e57t3yM8HYVg6bAnJiCiZ3wQQ5CSVsa6GA16nJuK'),
257
+ oracleSource: __1.OracleSource.SWITCHBOARD_ON_DEMAND,
258
258
  mint: new web3_js_1.PublicKey('Dso1bDeDjCQxTrWHqUUi63oBvV7Mdm6WaobLbQ7gnPQ'),
259
259
  precision: new __1.BN(10).pow(numericConstants_1.NINE),
260
260
  precisionExp: numericConstants_1.NINE,
@@ -798,9 +798,13 @@ export declare class DriftClient {
798
798
  postSwitchboardOnDemandUpdate(feed: PublicKey, numSignatures?: number): Promise<TransactionSignature>;
799
799
  private getBuildEncodedVaaIxs;
800
800
  enableUserHighLeverageMode(subAccountId: number, txParams?: TxParams): Promise<TransactionSignature>;
801
- getEnableHighLeverageModeIx(subAccountId: number): Promise<anchor.web3.TransactionInstruction>;
801
+ getEnableHighLeverageModeIx(subAccountId: number, depositToTradeArgs?: {
802
+ isMakingNewAccount: boolean;
803
+ depositMarketIndex: number;
804
+ orderMarketIndex: number;
805
+ }): Promise<TransactionInstruction>;
802
806
  disableUserHighLeverageMode(user: PublicKey, userAccount?: UserAccount, txParams?: TxParams): Promise<TransactionSignature>;
803
- getDisableHighLeverageModeIx(user: PublicKey, userAccount?: UserAccount): Promise<anchor.web3.TransactionInstruction>;
807
+ getDisableHighLeverageModeIx(user: PublicKey, userAccount?: UserAccount): Promise<TransactionInstruction>;
804
808
  fetchHighLeverageModeConfig(): Promise<HighLeverageModeConfig>;
805
809
  private handleSignedTransaction;
806
810
  private handlePreSignedTransaction;
@@ -69,6 +69,7 @@ const pyth_solana_receiver_json_1 = __importDefault(require("./idl/pyth_solana_r
69
69
  const on_demand_1 = require("@switchboard-xyz/on-demand");
70
70
  const grpcDriftClientAccountSubscriber_1 = require("./accounts/grpcDriftClientAccountSubscriber");
71
71
  const tweetnacl_1 = __importDefault(require("tweetnacl"));
72
+ const digest_1 = require("./util/digest");
72
73
  /**
73
74
  * # DriftClient
74
75
  * This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
@@ -477,8 +478,8 @@ class DriftClient {
477
478
  this.authority = authority !== null && authority !== void 0 ? authority : this.authority;
478
479
  this.userStatsAccountPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, this.authority);
479
480
  /* If changing the user authority ie switching from delegate to non-delegate account, need to re-subscribe to the user stats account */
480
- if (authorityChanged) {
481
- if (this.userStats && this.userStats.isSubscribed) {
481
+ if (authorityChanged && this.userStats) {
482
+ if (this.userStats.isSubscribed) {
482
483
  await this.userStats.unsubscribe();
483
484
  }
484
485
  this.userStats = new userStats_1.UserStats({
@@ -3006,11 +3007,11 @@ class DriftClient {
3006
3007
  };
3007
3008
  }
3008
3009
  signSwiftServerMessage(message) {
3009
- const swiftServerMessage = Uint8Array.from(this.encodeSwiftServerMessage(message));
3010
+ const swiftServerMessage = Uint8Array.from((0, digest_1.digest)(this.encodeSwiftServerMessage(message)));
3010
3011
  return this.signMessage(swiftServerMessage);
3011
3012
  }
3012
3013
  signSwiftOrderParamsMessage(orderParamsMessage) {
3013
- const takerOrderParamsMessage = Uint8Array.from(this.encodeSwiftOrderParamsMessage(orderParamsMessage));
3014
+ const takerOrderParamsMessage = Uint8Array.from((0, digest_1.digest)(this.encodeSwiftOrderParamsMessage(orderParamsMessage)));
3014
3015
  return this.signMessage(takerOrderParamsMessage);
3015
3016
  }
3016
3017
  encodeSwiftOrderParamsMessage(orderParamsMessage) {
@@ -3036,14 +3037,14 @@ class DriftClient {
3036
3037
  const swiftServerSignatureIx = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
3037
3038
  publicKey: new web3_js_1.PublicKey(this.swiftID).toBytes(),
3038
3039
  signature: Uint8Array.from(swiftSignature),
3039
- message: Uint8Array.from(encodedSwiftServerMessage),
3040
+ message: Uint8Array.from((0, digest_1.digest)(encodedSwiftServerMessage)),
3040
3041
  });
3041
3042
  const swiftOrderParamsSignatureIx = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
3042
3043
  publicKey: takerInfo.takerUserAccount.authority.toBytes(),
3043
3044
  signature: Uint8Array.from(swiftOrderParamsSignature),
3044
- message: Uint8Array.from(encodedSwiftOrderParamsMessage),
3045
+ message: Uint8Array.from((0, digest_1.digest)(encodedSwiftOrderParamsMessage)),
3045
3046
  });
3046
- const placeTakerSwiftPerpOrderIx = await this.program.instruction.placeSwiftTakerOrder(encodedSwiftServerMessage, encodedSwiftOrderParamsMessage, swiftSignature, {
3047
+ const placeTakerSwiftPerpOrderIx = await this.program.instruction.placeSwiftTakerOrder(encodedSwiftServerMessage, encodedSwiftOrderParamsMessage, {
3047
3048
  accounts: {
3048
3049
  state: await this.getStatePublicKey(),
3049
3050
  user: takerInfo.taker,
@@ -4372,9 +4373,17 @@ class DriftClient {
4372
4373
  const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getEnableHighLeverageModeIx(subAccountId), txParams), [], this.opts);
4373
4374
  return txSig;
4374
4375
  }
4375
- async getEnableHighLeverageModeIx(subAccountId) {
4376
+ async getEnableHighLeverageModeIx(subAccountId, depositToTradeArgs) {
4377
+ const isDepositToTradeTx = depositToTradeArgs !== undefined;
4376
4378
  const remainingAccounts = this.getRemainingAccounts({
4377
- userAccounts: [this.getUserAccount(subAccountId)],
4379
+ userAccounts: (depositToTradeArgs === null || depositToTradeArgs === void 0 ? void 0 : depositToTradeArgs.isMakingNewAccount)
4380
+ ? []
4381
+ : [this.getUserAccount(subAccountId)],
4382
+ useMarketLastSlotCache: false,
4383
+ readablePerpMarketIndex: depositToTradeArgs === null || depositToTradeArgs === void 0 ? void 0 : depositToTradeArgs.orderMarketIndex,
4384
+ readableSpotMarketIndexes: isDepositToTradeTx
4385
+ ? [depositToTradeArgs === null || depositToTradeArgs === void 0 ? void 0 : depositToTradeArgs.depositMarketIndex]
4386
+ : undefined,
4378
4387
  });
4379
4388
  const ix = await this.program.instruction.enableUserHighLeverageMode(subAccountId, {
4380
4389
  accounts: {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Commitment, PublicKey, TransactionSignature } from '@solana/web3.js';
3
- import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord } from '../index';
3
+ import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord, SwiftOrderRecord } from '../index';
4
4
  import { EventEmitter } from 'events';
5
5
  export type EventSubscriptionOptions = {
6
6
  address?: PublicKey;
@@ -41,9 +41,10 @@ export type EventMap = {
41
41
  CurveRecord: Event<CurveRecord>;
42
42
  SwapRecord: Event<SwapRecord>;
43
43
  SpotMarketVaultDepositRecord: Event<SpotMarketVaultDepositRecord>;
44
+ SwiftOrderRecord: Event<SwiftOrderRecord>;
44
45
  };
45
46
  export type EventType = keyof EventMap;
46
- export type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord> | Event<SwapRecord> | Event<SpotMarketVaultDepositRecord>;
47
+ export type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord> | Event<SwapRecord> | Event<SpotMarketVaultDepositRecord> | Event<SwiftOrderRecord>;
47
48
  export interface EventSubscriberEvents {
48
49
  newEvent: (event: WrappedEvent<EventType>) => void;
49
50
  }
@@ -18,6 +18,7 @@ exports.DefaultEventSubscriptionOptions = {
18
18
  'CurveRecord',
19
19
  'SwapRecord',
20
20
  'SpotMarketVaultDepositRecord',
21
+ 'SwiftOrderRecord',
21
22
  ],
22
23
  maxEventsPerType: 4096,
23
24
  orderBy: 'blockchain',
@@ -686,15 +686,6 @@
686
686
  {
687
687
  "name": "swiftOrderParamsMessageBytes",
688
688
  "type": "bytes"
689
- },
690
- {
691
- "name": "swiftMessageSignature",
692
- "type": {
693
- "array": [
694
- "u8",
695
- 64
696
- ]
697
- }
698
689
  }
699
690
  ]
700
691
  },
@@ -11529,6 +11520,38 @@
11529
11520
  }
11530
11521
  ]
11531
11522
  },
11523
+ {
11524
+ "name": "SwiftOrderRecord",
11525
+ "fields": [
11526
+ {
11527
+ "name": "user",
11528
+ "type": "publicKey",
11529
+ "index": false
11530
+ },
11531
+ {
11532
+ "name": "hash",
11533
+ "type": "string",
11534
+ "index": false
11535
+ },
11536
+ {
11537
+ "name": "matchingOrderParams",
11538
+ "type": {
11539
+ "defined": "OrderParams"
11540
+ },
11541
+ "index": false
11542
+ },
11543
+ {
11544
+ "name": "swiftOrderSlot",
11545
+ "type": "u64",
11546
+ "index": false
11547
+ },
11548
+ {
11549
+ "name": "userNextOrderId",
11550
+ "type": "u32",
11551
+ "index": false
11552
+ }
11553
+ ]
11554
+ },
11532
11555
  {
11533
11556
  "name": "OrderRecord",
11534
11557
  "fields": [
@@ -201,6 +201,12 @@ export interface QuoteResponse {
201
201
  * @memberof QuoteResponse
202
202
  */
203
203
  error?: string;
204
+ /**
205
+ *
206
+ * @type {string}
207
+ * @memberof QuoteResponse
208
+ */
209
+ errorCode?: string;
204
210
  }
205
211
  export declare class JupiterClient {
206
212
  url: string;
@@ -642,6 +642,14 @@ export type SettlePnlRecord = {
642
642
  settlePrice: BN;
643
643
  explanation: SettlePnlExplanation;
644
644
  };
645
+ export type SwiftOrderRecord = {
646
+ ts: BN;
647
+ user: PublicKey;
648
+ hash: string;
649
+ matchingOrderParams: OrderParams;
650
+ swiftOrderSlot: BN;
651
+ userNextOrderId: number;
652
+ };
645
653
  export type OrderRecord = {
646
654
  ts: BN;
647
655
  user: PublicKey;
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ export declare function digest(data: Buffer): Buffer;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.digest = void 0;
4
+ const crypto_1 = require("crypto");
5
+ function digest(data) {
6
+ const hash = (0, crypto_1.createHash)('sha256');
7
+ hash.update(data);
8
+ return hash.digest();
9
+ }
10
+ exports.digest = digest;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.98.0-beta.0",
3
+ "version": "2.98.0-beta.10",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "browser": "./lib/browser/index.js",
@@ -938,6 +938,18 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
938
938
  launchTs: 1729209600000,
939
939
  oracleSource: OracleSource.Prelaunch,
940
940
  },
941
+ {
942
+ fullName: '1KMEW',
943
+ category: ['Meme'],
944
+ symbol: '1KMEW-PERP',
945
+ baseAssetSymbol: '1KMEW',
946
+ marketIndex: 51,
947
+ oracle: new PublicKey('DKGwCUcwngwmgifGxnme7zVR695LCBGk2pnuksRnbhfD'),
948
+ launchTs: 1729702915000,
949
+ oracleSource: OracleSource.PYTH_1K_PULL,
950
+ pythFeedId:
951
+ '0x514aed52ca5294177f20187ae883cec4a018619772ddce41efcc36a6448f5d5d',
952
+ },
941
953
  ];
942
954
 
943
955
  export const PerpMarkets: { [key in DriftEnv]: PerpMarketConfig[] } = {
@@ -33,8 +33,8 @@ export const DevnetSpotMarkets: SpotMarketConfig[] = [
33
33
  {
34
34
  symbol: 'USDC',
35
35
  marketIndex: 0,
36
- oracle: new PublicKey('5SSkXsEKQepHHAewytPVwdej4epN1nxgLVM84L4KXgy7'),
37
- oracleSource: OracleSource.PYTH_STABLE_COIN,
36
+ oracle: new PublicKey('En8hkHLkRe9d9DraYmBTrus518BvmVH448YcvmrFM6Ce'),
37
+ oracleSource: OracleSource.PYTH_STABLE_COIN_PULL,
38
38
  mint: new PublicKey('8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2'),
39
39
  precision: new BN(10).pow(SIX),
40
40
  precisionExp: SIX,
@@ -325,8 +325,8 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
325
325
  {
326
326
  symbol: 'dSOL',
327
327
  marketIndex: 17,
328
- oracle: new PublicKey('HJ9K9AamqVMp86j3uQgpA1tdJNRAwfVuL75FD9P3QBrn'),
329
- oracleSource: OracleSource.SWITCHBOARD,
328
+ oracle: new PublicKey('7QJ6e57t3yM8HYVg6bAnJiCiZ3wQQ5CSVsa6GA16nJuK'),
329
+ oracleSource: OracleSource.SWITCHBOARD_ON_DEMAND,
330
330
  mint: new PublicKey('Dso1bDeDjCQxTrWHqUUi63oBvV7Mdm6WaobLbQ7gnPQ'),
331
331
  precision: new BN(10).pow(NINE),
332
332
  precisionExp: NINE,
@@ -169,6 +169,7 @@ import pythSolanaReceiverIdl from './idl/pyth_solana_receiver.json';
169
169
  import { asV0Tx, PullFeed } from '@switchboard-xyz/on-demand';
170
170
  import { gprcDriftClientAccountSubscriber } from './accounts/grpcDriftClientAccountSubscriber';
171
171
  import nacl from 'tweetnacl';
172
+ import { digest } from './util/digest';
172
173
 
173
174
  type RemainingAccountParams = {
174
175
  userAccounts: UserAccount[];
@@ -827,8 +828,8 @@ export class DriftClient {
827
828
  );
828
829
 
829
830
  /* If changing the user authority ie switching from delegate to non-delegate account, need to re-subscribe to the user stats account */
830
- if (authorityChanged) {
831
- if (this.userStats && this.userStats.isSubscribed) {
831
+ if (authorityChanged && this.userStats) {
832
+ if (this.userStats.isSubscribed) {
832
833
  await this.userStats.unsubscribe();
833
834
  }
834
835
 
@@ -5545,7 +5546,7 @@ export class DriftClient {
5545
5546
 
5546
5547
  public signSwiftServerMessage(message: SwiftServerMessage): Buffer {
5547
5548
  const swiftServerMessage = Uint8Array.from(
5548
- this.encodeSwiftServerMessage(message)
5549
+ digest(this.encodeSwiftServerMessage(message))
5549
5550
  );
5550
5551
  return this.signMessage(swiftServerMessage);
5551
5552
  }
@@ -5554,7 +5555,7 @@ export class DriftClient {
5554
5555
  orderParamsMessage: SwiftOrderParamsMessage
5555
5556
  ): Buffer {
5556
5557
  const takerOrderParamsMessage = Uint8Array.from(
5557
- this.encodeSwiftOrderParamsMessage(orderParamsMessage)
5558
+ digest(this.encodeSwiftOrderParamsMessage(orderParamsMessage))
5558
5559
  );
5559
5560
  return this.signMessage(takerOrderParamsMessage);
5560
5561
  }
@@ -5635,21 +5636,20 @@ export class DriftClient {
5635
5636
  Ed25519Program.createInstructionWithPublicKey({
5636
5637
  publicKey: new PublicKey(this.swiftID).toBytes(),
5637
5638
  signature: Uint8Array.from(swiftSignature),
5638
- message: Uint8Array.from(encodedSwiftServerMessage),
5639
+ message: Uint8Array.from(digest(encodedSwiftServerMessage)),
5639
5640
  });
5640
5641
 
5641
5642
  const swiftOrderParamsSignatureIx =
5642
5643
  Ed25519Program.createInstructionWithPublicKey({
5643
5644
  publicKey: takerInfo.takerUserAccount.authority.toBytes(),
5644
5645
  signature: Uint8Array.from(swiftOrderParamsSignature),
5645
- message: Uint8Array.from(encodedSwiftOrderParamsMessage),
5646
+ message: Uint8Array.from(digest(encodedSwiftOrderParamsMessage)),
5646
5647
  });
5647
5648
 
5648
5649
  const placeTakerSwiftPerpOrderIx =
5649
5650
  await this.program.instruction.placeSwiftTakerOrder(
5650
5651
  encodedSwiftServerMessage,
5651
5652
  encodedSwiftOrderParamsMessage,
5652
- swiftSignature,
5653
5653
  {
5654
5654
  accounts: {
5655
5655
  state: await this.getStatePublicKey(),
@@ -8300,9 +8300,25 @@ export class DriftClient {
8300
8300
  return txSig;
8301
8301
  }
8302
8302
 
8303
- public async getEnableHighLeverageModeIx(subAccountId: number) {
8303
+ public async getEnableHighLeverageModeIx(
8304
+ subAccountId: number,
8305
+ depositToTradeArgs?: {
8306
+ isMakingNewAccount: boolean;
8307
+ depositMarketIndex: number;
8308
+ orderMarketIndex: number;
8309
+ }
8310
+ ): Promise<TransactionInstruction> {
8311
+ const isDepositToTradeTx = depositToTradeArgs !== undefined;
8312
+
8304
8313
  const remainingAccounts = this.getRemainingAccounts({
8305
- userAccounts: [this.getUserAccount(subAccountId)],
8314
+ userAccounts: depositToTradeArgs?.isMakingNewAccount
8315
+ ? []
8316
+ : [this.getUserAccount(subAccountId)],
8317
+ useMarketLastSlotCache: false,
8318
+ readablePerpMarketIndex: depositToTradeArgs?.orderMarketIndex,
8319
+ readableSpotMarketIndexes: isDepositToTradeTx
8320
+ ? [depositToTradeArgs?.depositMarketIndex]
8321
+ : undefined,
8306
8322
  });
8307
8323
 
8308
8324
  const ix = await this.program.instruction.enableUserHighLeverageMode(
@@ -8346,7 +8362,7 @@ export class DriftClient {
8346
8362
  public async getDisableHighLeverageModeIx(
8347
8363
  user: PublicKey,
8348
8364
  userAccount?: UserAccount
8349
- ) {
8365
+ ): Promise<TransactionInstruction> {
8350
8366
  const remainingAccounts = userAccount
8351
8367
  ? this.getRemainingAccounts({
8352
8368
  userAccounts: [userAccount],
@@ -15,6 +15,7 @@ import {
15
15
  CurveRecord,
16
16
  SwapRecord,
17
17
  SpotMarketVaultDepositRecord,
18
+ SwiftOrderRecord,
18
19
  } from '../index';
19
20
  import { EventEmitter } from 'events';
20
21
 
@@ -49,6 +50,7 @@ export const DefaultEventSubscriptionOptions: EventSubscriptionOptions = {
49
50
  'CurveRecord',
50
51
  'SwapRecord',
51
52
  'SpotMarketVaultDepositRecord',
53
+ 'SwiftOrderRecord',
52
54
  ],
53
55
  maxEventsPerType: 4096,
54
56
  orderBy: 'blockchain',
@@ -92,6 +94,7 @@ export type EventMap = {
92
94
  CurveRecord: Event<CurveRecord>;
93
95
  SwapRecord: Event<SwapRecord>;
94
96
  SpotMarketVaultDepositRecord: Event<SpotMarketVaultDepositRecord>;
97
+ SwiftOrderRecord: Event<SwiftOrderRecord>;
95
98
  };
96
99
 
97
100
  export type EventType = keyof EventMap;
@@ -111,7 +114,8 @@ export type DriftEvent =
111
114
  | Event<InsuranceFundStakeRecord>
112
115
  | Event<CurveRecord>
113
116
  | Event<SwapRecord>
114
- | Event<SpotMarketVaultDepositRecord>;
117
+ | Event<SpotMarketVaultDepositRecord>
118
+ | Event<SwiftOrderRecord>;
115
119
 
116
120
  export interface EventSubscriberEvents {
117
121
  newEvent: (event: WrappedEvent<EventType>) => void;
@@ -686,15 +686,6 @@
686
686
  {
687
687
  "name": "swiftOrderParamsMessageBytes",
688
688
  "type": "bytes"
689
- },
690
- {
691
- "name": "swiftMessageSignature",
692
- "type": {
693
- "array": [
694
- "u8",
695
- 64
696
- ]
697
- }
698
689
  }
699
690
  ]
700
691
  },
@@ -11529,6 +11520,38 @@
11529
11520
  }
11530
11521
  ]
11531
11522
  },
11523
+ {
11524
+ "name": "SwiftOrderRecord",
11525
+ "fields": [
11526
+ {
11527
+ "name": "user",
11528
+ "type": "publicKey",
11529
+ "index": false
11530
+ },
11531
+ {
11532
+ "name": "hash",
11533
+ "type": "string",
11534
+ "index": false
11535
+ },
11536
+ {
11537
+ "name": "matchingOrderParams",
11538
+ "type": {
11539
+ "defined": "OrderParams"
11540
+ },
11541
+ "index": false
11542
+ },
11543
+ {
11544
+ "name": "swiftOrderSlot",
11545
+ "type": "u64",
11546
+ "index": false
11547
+ },
11548
+ {
11549
+ "name": "userNextOrderId",
11550
+ "type": "u32",
11551
+ "index": false
11552
+ }
11553
+ ]
11554
+ },
11532
11555
  {
11533
11556
  "name": "OrderRecord",
11534
11557
  "fields": [
@@ -216,6 +216,12 @@ export interface QuoteResponse {
216
216
  * @memberof QuoteResponse
217
217
  */
218
218
  error?: string;
219
+ /**
220
+ *
221
+ * @type {string}
222
+ * @memberof QuoteResponse
223
+ */
224
+ errorCode?: string;
219
225
  }
220
226
 
221
227
  export class JupiterClient {
package/src/types.ts CHANGED
@@ -541,6 +541,15 @@ export type SettlePnlRecord = {
541
541
  explanation: SettlePnlExplanation;
542
542
  };
543
543
 
544
+ export type SwiftOrderRecord = {
545
+ ts: BN;
546
+ user: PublicKey;
547
+ hash: string;
548
+ matchingOrderParams: OrderParams;
549
+ swiftOrderSlot: BN;
550
+ userNextOrderId: number;
551
+ };
552
+
544
553
  export type OrderRecord = {
545
554
  ts: BN;
546
555
  user: PublicKey;
@@ -0,0 +1,7 @@
1
+ import { createHash } from 'crypto';
2
+
3
+ export function digest(data: Buffer): Buffer {
4
+ const hash = createHash('sha256');
5
+ hash.update(data);
6
+ return hash.digest();
7
+ }