@drift-labs/sdk 2.28.0-beta.4 → 2.28.0-beta.5

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.
@@ -49,6 +49,8 @@ const spotMarkets_1 = require("./constants/spotMarkets");
49
49
  const userStats_1 = require("./userStats");
50
50
  const spotPosition_1 = require("./math/spotPosition");
51
51
  const market_1 = require("./math/market");
52
+ const fetch_1 = require("./accounts/fetch");
53
+ const spotMarket_1 = require("./math/spotMarket");
52
54
  /**
53
55
  * # DriftClient
54
56
  * 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.
@@ -61,7 +63,7 @@ class DriftClient {
61
63
  this._isSubscribed = val;
62
64
  }
63
65
  constructor(config) {
64
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
66
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
65
67
  this.users = new Map();
66
68
  this._isSubscribed = false;
67
69
  this.perpMarketLastSlotCache = new Map();
@@ -70,10 +72,11 @@ class DriftClient {
70
72
  this.wallet = config.wallet;
71
73
  this.opts = config.opts || anchor_1.AnchorProvider.defaultOptions();
72
74
  this.provider = new anchor_1.AnchorProvider(config.connection, config.wallet, this.opts);
73
- this.program = new anchor_1.Program(drift_json_1.default, config.programID, this.provider);
74
- this.authority = (_a = config.authority) !== null && _a !== void 0 ? _a : this.wallet.publicKey;
75
- this.activeSubAccountId = (_b = config.activeSubAccountId) !== null && _b !== void 0 ? _b : 0;
76
- this.skipLoadUsers = (_c = config.skipLoadUsers) !== null && _c !== void 0 ? _c : false;
75
+ this.program = new anchor_1.Program(drift_json_1.default, (_a = config.programID) !== null && _a !== void 0 ? _a : new web3_js_1.PublicKey(config_1.DRIFT_PROGRAM_ID), this.provider);
76
+ this.authority = (_b = config.authority) !== null && _b !== void 0 ? _b : this.wallet.publicKey;
77
+ this.activeSubAccountId = (_c = config.activeSubAccountId) !== null && _c !== void 0 ? _c : 0;
78
+ this.skipLoadUsers = (_d = config.skipLoadUsers) !== null && _d !== void 0 ? _d : false;
79
+ this.txVersion = (_e = config.txVersion) !== null && _e !== void 0 ? _e : 'legacy';
77
80
  if (config.includeDelegates && config.subAccountIds) {
78
81
  throw new Error('Can only pass one of includeDelegates or subAccountIds. If you want to specify subaccount ids for multiple authorities, pass authoritySubaccountMap instead');
79
82
  }
@@ -88,9 +91,9 @@ class DriftClient {
88
91
  : config.subAccountIds
89
92
  ? new Map([[this.authority.toString(), config.subAccountIds]])
90
93
  : new Map();
91
- this.includeDelegates = (_d = config.includeDelegates) !== null && _d !== void 0 ? _d : false;
94
+ this.includeDelegates = (_f = config.includeDelegates) !== null && _f !== void 0 ? _f : false;
92
95
  this.userAccountSubscriptionConfig =
93
- ((_e = config.accountSubscription) === null || _e === void 0 ? void 0 : _e.type) === 'polling'
96
+ ((_g = config.accountSubscription) === null || _g === void 0 ? void 0 : _g.type) === 'polling'
94
97
  ? {
95
98
  type: 'polling',
96
99
  accountLoader: config.accountSubscription.accountLoader,
@@ -122,14 +125,14 @@ class DriftClient {
122
125
  if (config.env && !this.marketLookupTable) {
123
126
  this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[config.env].MARKET_LOOKUP_TABLE);
124
127
  }
125
- if (((_f = config.accountSubscription) === null || _f === void 0 ? void 0 : _f.type) === 'polling') {
128
+ if (((_h = config.accountSubscription) === null || _h === void 0 ? void 0 : _h.type) === 'polling') {
126
129
  this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, perpMarketIndexes !== null && perpMarketIndexes !== void 0 ? perpMarketIndexes : [], spotMarketIndexes !== null && spotMarketIndexes !== void 0 ? spotMarketIndexes : [], oracleInfos !== null && oracleInfos !== void 0 ? oracleInfos : []);
127
130
  }
128
131
  else {
129
132
  this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, perpMarketIndexes !== null && perpMarketIndexes !== void 0 ? perpMarketIndexes : [], spotMarketIndexes !== null && spotMarketIndexes !== void 0 ? spotMarketIndexes : [], oracleInfos !== null && oracleInfos !== void 0 ? oracleInfos : []);
130
133
  }
131
134
  this.eventEmitter = this.accountSubscriber.eventEmitter;
132
- this.txSender = new retryTxSender_1.RetryTxSender(this.provider, (_g = config.txSenderConfig) === null || _g === void 0 ? void 0 : _g.timeout, (_h = config.txSenderConfig) === null || _h === void 0 ? void 0 : _h.retrySleep, (_j = config.txSenderConfig) === null || _j === void 0 ? void 0 : _j.additionalConnections);
135
+ this.txSender = new retryTxSender_1.RetryTxSender(this.provider, (_j = config.txSenderConfig) === null || _j === void 0 ? void 0 : _j.timeout, (_k = config.txSenderConfig) === null || _k === void 0 ? void 0 : _k.retrySleep, (_l = config.txSenderConfig) === null || _l === void 0 ? void 0 : _l.additionalConnections);
133
136
  }
134
137
  getUserMapKey(subAccountId, authority) {
135
138
  return `${subAccountId}_${authority.toString()}`;
@@ -442,6 +445,17 @@ class DriftClient {
442
445
  },
443
446
  });
444
447
  }
448
+ async getNextSubAccountId() {
449
+ const userStats = this.getUserStats();
450
+ let userStatsAccount;
451
+ if (!userStats) {
452
+ userStatsAccount = await (0, fetch_1.fetchUserStatsAccount)(this.connection, this.program, this.wallet.publicKey);
453
+ }
454
+ else {
455
+ userStatsAccount = userStats.getAccount();
456
+ }
457
+ return userStatsAccount.numberOfSubAccountsCreated;
458
+ }
445
459
  async initializeReferrerName(name) {
446
460
  const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, 0);
447
461
  const nameBuffer = (0, userName_1.encodeName)(name);
@@ -597,7 +611,7 @@ class DriftClient {
597
611
  state: await this.getStatePublicKey(),
598
612
  },
599
613
  });
600
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(ix, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
614
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(ix, txParams), [], this.opts);
601
615
  const userMapKey = this.getUserMapKey(subAccountId, this.wallet.publicKey);
602
616
  await ((_a = this.users.get(userMapKey)) === null || _a === void 0 ? void 0 : _a.unsubscribe());
603
617
  this.users.delete(userMapKey);
@@ -654,17 +668,45 @@ class DriftClient {
654
668
  return this.getUserAccount().spotPositions.find((spotPosition) => spotPosition.marketIndex === marketIndex);
655
669
  }
656
670
  getQuoteAssetTokenAmount() {
657
- const spotMarket = this.getSpotMarketAccount(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
658
- const spotPosition = this.getSpotPosition(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
659
- return (0, spotBalance_1.getTokenAmount)(spotPosition.scaledBalance, spotMarket, spotPosition.balanceType);
671
+ return this.getTokenAmount(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
660
672
  }
673
+ /**
674
+ * Returns the token amount for a given market. The spot market precision is based on the token mint decimals.
675
+ * Positive if it is a deposit, negative if it is a borrow.
676
+ * @param marketIndex
677
+ */
661
678
  getTokenAmount(marketIndex) {
662
679
  const spotPosition = this.getSpotPosition(marketIndex);
663
680
  if (spotPosition === undefined) {
664
681
  return numericConstants_1.ZERO;
665
682
  }
666
683
  const spotMarket = this.getSpotMarketAccount(marketIndex);
667
- return (0, spotBalance_1.getTokenAmount)(spotPosition.scaledBalance, spotMarket, spotPosition.balanceType);
684
+ return (0, spotBalance_1.getSignedTokenAmount)((0, spotBalance_1.getTokenAmount)(spotPosition.scaledBalance, spotMarket, spotPosition.balanceType), spotPosition.balanceType);
685
+ }
686
+ /**
687
+ * Converts an amount to the spot precision for a given market. The spot market precision is based on the token mint decimals.
688
+ * @param marketIndex
689
+ * @param amount
690
+ */
691
+ convertToSpotPrecision(marketIndex, amount) {
692
+ const spotMarket = this.getSpotMarketAccount(marketIndex);
693
+ return (0, spotMarket_1.castNumberToSpotPrecision)(amount, spotMarket);
694
+ }
695
+ /**
696
+ * Converts an amount to the perp precision. The perp market precision is {@link BASE_PRECISION} (1e9).
697
+ * @param amount
698
+ */
699
+ convertToPerpPrecision(amount) {
700
+ amount = typeof amount === 'number' ? new anchor_1.BN(amount) : amount;
701
+ return amount.mul(numericConstants_1.BASE_PRECISION);
702
+ }
703
+ /**
704
+ * Converts an amount to the price precision. The perp market precision is {@link PRICE_PRECISION} (1e6).
705
+ * @param amount
706
+ */
707
+ convertToPricePrecision(amount) {
708
+ amount = typeof amount === 'number' ? new anchor_1.BN(amount) : amount;
709
+ return amount.mul(numericConstants_1.PRICE_PRECISION);
668
710
  }
669
711
  getRemainingAccounts(params) {
670
712
  var _a;
@@ -902,7 +944,29 @@ class DriftClient {
902
944
  var _a;
903
945
  return (_a = this.getUserAccount()) === null || _a === void 0 ? void 0 : _a.orders.find((order) => order.userOrderId === userOrderId);
904
946
  }
905
- async deposit(amount, marketIndex, collateralAccountPublicKey, subAccountId, reduceOnly = false) {
947
+ /**
948
+ * Get the associated token address for the given spot market
949
+ * @param marketIndex
950
+ * @param useNative
951
+ */
952
+ async getAssociatedTokenAccount(marketIndex, useNative = true) {
953
+ const spotMarket = this.getSpotMarketAccount(marketIndex);
954
+ if (useNative && spotMarket.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT)) {
955
+ return this.wallet.publicKey;
956
+ }
957
+ const mint = spotMarket.mint;
958
+ return await spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mint, this.wallet.publicKey);
959
+ }
960
+ /**
961
+ * Deposit funds into the given spot market
962
+ *
963
+ * @param amount
964
+ * @param marketIndex
965
+ * @param associatedTokenAccount can be the wallet public key if using native sol
966
+ * @param subAccountId
967
+ * @param reduceOnly
968
+ */
969
+ async deposit(amount, marketIndex, associatedTokenAccount, subAccountId, reduceOnly = false) {
906
970
  const tx = new web3_js_1.Transaction();
907
971
  tx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
908
972
  units: 600000,
@@ -911,20 +975,20 @@ class DriftClient {
911
975
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
912
976
  const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
913
977
  const signerAuthority = this.wallet.publicKey;
914
- const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(signerAuthority);
978
+ const createWSOLTokenAccount = isSolMarket && associatedTokenAccount.equals(signerAuthority);
915
979
  if (createWSOLTokenAccount) {
916
980
  const { ixs, signers, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, true);
917
- collateralAccountPublicKey = pubkey;
981
+ associatedTokenAccount = pubkey;
918
982
  ixs.forEach((ix) => {
919
983
  tx.add(ix);
920
984
  });
921
985
  signers.forEach((signer) => additionalSigners.push(signer));
922
986
  }
923
- const depositCollateralIx = await this.getDepositInstruction(amount, marketIndex, collateralAccountPublicKey, subAccountId, reduceOnly, true);
987
+ const depositCollateralIx = await this.getDepositInstruction(amount, marketIndex, associatedTokenAccount, subAccountId, reduceOnly, true);
924
988
  tx.add(depositCollateralIx);
925
989
  // Close the wrapped sol account at the end of the transaction
926
990
  if (createWSOLTokenAccount) {
927
- tx.add(spl_token_1.Token.createCloseAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, collateralAccountPublicKey, signerAuthority, signerAuthority, []));
991
+ tx.add(spl_token_1.Token.createCloseAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, associatedTokenAccount, signerAuthority, signerAuthority, []));
928
992
  }
929
993
  const { txSig, slot } = await this.sendTransaction(tx, additionalSigners, this.opts);
930
994
  this.spotMarketLastSlotCache.set(marketIndex, slot);
@@ -1066,7 +1130,14 @@ class DriftClient {
1066
1130
  await this.addUser(subAccountId);
1067
1131
  return [txSig, userAccountPublicKey];
1068
1132
  }
1069
- async withdraw(amount, marketIndex, userTokenAccount, reduceOnly = false) {
1133
+ /**
1134
+ * Withdraws from a user account. If deposit doesn't already exist, creates a borrow
1135
+ * @param amount
1136
+ * @param marketIndex
1137
+ * @param associatedTokenAddress - the token account to withdraw to. can be the wallet public key if using native sol
1138
+ * @param reduceOnly
1139
+ */
1140
+ async withdraw(amount, marketIndex, associatedTokenAddress, reduceOnly = false) {
1070
1141
  const tx = new web3_js_1.Transaction();
1071
1142
  tx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
1072
1143
  units: 600000,
@@ -1075,27 +1146,27 @@ class DriftClient {
1075
1146
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
1076
1147
  const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
1077
1148
  const authority = this.wallet.publicKey;
1078
- const createWSOLTokenAccount = isSolMarket && userTokenAccount.equals(authority);
1149
+ const createWSOLTokenAccount = isSolMarket && associatedTokenAddress.equals(authority);
1079
1150
  if (createWSOLTokenAccount) {
1080
1151
  const { ixs, signers, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, false);
1081
- userTokenAccount = pubkey;
1152
+ associatedTokenAddress = pubkey;
1082
1153
  ixs.forEach((ix) => {
1083
1154
  tx.add(ix);
1084
1155
  });
1085
1156
  signers.forEach((signer) => additionalSigners.push(signer));
1086
1157
  }
1087
1158
  else {
1088
- const accountExists = await this.checkIfAccountExists(userTokenAccount);
1159
+ const accountExists = await this.checkIfAccountExists(associatedTokenAddress);
1089
1160
  if (!accountExists) {
1090
- const createAssociatedTokenAccountIx = this.getAssociatedTokenAccountCreationIx(spotMarketAccount.mint, userTokenAccount);
1161
+ const createAssociatedTokenAccountIx = this.getAssociatedTokenAccountCreationIx(spotMarketAccount.mint, associatedTokenAddress);
1091
1162
  tx.add(createAssociatedTokenAccountIx);
1092
1163
  }
1093
1164
  }
1094
- const withdrawCollateral = await this.getWithdrawIx(amount, spotMarketAccount.marketIndex, userTokenAccount, reduceOnly);
1165
+ const withdrawCollateral = await this.getWithdrawIx(amount, spotMarketAccount.marketIndex, associatedTokenAddress, reduceOnly);
1095
1166
  tx.add(withdrawCollateral);
1096
1167
  // Close the wrapped sol account at the end of the transaction
1097
1168
  if (createWSOLTokenAccount) {
1098
- tx.add(spl_token_1.Token.createCloseAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, userTokenAccount, authority, authority, []));
1169
+ tx.add(spl_token_1.Token.createCloseAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, associatedTokenAddress, authority, authority, []));
1099
1170
  }
1100
1171
  const { txSig, slot } = await this.sendTransaction(tx, additionalSigners, this.opts);
1101
1172
  this.spotMarketLastSlotCache.set(marketIndex, slot);
@@ -1125,8 +1196,16 @@ class DriftClient {
1125
1196
  remainingAccounts,
1126
1197
  });
1127
1198
  }
1199
+ /**
1200
+ * Withdraws from the fromSubAccount and deposits into the toSubAccount
1201
+ * @param amount
1202
+ * @param marketIndex
1203
+ * @param fromSubAccountId
1204
+ * @param toSubAccountId
1205
+ * @param txParams
1206
+ */
1128
1207
  async transferDeposit(amount, marketIndex, fromSubAccountId, toSubAccountId, txParams) {
1129
- const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getTransferDepositIx(amount, marketIndex, fromSubAccountId, toSubAccountId), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1208
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getTransferDepositIx(amount, marketIndex, fromSubAccountId, toSubAccountId), txParams), [], this.opts);
1130
1209
  if (fromSubAccountId === this.activeSubAccountId ||
1131
1210
  toSubAccountId === this.activeSubAccountId) {
1132
1211
  this.spotMarketLastSlotCache.set(marketIndex, slot);
@@ -1167,7 +1246,7 @@ class DriftClient {
1167
1246
  });
1168
1247
  }
1169
1248
  async updateSpotMarketCumulativeInterest(marketIndex, txParams) {
1170
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.updateSpotMarketCumulativeInterestIx(marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1249
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.updateSpotMarketCumulativeInterestIx(marketIndex), txParams), [], this.opts);
1171
1250
  return txSig;
1172
1251
  }
1173
1252
  async updateSpotMarketCumulativeInterestIx(marketIndex) {
@@ -1181,7 +1260,7 @@ class DriftClient {
1181
1260
  });
1182
1261
  }
1183
1262
  async settleLP(settleeUserAccountPublicKey, marketIndex, txParams) {
1184
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.settleLPIx(settleeUserAccountPublicKey, marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1263
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.settleLPIx(settleeUserAccountPublicKey, marketIndex), txParams), [], this.opts);
1185
1264
  return txSig;
1186
1265
  }
1187
1266
  async settleLPIx(settleeUserAccountPublicKey, marketIndex) {
@@ -1199,11 +1278,11 @@ class DriftClient {
1199
1278
  });
1200
1279
  }
1201
1280
  async removePerpLpShares(marketIndex, sharesToBurn, txParams) {
1202
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getRemovePerpLpSharesIx(marketIndex, sharesToBurn), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1281
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getRemovePerpLpSharesIx(marketIndex, sharesToBurn), txParams), [], this.opts);
1203
1282
  return txSig;
1204
1283
  }
1205
1284
  async removePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn, txParams) {
1206
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getRemovePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1285
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getRemovePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn), txParams), [], this.opts);
1207
1286
  return txSig;
1208
1287
  }
1209
1288
  async getRemovePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn) {
@@ -1249,7 +1328,7 @@ class DriftClient {
1249
1328
  });
1250
1329
  }
1251
1330
  async addPerpLpShares(amount, marketIndex, txParams) {
1252
- const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getAddPerpLpSharesIx(amount, marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1331
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getAddPerpLpSharesIx(amount, marketIndex), txParams), [], this.opts);
1253
1332
  this.perpMarketLastSlotCache.set(marketIndex, slot);
1254
1333
  return txSig;
1255
1334
  }
@@ -1269,6 +1348,9 @@ class DriftClient {
1269
1348
  remainingAccounts: remainingAccounts,
1270
1349
  });
1271
1350
  }
1351
+ /**
1352
+ * @deprecated use {@link placePerpOrder} or {@link placeAndTakePerpOrder} instead
1353
+ */
1272
1354
  async openPosition(direction, amount, marketIndex, limitPrice) {
1273
1355
  return await this.placeAndTakePerpOrder({
1274
1356
  orderType: types_1.OrderType.MARKET,
@@ -1343,7 +1425,7 @@ class DriftClient {
1343
1425
  }
1344
1426
  }
1345
1427
  async placePerpOrder(orderParams, txParams) {
1346
- const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getPlacePerpOrderIx(orderParams), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1428
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlacePerpOrderIx(orderParams), txParams), [], this.opts);
1347
1429
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
1348
1430
  return txSig;
1349
1431
  }
@@ -1371,7 +1453,7 @@ class DriftClient {
1371
1453
  });
1372
1454
  }
1373
1455
  async updateAMMs(marketIndexes, txParams) {
1374
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getUpdateAMMsIx(marketIndexes), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1456
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateAMMsIx(marketIndexes), txParams), [], this.opts);
1375
1457
  return txSig;
1376
1458
  }
1377
1459
  async getUpdateAMMsIx(marketIndexes) {
@@ -1405,7 +1487,7 @@ class DriftClient {
1405
1487
  });
1406
1488
  }
1407
1489
  async settleExpiredMarket(marketIndex, txParams) {
1408
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getSettleExpiredMarketIx(marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1490
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getSettleExpiredMarketIx(marketIndex), txParams), [], this.opts);
1409
1491
  return txSig;
1410
1492
  }
1411
1493
  async getSettleExpiredMarketIx(marketIndex) {
@@ -1450,11 +1532,11 @@ class DriftClient {
1450
1532
  perpMarket: perpMarketPublicKey,
1451
1533
  },
1452
1534
  });
1453
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(ix, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1535
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(ix, txParams), [], this.opts);
1454
1536
  return txSig;
1455
1537
  }
1456
1538
  async cancelOrder(orderId, txParams) {
1457
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getCancelOrderIx(orderId), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1539
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getCancelOrderIx(orderId), txParams), [], this.opts);
1458
1540
  return txSig;
1459
1541
  }
1460
1542
  async getCancelOrderIx(orderId) {
@@ -1473,7 +1555,7 @@ class DriftClient {
1473
1555
  });
1474
1556
  }
1475
1557
  async cancelOrderByUserId(userOrderId, txParams) {
1476
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getCancelOrderByUserIdIx(userOrderId), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1558
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getCancelOrderByUserIdIx(userOrderId), txParams), [], this.opts);
1477
1559
  return txSig;
1478
1560
  }
1479
1561
  async getCancelOrderByUserIdIx(userOrderId) {
@@ -1495,7 +1577,7 @@ class DriftClient {
1495
1577
  });
1496
1578
  }
1497
1579
  async cancelOrders(marketType, marketIndex, direction, txParams) {
1498
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getCancelOrdersIx(marketType, marketIndex, direction), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1580
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getCancelOrdersIx(marketType, marketIndex, direction), txParams), [], this.opts);
1499
1581
  return txSig;
1500
1582
  }
1501
1583
  async getCancelOrdersIx(marketType, marketIndex, direction) {
@@ -1545,7 +1627,7 @@ class DriftClient {
1545
1627
  return txSig;
1546
1628
  }
1547
1629
  async fillPerpOrder(userAccountPublicKey, user, order, makerInfo, referrerInfo, txParams) {
1548
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1630
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo), txParams), [], this.opts);
1549
1631
  return txSig;
1550
1632
  }
1551
1633
  async getFillPerpOrderIx(userAccountPublicKey, userAccount, order, makerInfo, referrerInfo) {
@@ -1622,7 +1704,7 @@ class DriftClient {
1622
1704
  });
1623
1705
  }
1624
1706
  async placeSpotOrder(orderParams, txParams) {
1625
- const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getPlaceSpotOrderIx(orderParams), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1707
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceSpotOrderIx(orderParams), txParams), [], this.opts);
1626
1708
  this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
1627
1709
  this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
1628
1710
  return txSig;
@@ -1649,7 +1731,7 @@ class DriftClient {
1649
1731
  });
1650
1732
  }
1651
1733
  async fillSpotOrder(userAccountPublicKey, user, order, fulfillmentConfig, makerInfo, referrerInfo, txParams) {
1652
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getFillSpotOrderIx(userAccountPublicKey, user, order, fulfillmentConfig, makerInfo, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1734
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getFillSpotOrderIx(userAccountPublicKey, user, order, fulfillmentConfig, makerInfo, referrerInfo), txParams), [], this.opts);
1653
1735
  return txSig;
1654
1736
  }
1655
1737
  async getFillSpotOrderIx(userAccountPublicKey, userAccount, order, fulfillmentConfig, makerInfo, referrerInfo) {
@@ -1866,7 +1948,7 @@ class DriftClient {
1866
1948
  });
1867
1949
  }
1868
1950
  async triggerOrder(userAccountPublicKey, user, order, txParams) {
1869
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getTriggerOrderIx(userAccountPublicKey, user, order), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1951
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getTriggerOrderIx(userAccountPublicKey, user, order), txParams), [], this.opts);
1870
1952
  return txSig;
1871
1953
  }
1872
1954
  async getTriggerOrderIx(userAccountPublicKey, userAccount, order) {
@@ -1897,7 +1979,7 @@ class DriftClient {
1897
1979
  });
1898
1980
  }
1899
1981
  async forceCancelOrders(userAccountPublicKey, user, txParams) {
1900
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getForceCancelOrdersIx(userAccountPublicKey, user), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1982
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getForceCancelOrdersIx(userAccountPublicKey, user), txParams), [], this.opts);
1901
1983
  return txSig;
1902
1984
  }
1903
1985
  async getForceCancelOrdersIx(userAccountPublicKey, userAccount) {
@@ -1917,7 +1999,7 @@ class DriftClient {
1917
1999
  });
1918
2000
  }
1919
2001
  async updateUserIdle(userAccountPublicKey, user, txParams) {
1920
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getUpdateUserIdleIx(userAccountPublicKey, user), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2002
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateUserIdleIx(userAccountPublicKey, user), txParams), [], this.opts);
1921
2003
  return txSig;
1922
2004
  }
1923
2005
  async getUpdateUserIdleIx(userAccountPublicKey, userAccount) {
@@ -1936,7 +2018,7 @@ class DriftClient {
1936
2018
  });
1937
2019
  }
1938
2020
  async placeAndTakePerpOrder(orderParams, makerInfo, referrerInfo, txParams) {
1939
- const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2021
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo), txParams), [], this.opts);
1940
2022
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
1941
2023
  return txSig;
1942
2024
  }
@@ -1997,7 +2079,7 @@ class DriftClient {
1997
2079
  });
1998
2080
  }
1999
2081
  async placeAndMakePerpOrder(orderParams, takerInfo, referrerInfo, txParams) {
2000
- const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getPlaceAndMakePerpOrderIx(orderParams, takerInfo, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2082
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndMakePerpOrderIx(orderParams, takerInfo, referrerInfo), txParams), [], this.opts);
2001
2083
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
2002
2084
  return txSig;
2003
2085
  }
@@ -2036,7 +2118,7 @@ class DriftClient {
2036
2118
  });
2037
2119
  }
2038
2120
  async placeAndTakeSpotOrder(orderParams, fulfillmentConfig, makerInfo, referrerInfo, txParams) {
2039
- const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getPlaceAndTakeSpotOrderIx(orderParams, fulfillmentConfig, makerInfo, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2121
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndTakeSpotOrderIx(orderParams, fulfillmentConfig, makerInfo, referrerInfo), txParams), [], this.opts);
2040
2122
  this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
2041
2123
  this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
2042
2124
  return txSig;
@@ -2095,7 +2177,7 @@ class DriftClient {
2095
2177
  });
2096
2178
  }
2097
2179
  async placeAndMakeSpotOrder(orderParams, takerInfo, fulfillmentConfig, referrerInfo, txParams) {
2098
- const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getPlaceAndMakeSpotOrderIx(orderParams, takerInfo, fulfillmentConfig, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2180
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndMakeSpotOrderIx(orderParams, takerInfo, fulfillmentConfig, referrerInfo), txParams), [], this.opts);
2099
2181
  this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
2100
2182
  this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
2101
2183
  return txSig;
@@ -2139,9 +2221,7 @@ class DriftClient {
2139
2221
  });
2140
2222
  }
2141
2223
  /**
2142
- * Close an entire position. If you want to reduce a position, use the {@link openPosition} method in the opposite direction of the current position.
2143
- * @param marketIndex
2144
- * @returns
2224
+ * @deprecated use {@link placePerpOrder} or {@link placeAndTakePerpOrder} instead
2145
2225
  */
2146
2226
  async closePosition(marketIndex, limitPrice) {
2147
2227
  const userPosition = this.getUser().getPerpPosition(marketIndex);
@@ -2224,7 +2304,7 @@ class DriftClient {
2224
2304
  immediateOrCancel: immediateOrCancel || null,
2225
2305
  maxTs: maxTs || null,
2226
2306
  };
2227
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getModifyOrderIx(orderId, orderParams), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2307
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getModifyOrderIx(orderId, orderParams), txParams), [], this.opts);
2228
2308
  return txSig;
2229
2309
  }
2230
2310
  async getModifyOrderIx(orderId, orderParams) {
@@ -2276,7 +2356,7 @@ class DriftClient {
2276
2356
  immediateOrCancel: immediateOrCancel || null,
2277
2357
  maxTs: maxTs || null,
2278
2358
  };
2279
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getModifyOrderByUserIdIx(userOrderId, orderParams), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2359
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getModifyOrderByUserIdIx(userOrderId, orderParams), txParams), [], this.opts);
2280
2360
  return txSig;
2281
2361
  }
2282
2362
  async getModifyOrderByUserIdIx(userOrderId, orderParams) {
@@ -2311,7 +2391,7 @@ class DriftClient {
2311
2391
  return txSig;
2312
2392
  }
2313
2393
  async settlePNL(settleeUserAccountPublicKey, settleeUserAccount, marketIndex, txParams) {
2314
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2394
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex), txParams), [], this.opts);
2315
2395
  return txSig;
2316
2396
  }
2317
2397
  async settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex) {
@@ -2331,7 +2411,7 @@ class DriftClient {
2331
2411
  });
2332
2412
  }
2333
2413
  async liquidatePerp(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice, txParams) {
2334
- const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2414
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice), txParams), [], this.opts);
2335
2415
  this.perpMarketLastSlotCache.set(marketIndex, slot);
2336
2416
  return txSig;
2337
2417
  }
@@ -2357,7 +2437,7 @@ class DriftClient {
2357
2437
  });
2358
2438
  }
2359
2439
  async liquidateSpot(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams) {
2360
- const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2440
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice), txParams), [], this.opts);
2361
2441
  this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
2362
2442
  this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
2363
2443
  return txSig;
@@ -2384,7 +2464,7 @@ class DriftClient {
2384
2464
  });
2385
2465
  }
2386
2466
  async liquidateBorrowForPerpPnl(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams) {
2387
- const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2467
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice), txParams), [], this.opts);
2388
2468
  this.perpMarketLastSlotCache.set(perpMarketIndex, slot);
2389
2469
  this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
2390
2470
  return txSig;
@@ -2411,7 +2491,7 @@ class DriftClient {
2411
2491
  });
2412
2492
  }
2413
2493
  async liquidatePerpPnlForDeposit(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice, txParams) {
2414
- const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2494
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice), txParams), [], this.opts);
2415
2495
  this.perpMarketLastSlotCache.set(perpMarketIndex, slot);
2416
2496
  this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
2417
2497
  return txSig;
@@ -2438,7 +2518,7 @@ class DriftClient {
2438
2518
  });
2439
2519
  }
2440
2520
  async resolvePerpBankruptcy(userAccountPublicKey, userAccount, marketIndex, txParams) {
2441
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2521
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex), txParams), [], this.opts);
2442
2522
  return txSig;
2443
2523
  }
2444
2524
  async getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex) {
@@ -2468,7 +2548,7 @@ class DriftClient {
2468
2548
  });
2469
2549
  }
2470
2550
  async resolveSpotBankruptcy(userAccountPublicKey, userAccount, marketIndex, txParams) {
2471
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2551
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex), txParams), [], this.opts);
2472
2552
  return txSig;
2473
2553
  }
2474
2554
  async getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex) {
@@ -2497,7 +2577,7 @@ class DriftClient {
2497
2577
  });
2498
2578
  }
2499
2579
  async updateFundingRate(perpMarketIndex, oracle, txParams) {
2500
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getUpdateFundingRateIx(perpMarketIndex, oracle), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2580
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateFundingRateIx(perpMarketIndex, oracle), txParams), [], this.opts);
2501
2581
  return txSig;
2502
2582
  }
2503
2583
  async getUpdateFundingRateIx(perpMarketIndex, oracle) {
@@ -2511,7 +2591,7 @@ class DriftClient {
2511
2591
  });
2512
2592
  }
2513
2593
  async settleFundingPayment(userAccountPublicKey, txParams) {
2514
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getSettleFundingPaymentIx(userAccountPublicKey), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2594
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getSettleFundingPaymentIx(userAccountPublicKey), txParams), [], this.opts);
2515
2595
  return txSig;
2516
2596
  }
2517
2597
  async getSettleFundingPaymentIx(userAccountPublicKey) {
@@ -2548,7 +2628,7 @@ class DriftClient {
2548
2628
  return oracleData;
2549
2629
  }
2550
2630
  async initializeInsuranceFundStake(marketIndex, txParams) {
2551
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getInitializeInsuranceFundStakeIx(marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2631
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getInitializeInsuranceFundStakeIx(marketIndex), txParams), [], this.opts);
2552
2632
  return txSig;
2553
2633
  }
2554
2634
  async getInitializeInsuranceFundStakeIx(marketIndex) {
@@ -2740,7 +2820,7 @@ class DriftClient {
2740
2820
  return txSig;
2741
2821
  }
2742
2822
  async resolvePerpPnlDeficit(spotMarketIndex, perpMarketIndex, txParams) {
2743
- const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
2823
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex), txParams), [], this.opts);
2744
2824
  return txSig;
2745
2825
  }
2746
2826
  async getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex) {
@@ -2803,7 +2883,47 @@ class DriftClient {
2803
2883
  return undefined;
2804
2884
  }
2805
2885
  sendTransaction(tx, additionalSigners, opts, preSigned) {
2806
- return this.txSender.send(tx, additionalSigners, opts, preSigned);
2886
+ // @ts-ignore
2887
+ if (!tx.message) {
2888
+ return this.txSender.send(tx, additionalSigners, opts, preSigned);
2889
+ }
2890
+ else {
2891
+ return this.txSender.sendVersionedTransaction(tx, additionalSigners, opts);
2892
+ }
2893
+ }
2894
+ async buildTransaction(instructions, txParams) {
2895
+ var _a, _b;
2896
+ const allIx = [];
2897
+ const computeUnits = (_a = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits) !== null && _a !== void 0 ? _a : 600000;
2898
+ if (computeUnits !== 200000) {
2899
+ allIx.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
2900
+ units: computeUnits,
2901
+ }));
2902
+ }
2903
+ const computeUnitsPrice = (_b = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice) !== null && _b !== void 0 ? _b : 0;
2904
+ if (computeUnitsPrice !== 0) {
2905
+ allIx.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
2906
+ microLamports: computeUnitsPrice,
2907
+ }));
2908
+ }
2909
+ if (Array.isArray(instructions)) {
2910
+ allIx.push(...instructions);
2911
+ }
2912
+ else {
2913
+ allIx.push(instructions);
2914
+ }
2915
+ if (this.txVersion === 'legacy') {
2916
+ return new web3_js_1.Transaction().add(...allIx);
2917
+ }
2918
+ else {
2919
+ const marketLookupTable = await this.fetchMarketLookupTableAccount();
2920
+ const message = new web3_js_1.TransactionMessage({
2921
+ payerKey: this.provider.wallet.publicKey,
2922
+ recentBlockhash: (await this.provider.connection.getRecentBlockhash(this.opts.preflightCommitment)).blockhash,
2923
+ instructions: allIx,
2924
+ }).compileToV0Message([marketLookupTable]);
2925
+ return new web3_js_1.VersionedTransaction(message);
2926
+ }
2807
2927
  }
2808
2928
  }
2809
2929
  exports.DriftClient = DriftClient;