@drift-labs/sdk 2.85.0-beta.1 → 2.85.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.85.0-beta.1
1
+ 2.85.0-beta.3
@@ -2544,7 +2544,7 @@ class DriftClient {
2544
2544
  };
2545
2545
  if (shouldUseSimulationComputeUnits || shouldExitIfSimulationFails) {
2546
2546
  const placeAndTakeTxToSim = (await this.buildTransaction(placeAndTakeIxs, txParams, undefined, undefined, true, recentBlockHash));
2547
- const simulationResult = await txParamProcessor_1.TransactionParamProcessor.getTxSimComputeUnits(placeAndTakeTxToSim, this.connection, (_a = txParams.computeUnitsBufferMultiplier) !== null && _a !== void 0 ? _a : 1.2);
2547
+ const simulationResult = await txParamProcessor_1.TransactionParamProcessor.getTxSimComputeUnits(placeAndTakeTxToSim, this.connection, (_a = txParams.computeUnitsBufferMultiplier) !== null && _a !== void 0 ? _a : 1.2, txParams.lowerBoundCu);
2548
2548
  if (shouldExitIfSimulationFails && !simulationResult.success) {
2549
2549
  earlyExitFailedPlaceAndTakeSim = true;
2550
2550
  return;
@@ -2586,6 +2586,9 @@ class DriftClient {
2586
2586
  }
2587
2587
  async placeAndTakePerpWithAdditionalOrders(orderParams, makerInfo, referrerInfo, bracketOrdersParams = new Array(), txParams, subAccountId, cancelExistingOrders, settlePnl, exitEarlyIfSimFails) {
2588
2588
  const txsToSign = await this.preparePlaceAndTakePerpOrderWithAdditionalOrders(orderParams, makerInfo, referrerInfo, bracketOrdersParams, txParams, subAccountId, cancelExistingOrders, settlePnl, exitEarlyIfSimFails);
2589
+ if (!txsToSign) {
2590
+ return null;
2591
+ }
2589
2592
  const signedTxs = (await this.txHandler.getSignedTransactionMap(txsToSign, this.provider.wallet)).signedTxMap;
2590
2593
  const { txSig, slot } = await this.sendTransaction(signedTxs.placeAndTakeTx, [], this.opts, true);
2591
2594
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
@@ -8,7 +8,8 @@ type TransactionBuildingProps = {
8
8
  */
9
9
  export declare class TransactionParamProcessor {
10
10
  private static getComputeUnitsFromSim;
11
- static getTxSimComputeUnits(tx: VersionedTransaction, connection: Connection, bufferMultiplier: number): Promise<{
11
+ static getTxSimComputeUnits(tx: VersionedTransaction, connection: Connection, bufferMultiplier: number, // Making this a mandatory param to force the user to remember that simulated CU's can be inaccurate and a buffer should be applied
12
+ lowerBoundCu?: number): Promise<{
12
13
  success: boolean;
13
14
  computeUnits: number;
14
15
  }>;
@@ -15,8 +15,8 @@ class TransactionParamProcessor {
15
15
  }
16
16
  return undefined;
17
17
  }
18
- static async getTxSimComputeUnits(tx, connection, bufferMultiplier // Making this a mandatory param to force the user to remember that simulated CU's can be inaccurate and a buffer should be applied
19
- ) {
18
+ static async getTxSimComputeUnits(tx, connection, bufferMultiplier, // Making this a mandatory param to force the user to remember that simulated CU's can be inaccurate and a buffer should be applied
19
+ lowerBoundCu) {
20
20
  var _a, _b, _c;
21
21
  try {
22
22
  if (TEST_SIMS_ALWAYS_FAIL)
@@ -29,7 +29,11 @@ class TransactionParamProcessor {
29
29
  }
30
30
  const computeUnits = await this.getComputeUnitsFromSim(simTxResult);
31
31
  // Apply the buffer, but round down to the MAX_COMPUTE_UNITS, and round up to the nearest whole number
32
- const bufferedComputeUnits = Math.ceil(Math.min(computeUnits * bufferMultiplier, MAX_COMPUTE_UNITS));
32
+ let bufferedComputeUnits = Math.ceil(Math.min(computeUnits * bufferMultiplier, MAX_COMPUTE_UNITS));
33
+ // If a lower bound CU is passed then enforce it
34
+ if (lowerBoundCu) {
35
+ bufferedComputeUnits = Math.max(bufferedComputeUnits, Math.min(lowerBoundCu, MAX_COMPUTE_UNITS));
36
+ }
33
37
  return {
34
38
  success: true,
35
39
  computeUnits: bufferedComputeUnits,
package/lib/types.d.ts CHANGED
@@ -1085,6 +1085,7 @@ export type ProcessingTxParams = {
1085
1085
  computeUnitsBufferMultiplier?: number;
1086
1086
  useSimulatedComputeUnitsForCUPriceCalculation?: boolean;
1087
1087
  getCUPriceFromComputeUnits?: (computeUnits: number) => number;
1088
+ lowerBoundCu?: number;
1088
1089
  };
1089
1090
  export type TxParams = BaseTxParams & ProcessingTxParams;
1090
1091
  export declare class SwapReduceOnly {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.85.0-beta.1",
3
+ "version": "2.85.0-beta.3",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -4664,7 +4664,8 @@ export class DriftClient {
4664
4664
  await TransactionParamProcessor.getTxSimComputeUnits(
4665
4665
  placeAndTakeTxToSim,
4666
4666
  this.connection,
4667
- txParams.computeUnitsBufferMultiplier ?? 1.2
4667
+ txParams.computeUnitsBufferMultiplier ?? 1.2,
4668
+ txParams.lowerBoundCu
4668
4669
  );
4669
4670
 
4670
4671
  if (shouldExitIfSimulationFails && !simulationResult.success) {
@@ -4784,6 +4785,10 @@ export class DriftClient {
4784
4785
  exitEarlyIfSimFails
4785
4786
  );
4786
4787
 
4788
+ if (!txsToSign) {
4789
+ return null;
4790
+ }
4791
+
4787
4792
  const signedTxs = (
4788
4793
  await this.txHandler.getSignedTransactionMap(
4789
4794
  txsToSign,
@@ -32,7 +32,8 @@ export class TransactionParamProcessor {
32
32
  public static async getTxSimComputeUnits(
33
33
  tx: VersionedTransaction,
34
34
  connection: Connection,
35
- bufferMultiplier: number // Making this a mandatory param to force the user to remember that simulated CU's can be inaccurate and a buffer should be applied
35
+ bufferMultiplier: number, // Making this a mandatory param to force the user to remember that simulated CU's can be inaccurate and a buffer should be applied
36
+ lowerBoundCu?: number
36
37
  ): Promise<{ success: boolean; computeUnits: number }> {
37
38
  try {
38
39
  if (TEST_SIMS_ALWAYS_FAIL)
@@ -49,10 +50,18 @@ export class TransactionParamProcessor {
49
50
  const computeUnits = await this.getComputeUnitsFromSim(simTxResult);
50
51
 
51
52
  // Apply the buffer, but round down to the MAX_COMPUTE_UNITS, and round up to the nearest whole number
52
- const bufferedComputeUnits = Math.ceil(
53
+ let bufferedComputeUnits = Math.ceil(
53
54
  Math.min(computeUnits * bufferMultiplier, MAX_COMPUTE_UNITS)
54
55
  );
55
56
 
57
+ // If a lower bound CU is passed then enforce it
58
+ if (lowerBoundCu) {
59
+ bufferedComputeUnits = Math.max(
60
+ bufferedComputeUnits,
61
+ Math.min(lowerBoundCu, MAX_COMPUTE_UNITS)
62
+ );
63
+ }
64
+
56
65
  return {
57
66
  success: true,
58
67
  computeUnits: bufferedComputeUnits,
package/src/types.ts CHANGED
@@ -1042,6 +1042,7 @@ export type ProcessingTxParams = {
1042
1042
  computeUnitsBufferMultiplier?: number;
1043
1043
  useSimulatedComputeUnitsForCUPriceCalculation?: boolean;
1044
1044
  getCUPriceFromComputeUnits?: (computeUnits: number) => number;
1045
+ lowerBoundCu?: number;
1045
1046
  };
1046
1047
 
1047
1048
  export type TxParams = BaseTxParams & ProcessingTxParams;