Skip to content

Commit 27588b2

Browse files
committed
allow enter HLM on position margin ratio update
1 parent bfbe20b commit 27588b2

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

sdk/src/driftClient.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,14 +1570,21 @@ export class DriftClient {
15701570
perpMarketIndex: number,
15711571
marginRatio: number,
15721572
subAccountId = 0,
1573-
txParams?: TxParams
1573+
txParams?: TxParams,
1574+
enterHighLeverageMode?: boolean
15741575
): Promise<TransactionSignature> {
1575-
const ix = await this.getUpdateUserPerpPositionCustomMarginRatioIx(
1576+
const ixs = [];
1577+
if (enterHighLeverageMode) {
1578+
const enableIx = await this.getEnableHighLeverageModeIx(subAccountId);
1579+
ixs.push(enableIx);
1580+
}
1581+
const updateIx = await this.getUpdateUserPerpPositionCustomMarginRatioIx(
15761582
perpMarketIndex,
15771583
marginRatio,
15781584
subAccountId
15791585
);
1580-
const tx = await this.buildTransaction(ix, txParams ?? this.txParams);
1586+
ixs.push(updateIx);
1587+
const tx = await this.buildTransaction(ixs, txParams ?? this.txParams);
15811588
const { txSig } = await this.sendTransaction(tx, [], this.opts);
15821589
return txSig;
15831590
}
@@ -4958,9 +4965,8 @@ export class DriftClient {
49584965
subAccountId?: number
49594966
): Promise<TransactionSignature> {
49604967
const { txSig, slot } = await this.sendTransaction(
4961-
(
4962-
await this.preparePlaceSpotOrderTx(orderParams, txParams, subAccountId)
4963-
).placeSpotOrderTx,
4968+
(await this.preparePlaceSpotOrderTx(orderParams, txParams, subAccountId))
4969+
.placeSpotOrderTx,
49644970
[],
49654971
this.opts,
49664972
false

sdk/src/user.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,6 @@ export class User {
10271027

10281028
if (marketIndex === undefined || marketIndex === QUOTE_SPOT_MARKET_INDEX) {
10291029
if (netQuoteValue.gt(ZERO)) {
1030-
10311030
totalAssetValue = totalAssetValue.add(netQuoteValue);
10321031
} else {
10331032
totalLiabilityValue = totalLiabilityValue.add(netQuoteValue.abs());
@@ -2465,7 +2464,10 @@ export class User {
24652464
const marginRequirement = this.getInitialMarginRequirement(
24662465
enterHighLeverageMode
24672466
);
2468-
const marginRatio = Math.max(currentPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
2467+
const marginRatio = Math.max(
2468+
currentPosition.maxMarginRatio,
2469+
this.getUserAccount().maxMarginRatio
2470+
);
24692471
const marginFreedByClosing = perpLiabilityValue
24702472
.mul(new BN(marginRatio))
24712473
.div(MARGIN_PRECISION);

0 commit comments

Comments
 (0)