@@ -8462,9 +8462,56 @@ export class DriftClient {
8462
8462
fromSubaccount ?: boolean ;
8463
8463
txParams ?: TxParams ;
8464
8464
} ) : Promise < TransactionSignature > {
8465
- const addIfStakeIxs = [ ] ;
8465
+ const addIfStakeIxs = await this . getAddInsuranceFundStakeIxs ( {
8466
+ marketIndex,
8467
+ amount,
8468
+ collateralAccountPublicKey,
8469
+ initializeStakeAccount,
8470
+ fromSubaccount,
8471
+ } ) ;
8466
8472
8467
8473
const additionalSigners : Array < Signer > = [ ] ;
8474
+ const tx = await this . buildTransaction ( addIfStakeIxs , txParams ) ;
8475
+
8476
+ const { txSig } = await this . sendTransaction (
8477
+ tx ,
8478
+ additionalSigners ,
8479
+ this . opts
8480
+ ) ;
8481
+
8482
+ return txSig ;
8483
+ }
8484
+
8485
+ /**
8486
+ * Get instructions to add to an insurance fund stake and optionally initialize the account
8487
+ */
8488
+ public async getAddInsuranceFundStakeIxs ( {
8489
+ marketIndex,
8490
+ amount,
8491
+ collateralAccountPublicKey,
8492
+ initializeStakeAccount,
8493
+ fromSubaccount,
8494
+ } : {
8495
+ /**
8496
+ * Spot market index
8497
+ */
8498
+ marketIndex : number ;
8499
+ amount : BN ;
8500
+ /**
8501
+ * The account where the funds to stake come from. Usually an associated token account
8502
+ */
8503
+ collateralAccountPublicKey : PublicKey ;
8504
+ /**
8505
+ * Add instructions to initialize the staking account -- required if its the first time the currrent authority has staked in this market
8506
+ */
8507
+ initializeStakeAccount ?: boolean ;
8508
+ /**
8509
+ * Optional -- withdraw from current subaccount to fund stake amount, instead of wallet balance
8510
+ */
8511
+ fromSubaccount ?: boolean ;
8512
+ } ) : Promise < TransactionInstruction [ ] > {
8513
+ const addIfStakeIxs = [ ] ;
8514
+
8468
8515
const spotMarketAccount = this . getSpotMarketAccount ( marketIndex ) ;
8469
8516
const isSolMarket = spotMarketAccount . mint . equals ( WRAPPED_SOL_MINT ) ;
8470
8517
const createWSOLTokenAccount =
@@ -8545,15 +8592,7 @@ export class DriftClient {
8545
8592
) ;
8546
8593
}
8547
8594
8548
- const tx = await this . buildTransaction ( addIfStakeIxs , txParams ) ;
8549
-
8550
- const { txSig } = await this . sendTransaction (
8551
- tx ,
8552
- additionalSigners ,
8553
- this . opts
8554
- ) ;
8555
-
8556
- return txSig ;
8595
+ return addIfStakeIxs ;
8557
8596
}
8558
8597
8559
8598
public async requestRemoveInsuranceFundStake (
0 commit comments