@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 +1 -1
- package/lib/driftClient.js +1 -1
- package/lib/tx/txParamProcessor.d.ts +2 -1
- package/lib/tx/txParamProcessor.js +7 -3
- package/lib/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/driftClient.ts +2 -1
- package/src/tx/txParamProcessor.ts +11 -2
- package/src/types.ts +1 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.85.0-beta.
|
|
1
|
+
2.85.0-beta.2
|
package/lib/driftClient.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
package/src/driftClient.ts
CHANGED
|
@@ -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
|
-
|
|
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;
|