Skip to content

Commit

Permalink
Reorder errors and use const pubkey
Browse files Browse the repository at this point in the history
  • Loading branch information
m30m committed Jan 17, 2025
1 parent fdada5a commit e2658c0
Showing 1 changed file with 33 additions and 39 deletions.
72 changes: 33 additions & 39 deletions auction-server/src/auction/service/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ use {
transaction::VersionedTransaction,
},
std::{
str::FromStr,
sync::Arc,
time::Duration,
},
Expand Down Expand Up @@ -614,6 +613,30 @@ impl Service<Svm> {
Some(output_token.amount),
),
};
if user_wallet != opp_swap_data.user_wallet_address {
return Err(RestError::BadParameters(
format!(
"User wallet address in swap opportunity {} does not match the user wallet address in the swap instruction {}",
opp_swap_data.user_wallet_address, user_wallet
),
));
}
if expected_input_token != mint_input {
return Err(RestError::BadParameters(
format!(
"Input token in swap opportunity {} does not match the input token in the swap instruction {}",
expected_input_token, mint_input
),
));
}
if expected_output_token != mint_output {
return Err(RestError::BadParameters(
format!(
"Output token in swap opportunity {} does not match the output token in the swap instruction {}",
expected_output_token, mint_output
),
));
}
if let Some(expected_input_amount) = expected_input_amount {
if expected_input_amount != swap_data.amount_input {
return Err(RestError::BadParameters(
Expand All @@ -634,24 +657,15 @@ impl Service<Svm> {
));
}
}
if expected_input_token != mint_input {
return Err(RestError::BadParameters(
format!(
"Input token in swap opportunity {} does not match the input token in the swap instruction {}",
expected_input_token, mint_input
),
));
}
if expected_output_token != mint_output {
if opp_swap_data.fee_token != swap_data.fee_token {
return Err(RestError::BadParameters(
format!(
"Output token in swap opportunity {} does not match the output token in the swap instruction {}",
expected_output_token, mint_output
"Fee token in swap opportunity {:?} does not match the fee token in the swap instruction {:?}",
opp_swap_data.fee_token, swap_data.fee_token
),
));
}


if swap_data.referral_fee_bps != opp_swap_data.referral_fee_bps {
return Err(RestError::BadParameters(
format!(
Expand All @@ -660,44 +674,24 @@ impl Service<Svm> {
),
));
}
if user_wallet != opp_swap_data.user_wallet_address {
return Err(RestError::BadParameters(
format!(
"User wallet address in swap opportunity {} does not match the user wallet address in the swap instruction {}",
opp_swap_data.user_wallet_address, user_wallet
),
));
}
let (fee_token, fee_token_program) = match swap_data.fee_token {
FeeToken::Input => (mint_input, opp_swap_data.input_token_program),
FeeToken::Output => (mint_output, opp_swap_data.output_token_program),
};
if opp_swap_data.fee_token != swap_data.fee_token {
return Err(RestError::BadParameters(
format!(
"Fee token in swap opportunity {:?} does not match the fee token in the swap instruction {:?}",
opp_swap_data.fee_token, swap_data.fee_token
),
));
}

let associated_token_program = Pubkey::from_str(
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
)
.map_err(|e| {
RestError::BadParameters(format!(
"Invalid associated token program address: {:?}",
e
))
})?;
// ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL
const ASSOCIATED_TOKEN_PROGRAM: Pubkey = Pubkey::new_from_array([
140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90,
19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89,
]);

let expected_router_fee_receiver_ta = Pubkey::find_program_address(
&[
&opp.router.to_bytes(),
&fee_token_program.to_bytes(),
&fee_token.to_bytes(),
],
&associated_token_program,
&ASSOCIATED_TOKEN_PROGRAM,
)
.0;
let router_fee_receiver_ta = self
Expand Down

0 comments on commit e2658c0

Please sign in to comment.