From ad242c54abcd6e0cc309b5e009091ab38eaa8bfb Mon Sep 17 00:00:00 2001 From: Kazem Date: Wed, 20 Sep 2023 17:37:34 +0330 Subject: [PATCH] check partyB leverage --- contracts/facets/PartyA/PartyAFacetImpl.sol | 5 ++++- contracts/libraries/LibQuote.sol | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/contracts/facets/PartyA/PartyAFacetImpl.sol b/contracts/facets/PartyA/PartyAFacetImpl.sol index e1bbf18..6d349dd 100644 --- a/contracts/facets/PartyA/PartyAFacetImpl.sol +++ b/contracts/facets/PartyA/PartyAFacetImpl.sol @@ -52,7 +52,10 @@ library PartyAFacetImpl { lockedValues.totalForPartyA() <= notionalValue, "PartyAFacet: Leverage can't be lower than one" ); - // TODO: should we check for partyB + require( + lockedValues.totalForPartyB() <= notionalValue, + "PartyAFacet: Leverage for partyB can't be lower than one" + ); require( lockedValues.lf >= (symbolLayout.symbols[symbolId].minAcceptablePortionLF * lockedValues.totalForPartyA()) / diff --git a/contracts/libraries/LibQuote.sol b/contracts/libraries/LibQuote.sol index 9f8828c..fdfd4ad 100644 --- a/contracts/libraries/LibQuote.sol +++ b/contracts/libraries/LibQuote.sol @@ -132,9 +132,9 @@ library LibQuote { AccountStorage.Layout storage accountLayout = AccountStorage.layout(); SymbolStorage.Layout storage symbolLayout = SymbolStorage.layout(); - require(quote.lockedValues.cva * filledAmount / LibQuote.quoteOpenAmount(quote) > 0, "LibQuote: Low filled amount"); - require(quote.lockedValues.partyAmm * filledAmount / LibQuote.quoteOpenAmount(quote) > 0, "LibQuote: Low filled amount"); - require(quote.lockedValues.partyBmm * filledAmount / LibQuote.quoteOpenAmount(quote) > 0, "LibQuote: Low filled amount"); + require(quote.lockedValues.cva == 0 || quote.lockedValues.cva * filledAmount / LibQuote.quoteOpenAmount(quote) > 0, "LibQuote: Low filled amount"); + require(quote.lockedValues.partyAmm == 0 || quote.lockedValues.partyAmm * filledAmount / LibQuote.quoteOpenAmount(quote) > 0, "LibQuote: Low filled amount"); + require(quote.lockedValues.partyBmm == 0 || quote.lockedValues.partyBmm * filledAmount / LibQuote.quoteOpenAmount(quote) > 0, "LibQuote: Low filled amount"); require(quote.lockedValues.lf * filledAmount / LibQuote.quoteOpenAmount(quote) > 0, "LibQuote: Low filled amount"); LockedValues memory lockedValues = LockedValues( quote.lockedValues.cva -