Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing issue with exact out dumping #26

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bin/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ async fn main() -> Result<(), anyhow::Error> {
}
&CREATE_REFERRAL_LOG_DISCRIMINANT => {
let event = bytemuck::from_bytes::<CreateReferralLog>(&decoded[8..]);
println!("CreateReferralLog - referer: {:?}, referee: {:?}, vault: {:?}, mint: {:?}", event.referer, event.referee, event.vault, event.mint);
println!(
"CreateReferralLog - referer: {:?}, referee: {:?}, vault: {:?}, mint: {:?}",
event.referer, event.referee, event.vault, event.mint
);
}
_ => panic!("Unknown log discriminant"),
}
Expand Down
2 changes: 1 addition & 1 deletion lib/dex-infinity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async-trait = "0.1.79"
chrono = "0.4.38"
sha2 = "0.10.8"
tracing = "0.1.40"
spl-associated-token-account = "1.0.5"
spl-associated-token-account = { version = "1.0.5", features = ["no-entrypoint"] }

# infinity
solana-readonly-account = { version = "1.1.0", features=["solana-sdk"] }
Expand Down
4 changes: 2 additions & 2 deletions lib/router-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ pub mod test_tools;
pub mod utils;

pub mod autobahn_executor {
use solana_sdk::declare_id;
declare_id!("AutobNFLMzX1rFCDgwWpwr3ztG5c1oDbSrGq7Jj2LgE");
use solana_sdk::declare_id;
declare_id!("AutobNFLMzX1rFCDgwWpwr3ztG5c1oDbSrGq7Jj2LgE");
}
52 changes: 19 additions & 33 deletions lib/router-lib/src/test_tools/generate_dex_rpc_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,25 @@ pub async fn run_dump_swap_ix_with_custom_amount(
is_exact_out: false,
});

let chain_data_reader = chain_data.read().unwrap();
for account in swap_ix.instruction.accounts {
if let Ok(acc) = chain_data_reader.account(&account.pubkey) {
dump.accounts.insert(account.pubkey, acc.account.clone());
} else {
error!("Missing account (needed for swap) {}", account.pubkey);
}
}
let account = chain_data_reader
.account(&id.input_mint())
.expect("missing mint");
dump.accounts
.insert(id.input_mint(), account.account.clone());
let account = chain_data_reader
.account(&id.input_mint())
.expect("missing mint");
dump.accounts
.insert(id.output_mint(), account.account.clone());

// build exact out tests
if dex.supports_exact_out(&id) {
let Ok(mut quote_exact_out) =
Expand Down Expand Up @@ -284,41 +303,8 @@ pub async fn run_dump_swap_ix_with_custom_amount(
error!("Missing account (needed for swap) {}", account.pubkey);
}
}

let account = chain_data_reader
.account(&id.input_mint())
.expect("missing mint");
dump.accounts
.insert(id.input_mint(), account.account.clone());

let account = chain_data_reader
.account(&id.input_mint())
.expect("missing mint");
dump.accounts
.insert(id.output_mint(), account.account.clone());
}
}

let chain_data_reader = chain_data.read().unwrap();
for account in swap_ix.instruction.accounts {
if let Ok(acc) = chain_data_reader.account(&account.pubkey) {
dump.accounts.insert(account.pubkey, acc.account.clone());
} else {
error!("Missing account (needed for swap) {}", account.pubkey);
}
}

let account = chain_data_reader
.account(&id.input_mint())
.expect("missing mint");
dump.accounts
.insert(id.input_mint(), account.account.clone());

let account = chain_data_reader
.account(&id.input_mint())
.expect("missing mint");
dump.accounts
.insert(id.output_mint(), account.account.clone());
}

println!("Error count: {}", errors);
Expand Down
1 change: 1 addition & 0 deletions lib/router-test-lib/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ where
let mut writer = lz4::EncoderBuilder::new().build(file_writer).unwrap();
writer.write_all(serialized_data.as_slice()).unwrap();
writer.flush().unwrap();
let _ = writer.finish();
}

pub fn deserialize_from_file<T>(path: &String) -> anyhow::Result<T>
Expand Down
3 changes: 1 addition & 2 deletions programs/autobahn-executor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod instructions;
pub mod create_pda;
mod instructions;
pub mod logs;
pub mod swap_ix;
pub mod utils;
Expand All @@ -14,7 +14,6 @@ use solana_program::program_error::ProgramError;
use solana_program::program_pack::Pack;
use solana_program::{account_info::AccountInfo, pubkey::Pubkey};


#[cfg(not(feature = "no-entrypoint"))]
use {default_env::default_env, solana_program::entrypoint, solana_security_txt::security_txt};

Expand Down
15 changes: 9 additions & 6 deletions programs/simulator/tests/cases/test_swap_from_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,18 @@ async fn simulate_cu_usage(
match sim {
Ok(sim) => {
log::debug!("{:?}", sim.result);
if sim.result.is_some() && sim.result.unwrap().is_ok() {
let simulation_details = sim.simulation_details.unwrap();
let cus = simulation_details.units_consumed;
let simulation_details = sim.simulation_details.unwrap();
let cus = simulation_details.units_consumed;
if sim.result.is_some() && sim.result.clone().unwrap().is_ok() {
log::debug!("units consumed : {}", cus);
log::debug!("----logs");
Some(cus)
} else if sim.result.is_some() && sim.result.clone().unwrap().is_err() {
println!("simluation failed : {:?}", sim.result.unwrap());
println!("----logs");
for log in simulation_details.logs {
log::debug!("{log:?}");
println!("{log:?}");
}
Some(cus)
None
} else {
None
}
Expand Down
Loading