Skip to content

Commit

Permalink
anchor: relax accounts validation for jupiter swap (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurushao authored Jan 12, 2025
1 parent 7fe537c commit 7f394a7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions anchor/programs/glam/src/instructions/jupiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ fn parse_route(ctx: &Context<JupiterSwap>) -> (bool, usize) {
let mut res = true;
res &= ctx.remaining_accounts.len() > 9;

res &= ctx.remaining_accounts[0].key() == ctx.accounts.output_token_program.key();
res &= ctx.remaining_accounts[0].key() == ctx.accounts.output_token_program.key()
|| ctx.remaining_accounts[0].key() == ctx.accounts.input_token_program.key();
res &= ctx.remaining_accounts[1].key() == ctx.accounts.signer.key();
res &= ctx.remaining_accounts[2].key() == ctx.accounts.input_signer_ata.key();
res &= ctx.remaining_accounts[3].key() == ctx.accounts.output_signer_ata.key();
Expand All @@ -114,7 +115,8 @@ fn parse_exact_out_route(ctx: &Context<JupiterSwap>) -> (bool, usize) {
let mut res = true;
res &= ctx.remaining_accounts.len() > 11;

res &= ctx.remaining_accounts[0].key() == ctx.accounts.output_token_program.key();
res &= ctx.remaining_accounts[0].key() == ctx.accounts.output_token_program.key()
|| ctx.remaining_accounts[0].key() == ctx.accounts.input_token_program.key();
res &= ctx.remaining_accounts[1].key() == ctx.accounts.signer.key();
res &= ctx.remaining_accounts[2].key() == ctx.accounts.input_signer_ata.key();
res &= ctx.remaining_accounts[3].key() == ctx.accounts.output_signer_ata.key();
Expand All @@ -136,7 +138,8 @@ fn parse_shared_accounts_route(ctx: &Context<JupiterSwap>) -> (bool, usize) {
let mut res = true;
res &= ctx.remaining_accounts.len() > 13;

res &= ctx.remaining_accounts[0].key() == ctx.accounts.output_token_program.key();
res &= ctx.remaining_accounts[0].key() == ctx.accounts.output_token_program.key()
|| ctx.remaining_accounts[0].key() == ctx.accounts.input_token_program.key();
// res &= ctx.remaining_accounts[1].key() - programAuthority ignored

res &= ctx.remaining_accounts[2].key() == ctx.accounts.signer.key();
Expand Down

0 comments on commit 7f394a7

Please sign in to comment.