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

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.2
@@ -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;
@@ -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.2",
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) {
@@ -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;