Skip to content

Commit

Permalink
Feat: Add lut's adaptable LUT's into transaction sender
Browse files Browse the repository at this point in the history
  • Loading branch information
LevBeta committed Sep 5, 2024
1 parent 9ce77d6 commit 57ac2a1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/rebalancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
geyser::{AccountType, GeyserUpdate},
sender::{SenderCfg, TransactionSender},
token_account_manager::TokenAccountManager,
transaction_manager::BatchTransactions,
transaction_manager::{BatchTransactions, RawTransaction},
utils::{
accessor, batch_get_multiple_accounts, calc_weighted_assets_new, calc_weighted_liabs_new,
BankAccountWithPriceFeedEva,
Expand Down Expand Up @@ -306,7 +306,7 @@ impl Rebalancer {
.collect();

if !active_swb_oracles.is_empty() {
if let Ok(crank_data) = PullFeed::fetch_update_many_ix(
if let Ok((ix, lut)) = PullFeed::fetch_update_many_ix(
&self.liquidator_account.non_blocking_rpc_client,
FetchUpdateManyParams {
feeds: active_swb_oracles,
Expand All @@ -320,7 +320,7 @@ impl Rebalancer {
{
self.liquidator_account
.transaction_tx
.send(vec![vec![crank_data.0]])
.send(vec![RawTransaction::new(vec![ix]).with_lookup_tables(lut)])
.unwrap();
}
}
Expand Down
40 changes: 32 additions & 8 deletions src/transaction_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,30 @@ pub struct TransactionManager {
lookup_tables: Vec<AddressLookupTableAccount>,
}

/// Type alias for a batch of transactions
/// A batch of transactions is a vector of vectors of instructions
/// Each vector of instructions represents a single transaction
/// The outer vector represents a batch of transactions
pub type BatchTransactions = Vec<Vec<Instruction>>;
// Type alias for a batch of transactions
// A batch of transactions is a vector of vectors of instructions
// Each vector of instructions represents a single transaction
// The outer vector represents a batch of transactions
pub type BatchTransactions = Vec<RawTransaction>;

pub struct RawTransaction {
pub instructions: Vec<Instruction>,
pub lookup_tables: Option<Vec<AddressLookupTableAccount>>,
}

impl RawTransaction {
pub fn new(instructions: Vec<Instruction>) -> Self {
Self {
instructions,
lookup_tables: None,
}
}

pub fn with_lookup_tables(mut self, lookup_tables: Vec<AddressLookupTableAccount>) -> Self {
self.lookup_tables = Some(lookup_tables);
self
}
}

impl TransactionManager {
/// Creates a new transaction manager
Expand Down Expand Up @@ -229,8 +248,9 @@ impl TransactionManager {
let blockhash = self.rpc.get_latest_blockhash().await?;

let mut txs = Vec::new();
for mut ixs in instructions {
ixs.push(ComputeBudgetInstruction::set_compute_unit_limit(500_000));
for mut raw_transaction in instructions {
let mut ixs = raw_transaction.instructions;
ixs.push(ComputeBudgetInstruction::set_compute_unit_limit(1_000_000));
ixs.push(transfer(
&self.keypair.pubkey(),
&self.tip_accounts[0],
Expand All @@ -240,7 +260,11 @@ impl TransactionManager {
VersionedMessage::V0(v0::Message::try_compile(
&self.keypair.pubkey(),
&ixs,
&self.lookup_tables,
if raw_transaction.lookup_tables.is_some() {
raw_transaction.lookup_tables.as_ref().unwrap()
} else {
&self.lookup_tables
},
blockhash,
)?),
&[&self.keypair],
Expand Down
28 changes: 16 additions & 12 deletions src/wrappers/liquidator_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ 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},
transaction_manager::BatchTransactions,
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,
};
Expand Down Expand Up @@ -137,7 +140,7 @@ impl LiquidatorAccount {
})
.collect::<Vec<_>>();

let crank_ix = if !observation_swb_oracles.is_empty() {
let (crank_ix, crank_lut) = if !observation_swb_oracles.is_empty() {
if let Ok(crank_data) = PullFeed::fetch_update_many_ix(
&self.non_blocking_rpc_client,
FetchUpdateManyParams {
Expand All @@ -150,7 +153,7 @@ impl LiquidatorAccount {
)
.await
{
crank_data.0
crank_data
} else {
return Err(anyhow::anyhow!("Failed to fetch crank data"));
}
Expand Down Expand Up @@ -178,9 +181,10 @@ impl LiquidatorAccount {
asset_amount,
);

// Double vec implies that is a single bundle
self.transaction_tx
.send(vec![vec![crank_ix, liquidate_ix]])?;
self.transaction_tx.send(vec![
RawTransaction::new(vec![crank_ix]).with_lookup_tables(crank_lut),
RawTransaction::new(vec![liquidate_ix]),
])?;

Ok(())
}
Expand Down Expand Up @@ -231,8 +235,8 @@ impl LiquidatorAccount {
withdraw_all,
);

// Double vec implies that is a single bundle
self.transaction_tx.send(vec![vec![withdraw_ix]])?;
self.transaction_tx
.send(vec![RawTransaction::new(vec![withdraw_ix])])?;

Ok(())
}
Expand Down Expand Up @@ -265,8 +269,8 @@ impl LiquidatorAccount {
repay_all,
);

// Double vec implies that is a single bundle
self.transaction_tx.send(vec![vec![repay_ix]])?;
self.transaction_tx
.send(vec![RawTransaction::new(vec![repay_ix])])?;

Ok(())
}
Expand Down Expand Up @@ -297,8 +301,8 @@ impl LiquidatorAccount {
amount,
);

// Double vec implies that is a single bundle
self.transaction_tx.send(vec![vec![deposit_ix]])?;
self.transaction_tx
.send(vec![RawTransaction::new(vec![deposit_ix])])?;

Ok(())
}
Expand Down

0 comments on commit 57ac2a1

Please sign in to comment.