Skip to content

Commit 68ee193

Browse files
committed
fix margin ratio calc
1 parent 9b4228e commit 68ee193

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sdk/src/driftClient.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ import { TxSender, TxSigAndSlot } from './tx/types';
124124
import {
125125
BASE_PRECISION,
126126
GOV_SPOT_MARKET_INDEX,
127+
MARGIN_PRECISION,
127128
ONE,
128129
PERCENTAGE_PRECISION,
129130
PRICE_PRECISION,
@@ -4798,11 +4799,15 @@ export class DriftClient {
47984799
}
47994800
);
48004801

4802+
const marginRatio = Math.floor(
4803+
(1 / positionMaxLev) * MARGIN_PRECISION.toNumber()
4804+
);
4805+
48014806
// TODO: Handle multiple markets?
48024807
const setPositionMaxLevIxs =
48034808
await this.getUpdateUserPerpPositionCustomMarginRatioIx(
48044809
readablePerpMarketIndex[0],
4805-
1 / positionMaxLev,
4810+
marginRatio,
48064811
subAccountId
48074812
);
48084813

0 commit comments

Comments
 (0)