@drift-labs/sdk 2.152.0-beta.2 → 2.153.0-beta.0

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.
Files changed (44) hide show
  1. package/VERSION +1 -1
  2. package/build-browser.js +58 -0
  3. package/bun.lock +182 -1
  4. package/esbuild-shims.js +12 -0
  5. package/lib/browser/constants/perpMarkets.js +12 -0
  6. package/lib/browser/constants/txConstants.d.ts +1 -0
  7. package/lib/browser/constants/txConstants.js +2 -1
  8. package/lib/browser/driftClient.d.ts +13 -6
  9. package/lib/browser/driftClient.js +280 -36
  10. package/lib/browser/idl/drift.json +207 -18
  11. package/lib/browser/markets.d.ts +5 -0
  12. package/lib/browser/markets.js +16 -0
  13. package/lib/browser/swap/UnifiedSwapClient.js +2 -0
  14. package/lib/browser/titan/titanClient.d.ts +3 -0
  15. package/lib/browser/titan/titanClient.js +58 -60
  16. package/lib/browser/user.d.ts +1 -1
  17. package/lib/node/constants/perpMarkets.d.ts.map +1 -1
  18. package/lib/node/constants/perpMarkets.js +12 -0
  19. package/lib/node/constants/txConstants.d.ts +1 -0
  20. package/lib/node/constants/txConstants.d.ts.map +1 -1
  21. package/lib/node/constants/txConstants.js +2 -1
  22. package/lib/node/driftClient.d.ts +13 -6
  23. package/lib/node/driftClient.d.ts.map +1 -1
  24. package/lib/node/driftClient.js +280 -36
  25. package/lib/node/idl/drift.json +207 -18
  26. package/lib/node/markets.d.ts +6 -0
  27. package/lib/node/markets.d.ts.map +1 -0
  28. package/lib/node/markets.js +16 -0
  29. package/lib/node/swap/UnifiedSwapClient.d.ts.map +1 -1
  30. package/lib/node/swap/UnifiedSwapClient.js +2 -0
  31. package/lib/node/titan/titanClient.d.ts +3 -0
  32. package/lib/node/titan/titanClient.d.ts.map +1 -1
  33. package/lib/node/titan/titanClient.js +58 -60
  34. package/lib/node/user.d.ts +1 -1
  35. package/lib/node/user.d.ts.map +1 -1
  36. package/package.json +10 -2
  37. package/src/constants/perpMarkets.ts +13 -0
  38. package/src/constants/txConstants.ts +2 -0
  39. package/src/driftClient.ts +477 -52
  40. package/src/idl/drift.json +207 -18
  41. package/src/markets.ts +24 -0
  42. package/src/swap/UnifiedSwapClient.ts +2 -0
  43. package/src/titan/titanClient.ts +88 -72
  44. package/src/user.ts +1 -1
@@ -77,6 +77,7 @@ 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");
80
81
  /**
81
82
  * # DriftClient
82
83
  * 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.
@@ -196,14 +197,12 @@ class DriftClient {
196
197
  accountSubscription: this.userAccountSubscriptionConfig,
197
198
  });
198
199
  }
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
- }
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));
207
206
  const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Unsubscribe;
208
207
  const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
209
208
  config.spotMarketIndexes === undefined &&
@@ -1382,6 +1381,9 @@ class DriftClient {
1382
1381
  getQuoteAssetTokenAmount() {
1383
1382
  return this.getTokenAmount(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
1384
1383
  }
1384
+ getIsolatedPerpPositionTokenAmount(perpMarketIndex, subAccountId) {
1385
+ return this.getUser(subAccountId).getIsolatePerpPositionTokenAmount(perpMarketIndex);
1386
+ }
1385
1387
  /**
1386
1388
  * Returns the token amount for a given market. The spot market precision is based on the token mint decimals.
1387
1389
  * Positive if it is a deposit, negative if it is a borrow.
@@ -1841,6 +1843,17 @@ class DriftClient {
1841
1843
  }
1842
1844
  ixs.push(...startIxs);
1843
1845
  }
1846
+ // For Token2022 tokens, check if the user's token account exists and create it if it doesn't
1847
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarket);
1848
+ if (!isSolMarket &&
1849
+ !isFromSubaccount &&
1850
+ !tokenProgram.equals(spl_token_1.TOKEN_PROGRAM_ID)) {
1851
+ const accountExists = await this.checkIfAccountExists(userTokenAccount);
1852
+ if (!accountExists) {
1853
+ const createAtaIx = this.getAssociatedTokenAccountCreationIx(spotMarket.mint, userTokenAccount, tokenProgram);
1854
+ ixs.push(createAtaIx);
1855
+ }
1856
+ }
1844
1857
  const depositCollateralIx = isFromSubaccount
1845
1858
  ? await this.getTransferDepositIx(amount, marketIndex, fromSubAccountId, subAccountId)
1846
1859
  : await this.getDepositInstruction(amount, marketIndex, userTokenAccount, subAccountId, false, false);
@@ -2139,6 +2152,88 @@ class DriftClient {
2139
2152
  remainingAccounts,
2140
2153
  });
2141
2154
  }
2155
+ async depositIntoIsolatedPerpPosition(amount, perpMarketIndex, userTokenAccount, subAccountId, txParams) {
2156
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getDepositIntoIsolatedPerpPositionIx(amount, perpMarketIndex, userTokenAccount, subAccountId), txParams), [], this.opts);
2157
+ return txSig;
2158
+ }
2159
+ async getDepositIntoIsolatedPerpPositionIx(amount, perpMarketIndex, userTokenAccount, subAccountId) {
2160
+ const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, subAccountId !== null && subAccountId !== void 0 ? subAccountId : this.activeSubAccountId);
2161
+ const perpMarketAccount = this.getPerpMarketAccount(perpMarketIndex);
2162
+ const spotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;
2163
+ const spotMarketAccount = this.getSpotMarketAccount(spotMarketIndex);
2164
+ const remainingAccounts = this.getRemainingAccounts({
2165
+ userAccounts: [],
2166
+ writableSpotMarketIndexes: [spotMarketIndex],
2167
+ readablePerpMarketIndex: [perpMarketIndex],
2168
+ });
2169
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarketAccount);
2170
+ return await this.program.instruction.depositIntoIsolatedPerpPosition(spotMarketIndex, perpMarketIndex, amount, {
2171
+ accounts: {
2172
+ state: await this.getStatePublicKey(),
2173
+ spotMarketVault: spotMarketAccount.vault,
2174
+ user: userAccountPublicKey,
2175
+ userStats: this.getUserStatsAccountPublicKey(),
2176
+ userTokenAccount: userTokenAccount,
2177
+ authority: this.wallet.publicKey,
2178
+ tokenProgram,
2179
+ },
2180
+ remainingAccounts,
2181
+ });
2182
+ }
2183
+ async transferIsolatedPerpPositionDeposit(amount, perpMarketIndex, subAccountId, txParams) {
2184
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getTransferIsolatedPerpPositionDepositIx(amount, perpMarketIndex, subAccountId), txParams), [], this.opts);
2185
+ return txSig;
2186
+ }
2187
+ async getTransferIsolatedPerpPositionDepositIx(amount, perpMarketIndex, subAccountId) {
2188
+ const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, subAccountId !== null && subAccountId !== void 0 ? subAccountId : this.activeSubAccountId);
2189
+ const perpMarketAccount = this.getPerpMarketAccount(perpMarketIndex);
2190
+ const spotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;
2191
+ const spotMarketAccount = this.getSpotMarketAccount(spotMarketIndex);
2192
+ const user = await this.getUserAccount(subAccountId);
2193
+ const remainingAccounts = this.getRemainingAccounts({
2194
+ userAccounts: [user],
2195
+ writableSpotMarketIndexes: [spotMarketIndex],
2196
+ readablePerpMarketIndex: [perpMarketIndex],
2197
+ });
2198
+ return await this.program.instruction.transferIsolatedPerpPositionDeposit(spotMarketIndex, perpMarketIndex, amount, {
2199
+ accounts: {
2200
+ state: await this.getStatePublicKey(),
2201
+ spotMarketVault: spotMarketAccount.vault,
2202
+ user: userAccountPublicKey,
2203
+ userStats: this.getUserStatsAccountPublicKey(),
2204
+ authority: this.wallet.publicKey,
2205
+ },
2206
+ remainingAccounts,
2207
+ });
2208
+ }
2209
+ async withdrawFromIsolatedPerpPosition(amount, perpMarketIndex, userTokenAccount, subAccountId, txParams) {
2210
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getWithdrawFromIsolatedPerpPositionIx(amount, perpMarketIndex, userTokenAccount, subAccountId), txParams));
2211
+ return txSig;
2212
+ }
2213
+ async getWithdrawFromIsolatedPerpPositionIx(amount, perpMarketIndex, userTokenAccount, subAccountId) {
2214
+ const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, subAccountId !== null && subAccountId !== void 0 ? subAccountId : this.activeSubAccountId);
2215
+ const perpMarketAccount = this.getPerpMarketAccount(perpMarketIndex);
2216
+ const spotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;
2217
+ const spotMarketAccount = this.getSpotMarketAccount(spotMarketIndex);
2218
+ const remainingAccounts = this.getRemainingAccounts({
2219
+ userAccounts: [this.getUserAccount(subAccountId)],
2220
+ writableSpotMarketIndexes: [spotMarketIndex],
2221
+ readablePerpMarketIndex: [perpMarketIndex],
2222
+ });
2223
+ return await this.program.instruction.withdrawFromIsolatedPerpPosition(spotMarketIndex, perpMarketIndex, amount, {
2224
+ accounts: {
2225
+ state: await this.getStatePublicKey(),
2226
+ spotMarketVault: spotMarketAccount.vault,
2227
+ user: userAccountPublicKey,
2228
+ userStats: this.getUserStatsAccountPublicKey(),
2229
+ authority: this.wallet.publicKey,
2230
+ userTokenAccount: userTokenAccount,
2231
+ tokenProgram: this.getTokenProgramForSpotMarket(spotMarketAccount),
2232
+ driftSigner: this.getSignerPublicKey(),
2233
+ },
2234
+ remainingAccounts,
2235
+ });
2236
+ }
2142
2237
  async updateSpotMarketCumulativeInterest(marketIndex, txParams) {
2143
2238
  const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.updateSpotMarketCumulativeInterestIx(marketIndex), txParams), [], this.opts);
2144
2239
  return txSig;
@@ -4651,8 +4746,12 @@ class DriftClient {
4651
4746
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
4652
4747
  const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
4653
4748
  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
+ }
4654
4753
  const remainingAccounts = this.getRemainingAccounts({
4655
- userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
4754
+ userAccounts: [liquidatorUser, userAccount],
4656
4755
  useMarketLastSlotCache: true,
4657
4756
  writableSpotMarketIndexes: [liabilityMarketIndex, assetMarketIndex],
4658
4757
  });
@@ -4670,7 +4769,13 @@ class DriftClient {
4670
4769
  }
4671
4770
  async getJupiterLiquidateSpotWithSwapIxV6({ jupiterClient, liabilityMarketIndex, assetMarketIndex, swapAmount, assetTokenAccount, liabilityTokenAccount, slippageBps, swapMode, onlyDirectRoutes, quote, userAccount, userAccountPublicKey, userStatsAccountPublicKey, liquidatorSubAccountId, maxAccounts, }) {
4672
4771
  const liabilityMarket = this.getSpotMarketAccount(liabilityMarketIndex);
4772
+ if (!liabilityMarket) {
4773
+ throw new Error(`Liability spot market account not found for index ${liabilityMarketIndex}`);
4774
+ }
4673
4775
  const assetMarket = this.getSpotMarketAccount(assetMarketIndex);
4776
+ if (!assetMarket) {
4777
+ throw new Error(`Asset spot market account not found for index ${assetMarketIndex}`);
4778
+ }
4674
4779
  if (!quote) {
4675
4780
  const fetchedQuote = await jupiterClient.getQuote({
4676
4781
  inputMint: assetMarket.mint,
@@ -4752,7 +4857,13 @@ class DriftClient {
4752
4857
  readableSpotMarketIndexes: [numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
4753
4858
  });
4754
4859
  const liabilitySpotMarket = this.getSpotMarketAccount(liabilityMarketIndex);
4860
+ if (!liabilitySpotMarket) {
4861
+ throw new Error(`Liability spot market account not found for index ${liabilityMarketIndex}`);
4862
+ }
4755
4863
  const assetSpotMarket = this.getSpotMarketAccount(assetMarketIndex);
4864
+ if (!assetSpotMarket) {
4865
+ throw new Error(`Asset spot market account not found for index ${assetMarketIndex}`);
4866
+ }
4756
4867
  const liabilityTokenProgram = this.getTokenProgramForSpotMarket(liabilitySpotMarket);
4757
4868
  const assetTokenProgram = this.getTokenProgramForSpotMarket(assetSpotMarket);
4758
4869
  if (!liabilityTokenProgram.equals(assetTokenProgram)) {
@@ -4825,7 +4936,13 @@ class DriftClient {
4825
4936
  writableSpotMarketIndexes: [inMarketIndex, outMarketIndex],
4826
4937
  });
4827
4938
  const inSpotMarket = this.getSpotMarketAccount(inMarketIndex);
4939
+ if (!inSpotMarket) {
4940
+ throw new Error(`In spot market account not found for index ${inMarketIndex}`);
4941
+ }
4828
4942
  const outSpotMarket = this.getSpotMarketAccount(outMarketIndex);
4943
+ if (!outSpotMarket) {
4944
+ throw new Error(`Out spot market account not found for index ${outMarketIndex}`);
4945
+ }
4829
4946
  if (this.isToken2022(inSpotMarket) || this.isToken2022(outSpotMarket)) {
4830
4947
  remainingAccounts.push({
4831
4948
  pubkey: inSpotMarket.mint,
@@ -4887,8 +5004,12 @@ class DriftClient {
4887
5004
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
4888
5005
  const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
4889
5006
  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
+ }
4890
5011
  const remainingAccounts = this.getRemainingAccounts({
4891
- userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
5012
+ userAccounts: [liquidatorUser, userAccount],
4892
5013
  writablePerpMarketIndexes: [perpMarketIndex],
4893
5014
  writableSpotMarketIndexes: [liabilityMarketIndex],
4894
5015
  });
@@ -4914,8 +5035,12 @@ class DriftClient {
4914
5035
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
4915
5036
  const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
4916
5037
  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
+ }
4917
5042
  const remainingAccounts = this.getRemainingAccounts({
4918
- userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
5043
+ userAccounts: [liquidatorUser, userAccount],
4919
5044
  writablePerpMarketIndexes: [perpMarketIndex],
4920
5045
  writableSpotMarketIndexes: [assetMarketIndex],
4921
5046
  });
@@ -4939,8 +5064,12 @@ class DriftClient {
4939
5064
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
4940
5065
  const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
4941
5066
  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
+ }
4942
5071
  const remainingAccounts = this.getRemainingAccounts({
4943
- userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
5072
+ userAccounts: [liquidatorUser, userAccount],
4944
5073
  writablePerpMarketIndexes: [marketIndex],
4945
5074
  writableSpotMarketIndexes: [numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
4946
5075
  });
@@ -4969,11 +5098,18 @@ class DriftClient {
4969
5098
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
4970
5099
  const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
4971
5100
  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
+ }
4972
5105
  const remainingAccounts = this.getRemainingAccounts({
4973
- userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
5106
+ userAccounts: [liquidatorUser, userAccount],
4974
5107
  writableSpotMarketIndexes: [marketIndex],
4975
5108
  });
4976
5109
  const spotMarket = this.getSpotMarketAccount(marketIndex);
5110
+ if (!spotMarket) {
5111
+ throw new Error(`Spot market account not found for index ${marketIndex}`);
5112
+ }
4977
5113
  const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarket);
4978
5114
  this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
4979
5115
  if (this.isTransferHook(spotMarket)) {
@@ -5015,6 +5151,9 @@ class DriftClient {
5015
5151
  }
5016
5152
  async getUpdatePrelaunchOracleIx(perpMarketIndex) {
5017
5153
  const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
5154
+ if (!perpMarket) {
5155
+ throw new Error(`Perp market account not found for index ${perpMarketIndex}`);
5156
+ }
5018
5157
  if (!(0, types_1.isVariant)(perpMarket.amm.oracleSource, 'prelaunch')) {
5019
5158
  throw new Error(`Wrong oracle source ${perpMarket.amm.oracleSource}`);
5020
5159
  }
@@ -5032,6 +5171,9 @@ class DriftClient {
5032
5171
  }
5033
5172
  async getUpdatePerpBidAskTwapIx(perpMarketIndex, makers) {
5034
5173
  const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
5174
+ if (!perpMarket) {
5175
+ throw new Error(`Perp market account not found for index ${perpMarketIndex}`);
5176
+ }
5035
5177
  const remainingAccounts = [];
5036
5178
  for (const [maker, makerStats] of makers) {
5037
5179
  remainingAccounts.push({
@@ -5084,11 +5226,19 @@ class DriftClient {
5084
5226
  this.eventEmitter.emit(eventName, data);
5085
5227
  }
5086
5228
  getOracleDataForPerpMarket(marketIndex) {
5087
- return this.accountSubscriber.getOraclePriceDataAndSlotForPerpMarket(marketIndex).data;
5229
+ var _a;
5230
+ return (_a = this.accountSubscriber.getOraclePriceDataAndSlotForPerpMarket(marketIndex)) === null || _a === void 0 ? void 0 : _a.data;
5088
5231
  }
5089
5232
  getMMOracleDataForPerpMarket(marketIndex) {
5233
+ var _a;
5090
5234
  const perpMarket = this.getPerpMarketAccount(marketIndex);
5235
+ if (!perpMarket) {
5236
+ throw new Error(`Perp market account not found for index ${marketIndex}`);
5237
+ }
5091
5238
  const oracleData = this.getOracleDataForPerpMarket(marketIndex);
5239
+ if (!oracleData) {
5240
+ return undefined;
5241
+ }
5092
5242
  const stateAccountAndSlot = this.accountSubscriber.getStateAccountAndSlot();
5093
5243
  const isMMOracleActive = !perpMarket.amm.mmOracleSlot.eq(numericConstants_1.ZERO);
5094
5244
  const pctDiff = perpMarket.amm.mmOraclePrice
@@ -5111,7 +5261,7 @@ class DriftClient {
5111
5261
  isExchangeOracleMoreRecent = false;
5112
5262
  }
5113
5263
  else if (!doSlotCheckForRecency &&
5114
- oracleData.sequenceId < mmOracleSequenceId) {
5264
+ ((_a = oracleData.sequenceId) !== null && _a !== void 0 ? _a : numericConstants_1.ZERO) < mmOracleSequenceId) {
5115
5265
  isExchangeOracleMoreRecent = false;
5116
5266
  }
5117
5267
  const conf = (0, utils_3.getOracleConfidenceFromMMOracleData)(perpMarket.amm.mmOraclePrice, oracleData);
@@ -5138,7 +5288,8 @@ class DriftClient {
5138
5288
  }
5139
5289
  }
5140
5290
  getOracleDataForSpotMarket(marketIndex) {
5141
- return this.accountSubscriber.getOraclePriceDataAndSlotForSpotMarket(marketIndex).data;
5291
+ var _a;
5292
+ return (_a = this.accountSubscriber.getOraclePriceDataAndSlotForSpotMarket(marketIndex)) === null || _a === void 0 ? void 0 : _a.data;
5142
5293
  }
5143
5294
  async initializeInsuranceFundStake(marketIndex, txParams) {
5144
5295
  const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getInitializeInsuranceFundStakeIx(marketIndex), txParams), [], this.opts);
@@ -5146,9 +5297,13 @@ class DriftClient {
5146
5297
  }
5147
5298
  async getInitializeInsuranceFundStakeIx(marketIndex) {
5148
5299
  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
+ }
5149
5304
  const accounts = {
5150
5305
  insuranceFundStake: ifStakeAccountPublicKey,
5151
- spotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
5306
+ spotMarket: spotMarket.pubkey,
5152
5307
  userStats: (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, this.wallet.publicKey // only allow payer to initialize own insurance fund stake account
5153
5308
  ),
5154
5309
  authority: this.wallet.publicKey,
@@ -5163,6 +5318,9 @@ class DriftClient {
5163
5318
  }
5164
5319
  async getAddInsuranceFundStakeIx(marketIndex, amount, collateralAccountPublicKey) {
5165
5320
  const spotMarket = this.getSpotMarketAccount(marketIndex);
5321
+ if (!spotMarket) {
5322
+ throw new Error(`Spot market account not found for index ${marketIndex}`);
5323
+ }
5166
5324
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
5167
5325
  const remainingAccounts = [];
5168
5326
  this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
@@ -5210,6 +5368,9 @@ class DriftClient {
5210
5368
  async getAddInsuranceFundStakeIxs({ marketIndex, amount, collateralAccountPublicKey, initializeStakeAccount, fromSubaccount, }) {
5211
5369
  const addIfStakeIxs = [];
5212
5370
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
5371
+ if (!spotMarketAccount) {
5372
+ throw new Error(`Spot market account not found for index ${marketIndex}`);
5373
+ }
5213
5374
  const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
5214
5375
  const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
5215
5376
  const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarketAccount);
@@ -5248,6 +5409,9 @@ class DriftClient {
5248
5409
  }
5249
5410
  async requestRemoveInsuranceFundStake(marketIndex, amount, txParams) {
5250
5411
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
5412
+ if (!spotMarketAccount) {
5413
+ throw new Error(`Spot market account not found for index ${marketIndex}`);
5414
+ }
5251
5415
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
5252
5416
  const ix = await this.program.instruction.requestRemoveInsuranceFundStake(marketIndex, amount, {
5253
5417
  accounts: {
@@ -5266,6 +5430,9 @@ class DriftClient {
5266
5430
  }
5267
5431
  async cancelRequestRemoveInsuranceFundStake(marketIndex, txParams) {
5268
5432
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
5433
+ if (!spotMarketAccount) {
5434
+ throw new Error(`Spot market account not found for index ${marketIndex}`);
5435
+ }
5269
5436
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
5270
5437
  const ix = await this.program.instruction.cancelRequestRemoveInsuranceFundStake(marketIndex, {
5271
5438
  accounts: {
@@ -5285,6 +5452,9 @@ class DriftClient {
5285
5452
  async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey, txParams) {
5286
5453
  const removeIfStakeIxs = [];
5287
5454
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
5455
+ if (!spotMarketAccount) {
5456
+ throw new Error(`Spot market account not found for index ${marketIndex}`);
5457
+ }
5288
5458
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
5289
5459
  const additionalSigners = [];
5290
5460
  const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
@@ -5344,6 +5514,9 @@ class DriftClient {
5344
5514
  async getUpdateUserQuoteAssetInsuranceStakeIx(authority) {
5345
5515
  const marketIndex = numericConstants_1.QUOTE_SPOT_MARKET_INDEX;
5346
5516
  const spotMarket = this.getSpotMarketAccount(marketIndex);
5517
+ if (!spotMarket) {
5518
+ throw new Error(`Spot market account not found for index ${marketIndex}`);
5519
+ }
5347
5520
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, authority, marketIndex);
5348
5521
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, authority);
5349
5522
  const ix = this.program.instruction.updateUserQuoteAssetInsuranceStake({
@@ -5367,6 +5540,9 @@ class DriftClient {
5367
5540
  async getUpdateUserGovTokenInsuranceStakeIx(authority) {
5368
5541
  const marketIndex = numericConstants_1.GOV_SPOT_MARKET_INDEX;
5369
5542
  const spotMarket = this.getSpotMarketAccount(marketIndex);
5543
+ if (!spotMarket) {
5544
+ throw new Error(`Spot market account not found for index ${marketIndex}`);
5545
+ }
5370
5546
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, authority, marketIndex);
5371
5547
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, authority);
5372
5548
  const ix = this.program.instruction.updateUserGovTokenInsuranceStake({
@@ -5388,6 +5564,9 @@ class DriftClient {
5388
5564
  }
5389
5565
  async getSettleRevenueToInsuranceFundIx(spotMarketIndex) {
5390
5566
  const spotMarketAccount = this.getSpotMarketAccount(spotMarketIndex);
5567
+ if (!spotMarketAccount) {
5568
+ throw new Error(`Spot market account not found for index ${spotMarketIndex}`);
5569
+ }
5391
5570
  const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarketAccount);
5392
5571
  const remainingAccounts = [];
5393
5572
  this.addTokenMintToRemainingAccounts(spotMarketAccount, remainingAccounts);
@@ -5412,12 +5591,19 @@ class DriftClient {
5412
5591
  return txSig;
5413
5592
  }
5414
5593
  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
+ }
5415
5598
  const remainingAccounts = this.getRemainingAccounts({
5416
- userAccounts: [this.getUserAccount()],
5599
+ userAccounts: [userAccount],
5417
5600
  writablePerpMarketIndexes: [perpMarketIndex],
5418
5601
  writableSpotMarketIndexes: [spotMarketIndex],
5419
5602
  });
5420
5603
  const spotMarket = this.getSpotMarketAccount(spotMarketIndex);
5604
+ if (!spotMarket) {
5605
+ throw new Error(`Spot market account not found for index ${spotMarketIndex}`);
5606
+ }
5421
5607
  const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarket);
5422
5608
  return await this.program.instruction.resolvePerpPnlDeficit(spotMarketIndex, perpMarketIndex, {
5423
5609
  accounts: {
@@ -5433,6 +5619,9 @@ class DriftClient {
5433
5619
  }
5434
5620
  async getDepositIntoSpotMarketRevenuePoolIx(marketIndex, amount, userTokenAccountPublicKey) {
5435
5621
  const spotMarket = await this.getSpotMarketAccount(marketIndex);
5622
+ if (!spotMarket) {
5623
+ throw new Error(`Spot market account not found for index ${marketIndex}`);
5624
+ }
5436
5625
  const remainingAccounts = [];
5437
5626
  this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
5438
5627
  if (this.isTransferHook(spotMarket)) {
@@ -5467,7 +5656,13 @@ class DriftClient {
5467
5656
  getPerpMarketExtendedInfo(marketIndex) {
5468
5657
  var _a, _b;
5469
5658
  const marketAccount = this.getPerpMarketAccount(marketIndex);
5659
+ if (!marketAccount) {
5660
+ return undefined;
5661
+ }
5470
5662
  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
+ }
5471
5666
  const extendedInfo = {
5472
5667
  marketIndex,
5473
5668
  minOrderSize: (_a = marketAccount.amm) === null || _a === void 0 ? void 0 : _a.minOrderSize,
@@ -5485,7 +5680,7 @@ class DriftClient {
5485
5680
  * @returns : {takerFee: number, makerFee: number} Precision None
5486
5681
  */
5487
5682
  getMarketFees(marketType, marketIndex, user, enteringHighLeverageMode) {
5488
- var _a;
5683
+ var _a, _b;
5489
5684
  let feeTier;
5490
5685
  const userHLM = ((_a = user === null || user === void 0 ? void 0 : user.isHighLeverageMode('Initial')) !== null && _a !== void 0 ? _a : false) ||
5491
5686
  enteringHighLeverageMode;
@@ -5502,17 +5697,19 @@ class DriftClient {
5502
5697
  let makerFee = feeTier.makerRebateNumerator / feeTier.makerRebateDenominator;
5503
5698
  if (marketIndex !== undefined) {
5504
5699
  let marketAccount = null;
5700
+ let feeAdjustment = 1;
5505
5701
  if ((0, types_1.isVariant)(marketType, 'perp')) {
5506
5702
  marketAccount = this.getPerpMarketAccount(marketIndex);
5703
+ feeAdjustment = (_b = marketAccount === null || marketAccount === void 0 ? void 0 : marketAccount.feeAdjustment) !== null && _b !== void 0 ? _b : 0;
5507
5704
  }
5508
5705
  else {
5509
5706
  marketAccount = this.getSpotMarketAccount(marketIndex);
5510
5707
  }
5511
- takerFee += (takerFee * marketAccount.feeAdjustment) / 100;
5708
+ takerFee += (takerFee * feeAdjustment) / 100;
5512
5709
  if (userHLM) {
5513
5710
  takerFee *= 2;
5514
5711
  }
5515
- makerFee += (makerFee * marketAccount.feeAdjustment) / 100;
5712
+ makerFee += (makerFee * feeAdjustment) / 100;
5516
5713
  }
5517
5714
  return {
5518
5715
  takerFee,
@@ -5696,6 +5893,9 @@ class DriftClient {
5696
5893
  // @deprecated use getPostManySwitchboardOnDemandUpdatesAtomicIxs instead. This function no longer returns the required ixs due to upstream sdk changes.
5697
5894
  async getPostSwitchboardOnDemandUpdateAtomicIx(feed, recentSlothash, numSignatures = 3) {
5698
5895
  const program = await this.getSwitchboardOnDemandProgram();
5896
+ if (!program) {
5897
+ return undefined;
5898
+ }
5699
5899
  const feedAccount = new on_demand_1.PullFeed(program, feed);
5700
5900
  if (!this.sbProgramFeedConfigs) {
5701
5901
  this.sbProgramFeedConfigs = new Map();
@@ -5783,11 +5983,14 @@ class DriftClient {
5783
5983
  return txSig;
5784
5984
  }
5785
5985
  async getEnableHighLeverageModeIx(subAccountId, depositToTradeArgs, overrides) {
5786
- var _a, _b, _c, _d;
5986
+ var _a, _b, _c, _d, _e;
5787
5987
  const isDepositToTradeTx = depositToTradeArgs !== undefined;
5788
5988
  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);
5789
5989
  const signingAuthority = (_c = overrides === null || overrides === void 0 ? void 0 : overrides.signingAuthority) !== null && _c !== void 0 ? _c : this.wallet.publicKey;
5790
- const userAccount = (_d = overrides === null || overrides === void 0 ? void 0 : overrides.user.getUserAccount()) !== null && _d !== void 0 ? _d : this.getUserAccount(subAccountId);
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
+ }
5791
5994
  const remainingAccounts = this.getRemainingAccounts({
5792
5995
  userAccounts: (depositToTradeArgs === null || depositToTradeArgs === void 0 ? void 0 : depositToTradeArgs.isMakingNewAccount) ? [] : [userAccount],
5793
5996
  useMarketLastSlotCache: false,
@@ -5853,6 +6056,9 @@ class DriftClient {
5853
6056
  }
5854
6057
  async getPauseSpotMarketDepositWithdrawIx(spotMarketIndex) {
5855
6058
  const spotMarket = await this.getSpotMarketAccount(spotMarketIndex);
6059
+ if (!spotMarket) {
6060
+ throw new Error(`Spot market account not found for index ${spotMarketIndex}`);
6061
+ }
5856
6062
  return this.program.instruction.pauseSpotMarketDepositWithdraw({
5857
6063
  accounts: {
5858
6064
  state: await this.getStatePublicKey(),
@@ -5881,12 +6087,16 @@ class DriftClient {
5881
6087
  data.set(discriminatorBuffer, 0);
5882
6088
  data.set(oraclePrice.toArrayLike(Buffer, 'le', 8), 5); // next 8 bytes
5883
6089
  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
+ }
5884
6094
  // Build the instruction manually
5885
6095
  return new web3_js_1.TransactionInstruction({
5886
6096
  programId: this.program.programId,
5887
6097
  keys: [
5888
6098
  {
5889
- pubkey: this.getPerpMarketAccount(marketIndex).pubkey,
6099
+ pubkey: perpMarket.pubkey,
5890
6100
  isWritable: true,
5891
6101
  isSigner: false,
5892
6102
  },
@@ -5924,12 +6134,16 @@ class DriftClient {
5924
6134
  const data = Buffer.alloc(discriminatorBuffer.length + 4);
5925
6135
  data.set(discriminatorBuffer, 0);
5926
6136
  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
+ }
5927
6141
  // Build the instruction manually
5928
6142
  return new web3_js_1.TransactionInstruction({
5929
6143
  programId: this.program.programId,
5930
6144
  keys: [
5931
6145
  {
5932
- pubkey: this.getPerpMarketAccount(marketIndex).pubkey,
6146
+ pubkey: perpMarket.pubkey,
5933
6147
  isWritable: true,
5934
6148
  isSigner: false,
5935
6149
  },
@@ -6018,12 +6232,16 @@ class DriftClient {
6018
6232
  userAccounts: [],
6019
6233
  readablePerpMarketIndex: perpMarketIndexes,
6020
6234
  });
6235
+ const quoteMarket = this.getSpotMarketAccount(0);
6236
+ if (!quoteMarket) {
6237
+ throw new Error(`Quote spot market account not found for index 0`);
6238
+ }
6021
6239
  return this.program.instruction.updateAmmCache({
6022
6240
  accounts: {
6023
6241
  state: await this.getStatePublicKey(),
6024
6242
  keeper: this.wallet.publicKey,
6025
6243
  ammCache: (0, pda_1.getAmmCachePublicKey)(this.program.programId),
6026
- quoteMarket: this.getSpotMarketAccount(0).pubkey,
6244
+ quoteMarket: quoteMarket.pubkey,
6027
6245
  },
6028
6246
  remainingAccounts,
6029
6247
  });
@@ -6034,6 +6252,9 @@ class DriftClient {
6034
6252
  }
6035
6253
  async getUpdateConstituentOracleInfoIx(constituent) {
6036
6254
  const spotMarket = this.getSpotMarketAccount(constituent.spotMarketIndex);
6255
+ if (!spotMarket) {
6256
+ throw new Error(`Spot market account not found for index ${constituent.spotMarketIndex}`);
6257
+ }
6037
6258
  return this.program.instruction.updateConstituentOracleInfo({
6038
6259
  accounts: {
6039
6260
  keeper: this.wallet.publicKey,
@@ -6055,12 +6276,20 @@ class DriftClient {
6055
6276
  });
6056
6277
  const constituentInTokenAccount = (0, pda_1.getConstituentVaultPublicKey)(this.program.programId, lpPool, inMarketIndex);
6057
6278
  const constituentOutTokenAccount = (0, pda_1.getConstituentVaultPublicKey)(this.program.programId, lpPool, outMarketIndex);
6058
- const userInTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(this.getSpotMarketAccount(inMarketIndex).mint, userAuthority);
6059
- const userOutTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(this.getSpotMarketAccount(outMarketIndex).mint, userAuthority);
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);
6060
6289
  const inConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool, inMarketIndex);
6061
6290
  const outConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool, outMarketIndex);
6062
- const inMarketMint = this.getSpotMarketAccount(inMarketIndex).mint;
6063
- const outMarketMint = this.getSpotMarketAccount(outMarketIndex).mint;
6291
+ const inMarketMint = inSpotMarket.mint;
6292
+ const outMarketMint = outSpotMarket.mint;
6064
6293
  const constituentTargetBase = (0, pda_1.getConstituentTargetBasePublicKey)(this.program.programId, lpPool);
6065
6294
  return this.program.instruction.lpPoolSwap(inMarketIndex, outMarketIndex, inAmount, minOutAmount, {
6066
6295
  remainingAccounts,
@@ -6133,6 +6362,9 @@ class DriftClient {
6133
6362
  writableSpotMarketIndexes: [inMarketIndex],
6134
6363
  });
6135
6364
  const spotMarket = this.getSpotMarketAccount(inMarketIndex);
6365
+ if (!spotMarket) {
6366
+ throw new Error(`Spot market account not found for index ${inMarketIndex}`);
6367
+ }
6136
6368
  const inMarketMint = spotMarket.mint;
6137
6369
  const isSolMarket = inMarketMint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
6138
6370
  let wSolTokenAccount;
@@ -6228,6 +6460,9 @@ class DriftClient {
6228
6460
  writableSpotMarketIndexes: [outMarketIndex],
6229
6461
  });
6230
6462
  const spotMarket = this.getSpotMarketAccount(outMarketIndex);
6463
+ if (!spotMarket) {
6464
+ throw new Error(`Spot market account not found for index ${outMarketIndex}`);
6465
+ }
6231
6466
  const outMarketMint = spotMarket.mint;
6232
6467
  const outConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool.pubkey, outMarketIndex);
6233
6468
  if (outMarketMint.equals(spotMarkets_1.WRAPPED_SOL_MINT)) {
@@ -6274,6 +6509,9 @@ class DriftClient {
6274
6509
  writableSpotMarketIndexes: [outMarketIndex],
6275
6510
  });
6276
6511
  const spotMarket = this.getSpotMarketAccount(outMarketIndex);
6512
+ if (!spotMarket) {
6513
+ throw new Error(`Spot market account not found for index ${outMarketIndex}`);
6514
+ }
6277
6515
  const outMarketMint = spotMarket.mint;
6278
6516
  const outConstituent = (0, pda_1.getConstituentPublicKey)(this.program.programId, lpPool.pubkey, outMarketIndex);
6279
6517
  const lpMint = lpPool.mint;
@@ -6372,8 +6610,9 @@ class DriftClient {
6372
6610
  async getSettlePerpToLpPoolIx(lpPoolId, perpMarketIndexes) {
6373
6611
  const remainingAccounts = [];
6374
6612
  remainingAccounts.push(...perpMarketIndexes.map((index) => {
6613
+ var _a, _b;
6375
6614
  return {
6376
- pubkey: this.getPerpMarketAccount(index).pubkey,
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,
6377
6616
  isSigner: false,
6378
6617
  isWritable: true,
6379
6618
  };
@@ -6437,12 +6676,13 @@ class DriftClient {
6437
6676
  }
6438
6677
  }
6439
6678
  async buildTransaction(instructions, txParams, txVersion, lookupTables, forceVersionedTransaction, recentBlockhash, optionalIxs) {
6679
+ var _a, _b;
6440
6680
  return this.txHandler.buildTransaction({
6441
6681
  instructions,
6442
6682
  txVersion: txVersion !== null && txVersion !== void 0 ? txVersion : this.txVersion,
6443
6683
  txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
6444
6684
  connection: this.connection,
6445
- preFlightCommitment: this.opts.preflightCommitment,
6685
+ preFlightCommitment: (_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.preflightCommitment) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_COMMITMENT_LEVEL,
6446
6686
  fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
6447
6687
  lookupTables,
6448
6688
  forceVersionedTransaction,
@@ -6451,36 +6691,40 @@ class DriftClient {
6451
6691
  });
6452
6692
  }
6453
6693
  async buildBulkTransactions(instructions, txParams, txVersion, lookupTables, forceVersionedTransaction) {
6454
- return this.txHandler.buildBulkTransactions({
6694
+ var _a, _b;
6695
+ const txns = await this.txHandler.buildBulkTransactions({
6455
6696
  instructions,
6456
6697
  txVersion: txVersion !== null && txVersion !== void 0 ? txVersion : this.txVersion,
6457
6698
  txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
6458
6699
  connection: this.connection,
6459
- preFlightCommitment: this.opts.preflightCommitment,
6700
+ preFlightCommitment: (_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.preflightCommitment) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_COMMITMENT_LEVEL,
6460
6701
  fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
6461
6702
  lookupTables,
6462
6703
  forceVersionedTransaction,
6463
6704
  });
6705
+ return txns.filter(Boolean);
6464
6706
  }
6465
6707
  async buildTransactionsMap(instructionsMap, txParams, txVersion, lookupTables, forceVersionedTransaction) {
6708
+ var _a, _b;
6466
6709
  return this.txHandler.buildTransactionsMap({
6467
6710
  instructionsMap,
6468
6711
  txVersion: txVersion !== null && txVersion !== void 0 ? txVersion : this.txVersion,
6469
6712
  txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
6470
6713
  connection: this.connection,
6471
- preFlightCommitment: this.opts.preflightCommitment,
6714
+ preFlightCommitment: (_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.preflightCommitment) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_COMMITMENT_LEVEL,
6472
6715
  fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
6473
6716
  lookupTables,
6474
6717
  forceVersionedTransaction,
6475
6718
  });
6476
6719
  }
6477
6720
  async buildAndSignTransactionsMap(instructionsMap, txParams, txVersion, lookupTables, forceVersionedTransaction) {
6721
+ var _a, _b;
6478
6722
  return this.txHandler.buildAndSignTransactionMap({
6479
6723
  instructionsMap,
6480
6724
  txVersion: txVersion !== null && txVersion !== void 0 ? txVersion : this.txVersion,
6481
6725
  txParams: txParams !== null && txParams !== void 0 ? txParams : this.txParams,
6482
6726
  connection: this.connection,
6483
- preFlightCommitment: this.opts.preflightCommitment,
6727
+ preFlightCommitment: (_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.preflightCommitment) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_COMMITMENT_LEVEL,
6484
6728
  fetchAllMarketLookupTableAccounts: this.fetchAllLookupTableAccounts.bind(this),
6485
6729
  lookupTables,
6486
6730
  forceVersionedTransaction,