@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,371 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {Chainlink} from "@chainlink/contracts/src/v0.8/Chainlink.sol";
5
+ import {ENSInterface} from "@chainlink/contracts/src/v0.8/interfaces/ENSInterface.sol";
6
+ import {LinkTokenInterface} from "@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol";
7
+ import {OperatorInterface} from "@chainlink/contracts/src/v0.8/interfaces/OperatorInterface.sol";
8
+ import {PointerInterface} from "@chainlink/contracts/src/v0.8/interfaces/PointerInterface.sol";
9
+ import {ENSResolver as ENSResolver_Chainlink} from "@chainlink/contracts/src/v0.8/vendor/ENSResolver.sol";
10
+ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
11
+
12
+ /**
13
+ * @title The ChainlinkClient contract in upgradeable version
14
+ * @dev Changes to make it compatible with OZ UUPS proxies
15
+ * @notice Contract writers can inherit this contract in order to create requests for the
16
+ * Chainlink network
17
+ */
18
+ contract ChainlinkClientUpgradeable is Initializable {
19
+ using Chainlink for Chainlink.Request;
20
+
21
+ uint256 constant internal LINK_DIVISIBILITY = 10**18;
22
+ uint256 constant private AMOUNT_OVERRIDE = 0;
23
+ address constant private SENDER_OVERRIDE = address(0);
24
+ uint256 constant private ORACLE_ARGS_VERSION = 1;
25
+ uint256 constant private OPERATOR_ARGS_VERSION = 2;
26
+ bytes32 constant private ENS_TOKEN_SUBNAME = keccak256("link");
27
+ bytes32 constant private ENS_ORACLE_SUBNAME = keccak256("oracle");
28
+ address constant private LINK_TOKEN_POINTER = 0xC89bD4E1632D3A43CB03AAAd5262cbe4038Bc571;
29
+
30
+ ENSInterface private ens;
31
+ bytes32 private ensNode;
32
+ LinkTokenInterface private link;
33
+ OperatorInterface private oracle;
34
+ uint256 private requestCount;
35
+ mapping(bytes32 => address) private pendingRequests;
36
+
37
+ event ChainlinkRequested(
38
+ bytes32 indexed id
39
+ );
40
+ event ChainlinkFulfilled(
41
+ bytes32 indexed id
42
+ );
43
+ event ChainlinkCancelled(
44
+ bytes32 indexed id
45
+ );
46
+
47
+ function __ChainlinkClient_init() internal initializer {
48
+ requestCount = 1;
49
+ }
50
+
51
+ /**
52
+ * @notice Creates a request that can hold additional parameters
53
+ * @param specId The Job Specification ID that the request will be created for
54
+ * @param callbackAddress The callback address that the response will be sent to
55
+ * @param callbackFunctionSignature The callback function signature to use for the callback address
56
+ * @return A Chainlink Request struct in memory
57
+ */
58
+ function buildChainlinkRequest(
59
+ bytes32 specId,
60
+ address callbackAddress,
61
+ bytes4 callbackFunctionSignature
62
+ )
63
+ internal
64
+ pure
65
+ returns (
66
+ Chainlink.Request memory
67
+ )
68
+ {
69
+ Chainlink.Request memory req;
70
+ return req.initialize(specId, callbackAddress, callbackFunctionSignature);
71
+ }
72
+
73
+ /**
74
+ * @notice Creates a Chainlink request to the stored oracle address
75
+ * @dev Calls `chainlinkRequestTo` with the stored oracle address
76
+ * @param req The initialized Chainlink Request
77
+ * @param payment The amount of LINK to send for the request
78
+ * @return requestId The request ID
79
+ */
80
+ function sendChainlinkRequest(
81
+ Chainlink.Request memory req,
82
+ uint256 payment
83
+ )
84
+ internal
85
+ returns (
86
+ bytes32
87
+ )
88
+ {
89
+ return sendChainlinkRequestTo(address(oracle), req, payment);
90
+ }
91
+
92
+ /**
93
+ * @notice Creates a Chainlink request to the specified oracle address
94
+ * @dev Generates and stores a request ID, increments the local nonce, and uses `transferAndCall` to
95
+ * send LINK which creates a request on the target oracle contract.
96
+ * Emits ChainlinkRequested event.
97
+ * @param oracleAddress The address of the oracle for the request
98
+ * @param req The initialized Chainlink Request
99
+ * @param payment The amount of LINK to send for the request
100
+ * @return requestId The request ID
101
+ */
102
+ function sendChainlinkRequestTo(
103
+ address oracleAddress,
104
+ Chainlink.Request memory req,
105
+ uint256 payment
106
+ )
107
+ internal
108
+ returns (
109
+ bytes32 requestId
110
+ )
111
+ {
112
+ return rawRequest(oracleAddress, req, payment, ORACLE_ARGS_VERSION, oracle.oracleRequest.selector);
113
+ }
114
+
115
+ /**
116
+ * @notice Creates a Chainlink request to the stored oracle address
117
+ * @dev This function supports multi-word response
118
+ * @dev Calls `requestOracleDataFrom` with the stored oracle address
119
+ * @param req The initialized Chainlink Request
120
+ * @param payment The amount of LINK to send for the request
121
+ * @return requestId The request ID
122
+ */
123
+ function requestOracleData(
124
+ Chainlink.Request memory req,
125
+ uint256 payment
126
+ )
127
+ internal
128
+ returns (
129
+ bytes32
130
+ )
131
+ {
132
+ return requestOracleDataFrom(address(oracle), req, payment);
133
+ }
134
+
135
+ /**
136
+ * @notice Creates a Chainlink request to the specified oracle address
137
+ * @dev This function supports multi-word response
138
+ * @dev Generates and stores a request ID, increments the local nonce, and uses `transferAndCall` to
139
+ * send LINK which creates a request on the target oracle contract.
140
+ * Emits ChainlinkRequested event.
141
+ * @param oracleAddress The address of the oracle for the request
142
+ * @param req The initialized Chainlink Request
143
+ * @param payment The amount of LINK to send for the request
144
+ * @return requestId The request ID
145
+ */
146
+ function requestOracleDataFrom(
147
+ address oracleAddress,
148
+ Chainlink.Request memory req,
149
+ uint256 payment
150
+ )
151
+ internal
152
+ returns (
153
+ bytes32 requestId
154
+ )
155
+ {
156
+ return rawRequest(oracleAddress, req, payment, OPERATOR_ARGS_VERSION, oracle.requestOracleData.selector);
157
+ }
158
+
159
+ /**
160
+ * @notice Make a request to an oracle
161
+ * @param oracleAddress The address of the oracle for the request
162
+ * @param req The initialized Chainlink Request
163
+ * @param payment The amount of LINK to send for the request
164
+ * @param argsVersion The version of data support (single word, multi word)
165
+ * @return requestId The request ID
166
+ */
167
+ function rawRequest(
168
+ address oracleAddress,
169
+ Chainlink.Request memory req,
170
+ uint256 payment,
171
+ uint256 argsVersion,
172
+ bytes4 funcSelector
173
+ )
174
+ private
175
+ returns (
176
+ bytes32 requestId
177
+ )
178
+ {
179
+ requestId = keccak256(abi.encodePacked(this, requestCount));
180
+ req.nonce = requestCount;
181
+ pendingRequests[requestId] = oracleAddress;
182
+ emit ChainlinkRequested(requestId);
183
+ bytes memory encodedData = abi.encodeWithSelector(
184
+ funcSelector,
185
+ SENDER_OVERRIDE, // Sender value - overridden by onTokenTransfer by the requesting contract's address
186
+ AMOUNT_OVERRIDE, // Amount value - overridden by onTokenTransfer by the actual amount of LINK sent
187
+ req.id,
188
+ req.callbackAddress,
189
+ req.callbackFunctionId,
190
+ req.nonce,
191
+ argsVersion,
192
+ req.buf.buf);
193
+ require(link.transferAndCall(oracleAddress, payment, encodedData), "unable to transferAndCall to oracle");
194
+ requestCount += 1;
195
+ }
196
+
197
+ /**
198
+ * @notice Allows a request to be cancelled if it has not been fulfilled
199
+ * @dev Requires keeping track of the expiration value emitted from the oracle contract.
200
+ * Deletes the request from the `pendingRequests` mapping.
201
+ * Emits ChainlinkCancelled event.
202
+ * @param requestId The request ID
203
+ * @param payment The amount of LINK sent for the request
204
+ * @param callbackFunc The callback function specified for the request
205
+ * @param expiration The time of the expiration for the request
206
+ */
207
+ function cancelChainlinkRequest(
208
+ bytes32 requestId,
209
+ uint256 payment,
210
+ bytes4 callbackFunc,
211
+ uint256 expiration
212
+ )
213
+ internal
214
+ {
215
+ OperatorInterface requested = OperatorInterface(pendingRequests[requestId]);
216
+ delete pendingRequests[requestId];
217
+ emit ChainlinkCancelled(requestId);
218
+ requested.cancelOracleRequest(requestId, payment, callbackFunc, expiration);
219
+ }
220
+
221
+ /**
222
+ * @notice Sets the stored oracle address
223
+ * @param oracleAddress The address of the oracle contract
224
+ */
225
+ function setChainlinkOracle(
226
+ address oracleAddress
227
+ )
228
+ internal
229
+ {
230
+ oracle = OperatorInterface(oracleAddress);
231
+ }
232
+
233
+ /**
234
+ * @notice Sets the LINK token address
235
+ * @param linkAddress The address of the LINK token contract
236
+ */
237
+ function setChainlinkToken(
238
+ address linkAddress
239
+ )
240
+ internal
241
+ {
242
+ link = LinkTokenInterface(linkAddress);
243
+ }
244
+
245
+ /**
246
+ * @notice Sets the Chainlink token address for the public
247
+ * network as given by the Pointer contract
248
+ */
249
+ function setPublicChainlinkToken()
250
+ internal
251
+ {
252
+ setChainlinkToken(PointerInterface(LINK_TOKEN_POINTER).getAddress());
253
+ }
254
+
255
+ /**
256
+ * @notice Retrieves the stored address of the LINK token
257
+ * @return The address of the LINK token
258
+ */
259
+ function chainlinkTokenAddress()
260
+ internal
261
+ view
262
+ returns (
263
+ address
264
+ )
265
+ {
266
+ return address(link);
267
+ }
268
+
269
+ /**
270
+ * @notice Retrieves the stored address of the oracle contract
271
+ * @return The address of the oracle contract
272
+ */
273
+ function chainlinkOracleAddress()
274
+ internal
275
+ view
276
+ returns (
277
+ address
278
+ )
279
+ {
280
+ return address(oracle);
281
+ }
282
+
283
+ /**
284
+ * @notice Allows for a request which was created on another contract to be fulfilled
285
+ * on this contract
286
+ * @param oracleAddress The address of the oracle contract that will fulfill the request
287
+ * @param requestId The request ID used for the response
288
+ */
289
+ function addChainlinkExternalRequest(
290
+ address oracleAddress,
291
+ bytes32 requestId
292
+ )
293
+ internal
294
+ notPendingRequest(requestId)
295
+ {
296
+ pendingRequests[requestId] = oracleAddress;
297
+ }
298
+
299
+ /**
300
+ * @notice Sets the stored oracle and LINK token contracts with the addresses resolved by ENS
301
+ * @dev Accounts for subnodes having different resolvers
302
+ * @param ensAddress The address of the ENS contract
303
+ * @param node The ENS node hash
304
+ */
305
+ function useChainlinkWithENS(
306
+ address ensAddress,
307
+ bytes32 node
308
+ )
309
+ internal
310
+ {
311
+ ens = ENSInterface(ensAddress);
312
+ ensNode = node;
313
+ bytes32 linkSubnode = keccak256(abi.encodePacked(ensNode, ENS_TOKEN_SUBNAME));
314
+ ENSResolver_Chainlink resolver = ENSResolver_Chainlink(ens.resolver(linkSubnode));
315
+ setChainlinkToken(resolver.addr(linkSubnode));
316
+ updateChainlinkOracleWithENS();
317
+ }
318
+
319
+ /**
320
+ * @notice Sets the stored oracle contract with the address resolved by ENS
321
+ * @dev This may be called on its own as long as `useChainlinkWithENS` has been called previously
322
+ */
323
+ function updateChainlinkOracleWithENS()
324
+ internal
325
+ {
326
+ bytes32 oracleSubnode = keccak256(abi.encodePacked(ensNode, ENS_ORACLE_SUBNAME));
327
+ ENSResolver_Chainlink resolver = ENSResolver_Chainlink(ens.resolver(oracleSubnode));
328
+ setChainlinkOracle(resolver.addr(oracleSubnode));
329
+ }
330
+
331
+ /**
332
+ * @notice Ensures that the fulfillment is valid for this contract
333
+ * @dev Use if the contract developer prefers methods instead of modifiers for validation
334
+ * @param requestId The request ID for fulfillment
335
+ */
336
+ function validateChainlinkCallback(
337
+ bytes32 requestId
338
+ )
339
+ internal
340
+ recordChainlinkFulfillment(requestId)
341
+ // solhint-disable-next-line no-empty-blocks
342
+ {}
343
+
344
+ /**
345
+ * @dev Reverts if the sender is not the oracle of the request.
346
+ * Emits ChainlinkFulfilled event.
347
+ * @param requestId The request ID for fulfillment
348
+ */
349
+ modifier recordChainlinkFulfillment(
350
+ bytes32 requestId
351
+ )
352
+ {
353
+ require(msg.sender == pendingRequests[requestId],
354
+ "Source must be the oracle of the request");
355
+ delete pendingRequests[requestId];
356
+ emit ChainlinkFulfilled(requestId);
357
+ _;
358
+ }
359
+
360
+ /**
361
+ * @dev Reverts if the request is already pending
362
+ * @param requestId The request ID for fulfillment
363
+ */
364
+ modifier notPendingRequest(
365
+ bytes32 requestId
366
+ )
367
+ {
368
+ require(pendingRequests[requestId] == address(0), "Request is already pending");
369
+ _;
370
+ }
371
+ }
@@ -0,0 +1,15 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {IERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";
5
+
6
+ /**
7
+ * @title IPolicyNFT interface
8
+ * @dev Interface for mintable NFT token that returns tokenId
9
+ * @author Ensuro
10
+ */
11
+ interface IPolicyNFTv1 is IERC721Upgradeable {
12
+ function safeMint(address to) external returns (uint256);
13
+
14
+ function connect() external;
15
+ }
@@ -0,0 +1,126 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.2;
3
+
4
+ import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
5
+ import {ERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
6
+ import {CountersUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol";
7
+ import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
8
+ import {IPolicyPool} from "../../interfaces/IPolicyPool.sol";
9
+ import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
10
+ import {IPolicyNFTv1} from "./IPolicyNFTv1.sol";
11
+
12
+ /**
13
+ * @title PolicyNFT - NFT that keeps track of issued policies and its owners
14
+ * @dev Every time a new policy is accepted by the PolicyPool, a new NFT is minted generating a new
15
+ * policyId owned by the customer. Only the PolicyPool can mint NFTs.
16
+ * After creation, NFTs can be transferred in the ERC721 standard way and that changes the policy holder.
17
+ * @custom:security-contact security@ensuro.co
18
+ * @author Ensuro
19
+ */
20
+ contract PolicyNFTv1 is UUPSUpgradeable, ERC721Upgradeable, PausableUpgradeable, IPolicyNFTv1 {
21
+ using CountersUpgradeable for CountersUpgradeable.Counter;
22
+
23
+ bytes32 public constant GUARDIAN_ROLE = keccak256("GUARDIAN_ROLE");
24
+ bytes32 public constant LEVEL1_ROLE = keccak256("LEVEL1_ROLE");
25
+
26
+ CountersUpgradeable.Counter private _tokenIdCounter;
27
+ IPolicyPool internal _policyPool;
28
+
29
+ modifier onlyPolicyPool() {
30
+ require(_msgSender() == address(_policyPool), "The caller must be the PolicyPool");
31
+ _;
32
+ }
33
+
34
+ modifier onlyPoolRole2(bytes32 role1, bytes32 role2) {
35
+ _policyPool.config().checkRole2(role1, role2, msg.sender);
36
+ _;
37
+ }
38
+
39
+ modifier onlyPoolRole(bytes32 role) {
40
+ _policyPool.config().checkRole(role, msg.sender);
41
+ _;
42
+ }
43
+
44
+ function initialize(
45
+ string memory name_,
46
+ string memory symbol_,
47
+ IPolicyPool policyPool_
48
+ ) public initializer {
49
+ __UUPSUpgradeable_init();
50
+ __Pausable_init();
51
+ __ERC721_init(name_, symbol_);
52
+ __PolicyNFT_init_unchained(policyPool_);
53
+ }
54
+
55
+ // solhint-disable-next-line func-name-mixedcase
56
+ function __PolicyNFT_init_unchained(IPolicyPool policyPool_) internal initializer {
57
+ _policyPool = policyPool_;
58
+ _tokenIdCounter.increment(); // I don't want _tokenId==0
59
+ }
60
+
61
+ // solhint-disable-next-line no-empty-blocks
62
+ function _authorizeUpgrade(address) internal override onlyPoolRole2(GUARDIAN_ROLE, LEVEL1_ROLE) {}
63
+
64
+ function pause() public onlyPoolRole(GUARDIAN_ROLE) {
65
+ _pause();
66
+ }
67
+
68
+ function unpause() public onlyPoolRole2(GUARDIAN_ROLE, LEVEL1_ROLE) {
69
+ _unpause();
70
+ }
71
+
72
+ /**
73
+ * @dev This function can be called only once in contract's lifetime. It links the NFT with the
74
+ * PolicyPool contract. It's called in PolicyPool initialization.
75
+ */
76
+ function connect() external override {
77
+ require(
78
+ address(_policyPool) == address(0) || address(_policyPool) == _msgSender(),
79
+ "PolicyPool already connected"
80
+ );
81
+ _policyPool = IPolicyPool(_msgSender());
82
+ // Not possible to do this validation because connect is called in _policyPool initialize :'(
83
+ // require(_policyPool.policyNFT() == address(this), "PolicyPool not connected to this config");
84
+ }
85
+
86
+ function safeMint(address to)
87
+ external
88
+ virtual
89
+ override
90
+ onlyPolicyPool
91
+ whenNotPaused
92
+ returns (uint256)
93
+ {
94
+ uint256 tokenId = _tokenIdCounter.current();
95
+ _safeMint(to, tokenId);
96
+ _tokenIdCounter.increment();
97
+ return tokenId;
98
+ }
99
+
100
+ function _beforeTokenTransfer(
101
+ address from,
102
+ address to,
103
+ uint256 tokenId
104
+ ) internal override whenNotPaused {
105
+ super._beforeTokenTransfer(from, to, tokenId);
106
+ }
107
+
108
+ function nextId() external view returns (uint256) {
109
+ return _tokenIdCounter.current();
110
+ }
111
+ }
112
+
113
+ // solhint-disable-next-line contract-name-camelcase
114
+ contract PolicyNFTv1_Upgrade is PolicyNFTv1 {
115
+ function safeMint(address to, uint256 policyId) external onlyPolicyPool whenNotPaused {
116
+ _safeMint(to, policyId, "");
117
+ }
118
+
119
+ function safeMint(address) external view override onlyPolicyPool whenNotPaused returns (uint256) {
120
+ revert("Not supported anymore");
121
+ }
122
+
123
+ function policyPool() external view returns (IPolicyPool) {
124
+ return _policyPool;
125
+ }
126
+ }
@@ -0,0 +1,23 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ /**
5
+ * @title IAssetManager interface
6
+ * @dev Interface for asset manager, that manages assets and refills pool wallet when needed
7
+ * @author Ensuro
8
+ */
9
+ interface IAssetManager {
10
+ /**
11
+ * @dev This is called from PolicyPool when doesn't have enought money for payment.
12
+ * After the call, there should be enought money in PolicyPool.currency().balanceOf(_policyPool) to
13
+ * do the payment
14
+ * @param paymentAmount The amount of the payment
15
+ */
16
+ function refillWallet(uint256 paymentAmount) external;
17
+
18
+ /**
19
+ * @dev Deinvest all the assets and return the cash back to the PolicyPool.
20
+ * Called from PolicyPool when new asset manager is assigned
21
+ */
22
+ function deinvestAll() external;
23
+ }
@@ -0,0 +1,44 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5
+
6
+ /**
7
+ * @title IEToken interface
8
+ * @dev Interface for EToken smart contracts, these are the capital pools.
9
+ * @author Ensuro
10
+ */
11
+ interface IEToken is IERC20 {
12
+ event SCRLocked(uint256 interestRate, uint256 value);
13
+ event SCRUnlocked(uint256 interestRate, uint256 value);
14
+
15
+ function ocean() external view returns (uint256);
16
+
17
+ function oceanForNewScr() external view returns (uint256);
18
+
19
+ function scr() external view returns (uint256);
20
+
21
+ function lockScr(uint256 policyInterestRate, uint256 scrAmount) external;
22
+
23
+ function unlockScr(uint256 policyInterestRate, uint256 scrAmount) external;
24
+
25
+ function discreteEarning(uint256 amount, bool positive) external;
26
+
27
+ function assetEarnings(uint256 amount, bool positive) external;
28
+
29
+ function deposit(address provider, uint256 amount) external returns (uint256);
30
+
31
+ function totalWithdrawable() external view returns (uint256);
32
+
33
+ function withdraw(address provider, uint256 amount) external returns (uint256);
34
+
35
+ function accepts(address riskModule, uint40 policyExpiration) external view returns (bool);
36
+
37
+ function lendToPool(uint256 amount, bool fromOcean) external returns (uint256);
38
+
39
+ function repayPoolLoan(uint256 amount) external;
40
+
41
+ function getPoolLoan() external view returns (uint256);
42
+
43
+ function getInvestable() external view returns (uint256);
44
+ }
@@ -0,0 +1,27 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {IEToken} from "./IEToken.sol";
5
+
6
+ /**
7
+ * @title IInsolvencyHook interface
8
+ * @dev Interface for insolvency hook, the contract that manages the insolvency situation of the pool
9
+ * @author Ensuro
10
+ */
11
+ interface IInsolvencyHook {
12
+ /**
13
+ * @dev This is called from PolicyPool when doesn't have enought money for payment.
14
+ * After the call, there should be enought money in PolicyPool.currency().balanceOf(_policyPool) to
15
+ * do the payment
16
+ * @param paymentAmount The amount of the payment
17
+ */
18
+ function outOfCash(uint256 paymentAmount) external;
19
+
20
+ /**
21
+ * @dev This is called from EToken when doesn't have enought totalSupply to cover the SCR
22
+ * The hook might choose not to do anything or solve the insolvency with a deposit
23
+ * @param eToken The token that suffers insolvency
24
+ * @param paymentAmount The amount of the payment
25
+ */
26
+ function insolventEToken(IEToken eToken, uint256 paymentAmount) external;
27
+ }
@@ -0,0 +1,23 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {IEToken} from "./IEToken.sol";
5
+
6
+ /**
7
+ * @title ILPWhitelist - Interface that handles the whitelisting of Liquidity Providers
8
+ * @author Ensuro
9
+ */
10
+ interface ILPWhitelist {
11
+ function acceptsDeposit(
12
+ IEToken etoken,
13
+ address provider,
14
+ uint256 amount
15
+ ) external view returns (bool);
16
+
17
+ function acceptsTransfer(
18
+ IEToken etoken,
19
+ address providerFrom,
20
+ address providerTo,
21
+ uint256 amount
22
+ ) external view returns (bool);
23
+ }
@@ -0,0 +1,15 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {IERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";
5
+
6
+ /**
7
+ * @title IPolicyNFT interface
8
+ * @dev Interface for mintable NFT token that returns tokenId
9
+ * @author Ensuro
10
+ */
11
+ interface IPolicyNFT is IERC721Upgradeable {
12
+ function safeMint(address to, uint256 policyId) external;
13
+
14
+ function connect() external;
15
+ }
@@ -0,0 +1,44 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
5
+ import {Policy} from "../contracts/Policy.sol";
6
+ import {IEToken} from "./IEToken.sol";
7
+ import {IPolicyPoolConfig} from "./IPolicyPoolConfig.sol";
8
+ import {IAssetManager} from "./IAssetManager.sol";
9
+
10
+ interface IPolicyPool {
11
+ function currency() external view returns (IERC20Metadata);
12
+
13
+ function config() external view returns (IPolicyPoolConfig);
14
+
15
+ function policyNFT() external view returns (address);
16
+
17
+ function setAssetManager(IAssetManager newAssetManager) external;
18
+
19
+ function newPolicy(
20
+ Policy.PolicyData memory policy,
21
+ address customer,
22
+ uint96 internalId
23
+ ) external returns (uint256);
24
+
25
+ function resolvePolicy(Policy.PolicyData calldata policy, uint256 payout) external;
26
+
27
+ function resolvePolicyFullPayout(Policy.PolicyData calldata policy, bool customerWon) external;
28
+
29
+ function receiveGrant(uint256 amount) external;
30
+
31
+ function getInvestable() external view returns (uint256);
32
+
33
+ function getETokenCount() external view returns (uint256);
34
+
35
+ function getETokenAt(uint256 index) external view returns (IEToken);
36
+
37
+ function assetEarnings(uint256 amount, bool positive) external;
38
+
39
+ function deposit(IEToken eToken, uint256 amount) external;
40
+
41
+ function withdraw(IEToken eToken, uint256 amount) external returns (uint256);
42
+
43
+ function totalETokenSupply() external view returns (uint256);
44
+ }