Skip to content

Commit

Permalink
add minMargin buffer in vault
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrizzle committed Sep 4, 2023
1 parent 6d192cc commit 89efc21
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/perennial-vault/contracts/lib/StrategyLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ library StrategyLib {
.muldiv(registrations[marketId].weight, totalWeight)
.min(_locals.marketCollateral.mul(LEVERAGE_BUFFER));

if (
contexts[marketId].marketParameter.closed ||
_locals.marketAssets.lt(contexts[marketId].riskParameter.minMargin)
) _locals.marketAssets = UFixed6Lib.ZERO;
UFixed6 minAssets = contexts[marketId].riskParameter.minMargin
.unsafeDiv(registrations[marketId].leverage.mul(contexts[marketId].riskParameter.maintenance));
if (contexts[marketId].marketParameter.closed || _locals.marketAssets.lt(minAssets))
_locals.marketAssets = UFixed6Lib.ZERO;

(_locals.minPosition, _locals.maxPosition) = _positionLimit(contexts[marketId]);

Expand Down
2 changes: 2 additions & 0 deletions packages/perennial-vault/test/integration/vault/Vault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ describe('Vault', () => {
oracle: rootOracle.address,
payoff: constants.AddressZero,
makerLimit: parse6decimal('1000'),
minMargin: parse6decimal('50'),
minMaintenance: parse6decimal('50'),
maxLiquidationFee: parse6decimal('25000'),
})
Expand All @@ -214,6 +215,7 @@ describe('Vault', () => {
owner: owner,
oracle: btcRootOracle.address,
payoff: constants.AddressZero,
minMargin: parse6decimal('50'),
minMaintenance: parse6decimal('50'),
maxLiquidationFee: parse6decimal('25000'),
})
Expand Down

0 comments on commit 89efc21

Please sign in to comment.