Skip to content

Instantly share code, notes, and snippets.

@0ex-d
Created February 19, 2025 19:01
Show Gist options
  • Save 0ex-d/a40e26cf38850dfe3e6a3c892801e859 to your computer and use it in GitHub Desktop.
Save 0ex-d/a40e26cf38850dfe3e6a3c892801e859 to your computer and use it in GitHub Desktop.
Solana Multi-DEX Arbitrage (Pseudocode only!) (Orca -> Whirlpool -> Orca)
pub fn execute_orca_whirlpool_arbitrage(
ctx: Context<OrcaWhirlpoolArbitrage>,
amount_in: u64,
minimum_amount_1: u64,
minimum_final_amount: u64,
) -> Result<()> {
// 1. Orca swap
_orca_swap(
&ctx.accounts.orca_accounts_1,
amount_in,
minimum_amount_1,
)?;
// 2. Whirlpool swap
_orca_swap(
&ctx.accounts.whirlpool_accounts,
minimum_amount_1,
minimum_final_amount,
)?;
// Verify profit
let profit = minimum_final_amount.checked_sub(amount_in)
.ok_or(ErrorCode::ArithmeticError)?;
require!(
profit >= ctx.accounts.swap_state.profit_threshold,
ErrorCode::InsufficientProfit
);
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment