Skip to content

Commit

Permalink
program: fix force delete user for token 22 (#1358)
Browse files Browse the repository at this point in the history
* program: fix force delete user for token 22

* cargo fmt --

* CHANGELOG
  • Loading branch information
crispheaney authored Dec 5, 2024
1 parent d22aceb commit f489378
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions programs/drift/src/instructions/keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion programs/drift/src/math/spot_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 4 additions & 2 deletions programs/drift/src/math/spot_balance/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 3 additions & 2 deletions sdk/src/driftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit f489378

Please sign in to comment.