diff --git a/sdk/src/driftClient.ts b/sdk/src/driftClient.ts index 92bdc144f7..bf9fb50730 100644 --- a/sdk/src/driftClient.ts +++ b/sdk/src/driftClient.ts @@ -5962,7 +5962,8 @@ export class DriftClient { settlePnl?: boolean, exitEarlyIfSimFails?: boolean, auctionDurationPercentage?: number, - optionalIxs?: TransactionInstruction[] + optionalIxs?: TransactionInstruction[], + exitHighLeverageMode?: boolean ): Promise<{ placeAndTakeTx: Transaction | VersionedTransaction; cancelExistingOrdersTx: Transaction | VersionedTransaction; @@ -6095,14 +6096,30 @@ export class DriftClient { subAccountId ); + const userAccount = this.getUserAccount(subAccountId); + + const ixs = []; + const settlePnlIx = await this.settlePNLIx( userAccountPublicKey, - this.getUserAccount(subAccountId), + userAccount, orderParams.marketIndex ); + ixs.push(settlePnlIx); + + if (exitHighLeverageMode) { + const disableHighLeverageModeIx = + await this.getDisableHighLeverageModeIx( + userAccountPublicKey, + userAccount + ); + + ixs.push(disableHighLeverageModeIx); + } + txsToSign.settlePnlTx = await this.buildTransaction( - [settlePnlIx], + ixs, txParams, this.txVersion, lookupTableAccounts,