@quicknode/sdk 2.2.1 → 2.2.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/cjs/index.js +12 -8
- package/esm/solana/solana.js +12 -8
- package/package.json +1 -1
package/cjs/index.js
CHANGED
|
@@ -383,16 +383,19 @@ class Solana {
|
|
|
383
383
|
*/
|
|
384
384
|
async prepareSmartTransaction(args) {
|
|
385
385
|
const { transaction, payerPublicKey, feeLevel = 'medium' } = args;
|
|
386
|
-
//
|
|
387
|
-
//
|
|
388
|
-
const
|
|
389
|
-
|
|
386
|
+
// Send simulation with placeholders so the value calculated is accurate
|
|
387
|
+
// placeholders kept low to avoid InsufficientFundsForFee error with the high cu budget limit
|
|
388
|
+
const simulationInstructions = [
|
|
389
|
+
web3_js.ComputeBudgetProgram.setComputeUnitPrice({
|
|
390
|
+
microLamports: 1,
|
|
391
|
+
}),
|
|
392
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1400000 }),
|
|
390
393
|
...transaction.instructions,
|
|
391
|
-
computeUnitPriceInstruction,
|
|
392
394
|
];
|
|
393
395
|
// eslint-disable-next-line prefer-const
|
|
394
|
-
let [units, recentBlockhash] = await Promise.all([
|
|
395
|
-
this.getSimulationUnits(this.connection,
|
|
396
|
+
let [units, computeUnitPriceInstruction, recentBlockhash] = await Promise.all([
|
|
397
|
+
this.getSimulationUnits(this.connection, simulationInstructions, payerPublicKey),
|
|
398
|
+
this.createDynamicPriorityFeeInstruction(feeLevel),
|
|
396
399
|
this.connection.getLatestBlockhash(),
|
|
397
400
|
]);
|
|
398
401
|
transaction.add(computeUnitPriceInstruction);
|
|
@@ -446,7 +449,8 @@ class Solana {
|
|
|
446
449
|
sigVerify: false,
|
|
447
450
|
});
|
|
448
451
|
if (simulation.value.err) {
|
|
449
|
-
|
|
452
|
+
console.error('Simulation error:', simulation.value.err);
|
|
453
|
+
throw new Error(`Failed to simulate transaction ${simulation.value.err}`);
|
|
450
454
|
}
|
|
451
455
|
return simulation.value.unitsConsumed;
|
|
452
456
|
}
|
package/esm/solana/solana.js
CHANGED
|
@@ -28,16 +28,19 @@ class Solana {
|
|
|
28
28
|
*/
|
|
29
29
|
async prepareSmartTransaction(args) {
|
|
30
30
|
const { transaction, payerPublicKey, feeLevel = 'medium' } = args;
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
const
|
|
34
|
-
|
|
31
|
+
// Send simulation with placeholders so the value calculated is accurate
|
|
32
|
+
// placeholders kept low to avoid InsufficientFundsForFee error with the high cu budget limit
|
|
33
|
+
const simulationInstructions = [
|
|
34
|
+
ComputeBudgetProgram.setComputeUnitPrice({
|
|
35
|
+
microLamports: 1,
|
|
36
|
+
}),
|
|
37
|
+
ComputeBudgetProgram.setComputeUnitLimit({ units: 1400000 }),
|
|
35
38
|
...transaction.instructions,
|
|
36
|
-
computeUnitPriceInstruction,
|
|
37
39
|
];
|
|
38
40
|
// eslint-disable-next-line prefer-const
|
|
39
|
-
let [units, recentBlockhash] = await Promise.all([
|
|
40
|
-
this.getSimulationUnits(this.connection,
|
|
41
|
+
let [units, computeUnitPriceInstruction, recentBlockhash] = await Promise.all([
|
|
42
|
+
this.getSimulationUnits(this.connection, simulationInstructions, payerPublicKey),
|
|
43
|
+
this.createDynamicPriorityFeeInstruction(feeLevel),
|
|
41
44
|
this.connection.getLatestBlockhash(),
|
|
42
45
|
]);
|
|
43
46
|
transaction.add(computeUnitPriceInstruction);
|
|
@@ -91,7 +94,8 @@ class Solana {
|
|
|
91
94
|
sigVerify: false,
|
|
92
95
|
});
|
|
93
96
|
if (simulation.value.err) {
|
|
94
|
-
|
|
97
|
+
console.error('Simulation error:', simulation.value.err);
|
|
98
|
+
throw new Error(`Failed to simulate transaction ${simulation.value.err}`);
|
|
95
99
|
}
|
|
96
100
|
return simulation.value.unitsConsumed;
|
|
97
101
|
}
|