forked from sherlock-audit/2023-06-symmetrical
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PartyAFacet.sol
170 lines (160 loc) · 5.33 KB
/
PartyAFacet.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;
import "./PartyAFacetImpl.sol";
import "../../utils/Accessibility.sol";
import "../../utils/Pausable.sol";
import "./IPartyAEvents.sol";
contract PartyAFacet is Accessibility, Pausable, IPartyAEvents {
function sendQuote(
address[] memory partyBsWhiteList,
uint256 symbolId,
PositionType positionType,
OrderType orderType,
uint256 price,
uint256 quantity,
uint256 cva,
uint256 mm,
uint256 lf,
uint256 maxInterestRate,
uint256 deadline,
SingleUpnlAndPriceSig memory upnlSig
) external whenNotPartyAActionsPaused notLiquidatedPartyA(msg.sender) notSuspended(msg.sender) {
uint256 quoteId = PartyAFacetImpl.sendQuote(
partyBsWhiteList,
symbolId,
positionType,
orderType,
price,
quantity,
cva,
mm,
lf,
maxInterestRate,
deadline,
upnlSig
);
Quote storage quote = QuoteStorage.layout().quotes[quoteId];
emit SendQuote(
msg.sender,
quoteId,
partyBsWhiteList,
symbolId,
positionType,
orderType,
price,
upnlSig.price,
quantity,
quote.lockedValues.cva,
quote.lockedValues.mm,
quote.lockedValues.lf,
maxInterestRate,
deadline,
QuoteStatus.PENDING
);
}
function expireQuote(uint256[] memory expiredQuoteIds) external whenNotPartyAActionsPaused {
QuoteStatus result;
for (uint8 i; i < expiredQuoteIds.length; i++) {
result = LibQuote.expireQuote(expiredQuoteIds[i]);
emit ExpireQuote(result, expiredQuoteIds[i]);
}
}
function requestToCancelQuote(uint256 quoteId)
external
whenNotPartyAActionsPaused
onlyPartyAOfQuote(quoteId)
notLiquidated(quoteId)
{
QuoteStatus result = PartyAFacetImpl.requestToCancelQuote(quoteId);
Quote storage quote = QuoteStorage.layout().quotes[quoteId];
if (result == QuoteStatus.EXPIRED) {
emit ExpireQuote(result, quoteId);
} else if (result == QuoteStatus.CANCELED || result == QuoteStatus.CANCEL_PENDING) {
emit RequestToCancelQuote(quote.partyA, quote.partyB, result, quoteId);
}
}
function requestToClosePosition(
uint256 quoteId,
uint256 closePrice,
uint256 quantityToClose,
OrderType orderType,
uint256 deadline,
SingleUpnlAndPriceSig memory upnlSig
) external whenNotPartyAActionsPaused onlyPartyAOfQuote(quoteId) notLiquidated(quoteId) {
PartyAFacetImpl.requestToClosePosition(
quoteId,
closePrice,
quantityToClose,
orderType,
deadline,
upnlSig
);
Quote storage quote = QuoteStorage.layout().quotes[quoteId];
emit RequestToClosePosition(
quote.partyA,
quote.partyB,
quoteId,
closePrice,
quantityToClose,
orderType,
deadline,
QuoteStatus.CLOSE_PENDING
);
}
function requestToCancelCloseRequest(uint256 quoteId)
external
whenNotPartyAActionsPaused
onlyPartyAOfQuote(quoteId)
notLiquidated(quoteId)
{
QuoteStatus result = PartyAFacetImpl.requestToCancelCloseRequest(quoteId);
Quote storage quote = QuoteStorage.layout().quotes[quoteId];
if (result == QuoteStatus.OPENED) {
emit ExpireQuote(QuoteStatus.OPENED, quoteId);
} else if (result == QuoteStatus.CANCEL_CLOSE_PENDING) {
emit RequestToCancelCloseRequest(
quote.partyA,
quote.partyB,
quoteId,
QuoteStatus.CANCEL_CLOSE_PENDING
);
}
}
function forceCancelQuote(uint256 quoteId)
external
notLiquidated(quoteId)
whenNotPartyAActionsPaused
{
PartyAFacetImpl.forceCancelQuote(quoteId);
emit ForceCancelQuote(quoteId, QuoteStatus.CANCELED);
}
function forceCancelCloseRequest(uint256 quoteId)
external
notLiquidated(quoteId)
whenNotPartyAActionsPaused
{
PartyAFacetImpl.forceCancelCloseRequest(quoteId);
emit ForceCancelCloseRequest(quoteId, QuoteStatus.OPENED);
}
function forceClosePosition(uint256 quoteId, PairUpnlAndPriceSig memory upnlSig)
external
notLiquidated(quoteId)
whenNotPartyAActionsPaused
{
Quote storage quote = QuoteStorage.layout().quotes[quoteId];
uint256 filledAmount = quote.quantityToClose;
uint256 requestedClosePrice = quote.requestedClosePrice;
PartyAFacetImpl.forceClosePosition(quoteId, upnlSig);
emit ForceClosePosition(
quoteId,
quote.partyA,
quote.partyB,
filledAmount,
requestedClosePrice,
quote.quoteStatus
);
}
}