Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions sdk/src/driftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1570,14 +1570,21 @@ export class DriftClient {
perpMarketIndex: number,
marginRatio: number,
subAccountId = 0,
txParams?: TxParams
txParams?: TxParams,
enterHighLeverageMode?: boolean
): Promise<TransactionSignature> {
const ix = await this.getUpdateUserPerpPositionCustomMarginRatioIx(
const ixs = [];
if (enterHighLeverageMode) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lowkeynicc I think just wanna call out that we will need to update the slider in the modal to always have the HLM max as the absolute max leverage available.

const enableIx = await this.getEnableHighLeverageModeIx(subAccountId);
ixs.push(enableIx);
}
const updateIx = await this.getUpdateUserPerpPositionCustomMarginRatioIx(
perpMarketIndex,
marginRatio,
subAccountId
);
const tx = await this.buildTransaction(ix, txParams ?? this.txParams);
ixs.push(updateIx);
const tx = await this.buildTransaction(ixs, txParams ?? this.txParams);
const { txSig } = await this.sendTransaction(tx, [], this.opts);
return txSig;
}
Expand Down Expand Up @@ -4958,9 +4965,8 @@ export class DriftClient {
subAccountId?: number
): Promise<TransactionSignature> {
const { txSig, slot } = await this.sendTransaction(
(
await this.preparePlaceSpotOrderTx(orderParams, txParams, subAccountId)
).placeSpotOrderTx,
(await this.preparePlaceSpotOrderTx(orderParams, txParams, subAccountId))
.placeSpotOrderTx,
[],
this.opts,
false
Expand Down
6 changes: 4 additions & 2 deletions sdk/src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,6 @@ export class User {

if (marketIndex === undefined || marketIndex === QUOTE_SPOT_MARKET_INDEX) {
if (netQuoteValue.gt(ZERO)) {

totalAssetValue = totalAssetValue.add(netQuoteValue);
} else {
totalLiabilityValue = totalLiabilityValue.add(netQuoteValue.abs());
Expand Down Expand Up @@ -2465,7 +2464,10 @@ export class User {
const marginRequirement = this.getInitialMarginRequirement(
enterHighLeverageMode
);
const marginRatio = Math.max(currentPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
const marginRatio = Math.max(
currentPosition.maxMarginRatio,
this.getUserAccount().maxMarginRatio
);
const marginFreedByClosing = perpLiabilityValue
.mul(new BN(marginRatio))
.div(MARGIN_PRECISION);
Expand Down