@drift-labs/sdk 2.25.0 → 2.25.1

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.
@@ -361,7 +361,11 @@ export declare class DriftClient {
361
361
  }): Promise<TransactionSignature>;
362
362
  requestRemoveInsuranceFundStake(marketIndex: number, amount: BN): Promise<TransactionSignature>;
363
363
  cancelRequestRemoveInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
364
- removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
364
+ removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey,
365
+ /**
366
+ * If unstaking SOL, it's required to pass in the amount
367
+ */
368
+ amount?: BN): Promise<TransactionSignature>;
365
369
  settleRevenueToInsuranceFund(marketIndex: number): Promise<TransactionSignature>;
366
370
  resolvePerpPnlDeficit(spotMarketIndex: number, perpMarketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
367
371
  getResolvePerpPnlDeficitIx(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionInstruction>;
@@ -2474,26 +2474,29 @@ class DriftClient {
2474
2474
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
2475
2475
  return txSig;
2476
2476
  }
2477
- async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey) {
2477
+ async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey,
2478
+ /**
2479
+ * If unstaking SOL, it's required to pass in the amount
2480
+ */
2481
+ amount) {
2478
2482
  const tx = new web3_js_1.Transaction();
2479
2483
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
2480
2484
  const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
2481
- const tokenAccount = collateralAccountPublicKey;
2482
- // Todo wsol remove iF stake... how do we determine the amount?
2483
- // const amount = // get balance here...?
2484
- // const additionalSigners: Array<Signer> = [];
2485
- // const isSolMarket = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);
2486
- // const createWSOLTokenAccount =
2487
- // isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
2488
- // if (createWSOLTokenAccount) {
2489
- // const { ixs, signers, pubkey } =
2490
- // await this.getWrappedSolAccountCreationIxs(amount, true);
2491
- // tokenAccount = pubkey;
2492
- // ixs.forEach((ix) => {
2493
- // tx.add(ix);
2494
- // });
2495
- // signers.forEach((signer) => additionalSigners.push(signer));
2496
- // }
2485
+ const additionalSigners = [];
2486
+ const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
2487
+ const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
2488
+ let tokenAccount;
2489
+ if (createWSOLTokenAccount) {
2490
+ const { ixs, signers, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, true);
2491
+ tokenAccount = pubkey;
2492
+ ixs.forEach((ix) => {
2493
+ tx.add(ix);
2494
+ });
2495
+ signers.forEach((signer) => additionalSigners.push(signer));
2496
+ }
2497
+ else {
2498
+ tokenAccount = collateralAccountPublicKey;
2499
+ }
2497
2500
  const remainingAccounts = this.getRemainingAccounts({
2498
2501
  userAccounts: [this.getUserAccount()],
2499
2502
  useMarketLastSlotCache: true,
@@ -2514,6 +2517,10 @@ class DriftClient {
2514
2517
  remainingAccounts,
2515
2518
  });
2516
2519
  tx.add(removeStakeIx);
2520
+ // Close the wrapped sol account at the end of the transaction
2521
+ if (createWSOLTokenAccount) {
2522
+ tx.add(spl_token_1.Token.createCloseAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, tokenAccount, this.wallet.publicKey, this.wallet.publicKey, []));
2523
+ }
2517
2524
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
2518
2525
  return txSig;
2519
2526
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.25.0",
2
+ "version": "2.25.1",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.25.0",
3
+ "version": "2.25.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -4404,7 +4404,11 @@ export class DriftClient {
4404
4404
 
4405
4405
  public async removeInsuranceFundStake(
4406
4406
  marketIndex: number,
4407
- collateralAccountPublicKey: PublicKey
4407
+ collateralAccountPublicKey: PublicKey,
4408
+ /**
4409
+ * If unstaking SOL, it's required to pass in the amount
4410
+ */
4411
+ amount?: BN
4408
4412
  ): Promise<TransactionSignature> {
4409
4413
  const tx = new Transaction();
4410
4414
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
@@ -4413,26 +4417,26 @@ export class DriftClient {
4413
4417
  this.wallet.publicKey,
4414
4418
  marketIndex
4415
4419
  );
4416
- const tokenAccount = collateralAccountPublicKey;
4417
4420
 
4418
- // Todo wsol remove iF stake... how do we determine the amount?
4419
- // const amount = // get balance here...?
4421
+ const additionalSigners: Array<Signer> = [];
4422
+ const isSolMarket = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);
4423
+ const createWSOLTokenAccount =
4424
+ isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
4420
4425
 
4421
- // const additionalSigners: Array<Signer> = [];
4422
- // const isSolMarket = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);
4423
- // const createWSOLTokenAccount =
4424
- // isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
4426
+ let tokenAccount;
4425
4427
 
4426
- // if (createWSOLTokenAccount) {
4427
- // const { ixs, signers, pubkey } =
4428
- // await this.getWrappedSolAccountCreationIxs(amount, true);
4429
- // tokenAccount = pubkey;
4430
- // ixs.forEach((ix) => {
4431
- // tx.add(ix);
4432
- // });
4428
+ if (createWSOLTokenAccount) {
4429
+ const { ixs, signers, pubkey } =
4430
+ await this.getWrappedSolAccountCreationIxs(amount, true);
4431
+ tokenAccount = pubkey;
4432
+ ixs.forEach((ix) => {
4433
+ tx.add(ix);
4434
+ });
4433
4435
 
4434
- // signers.forEach((signer) => additionalSigners.push(signer));
4435
- // }
4436
+ signers.forEach((signer) => additionalSigners.push(signer));
4437
+ } else {
4438
+ tokenAccount = collateralAccountPublicKey;
4439
+ }
4436
4440
 
4437
4441
  const remainingAccounts = this.getRemainingAccounts({
4438
4442
  userAccounts: [this.getUserAccount()],
@@ -4458,6 +4462,19 @@ export class DriftClient {
4458
4462
 
4459
4463
  tx.add(removeStakeIx);
4460
4464
 
4465
+ // Close the wrapped sol account at the end of the transaction
4466
+ if (createWSOLTokenAccount) {
4467
+ tx.add(
4468
+ Token.createCloseAccountInstruction(
4469
+ TOKEN_PROGRAM_ID,
4470
+ tokenAccount,
4471
+ this.wallet.publicKey,
4472
+ this.wallet.publicKey,
4473
+ []
4474
+ )
4475
+ );
4476
+ }
4477
+
4461
4478
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
4462
4479
  return txSig;
4463
4480
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.25.0",
2
+ "version": "2.25.1",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {