From 31b4f35d61022ad0eb00d792387d3f9335ad405f Mon Sep 17 00:00:00 2001 From: Serge Farny Date: Mon, 30 Sep 2024 14:50:54 +0200 Subject: [PATCH] Router: move raydium 'frozen vault' check to quote (avoid double loading of the tokens accounts) (#4) --- lib/dex-raydium/src/raydium_dex.rs | 34 +++++++++++------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/lib/dex-raydium/src/raydium_dex.rs b/lib/dex-raydium/src/raydium_dex.rs index 40ad660..cbae476 100644 --- a/lib/dex-raydium/src/raydium_dex.rs +++ b/lib/dex-raydium/src/raydium_dex.rs @@ -55,28 +55,6 @@ impl DexInterface for RaydiumDex { }) .collect_vec(); - let vaults = filtered_pools - .iter() - .flat_map(|x| [x.1.coin_vault, x.1.pc_vault]) - .collect::>(); - let vaults = rpc.get_multiple_accounts(&vaults).await?; - let banned_vaults = vaults - .iter() - .filter(|x| { - x.1.owner == Token::id() - && spl_token::state::Account::unpack(x.1.data()).unwrap().state - == AccountState::Frozen - }) - .map(|x| x.0) - .collect::>(); - - let filtered_pools = filtered_pools - .into_iter() - .filter(|(_, amm)| { - !banned_vaults.contains(&amm.coin_vault) && !banned_vaults.contains(&amm.pc_vault) - }) - .collect_vec(); - info!( "Number of raydium AMM post filtering: {:?}", filtered_pools.len() @@ -178,6 +156,18 @@ impl DexInterface for RaydiumDex { let coin_vault = &edge.coin_vault; let pc_vault = &edge.pc_vault; + let coin_vault_is_frozen = coin_vault.state == AccountState::Frozen; + let pc_vault_is_frozen = pc_vault.state == AccountState::Frozen; + + if coin_vault_is_frozen || pc_vault_is_frozen { + return Ok(Quote { + in_amount, + out_amount: 0, + fee_amount: 0, + fee_mint: Default::default(), + }); + } + let swap_direction = if id.is_pc_to_coin { SwapDirection::PC2Coin } else {