diff --git a/src/liquidator.rs b/src/liquidator.rs index 1fbf284..3ef9307 100644 --- a/src/liquidator.rs +++ b/src/liquidator.rs @@ -22,7 +22,7 @@ use marginfi::{ constants::EXP_10_I80F48, state::{ marginfi_account::{BalanceSide, MarginfiAccount, RequirementType}, - marginfi_group::{Bank, RiskTier}, + marginfi_group::{Bank, BankOperationalState, RiskTier}, price::{ OraclePriceFeedAdapter, OraclePriceType, OracleSetup, PriceBias, SwitchboardPullPriceFeed, @@ -492,9 +492,11 @@ impl Liquidator { RequirementType::Maintenance, )?; - debug!("Account {:?}", account.address); - debug!("Health {:?}", maintenance_health); - debug!("Liquidator profit {:?}", liquidator_profit); + if liquidator_profit > self.config.min_profit { + debug!("Account {:?}", account.address); + debug!("Health {:?}", maintenance_health); + debug!("Liquidator profit {:?}", liquidator_profit); + } Ok((max_liquidatable_asset_amount, liquidator_profit)) } @@ -780,6 +782,13 @@ impl Liquidator { continue; } + if !matches!( + bank.bank.config.operational_state, + BankOperationalState::Operational + ) { + continue; + } + let value = match balance_side { BalanceSide::Liabilities => bank .calc_value(share.0, BalanceSide::Liabilities, requirement_type) diff --git a/src/sender.rs b/src/sender.rs index 898f31a..b12864a 100644 --- a/src/sender.rs +++ b/src/sender.rs @@ -2,7 +2,7 @@ use crate::wrappers::marginfi_account::TxConfig; use log::{error, info}; use serde::Deserialize; use solana_client::rpc_client::{RpcClient, SerializableTransaction}; -use solana_client::rpc_config::RpcSimulateTransactionConfig; +use solana_client::rpc_config::{RpcSendTransactionConfig, RpcSimulateTransactionConfig}; use solana_sdk::signature::Signature; use solana_sdk::{ commitment_config::CommitmentConfig, @@ -165,7 +165,13 @@ impl TransactionSender { } (0..cfg.spam_times).try_for_each(|_| { - rpc.send_transaction(transaction)?; + rpc.send_transaction_with_config( + transaction, + RpcSendTransactionConfig { + skip_preflight: true, + ..Default::default() + }, + )?; Ok::<_, Box>(()) })?; diff --git a/src/token_account_manager.rs b/src/token_account_manager.rs index 1956796..816a93f 100644 --- a/src/token_account_manager.rs +++ b/src/token_account_manager.rs @@ -3,27 +3,20 @@ use std::{ sync::{Arc, RwLock}, }; -use anchor_lang::accounts::program; use anchor_spl::associated_token; -use crossbeam::epoch::Owned; use log::{debug, error, info}; use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator}; use sha2::{Digest, Sha256}; use solana_client::rpc_client::RpcClient; -use solana_sdk::{ - account::Account, - pubkey::Pubkey, - signature::Keypair, - signer::{SeedDerivable, Signer}, -}; +use solana_sdk::{account::Account, pubkey::Pubkey, signature::Keypair, signer::Signer}; use crate::{ sender::{SenderCfg, TransactionSender}, utils::{batch_get_multiple_accounts, BatchLoadingConfig}, }; -const TOKEN_ACCOUNT_SEED: &[u8] = b"liquidator_ta"; -const MAX_INIT_TA_IXS: usize = 4; +// const TOKEN_ACCOUNT_SEED: &[u8] = b"liquidator_ta"; +const MAX_INIT_TA_IXS: usize = 10; #[derive(Debug, Clone, thiserror::Error)] pub enum TokenAccountManagerError { @@ -230,15 +223,15 @@ fn get_liquidator_seed(signer: Pubkey, mint: Pubkey, seed: &[u8]) -> [u8; 32] { hasher.finalize().into() } -fn get_keypair_for_token_account( - signer: Pubkey, - mint: Pubkey, - seed: &[u8], -) -> Result { - let keypair_seed = get_liquidator_seed(signer, mint, seed); - Keypair::from_seed(&keypair_seed) - .map_err(|_| TokenAccountManagerError::SetupFailed("Keypair::from_seed failed")) -} +// fn get_keypair_for_token_account( +// signer: Pubkey, +// mint: Pubkey, +// seed: &[u8], +// ) -> Result { +// let keypair_seed = get_liquidator_seed(signer, mint, seed); +// Keypair::from_seed(&keypair_seed) +// .map_err(|_| TokenAccountManagerError::SetupFailed("Keypair::from_seed failed")) +// } fn get_address_for_token_account( signer: Pubkey, diff --git a/src/wrappers/liquidator_account.rs b/src/wrappers/liquidator_account.rs index 0e437e9..bd0e649 100644 --- a/src/wrappers/liquidator_account.rs +++ b/src/wrappers/liquidator_account.rs @@ -2,18 +2,15 @@ use super::{bank::BankWrapper, marginfi_account::MarginfiAccountWrapper}; use crate::{ config::GeneralConfig, marginfi_ixs::{make_deposit_ix, make_liquidate_ix, make_repay_ix, make_withdraw_ix}, - sender::{SenderCfg, TransactionSender}, transaction_manager::{BatchTransactions, RawTransaction}, }; use crossbeam::channel::Sender; use marginfi::state::{marginfi_account::MarginfiAccount, marginfi_group::BankVaultType}; -use rayon::vec; use solana_client::{ nonblocking::rpc_client::RpcClient as NonBlockingRpcClient, rpc_client::RpcClient, }; use solana_program::pubkey::Pubkey; use solana_sdk::{ - compute_budget::ComputeBudgetInstruction, signature::{read_keypair_file, Keypair}, signer::Signer, }; @@ -140,8 +137,8 @@ impl LiquidatorAccount { }) .collect::>(); - let (crank_ix, crank_lut) = if !observation_swb_oracles.is_empty() { - if let Ok(crank_data) = PullFeed::fetch_update_many_ix( + let crank_data = if !observation_swb_oracles.is_empty() { + if let Ok((ix, luts)) = PullFeed::fetch_update_many_ix( &self.non_blocking_rpc_client, FetchUpdateManyParams { feeds: observation_swb_oracles, @@ -153,12 +150,12 @@ impl LiquidatorAccount { ) .await { - crank_data + Some((ix, luts)) } else { return Err(anyhow::anyhow!("Failed to fetch crank data")); } } else { - return Err(anyhow::anyhow!("No crank data available")); + None }; let liquidate_ix = make_liquidate_ix( @@ -181,10 +178,13 @@ impl LiquidatorAccount { asset_amount, ); - self.transaction_tx.send(vec![ - RawTransaction::new(vec![crank_ix]).with_lookup_tables(crank_lut), - RawTransaction::new(vec![liquidate_ix]), - ])?; + let mut bundle = vec![]; + if let Some((crank_ix, crank_lut)) = crank_data { + bundle.push(RawTransaction::new(vec![crank_ix]).with_lookup_tables(crank_lut)); + } + bundle.push(RawTransaction::new(vec![liquidate_ix])); + + self.transaction_tx.send(bundle)?; Ok(()) }