How the MEV Protection Layer Coordinates Jito Bundles and Flashbots Transactions in CloddsBot
The MEV protection layer in CloddsBot abstracts Solana and EVM transaction protection through a unified interface that routes Solana transactions to Jito bundles with configurable lamport tips and EVM transactions to Flashbots Protect RPC, encapsulating chain-specific bundle mechanics behind a single strategy dispatcher.
The CloddsBot trading infrastructure implements a sophisticated MEV protection layer to prevent front-running and sandwich attacks across heterogeneous blockchain environments. By inspecting transaction metadata and detecting the target chain, the system dynamically selects between Jito's block-engine for Solana and Flashbots' private mempool services for EVM-compatible networks. This architectural pattern allows the bot to submit high-value trades through protected channels without requiring caller components to understand the underlying bundle mechanics of each network.
Chain Detection and Routing Strategy
The MEV protection layer operates as a strategy dispatcher that inspects incoming transactions to determine the appropriate protection mechanism. When a signed transaction enters the system via src/execution/mev-protection.ts, the layer analyzes the destination chain identifier to branch execution logic.
For Solana destinations, the system invokes the Jito workflow, while any EVM-compatible chain triggers the Flashbots protect pipeline. This routing decision happens transparently, allowing downstream components to call a single protectTransaction() method regardless of the underlying blockchain architecture.
The configuration structure defines chain-specific parameters in a unified schema:
// src/execution/mev-protection.ts
interface MevProtectionConfig {
flashbotsApiKey?: string; // Line 36: EVM API authentication
jitoTipLamports?: number; // Line 38: Solana tip amount (default 10,000)
}
Jito Bundle Coordination for Solana
When processing Solana transactions, the MEV protection layer constructs Jito bundles that include a tip instruction to incentivize block producers for priority inclusion. The implementation targets Jito's low-latency block engine at https://mainnet.block-engine.jito.wtf (defined at line 99 of mev-protection.ts).
The coordination process involves three distinct steps:
-
Tip Instruction Construction: The
createJitoTipInstructionhelper (line 479) generates a System Program transfer instruction directing lamports to Jito's tip accounts. -
Bundle Assembly: The original transaction is bundled with the tip instruction to ensure atomic execution.
-
Submission: The complete bundle is transmitted to the Jito block engine endpoint via the
JITO_BLOCK_ENGINEconstant.
The default tip amount is 10,000 lamports (configurable via jitoTipLamports), though the system allows dynamic adjustment based on network congestion:
// Configuration for Solana MEV protection
const solanaConfig: MevProtectionConfig = {
jitoTipLamports: 12_000, // 0.000012 SOL priority tip
flashbotsApiKey: '', // Not utilized for Solana flows
};
const mevProtection = createMevProtection(solanaConfig);
Flashbots Integration for EVM Chains
For EVM transactions, the layer leverages Flashbots Protect to prevent mempool exposure. The implementation references three distinct Flashbots endpoints defined in src/execution/mev-protection.ts:
- RPC Endpoint:
https://rpc.flashbots.net(line 91) - Protect Endpoint:
https://protect.flashbots.net(line 92) - Relay Endpoint:
https://relay.flashbots.net(line 93)
The sendFlashbotsProtect function (invoked at line 439) handles the cryptographic authentication required by the Flashbots relay, accepting the flashbotsApiKey parameter (line 440) to sign bundle submissions. Unlike the Solana implementation, Flashbots integration does not require explicit tip configuration; the relay automatically deducts fees from the transaction value, with results encapsulated in the flashbotsResult object (line 444).
Configuration for EVM deployments requires only the API key:
// Configuration for EVM MEV protection
const evmConfig: MevProtectionConfig = {
jitoTipLamports: undefined, // Unused for EVM
flashbotsApiKey: process.env.FLASHBOTS_API_KEY,
};
Unified Transaction Interface
The MEV protection layer exposes a chain-agnostic API that returns a standardized response shape regardless of the underlying protection mechanism:
interface ProtectedTransactionResult {
transactions: Tx[];
tipLamports?: number; // Populated for Jito bundles
bundleId?: string; // Transaction identifier
}
This abstraction allows callers to submit transactions without importing chain-specific libraries. The following example demonstrates the unified interface handling both Solana and EVM transactions identically:
async function submitProtectedTrade(
signedTx: Uint8Array,
mev: ReturnType<typeof createMevProtection>
) {
const result = await mev.protectTransaction(signedTx);
if (result.transactions.length === 0) {
console.warn('MEV protection failed to construct bundle');
return;
}
// Broadcast logic remains identical for Solana and EVM
await broadcastTransactions(result.transactions);
if (result.tipLamports) {
console.log(`Jito tip included: ${result.tipLamports} lamports`);
}
}
Fee Accounting and Graceful Fallback
The MEV protection layer incorporates economic safety mechanisms to prevent transaction failures due to insufficient fees or missing tip accounts.
In src/solana/pump-swarm.ts (lines 1656-1659), the system augments fee estimations by adding the configured Jito tip amount to the base transaction cost:
// Inside pump-swarm.ts execution flow
const mevResult = await this.mevProtection.protectTransaction(serializedTx);
if (mevResult.tipLamports) {
estimatedFees += mevResult.tipLamports / 1e9; // Convert lamports to SOL
}
If the Jito tip instruction cannot be generated—such as when tip accounts are temporarily unavailable—the layer implements a graceful fallback at line 464 of mev-protection.ts, returning an empty transaction array with the configured tip amount preserved. This allows the caller to either retry with standard mempool submission or abort the transaction without losing funds to failed bundle attempts.
Summary
- The MEV protection layer in
src/execution/mev-protection.tsfunctions as a strategy dispatcher, automatically routing Solana transactions to Jito and EVM transactions to Flashbots. - Jito coordination requires constructing tip instructions via
createJitoTipInstructionand submitting tohttps://mainnet.block-engine.jito.wtfwith configurable lamport amounts (default 10,000). - Flashbots integration utilizes the Protect RPC at
https://protect.flashbots.net, authenticated viaflashbotsApiKeyand managed through thesendFlashbotsProtecthelper. - A unified response interface
{ transactions: Tx[], tipLamports?: number, bundleId?: string }abstracts chain-specific complexity from calling components. - Fee calculations in
src/solana/pump-swarm.tsaccount for Jito tips by adding the lamport amount to estimated transaction costs. - Graceful fallback mechanisms return empty transaction arrays when bundle construction fails, preventing failed submissions without explicit error throws.
Frequently Asked Questions
How does the MEV protection layer decide between Jito and Flashbots?
The layer inspects the transaction's destination chain identifier during the routing phase in src/execution/mev-protection.ts. Solana destinations trigger the Jito bundle workflow with lamport tips, while any EVM-compatible chain activates the Flashbots Protect RPC pipeline. This detection happens transparently within the protectTransaction() method, requiring no explicit chain parameter from the caller.
What happens if the Jito tip account is unavailable?
According to the source code at line 464 of mev-protection.ts, the layer returns an empty transaction array along with the configured tipLamports value when the createJitoTipInstruction function fails. This graceful degradation allows the caller to implement fallback logic—such as standard RPC submission or transaction cancellation—without throwing exceptions or losing track of the intended tip amount.
Why does the Flashbots implementation require an API key while Jito uses lamport tips?
The architectural models differ between networks. Flashbots operates on a reputation-based system where the flashbotsApiKey (line 36) authenticates bundles to the Flashbots relay at https://relay.flashbots.net, with fees automatically deducted from transaction value. Jito's Solana model relies on direct lamport transfers to validator tip accounts (configured via jitoTipLamports at line 38), functioning as native Solana instructions without external API authentication.
Can the MEV protection layer handle multiple transactions atomically?
Yes. The unified response interface returns a transactions array (type Tx[]) that may contain multiple signed transactions bundled together. For Solana, this represents a Jito bundle with the tip instruction plus the original transaction. For Flashbots, this represents the transaction set submitted to the Protect RPC. The caller processes these arrays identically regardless of whether they originated from Jito or Flashbots coordination.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →