@ensuro/core 2.7.0 → 2.8.0-beta1

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 (77) hide show
  1. package/README.md +11 -5
  2. package/contracts/AccessManager.sol +3 -13
  3. package/contracts/EToken.sol +29 -95
  4. package/contracts/LPManualWhitelist.sol +11 -26
  5. package/contracts/LiquidityThresholdAssetManager.sol +10 -21
  6. package/contracts/Policy.sol +6 -17
  7. package/contracts/PolicyPool.sol +23 -75
  8. package/contracts/PolicyPoolComponent.sol +9 -32
  9. package/contracts/PremiumsAccount.sol +16 -47
  10. package/contracts/Reserve.sol +10 -16
  11. package/contracts/RiskModule.sol +22 -80
  12. package/contracts/SignedBucketRiskModule.sol +18 -80
  13. package/contracts/SignedQuoteRiskModule.sol +13 -44
  14. package/contracts/TieredSignedQuoteRiskModule.sol +7 -13
  15. package/contracts/TimeScaled.sol +8 -39
  16. package/contracts/TrustfulRiskModule.sol +13 -48
  17. package/contracts/interfaces/IAccessManager.sol +2 -11
  18. package/contracts/interfaces/IEToken.sol +1 -5
  19. package/contracts/interfaces/ILPWhitelist.sol +2 -10
  20. package/contracts/interfaces/IPolicyHolder.sol +2 -11
  21. package/contracts/interfaces/IPremiumsAccount.sol +1 -5
  22. package/contracts/migration/LPManualWhitelistV20.sol +3 -15
  23. package/contracts/migration/LPManualWhitelistV20Upgraded.sol +1 -5
  24. package/contracts/mocks/FixedRateVault.sol +1 -6
  25. package/contracts/mocks/PolicyHolderMock.sol +3 -13
  26. package/contracts/mocks/PolicyPoolComponentMock.sol +1 -3
  27. package/contracts/mocks/PolicyPoolMock.sol +8 -28
  28. package/contracts/mocks/RiskModuleMock.sol +3 -16
  29. package/contracts/mocks/TestNFT.sol +1 -1
  30. package/js/deploy.js +44 -39
  31. package/js/test-utils.js +30 -19
  32. package/js/utils.js +62 -29
  33. package/package.json +1 -1
  34. package/scripts/utils.sh +23 -12
  35. package/build/contracts/AccessManager.sol/AccessManager.json +0 -618
  36. package/build/contracts/ERC4626AssetManager.sol/ERC4626AssetManager.json +0 -238
  37. package/build/contracts/EToken.sol/EToken.json +0 -1277
  38. package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +0 -647
  39. package/build/contracts/LiquidityThresholdAssetManager.sol/LiquidityThresholdAssetManager.json +0 -222
  40. package/build/contracts/Policy.sol/Policy.json +0 -10
  41. package/build/contracts/PolicyPool.sol/PolicyPool.json +0 -1416
  42. package/build/contracts/PolicyPoolComponent.sol/PolicyPoolComponent.json +0 -332
  43. package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +0 -970
  44. package/build/contracts/Reserve.sol/Reserve.json +0 -403
  45. package/build/contracts/RiskModule.sol/RiskModule.json +0 -559
  46. package/build/contracts/SignedBucketRiskModule.sol/SignedBucketRiskModule.json +0 -1262
  47. package/build/contracts/SignedQuoteRiskModule.sol/SignedQuoteRiskModule.json +0 -1110
  48. package/build/contracts/TieredSignedQuoteRiskModule.sol/TieredSignedQuoteRiskModule.json +0 -1316
  49. package/build/contracts/TimeScaled.sol/TimeScaled.json +0 -10
  50. package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +0 -984
  51. package/build/contracts/dependencies/ERC1967Proxy.sol/ERC1967Proxy.json +0 -64
  52. package/build/contracts/dependencies/IERC20Metadata.sol/IERC20Metadata.json +0 -233
  53. package/build/contracts/dependencies/WadRayMath.sol/WadRayMath.json +0 -10
  54. package/build/contracts/interfaces/IAccessManager.sol/IAccessManager.json +0 -343
  55. package/build/contracts/interfaces/IAssetManager.sol/IAssetManager.json +0 -128
  56. package/build/contracts/interfaces/IEToken.sol/IEToken.json +0 -460
  57. package/build/contracts/interfaces/ILPWhitelist.sol/ILPWhitelist.json +0 -103
  58. package/build/contracts/interfaces/IPolicyHolder.sol/IPolicyHolder.json +0 -108
  59. package/build/contracts/interfaces/IPolicyPool.sol/IPolicyPool.json +0 -501
  60. package/build/contracts/interfaces/IPolicyPoolComponent.sol/IPolicyPoolComponent.json +0 -43
  61. package/build/contracts/interfaces/IPremiumsAccount.sol/IPremiumsAccount.json +0 -315
  62. package/build/contracts/interfaces/IRiskModule.sol/IRiskModule.json +0 -165
  63. package/build/contracts/migration/LPManualWhitelistV20.sol/LPManualWhitelistV20.json +0 -481
  64. package/build/contracts/migration/LPManualWhitelistV20Upgraded.sol/LPManualWhitelistV20Upgraded.json +0 -492
  65. package/build/contracts/mocks/FixedRateVault.sol/FixedRateVault.json +0 -736
  66. package/build/contracts/mocks/ForwardProxy.sol/ForwardProxy.json +0 -43
  67. package/build/contracts/mocks/IMintableERC20.sol/IMintableERC20.json +0 -47
  68. package/build/contracts/mocks/InterfaceIdCalculator.sol/InterfaceIdCalculator.json +0 -180
  69. package/build/contracts/mocks/PolicyHolderMock.sol/PolicyHolderMock.json +0 -319
  70. package/build/contracts/mocks/PolicyPoolComponentMock.sol/PolicyPoolComponentMock.json +0 -54
  71. package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMock.json +0 -721
  72. package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +0 -92
  73. package/build/contracts/mocks/RiskModuleMock.sol/RiskModuleMock.json +0 -783
  74. package/build/contracts/mocks/TestCurrency.sol/TestCurrency.json +0 -343
  75. package/build/contracts/mocks/TestNFT.sol/TestNFT.json +0 -388
  76. package/contracts/dependencies/ERC1967Proxy.sol +0 -19
  77. package/contracts/dependencies/IERC20Metadata.sol +0 -19
package/README.md CHANGED
@@ -85,11 +85,11 @@ Have in mind the new versions of the contracts might or might not be covered by
85
85
 
86
86
  ## Development
87
87
 
88
- For coding the smart contracts the approach we took was prototyping initially in Python (see folder `prototype`), and later we coded in Solidity. The tests run the same test case both on the Python prototype code and the Solidity code. To adapt the Solidity code that is called using [brownie](https://eth-brownie.readthedocs.io/en/stable/), we have some glue code implemented in `tests/wrappers.py`.
88
+ For coding the smart contracts the approach we took was prototyping initially in Python (see folder `prototype`), and later we coded in Solidity. The tests run the same test case both on the Python prototype code and the Solidity code. To adapt the Solidity code that is called using [ethproto](https://github.com/gnarvaja/eth-prototype), we have some glue code implemented in `tests/wrappers.py`.
89
89
 
90
90
  ### Without docker
91
91
 
92
- You can also run the development environment without using docker, just Python (>=3.9) and Node v16 are required as pre-requisits.
92
+ You can also run the development environment without using docker, just Python (>=3.9) and Node v20 are required as pre-requisits.
93
93
 
94
94
  Initial setup:
95
95
 
@@ -101,15 +101,21 @@ source venv/bin/activate
101
101
  pip install -r requirements.txt
102
102
  pip install -r requirements-dev.txt
103
103
  # Install javascript dependencies
104
- nvm use # To change to node v16
104
+ nvm use # To change to node v20
105
105
  npm install
106
106
  ```
107
107
 
108
108
  Then, you can run the tests with:
109
109
 
110
110
  ```bash
111
- brownie test -v
112
- npx hardhat test
111
+ # Start a local node
112
+ npx hardhat node
113
+
114
+ # Run python tests
115
+ pytest
116
+
117
+ # Run js tests
118
+ npx hardhat test --network localhost
113
119
  ```
114
120
 
115
121
  ### Using docker
@@ -102,12 +102,7 @@ contract AccessManager is Initializable, AccessControlUpgradeable, UUPSUpgradeab
102
102
  * @param role The role to get
103
103
  * @return The component role
104
104
  */
105
- function getComponentRole(address component, bytes32 role)
106
- public
107
- pure
108
- override
109
- returns (bytes32)
110
- {
105
+ function getComponentRole(address component, bytes32 role) public pure override returns (bytes32) {
111
106
  return bytes32(bytes20(component)) ^ role;
112
107
  }
113
108
 
@@ -125,8 +120,7 @@ contract AccessManager is Initializable, AccessControlUpgradeable, UUPSUpgradeab
125
120
  address account,
126
121
  bool alsoGlobal
127
122
  ) public view override returns (bool) {
128
- return
129
- (alsoGlobal && hasRole(role, account)) || hasRole(getComponentRole(component, role), account);
123
+ return (alsoGlobal && hasRole(role, account)) || hasRole(getComponentRole(component, role), account);
130
124
  }
131
125
 
132
126
  /**
@@ -183,11 +177,7 @@ contract AccessManager is Initializable, AccessControlUpgradeable, UUPSUpgradeab
183
177
  * @param role2 The second role to check.
184
178
  * @param account The account to check for the role.
185
179
  */
186
- function checkRole2(
187
- bytes32 role1,
188
- bytes32 role2,
189
- address account
190
- ) external view override {
180
+ function checkRole2(bytes32 role1, bytes32 role2, address account) external view override {
191
181
  if (!hasRole(role1, account)) _checkRole(role2, account);
192
182
  }
193
183
 
@@ -151,10 +151,7 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
151
151
  _params.maxUtilizationRate >= MAX_UR_MIN && _params.maxUtilizationRate <= HUNDRED_PERCENT,
152
152
  "Validation: maxUtilizationRate must be [0.5, 1]"
153
153
  );
154
- require(
155
- _params.minUtilizationRate <= HUNDRED_PERCENT,
156
- "Validation: minUtilizationRate must be [0, 1]"
157
- );
154
+ require(_params.minUtilizationRate <= HUNDRED_PERCENT, "Validation: minUtilizationRate must be [0, 1]");
158
155
  /*
159
156
  * We don't validate minUtilizationRate < maxUtilizationRate because the opposite is valid too.
160
157
  * These limits aren't strong limits on the values the utilization rate can take, but instead they are
@@ -164,10 +161,7 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
164
161
  * `maxUtilizationRate` is used to prevent selling more coverage when UR is too high, only checked on `lockScr`
165
162
  * operations, but not in withdrawals or other operations.
166
163
  */
167
- require(
168
- _params.internalLoanInterestRate <= INT_LOAN_IR_MAX,
169
- "Validation: internalLoanInterestRate must be <= 50%"
170
- );
164
+ require(_params.internalLoanInterestRate <= INT_LOAN_IR_MAX, "Validation: internalLoanInterestRate must be <= 50%");
171
165
  }
172
166
 
173
167
  /*** BEGIN ERC20 methods - mainly copied from OpenZeppelin but changes in events and scaledAmount */
@@ -266,13 +260,7 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
266
260
  /**
267
261
  * @dev See {IERC20-allowance}.
268
262
  */
269
- function allowance(address owner, address spender)
270
- public
271
- view
272
- virtual
273
- override
274
- returns (uint256)
275
- {
263
+ function allowance(address owner, address spender) public view virtual override returns (uint256) {
276
264
  return _allowances[owner][spender];
277
265
  }
278
266
 
@@ -301,11 +289,7 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
301
289
  * - the caller must have allowance for ``sender``'s tokens of at least
302
290
  * `amount`.
303
291
  */
304
- function transferFrom(
305
- address sender,
306
- address recipient,
307
- uint256 amount
308
- ) public virtual override returns (bool) {
292
+ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
309
293
  address spender = _msgSender();
310
294
  _spendAllowance(sender, spender, amount);
311
295
  _transfer(sender, recipient, amount);
@@ -320,11 +304,7 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
320
304
  *
321
305
  * Might emit an {Approval} event.
322
306
  */
323
- function _spendAllowance(
324
- address owner,
325
- address spender,
326
- uint256 amount
327
- ) internal virtual {
307
+ function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
328
308
  uint256 currentAllowance = allowance(owner, spender);
329
309
  if (currentAllowance != type(uint256).max) {
330
310
  require(currentAllowance >= amount, "EToken: insufficient allowance");
@@ -365,11 +345,7 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
365
345
  * - `spender` must have allowance for the caller of at least
366
346
  * `subtractedValue`.
367
347
  */
368
- function decreaseAllowance(address spender, uint256 subtractedValue)
369
- public
370
- virtual
371
- returns (bool)
372
- {
348
+ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
373
349
  uint256 currentAllowance = _allowances[_msgSender()][spender];
374
350
  require(currentAllowance >= subtractedValue, "EToken: decreased allowance below zero");
375
351
  _approve(_msgSender(), spender, currentAllowance - subtractedValue);
@@ -391,11 +367,7 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
391
367
  * - `recipient` cannot be the zero address.
392
368
  * - `sender` must have a balance of at least `amount`.
393
369
  */
394
- function _transfer(
395
- address sender,
396
- address recipient,
397
- uint256 amount
398
- ) internal virtual {
370
+ function _transfer(address sender, address recipient, uint256 amount) internal virtual {
399
371
  require(sender != address(0), "EToken: transfer from the zero address");
400
372
  require(recipient != address(0), "EToken: transfer to the zero address");
401
373
 
@@ -465,11 +437,7 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
465
437
  * - `owner` cannot be the zero address.
466
438
  * - `spender` cannot be the zero address.
467
439
  */
468
- function _approve(
469
- address owner,
470
- address spender,
471
- uint256 amount
472
- ) internal virtual {
440
+ function _approve(address owner, address spender, uint256 amount) internal virtual {
473
441
  require(owner != address(0), "EToken: approve from the zero address");
474
442
  require(spender != address(0), "EToken: approve to the zero address");
475
443
 
@@ -491,11 +459,7 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
491
459
  *
492
460
  * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
493
461
  */
494
- function _beforeTokenTransfer(
495
- address from,
496
- address to,
497
- uint256 amount
498
- ) internal virtual whenNotPaused {
462
+ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual whenNotPaused {
499
463
  require(
500
464
  from == address(0) ||
501
465
  to == address(0) ||
@@ -511,9 +475,7 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
511
475
  uint256 totalSupply_ = this.totalSupply();
512
476
  if (totalSupply_ == 0) _scr.tokenInterestRate = 0;
513
477
  else {
514
- uint256 newTokenInterestRate = uint256(_scr.interestRate).wadMul(uint256(_scr.scr)).wadDiv(
515
- totalSupply_
516
- );
478
+ uint256 newTokenInterestRate = uint256(_scr.interestRate).wadMul(uint256(_scr.scr)).wadDiv(totalSupply_);
517
479
  _scr.tokenInterestRate = (newTokenInterestRate > type(uint64).max)
518
480
  ? type(uint64).max
519
481
  : newTokenInterestRate.toUint64();
@@ -586,16 +548,8 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
586
548
  return uint256(_scr.scr).wadDiv(this.totalSupply());
587
549
  }
588
550
 
589
- function lockScr(uint256 scrAmount, uint256 policyInterestRate)
590
- external
591
- override
592
- onlyBorrower
593
- whenNotPaused
594
- {
595
- require(
596
- scrAmount <= this.fundsAvailableToLock(),
597
- "Not enough funds available to cover the SCR"
598
- );
551
+ function lockScr(uint256 scrAmount, uint256 policyInterestRate) external override onlyBorrower whenNotPaused {
552
+ require(scrAmount <= this.fundsAvailableToLock(), "Not enough funds available to cover the SCR");
599
553
  _tsScaled.updateScale(tokenInterestRate());
600
554
  if (_scr.scr == 0) {
601
555
  _scr.scr = scrAmount.toUint128();
@@ -603,8 +557,9 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
603
557
  } else {
604
558
  uint256 origScr = uint256(_scr.scr);
605
559
  uint256 newScr = origScr + scrAmount;
606
- _scr.interestRate = (uint256(_scr.interestRate).wadMul(origScr) +
607
- policyInterestRate.wadMul(scrAmount)).wadDiv(newScr).toUint64();
560
+ _scr.interestRate = (uint256(_scr.interestRate).wadMul(origScr) + policyInterestRate.wadMul(scrAmount))
561
+ .wadDiv(newScr)
562
+ .toUint64();
608
563
  _scr.scr = newScr.toUint128();
609
564
  }
610
565
  emit SCRLocked(policyInterestRate, scrAmount);
@@ -625,8 +580,9 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
625
580
  } else {
626
581
  uint256 origScr = uint256(_scr.scr);
627
582
  uint256 newScr = origScr - scrAmount;
628
- _scr.interestRate = (uint256(_scr.interestRate).wadMul(origScr) -
629
- policyInterestRate.wadMul(scrAmount)).wadDiv(newScr).toUint64();
583
+ _scr.interestRate = (uint256(_scr.interestRate).wadMul(origScr) - policyInterestRate.wadMul(scrAmount))
584
+ .wadDiv(newScr)
585
+ .toUint64();
630
586
  _scr.scr = newScr.toUint128();
631
587
  }
632
588
  emit SCRUnlocked(policyInterestRate, scrAmount);
@@ -642,15 +598,9 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
642
598
  _updateTokenInterestRate();
643
599
  }
644
600
 
645
- function deposit(address provider, uint256 amount)
646
- external
647
- override
648
- onlyPolicyPool
649
- returns (uint256)
650
- {
601
+ function deposit(address provider, uint256 amount) external override onlyPolicyPool returns (uint256) {
651
602
  require(
652
- address(_params.whitelist) == address(0) ||
653
- _params.whitelist.acceptsDeposit(this, provider, amount),
603
+ address(_params.whitelist) == address(0) || _params.whitelist.acceptsDeposit(this, provider, amount),
654
604
  "Liquidity Provider not whitelisted"
655
605
  );
656
606
  _mint(provider, amount);
@@ -666,12 +616,7 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
666
616
  else return 0;
667
617
  }
668
618
 
669
- function withdraw(address provider, uint256 amount)
670
- external
671
- override
672
- onlyPolicyPool
673
- returns (uint256)
674
- {
619
+ function withdraw(address provider, uint256 amount) external override onlyPolicyPool returns (uint256) {
675
620
  /**
676
621
  * Here we don't check for maxUtilizationRate because that limit only affects locking more capital (`lockScr`), but
677
622
  * doesn't affects the right of liquidity providers to withdraw their funds.
@@ -683,8 +628,7 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
683
628
  if (amount == 0) return 0;
684
629
  require(amount <= maxWithdraw, "amount > max withdrawable");
685
630
  require(
686
- address(_params.whitelist) == address(0) ||
687
- _params.whitelist.acceptsWithdrawal(this, provider, amount),
631
+ address(_params.whitelist) == address(0) || _params.whitelist.acceptsWithdrawal(this, provider, amount),
688
632
  "Liquidity Provider not whitelisted"
689
633
  );
690
634
  _burn(provider, amount);
@@ -717,13 +661,10 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
717
661
  return totalSupply() - _tsScaled.minValue(); // Min value accepted by _tsScaled
718
662
  }
719
663
 
720
- function internalLoan(uint256 amount, address receiver)
721
- external
722
- override
723
- onlyBorrower
724
- whenNotPaused
725
- returns (uint256)
726
- {
664
+ function internalLoan(
665
+ uint256 amount,
666
+ address receiver
667
+ ) external override onlyBorrower whenNotPaused returns (uint256) {
727
668
  uint256 amountAsked = amount;
728
669
  amount = Math.min(amount, maxNegativeAdjustment());
729
670
  if (amount == 0) return amountAsked;
@@ -756,10 +697,7 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
756
697
  return _4toWad(_params.internalLoanInterestRate);
757
698
  }
758
699
 
759
- function setParam(Parameter param, uint256 newValue)
760
- external
761
- onlyGlobalOrComponentRole2(LEVEL2_ROLE, LEVEL3_ROLE)
762
- {
700
+ function setParam(Parameter param, uint256 newValue) external onlyGlobalOrComponentRole2(LEVEL2_ROLE, LEVEL3_ROLE) {
763
701
  bool tweak = !hasPoolRole(LEVEL2_ROLE);
764
702
  if (param == Parameter.liquidityRequirement) {
765
703
  require(
@@ -799,13 +737,9 @@ contract EToken is Reserve, IERC20Metadata, IEToken {
799
737
  );
800
738
  }
801
739
 
802
- function setWhitelist(ILPWhitelist lpWhitelist_)
803
- external
804
- onlyGlobalOrComponentRole2(GUARDIAN_ROLE, LEVEL1_ROLE)
805
- {
740
+ function setWhitelist(ILPWhitelist lpWhitelist_) external onlyGlobalOrComponentRole2(GUARDIAN_ROLE, LEVEL1_ROLE) {
806
741
  require(
807
- address(lpWhitelist_) == address(0) ||
808
- IPolicyPoolComponent(address(lpWhitelist_)).policyPool() == _policyPool,
742
+ address(lpWhitelist_) == address(0) || IPolicyPoolComponent(address(lpWhitelist_)).policyPool() == _policyPool,
809
743
  "Component not linked to this PolicyPool"
810
744
  );
811
745
  _params.whitelist = lpWhitelist_;
@@ -48,28 +48,22 @@ contract LPManualWhitelist is ILPWhitelist, PolicyPoolComponent {
48
48
  }
49
49
 
50
50
  // solhint-disable-next-line func-name-mixedcase
51
- function __LPManualWhitelist_init(WhitelistStatus calldata defaultStatus)
52
- internal
53
- onlyInitializing
54
- {
51
+ function __LPManualWhitelist_init(WhitelistStatus calldata defaultStatus) internal onlyInitializing {
55
52
  __PolicyPoolComponent_init();
56
53
  __LPManualWhitelist_init_unchained(defaultStatus);
57
54
  }
58
55
 
59
56
  // solhint-disable-next-line func-name-mixedcase
60
- function __LPManualWhitelist_init_unchained(WhitelistStatus calldata defaultStatus)
61
- internal
62
- onlyInitializing
63
- {
57
+ function __LPManualWhitelist_init_unchained(WhitelistStatus calldata defaultStatus) internal onlyInitializing {
64
58
  _checkDefaultStatus(defaultStatus);
65
59
  _wlStatus[address(0)] = defaultStatus;
66
60
  emit LPWhitelistStatusChanged(address(0), defaultStatus);
67
61
  }
68
62
 
69
- function whitelistAddress(address provider, WhitelistStatus calldata newStatus)
70
- external
71
- onlyComponentRole(LP_WHITELIST_ROLE)
72
- {
63
+ function whitelistAddress(
64
+ address provider,
65
+ WhitelistStatus calldata newStatus
66
+ ) external onlyComponentRole(LP_WHITELIST_ROLE) {
73
67
  require(provider != address(0), "You can't change the defaults");
74
68
  _whitelistAddress(provider, newStatus);
75
69
  }
@@ -84,10 +78,9 @@ contract LPManualWhitelist is ILPWhitelist, PolicyPoolComponent {
84
78
  );
85
79
  }
86
80
 
87
- function setWhitelistDefaults(WhitelistStatus calldata newStatus)
88
- external
89
- onlyComponentRole(LP_WHITELIST_ADMIN_ROLE)
90
- {
81
+ function setWhitelistDefaults(
82
+ WhitelistStatus calldata newStatus
83
+ ) external onlyComponentRole(LP_WHITELIST_ADMIN_ROLE) {
91
84
  _checkDefaultStatus(newStatus);
92
85
  _whitelistAddress(address(0), newStatus);
93
86
  }
@@ -108,11 +101,7 @@ contract LPManualWhitelist is ILPWhitelist, PolicyPoolComponent {
108
101
  return super.supportsInterface(interfaceId) || interfaceId == type(ILPWhitelist).interfaceId;
109
102
  }
110
103
 
111
- function acceptsDeposit(
112
- IEToken,
113
- address provider,
114
- uint256
115
- ) external view override returns (bool) {
104
+ function acceptsDeposit(IEToken, address provider, uint256) external view override returns (bool) {
116
105
  WhitelistOptions wl = _wlStatus[provider].deposit;
117
106
  if (wl == WhitelistOptions.undefined) {
118
107
  wl = _wlStatus[address(0)].deposit;
@@ -120,11 +109,7 @@ contract LPManualWhitelist is ILPWhitelist, PolicyPoolComponent {
120
109
  return wl == WhitelistOptions.whitelisted;
121
110
  }
122
111
 
123
- function acceptsWithdrawal(
124
- IEToken,
125
- address provider,
126
- uint256
127
- ) external view override returns (bool) {
112
+ function acceptsWithdrawal(IEToken, address provider, uint256) external view override returns (bool) {
128
113
  WhitelistOptions wl = _wlStatus[provider].withdraw;
129
114
  if (wl == WhitelistOptions.undefined) {
130
115
  wl = _wlStatus[address(0)].withdraw;
@@ -40,10 +40,7 @@ abstract contract LiquidityThresholdAssetManager is IAssetManager {
40
40
  }
41
41
 
42
42
  constructor(IERC20Metadata asset_) {
43
- require(
44
- address(asset_) != address(0),
45
- "LiquidityThresholdAssetManager: asset cannot be zero address"
46
- );
43
+ require(address(asset_) != address(0), "LiquidityThresholdAssetManager: asset cannot be zero address");
47
44
  _asset = asset_;
48
45
  }
49
46
 
@@ -67,10 +64,7 @@ abstract contract LiquidityThresholdAssetManager is IAssetManager {
67
64
  }
68
65
 
69
66
  function connect() public virtual override {
70
- require(
71
- IPolicyPoolComponent(address(this)).policyPool().currency() == _asset,
72
- "Asset mismatch"
73
- );
67
+ require(IPolicyPoolComponent(address(this)).policyPool().currency() == _asset, "Asset mismatch");
74
68
  DiamondStorage storage ds = diamondStorage();
75
69
  // When connecting I make sure the storage is clean, to avoid reusing data from previous AM that left
76
70
  // the data in a wrong state.
@@ -141,33 +135,29 @@ abstract contract LiquidityThresholdAssetManager is IAssetManager {
141
135
  }
142
136
 
143
137
  function liquidityMin() public view returns (uint256) {
144
- return diamondStorage().liquidityMin * 10**_asset.decimals();
138
+ return diamondStorage().liquidityMin * 10 ** _asset.decimals();
145
139
  }
146
140
 
147
141
  function liquidityMiddle() public view returns (uint256) {
148
- return diamondStorage().liquidityMiddle * 10**_asset.decimals();
142
+ return diamondStorage().liquidityMiddle * 10 ** _asset.decimals();
149
143
  }
150
144
 
151
145
  function liquidityMax() public view returns (uint256) {
152
- return diamondStorage().liquidityMax * 10**_asset.decimals();
146
+ return diamondStorage().liquidityMax * 10 ** _asset.decimals();
153
147
  }
154
148
 
155
- function setLiquidityThresholds(
156
- uint256 min,
157
- uint256 middle,
158
- uint256 max
159
- ) external validateParamsAfterChange {
149
+ function setLiquidityThresholds(uint256 min, uint256 middle, uint256 max) external validateParamsAfterChange {
160
150
  DiamondStorage storage ds = diamondStorage();
161
151
  if (min != type(uint256).max) {
162
- ds.liquidityMin = (min / 10**_asset.decimals()).toUint32();
152
+ ds.liquidityMin = (min / 10 ** _asset.decimals()).toUint32();
163
153
  emit GovernanceAction(IAccessManager.GovernanceActions.setLiquidityMin, min);
164
154
  }
165
155
  if (middle != type(uint256).max) {
166
- ds.liquidityMiddle = (middle / 10**_asset.decimals()).toUint32();
156
+ ds.liquidityMiddle = (middle / 10 ** _asset.decimals()).toUint32();
167
157
  emit GovernanceAction(IAccessManager.GovernanceActions.setLiquidityMiddle, middle);
168
158
  }
169
159
  if (max != type(uint256).max) {
170
- ds.liquidityMax = (max / 10**_asset.decimals()).toUint32();
160
+ ds.liquidityMax = (max / 10 ** _asset.decimals()).toUint32();
171
161
  emit GovernanceAction(IAccessManager.GovernanceActions.setLiquidityMax, max);
172
162
  }
173
163
  }
@@ -176,7 +166,6 @@ abstract contract LiquidityThresholdAssetManager is IAssetManager {
176
166
  * @dev See {IERC165-supportsInterface}.
177
167
  */
178
168
  function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
179
- return
180
- interfaceId == type(IERC165).interfaceId || interfaceId == type(IAssetManager).interfaceId;
169
+ return interfaceId == type(IERC165).interfaceId || interfaceId == type(IAssetManager).interfaceId;
181
170
  }
182
171
  }
@@ -66,27 +66,17 @@ library Policy {
66
66
  policy.srScr = 0;
67
67
  }
68
68
  // Calculate CoCs
69
- policy.jrCoc = policy.jrScr.wadMul(
70
- (rmParams.jrRoc * (policy.expiration - policy.start)) / SECONDS_PER_YEAR
71
- );
72
- policy.srCoc = policy.srScr.wadMul(
73
- (rmParams.srRoc * (policy.expiration - policy.start)) / SECONDS_PER_YEAR
74
- );
69
+ policy.jrCoc = policy.jrScr.wadMul((rmParams.jrRoc * (policy.expiration - policy.start)) / SECONDS_PER_YEAR);
70
+ policy.srCoc = policy.srScr.wadMul((rmParams.srRoc * (policy.expiration - policy.start)) / SECONDS_PER_YEAR);
75
71
  uint256 coc = policy.jrCoc + policy.srCoc;
76
- policy.ensuroCommission =
77
- policy.purePremium.wadMul(rmParams.ensuroPpFee) +
78
- coc.wadMul(rmParams.ensuroCocFee);
79
- require(
80
- (policy.purePremium + policy.ensuroCommission + coc) <= premium,
81
- "Premium less than minimum"
82
- );
72
+ policy.ensuroCommission = policy.purePremium.wadMul(rmParams.ensuroPpFee) + coc.wadMul(rmParams.ensuroCocFee);
73
+ require((policy.purePremium + policy.ensuroCommission + coc) <= premium, "Premium less than minimum");
83
74
  policy.partnerCommission = premium - policy.purePremium - coc - policy.ensuroCommission;
84
75
  return policy;
85
76
  }
86
77
 
87
78
  function jrInterestRate(PolicyData memory policy) internal pure returns (uint256) {
88
- return
89
- ((policy.jrCoc * SECONDS_PER_YEAR) / (policy.expiration - policy.start)).wadDiv(policy.jrScr);
79
+ return ((policy.jrCoc * SECONDS_PER_YEAR) / (policy.expiration - policy.start)).wadDiv(policy.jrScr);
90
80
  }
91
81
 
92
82
  function jrAccruedInterest(PolicyData memory policy) internal view returns (uint256) {
@@ -94,8 +84,7 @@ library Policy {
94
84
  }
95
85
 
96
86
  function srInterestRate(PolicyData memory policy) internal pure returns (uint256) {
97
- return
98
- ((policy.srCoc * SECONDS_PER_YEAR) / (policy.expiration - policy.start)).wadDiv(policy.srScr);
87
+ return ((policy.srCoc * SECONDS_PER_YEAR) / (policy.expiration - policy.start)).wadDiv(policy.srScr);
99
88
  }
100
89
 
101
90
  function srAccruedInterest(PolicyData memory policy) internal view returns (uint256) {