Skip to content

Commit 3b9b05d

Browse files
authored
Separate getAddInsuranceFundStakeIxs (#1695)
1 parent de63cf9 commit 3b9b05d

File tree

1 file changed

+49
-10
lines changed

1 file changed

+49
-10
lines changed

sdk/src/driftClient.ts

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8462,9 +8462,56 @@ export class DriftClient {
84628462
fromSubaccount?: boolean;
84638463
txParams?: TxParams;
84648464
}): Promise<TransactionSignature> {
8465-
const addIfStakeIxs = [];
8465+
const addIfStakeIxs = await this.getAddInsuranceFundStakeIxs({
8466+
marketIndex,
8467+
amount,
8468+
collateralAccountPublicKey,
8469+
initializeStakeAccount,
8470+
fromSubaccount,
8471+
});
84668472

84678473
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+
84688515
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
84698516
const isSolMarket = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);
84708517
const createWSOLTokenAccount =
@@ -8545,15 +8592,7 @@ export class DriftClient {
85458592
);
85468593
}
85478594

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;
85578596
}
85588597

85598598
public async requestRemoveInsuranceFundStake(

0 commit comments

Comments
 (0)