forked from sherlock-audit/2023-06-symmetrical
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibLockedValues.sol
103 lines (90 loc) · 2.77 KB
/
LibLockedValues.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
// 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 "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "../storages/QuoteStorage.sol";
struct LockedValues {
uint256 cva;
uint256 mm;
uint256 lf;
}
library LockedValuesOps {
using SafeMath for uint256;
function add(LockedValues storage self, LockedValues memory a)
internal
returns (LockedValues storage)
{
self.cva = self.cva.add(a.cva);
self.mm = self.mm.add(a.mm);
self.lf = self.lf.add(a.lf);
return self;
}
function addQuote(LockedValues storage self, Quote storage quote)
internal
returns (LockedValues storage)
{
return add(self, quote.lockedValues);
}
function sub(LockedValues storage self, LockedValues memory a)
internal
returns (LockedValues storage)
{
self.cva = self.cva.sub(a.cva);
self.mm = self.mm.sub(a.mm);
self.lf = self.lf.sub(a.lf);
return self;
}
function subQuote(LockedValues storage self, Quote storage quote)
internal
returns (LockedValues storage)
{
return sub(self, quote.lockedValues);
}
function makeZero(LockedValues storage self) internal returns (LockedValues storage) {
self.cva = 0;
self.mm = 0;
self.lf = 0;
return self;
}
function total(LockedValues memory self) internal pure returns (uint256) {
return self.cva + self.mm + self.lf;
}
function mul(LockedValues storage self, uint256 a) internal returns (LockedValues storage) {
self.cva = self.cva.mul(a);
self.mm = self.mm.mul(a);
self.lf = self.lf.mul(a);
return self;
}
function mulMem(LockedValues memory self, uint256 a)
internal
pure
returns (LockedValues memory)
{
LockedValues memory lockedValues = LockedValues(
self.cva.mul(a),
self.mm.mul(a),
self.lf.mul(a)
);
return lockedValues;
}
function div(LockedValues storage self, uint256 a) internal returns (LockedValues storage) {
self.cva = self.cva.div(a);
self.mm = self.mm.div(a);
self.lf = self.lf.div(a);
return self;
}
function divMem(LockedValues memory self, uint256 a)
internal
pure
returns (LockedValues memory)
{
LockedValues memory lockedValues = LockedValues(
self.cva.div(a),
self.mm.div(a),
self.lf.div(a)
);
return lockedValues;
}
}