-
Notifications
You must be signed in to change notification settings - Fork 2
/
LibPartyBQuoteActions.sol
43 lines (40 loc) · 1.8 KB
/
LibPartyBQuoteActions.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
// 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 "../storages/QuoteStorage.sol";
import "../storages/MAStorage.sol";
import "./LibAccount.sol";
import "./LibLockedValues.sol";
library LibPartyBQuoteActions {
using LockedValuesOps for LockedValues;
function lockQuote(uint256 quoteId) internal {
QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
AccountStorage.Layout storage accountLayout = AccountStorage.layout();
Quote storage quote = quoteLayout.quotes[quoteId];
require(quote.quoteStatus == QuoteStatus.PENDING, "PartyBFacet: Invalid state");
require(block.timestamp <= quote.deadline, "PartyBFacet: Quote is expired");
require(quoteId <= quoteLayout.lastId, "PartyBFacet: Invalid quoteId");
require(!MAStorage.layout().partyBLiquidationStatus[msg.sender][quote.partyA], "PartyBFacet: PartyB isn't solvent");
bool isValidPartyB;
if (quote.partyBsWhiteList.length == 0) {
require(msg.sender != quote.partyA, "PartyBFacet: PartyA can't be partyB too");
isValidPartyB = true;
} else {
for (uint8 index = 0; index < quote.partyBsWhiteList.length; index++) {
if (msg.sender == quote.partyBsWhiteList[index]) {
isValidPartyB = true;
break;
}
}
}
require(isValidPartyB, "PartyBFacet: Sender isn't whitelisted");
quote.statusModifyTimestamp = block.timestamp;
quote.quoteStatus = QuoteStatus.LOCKED;
quote.partyB = msg.sender;
// lock funds for partyB
accountLayout.partyBPendingLockedBalances[msg.sender][quote.partyA].addQuote(quote);
quoteLayout.partyBPendingQuotes[msg.sender][quote.partyA].push(quote.id);
}
}