Skip to content

Commit 353f974

Browse files
committed
address comments
1 parent 9b27925 commit 353f974

File tree

2 files changed

+22
-52
lines changed

2 files changed

+22
-52
lines changed

auction-server/src/api.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,24 +159,24 @@ impl std::fmt::Display for InstructionError {
159159
}
160160
InstructionError::InvalidUserTransferInstructionsCount { found } => {
161161
match found {
162-
0 => write!(f, "At least one sol transfer instruction from the user wallet account is required"),
163-
_ => write!(f, "Invalid number ({}) of sol transfer instructions from the user wallet account", found),
162+
0 => write!(f, "At least one SOL transfer instruction from the user wallet account is required"),
163+
_ => write!(f, "Invalid number ({}) of SOL transfer instructions from the user wallet account", found),
164164
}
165165
}
166166
InstructionError::InvalidUserAccountTransferInstruction => {
167-
write!(f, "Invalid sol transfer instruction from the user account.")
167+
write!(f, "Invalid SOL transfer instruction from the user account.")
168168
}
169169
InstructionError::InvalidToAccountTransferInstruction { expected, found } => {
170170
write!(
171171
f,
172-
"Invalid to account in sol transfer instruction. Expected: {:?} found: {:?}",
172+
"Invalid to account in SOL transfer instruction. Expected: {:?} found: {:?}",
173173
expected, found
174174
)
175175
}
176176
InstructionError::InvalidAmountTransferInstruction { expected, found } => {
177177
write!(
178178
f,
179-
"Invalid amount in sol transfer instruction. Expected: {:?} found: {:?}",
179+
"Invalid amount in SOL transfer instruction. Expected: {:?} found: {:?}",
180180
expected, found
181181
)
182182
}

auction-server/src/auction/service/verification.rs

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -583,18 +583,20 @@ impl Service {
583583
// User has to wrap Sol
584584
if transaction_data.accounts.mint_user == spl_token::native_mint::id() {
585585
// Sometimes the user doesn't have enough SOL, but we want the transaction to fail in the Express Relay program with InsufficientUserFunds.
586-
// Sometimes the user will already have a WSOL account, and they don't need to wrap the full user_amount of SOL.
586+
// Sometimes the user will already have a WSOL account, and they might not be able to wrap the necessary amount from their SOL balance. In this case, we want to enable the tx to proceed with whatever they have in SOL being wrapped. The tx should still succeed if they have enough SOL + WSOL to cover the amount_user.
587587
// For both these reasons, we allow the user to wrap less SOL than needed so it doesn't fail in the transfer instruction.
588588
let amount_user_to_wrap =
589589
opportunity_swap_data.get_user_amount_to_wrap(transaction_data.data.amount_user);
590590

591-
if user_transfer_instructions.is_empty() {
592-
return Err(RestError::InvalidInstruction(
593-
None,
594-
InstructionError::InvalidUserTransferInstructionsCount { found: 0 },
595-
));
596-
}
597-
let user_transfer_instruction = user_transfer_instructions[0].clone();
591+
let user_transfer_instruction = match user_transfer_instructions.first() {
592+
Some(instruction) => instruction,
593+
None => {
594+
return Err(RestError::InvalidInstruction(
595+
None,
596+
InstructionError::InvalidUserTransferInstructionsCount { found: 0 },
597+
));
598+
}
599+
};
598600
let user_ata = get_associated_token_address(
599601
&transaction_data.accounts.user_wallet,
600602
&spl_token::native_mint::id(),
@@ -623,9 +625,10 @@ impl Service {
623625
}
624626
// otherwise, if user mint is not SOL, then user should not be system transferring any SOL
625627
else if !user_transfer_instructions.is_empty() {
626-
let user_transfer_instruction = user_transfer_instructions[0].clone();
627628
return Err(RestError::InvalidInstruction(
628-
Some(user_transfer_instruction.index),
629+
transfer_instructions
630+
.first()
631+
.map(|instruction| instruction.index),
629632
InstructionError::InvalidUserAccountTransferInstruction,
630633
));
631634
}
@@ -1073,16 +1076,16 @@ impl Service {
10731076
..
10741077
} = transaction_data.accounts;
10751078

1076-
let quote_tokens = get_swap_quote_tokens(&opp);
1077-
let opportunity_swap_data = get_opportunity_swap_data(&opp);
1078-
self.check_svm_swap_bid_fields(bid_data, opportunity_swap_data, &quote_tokens)
1079-
.await?;
10801079
self.validate_swap_transaction_instructions(
10811080
bid_chain_data_create_svm.get_transaction(),
10821081
&user_wallet,
10831082
&self.config.chain_config.express_relay.relayer.pubkey(),
10841083
)
10851084
.await?;
1085+
let quote_tokens = get_swap_quote_tokens(&opp);
1086+
let opportunity_swap_data = get_opportunity_swap_data(&opp);
1087+
self.check_svm_swap_bid_fields(bid_data, opportunity_swap_data, &quote_tokens)
1088+
.await?;
10861089

10871090
Self::check_memo_instructions(&bid_data.transaction, &opportunity_swap_data.memo)
10881091
.await?;
@@ -2798,39 +2801,6 @@ mod tests {
27982801
);
27992802
}
28002803

2801-
#[tokio::test]
2802-
async fn test_verify_bid_when_sol_transfer_relayer() {
2803-
let (service, opportunities) = get_service(true);
2804-
let opportunity = opportunities.user_token_specified.clone();
2805-
let bid_amount = 1;
2806-
let searcher = Keypair::new();
2807-
let swap_instruction = svm::Svm::get_swap_instruction(GetSwapInstructionParams {
2808-
searcher: searcher.pubkey(),
2809-
opportunity_params: get_opportunity_params(opportunity.clone()),
2810-
bid_amount,
2811-
deadline: (OffsetDateTime::now_utc() + Duration::seconds(30)).unix_timestamp(),
2812-
fee_receiver_relayer: Pubkey::new_unique(),
2813-
relayer_signer: service.config.chain_config.express_relay.relayer.pubkey(),
2814-
})
2815-
.unwrap();
2816-
let relayer = service.config.chain_config.express_relay.relayer.pubkey();
2817-
let transfer_instruction = system_instruction::transfer(&relayer, &Pubkey::new_unique(), 1);
2818-
let result = get_verify_bid_result(
2819-
service.clone(),
2820-
searcher.insecure_clone(),
2821-
vec![transfer_instruction, swap_instruction.clone()],
2822-
opportunities.user_token_specified.clone(),
2823-
)
2824-
.await;
2825-
assert_eq!(
2826-
result.unwrap_err(),
2827-
RestError::InvalidInstruction(
2828-
Some(0),
2829-
InstructionError::RelayerTransferInstructionNotAllowed
2830-
)
2831-
);
2832-
}
2833-
28342804
#[tokio::test]
28352805
async fn test_verify_bid_when_arbitrary_program_does_not_invoke_user() {
28362806
let (service, opportunities) = get_service(true);

0 commit comments

Comments
 (0)