@ensuro/core 2.0.0-beta1 → 2.0.0-beta11

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 (84) hide show
  1. package/README.md +36 -14
  2. package/build/contracts/AccessManager.sol/AccessManager.json +564 -0
  3. package/build/contracts/ERC4626AssetManager.sol/ERC4626AssetManager.json +238 -0
  4. package/build/contracts/EToken.sol/EToken.json +147 -46
  5. package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +23 -4
  6. package/build/contracts/LiquidityThresholdAssetManager.sol/LiquidityThresholdAssetManager.json +222 -0
  7. package/build/contracts/Policy.sol/Policy.json +2 -2
  8. package/build/contracts/PolicyPool.sol/PolicyPool.json +437 -61
  9. package/build/contracts/PolicyPoolComponent.sol/PolicyPoolComponent.json +21 -2
  10. package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +142 -16
  11. package/build/contracts/Reserve.sol/Reserve.json +85 -8
  12. package/build/contracts/RiskModule.sol/RiskModule.json +21 -2
  13. package/build/contracts/SignedQuoteRiskModule.sol/SignedQuoteRiskModule.json +979 -0
  14. package/build/contracts/TimeScaled.sol/TimeScaled.json +3 -17
  15. package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +24 -5
  16. package/build/contracts/{WadRayMath.sol → dependencies/WadRayMath.sol}/WadRayMath.json +3 -3
  17. package/build/contracts/interfaces/{IPolicyPoolConfig.sol/IPolicyPoolConfig.json → IAccessManager.sol/IAccessManager.json} +77 -59
  18. package/build/contracts/interfaces/IAssetManager.sol/IAssetManager.json +128 -0
  19. package/build/contracts/interfaces/IEToken.sol/IEToken.json +13 -0
  20. package/build/contracts/interfaces/IPolicyPool.sol/IPolicyPool.json +40 -16
  21. package/build/contracts/interfaces/IPolicyPoolComponent.sol/IPolicyPoolComponent.json +19 -0
  22. package/build/contracts/interfaces/IPremiumsAccount.sol/IPremiumsAccount.json +13 -0
  23. package/build/contracts/mocks/FixedRateVault.sol/FixedRateVault.json +736 -0
  24. package/build/contracts/mocks/ForwardProxy.sol/ForwardProxy.json +2 -2
  25. package/build/contracts/mocks/InterfaceIdCalculator.sol/InterfaceIdCalculator.json +180 -0
  26. package/build/contracts/mocks/PolicyHolderMock.sol/PolicyHolderMock.json +28 -2
  27. package/build/contracts/mocks/PolicyPoolComponentMock.sol/PolicyPoolComponentMock.json +21 -2
  28. package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMock.json +118 -19
  29. package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +6 -6
  30. package/build/contracts/mocks/RiskModuleMock.sol/RiskModuleMock.json +783 -0
  31. package/build/contracts/mocks/TestCurrency.sol/TestCurrency.json +2 -2
  32. package/build/contracts/mocks/TestNFT.sol/TestNFT.json +2 -2
  33. package/contracts/AccessManager.sol +132 -0
  34. package/contracts/ERC4626AssetManager.sol +55 -0
  35. package/contracts/EToken.sol +208 -102
  36. package/contracts/LPManualWhitelist.sol +19 -3
  37. package/contracts/LiquidityThresholdAssetManager.sol +175 -0
  38. package/contracts/Policy.sol +5 -3
  39. package/contracts/PolicyPool.sol +381 -116
  40. package/contracts/PolicyPoolComponent.sol +61 -44
  41. package/contracts/PremiumsAccount.sol +324 -86
  42. package/contracts/Reserve.sol +199 -4
  43. package/contracts/RiskModule.sol +62 -31
  44. package/contracts/SignedQuoteRiskModule.sol +248 -0
  45. package/contracts/TimeScaled.sol +19 -15
  46. package/contracts/TrustfulRiskModule.sol +69 -2
  47. package/contracts/dependencies/WadRayMath.sol +126 -0
  48. package/contracts/interfaces/IAccessManager.sol +148 -0
  49. package/contracts/interfaces/IAssetManager.sol +89 -0
  50. package/contracts/interfaces/IEToken.sol +25 -2
  51. package/contracts/interfaces/ILPWhitelist.sol +17 -0
  52. package/contracts/interfaces/IPolicyPool.sol +21 -14
  53. package/contracts/interfaces/IPolicyPoolComponent.sol +5 -1
  54. package/contracts/interfaces/IPremiumsAccount.sol +5 -0
  55. package/contracts/interfaces/IRiskModule.sol +67 -4
  56. package/contracts/mocks/FixedRateVault.sol +85 -0
  57. package/contracts/mocks/InterfaceIdCalculator.sol +32 -0
  58. package/contracts/mocks/PolicyHolderMock.sol +21 -0
  59. package/contracts/mocks/PolicyPoolComponentMock.sol +10 -0
  60. package/contracts/mocks/PolicyPoolMock.sol +41 -15
  61. package/contracts/mocks/RiskModuleMock.sol +75 -0
  62. package/js/deploy.js +704 -0
  63. package/js/test-utils.js +339 -159
  64. package/package.json +1 -1
  65. package/build/contracts/FlightDelayRiskModule.sol/FlightDelayRiskModule.json +0 -890
  66. package/build/contracts/PolicyNFT.sol/PolicyNFT.json +0 -583
  67. package/build/contracts/PolicyPoolConfig.sol/PolicyPoolConfig.json +0 -691
  68. package/build/contracts/dependencies/ChainlinkClientUpgradeable.sol/ChainlinkClientUpgradeable.json +0 -63
  69. package/build/contracts/interfaces/IPolicyNFT.sol/IPolicyNFT.json +0 -321
  70. package/build/contracts/mocks/LinkTokenMock.sol/LinkTokenMock.json +0 -370
  71. package/build/contracts/mocks/TestCurrencyUUPS.sol/TestCurrencyUUPS.json +0 -353
  72. package/build/contracts/upgraded/IPolicyNFTv1.sol/IPolicyNFTv1.json +0 -322
  73. package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1.json +0 -584
  74. package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1_Upgrade.json +0 -615
  75. package/contracts/FlightDelayRiskModule.sol +0 -217
  76. package/contracts/PolicyNFT.sol +0 -96
  77. package/contracts/PolicyPoolConfig.sol +0 -204
  78. package/contracts/WadRayMath.sol +0 -135
  79. package/contracts/dependencies/ChainlinkClientUpgradeable.sol +0 -371
  80. package/contracts/interfaces/IPolicyNFT.sol +0 -15
  81. package/contracts/interfaces/IPolicyPoolConfig.sol +0 -96
  82. package/contracts/mocks/LinkTokenMock.sol +0 -30
  83. package/contracts/upgraded/IPolicyNFTv1.sol +0 -15
  84. package/contracts/upgraded/PolicyNFTv1.sol +0 -126
@@ -1,371 +0,0 @@
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
- }
@@ -1,15 +0,0 @@
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
- }
@@ -1,96 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.0;
3
-
4
- import {IAccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
5
- import {ILPWhitelist} from "./ILPWhitelist.sol";
6
- import {IRiskModule} from "./IRiskModule.sol";
7
-
8
- /**
9
- * @title IPolicyPoolAccess - Interface for the contract that handles roles for the PolicyPool and components
10
- * @dev Interface for the contract that handles roles for the PolicyPool and components
11
- * @author Ensuro
12
- */
13
- interface IPolicyPoolConfig is IAccessControlUpgradeable {
14
- enum GovernanceActions {
15
- none,
16
- setTreasury, // Changes PolicyPool treasury address
17
- setAssetManager, // Changes PolicyPool AssetManager
18
- setInsolvencyHook, // Changes PolicyPool InsolvencyHook
19
- setLPWhitelist, // Changes PolicyPool Liquidity Providers Whitelist
20
- addRiskModule,
21
- removeRiskModule,
22
- cfgFiller1, // Reserve space for future PolicyPoolConfig actions
23
- cfgFiller2, // Reserve space for future PolicyPoolConfig actions
24
- cfgFiller3, // Reserve space for future PolicyPoolConfig actions
25
- cfgFiller4, // Reserve space for future PolicyPoolConfig actions
26
- // RiskModule Governance Actions
27
- setMoc,
28
- setJrCollRatio,
29
- setCollRatio,
30
- setEnsuroPpFee,
31
- setEnsuroCocFee,
32
- setJrRoc,
33
- setSrRoc,
34
- setMaxPayoutPerPolicy,
35
- setExposureLimit,
36
- setMaxDuration,
37
- setWallet,
38
- rmFiller1, // Reserve space for future RM actions
39
- rmFiller2, // Reserve space for future RM actions
40
- rmFiller3, // Reserve space for future RM actions
41
- rmFiller4, // Reserve space for future RM actions
42
- // EToken Governance Actions
43
- setLiquidityRequirement,
44
- setMinUtilizationRate,
45
- setMaxUtilizationRate,
46
- setInternalLoanInterestRate,
47
- etkFiller1, // Reserve space for future EToken actions
48
- etkFiller2, // Reserve space for future EToken actions
49
- etkFiller3, // Reserve space for future EToken actions
50
- etkFiller4, // Reserve space for future EToken actions
51
- // AssetManager Governance Actions
52
- setLiquidityMin,
53
- setLiquidityMiddle,
54
- setLiquidityMax,
55
- // AaveAssetManager Governance Actions
56
- setClaimRewardsMin,
57
- setReinvestRewardsMin,
58
- setMaxSlippage,
59
- setPriceOracle, // Changes exchange's PriceOracle
60
- setSwapRouter, // Changes exchange's SwapRouter
61
- last
62
- }
63
-
64
- enum RiskModuleStatus {
65
- inactive, // newPolicy and resolvePolicy rejected
66
- active, // newPolicy and resolvePolicy accepted
67
- deprecated, // newPolicy rejected, resolvePolicy accepted
68
- suspended // newPolicy and resolvePolicy rejected (temporarily)
69
- }
70
-
71
- event RiskModuleStatusChanged(IRiskModule indexed riskModule, RiskModuleStatus newStatus);
72
-
73
- function checkRole(bytes32 role, address account) external view;
74
-
75
- function checkComponentRole(
76
- address component,
77
- bytes32 role,
78
- address account
79
- ) external view;
80
-
81
- function checkRole2(
82
- bytes32 role1,
83
- bytes32 role2,
84
- address account
85
- ) external view;
86
-
87
- function connect() external;
88
-
89
- function lpWhitelist() external view returns (ILPWhitelist);
90
-
91
- function treasury() external view returns (address);
92
-
93
- function checkAcceptsNewPolicy(IRiskModule riskModule) external view;
94
-
95
- function checkAcceptsResolvePolicy(IRiskModule riskModule) external view;
96
- }
@@ -1,30 +0,0 @@
1
- //SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.0;
3
-
4
- import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
- import {LinkTokenInterface} from "@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol";
6
-
7
- contract LinkTokenMock is ERC20 {
8
- address public lastTransferTo;
9
- uint256 public lastTransferValue;
10
- bytes public lastTransferData;
11
-
12
- constructor(
13
- string memory name_,
14
- string memory symbol_,
15
- uint256 initialSupply
16
- ) ERC20(name_, symbol_) {
17
- _mint(msg.sender, initialSupply);
18
- }
19
-
20
- function transferAndCall(
21
- address to,
22
- uint256 value,
23
- bytes calldata data
24
- ) external returns (bool success) {
25
- lastTransferTo = to;
26
- lastTransferValue = value;
27
- lastTransferData = data;
28
- return true;
29
- }
30
- }
@@ -1,15 +0,0 @@
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
- }
@@ -1,126 +0,0 @@
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
- }