@ensuro/core 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +93 -0
  2. package/build/contracts/AaveAssetManager.sol/AaveAssetManager.json +772 -0
  3. package/build/contracts/BaseAssetManager.sol/BaseAssetManager.json +494 -0
  4. package/build/contracts/DataTypes.sol/DataTypes.json +10 -0
  5. package/build/contracts/EToken.sol/EToken.json +1148 -0
  6. package/build/contracts/FlightDelayRiskModule.sol/FlightDelayRiskModule.json +1093 -0
  7. package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +412 -0
  8. package/build/contracts/Policy.sol/Policy.json +10 -0
  9. package/build/contracts/PolicyNFT.sol/PolicyNFT.json +570 -0
  10. package/build/contracts/PolicyPool.sol/PolicyPool.json +1257 -0
  11. package/build/contracts/PolicyPoolComponent.sol/PolicyPoolComponent.json +281 -0
  12. package/build/contracts/PolicyPoolConfig.sol/PolicyPoolConfig.json +660 -0
  13. package/build/contracts/RiskModule.sol/RiskModule.json +748 -0
  14. package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +1032 -0
  15. package/build/contracts/WadRayMath.sol/WadRayMath.json +10 -0
  16. package/build/contracts/dependencies/ChainlinkClientUpgradeable.sol/ChainlinkClientUpgradeable.json +50 -0
  17. package/build/contracts/upgraded/IPolicyNFTv1.sol/IPolicyNFTv1.json +322 -0
  18. package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1.json +571 -0
  19. package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1_Upgrade.json +602 -0
  20. package/build/interfaces/IAssetManager.sol/IAssetManager.json +31 -0
  21. package/build/interfaces/IEToken.sol/IEToken.json +491 -0
  22. package/build/interfaces/IInsolvencyHook.sol/IInsolvencyHook.json +42 -0
  23. package/build/interfaces/ILPWhitelist.sol/ILPWhitelist.json +74 -0
  24. package/build/interfaces/IPolicyNFT.sol/IPolicyNFT.json +321 -0
  25. package/build/interfaces/IPolicyPool.sol/IPolicyPool.json +445 -0
  26. package/build/interfaces/IPolicyPoolComponent.sol/IPolicyPoolComponent.json +24 -0
  27. package/build/interfaces/IPolicyPoolConfig.sol/IPolicyPoolConfig.json +328 -0
  28. package/build/interfaces/IRiskModule.sol/IRiskModule.json +141 -0
  29. package/contracts/AaveAssetManager.sol +326 -0
  30. package/contracts/BaseAssetManager.sol +283 -0
  31. package/contracts/DataTypes.sol +287 -0
  32. package/contracts/EToken.sol +773 -0
  33. package/contracts/FlightDelayRiskModule.sol +208 -0
  34. package/contracts/LPManualWhitelist.sol +57 -0
  35. package/contracts/Policy.sol +104 -0
  36. package/contracts/PolicyNFT.sol +96 -0
  37. package/contracts/PolicyPool.sol +716 -0
  38. package/contracts/PolicyPoolComponent.sol +164 -0
  39. package/contracts/PolicyPoolConfig.sol +231 -0
  40. package/contracts/RiskModule.sol +323 -0
  41. package/contracts/TrustfulRiskModule.sol +81 -0
  42. package/contracts/WadRayMath.sol +135 -0
  43. package/contracts/dependencies/ChainlinkClientUpgradeable.sol +371 -0
  44. package/contracts/upgraded/IPolicyNFTv1.sol +15 -0
  45. package/contracts/upgraded/PolicyNFTv1.sol +126 -0
  46. package/interfaces/IAssetManager.sol +23 -0
  47. package/interfaces/IEToken.sol +44 -0
  48. package/interfaces/IInsolvencyHook.sol +27 -0
  49. package/interfaces/ILPWhitelist.sol +23 -0
  50. package/interfaces/IPolicyNFT.sol +15 -0
  51. package/interfaces/IPolicyPool.sol +44 -0
  52. package/interfaces/IPolicyPoolComponent.sol +13 -0
  53. package/interfaces/IPolicyPoolConfig.sol +81 -0
  54. package/interfaces/IRiskModule.sol +29 -0
  55. package/package.json +30 -0
@@ -0,0 +1,287 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
6
+ import {IEToken} from "../interfaces/IEToken.sol";
7
+
8
+ /**
9
+ * @title DataTypes library
10
+ * @dev Library with two EnumerableSet:
11
+ * - ETokenToWadMap: enumerable mapping(EToken ==> amount)
12
+ * - ETokenStatusMap: enumerable mapping(EToken ==> ETokenStatus)
13
+ * @custom:security-contact security@ensuro.co
14
+ * @author Ensuro
15
+ */
16
+ library DataTypes {
17
+ using EnumerableSet for EnumerableSet.AddressSet;
18
+
19
+ enum ETokenStatus {
20
+ inactive, // doesn't exists - All operations rejected
21
+ active, // deposit / withdraw / lockScr / unlockScr OK
22
+ deprecated, // withdraw OK, unlockScr OK, deposit rejected, no new policies
23
+ suspended // all operations temporarily rejected
24
+ }
25
+
26
+ // Copied from OpenZeppelin's EnumerableMap but with address as keys
27
+ // and reimplemented with interfaces as keys
28
+ // To implement this library for multiple types with as little code
29
+ // repetition as possible, we write it in terms of a generic Map type with
30
+ // address keys and uint256 values.
31
+ // The Map implementation uses private functions, and user-facing
32
+ // implementations (such as Uint256ToAddressMap) are just wrappers around
33
+ // the underlying Map.
34
+
35
+ struct Map {
36
+ // Storage of keys
37
+ EnumerableSet.AddressSet _keys;
38
+ mapping(address => uint256) _values;
39
+ }
40
+
41
+ /**
42
+ * @dev Adds a key-value pair to a map, or updates the value for an existing
43
+ * key. O(1).
44
+ *
45
+ * Returns true if the key was added to the map, that is if it was not
46
+ * already present.
47
+ */
48
+ function _set(
49
+ Map storage map,
50
+ address key,
51
+ uint256 value
52
+ ) private returns (bool) {
53
+ map._values[key] = value;
54
+ return map._keys.add(key);
55
+ }
56
+
57
+ /**
58
+ * @dev Removes a key-value pair from a map. O(1).
59
+ *
60
+ * Returns true if the key was removed from the map, that is if it was present.
61
+ */
62
+ function _remove(Map storage map, address key) private returns (bool) {
63
+ delete map._values[key];
64
+ return map._keys.remove(key);
65
+ }
66
+
67
+ /**
68
+ * @dev Returns true if the key is in the map. O(1).
69
+ */
70
+ function _contains(Map storage map, address key) private view returns (bool) {
71
+ return map._keys.contains(key);
72
+ }
73
+
74
+ /**
75
+ * @dev Returns the number of key-value pairs in the map. O(1).
76
+ */
77
+ function _length(Map storage map) private view returns (uint256) {
78
+ return map._keys.length();
79
+ }
80
+
81
+ /**
82
+ * @dev Returns the key-value pair stored at position `index` in the map. O(1).
83
+ *
84
+ * Note that there are no guarantees on the ordering of entries inside the
85
+ * array, and it may change when more entries are added or removed.
86
+ *
87
+ * Requirements:
88
+ *
89
+ * - `index` must be strictly less than {length}.
90
+ */
91
+ function _at(Map storage map, uint256 index) private view returns (address, uint256) {
92
+ address key = map._keys.at(index);
93
+ return (key, map._values[key]);
94
+ }
95
+
96
+ /**
97
+ * @dev Tries to returns the value associated with `key`. O(1).
98
+ * Does not revert if `key` is not in the map.
99
+ */
100
+ function _tryGet(Map storage map, address key) private view returns (bool, uint256) {
101
+ uint256 value = map._values[key];
102
+ if (value == 0) {
103
+ return (_contains(map, key), 0);
104
+ } else {
105
+ return (true, value);
106
+ }
107
+ }
108
+
109
+ /**
110
+ * @dev Returns the value associated with `key`. O(1).
111
+ *
112
+ * Requirements:
113
+ *
114
+ * - `key` must be in the map.
115
+ */
116
+ function _get(Map storage map, address key) private view returns (uint256) {
117
+ uint256 value = map._values[key];
118
+ require(value != 0 || _contains(map, key), "EnumerableMap: nonexistent key");
119
+ return value;
120
+ }
121
+
122
+ // ETokenToWadMap
123
+ struct ETokenToWadMap {
124
+ Map _inner;
125
+ }
126
+
127
+ /**
128
+ * @dev Adds a key-value pair to a map, or updates the value for an existing
129
+ * key. O(1).
130
+ *
131
+ * Returns true if the key was added to the map, that is if it was not
132
+ * already present.
133
+ */
134
+ function set(
135
+ ETokenToWadMap storage map,
136
+ IEToken key,
137
+ uint256 value
138
+ ) internal returns (bool) {
139
+ return _set(map._inner, address(key), value);
140
+ }
141
+
142
+ /**
143
+ * @dev Removes a value from a set. O(1).
144
+ *
145
+ * Returns true if the key was removed from the map, that is if it was present.
146
+ */
147
+ function remove(ETokenToWadMap storage map, IEToken key) internal returns (bool) {
148
+ return _remove(map._inner, address(key));
149
+ }
150
+
151
+ /**
152
+ * @dev Returns true if the key is in the map. O(1).
153
+ */
154
+ function contains(ETokenToWadMap storage map, IEToken key) internal view returns (bool) {
155
+ return _contains(map._inner, address(key));
156
+ }
157
+
158
+ /**
159
+ * @dev Returns the number of elements in the map. O(1).
160
+ */
161
+ function length(ETokenToWadMap storage map) internal view returns (uint256) {
162
+ return _length(map._inner);
163
+ }
164
+
165
+ /**
166
+ * @dev Returns the element stored at position `index` in the set. O(1).
167
+ * Note that there are no guarantees on the ordering of values inside the
168
+ * array, and it may change when more values are added or removed.
169
+ *
170
+ * Requirements:
171
+ *
172
+ * - `index` must be strictly less than {length}.
173
+ */
174
+ function at(ETokenToWadMap storage map, uint256 index) internal view returns (IEToken, uint256) {
175
+ (address key, uint256 value) = _at(map._inner, index);
176
+ return (IEToken(key), value);
177
+ }
178
+
179
+ /**
180
+ * @dev Tries to returns the value associated with `key`. O(1).
181
+ * Does not revert if `key` is not in the map.
182
+ *
183
+ * _Available since v3.4._
184
+ */
185
+ function tryGet(ETokenToWadMap storage map, IEToken key) internal view returns (bool, uint256) {
186
+ (bool success, uint256 value) = _tryGet(map._inner, address(key));
187
+ return (success, value);
188
+ }
189
+
190
+ /**
191
+ * @dev Returns the value associated with `key`. O(1).
192
+ *
193
+ * Requirements:
194
+ *
195
+ * - `key` must be in the map.
196
+ */
197
+ function get(ETokenToWadMap storage map, IEToken key) internal view returns (uint256) {
198
+ return uint256(_get(map._inner, address(key)));
199
+ }
200
+
201
+ // ETokenStatusMap
202
+ struct ETokenStatusMap {
203
+ Map _inner;
204
+ }
205
+
206
+ /**
207
+ * @dev Adds a key-value pair to a map, or updates the value for an existing
208
+ * key. O(1).
209
+ *
210
+ * Returns true if the key was added to the map, that is if it was not
211
+ * already present.
212
+ */
213
+ function set(
214
+ ETokenStatusMap storage map,
215
+ IEToken key,
216
+ ETokenStatus value
217
+ ) internal returns (bool) {
218
+ return _set(map._inner, address(key), uint256(value));
219
+ }
220
+
221
+ /**
222
+ * @dev Removes a value from a set. O(1).
223
+ *
224
+ * Returns true if the key was removed from the map, that is if it was present.
225
+ */
226
+ function remove(ETokenStatusMap storage map, IEToken key) internal returns (bool) {
227
+ return _remove(map._inner, address(key));
228
+ }
229
+
230
+ /**
231
+ * @dev Returns true if the key is in the map. O(1).
232
+ */
233
+ function contains(ETokenStatusMap storage map, IEToken key) internal view returns (bool) {
234
+ return _contains(map._inner, address(key));
235
+ }
236
+
237
+ /**
238
+ * @dev Returns the number of elements in the map. O(1).
239
+ */
240
+ function length(ETokenStatusMap storage map) internal view returns (uint256) {
241
+ return _length(map._inner);
242
+ }
243
+
244
+ /**
245
+ * @dev Returns the element stored at position `index` in the set. O(1).
246
+ * Note that there are no guarantees on the ordering of values inside the
247
+ * array, and it may change when more values are added or removed.
248
+ *
249
+ * Requirements:
250
+ *
251
+ * - `index` must be strictly less than {length}.
252
+ */
253
+ function at(ETokenStatusMap storage map, uint256 index)
254
+ internal
255
+ view
256
+ returns (IEToken, ETokenStatus)
257
+ {
258
+ (address key, uint256 value) = _at(map._inner, index);
259
+ return (IEToken(key), ETokenStatus(value));
260
+ }
261
+
262
+ /**
263
+ * @dev Tries to returns the value associated with `key`. O(1).
264
+ * Does not revert if `key` is not in the map.
265
+ *
266
+ * _Available since v3.4._
267
+ */
268
+ function tryGet(ETokenStatusMap storage map, IEToken key)
269
+ internal
270
+ view
271
+ returns (bool, ETokenStatus)
272
+ {
273
+ (bool success, uint256 value) = _tryGet(map._inner, address(key));
274
+ return (success, ETokenStatus(value));
275
+ }
276
+
277
+ /**
278
+ * @dev Returns the value associated with `key`. O(1).
279
+ *
280
+ * Requirements:
281
+ *
282
+ * - `key` must be in the map.
283
+ */
284
+ function get(ETokenStatusMap storage map, IEToken key) internal view returns (ETokenStatus) {
285
+ return ETokenStatus(_get(map._inner, address(key)));
286
+ }
287
+ }