Skip to content

Commit

Permalink
Don't repeat simulateTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpmitsch committed Mar 20, 2024
1 parent 55976d2 commit 69ad07a
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions packages/libs/sdk/src/solana/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export class Solana {
*/
async prepareSmartTransaction(args: PrepareSmartTransactionArgs) {
const { transaction, payerPublicKey, feeLevel = 'medium' } = args;
// Need to fetch this ahead of time and add to transaction so it's in the transaction instructions
// for the simulation
const computeUnitPriceInstruction =
await this.createDynamicPriorityFeeInstruction(feeLevel);
const allInstructions = [
Expand All @@ -68,12 +70,7 @@ export class Solana {

// eslint-disable-next-line prefer-const
let [units, recentBlockhash] = await Promise.all([
this.getSimulationUnits(
this.connection,
allInstructions,
payerPublicKey,
feeLevel
),
this.getSimulationUnits(this.connection, allInstructions, payerPublicKey),
this.connection.getLatestBlockhash(),
]);

Expand Down Expand Up @@ -133,16 +130,11 @@ export class Solana {
private async getSimulationUnits(
connection: Connection,
instructions: TransactionInstruction[],
publicKey: PublicKey,
feeLevel: PriorityFeeLevels
publicKey: PublicKey
): Promise<number | undefined> {
const computeUnitPriceInstruction =
await this.createDynamicPriorityFeeInstruction(feeLevel);
const testInstructions = [...instructions, computeUnitPriceInstruction];

const testVersionedTxn = new VersionedTransaction(
new TransactionMessage({
instructions: testInstructions,
instructions: instructions,
payerKey: publicKey,
recentBlockhash: PublicKey.default.toString(), // just a placeholder
}).compileToV0Message()
Expand Down

0 comments on commit 69ad07a

Please sign in to comment.