Created
February 19, 2025 19:01
-
-
Save 0ex-d/a40e26cf38850dfe3e6a3c892801e859 to your computer and use it in GitHub Desktop.
Solana Multi-DEX Arbitrage (Pseudocode only!) (Orca -> Whirlpool -> Orca)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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