Skip to content

Commit

Permalink
correctly parse token 2022
Browse files Browse the repository at this point in the history
  • Loading branch information
mschneider committed Nov 7, 2024
1 parent ad4d6f1 commit d7a67a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions programs/autobahn-executor/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ pub fn get_balance(account: &AccountInfo) -> Result<u64, ProgramError> {
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::<spl_token_2022::state::Account>::unpack(&data)?;
Ok(token.base.amount)
}
_ => Err(ProgramError::IllegalOwner),
}
Expand All @@ -30,9 +31,9 @@ pub fn get_mint(account: &AccountInfo) -> Result<Pubkey, ProgramError> {
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::<spl_token_2022::state::Account>::unpack(&data)?;
Ok(token.base.mint)
}
_ => Err(ProgramError::IllegalOwner),
}
Expand All @@ -45,9 +46,9 @@ pub fn get_owner(account: &AccountInfo) -> Result<Pubkey, ProgramError> {
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::<spl_token_2022::state::Account>::unpack(&data)?;
Ok(token.base.owner)
}
_ => Err(ProgramError::IllegalOwner),
}
Expand Down

0 comments on commit d7a67a6

Please sign in to comment.