From d7a67a67b84b5b07d5e72ca06edbbb49ab1b05ce Mon Sep 17 00:00:00 2001 From: Maximilian Schneider Date: Fri, 8 Nov 2024 00:13:37 +0100 Subject: [PATCH] correctly parse token 2022 --- .../src/instructions/execute_swap_v3.rs | 1 + programs/autobahn-executor/src/token.rs | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/programs/autobahn-executor/src/instructions/execute_swap_v3.rs b/programs/autobahn-executor/src/instructions/execute_swap_v3.rs index 10f294c..ef8d90b 100644 --- a/programs/autobahn-executor/src/instructions/execute_swap_v3.rs +++ b/programs/autobahn-executor/src/instructions/execute_swap_v3.rs @@ -86,6 +86,7 @@ pub fn execute_swap_v3( let out_amount = balance_after - balance_before; let out_mint = token::get_mint(ix_token_account)?; + if ix_index == 0 { input_amount = input_token_account_balance - token::get_balance(&accounts[0])?; input_mint = in_mint; diff --git a/programs/autobahn-executor/src/token.rs b/programs/autobahn-executor/src/token.rs index 40c535e..f6bbd01 100644 --- a/programs/autobahn-executor/src/token.rs +++ b/programs/autobahn-executor/src/token.rs @@ -16,8 +16,9 @@ pub fn get_balance(account: &AccountInfo) -> Result { Ok(token.amount) } spl_token_2022::ID => { - let token = spl_token_2022::state::Account::unpack(&account.try_borrow_data()?)?; - Ok(token.amount) + let data = account.data.borrow(); + let token = StateWithExtensions::::unpack(&data)?; + Ok(token.base.amount) } _ => Err(ProgramError::IllegalOwner), } @@ -30,9 +31,9 @@ pub fn get_mint(account: &AccountInfo) -> Result { Ok(token.mint) } spl_token_2022::ID => { - let token: spl_token_2022::state::Account = - spl_token_2022::state::Account::unpack(&account.try_borrow_data()?)?; - Ok(token.mint) + let data = account.data.borrow(); + let token = StateWithExtensions::::unpack(&data)?; + Ok(token.base.mint) } _ => Err(ProgramError::IllegalOwner), } @@ -45,9 +46,9 @@ pub fn get_owner(account: &AccountInfo) -> Result { Ok(token.owner) } spl_token_2022::ID => { - let token: spl_token_2022::state::Account = - spl_token_2022::state::Account::unpack(&account.try_borrow_data()?)?; - Ok(token.owner) + let data = account.data.borrow(); + let token = StateWithExtensions::::unpack(&data)?; + Ok(token.base.owner) } _ => Err(ProgramError::IllegalOwner), }