@drift-labs/sdk 2.25.0 → 2.25.2
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/lib/driftClient.d.ts +5 -1
- package/lib/driftClient.js +24 -17
- package/lib/idl/drift.json +1 -1
- package/package.json +1 -1
- package/src/driftClient.ts +34 -17
- package/src/idl/drift.json +1 -1
package/lib/driftClient.d.ts
CHANGED
|
@@ -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
|
|
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>;
|
package/lib/driftClient.js
CHANGED
|
@@ -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
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
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
|
}
|
package/lib/idl/drift.json
CHANGED
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -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
|
-
|
|
4419
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
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
|
-
|
|
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
|
}
|
package/src/idl/drift.json
CHANGED