@drift-labs/sdk 2.102.0-beta.4 → 2.103.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.102.0-beta.4
1
+ 2.103.0-beta.0
@@ -179,6 +179,8 @@ export declare class DriftClient {
179
179
  getReferrerNameAccountsForAuthority(authority: PublicKey): Promise<ReferrerNameAccount[]>;
180
180
  deleteUser(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
181
181
  getUserDeletionIx(userAccountPublicKey: PublicKey): Promise<anchor.web3.TransactionInstruction>;
182
+ forceDeleteUser(userAccountPublicKey: PublicKey, userAccount: UserAccount, txParams?: TxParams): Promise<TransactionSignature>;
183
+ getForceDeleteUserIx(userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<anchor.web3.TransactionInstruction>;
182
184
  deleteSwiftUserOrders(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
183
185
  getSwiftUserOrdersDeletionIx(userAccountPublicKey: PublicKey): Promise<anchor.web3.TransactionInstruction>;
184
186
  reclaimRent(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
@@ -294,7 +296,7 @@ export declare class DriftClient {
294
296
  */
295
297
  initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo, donateAmount?: BN, txParams?: TxParams, customMaxMarginRatio?: number): Promise<[TransactionSignature, PublicKey]>;
296
298
  initializeUserAccountForDevnet(subAccountId: number, name: string, marketIndex: number, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
297
- private getWithdrawalIxs;
299
+ getWithdrawalIxs(amount: BN, marketIndex: number, associatedTokenAddress: PublicKey, reduceOnly?: boolean, subAccountId?: number, updateFuel?: boolean): Promise<TransactionInstruction[]>;
298
300
  /**
299
301
  * Withdraws from a user account. If deposit doesn't already exist, creates a borrow
300
302
  * @param amount
@@ -916,6 +916,65 @@ class DriftClient {
916
916
  });
917
917
  return ix;
918
918
  }
919
+ async forceDeleteUser(userAccountPublicKey, userAccount, txParams) {
920
+ const tx = await this.buildTransaction(await this.getForceDeleteUserIx(userAccountPublicKey, userAccount), txParams);
921
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
922
+ return txSig;
923
+ }
924
+ async getForceDeleteUserIx(userAccountPublicKey, userAccount) {
925
+ const writableSpotMarketIndexes = [];
926
+ for (const spotPosition of userAccount.spotPositions) {
927
+ if ((0, spotPosition_1.isSpotPositionAvailable)(spotPosition)) {
928
+ continue;
929
+ }
930
+ writableSpotMarketIndexes.push(spotPosition.marketIndex);
931
+ }
932
+ const remainingAccounts = this.getRemainingAccounts({
933
+ userAccounts: [userAccount],
934
+ writableSpotMarketIndexes,
935
+ });
936
+ const tokenPrograms = new Set();
937
+ for (const spotPosition of userAccount.spotPositions) {
938
+ if ((0, spotPosition_1.isSpotPositionAvailable)(spotPosition)) {
939
+ continue;
940
+ }
941
+ const spotMarket = this.getSpotMarketAccount(spotPosition.marketIndex);
942
+ remainingAccounts.push({
943
+ isSigner: false,
944
+ isWritable: true,
945
+ pubkey: spotMarket.vault,
946
+ });
947
+ const keeperVault = await this.getAssociatedTokenAccount(spotPosition.marketIndex, false);
948
+ remainingAccounts.push({
949
+ isSigner: false,
950
+ isWritable: true,
951
+ pubkey: keeperVault,
952
+ });
953
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarket);
954
+ tokenPrograms.add(tokenProgram.toBase58());
955
+ }
956
+ for (const tokenProgram of tokenPrograms) {
957
+ remainingAccounts.push({
958
+ isSigner: false,
959
+ isWritable: false,
960
+ pubkey: new web3_js_1.PublicKey(tokenProgram),
961
+ });
962
+ }
963
+ const authority = userAccount.authority;
964
+ const userStats = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, authority);
965
+ const ix = await this.program.instruction.forceDeleteUser({
966
+ accounts: {
967
+ user: userAccountPublicKey,
968
+ userStats,
969
+ authority,
970
+ state: await this.getStatePublicKey(),
971
+ driftSigner: this.getSignerPublicKey(),
972
+ keeper: this.wallet.publicKey,
973
+ },
974
+ remainingAccounts,
975
+ });
976
+ return ix;
977
+ }
919
978
  async deleteSwiftUserOrders(subAccountId = 0, txParams) {
920
979
  var _a;
921
980
  const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Commitment, PublicKey, TransactionSignature } from '@solana/web3.js';
3
- import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord, SwiftOrderRecord } from '../index';
3
+ import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord, SwiftOrderRecord, DeleteUserRecord } from '../index';
4
4
  import { EventEmitter } from 'events';
5
5
  export type EventSubscriptionOptions = {
6
6
  address?: PublicKey;
@@ -42,9 +42,10 @@ export type EventMap = {
42
42
  SwapRecord: Event<SwapRecord>;
43
43
  SpotMarketVaultDepositRecord: Event<SpotMarketVaultDepositRecord>;
44
44
  SwiftOrderRecord: Event<SwiftOrderRecord>;
45
+ DeleteUserRecord: Event<DeleteUserRecord>;
45
46
  };
46
47
  export type EventType = keyof EventMap;
47
- export type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord> | Event<SwapRecord> | Event<SpotMarketVaultDepositRecord> | Event<SwiftOrderRecord>;
48
+ export type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord> | Event<SwapRecord> | Event<SpotMarketVaultDepositRecord> | Event<SwiftOrderRecord> | Event<DeleteUserRecord>;
48
49
  export interface EventSubscriberEvents {
49
50
  newEvent: (event: WrappedEvent<EventType>) => void;
50
51
  }
@@ -19,6 +19,7 @@ exports.DefaultEventSubscriptionOptions = {
19
19
  'SwapRecord',
20
20
  'SpotMarketVaultDepositRecord',
21
21
  'SwiftOrderRecord',
22
+ 'DeleteUserRecord',
22
23
  ],
23
24
  maxEventsPerType: 4096,
24
25
  orderBy: 'blockchain',
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.101.0",
2
+ "version": "2.102.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -1458,6 +1458,42 @@
1458
1458
  ],
1459
1459
  "args": []
1460
1460
  },
1461
+ {
1462
+ "name": "forceDeleteUser",
1463
+ "accounts": [
1464
+ {
1465
+ "name": "user",
1466
+ "isMut": true,
1467
+ "isSigner": false
1468
+ },
1469
+ {
1470
+ "name": "userStats",
1471
+ "isMut": true,
1472
+ "isSigner": false
1473
+ },
1474
+ {
1475
+ "name": "state",
1476
+ "isMut": true,
1477
+ "isSigner": false
1478
+ },
1479
+ {
1480
+ "name": "authority",
1481
+ "isMut": true,
1482
+ "isSigner": false
1483
+ },
1484
+ {
1485
+ "name": "keeper",
1486
+ "isMut": true,
1487
+ "isSigner": true
1488
+ },
1489
+ {
1490
+ "name": "driftSigner",
1491
+ "isMut": false,
1492
+ "isSigner": false
1493
+ }
1494
+ ],
1495
+ "args": []
1496
+ },
1461
1497
  {
1462
1498
  "name": "deleteSwiftUserOrders",
1463
1499
  "accounts": [
@@ -10826,7 +10862,8 @@
10826
10862
  {
10827
10863
  "name": "PlaceAndTake",
10828
10864
  "fields": [
10829
- "bool"
10865
+ "bool",
10866
+ "u8"
10830
10867
  ]
10831
10868
  },
10832
10869
  {
@@ -12508,6 +12545,38 @@
12508
12545
  "index": false
12509
12546
  }
12510
12547
  ]
12548
+ },
12549
+ {
12550
+ "name": "DeleteUserRecord",
12551
+ "fields": [
12552
+ {
12553
+ "name": "ts",
12554
+ "type": "i64",
12555
+ "index": false
12556
+ },
12557
+ {
12558
+ "name": "userAuthority",
12559
+ "type": "publicKey",
12560
+ "index": false
12561
+ },
12562
+ {
12563
+ "name": "user",
12564
+ "type": "publicKey",
12565
+ "index": false
12566
+ },
12567
+ {
12568
+ "name": "subAccountId",
12569
+ "type": "u16",
12570
+ "index": false
12571
+ },
12572
+ {
12573
+ "name": "keeper",
12574
+ "type": {
12575
+ "option": "publicKey"
12576
+ },
12577
+ "index": false
12578
+ }
12579
+ ]
12511
12580
  }
12512
12581
  ],
12513
12582
  "errors": [
@@ -707,6 +707,13 @@ export type SpotMarketVaultDepositRecord = {
707
707
  depositTokenAmountBefore: BN;
708
708
  amount: BN;
709
709
  };
710
+ export type DeleteUserRecord = {
711
+ ts: BN;
712
+ userAuthority: PublicKey;
713
+ user: PublicKey;
714
+ subAccountId: number;
715
+ keeper: PublicKey | null;
716
+ };
710
717
  export type StateAccount = {
711
718
  admin: PublicKey;
712
719
  exchangeStatus: number;
@@ -179,6 +179,8 @@ export declare class DriftClient {
179
179
  getReferrerNameAccountsForAuthority(authority: PublicKey): Promise<ReferrerNameAccount[]>;
180
180
  deleteUser(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
181
181
  getUserDeletionIx(userAccountPublicKey: PublicKey): Promise<anchor.web3.TransactionInstruction>;
182
+ forceDeleteUser(userAccountPublicKey: PublicKey, userAccount: UserAccount, txParams?: TxParams): Promise<TransactionSignature>;
183
+ getForceDeleteUserIx(userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<anchor.web3.TransactionInstruction>;
182
184
  deleteSwiftUserOrders(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
183
185
  getSwiftUserOrdersDeletionIx(userAccountPublicKey: PublicKey): Promise<anchor.web3.TransactionInstruction>;
184
186
  reclaimRent(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
@@ -294,7 +296,7 @@ export declare class DriftClient {
294
296
  */
295
297
  initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo, donateAmount?: BN, txParams?: TxParams, customMaxMarginRatio?: number): Promise<[TransactionSignature, PublicKey]>;
296
298
  initializeUserAccountForDevnet(subAccountId: number, name: string, marketIndex: number, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
297
- private getWithdrawalIxs;
299
+ getWithdrawalIxs(amount: BN, marketIndex: number, associatedTokenAddress: PublicKey, reduceOnly?: boolean, subAccountId?: number, updateFuel?: boolean): Promise<TransactionInstruction[]>;
298
300
  /**
299
301
  * Withdraws from a user account. If deposit doesn't already exist, creates a borrow
300
302
  * @param amount
@@ -916,6 +916,65 @@ class DriftClient {
916
916
  });
917
917
  return ix;
918
918
  }
919
+ async forceDeleteUser(userAccountPublicKey, userAccount, txParams) {
920
+ const tx = await this.buildTransaction(await this.getForceDeleteUserIx(userAccountPublicKey, userAccount), txParams);
921
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
922
+ return txSig;
923
+ }
924
+ async getForceDeleteUserIx(userAccountPublicKey, userAccount) {
925
+ const writableSpotMarketIndexes = [];
926
+ for (const spotPosition of userAccount.spotPositions) {
927
+ if ((0, spotPosition_1.isSpotPositionAvailable)(spotPosition)) {
928
+ continue;
929
+ }
930
+ writableSpotMarketIndexes.push(spotPosition.marketIndex);
931
+ }
932
+ const remainingAccounts = this.getRemainingAccounts({
933
+ userAccounts: [userAccount],
934
+ writableSpotMarketIndexes,
935
+ });
936
+ const tokenPrograms = new Set();
937
+ for (const spotPosition of userAccount.spotPositions) {
938
+ if ((0, spotPosition_1.isSpotPositionAvailable)(spotPosition)) {
939
+ continue;
940
+ }
941
+ const spotMarket = this.getSpotMarketAccount(spotPosition.marketIndex);
942
+ remainingAccounts.push({
943
+ isSigner: false,
944
+ isWritable: true,
945
+ pubkey: spotMarket.vault,
946
+ });
947
+ const keeperVault = await this.getAssociatedTokenAccount(spotPosition.marketIndex, false);
948
+ remainingAccounts.push({
949
+ isSigner: false,
950
+ isWritable: true,
951
+ pubkey: keeperVault,
952
+ });
953
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarket);
954
+ tokenPrograms.add(tokenProgram.toBase58());
955
+ }
956
+ for (const tokenProgram of tokenPrograms) {
957
+ remainingAccounts.push({
958
+ isSigner: false,
959
+ isWritable: false,
960
+ pubkey: new web3_js_1.PublicKey(tokenProgram),
961
+ });
962
+ }
963
+ const authority = userAccount.authority;
964
+ const userStats = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, authority);
965
+ const ix = await this.program.instruction.forceDeleteUser({
966
+ accounts: {
967
+ user: userAccountPublicKey,
968
+ userStats,
969
+ authority,
970
+ state: await this.getStatePublicKey(),
971
+ driftSigner: this.getSignerPublicKey(),
972
+ keeper: this.wallet.publicKey,
973
+ },
974
+ remainingAccounts,
975
+ });
976
+ return ix;
977
+ }
919
978
  async deleteSwiftUserOrders(subAccountId = 0, txParams) {
920
979
  var _a;
921
980
  const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Commitment, PublicKey, TransactionSignature } from '@solana/web3.js';
3
- import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord, SwiftOrderRecord } from '../index';
3
+ import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord, SwiftOrderRecord, DeleteUserRecord } from '../index';
4
4
  import { EventEmitter } from 'events';
5
5
  export type EventSubscriptionOptions = {
6
6
  address?: PublicKey;
@@ -42,9 +42,10 @@ export type EventMap = {
42
42
  SwapRecord: Event<SwapRecord>;
43
43
  SpotMarketVaultDepositRecord: Event<SpotMarketVaultDepositRecord>;
44
44
  SwiftOrderRecord: Event<SwiftOrderRecord>;
45
+ DeleteUserRecord: Event<DeleteUserRecord>;
45
46
  };
46
47
  export type EventType = keyof EventMap;
47
- export type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord> | Event<SwapRecord> | Event<SpotMarketVaultDepositRecord> | Event<SwiftOrderRecord>;
48
+ export type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord> | Event<SwapRecord> | Event<SpotMarketVaultDepositRecord> | Event<SwiftOrderRecord> | Event<DeleteUserRecord>;
48
49
  export interface EventSubscriberEvents {
49
50
  newEvent: (event: WrappedEvent<EventType>) => void;
50
51
  }
@@ -19,6 +19,7 @@ exports.DefaultEventSubscriptionOptions = {
19
19
  'SwapRecord',
20
20
  'SpotMarketVaultDepositRecord',
21
21
  'SwiftOrderRecord',
22
+ 'DeleteUserRecord',
22
23
  ],
23
24
  maxEventsPerType: 4096,
24
25
  orderBy: 'blockchain',
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.101.0",
2
+ "version": "2.102.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -1458,6 +1458,42 @@
1458
1458
  ],
1459
1459
  "args": []
1460
1460
  },
1461
+ {
1462
+ "name": "forceDeleteUser",
1463
+ "accounts": [
1464
+ {
1465
+ "name": "user",
1466
+ "isMut": true,
1467
+ "isSigner": false
1468
+ },
1469
+ {
1470
+ "name": "userStats",
1471
+ "isMut": true,
1472
+ "isSigner": false
1473
+ },
1474
+ {
1475
+ "name": "state",
1476
+ "isMut": true,
1477
+ "isSigner": false
1478
+ },
1479
+ {
1480
+ "name": "authority",
1481
+ "isMut": true,
1482
+ "isSigner": false
1483
+ },
1484
+ {
1485
+ "name": "keeper",
1486
+ "isMut": true,
1487
+ "isSigner": true
1488
+ },
1489
+ {
1490
+ "name": "driftSigner",
1491
+ "isMut": false,
1492
+ "isSigner": false
1493
+ }
1494
+ ],
1495
+ "args": []
1496
+ },
1461
1497
  {
1462
1498
  "name": "deleteSwiftUserOrders",
1463
1499
  "accounts": [
@@ -10826,7 +10862,8 @@
10826
10862
  {
10827
10863
  "name": "PlaceAndTake",
10828
10864
  "fields": [
10829
- "bool"
10865
+ "bool",
10866
+ "u8"
10830
10867
  ]
10831
10868
  },
10832
10869
  {
@@ -12508,6 +12545,38 @@
12508
12545
  "index": false
12509
12546
  }
12510
12547
  ]
12548
+ },
12549
+ {
12550
+ "name": "DeleteUserRecord",
12551
+ "fields": [
12552
+ {
12553
+ "name": "ts",
12554
+ "type": "i64",
12555
+ "index": false
12556
+ },
12557
+ {
12558
+ "name": "userAuthority",
12559
+ "type": "publicKey",
12560
+ "index": false
12561
+ },
12562
+ {
12563
+ "name": "user",
12564
+ "type": "publicKey",
12565
+ "index": false
12566
+ },
12567
+ {
12568
+ "name": "subAccountId",
12569
+ "type": "u16",
12570
+ "index": false
12571
+ },
12572
+ {
12573
+ "name": "keeper",
12574
+ "type": {
12575
+ "option": "publicKey"
12576
+ },
12577
+ "index": false
12578
+ }
12579
+ ]
12511
12580
  }
12512
12581
  ],
12513
12582
  "errors": [
@@ -707,6 +707,13 @@ export type SpotMarketVaultDepositRecord = {
707
707
  depositTokenAmountBefore: BN;
708
708
  amount: BN;
709
709
  };
710
+ export type DeleteUserRecord = {
711
+ ts: BN;
712
+ userAuthority: PublicKey;
713
+ user: PublicKey;
714
+ subAccountId: number;
715
+ keeper: PublicKey | null;
716
+ };
710
717
  export type StateAccount = {
711
718
  admin: PublicKey;
712
719
  exchangeStatus: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.102.0-beta.4",
3
+ "version": "2.103.0-beta.0",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "browser": "./lib/browser/index.js",
@@ -1580,6 +1580,88 @@ export class DriftClient {
1580
1580
  return ix;
1581
1581
  }
1582
1582
 
1583
+ public async forceDeleteUser(
1584
+ userAccountPublicKey: PublicKey,
1585
+ userAccount: UserAccount,
1586
+ txParams?: TxParams
1587
+ ): Promise<TransactionSignature> {
1588
+ const tx = await this.buildTransaction(
1589
+ await this.getForceDeleteUserIx(userAccountPublicKey, userAccount),
1590
+ txParams
1591
+ );
1592
+
1593
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1594
+ return txSig;
1595
+ }
1596
+
1597
+ public async getForceDeleteUserIx(
1598
+ userAccountPublicKey: PublicKey,
1599
+ userAccount: UserAccount
1600
+ ) {
1601
+ const writableSpotMarketIndexes = [];
1602
+ for (const spotPosition of userAccount.spotPositions) {
1603
+ if (isSpotPositionAvailable(spotPosition)) {
1604
+ continue;
1605
+ }
1606
+ writableSpotMarketIndexes.push(spotPosition.marketIndex);
1607
+ }
1608
+ const remainingAccounts = this.getRemainingAccounts({
1609
+ userAccounts: [userAccount],
1610
+ writableSpotMarketIndexes,
1611
+ });
1612
+
1613
+ const tokenPrograms = new Set<string>();
1614
+ for (const spotPosition of userAccount.spotPositions) {
1615
+ if (isSpotPositionAvailable(spotPosition)) {
1616
+ continue;
1617
+ }
1618
+ const spotMarket = this.getSpotMarketAccount(spotPosition.marketIndex);
1619
+ remainingAccounts.push({
1620
+ isSigner: false,
1621
+ isWritable: true,
1622
+ pubkey: spotMarket.vault,
1623
+ });
1624
+ const keeperVault = await this.getAssociatedTokenAccount(
1625
+ spotPosition.marketIndex,
1626
+ false
1627
+ );
1628
+ remainingAccounts.push({
1629
+ isSigner: false,
1630
+ isWritable: true,
1631
+ pubkey: keeperVault,
1632
+ });
1633
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarket);
1634
+ tokenPrograms.add(tokenProgram.toBase58());
1635
+ }
1636
+
1637
+ for (const tokenProgram of tokenPrograms) {
1638
+ remainingAccounts.push({
1639
+ isSigner: false,
1640
+ isWritable: false,
1641
+ pubkey: new PublicKey(tokenProgram),
1642
+ });
1643
+ }
1644
+
1645
+ const authority = userAccount.authority;
1646
+ const userStats = getUserStatsAccountPublicKey(
1647
+ this.program.programId,
1648
+ authority
1649
+ );
1650
+ const ix = await this.program.instruction.forceDeleteUser({
1651
+ accounts: {
1652
+ user: userAccountPublicKey,
1653
+ userStats,
1654
+ authority,
1655
+ state: await this.getStatePublicKey(),
1656
+ driftSigner: this.getSignerPublicKey(),
1657
+ keeper: this.wallet.publicKey,
1658
+ },
1659
+ remainingAccounts,
1660
+ });
1661
+
1662
+ return ix;
1663
+ }
1664
+
1583
1665
  public async deleteSwiftUserOrders(
1584
1666
  subAccountId = 0,
1585
1667
  txParams?: TxParams
@@ -2644,14 +2726,14 @@ export class DriftClient {
2644
2726
  return [txSig, userAccountPublicKey];
2645
2727
  }
2646
2728
 
2647
- private async getWithdrawalIxs(
2729
+ public async getWithdrawalIxs(
2648
2730
  amount: BN,
2649
2731
  marketIndex: number,
2650
2732
  associatedTokenAddress: PublicKey,
2651
2733
  reduceOnly = false,
2652
2734
  subAccountId?: number,
2653
2735
  updateFuel = false
2654
- ) {
2736
+ ): Promise<TransactionInstruction[]> {
2655
2737
  const withdrawIxs: anchor.web3.TransactionInstruction[] = [];
2656
2738
 
2657
2739
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
@@ -16,6 +16,7 @@ import {
16
16
  SwapRecord,
17
17
  SpotMarketVaultDepositRecord,
18
18
  SwiftOrderRecord,
19
+ DeleteUserRecord,
19
20
  } from '../index';
20
21
  import { EventEmitter } from 'events';
21
22
 
@@ -51,6 +52,7 @@ export const DefaultEventSubscriptionOptions: EventSubscriptionOptions = {
51
52
  'SwapRecord',
52
53
  'SpotMarketVaultDepositRecord',
53
54
  'SwiftOrderRecord',
55
+ 'DeleteUserRecord',
54
56
  ],
55
57
  maxEventsPerType: 4096,
56
58
  orderBy: 'blockchain',
@@ -95,6 +97,7 @@ export type EventMap = {
95
97
  SwapRecord: Event<SwapRecord>;
96
98
  SpotMarketVaultDepositRecord: Event<SpotMarketVaultDepositRecord>;
97
99
  SwiftOrderRecord: Event<SwiftOrderRecord>;
100
+ DeleteUserRecord: Event<DeleteUserRecord>;
98
101
  };
99
102
 
100
103
  export type EventType = keyof EventMap;
@@ -115,7 +118,8 @@ export type DriftEvent =
115
118
  | Event<CurveRecord>
116
119
  | Event<SwapRecord>
117
120
  | Event<SpotMarketVaultDepositRecord>
118
- | Event<SwiftOrderRecord>;
121
+ | Event<SwiftOrderRecord>
122
+ | Event<DeleteUserRecord>;
119
123
 
120
124
  export interface EventSubscriberEvents {
121
125
  newEvent: (event: WrappedEvent<EventType>) => void;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.101.0",
2
+ "version": "2.102.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -1458,6 +1458,42 @@
1458
1458
  ],
1459
1459
  "args": []
1460
1460
  },
1461
+ {
1462
+ "name": "forceDeleteUser",
1463
+ "accounts": [
1464
+ {
1465
+ "name": "user",
1466
+ "isMut": true,
1467
+ "isSigner": false
1468
+ },
1469
+ {
1470
+ "name": "userStats",
1471
+ "isMut": true,
1472
+ "isSigner": false
1473
+ },
1474
+ {
1475
+ "name": "state",
1476
+ "isMut": true,
1477
+ "isSigner": false
1478
+ },
1479
+ {
1480
+ "name": "authority",
1481
+ "isMut": true,
1482
+ "isSigner": false
1483
+ },
1484
+ {
1485
+ "name": "keeper",
1486
+ "isMut": true,
1487
+ "isSigner": true
1488
+ },
1489
+ {
1490
+ "name": "driftSigner",
1491
+ "isMut": false,
1492
+ "isSigner": false
1493
+ }
1494
+ ],
1495
+ "args": []
1496
+ },
1461
1497
  {
1462
1498
  "name": "deleteSwiftUserOrders",
1463
1499
  "accounts": [
@@ -10826,7 +10862,8 @@
10826
10862
  {
10827
10863
  "name": "PlaceAndTake",
10828
10864
  "fields": [
10829
- "bool"
10865
+ "bool",
10866
+ "u8"
10830
10867
  ]
10831
10868
  },
10832
10869
  {
@@ -12508,6 +12545,38 @@
12508
12545
  "index": false
12509
12546
  }
12510
12547
  ]
12548
+ },
12549
+ {
12550
+ "name": "DeleteUserRecord",
12551
+ "fields": [
12552
+ {
12553
+ "name": "ts",
12554
+ "type": "i64",
12555
+ "index": false
12556
+ },
12557
+ {
12558
+ "name": "userAuthority",
12559
+ "type": "publicKey",
12560
+ "index": false
12561
+ },
12562
+ {
12563
+ "name": "user",
12564
+ "type": "publicKey",
12565
+ "index": false
12566
+ },
12567
+ {
12568
+ "name": "subAccountId",
12569
+ "type": "u16",
12570
+ "index": false
12571
+ },
12572
+ {
12573
+ "name": "keeper",
12574
+ "type": {
12575
+ "option": "publicKey"
12576
+ },
12577
+ "index": false
12578
+ }
12579
+ ]
12511
12580
  }
12512
12581
  ],
12513
12582
  "errors": [
package/src/types.ts CHANGED
@@ -611,6 +611,14 @@ export type SpotMarketVaultDepositRecord = {
611
611
  amount: BN;
612
612
  };
613
613
 
614
+ export type DeleteUserRecord = {
615
+ ts: BN;
616
+ userAuthority: PublicKey;
617
+ user: PublicKey;
618
+ subAccountId: number;
619
+ keeper: PublicKey | null;
620
+ };
621
+
614
622
  export type StateAccount = {
615
623
  admin: PublicKey;
616
624
  exchangeStatus: number;