Skip to content

Commit

Permalink
fix: swap indexing broken
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasDeco committed Sep 4, 2024
1 parent b6a9b45 commit c03fe9e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/services/swaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub async fn handle_swap_tx(
transaction_sig: String,
) -> Result<(), Box<dyn std::error::Error>> {
let swap_instruction = find_swap_instruction(&transaction_payload)?;
let authority_account = transactions::find_authority_account(&swap_instruction)?;
let user_account = transactions::find_user_account(&swap_instruction)?;
let amm_acct = swap_instruction
.accounts_with_data
.iter()
Expand Down Expand Up @@ -47,7 +47,7 @@ pub async fn handle_swap_tx(
transaction_sig.clone(),
&mint_acct_value,
token_account,
&authority_account,
&user_account,
)
.await?
}
Expand Down
11 changes: 11 additions & 0 deletions src/services/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ pub fn find_instruction(
.ok_or_else(|| "Instruction not found".into())
}

pub fn find_user_account(
swap_instruction: &Instruction,
) -> Result<String, Box<dyn std::error::Error>> {
swap_instruction
.accounts_with_data
.iter()
.find(|account| account.name == "user")
.map(|account| account.pubkey.clone())
.ok_or_else(|| "User account not found in swap instruction".into())
}

pub fn find_authority_account(
mint_instruction: &Instruction,
) -> Result<String, Box<dyn std::error::Error>> {
Expand Down

0 comments on commit c03fe9e

Please sign in to comment.