correctly parse token 2022

This commit is contained in:
Maximilian Schneider 2024-11-08 00:13:37 +01:00
parent ad4d6f1d79
commit d7a67a67b8
2 changed files with 10 additions and 8 deletions

View File

@ -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;

View File

@ -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),
}
@ -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),
}
@ -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),
}