diff --git a/CHANGELOG.md b/CHANGELOG.md index 44b0cb3ef..d456a1f41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixes +- program: fix force delete user for token 2022 ([#1358](https://github.com/drift-labs/protocol-v2/pull/1358)) + ### Breaking ## [2.102.0] - 2024-11-21 diff --git a/programs/drift/src/instructions/keeper.rs b/programs/drift/src/instructions/keeper.rs index b79d8b6ed..64c5fe381 100644 --- a/programs/drift/src/instructions/keeper.rs +++ b/programs/drift/src/instructions/keeper.rs @@ -2,7 +2,9 @@ use std::cell::RefMut; use std::convert::{TryFrom, TryInto}; use anchor_lang::prelude::*; -use anchor_spl::associated_token::get_associated_token_address; +use anchor_spl::associated_token::{ + get_associated_token_address, get_associated_token_address_with_program_id, +}; use anchor_spl::token::spl_token; use anchor_spl::token_2022::spl_token_2022; use anchor_spl::token_interface::{TokenAccount, TokenInterface}; @@ -2245,7 +2247,11 @@ pub fn handle_force_delete_user<'c: 'info, 'info>( .find(|acc| acc.key() == spot_market_mint.key()) .map(|acc| InterfaceAccount::try_from(acc).unwrap()); - let keeper_vault = get_associated_token_address(&keeper_key, spot_market_mint); + let keeper_vault = get_associated_token_address_with_program_id( + &keeper_key, + spot_market_mint, + &token_program_pubkey, + ); let keeper_vault_account_info = ctx .remaining_accounts .iter() diff --git a/programs/drift/src/math/spot_balance.rs b/programs/drift/src/math/spot_balance.rs index 5005b2a14..5af43ef48 100644 --- a/programs/drift/src/math/spot_balance.rs +++ b/programs/drift/src/math/spot_balance.rs @@ -8,7 +8,6 @@ use crate::state::oracle::{OraclePriceData, StrictOraclePrice}; use crate::state::spot_market::{SpotBalanceType, SpotMarket}; use crate::state::user::SpotPosition; - #[cfg(test)] mod tests; diff --git a/programs/drift/src/math/spot_balance/tests.rs b/programs/drift/src/math/spot_balance/tests.rs index 725313bc0..5fbe7427a 100644 --- a/programs/drift/src/math/spot_balance/tests.rs +++ b/programs/drift/src/math/spot_balance/tests.rs @@ -14,9 +14,11 @@ mod test { let one_bonk = 10_u128.pow(spot_market.decimals); - let balance = get_spot_balance(one_bonk, &spot_market, &SpotBalanceType::Deposit, false).unwrap(); + let balance = + get_spot_balance(one_bonk, &spot_market, &SpotBalanceType::Deposit, false).unwrap(); - let token_amount = get_token_amount(balance, &spot_market, &SpotBalanceType::Deposit).unwrap(); + let token_amount = + get_token_amount(balance, &spot_market, &SpotBalanceType::Deposit).unwrap(); assert_eq!(token_amount, one_bonk); } } diff --git a/sdk/src/driftClient.ts b/sdk/src/driftClient.ts index fb1305992..69a7519fd 100644 --- a/sdk/src/driftClient.ts +++ b/sdk/src/driftClient.ts @@ -1658,16 +1658,17 @@ export class DriftClient { isWritable: true, pubkey: spotMarket.vault, }); + const tokenProgram = this.getTokenProgramForSpotMarket(spotMarket); const keeperVault = await this.getAssociatedTokenAccount( spotPosition.marketIndex, - false + false, + tokenProgram ); remainingAccounts.push({ isSigner: false, isWritable: true, pubkey: keeperVault, }); - const tokenProgram = this.getTokenProgramForSpotMarket(spotMarket); tokenPrograms.add(tokenProgram.toBase58()); }