This file contains 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, |
This file contains 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
// abstract from std | |
{ | |
enum Result <T, E> { | |
Ok(()), | |
Err(()) | |
} | |
enum Option <T> { | |
Some(()), | |
None |
This file contains 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
#[derive(Debug)] | |
pub struct Stack<L1, L2> { | |
l1: L1, | |
l2: L2, | |
} | |
impl<L1, L2> Stack<L1, L2> { | |
const fn new(l1: L1, l2: L2) -> Self { | |
Self { l1, l2 } | |
} |
This file contains 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
fn main(){ | |
let p1 = 1_000; | |
let p2 = p1; // Copy | |
let v1 = Box::new(200); stack pointer but value on the heap | |
let v2 = v1; // Clone | |
} |
This file contains 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 builtin_exec(cmd: &str) -> Option<Exec> { | |
let f = match cmd { | |
"add" => add::exec, | |
"bench" => bench::exec, | |
"build" => build::exec, | |
"check" => check::exec, | |
"clean" => clean::exec, | |
"config" => config::exec, | |
"doc" => doc::exec, | |
"fetch" => fetch::exec, |
This file contains 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
use tokio::time::{sleep, Duration, Instant}; | |
use anyhow::Result; | |
use thiserror::Error; | |
#[derive(Error,Debug)] | |
enum WorkerError { | |
#[error("Worker {0} encountered an error")] | |
Failed(isize), | |
} |
This file contains 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
use std::thread; | |
use std::time::{Duration, Instant}; | |
fn worker(id: isize) -> thread::JoinHandle<()> { | |
println!("starting worker {id}"); | |
thread::spawn(move || { | |
thread::sleep(Duration::from_secs(10)); | |
println!("worker {id} done"); | |
}) | |
} |
This file contains 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
fn simulate_mempool_flood() { | |
let mut mempool: Vec<Transaction> = Vec::new(); | |
let mut rng = rand::thread_rng(); | |
for i in 0..10_000 { | |
let tx = Transaction { | |
id: format!("tx_{}", i), | |
fee: rng.gen_range(1..=10), | |
vin: if rng.gen_bool(0.9) { | |
vec![format!("utxo_{}", rng.gen_range(1..=1000))] | |
} else { |
This file contains 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
// DEX-2-DEX only | |
// A pseudocode of my automated solidity code to execute fast Arb trade. | |
// I would be using Uniswap and PancakeSwap DEXs | |
// 1 ETH = 3,234 USDT (Uniswap) | |
// 1 ETH = 3,334 USDT (PancakeSwap) | |
function executeArbitrage( address tokenA, address tokenB, uint amountIn, address dex1, address dex2) external { | |
uint256 feeDex1 = Dex1(dex1).getTradingFee(tokenA, tokenB); | |
uint256 feeDex2 = Dex2(dex2).getTradingFee(tokenB, tokenA); | |
// bid 1 ETH = 3,234 USDT (Uniswap) |
This file contains 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
struct BinaryTree { | |
tree: Vec<u32>, | |
max_size: usize, | |
curr_size: usize, | |
} | |
impl BinaryTree { | |
fn new(max_size: usize) -> Self { | |
BinaryTree { | |
tree: vec![0; max_size + 1], // 1-based indexing |
NewerOlder