Skip to content

Commit 63154ae

Browse files
committed
fix: max margin ratio correct naming and decoding
1 parent bb9cd5c commit 63154ae

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

sdk/src/decode/user.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export function decodeUser(buffer: Buffer): UserAccount {
8484
const quoteAssetAmount = readSignedBigInt64LE(buffer, offset + 16);
8585
const lpShares = readUnsignedBigInt64LE(buffer, offset + 64);
8686
const openOrders = buffer.readUInt8(offset + 94);
87-
const customMarginRatio = buffer.readUInt32LE(offset + 95);
8887

8988
if (
9089
baseAssetAmount.eq(ZERO) &&
@@ -112,7 +111,7 @@ export function decodeUser(buffer: Buffer): UserAccount {
112111
offset += 8;
113112
const lastQuoteAssetAmountPerLp = readSignedBigInt64LE(buffer, offset);
114113
offset += 8;
115-
const remainderBaseAssetAmount = buffer.readInt32LE(offset);
114+
const maxMarginRatio = buffer.readInt32LE(offset);
116115
offset += 4;
117116
const marketIndex = buffer.readUInt16LE(offset);
118117
offset += 3;
@@ -129,13 +128,13 @@ export function decodeUser(buffer: Buffer): UserAccount {
129128
openAsks,
130129
settledPnl,
131130
lpShares,
131+
remainderBaseAssetAmount: 0,
132132
lastBaseAssetAmountPerLp,
133133
lastQuoteAssetAmountPerLp,
134-
remainderBaseAssetAmount,
135134
marketIndex,
136135
openOrders,
137136
perLpBase,
138-
customMarginRatio,
137+
maxMarginRatio,
139138
});
140139
}
141140

sdk/src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,11 +1042,12 @@ export type PerpPosition = {
10421042
openAsks: BN;
10431043
settledPnl: BN;
10441044
lpShares: BN;
1045+
/** TODO: remove this field - it doesn't exist on chain */
10451046
remainderBaseAssetAmount: number;
1047+
maxMarginRatio: number;
10461048
lastBaseAssetAmountPerLp: BN;
10471049
lastQuoteAssetAmountPerLp: BN;
10481050
perLpBase: number;
1049-
customMarginRatio: number;
10501051
};
10511052

10521053
export type UserStatsAccount = {

sdk/src/user.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export class User {
325325
lastBaseAssetAmountPerLp: ZERO,
326326
lastQuoteAssetAmountPerLp: ZERO,
327327
perLpBase: 0,
328-
customMarginRatio: 0,
328+
maxMarginRatio: 0,
329329
};
330330
}
331331

@@ -715,7 +715,7 @@ export class User {
715715
perpPosition?: PerpPosition
716716
): BN {
717717
const userCustomMargin = Math.max(
718-
perpPosition?.customMarginRatio ?? 0,
718+
perpPosition?.maxMarginRatio ?? 0,
719719
this.getUserAccount().maxMarginRatio
720720
);
721721
const marginRatio = calculateMarketMarginRatio(
@@ -2447,7 +2447,7 @@ export class User {
24472447
}
24482448

24492449
const userCustomMargin = Math.max(
2450-
perpPosition.customMarginRatio,
2450+
perpPosition.maxMarginRatio,
24512451
this.getUserAccount().maxMarginRatio
24522452
);
24532453
const marginRatio = calculateMarketMarginRatio(
@@ -2500,7 +2500,7 @@ export class User {
25002500
const proposedBaseAssetAmount = baseAssetAmount.add(positionBaseSizeChange);
25012501

25022502
const userCustomMargin = Math.max(
2503-
perpPosition.customMarginRatio,
2503+
perpPosition.maxMarginRatio,
25042504
this.getUserAccount().maxMarginRatio
25052505
);
25062506

@@ -3882,7 +3882,7 @@ export class User {
38823882
);
38833883

38843884
const userCustomMargin = Math.max(
3885-
perpPosition.customMarginRatio,
3885+
perpPosition.maxMarginRatio,
38863886
this.getUserAccount().maxMarginRatio
38873887
);
38883888
const marginRatio = new BN(

0 commit comments

Comments
 (0)