Skip to content

Commit d414b57

Browse files
committed
fix: logic to return with liq buffer
1 parent c6b850e commit d414b57

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

sdk/src/user.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -600,13 +600,18 @@ export class User {
600600
if (perpMarketIndex !== undefined) {
601601
const isolatedMarginCalculation =
602602
marginCalc.isolatedMarginCalculations.get(perpMarketIndex);
603-
const { marginRequirement } = isolatedMarginCalculation;
603+
const { marginRequirement, marginRequirementPlusBuffer } = isolatedMarginCalculation;
604604

605+
if(liquidationBuffer?.gt(ZERO)){
606+
return marginRequirementPlusBuffer;
607+
}
605608
return marginRequirement;
606609
}
607610

608611
// Default: Cross margin requirement
609-
// TODO: should we be using plus buffer sometimes?
612+
if(liquidationBuffer?.gt(ZERO)){
613+
return marginCalc.marginRequirementPlusBuffer;
614+
}
610615
return marginCalc.marginRequirement;
611616
}
612617

@@ -620,7 +625,7 @@ export class User {
620625
return this.getMarginRequirement(
621626
'Initial',
622627
undefined,
623-
false,
628+
true,
624629
undefined,
625630
enterHighLeverageMode,
626631
perpMarketIndex
@@ -637,7 +642,7 @@ export class User {
637642
return this.getMarginRequirement(
638643
'Maintenance',
639644
liquidationBuffer,
640-
true, // strict default
645+
false, // strict default
641646
true, // includeOpenOrders default
642647
false, // enteringHighLeverage default
643648
perpMarketIndex
@@ -1236,10 +1241,16 @@ export class User {
12361241
});
12371242

12381243
if (perpMarketIndex !== undefined) {
1239-
return marginCalc.isolatedMarginCalculations.get(perpMarketIndex)
1240-
.totalCollateral;
1244+
const { totalCollateral, totalCollateralBuffer } = marginCalc.isolatedMarginCalculations.get(perpMarketIndex)
1245+
if(liquidationBuffer?.gt(ZERO)){
1246+
return totalCollateralBuffer;
1247+
}
1248+
return totalCollateral;
12411249
}
12421250

1251+
if(liquidationBuffer?.gt(ZERO)){
1252+
return marginCalc.totalCollateralBuffer;
1253+
}
12431254
return marginCalc.totalCollateral;
12441255
}
12451256

0 commit comments

Comments
 (0)