@drift-labs/sdk 2.153.0-beta.0 → 2.153.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.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.153.0-beta.0
1
+ 2.153.0-beta.1
@@ -1,4 +1,3 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
2
  export declare const NOT_CONFIRMED_ERROR_CODE = -1001;
3
3
  export declare const FUEL_RESET_LOG_ACCOUNT: PublicKey;
4
- export declare const DEFAULT_COMMITMENT_LEVEL = "confirmed";
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_COMMITMENT_LEVEL = exports.FUEL_RESET_LOG_ACCOUNT = exports.NOT_CONFIRMED_ERROR_CODE = void 0;
3
+ exports.FUEL_RESET_LOG_ACCOUNT = exports.NOT_CONFIRMED_ERROR_CODE = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
5
  exports.NOT_CONFIRMED_ERROR_CODE = -1001;
6
6
  exports.FUEL_RESET_LOG_ACCOUNT = new web3_js_1.PublicKey('FuE1gqp2fzw2sDNLrbZqKsqpphJcoSW6HPaSJjGd4RZ4');
7
- exports.DEFAULT_COMMITMENT_LEVEL = 'confirmed';
@@ -998,9 +998,9 @@ export declare class DriftClient {
998
998
  settleFundingPayment(userAccountPublicKey: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
999
999
  getSettleFundingPaymentIx(userAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
1000
1000
  triggerEvent(eventName: keyof DriftClientAccountEvents, data?: any): void;
1001
- getOracleDataForPerpMarket(marketIndex: number): OraclePriceData | undefined;
1002
- getMMOracleDataForPerpMarket(marketIndex: number): MMOraclePriceData | undefined;
1003
- getOracleDataForSpotMarket(marketIndex: number): OraclePriceData | undefined;
1001
+ getOracleDataForPerpMarket(marketIndex: number): OraclePriceData;
1002
+ getMMOracleDataForPerpMarket(marketIndex: number): MMOraclePriceData;
1003
+ getOracleDataForSpotMarket(marketIndex: number): OraclePriceData;
1004
1004
  initializeInsuranceFundStake(marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
1005
1005
  getInitializeInsuranceFundStakeIx(marketIndex: number): Promise<TransactionInstruction>;
1006
1006
  getAddInsuranceFundStakeIx(marketIndex: number, amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
@@ -1069,7 +1069,7 @@ export declare class DriftClient {
1069
1069
  * @returns
1070
1070
  */
1071
1071
  depositIntoSpotMarketRevenuePool(marketIndex: number, amount: BN, userTokenAccountPublicKey: PublicKey): Promise<TransactionSignature>;
1072
- getPerpMarketExtendedInfo(marketIndex: number): PerpMarketExtendedInfo | undefined;
1072
+ getPerpMarketExtendedInfo(marketIndex: number): PerpMarketExtendedInfo;
1073
1073
  /**
1074
1074
  * Calculates taker / maker fee (as a percentage, e.g. .001 = 10 basis points) for particular marketType
1075
1075
  * @param marketType
@@ -1091,7 +1091,7 @@ export declare class DriftClient {
1091
1091
  marketType: MarketType;
1092
1092
  } | undefined;
1093
1093
  getReceiverProgram(): Program<PythSolanaReceiver>;
1094
- getSwitchboardOnDemandProgram(): Promise<Program30<Idl30> | undefined>;
1094
+ getSwitchboardOnDemandProgram(): Promise<Program30<Idl30>>;
1095
1095
  postPythPullOracleUpdateAtomic(vaaString: string, feedId: string): Promise<TransactionSignature>;
1096
1096
  postMultiPythPullOracleUpdatesAtomic(vaaString: string, feedIds: string[]): Promise<TransactionSignature>;
1097
1097
  getPostPythPullOracleUpdateAtomicIxs(vaaString: string, feedIds: string | string[], numSignatures?: number): Promise<TransactionInstruction[]>;
@@ -1107,7 +1107,7 @@ export declare class DriftClient {
1107
1107
  getPostPythLazerOracleUpdateIxs(feedIds: number[], pythMessageHex: string, precedingIxs?: TransactionInstruction[], overrideCustomIxIndex?: number): Promise<TransactionInstruction[]>;
1108
1108
  getPostManySwitchboardOnDemandUpdatesAtomicIxs(feeds: PublicKey[], recentSlothash?: Slothash, numSignatures?: number): Promise<TransactionInstruction[] | undefined>;
1109
1109
  getPostSwitchboardOnDemandUpdateAtomicIx(feed: PublicKey, recentSlothash?: Slothash, numSignatures?: number): Promise<TransactionInstruction | undefined>;
1110
- postSwitchboardOnDemandUpdate(feed: PublicKey, recentSlothash?: Slothash, numSignatures?: number): Promise<TransactionSignature | undefined>;
1110
+ postSwitchboardOnDemandUpdate(feed: PublicKey, recentSlothash?: Slothash, numSignatures?: number): Promise<TransactionSignature>;
1111
1111
  private getBuildEncodedVaaIxs;
1112
1112
  enableUserHighLeverageMode(subAccountId: number, txParams?: TxParams): Promise<TransactionSignature>;
1113
1113
  getEnableHighLeverageModeIx(subAccountId: number, depositToTradeArgs?: {
@@ -77,7 +77,6 @@ const orders_1 = require("./math/orders");
77
77
  const builder_1 = require("./math/builder");
78
78
  const titanClient_1 = require("./titan/titanClient");
79
79
  const UnifiedSwapClient_1 = require("./swap/UnifiedSwapClient");
80
- const constants_1 = require("./constants");
81
80
  /**
82
81
  * # DriftClient
83
82
  * 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.
@@ -197,12 +196,14 @@ class DriftClient {
197
196
  accountSubscription: this.userAccountSubscriptionConfig,
198
197
  });
199
198
  }
200
- this.marketLookupTable = config.marketLookupTable
201
- ? config.marketLookupTable
202
- : (this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[this.env].MARKET_LOOKUP_TABLE));
203
- this.marketLookupTables = config.marketLookupTables
204
- ? config.marketLookupTables
205
- : config_1.configs[this.env].MARKET_LOOKUP_TABLES.map((tableAddr) => new web3_js_1.PublicKey(tableAddr));
199
+ this.marketLookupTable = config.marketLookupTable;
200
+ if (!this.marketLookupTable) {
201
+ this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[this.env].MARKET_LOOKUP_TABLE);
202
+ }
203
+ this.marketLookupTables = config.marketLookupTables;
204
+ if (!this.marketLookupTables) {
205
+ this.marketLookupTables = config_1.configs[this.env].MARKET_LOOKUP_TABLES.map((tableAddr) => new web3_js_1.PublicKey(tableAddr));
206
+ }
206
207
  const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Unsubscribe;
207
208
  const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
208
209
  config.spotMarketIndexes === undefined &&
@@ -4746,12 +4747,8 @@ class DriftClient {
4746
4747
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
4747
4748
  const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
4748
4749
  const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
4749
- const liquidatorUser = this.getUserAccount(liquidatorSubAccountId);
4750
- if (!liquidatorUser) {
4751
- throw new Error(`Liquidator user account not found for subaccount id ${liquidatorSubAccountId}`);
4752
- }
4753
4750
  const remainingAccounts = this.getRemainingAccounts({
4754
- userAccounts: [liquidatorUser, userAccount],
4751
+ userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
4755
4752
  useMarketLastSlotCache: true,
4756
4753
  writableSpotMarketIndexes: [liabilityMarketIndex, assetMarketIndex],
4757
4754
  });
@@ -4769,13 +4766,7 @@ class DriftClient {
4769
4766
  }
4770
4767
  async getJupiterLiquidateSpotWithSwapIxV6({ jupiterClient, liabilityMarketIndex, assetMarketIndex, swapAmount, assetTokenAccount, liabilityTokenAccount, slippageBps, swapMode, onlyDirectRoutes, quote, userAccount, userAccountPublicKey, userStatsAccountPublicKey, liquidatorSubAccountId, maxAccounts, }) {
4771
4768
  const liabilityMarket = this.getSpotMarketAccount(liabilityMarketIndex);
4772
- if (!liabilityMarket) {
4773
- throw new Error(`Liability spot market account not found for index ${liabilityMarketIndex}`);
4774
- }
4775
4769
  const assetMarket = this.getSpotMarketAccount(assetMarketIndex);
4776
- if (!assetMarket) {
4777
- throw new Error(`Asset spot market account not found for index ${assetMarketIndex}`);
4778
- }
4779
4770
  if (!quote) {
4780
4771
  const fetchedQuote = await jupiterClient.getQuote({
4781
4772
  inputMint: assetMarket.mint,
@@ -4857,13 +4848,7 @@ class DriftClient {
4857
4848
  readableSpotMarketIndexes: [numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
4858
4849
  });
4859
4850
  const liabilitySpotMarket = this.getSpotMarketAccount(liabilityMarketIndex);
4860
- if (!liabilitySpotMarket) {
4861
- throw new Error(`Liability spot market account not found for index ${liabilityMarketIndex}`);
4862
- }
4863
4851
  const assetSpotMarket = this.getSpotMarketAccount(assetMarketIndex);
4864
- if (!assetSpotMarket) {
4865
- throw new Error(`Asset spot market account not found for index ${assetMarketIndex}`);
4866
- }
4867
4852
  const liabilityTokenProgram = this.getTokenProgramForSpotMarket(liabilitySpotMarket);
4868
4853
  const assetTokenProgram = this.getTokenProgramForSpotMarket(assetSpotMarket);
4869
4854
  if (!liabilityTokenProgram.equals(assetTokenProgram)) {
@@ -4936,13 +4921,7 @@ class DriftClient {
4936
4921
  writableSpotMarketIndexes: [inMarketIndex, outMarketIndex],
4937
4922
  });
4938
4923
  const inSpotMarket = this.getSpotMarketAccount(inMarketIndex);
4939
- if (!inSpotMarket) {
4940
- throw new Error(`In spot market account not found for index ${inMarketIndex}`);
4941
- }
4942
4924
  const outSpotMarket = this.getSpotMarketAccount(outMarketIndex);
4943
- if (!outSpotMarket) {
4944
- throw new Error(`Out spot market account not found for index ${outMarketIndex}`);
4945
- }
4946
4925
  if (this.isToken2022(inSpotMarket) || this.isToken2022(outSpotMarket)) {
4947
4926
  remainingAccounts.push({
4948
4927
  pubkey: inSpotMarket.mint,
@@ -5004,12 +4983,8 @@ class DriftClient {
5004
4983
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
5005
4984
  const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
5006
4985
  const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
5007
- const liquidatorUser = this.getUserAccount(liquidatorSubAccountId);
5008
- if (!liquidatorUser) {
5009
- throw new Error(`Liquidator user account not found for subaccount id ${liquidatorSubAccountId}`);
5010
- }
5011
4986
  const remainingAccounts = this.getRemainingAccounts({
5012
- userAccounts: [liquidatorUser, userAccount],
4987
+ userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
5013
4988
  writablePerpMarketIndexes: [perpMarketIndex],
5014
4989
  writableSpotMarketIndexes: [liabilityMarketIndex],
5015
4990
  });
@@ -5035,12 +5010,8 @@ class DriftClient {
5035
5010
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
5036
5011
  const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
5037
5012
  const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
5038
- const liquidatorUser = this.getUserAccount(liquidatorSubAccountId);
5039
- if (!liquidatorUser) {
5040
- throw new Error(`Liquidator user account not found for subaccount id ${liquidatorSubAccountId}`);
5041
- }
5042
5013
  const remainingAccounts = this.getRemainingAccounts({
5043
- userAccounts: [liquidatorUser, userAccount],
5014
+ userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
5044
5015
  writablePerpMarketIndexes: [perpMarketIndex],
5045
5016
  writableSpotMarketIndexes: [assetMarketIndex],
5046
5017
  });
@@ -5064,12 +5035,8 @@ class DriftClient {
5064
5035
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
5065
5036
  const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
5066
5037
  const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
5067
- const liquidatorUser = this.getUserAccount(liquidatorSubAccountId);
5068
- if (!liquidatorUser) {
5069
- throw new Error(`Liquidator user account not found for subaccount id ${liquidatorSubAccountId}`);
5070
- }
5071
5038
  const remainingAccounts = this.getRemainingAccounts({
5072
- userAccounts: [liquidatorUser, userAccount],
5039
+ userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
5073
5040
  writablePerpMarketIndexes: [marketIndex],
5074
5041
  writableSpotMarketIndexes: [numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
5075
5042
  });
@@ -5098,18 +5065,11 @@ class DriftClient {
5098
5065
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
5099
5066
  const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
5100
5067
  const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
5101
- const liquidatorUser = this.getUserAccount(liquidatorSubAccountId);
5102
- if (!liquidatorUser) {
5103
- throw new Error(`Liquidator user account not found for subaccount id ${liquidatorSubAccountId}`);
5104
- }
5105
5068
  const remainingAccounts = this.getRemainingAccounts({
5106
- userAccounts: [liquidatorUser, userAccount],
5069
+ userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
5107
5070
  writableSpotMarketIndexes: [marketIndex],
5108
5071
  });
5109
5072
  const spotMarket = this.getSpotMarketAccount(marketIndex);
5110
- if (!spotMarket) {
5111
- throw new Error(`Spot market account not found for index ${marketIndex}`);
5112
- }
5113
5073
  const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarket);
5114
5074
  this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
5115
5075
  if (this.isTransferHook(spotMarket)) {
@@ -5151,9 +5111,6 @@ class DriftClient {
5151
5111
  }
5152
5112
  async getUpdatePrelaunchOracleIx(perpMarketIndex) {
5153
5113
  const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
5154
- if (!perpMarket) {
5155
- throw new Error(`Perp market account not found for index ${perpMarketIndex}`);
5156
- }
5157
5114
  if (!(0, types_1.isVariant)(perpMarket.amm.oracleSource, 'prelaunch')) {
5158
5115
  throw new Error(`Wrong oracle source ${perpMarket.amm.oracleSource}`);
5159
5116
  }
@@ -5171,9 +5128,6 @@ class DriftClient {
5171
5128
  }
5172
5129
  async getUpdatePerpBidAskTwapIx(perpMarketIndex, makers) {
5173
5130
  const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
5174
- if (!perpMarket) {
5175
- throw new Error(`Perp market account not found for index ${perpMarketIndex}`);
5176
- }
5177
5131
  const remainingAccounts = [];
5178
5132
  for (const [maker, makerStats] of makers) {
5179
5133
  remainingAccounts.push({
@@ -5226,19 +5180,11 @@ class DriftClient {
5226
5180
  this.eventEmitter.emit(eventName, data);
5227
5181
  }
5228
5182
  getOracleDataForPerpMarket(marketIndex) {
5229
- var _a;
5230
- return (_a = this.accountSubscriber.getOraclePriceDataAndSlotForPerpMarket(marketIndex)) === null || _a === void 0 ? void 0 : _a.data;
5183
+ return this.accountSubscriber.getOraclePriceDataAndSlotForPerpMarket(marketIndex).data;
5231
5184
  }
5232
5185
  getMMOracleDataForPerpMarket(marketIndex) {
5233
- var _a;
5234
5186
  const perpMarket = this.getPerpMarketAccount(marketIndex);
5235
- if (!perpMarket) {
5236
- throw new Error(`Perp market account not found for index ${marketIndex}`);
5237
- }
5238
5187
  const oracleData = this.getOracleDataForPerpMarket(marketIndex);
5239
- if (!oracleData) {
5240
- return undefined;
5241
- }
5242
5188
  const stateAccountAndSlot = this.accountSubscriber.getStateAccountAndSlot();
5243
5189
  const isMMOracleActive = !perpMarket.amm.mmOracleSlot.eq(numericConstants_1.ZERO);
5244
5190
  const pctDiff = perpMarket.amm.mmOraclePrice
@@ -5261,7 +5207,7 @@ class DriftClient {
5261
5207
  isExchangeOracleMoreRecent = false;
5262
5208
  }
5263
5209
  else if (!doSlotCheckForRecency &&
5264
- ((_a = oracleData.sequenceId) !== null && _a !== void 0 ? _a : numericConstants_1.ZERO) < mmOracleSequenceId) {
5210
+ oracleData.sequenceId < mmOracleSequenceId) {
5265
5211
  isExchangeOracleMoreRecent = false;
5266
5212
  }
5267
5213
  const conf = (0, utils_3.getOracleConfidenceFromMMOracleData)(perpMarket.amm.mmOraclePrice, oracleData);
@@ -5288,8 +5234,7 @@ class DriftClient {
5288
5234
  }
5289
5235
  }
5290
5236
  getOracleDataForSpotMarket(marketIndex) {
5291
- var _a;
5292
- return (_a = this.accountSubscriber.getOraclePriceDataAndSlotForSpotMarket(marketIndex)) === null || _a === void 0 ? void 0 : _a.data;
5237
+ return this.accountSubscriber.getOraclePriceDataAndSlotForSpotMarket(marketIndex).data;
5293
5238
  }
5294
5239
  async initializeInsuranceFundStake(marketIndex, txParams) {
5295
5240
  const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getInitializeInsuranceFundStakeIx(marketIndex), txParams), [], this.opts);
@@ -5297,13 +5242,9 @@ class DriftClient {
5297
5242
  }
5298
5243
  async getInitializeInsuranceFundStakeIx(marketIndex) {
5299
5244
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
5300
- const spotMarket = this.getSpotMarketAccount(marketIndex);
5301
- if (!spotMarket) {
5302
- throw new Error(`Spot market account not found for index ${marketIndex}`);
5303
- }
5304
5245
  const accounts = {
5305
5246
  insuranceFundStake: ifStakeAccountPublicKey,
5306
- spotMarket: spotMarket.pubkey,
5247
+ spotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
5307
5248
  userStats: (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, this.wallet.publicKey // only allow payer to initialize own insurance fund stake account
5308
5249
  ),
5309
5250
  authority: this.wallet.publicKey,
@@ -5318,9 +5259,6 @@ class DriftClient {
5318
5259
  }
5319
5260
  async getAddInsuranceFundStakeIx(marketIndex, amount, collateralAccountPublicKey) {
5320
5261
  const spotMarket = this.getSpotMarketAccount(marketIndex);
5321
- if (!spotMarket) {
5322
- throw new Error(`Spot market account not found for index ${marketIndex}`);
5323
- }
5324
5262
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
5325
5263
  const remainingAccounts = [];
5326
5264
  this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
@@ -5368,9 +5306,6 @@ class DriftClient {
5368
5306
  async getAddInsuranceFundStakeIxs({ marketIndex, amount, collateralAccountPublicKey, initializeStakeAccount, fromSubaccount, }) {
5369
5307
  const addIfStakeIxs = [];
5370
5308
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
5371
- if (!spotMarketAccount) {
5372
- throw new Error(`Spot market account not found for index ${marketIndex}`);
5373
- }
5374
5309
  const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
5375
5310
  const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
5376
5311
  const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarketAccount);
@@ -5409,9 +5344,6 @@ class DriftClient {
5409
5344
  }
5410
5345
  async requestRemoveInsuranceFundStake(marketIndex, amount, txParams) {
5411
5346
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
5412
- if (!spotMarketAccount) {
5413
- throw new Error(`Spot market account not found for index ${marketIndex}`);
5414
- }
5415
5347
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
5416
5348
  const ix = await this.program.instruction.requestRemoveInsuranceFundStake(marketIndex, amount, {
5417
5349
  accounts: {
@@ -5430,9 +5362,6 @@ class DriftClient {
5430
5362
  }
5431
5363
  async cancelRequestRemoveInsuranceFundStake(marketIndex, txParams) {
5432
5364
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
5433
- if (!spotMarketAccount) {
5434
- throw new Error(`Spot market account not found for index ${marketIndex}`);
5435
- }
5436
5365
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
5437
5366
  const ix = await this.program.instruction.cancelRequestRemoveInsuranceFundStake(marketIndex, {
5438
5367
  accounts: {
@@ -5452,9 +5381,6 @@ class DriftClient {
5452
5381
  async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey, txParams) {
5453
5382
  const removeIfStakeIxs = [];
5454
5383
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
5455
- if (!spotMarketAccount) {
5456
- throw new Error(`Spot market account not found for index ${marketIndex}`);
5457
- }
5458
5384
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
5459
5385
  const additionalSigners = [];
5460
5386
  const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
@@ -5514,9 +5440,6 @@ class DriftClient {
5514
5440
  async getUpdateUserQuoteAssetInsuranceStakeIx(authority) {
5515
5441
  const marketIndex = numericConstants_1.QUOTE_SPOT_MARKET_INDEX;
5516
5442
  const spotMarket = this.getSpotMarketAccount(marketIndex);
5517
- if (!spotMarket) {
5518
- throw new Error(`Spot market account not found for index ${marketIndex}`);
5519
- }
5520
5443
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, authority, marketIndex);
5521
5444
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, authority);
5522
5445
  const ix = this.program.instruction.updateUserQuoteAssetInsuranceStake({
@@ -5540,9 +5463,6 @@ class DriftClient {
5540
5463
  async getUpdateUserGovTokenInsuranceStakeIx(authority) {
5541
5464
  const marketIndex = numericConstants_1.GOV_SPOT_MARKET_INDEX;
5542
5465
  const spotMarket = this.getSpotMarketAccount(marketIndex);
5543
- if (!spotMarket) {
5544
- throw new Error(`Spot market account not found for index ${marketIndex}`);
5545
- }
5546
5466
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, authority, marketIndex);
5547
5467
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, authority);
5548
5468
  const ix = this.program.instruction.updateUserGovTokenInsuranceStake({
@@ -5564,9 +5484,6 @@ class DriftClient {
5564
5484
  }
5565
5485
  async getSettleRevenueToInsuranceFundIx(spotMarketIndex) {
5566
5486
  const spotMarketAccount = this.getSpotMarketAccount(spotMarketIndex);
5567
- if (!spotMarketAccount) {
5568
- throw new Error(`Spot market account not found for index ${spotMarketIndex}`);
5569
- }
5570
5487
  const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarketAccount);
5571
5488
  const remainingAccounts = [];
5572
5489
  this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
@@ -5591,19 +5508,12 @@ class DriftClient {
5591
5508
  return txSig;
5592
5509
  }
5593
5510
  async getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex) {
5594
- const userAccount = this.getUserAccount();
5595
- if (!userAccount) {
5596
- throw new Error(`User account not found. Something is wrong with driftClient config`);
5597
- }
5598
5511
  const remainingAccounts = this.getRemainingAccounts({
5599
- userAccounts: [userAccount],
5512
+ userAccounts: [this.getUserAccount()],
5600
5513
  writablePerpMarketIndexes: [perpMarketIndex],
5601
5514
  writableSpotMarketIndexes: [spotMarketIndex],
5602
5515
  });
5603
5516
  const spotMarket = this.getSpotMarketAccount(spotMarketIndex);
5604
- if (!spotMarket) {
5605
- throw new Error(`Spot market account not found for index ${spotMarketIndex}`);
5606
- }
5607
5517
  const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarket);
5608
5518
  return await this.program.instruction.resolvePerpPnlDeficit(spotMarketIndex, perpMarketIndex, {
5609
5519
  accounts: {
@@ -5619,9 +5529,6 @@ class DriftClient {
5619
5529
  }
5620
5530
  async getDepositIntoSpotMarketRevenuePoolIx(marketIndex, amount, userTokenAccountPublicKey) {
5621
5531
  const spotMarket = await this.getSpotMarketAccount(marketIndex);
5622
- if (!spotMarket) {
5623
- throw new Error(`Spot market account not found for index ${marketIndex}`);
5624
- }
5625
5532
  const remainingAccounts = [];
5626
5533
  this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
5627
5534
  if (this.isTransferHook(spotMarket)) {
@@ -5656,13 +5563,7 @@ class DriftClient {
5656
5563
  getPerpMarketExtendedInfo(marketIndex) {
5657
5564
  var _a, _b;
5658
5565
  const marketAccount = this.getPerpMarketAccount(marketIndex);
5659
- if (!marketAccount) {
5660
- return undefined;
5661
- }
5662
5566
  const quoteAccount = this.getSpotMarketAccount(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
5663
- if (!quoteAccount) {
5664
- throw new Error(`Quote spot market account not found. Something is wrong with driftClient config`);
5665
- }
5666
5567
  const extendedInfo = {
5667
5568
  marketIndex,
5668
5569
  minOrderSize: (_a = marketAccount.amm) === null || _a === void 0 ? void 0 : _a.minOrderSize,
@@ -5680,7 +5581,7 @@ class DriftClient {
5680
5581
  * @returns : {takerFee: number, makerFee: number} Precision None
5681
5582
  */
5682
5583
  getMarketFees(marketType, marketIndex, user, enteringHighLeverageMode) {
5683
- var _a, _b;
5584
+ var _a;
5684
5585
  let feeTier;
5685
5586
  const userHLM = ((_a = user === null || user === void 0 ? void 0 : user.isHighLeverageMode('Initial')) !== null && _a !== void 0 ? _a : false) ||
5686
5587
  enteringHighLeverageMode;
@@ -5697,19 +5598,17 @@ class DriftClient {
5697
5598
  let makerFee = feeTier.makerRebateNumerator / feeTier.makerRebateDenominator;
5698
5599
  if (marketIndex !== undefined) {
5699
5600
  let marketAccount = null;
5700
- let feeAdjustment = 1;
5701
5601
  if ((0, types_1.isVariant)(marketType, 'perp')) {
5702
5602
  marketAccount = this.getPerpMarketAccount(marketIndex);
5703
- feeAdjustment = (_b = marketAccount === null || marketAccount === void 0 ? void 0 : marketAccount.feeAdjustment) !== null && _b !== void 0 ? _b : 0;
5704
5603
  }
5705
5604
  else {
5706
5605
  marketAccount = this.getSpotMarketAccount(marketIndex);
5707
5606
  }
5708
- takerFee += (takerFee * feeAdjustment) / 100;
5607
+ takerFee += (takerFee * marketAccount.feeAdjustment) / 100;
5709
5608
  if (userHLM) {
5710
5609
  takerFee *= 2;
5711
5610
  }
5712
- makerFee += (makerFee * feeAdjustment) / 100;
5611
+ makerFee += (makerFee * marketAccount.feeAdjustment) / 100;
5713
5612
  }
5714
5613
  return {
5715
5614
  takerFee,
@@ -5893,9 +5792,6 @@ class DriftClient {
5893
5792
  // @deprecated use getPostManySwitchboardOnDemandUpdatesAtomicIxs instead. This function no longer returns the required ixs due to upstream sdk changes.
5894
5793
  async getPostSwitchboardOnDemandUpdateAtomicIx(feed, recentSlothash, numSignatures = 3) {
5895
5794
  const program = await this.getSwitchboardOnDemandProgram();
5896
- if (!program) {
5897
- return undefined;
5898
- }
5899
5795
  const feedAccount = new on_demand_1.PullFeed(program, feed);
5900
5796
  if (!this.sbProgramFeedConfigs) {
5901
5797
  this.sbProgramFeedConfigs = new Map();
@@ -5983,14 +5879,11 @@ class DriftClient {
5983
5879
  return txSig;
5984
5880
  }
5985
5881
  async getEnableHighLeverageModeIx(subAccountId, depositToTradeArgs, overrides) {
5986
- var _a, _b, _c, _d, _e;
5882
+ var _a, _b, _c, _d;
5987
5883
  const isDepositToTradeTx = depositToTradeArgs !== undefined;
5988
5884
  const userAccountPublicKey = (_b = (_a = overrides === null || overrides === void 0 ? void 0 : overrides.user) === null || _a === void 0 ? void 0 : _a.getUserAccountPublicKey()) !== null && _b !== void 0 ? _b : (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
5989
5885
  const signingAuthority = (_c = overrides === null || overrides === void 0 ? void 0 : overrides.signingAuthority) !== null && _c !== void 0 ? _c : this.wallet.publicKey;
5990
- const userAccount = (_e = (_d = overrides === null || overrides === void 0 ? void 0 : overrides.user) === null || _d === void 0 ? void 0 : _d.getUserAccount()) !== null && _e !== void 0 ? _e : this.getUserAccount(subAccountId);
5991
- if (!userAccount) {
5992
- throw new Error(`User account not found for subAccountId ${subAccountId}`);
5993
- }
5886
+ const userAccount = (_d = overrides === null || overrides === void 0 ? void 0 : overrides.user.getUserAccount()) !== null && _d !== void 0 ? _d : this.getUserAccount(subAccountId);
5994
5887
  const remainingAccounts = this.getRemainingAccounts({
5995
5888
  userAccounts: (depositToTradeArgs === null || depositToTradeArgs === void 0 ? void 0 : depositToTradeArgs.isMakingNewAccount) ? [] : [userAccount],
5996
5889
  useMarketLastSlotCache: false,
@@ -6056,9 +5949,6 @@ class DriftClient {
6056
5949
  }
6057
5950
  async getPauseSpotMarketDepositWithdrawIx(spotMarketIndex) {
6058
5951
  const spotMarket = await this.getSpotMarketAccount(spotMarketIndex);
6059
- if (!spotMarket) {
6060
- throw new Error(`Spot market account not found for index ${spotMarketIndex}`);
6061
- }
6062
5952
  return this.program.instruction.pauseSpotMarketDepositWithdraw({
6063
5953
  accounts: {
6064
5954
  state: await this.getStatePublicKey(),
@@ -6087,16 +5977,12 @@ class DriftClient {
6087
5977
  data.set(discriminatorBuffer, 0);
6088
5978
  data.set(oraclePrice.toArrayLike(Buffer, 'le', 8), 5); // next 8 bytes
6089
5979
  data.set(oracleSequenceId.toArrayLike(Buffer, 'le', 8), 13); // next 8 bytes
6090
- const perpMarket = this.getPerpMarketAccount(marketIndex);
6091
- if (!perpMarket) {
6092
- throw new Error(`Perp market account not found for index ${marketIndex}`);
6093
- }
6094
5980
  // Build the instruction manually
6095
5981
  return new web3_js_1.TransactionInstruction({
6096
5982
  programId: this.program.programId,
6097
5983
  keys: [
6098
5984
  {
6099
- pubkey: perpMarket.pubkey,
5985
+ pubkey: this.getPerpMarketAccount(marketIndex).pubkey,
6100
5986
  isWritable: true,
6101
5987
  isSigner: false,
6102
5988
  },
@@ -6134,16 +6020,12 @@ class DriftClient {
6134
6020
  const data = Buffer.alloc(discriminatorBuffer.length + 4);
6135
6021
  data.set(discriminatorBuffer, 0);
6136
6022
  data.writeInt8(ammSpreadAdjustment, 5); // next byte
6137
- const perpMarket = this.getPerpMarketAccount(marketIndex);
6138
- if (!perpMarket) {
6139
- throw new Error(`Perp market account not found for index ${marketIndex}`);
6140
- }
6141
6023
  // Build the instruction manually
6142
6024
  return new web3_js_1.TransactionInstruction({
6143
6025
  programId: this.program.programId,
6144
6026
  keys: [
6145
6027
  {
6146
- pubkey: perpMarket.pubkey,
6028
+ pubkey: this.getPerpMarketAccount(marketIndex).pubkey,
6147
6029
  isWritable: true,
6148
6030
  isSigner: false,
6149
6031
  },
@@ -6232,16 +6114,12 @@ class DriftClient {
6232
6114
  userAccounts: [],
6233
6115
  readablePerpMarketIndex: perpMarketIndexes,
6234
6116
  });
6235
- const quoteMarket = this.getSpotMarketAccount(0);
6236
- if (!quoteMarket) {
6237
- throw new Error(`Quote spot market account not found for index 0`);
6238
- }
6239
6117
  return this.program.instruction.updateAmmCache({
6240
6118
  accounts: {
6241
6119
  state: await this.getStatePublicKey(),
6242
6120
  keeper: this.wallet.publicKey,
6243
6121
  ammCache: (0, pda_1.getAmmCachePublicKey)(this.program.programId),
6244
- quoteMarket: quoteMarket.pubkey,
6122
+ quoteMarket: this.getSpotMarketAccount(0).pubkey,
6245
6123
  },
6246
6124
  remainingAccounts,
6247
6125
  });
@@ -6252,9 +6130,6 @@ class DriftClient {
6252
6130
  }
6253
6131
  async getUpdateConstituentOracleInfoIx(constituent) {
6254
6132
  const spotMarket = this.getSpotMarketAccount(constituent.spotMarketIndex);
6255
- if (!spotMarket) {
6256
- throw new Error(`Spot market account not found for index ${constituent.spotMarketIndex}`);
6257
- }
6258
6133
  return this.program.instruction.updateConstituentOracleInfo({
6259
6134
  accounts: {
6260
6135
  keeper: this.wallet.publicKey,
@@ -6276,20 +6151,12 @@ class DriftClient {
6276
6151
  });
6277
6152
  const constituentInTokenAccount = (0, pda_1.getConstituentVaultPublicKey)(this.program.programId, lpPool, inMarketIndex);
6278
6153
  const constituentOutTokenAccount = (0, pda_1.getConstituentVaultPublicKey)(this.program.programId, lpPool, outMarketIndex);
6279
- const inSpotMarket = this.getSpotMarketAccount(inMarketIndex);
6280
- if (!inSpotMarket) {
6281
- throw new Error(`Spot market account not found for index ${inMarketIndex}`);
6282
- }
6283
- const outSpotMarket = this.getSpotMarketAccount(outMarketIndex);
6284
- if (!outSpotMarket) {
6285
- throw new Error(`Spot market account not found for index ${outMarketIndex}`);
6286
- }
6287
- const userInTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(inSpotMarket.mint, userAuthority);
6288
- const userOutTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(outSpotMarket.mint, userAuthority);
6154
+ const userInTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(this.getSpotMarketAccount(inMarketIndex).mint, userAuthority);
6155
+ const userOutTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(this.getSpotMarketAccount(outMarketIndex).mint, userAuthority);
6289
6156
  const inConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool, inMarketIndex);
6290
6157
  const outConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool, outMarketIndex);
6291
- const inMarketMint = inSpotMarket.mint;
6292
- const outMarketMint = outSpotMarket.mint;
6158
+ const inMarketMint = this.getSpotMarketAccount(inMarketIndex).mint;
6159
+ const outMarketMint = this.getSpotMarketAccount(outMarketIndex).mint;
6293
6160
  const constituentTargetBase = (0, pda_1.getConstituentTargetBasePublicKey)(this.program.programId, lpPool);
6294
6161
  return this.program.instruction.lpPoolSwap(inMarketIndex, outMarketIndex, inAmount, minOutAmount, {
6295
6162
  remainingAccounts,
@@ -6362,9 +6229,6 @@ class DriftClient {
6362
6229
  writableSpotMarketIndexes: [inMarketIndex],
6363
6230
  });
6364
6231
  const spotMarket = this.getSpotMarketAccount(inMarketIndex);
6365
- if (!spotMarket) {
6366
- throw new Error(`Spot market account not found for index ${inMarketIndex}`);
6367
- }
6368
6232
  const inMarketMint = spotMarket.mint;
6369
6233
  const isSolMarket = inMarketMint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
6370
6234
  let wSolTokenAccount;
@@ -6460,9 +6324,6 @@ class DriftClient {
6460
6324
  writableSpotMarketIndexes: [outMarketIndex],
6461
6325
  });
6462
6326
  const spotMarket = this.getSpotMarketAccount(outMarketIndex);
6463
- if (!spotMarket) {
6464
- throw new Error(`Spot market account not found for index ${outMarketIndex}`);
6465
- }
6466
6327
  const outMarketMint = spotMarket.mint;
6467
6328
  const outConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool.pubkey, outMarketIndex);
6468
6329
  if (outMarketMint.equals(spotMarkets_1.WRAPPED_SOL_MINT)) {
@@ -6509,9 +6370,6 @@ class DriftClient {
6509
6370
  writableSpotMarketIndexes: [outMarketIndex],
6510
6371
  });
6511
6372
  const spotMarket = this.getSpotMarketAccount(outMarketIndex);
6512
- if (!spotMarket) {
6513
- throw new Error(`Spot market account not found for index ${outMarketIndex}`);
6514
- }
6515
6373
  const outMarketMint = spotMarket.mint;
6516
6374
  const outConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool.pubkey, outMarketIndex);
6517
6375
  const lpMint = lpPool.mint;
@@ -6610,9 +6468,8 @@ class DriftClient {
6610
6468
  async getSettlePerpToLpPoolIx(lpPoolId, perpMarketIndexes) {
6611
6469
  const remainingAccounts = [];
6612
6470
  remainingAccounts.push(...perpMarketIndexes.map((index) => {
6613
- var _a, _b;
6614
6471
  return {
6615
- pubkey: (_b = (_a = this.getPerpMarketAccount(index)) === null || _a === void 0 ? void 0 : _a.pubkey) !== null && _b !== void 0 ? _b : web3_js_1.PublicKey.default,
6472
+ pubkey: this.getPerpMarketAccount(index).pubkey,
6616
6473
  isSigner: false,
6617
6474
  isWritable: true,
6618
6475
  };
@@ -6676,13 +6533,12 @@ class DriftClient {
6676
6533
  }
6677
6534
  }
6678
6535
  async buildTransaction(instructions, txParams, txVersion, lookupTables, forceVersionedTransaction, recentBlockhash, optionalIxs) {
6679
- var _a, _b;
6680
6536
  return this.txHandler.buildTransaction({
6681
6537
  instructions,
6682
6538
  txVersion: txVersion !== null && txVersion !== void 0 ? txVersion : this.txVersion,
6683
6539
  txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
6684
6540
  connection: this.connection,
6685
- preFlightCommitment: (_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.preflightCommitment) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_COMMITMENT_LEVEL,
6541
+ preFlightCommitment: this.opts.preflightCommitment,
6686
6542
  fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
6687
6543
  lookupTables,
6688
6544
  forceVersionedTransaction,
@@ -6691,40 +6547,36 @@ class DriftClient {
6691
6547
  });
6692
6548
  }
6693
6549
  async buildBulkTransactions(instructions, txParams, txVersion, lookupTables, forceVersionedTransaction) {
6694
- var _a, _b;
6695
- const txns = await this.txHandler.buildBulkTransactions({
6550
+ return this.txHandler.buildBulkTransactions({
6696
6551
  instructions,
6697
6552
  txVersion: txVersion !== null && txVersion !== void 0 ? txVersion : this.txVersion,
6698
6553
  txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
6699
6554
  connection: this.connection,
6700
- preFlightCommitment: (_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.preflightCommitment) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_COMMITMENT_LEVEL,
6555
+ preFlightCommitment: this.opts.preflightCommitment,
6701
6556
  fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
6702
6557
  lookupTables,
6703
6558
  forceVersionedTransaction,
6704
6559
  });
6705
- return txns.filter(Boolean);
6706
6560
  }
6707
6561
  async buildTransactionsMap(instructionsMap, txParams, txVersion, lookupTables, forceVersionedTransaction) {
6708
- var _a, _b;
6709
6562
  return this.txHandler.buildTransactionsMap({
6710
6563
  instructionsMap,
6711
6564
  txVersion: txVersion !== null && txVersion !== void 0 ? txVersion : this.txVersion,
6712
6565
  txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
6713
6566
  connection: this.connection,
6714
- preFlightCommitment: (_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.preflightCommitment) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_COMMITMENT_LEVEL,
6567
+ preFlightCommitment: this.opts.preflightCommitment,
6715
6568
  fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
6716
6569
  lookupTables,
6717
6570
  forceVersionedTransaction,
6718
6571
  });
6719
6572
  }
6720
6573
  async buildAndSignTransactionsMap(instructionsMap, txParams, txVersion, lookupTables, forceVersionedTransaction) {
6721
- var _a, _b;
6722
6574
  return this.txHandler.buildAndSignTransactionMap({
6723
6575
  instructionsMap,
6724
6576
  txVersion: txVersion !== null && txVersion !== void 0 ? txVersion : this.txVersion,
6725
6577
  txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
6726
6578
  connection: this.connection,
6727
- preFlightCommitment: (_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.preflightCommitment) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_COMMITMENT_LEVEL,
6579
+ preFlightCommitment: this.opts.preflightCommitment,
6728
6580
  fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
6729
6581
  lookupTables,
6730
6582
  forceVersionedTransaction,