Skip to content

Commit

Permalink
Stop paying priority fees in tokens to rent (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass authored Dec 21, 2023
1 parent 86299d0 commit c74ea32
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/tokens-to-rent-service/src/jupiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
import { ACCOUNT_SIZE, NATIVE_MINT, getMint } from "@solana/spl-token";
import {
AddressLookupTableAccount,
ComputeBudgetInstruction,
LAMPORTS_PER_SOL,
PublicKey,
SystemProgram,
TransactionInstruction,
Expand Down Expand Up @@ -156,14 +158,31 @@ export const fundFees = async ({
lamports: ataRent,
});

const budgetInstructions = computeBudgetInstructions.map(
instructionDataToTransactionInstruction
);
let fee = 10000;
if (budgetInstructions.length == 2) {
const units = ComputeBudgetInstruction.decodeRequestUnits(
budgetInstructions[0]!
);
const limit = ComputeBudgetInstruction.decodeSetComputeUnitPrice(
budgetInstructions[1]!
);
fee += Math.ceil(units.units * Number(limit.microLamports)) / 1000000;
if (fee / LAMPORTS_PER_SOL > 0.01) {
throw new Error("Priority fees are too high right now, try again later");
}
}

const repayIx = SystemProgram.transfer({
fromPubkey: userWallet,
toPubkey: platformWallet.publicKey,
lamports: ataRent + 10000,
lamports: ataRent + fee,
});

const instructions: TransactionInstruction[] = [
...computeBudgetInstructions.map(instructionDataToTransactionInstruction),
...budgetInstructions,
borrowIx,
...setupInstructions.map(instructionDataToTransactionInstruction),
instructionDataToTransactionInstruction(swapInstruction),
Expand Down

0 comments on commit c74ea32

Please sign in to comment.