Skip to content

Commit

Permalink
feat: handle to full for bundle tip edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
k0beLeenders committed Nov 25, 2024
1 parent 3d9d0ff commit 618a5cc
Showing 1 changed file with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import {
PublicKey,
VersionedTransaction,
TransactionInstruction,
TransactionSignature,
Connection,
Commitment,
ComputeBudgetProgram,
LAMPORTS_PER_SOL,
TransactionMessage,
} from "@solana/web3.js";
import {
isV0Tx,
decompileV0Transaction,
Expand All @@ -9,26 +20,14 @@ import {
sleep,
SolanaTransaction,
TransactionOptions,
decodeComputeBudgetInstruction,
getComputeBudgetUnits,
// PRIORITY_TX_SIZE,
// BUNDLE_TX_SIZE,
// MAX_TX_SIZE,
} from "@mrgnlabs/mrgn-common";
import {
PublicKey,
VersionedTransaction,
TransactionInstruction,
TransactionSignature,
Connection,
TransactionConfirmationStrategy,
Commitment,
ComputeBudgetProgram,
LAMPORTS_PER_SOL,
} from "@solana/web3.js";

import { MARGINFI_IDL, MarginfiIdlType } from "../../idl";
import { makeTxPriorityIx } from "../../models/account";
import { SystemProgram } from "@solana/web3.js";
import { makePriorityFeeMicroIx } from "../../utils";
import { confirmTransaction } from "./transaction.service";

Expand Down Expand Up @@ -80,7 +79,6 @@ const microLamportsToUi = (microLamports: number, limitCU: number = 1_400_000) =
return Math.trunc(priorityFeeUi * LAMPORTS_PER_SOL) / LAMPORTS_PER_SOL;
};

// TODO: add bundle tip tx if fails, measure the size
export function formatTransactions(
transactions: SolanaTransaction[],
broadcastType: TransactionBroadcastType,
Expand Down Expand Up @@ -139,6 +137,17 @@ export function formatTransactions(
}
}

// no space for bundle tip, so add seperate tx
if (bundleTipIndex === -1 && bundleTipIx) {
const bundleTipMessage = new TransactionMessage({
instructions: [bundleTipIx],
payerKey: feePayer,
recentBlockhash: blockhash,
});

formattedTransactions.push(new VersionedTransaction(bundleTipMessage.compileToV0Message()));
}

for (const [index, transaction] of transactions.entries()) {
const hasFlashloan = flashloanIndex !== null; // check if there is a flashloan
const isTxFlashloan = hasFlashloan && flashloanIndex === index; // check if the tx is the flashloan tx
Expand Down

0 comments on commit 618a5cc

Please sign in to comment.