-
Notifications
You must be signed in to change notification settings - Fork 15
/
SetUserConfiguration.sol
84 lines (69 loc) · 3.08 KB
/
SetUserConfiguration.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import {State, User} from "@src/SizeStorage.sol";
import {CreditPosition, LoanLibrary, LoanStatus} from "@src/libraries/LoanLibrary.sol";
import {Errors} from "@src/libraries/Errors.sol";
import {Events} from "@src/libraries/Events.sol";
struct SetUserConfigurationParams {
// The opening limit borrow CR
uint256 openingLimitBorrowCR;
// Whether all credit positions for sale are disabled
bool allCreditPositionsForSaleDisabled;
// Whether credit position IDs array are for sale
bool creditPositionIdsForSale;
// The credit position IDs array
uint256[] creditPositionIds;
}
/// @title SetUserConfiguration
/// @custom:security-contact [email protected]
/// @author Size (https://size.credit/)
library SetUserConfiguration {
using LoanLibrary for State;
/// @notice Validates the input parameters for setting user configuration
/// @param state The state
/// @param params The input parameters for setting user configuration
function validateSetUserConfiguration(State storage state, SetUserConfigurationParams calldata params)
external
view
{
// validate msg.sender
// N/A
// validate openingLimitBorrowCR
// N/A
// validate allCreditPositionsForSaleDisabled
// N/A
// validate creditPositionIdsForSale
// N/A
// validate creditPositionIds
for (uint256 i = 0; i < params.creditPositionIds.length; i++) {
CreditPosition storage creditPosition = state.getCreditPosition(params.creditPositionIds[i]);
if (creditPosition.lender != msg.sender) {
revert Errors.INVALID_CREDIT_POSITION_ID(params.creditPositionIds[i]);
}
if (state.getLoanStatus(params.creditPositionIds[i]) != LoanStatus.ACTIVE) {
revert Errors.LOAN_NOT_ACTIVE(params.creditPositionIds[i]);
}
}
}
/// @notice Executes the setting of user configuration
/// @param state The state
/// @param params The input parameters for setting user configuration
function executeSetUserConfiguration(State storage state, SetUserConfigurationParams calldata params) external {
User storage user = state.data.users[msg.sender];
user.openingLimitBorrowCR = params.openingLimitBorrowCR;
user.allCreditPositionsForSaleDisabled = params.allCreditPositionsForSaleDisabled;
for (uint256 i = 0; i < params.creditPositionIds.length; i++) {
CreditPosition storage creditPosition = state.getCreditPosition(params.creditPositionIds[i]);
creditPosition.forSale = params.creditPositionIdsForSale;
emit Events.UpdateCreditPosition(
params.creditPositionIds[i], creditPosition.lender, creditPosition.credit, creditPosition.forSale
);
}
emit Events.SetUserConfiguration(
params.openingLimitBorrowCR,
params.allCreditPositionsForSaleDisabled,
params.creditPositionIdsForSale,
params.creditPositionIds
);
}
}