@ensuro/core 2.0.0-beta4 → 2.0.0-beta5
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.
- package/build/contracts/AccessManager.sol/AccessManager.json +487 -0
- package/build/contracts/EToken.sol/EToken.json +4 -4
- package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +4 -4
- package/build/contracts/PolicyNFT.sol/PolicyNFT.json +2 -2
- package/build/contracts/PolicyPool.sol/PolicyPool.json +148 -15
- package/build/contracts/PolicyPoolComponent.sol/PolicyPoolComponent.json +2 -2
- package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +4 -4
- package/build/contracts/Reserve.sol/Reserve.json +2 -2
- package/build/contracts/RiskModule.sol/RiskModule.json +2 -2
- package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +4 -4
- package/build/contracts/interfaces/{IPolicyPoolConfig.sol/IPolicyPoolConfig.json → IAccessManager.sol/IAccessManager.json} +2 -67
- package/build/contracts/interfaces/IPolicyPool.sol/IPolicyPool.json +15 -2
- package/build/contracts/mocks/PolicyPoolComponentMock.sol/PolicyPoolComponentMock.json +2 -2
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMock.json +19 -6
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +6 -6
- package/contracts/AccessManager.sol +72 -0
- package/contracts/EToken.sol +6 -13
- package/contracts/PolicyNFT.sol +3 -3
- package/contracts/PolicyPool.sol +108 -43
- package/contracts/PolicyPoolComponent.sol +11 -11
- package/contracts/PremiumsAccount.sol +1 -1
- package/contracts/RiskModule.sol +4 -8
- package/contracts/interfaces/{IPolicyPoolConfig.sol → IAccessManager.sol} +2 -21
- package/contracts/interfaces/IPolicyPool.sol +10 -5
- package/contracts/mocks/PolicyPoolMock.sol +15 -13
- package/js/test-utils.js +177 -119
- package/package.json +1 -1
- package/build/contracts/FlightDelayRiskModule.sol/FlightDelayRiskModule.json +0 -890
- package/build/contracts/PolicyPoolConfig.sol/PolicyPoolConfig.json +0 -665
- package/build/contracts/dependencies/ChainlinkClientUpgradeable.sol/ChainlinkClientUpgradeable.json +0 -63
- package/build/contracts/mocks/LinkTokenMock.sol/LinkTokenMock.json +0 -370
- package/build/contracts/upgraded/IPolicyNFTv1.sol/IPolicyNFTv1.json +0 -322
- package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1.json +0 -584
- package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1_Upgrade.json +0 -615
- package/contracts/FlightDelayRiskModule.sol +0 -217
- package/contracts/PolicyPoolConfig.sol +0 -185
- package/contracts/dependencies/ChainlinkClientUpgradeable.sol +0 -371
- package/contracts/mocks/LinkTokenMock.sol +0 -30
- package/contracts/upgraded/IPolicyNFTv1.sol +0 -15
- 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,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
|
-
}
|