@ensuro/core 2.0.0-beta7 → 2.0.0-beta9

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 (50) hide show
  1. package/README.md +17 -14
  2. package/build/contracts/AccessManager.sol/AccessManager.json +2 -2
  3. package/build/contracts/ERC4626AssetManager.sol/ERC4626AssetManager.json +12 -12
  4. package/build/contracts/EToken.sol/EToken.json +2 -15
  5. package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +2 -2
  6. package/build/contracts/LiquidityThresholdAssetManager.sol/LiquidityThresholdAssetManager.json +10 -10
  7. package/build/contracts/Policy.sol/Policy.json +2 -2
  8. package/build/contracts/PolicyPool.sol/PolicyPool.json +21 -2
  9. package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +2 -15
  10. package/build/contracts/Reserve.sol/Reserve.json +0 -13
  11. package/build/contracts/TimeScaled.sol/TimeScaled.json +3 -17
  12. package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +2 -2
  13. package/build/contracts/{WadRayMath.sol → dependencies/WadRayMath.sol}/WadRayMath.json +3 -3
  14. package/build/contracts/interfaces/IAssetManager.sol/IAssetManager.json +10 -10
  15. package/build/contracts/interfaces/IPolicyPool.sol/IPolicyPool.json +19 -0
  16. package/build/contracts/mocks/FixedRateVault.sol/FixedRateVault.json +2 -2
  17. package/build/contracts/mocks/ForwardProxy.sol/ForwardProxy.json +2 -2
  18. package/build/contracts/mocks/PolicyHolderMock.sol/PolicyHolderMock.json +28 -2
  19. package/build/contracts/mocks/PolicyPoolComponentMock.sol/PolicyPoolComponentMock.json +2 -2
  20. package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMock.json +96 -2
  21. package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +2 -2
  22. package/build/contracts/mocks/RiskModuleMock.sol/RiskModuleMock.json +92 -2
  23. package/build/contracts/mocks/TestCurrency.sol/TestCurrency.json +2 -2
  24. package/build/contracts/mocks/TestNFT.sol/TestNFT.json +2 -2
  25. package/contracts/AccessManager.sol +1 -1
  26. package/contracts/ERC4626AssetManager.sol +7 -5
  27. package/contracts/EToken.sol +43 -44
  28. package/contracts/LiquidityThresholdAssetManager.sol +12 -10
  29. package/contracts/Policy.sol +1 -1
  30. package/contracts/PolicyPool.sol +152 -19
  31. package/contracts/PolicyPoolComponent.sol +7 -22
  32. package/contracts/PremiumsAccount.sol +159 -19
  33. package/contracts/Reserve.sol +113 -18
  34. package/contracts/RiskModule.sol +8 -8
  35. package/contracts/TimeScaled.sol +19 -15
  36. package/contracts/TrustfulRiskModule.sol +3 -3
  37. package/contracts/dependencies/WadRayMath.sol +126 -0
  38. package/contracts/interfaces/IAccessManager.sol +68 -13
  39. package/contracts/interfaces/IAssetManager.sol +64 -2
  40. package/contracts/interfaces/IEToken.sol +4 -1
  41. package/contracts/interfaces/ILPWhitelist.sol +17 -0
  42. package/contracts/interfaces/IPolicyPool.sol +7 -0
  43. package/contracts/interfaces/IPolicyPoolComponent.sol +3 -0
  44. package/contracts/interfaces/IRiskModule.sol +67 -4
  45. package/contracts/mocks/PolicyHolderMock.sol +21 -0
  46. package/contracts/mocks/PolicyPoolMock.sol +27 -0
  47. package/contracts/mocks/RiskModuleMock.sol +7 -1
  48. package/js/test-utils.js +49 -36
  49. package/package.json +1 -1
  50. package/contracts/WadRayMath.sol +0 -135
@@ -8,7 +8,6 @@ import {ERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC72
8
8
  import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
9
9
  import {IAccessManager} from "./interfaces/IAccessManager.sol";
10
10
  import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
11
- import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
12
11
  import {IPremiumsAccount} from "./interfaces/IPremiumsAccount.sol";
13
12
  import {IPolicyPool} from "./interfaces/IPolicyPool.sol";
14
13
  import {IRiskModule} from "./interfaces/IRiskModule.sol";
@@ -16,21 +15,22 @@ import {IPolicyPoolComponent} from "./interfaces/IPolicyPoolComponent.sol";
16
15
  import {IEToken} from "./interfaces/IEToken.sol";
17
16
  import {IPolicyHolder} from "./interfaces/IPolicyHolder.sol";
18
17
  import {Policy} from "./Policy.sol";
19
- import {WadRayMath} from "./WadRayMath.sol";
18
+ import {WadRayMath} from "./dependencies/WadRayMath.sol";
20
19
 
21
20
  /**
22
21
  * @title Ensuro PolicyPool contract
23
22
  * @dev This is the main contract of the protocol, it stores the eTokens (liquidity pools) and has the operations
24
- * to interact with them. This is also the contract that receives and sends the underlying asset.
23
+ * to interact with them. This is also the contract that receives and sends the underlying asset (currency).
25
24
  * Also this contract keeps track of accumulated premiums in different stages:
26
25
  * - activePurePremiums
27
26
  * - wonPurePremiums (surplus)
28
27
  * - borrowedActivePP (deficit borrowed from activePurePremiums)
28
+ * This contract also implements the ERC721 standard, because it mints and NFT for each policy created. The
29
+ * property of the NFT represents the one that will receive the payout.
29
30
  * @custom:security-contact security@ensuro.co
30
31
  * @author Ensuro
31
32
  */
32
33
  contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721Upgradeable {
33
- using EnumerableSet for EnumerableSet.AddressSet;
34
34
  using WadRayMath for uint256;
35
35
  using Policy for Policy.PolicyData;
36
36
  using SafeERC20 for IERC20Metadata;
@@ -40,13 +40,26 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
40
40
  bytes32 public constant LEVEL2_ROLE = keccak256("LEVEL2_ROLE");
41
41
  bytes32 public constant LEVEL3_ROLE = keccak256("LEVEL3_ROLE");
42
42
 
43
+ /**
44
+ * @dev {AccessManager} that handles the access permissions for the PolicyPool and its components.
45
+ */
43
46
  /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
44
47
  IAccessManager internal immutable _access;
48
+
49
+ /**
50
+ * @dev {ERC20} token used in PolicyPool as currency. Usually it will be a stablecoin such as USDC.
51
+ */
45
52
  /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
46
53
  IERC20Metadata internal immutable _currency;
47
54
 
55
+ /**
56
+ * @dev Address of Ensuro's treasury that receives the protocol fees.
57
+ */
48
58
  address internal _treasury; // address of Ensuro treasury
49
59
 
60
+ /**
61
+ * @dev This enum tracks the different status that a component ({PremiumsAccount}, {EToken} or {RiskModule} can have.
62
+ */
50
63
  enum ComponentStatus {
51
64
  /**
52
65
  * @dev inactive status = 0 means the component doesn't exists - All operations rejected
@@ -73,6 +86,10 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
73
86
  suspended
74
87
  }
75
88
 
89
+ /**
90
+ * @dev Enum of the different kind of top level components that can be plugged into the pool. Each one corresponds
91
+ * with the {EToken}, {RiskModule} and {PremiumsAccount} respectively.
92
+ */
76
93
  enum ComponentKind {
77
94
  unknown,
78
95
  eToken,
@@ -80,6 +97,10 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
80
97
  premiumsAccount
81
98
  }
82
99
 
100
+ /**
101
+ * @dev Struct to keep the state and type of the components installed. The `kind` never changes. The `status`
102
+ * initially is `active` and can be changes with {PolicyPool-changeComponentStatus} and {PolicyPool-removeComponent}.
103
+ */
83
104
  struct Component {
84
105
  ComponentStatus status;
85
106
  ComponentKind kind;
@@ -87,7 +108,6 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
87
108
 
88
109
  /**
89
110
  * @dev Mapping of installed components (see {EToken}, {RiskModule}, {PremiumsAccount}) in the PolicyPool.
90
- * For each one it keep an state {ComponentStatus}.
91
111
  */
92
112
  mapping(IPolicyPoolComponent => Component) private _components;
93
113
 
@@ -100,17 +120,27 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
100
120
  /**
101
121
  * @dev Event emitted every time a new policy is added to the pool. Contains all the data about the policy that is
102
122
  * later required for doing operations with the policy like resolution or expiration.
123
+ *
124
+ * @param riskModule The risk module that created the policy
125
+ * @param policy The {Policy-PolicyData} struct with all the immutable fields of the policy.
103
126
  */
104
127
  event NewPolicy(IRiskModule indexed riskModule, Policy.PolicyData policy);
105
128
 
106
129
  /**
107
130
  * @dev Event emitted every time a policy is removed from the pool. If the policy expired, the `payout` is 0,
108
131
  * otherwise is the amount transferred to the policyholder.
132
+ *
133
+ * @param riskModule The risk module where that created the policy initially.
134
+ * @param policyId The unique id of the policy
135
+ * @param payout The payout that has been paid to the policy holder. 0 when the policy expired.
109
136
  */
110
137
  event PolicyResolved(IRiskModule indexed riskModule, uint256 indexed policyId, uint256 payout);
111
138
 
112
139
  /**
113
140
  * @dev Event emitted when the treasury changes
141
+ *
142
+ * @param action The type of governance action (just setTreasury in this contract for now)
143
+ * @param value The address of the new treasury
114
144
  */
115
145
  event ComponentChanged(IAccessManager.GovernanceActions indexed action, address value);
116
146
 
@@ -127,22 +157,42 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
127
157
  ComponentStatus newStatus
128
158
  );
129
159
 
160
+ /**
161
+ * @dev Modifier that checks the caller has a given role
162
+ */
130
163
  modifier onlyRole(bytes32 role) {
131
- _access.checkRole(role, msg.sender);
164
+ _access.checkRole(role, _msgSender());
132
165
  _;
133
166
  }
134
167
 
168
+ /**
169
+ * @dev Modifier that checks the caller has any of the given rolea
170
+ */
135
171
  modifier onlyRole2(bytes32 role1, bytes32 role2) {
136
- _access.checkRole2(role1, role2, msg.sender);
172
+ _access.checkRole2(role1, role2, _msgSender());
137
173
  _;
138
174
  }
139
175
 
176
+ /**
177
+ * @dev Instantiates a Policy Pool. Sets immutable fields.
178
+ *
179
+ * @param access_ The address of the {AccessManager} that manages the access permissions for the pool governance
180
+ * operations.
181
+ * @param currency_ The {ERC20} token that's used as a currency in the protocol. Usually a stablecoin such as USDC.
182
+ */
140
183
  /// @custom:oz-upgrades-unsafe-allow constructor
141
184
  constructor(IAccessManager access_, IERC20Metadata currency_) {
142
185
  _access = access_;
143
186
  _currency = currency_;
144
187
  }
145
188
 
189
+ /**
190
+ * @dev Initializes a Policy Pool
191
+ *
192
+ * @param name_ The name of the ERC721 token.
193
+ * @param symbol_ The symbol of the ERC721 token.
194
+ * @param treasury_ The address of the treasury that will receive the protocol fees.
195
+ */
146
196
  function initialize(
147
197
  string memory name_,
148
198
  string memory symbol_,
@@ -162,10 +212,23 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
162
212
  // solhint-disable-next-line no-empty-blocks
163
213
  function _authorizeUpgrade(address) internal override onlyRole2(GUARDIAN_ROLE, LEVEL1_ROLE) {}
164
214
 
215
+ /**
216
+ * @dev Pauses the contract. When the contract is paused, several operations are rejected: deposits, withdrawals, new
217
+ * policies, policy resolution and expiration, nft transfers.
218
+ *
219
+ * Requirements:
220
+ * - Must be executed by a user with the {GUARDIAN_ROLE}.
221
+ */
165
222
  function pause() public onlyRole(GUARDIAN_ROLE) {
166
223
  _pause();
167
224
  }
168
225
 
226
+ /**
227
+ * @dev Unpauses the contract. All the operations disabled when the contract was paused are re-enabled.
228
+ *
229
+ * Requirements:
230
+ * - Must be called by a user with either the {GUARDIAN_ROLE} or a {LEVEL1_ROLE}.
231
+ */
169
232
  function unpause() public onlyRole2(GUARDIAN_ROLE, LEVEL1_ROLE) {
170
233
  _unpause();
171
234
  }
@@ -178,15 +241,42 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
178
241
  return _currency;
179
242
  }
180
243
 
244
+ /**
245
+ * @dev Changes the address of the treasury, the one that receives the protocol fees.
246
+ *
247
+ * Requirements:
248
+ * - Must be called by a user with the {LEVEL1_ROLE}.
249
+ *
250
+ * Events:
251
+ * - Emits {ComponentChanged} with action = setTreasury and the address of the new treasury.
252
+ */
181
253
  function setTreasury(address treasury_) external onlyRole(LEVEL1_ROLE) {
182
254
  _treasury = treasury_;
183
255
  emit ComponentChanged(IAccessManager.GovernanceActions.setTreasury, _treasury);
184
256
  }
185
257
 
258
+ /**
259
+ * @dev Returns the address of the treasury, the one that receives the protocol fees.
260
+ */
186
261
  function treasury() external view override returns (address) {
187
262
  return _treasury;
188
263
  }
189
264
 
265
+ /**
266
+ * @dev Adds a new component (either an {EToken}, {RiskModule} or {PremiumsAccount}) to the protocol. The component
267
+ * status will be `active`.
268
+ *
269
+ * Requirements:
270
+ * - Must be called by a user with the {LEVEL1_ROLE}
271
+ * - The component wasn't added before.
272
+ *
273
+ * Events:
274
+ * - Emits {ComponentStatusChanged} with status active.
275
+ *
276
+ * @param component The address of component contract. Must be an {EToken}, {RiskModule} or {PremiumsAccount} linked
277
+ * to this specific {PolicyPool} and matching the `kind` specified in the next paramter.
278
+ * @param kind The type of component to be added.
279
+ */
190
280
  function addComponent(IPolicyPoolComponent component, ComponentKind kind)
191
281
  external
192
282
  onlyRole(LEVEL1_ROLE)
@@ -211,6 +301,19 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
211
301
  emit ComponentStatusChanged(component, kind, ComponentStatus.active);
212
302
  }
213
303
 
304
+ /**
305
+ * @dev Removes a component from the protocol. The component needs to be in `deprecated` status before doing this
306
+ * operation.
307
+ *
308
+ * Requirements:
309
+ * - Must be called by a user with the {LEVEL1_ROLE}
310
+ * - The component status is `deprecated`.
311
+ *
312
+ * Events:
313
+ * - Emits {ComponentStatusChanged} with status inactive.
314
+ *
315
+ * @param component The address of component contract. Must be a component added before.
316
+ */
214
317
  function removeComponent(IPolicyPoolComponent component) external onlyRole(LEVEL1_ROLE) {
215
318
  Component storage comp = _components[component];
216
319
  require(comp.status == ComponentStatus.deprecated, "Component not deprecated");
@@ -240,6 +343,19 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
240
343
  delete _components[component];
241
344
  }
242
345
 
346
+ /**
347
+ * @dev Changes the status of a component.
348
+ *
349
+ * Requirements:
350
+ * - Must be called by a user with the {LEVEL1_ROLE} if the new status is `active` or `deprecated`.
351
+ * - Must be called by a user with the {GUARDIAN_ROLE} if the new status is `suspended`.
352
+ *
353
+ * Events:
354
+ * - Emits {ComponentStatusChanged} with the new status.
355
+ *
356
+ * @param component The address of component contract. Must be a component added before.
357
+ * @param newStatus The new status, must be either `active`, `deprecated` or `suspended`.
358
+ */
243
359
  function changeComponentStatus(IPolicyPoolComponent component, ComponentStatus newStatus)
244
360
  external
245
361
  onlyRole2(GUARDIAN_ROLE, LEVEL1_ROLE)
@@ -247,15 +363,21 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
247
363
  Component storage comp = _components[component];
248
364
  require(comp.status != ComponentStatus.inactive, "Component not found");
249
365
  require(
250
- (newStatus == ComponentStatus.active && _access.hasRole(LEVEL1_ROLE, msg.sender)) ||
251
- (newStatus == ComponentStatus.suspended && _access.hasRole(GUARDIAN_ROLE, msg.sender)) ||
252
- (newStatus == ComponentStatus.deprecated && _access.hasRole(LEVEL1_ROLE, msg.sender)),
366
+ (newStatus == ComponentStatus.active && _access.hasRole(LEVEL1_ROLE, _msgSender())) ||
367
+ (newStatus == ComponentStatus.suspended && _access.hasRole(GUARDIAN_ROLE, _msgSender())) ||
368
+ (newStatus == ComponentStatus.deprecated && _access.hasRole(LEVEL1_ROLE, _msgSender())),
253
369
  "Only GUARDIAN can suspend / Only LEVEL1 can activate/deprecate"
254
370
  );
255
371
  comp.status = newStatus;
256
372
  emit ComponentStatusChanged(component, comp.kind, newStatus);
257
373
  }
258
374
 
375
+ /**
376
+ * @dev Returns the status of a component.
377
+ *
378
+ * @param component The address of the component
379
+ * @return The status of the component. See {ComponentStatus}
380
+ */
259
381
  function getComponentStatus(IPolicyPoolComponent component)
260
382
  external
261
383
  view
@@ -284,8 +406,8 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
284
406
 
285
407
  function deposit(IEToken eToken, uint256 amount) external override whenNotPaused {
286
408
  require(_etkStatus(eToken) == ComponentStatus.active, "eToken is not active");
287
- _currency.safeTransferFrom(msg.sender, address(eToken), amount);
288
- eToken.deposit(msg.sender, amount);
409
+ _currency.safeTransferFrom(_msgSender(), address(eToken), amount);
410
+ eToken.deposit(_msgSender(), amount);
289
411
  }
290
412
 
291
413
  function withdraw(IEToken eToken, uint256 amount)
@@ -299,7 +421,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
299
421
  etkStatus == ComponentStatus.active || etkStatus == ComponentStatus.deprecated,
300
422
  "eToken not found or withdraws not allowed"
301
423
  );
302
- address provider = msg.sender;
424
+ address provider = _msgSender();
303
425
  return eToken.withdraw(provider, amount);
304
426
  }
305
427
 
@@ -310,7 +432,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
310
432
  uint96 internalId
311
433
  ) external override whenNotPaused returns (uint256) {
312
434
  IRiskModule rm = policy.riskModule;
313
- require(address(rm) == msg.sender, "Only the RM can create new policies");
435
+ require(address(rm) == _msgSender(), "Only the RM can create new policies");
314
436
  require(_rmStatus(rm) == ComponentStatus.active, "RM module not found or not active");
315
437
  policy.id = (uint256(uint160(address(rm))) << 96) + internalId;
316
438
  _policies[policy.id] = policy.hash();
@@ -332,10 +454,6 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
332
454
  return policy.id;
333
455
  }
334
456
 
335
- function _balance() internal view returns (uint256) {
336
- return _currency.balanceOf(address(this));
337
- }
338
-
339
457
  function _validatePolicy(Policy.PolicyData memory policy) internal view {
340
458
  require(policy.id != 0 && policy.hash() == _policies[policy.id], "Policy not found");
341
459
  }
@@ -361,10 +479,17 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
361
479
  return _resolvePolicy(policy, customerWon ? policy.payout : 0, false);
362
480
  }
363
481
 
482
+ function isActive(uint256 policyId) external view override returns (bool) {
483
+ return _policies[policyId] != bytes32(0);
484
+ }
485
+
364
486
  /**
365
487
  * @dev Internal function that handles the different alternative resolutions for a policy, with or without payout and
366
488
  * expiration.
367
489
  *
490
+ * Events:
491
+ * - Emits {PolicyResolved} with the payout
492
+ *
368
493
  * @param policy A policy created with {Policy-initialize}
369
494
  * @param payout The amount to paid to the policyholder
370
495
  * @param expired True for expiration resolution (`payout` must be 0)
@@ -376,7 +501,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
376
501
  ) internal {
377
502
  _validatePolicy(policy);
378
503
  IRiskModule rm = policy.riskModule;
379
- require(expired || address(rm) == msg.sender, "Only the RM can resolve policies");
504
+ require(expired || address(rm) == _msgSender(), "Only the RM can resolve policies");
380
505
  require(payout == 0 || policy.expiration > block.timestamp, "Can't pay expired policy");
381
506
  ComponentStatus compStatus = _rmStatus(rm);
382
507
  require(
@@ -451,4 +576,12 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
451
576
  return;
452
577
  }
453
578
  }
579
+
580
+ function _beforeTokenTransfer(
581
+ address from,
582
+ address to,
583
+ uint256 tokenId
584
+ ) internal override whenNotPaused {
585
+ super._beforeTokenTransfer(from, to, tokenId);
586
+ }
454
587
  }
@@ -7,7 +7,7 @@ import {IPolicyPool} from "./interfaces/IPolicyPool.sol";
7
7
  import {IPolicyPoolComponent} from "./interfaces/IPolicyPoolComponent.sol";
8
8
  import {IAccessManager} from "./interfaces/IAccessManager.sol";
9
9
  import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
10
- import {WadRayMath} from "./WadRayMath.sol";
10
+ import {WadRayMath} from "./dependencies/WadRayMath.sol";
11
11
 
12
12
  /**
13
13
  * @title Base class for PolicyPool components
@@ -51,17 +51,17 @@ abstract contract PolicyPoolComponent is
51
51
  }
52
52
 
53
53
  modifier onlyComponentRole(bytes32 role) {
54
- _policyPool.access().checkComponentRole(address(this), role, msg.sender, false);
54
+ _policyPool.access().checkComponentRole(address(this), role, _msgSender(), false);
55
55
  _;
56
56
  }
57
57
 
58
58
  modifier onlyGlobalOrComponentRole(bytes32 role) {
59
- _policyPool.access().checkComponentRole(address(this), role, msg.sender, true);
59
+ _policyPool.access().checkComponentRole(address(this), role, _msgSender(), true);
60
60
  _;
61
61
  }
62
62
 
63
63
  modifier onlyGlobalOrComponentRole2(bytes32 role1, bytes32 role2) {
64
- _policyPool.access().checkComponentRole2(address(this), role1, role2, msg.sender, true);
64
+ _policyPool.access().checkComponentRole2(address(this), role1, role2, _msgSender(), true);
65
65
  _;
66
66
  }
67
67
 
@@ -71,8 +71,8 @@ abstract contract PolicyPoolComponent is
71
71
  bytes32 role3
72
72
  ) {
73
73
  IAccessManager access = _policyPool.access();
74
- if (!access.hasComponentRole(address(this), role1, msg.sender, true)) {
75
- _policyPool.access().checkComponentRole2(address(this), role2, role3, msg.sender, true);
74
+ if (!access.hasComponentRole(address(this), role1, _msgSender(), true)) {
75
+ _policyPool.access().checkComponentRole2(address(this), role2, role3, _msgSender(), true);
76
76
  }
77
77
  _;
78
78
  }
@@ -117,22 +117,7 @@ abstract contract PolicyPoolComponent is
117
117
  }
118
118
 
119
119
  function hasPoolRole(bytes32 role) internal view returns (bool) {
120
- return _policyPool.access().hasComponentRole(address(this), role, msg.sender, true);
121
- }
122
-
123
- function _isTweakRay(
124
- uint256 oldValue,
125
- uint256 newValue,
126
- uint256 maxTweak
127
- ) internal pure returns (bool) {
128
- if (oldValue == newValue) return true;
129
- if (oldValue == 0) return maxTweak >= WadRayMath.RAY;
130
- if (newValue == 0) return false;
131
- if (oldValue < newValue) {
132
- return (newValue.rayDiv(oldValue) - WadRayMath.RAY) <= maxTweak;
133
- } else {
134
- return (WadRayMath.RAY - newValue.rayDiv(oldValue)) <= maxTweak;
135
- }
120
+ return _policyPool.access().hasComponentRole(address(this), role, _msgSender(), true);
136
121
  }
137
122
 
138
123
  function _isTweakWad(