@ensuro/core 2.7.0 → 2.8.0-beta2

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 (79) hide show
  1. package/README.md +13 -7
  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 +10 -20
  7. package/contracts/PolicyPool.sol +110 -127
  8. package/contracts/PolicyPoolComponent.sol +9 -32
  9. package/contracts/PremiumsAccount.sol +41 -47
  10. package/contracts/Reserve.sol +10 -16
  11. package/contracts/RiskModule.sol +74 -83
  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 +47 -42
  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/IPolicyPool.sol +59 -3
  22. package/contracts/interfaces/IPremiumsAccount.sol +17 -5
  23. package/contracts/migration/LPManualWhitelistV20.sol +3 -15
  24. package/contracts/migration/LPManualWhitelistV20Upgraded.sol +1 -5
  25. package/contracts/mocks/FixedRateVault.sol +1 -6
  26. package/contracts/mocks/InterfaceIdCalculator.sol +2 -0
  27. package/contracts/mocks/PolicyHolderMock.sol +3 -13
  28. package/contracts/mocks/PolicyPoolComponentMock.sol +1 -3
  29. package/contracts/mocks/PolicyPoolMock.sol +25 -25
  30. package/contracts/mocks/RiskModuleMock.sol +39 -16
  31. package/contracts/mocks/TestNFT.sol +1 -1
  32. package/js/deploy.js +44 -39
  33. package/js/test-utils.js +30 -19
  34. package/js/utils.js +62 -29
  35. package/package.json +1 -1
  36. package/scripts/utils.sh +23 -12
  37. package/build/contracts/AccessManager.sol/AccessManager.json +0 -618
  38. package/build/contracts/ERC4626AssetManager.sol/ERC4626AssetManager.json +0 -238
  39. package/build/contracts/EToken.sol/EToken.json +0 -1277
  40. package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +0 -647
  41. package/build/contracts/LiquidityThresholdAssetManager.sol/LiquidityThresholdAssetManager.json +0 -222
  42. package/build/contracts/Policy.sol/Policy.json +0 -10
  43. package/build/contracts/PolicyPool.sol/PolicyPool.json +0 -1416
  44. package/build/contracts/PolicyPoolComponent.sol/PolicyPoolComponent.json +0 -332
  45. package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +0 -970
  46. package/build/contracts/Reserve.sol/Reserve.json +0 -403
  47. package/build/contracts/RiskModule.sol/RiskModule.json +0 -559
  48. package/build/contracts/SignedBucketRiskModule.sol/SignedBucketRiskModule.json +0 -1262
  49. package/build/contracts/SignedQuoteRiskModule.sol/SignedQuoteRiskModule.json +0 -1110
  50. package/build/contracts/TieredSignedQuoteRiskModule.sol/TieredSignedQuoteRiskModule.json +0 -1316
  51. package/build/contracts/TimeScaled.sol/TimeScaled.json +0 -10
  52. package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +0 -984
  53. package/build/contracts/dependencies/ERC1967Proxy.sol/ERC1967Proxy.json +0 -64
  54. package/build/contracts/dependencies/IERC20Metadata.sol/IERC20Metadata.json +0 -233
  55. package/build/contracts/dependencies/WadRayMath.sol/WadRayMath.json +0 -10
  56. package/build/contracts/interfaces/IAccessManager.sol/IAccessManager.json +0 -343
  57. package/build/contracts/interfaces/IAssetManager.sol/IAssetManager.json +0 -128
  58. package/build/contracts/interfaces/IEToken.sol/IEToken.json +0 -460
  59. package/build/contracts/interfaces/ILPWhitelist.sol/ILPWhitelist.json +0 -103
  60. package/build/contracts/interfaces/IPolicyHolder.sol/IPolicyHolder.json +0 -108
  61. package/build/contracts/interfaces/IPolicyPool.sol/IPolicyPool.json +0 -501
  62. package/build/contracts/interfaces/IPolicyPoolComponent.sol/IPolicyPoolComponent.json +0 -43
  63. package/build/contracts/interfaces/IPremiumsAccount.sol/IPremiumsAccount.json +0 -315
  64. package/build/contracts/interfaces/IRiskModule.sol/IRiskModule.json +0 -165
  65. package/build/contracts/migration/LPManualWhitelistV20.sol/LPManualWhitelistV20.json +0 -481
  66. package/build/contracts/migration/LPManualWhitelistV20Upgraded.sol/LPManualWhitelistV20Upgraded.json +0 -492
  67. package/build/contracts/mocks/FixedRateVault.sol/FixedRateVault.json +0 -736
  68. package/build/contracts/mocks/ForwardProxy.sol/ForwardProxy.json +0 -43
  69. package/build/contracts/mocks/IMintableERC20.sol/IMintableERC20.json +0 -47
  70. package/build/contracts/mocks/InterfaceIdCalculator.sol/InterfaceIdCalculator.json +0 -180
  71. package/build/contracts/mocks/PolicyHolderMock.sol/PolicyHolderMock.json +0 -319
  72. package/build/contracts/mocks/PolicyPoolComponentMock.sol/PolicyPoolComponentMock.json +0 -54
  73. package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMock.json +0 -721
  74. package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +0 -92
  75. package/build/contracts/mocks/RiskModuleMock.sol/RiskModuleMock.json +0 -783
  76. package/build/contracts/mocks/TestCurrency.sol/TestCurrency.json +0 -343
  77. package/build/contracts/mocks/TestNFT.sol/TestNFT.json +0 -388
  78. package/contracts/dependencies/ERC1967Proxy.sol +0 -19
  79. package/contracts/dependencies/IERC20Metadata.sol +0 -19
@@ -5,7 +5,6 @@ import {IPolicyPool} from "../interfaces/IPolicyPool.sol";
5
5
  import {IRiskModule} from "../interfaces/IRiskModule.sol";
6
6
  import {IEToken} from "../interfaces/IEToken.sol";
7
7
  import {IAccessManager} from "../interfaces/IAccessManager.sol";
8
- import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
9
8
  import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
10
9
  import {Policy} from "../Policy.sol";
11
10
  import {ForwardProxy} from "./ForwardProxy.sol";
@@ -13,8 +12,7 @@ import {ForwardProxy} from "./ForwardProxy.sol";
13
12
  contract PolicyPoolMock is IPolicyPool {
14
13
  using Policy for Policy.PolicyData;
15
14
 
16
- uint256 public constant MAX_INT =
17
- 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
15
+ uint256 public constant MAX_INT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
18
16
 
19
17
  IERC20Metadata internal _currency;
20
18
  IAccessManager internal _access;
@@ -22,9 +20,6 @@ contract PolicyPoolMock is IPolicyPool {
22
20
  mapping(uint256 => Policy.PolicyData) internal policies;
23
21
  mapping(uint256 => bytes32) internal policyHashes;
24
22
 
25
- event NewPolicy(IRiskModule indexed riskModule, Policy.PolicyData policy);
26
- event PolicyResolved(IRiskModule indexed riskModule, uint256 indexed policyId, uint256 payout);
27
-
28
23
  constructor(IERC20Metadata currency_, IAccessManager access_) {
29
24
  _currency = currency_;
30
25
  _access = access_;
@@ -44,8 +39,8 @@ contract PolicyPoolMock is IPolicyPool {
44
39
 
45
40
  function newPolicy(
46
41
  Policy.PolicyData memory policy,
47
- address, /* caller */
48
- address, /* policyHolder */
42
+ address /* payer */,
43
+ address /* policyHolder */,
49
44
  uint96 internalId
50
45
  ) external override returns (uint256) {
51
46
  policy.id = (uint256(uint160(address(policy.riskModule))) << 96) + internalId;
@@ -54,13 +49,24 @@ contract PolicyPoolMock is IPolicyPool {
54
49
  return policy.id;
55
50
  }
56
51
 
52
+ function replacePolicy(
53
+ Policy.PolicyData memory oldPolicy,
54
+ Policy.PolicyData memory newPolicy_,
55
+ address /* payer */,
56
+ uint96 internalId
57
+ ) external override returns (uint256) {
58
+ newPolicy_.id = (uint256(uint160(address(newPolicy_.riskModule))) << 96) + internalId;
59
+ policyHashes[newPolicy_.id] = newPolicy_.hash();
60
+ IRiskModule rm = oldPolicy.riskModule;
61
+ emit NewPolicy(rm, newPolicy_);
62
+ emit PolicyReplaced(IRiskModule(msg.sender), oldPolicy.id, newPolicy_.id);
63
+ return newPolicy_.id;
64
+ }
65
+
57
66
  function _resolvePolicy(Policy.PolicyData memory policy, uint256 payout) internal {
58
67
  require(policy.id != 0, "Policy not found");
59
68
  require(policy.hash() == policyHashes[policy.id], "Hash doesn't match");
60
- require(
61
- msg.sender == address(policy.riskModule),
62
- "Only riskModule is authorized to resolve the policy"
63
- );
69
+ require(msg.sender == address(policy.riskModule), "Only riskModule is authorized to resolve the policy");
64
70
  delete policies[policy.id];
65
71
  delete policyHashes[policy.id];
66
72
  emit PolicyResolved(IRiskModule(msg.sender), policy.id, payout);
@@ -74,10 +80,7 @@ contract PolicyPoolMock is IPolicyPool {
74
80
  _resolvePolicy(policy, 0);
75
81
  }
76
82
 
77
- function resolvePolicyFullPayout(Policy.PolicyData calldata policy, bool customerWon)
78
- external
79
- override
80
- {
83
+ function resolvePolicyFullPayout(Policy.PolicyData calldata policy, bool customerWon) external override {
81
84
  return _resolvePolicy(policy, customerWon ? policy.payout : 0);
82
85
  }
83
86
 
@@ -106,7 +109,8 @@ contract PolicyPoolMock is IPolicyPool {
106
109
  uint256 premium,
107
110
  uint256 payout,
108
111
  uint256 lossProb,
109
- uint40 expiration
112
+ uint40 expiration,
113
+ uint40 start
110
114
  ) external {
111
115
  Policy.PolicyData memory policy = Policy.initialize(
112
116
  riskModule,
@@ -114,7 +118,8 @@ contract PolicyPoolMock is IPolicyPool {
114
118
  premium,
115
119
  payout,
116
120
  lossProb,
117
- expiration
121
+ expiration,
122
+ start == 0 ? uint40(block.timestamp) : start
118
123
  );
119
124
 
120
125
  emit NewPolicy(riskModule, policy);
@@ -127,17 +132,12 @@ contract PolicyPoolMock is IPolicyPool {
127
132
  * and other contracts that have functions that can be called only from PolicyPool
128
133
  */
129
134
  contract PolicyPoolMockForward is ForwardProxy {
130
- uint256 public constant MAX_INT =
131
- 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
135
+ uint256 public constant MAX_INT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
132
136
 
133
137
  IERC20Metadata internal _currency;
134
138
  IAccessManager internal _access;
135
139
 
136
- constructor(
137
- address forwardTo,
138
- IERC20Metadata currency_,
139
- IAccessManager access_
140
- ) ForwardProxy(forwardTo) {
140
+ constructor(address forwardTo, IERC20Metadata currency_, IAccessManager access_) ForwardProxy(forwardTo) {
141
141
  _currency = currency_;
142
142
  _access = access_;
143
143
  }
@@ -5,6 +5,7 @@ import {IPolicyPool} from "../interfaces/IPolicyPool.sol";
5
5
  import {IPremiumsAccount} from "../interfaces/IPremiumsAccount.sol";
6
6
  import {RiskModule} from "../RiskModule.sol";
7
7
  import {Policy} from "../Policy.sol";
8
+ import {IERC721} from "@openzeppelin/contracts/interfaces/IERC721.sol";
8
9
 
9
10
  /**
10
11
  * @title Trustful Risk Module
@@ -17,12 +18,11 @@ import {Policy} from "../Policy.sol";
17
18
  contract RiskModuleMock is RiskModule {
18
19
  bytes32 public constant PRICER_ROLE = keccak256("PRICER_ROLE");
19
20
  bytes32 public constant RESOLVER_ROLE = keccak256("RESOLVER_ROLE");
21
+ bytes32 public constant REPLACER_ROLE = keccak256("REPLACER_ROLE");
20
22
 
21
23
  /// @custom:oz-upgrades-unsafe-allow constructor
22
24
  // solhint-disable-next-line no-empty-blocks
23
- constructor(IPolicyPool policyPool_, IPremiumsAccount premiumsAccount_)
24
- RiskModule(policyPool_, premiumsAccount_)
25
- {} // solhint-disable-line no-empty-blocks
25
+ constructor(IPolicyPool policyPool_, IPremiumsAccount premiumsAccount_) RiskModule(policyPool_, premiumsAccount_) {}
26
26
 
27
27
  /**
28
28
  * @dev Initializes the RiskModule
@@ -43,15 +43,7 @@ contract RiskModuleMock is RiskModule {
43
43
  uint256 exposureLimit_,
44
44
  address wallet_
45
45
  ) public initializer {
46
- __RiskModule_init(
47
- name_,
48
- collRatio_,
49
- ensuroPpFee_,
50
- srRoc_,
51
- maxPayoutPerPolicy_,
52
- exposureLimit_,
53
- wallet_
54
- );
46
+ __RiskModule_init(name_, collRatio_, ensuroPpFee_, srRoc_, maxPayoutPerPolicy_, exposureLimit_, wallet_);
55
47
  }
56
48
 
57
49
  function newPolicy(
@@ -66,10 +58,41 @@ contract RiskModuleMock is RiskModule {
66
58
  return _newPolicy(payout, premium, lossProb, expiration, payer, onBehalfOf, internalId).id;
67
59
  }
68
60
 
69
- function resolvePolicy(Policy.PolicyData calldata policy, uint256 payout)
70
- external
71
- onlyComponentRole(RESOLVER_ROLE)
72
- {
61
+ function newPolicyRaw(
62
+ Policy.PolicyData memory policy,
63
+ address payer,
64
+ address policyHolder,
65
+ uint96 internalId
66
+ ) external returns (uint256) {
67
+ return _policyPool.newPolicy(policy, payer, policyHolder, internalId);
68
+ }
69
+
70
+ function resolvePolicy(Policy.PolicyData calldata policy, uint256 payout) external onlyComponentRole(RESOLVER_ROLE) {
73
71
  _policyPool.resolvePolicy(policy, payout);
74
72
  }
73
+
74
+ function resolvePolicyRaw(Policy.PolicyData calldata policy, uint256 payout) external {
75
+ return _policyPool.resolvePolicy(policy, payout);
76
+ }
77
+
78
+ function replacePolicy(
79
+ Policy.PolicyData calldata oldPolicy,
80
+ uint256 payout,
81
+ uint256 premium,
82
+ uint256 lossProb,
83
+ uint40 expiration,
84
+ uint96 internalId
85
+ ) external whenNotPaused onlyComponentRole(REPLACER_ROLE) returns (uint256) {
86
+ address onBehalfOf = IERC721(address(_policyPool)).ownerOf(oldPolicy.id);
87
+ return _replacePolicy(oldPolicy, payout, premium, lossProb, expiration, onBehalfOf, internalId, params()).id;
88
+ }
89
+
90
+ function replacePolicyRaw(
91
+ Policy.PolicyData memory oldPolicy,
92
+ Policy.PolicyData memory newPolicy_,
93
+ address payer,
94
+ uint96 internalId
95
+ ) external returns (uint256) {
96
+ return _policyPool.replacePolicy(oldPolicy, newPolicy_, payer, internalId);
97
+ }
75
98
  }
@@ -2,7 +2,7 @@
2
2
  pragma solidity ^0.8.0;
3
3
  pragma experimental ABIEncoderV2;
4
4
 
5
- import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
5
+ import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
6
6
 
7
7
  contract TestNFT is ERC721 {
8
8
  address private _owner;
package/js/deploy.js CHANGED
@@ -77,9 +77,10 @@ async function logContractCreated(hre, contractName, address) {
77
77
  async function verifyContract(hre, contract, isProxy, constructorArguments) {
78
78
  if (isProxy === undefined) isProxy = false;
79
79
  if (constructorArguments === undefined) constructorArguments = [];
80
+ const contractAddr = await ethers.resolveAddress(contract);
80
81
  const address = isProxy
81
- ? await upgrades_core.getImplementationAddress(hre.network.provider, contract.address)
82
- : contract.address;
82
+ ? await upgrades_core.getImplementationAddress(hre.network.provider, contractAddr)
83
+ : contractAddr;
83
84
  try {
84
85
  await hre.run("verify:verify", {
85
86
  address: address,
@@ -97,27 +98,29 @@ async function verifyContract(hre, contract, isProxy, constructorArguments) {
97
98
  try {
98
99
  if (isProxy) {
99
100
  await hre.run("verify:verify", {
100
- address: contract.address,
101
+ address: contractAddr,
102
+ constructorArguments: constructorArguments,
101
103
  });
102
104
  }
103
105
  } catch (error) {
104
106
  console.log("Error verifying contract proxy: ", error);
105
107
  const endpoints = await hre.run("verify:get-etherscan-endpoint");
106
- console.log(`You should do it manually at ${endpoints.urls.browserURL}/proxyContractChecker?a=${contract.address}`);
108
+ console.log(`You should do it manually at ${endpoints.urls.browserURL}/proxyContractChecker?a=${contractAddr}`);
107
109
  }
108
110
  }
109
111
 
110
112
  async function deployContract({ saveAddr, verify, contractClass, constructorArgs }, hre) {
111
113
  const ContractFactory = await hre.ethers.getContractFactory(contractClass);
112
114
  const contract = await ContractFactory.deploy(...constructorArgs, txOverrides());
115
+ const contractAddr = await ethers.resolveAddress(contract);
113
116
  if (verify) {
114
117
  // From https://ethereum.stackexchange.com/a/119622/79726
115
118
  await contract.deployTransaction.wait(6);
116
119
  } else {
117
- await contract.deployed();
120
+ await contract.waitForDeployment();
118
121
  }
119
- await logContractCreated(hre, contractClass, contract.address);
120
- saveAddress(saveAddr, contract.address);
122
+ await logContractCreated(hre, contractClass, contractAddr);
123
+ saveAddress(saveAddr, contractAddr);
121
124
  if (verify) await verifyContract(hre, contract, false, constructorArgs);
122
125
  return { ContractFactory, contract };
123
126
  }
@@ -133,14 +136,15 @@ async function deployProxyContract(
133
136
  initializer: initializer,
134
137
  ...deployProxyArgs,
135
138
  });
139
+ const contractAddr = await ethers.resolveAddress(contract);
136
140
  if (verify) {
137
141
  // From https://ethereum.stackexchange.com/a/119622/79726
138
142
  await contract.deployTransaction.wait(6);
139
143
  } else {
140
- await contract.deployed();
144
+ await contract.waitForDeployment();
141
145
  }
142
- await logContractCreated(hre, contractClass, contract.address);
143
- saveAddress(saveAddr, contract.address);
146
+ await logContractCreated(hre, contractClass, contractAddr);
147
+ saveAddress(saveAddr, contractAddr);
144
148
  if (verify) await verifyContract(hre, contract, true, constructorArgs);
145
149
  return { ContractFactory, contract };
146
150
  }
@@ -154,7 +158,7 @@ async function grantRoleTask({ contractAddress, role, account, component, impers
154
158
  }
155
159
  contract = contract.connect(signer);
156
160
  }
157
- if (component === ethers.constants.AddressZero) {
161
+ if (component === ethers.ZeroAddress) {
158
162
  await grantRole(hre, contract, role, account, txOverrides(), console.log);
159
163
  } else {
160
164
  await grantComponentRole(hre, contract, component, role, account, txOverrides(), console.log);
@@ -171,11 +175,11 @@ async function deployTestCurrency({ currName, currSymbol, initialSupply, ...opts
171
175
  },
172
176
  hre
173
177
  )
174
- ).contract.address;
178
+ ).contract;
175
179
  }
176
180
 
177
181
  async function deployAccessManager(opts, hre) {
178
- return (await deployProxyContract({ contractClass: "AccessManager", ...opts }, hre)).contract.address;
182
+ return (await deployProxyContract({ contractClass: "AccessManager", ...opts }, hre)).contract;
179
183
  }
180
184
 
181
185
  async function deployPolicyPool({ accessAddress, currencyAddress, nftName, nftSymbol, treasuryAddress, ...opts }, hre) {
@@ -189,7 +193,7 @@ async function deployPolicyPool({ accessAddress, currencyAddress, nftName, nftSy
189
193
  },
190
194
  hre
191
195
  )
192
- ).contract.address;
196
+ ).contract;
193
197
  }
194
198
 
195
199
  async function deployEToken(
@@ -209,9 +213,9 @@ async function deployEToken(
209
213
  if (opts.addComponent) {
210
214
  let policyPool = await hre.ethers.getContractAt("PolicyPool", poolAddress);
211
215
  if (runAs) policyPool = policyPool.connect(runAs);
212
- await policyPool.addComponent(contract.address, 1);
216
+ await policyPool.addComponent(contract, 1);
213
217
  }
214
- return contract.address;
218
+ return contract;
215
219
  }
216
220
 
217
221
  async function deployPremiumsAccount({ poolAddress, juniorEtk, seniorEtk, runAs, ...opts }, hre) {
@@ -228,9 +232,9 @@ async function deployPremiumsAccount({ poolAddress, juniorEtk, seniorEtk, runAs,
228
232
  if (opts.addComponent) {
229
233
  let policyPool = await hre.ethers.getContractAt("PolicyPool", poolAddress);
230
234
  if (runAs) policyPool = policyPool.connect(runAs);
231
- await policyPool.addComponent(contract.address, 3);
235
+ await policyPool.addComponent(contract, 3);
232
236
  }
233
- return contract.address;
237
+ return contract;
234
238
  }
235
239
 
236
240
  async function deployRiskModule(
@@ -281,7 +285,6 @@ async function deployRiskModule(
281
285
  hre
282
286
  );
283
287
  const rm = runAs === undefined ? contract : contract.connect(runAs);
284
-
285
288
  if (opts.addComponent) {
286
289
  if (moc != 1.0) {
287
290
  moc = _W(moc);
@@ -304,9 +307,9 @@ async function deployRiskModule(
304
307
  }
305
308
  let policyPool = await hre.ethers.getContractAt("PolicyPool", poolAddress);
306
309
  if (runAs) policyPool = policyPool.connect(runAs);
307
- await policyPool.addComponent(contract.address, 2);
310
+ await policyPool.addComponent(contract, 2);
308
311
  }
309
- return contract.address;
312
+ return contract;
310
313
  }
311
314
 
312
315
  async function deploySignedQuoteRM(opts, hre) {
@@ -319,9 +322,9 @@ async function setAssetManager({ reserve, amAddress, liquidityMin, liquidityMidd
319
322
  const tx = await reserveContract.setAssetManager(amAddress, false);
320
323
  console.log(`Asset Manager ${amAddress} set to reserve ${reserve}`);
321
324
  if (liquidityMin !== undefined || liquidityMiddle !== undefined || liquidityMax !== undefined) {
322
- liquidityMin = liquidityMin === undefined ? ethers.constants.MaxUint256 : _A(liquidityMin);
323
- liquidityMiddle = liquidityMiddle === undefined ? ethers.constants.MaxUint256 : _A(liquidityMiddle);
324
- liquidityMax = liquidityMax === undefined ? ethers.constants.MaxUint256 : _A(liquidityMax);
325
+ liquidityMin = liquidityMin === undefined ? ethers.MaxUint256 : _A(liquidityMin);
326
+ liquidityMiddle = liquidityMiddle === undefined ? ethers.MaxUint256 : _A(liquidityMiddle);
327
+ liquidityMax = liquidityMax === undefined ? ethers.MaxUint256 : _A(liquidityMax);
325
328
  const amContract = await hre.ethers.getContractAt(
326
329
  "ERC4626AssetManager", // Not relevant if it's ERC4626AssetManager, only need setLiquidityThresholds
327
330
  amAddress
@@ -346,7 +349,7 @@ async function deployERC4626AssetManager({ asset, vault, amClass, ...opts }, hre
346
349
  },
347
350
  hre
348
351
  )
349
- ).contract.address;
352
+ ).contract;
350
353
  }
351
354
 
352
355
  async function deployAaveAssetManager({ asset, aave, amClass, ...opts }, hre) {
@@ -359,7 +362,7 @@ async function deployAaveAssetManager({ asset, aave, amClass, ...opts }, hre) {
359
362
  },
360
363
  hre
361
364
  )
362
- ).contract.address;
365
+ ).contract;
363
366
  }
364
367
 
365
368
  async function deployWhitelist(
@@ -386,17 +389,17 @@ async function deployWhitelist(
386
389
  );
387
390
  if (eToken !== undefined) {
388
391
  const etk = await hre.ethers.getContractAt("EToken", eToken);
389
- await etk.setWhitelist(contract.address);
392
+ await etk.setWhitelist(contract);
390
393
  }
391
394
  if (eToken2 !== undefined) {
392
395
  const etk = await hre.ethers.getContractAt("EToken", eToken2);
393
- await etk.setWhitelist(contract.address);
396
+ await etk.setWhitelist(contract);
394
397
  }
395
398
  if (eToken3 !== undefined) {
396
399
  const etk = await hre.ethers.getContractAt("EToken", eToken3);
397
- await etk.setWhitelist(contract.address);
400
+ await etk.setWhitelist(contract);
398
401
  }
399
- return contract.address;
402
+ return contract;
400
403
  }
401
404
 
402
405
  async function trustfullPolicy({ rmAddress, payout, premium, lossProb, expiration, customer }, hre) {
@@ -409,7 +412,7 @@ async function trustfullPolicy({ rmAddress, payout, premium, lossProb, expiratio
409
412
  customer = customer || (await getDefaultSigner(hre));
410
413
  premium = _A(premium);
411
414
 
412
- await currency.approve(policyPool.address, premium);
415
+ await currency.approve(policyPool, premium);
413
416
  lossProb = _W(lossProb);
414
417
  if (expiration === undefined) {
415
418
  expiration = 3600;
@@ -453,7 +456,7 @@ async function flightDelayPolicy(
453
456
  customer = customer || (await getDefaultSigner(hre));
454
457
  premium = _A(premium);
455
458
 
456
- await currency.approve(policyPool.address, premium);
459
+ await currency.approve(policyPool, premium);
457
460
  lossProb = _W(lossProb);
458
461
  payout = _A(payout);
459
462
 
@@ -480,7 +483,7 @@ async function listETokens({ poolAddress }, hre) {
480
483
  for (let i = 0; i < etkCount; i++) {
481
484
  const etk = await hre.ethers.getContractAt("EToken", await policyPool.getETokenAt(i));
482
485
  const etkName = await etk.name();
483
- console.log(`eToken at ${etk.address}: ${etkName}`);
486
+ console.log(`eToken at ${etk.target}: ${etkName}`);
484
487
  }
485
488
  }
486
489
 
@@ -489,8 +492,8 @@ async function deposit({ etkAddress, amount }, hre) {
489
492
  const policyPool = await hre.ethers.getContractAt("PolicyPool", await etk.policyPool());
490
493
  const currency = await hre.ethers.getContractAt("IERC20Metadata", await policyPool.currency());
491
494
  amount = _A(amount);
492
- await currency.approve(policyPool.address, amount);
493
- const tx = await policyPool.deposit(etk.address, amount, { gasLimit: 999999 });
495
+ await currency.approve(policyPool, amount);
496
+ const tx = await policyPool.deposit(etk, amount, { gasLimit: 999999 });
494
497
  console.log(tx);
495
498
  }
496
499
 
@@ -508,11 +511,13 @@ function add_task() {
508
511
  .setAction(async function (taskArgs, hre) {
509
512
  if (taskArgs.currencyAddress === undefined) {
510
513
  taskArgs.saveAddr = "CURRENCY";
511
- taskArgs.currencyAddress = await deployTestCurrency(taskArgs, hre);
514
+ const currency = await deployTestCurrency(taskArgs, hre);
515
+ taskArgs.currencyAddress = await ethers.resolveAddress(currency);
512
516
  }
513
517
  if (taskArgs.accessAddress === undefined) {
514
518
  taskArgs.saveAddr = "ACCESSMANAGER";
515
- taskArgs.accessAddress = await deployAccessManager(taskArgs, hre);
519
+ const access = await deployAccessManager(taskArgs, hre);
520
+ taskArgs.accessAddress = await ethers.resolveAddress(access);
516
521
  }
517
522
  taskArgs.saveAddr = "POOL";
518
523
  await deployPolicyPool(taskArgs, hre);
@@ -536,7 +541,7 @@ function add_task() {
536
541
  .addOptionalParam("saveAddr", "Save created contract address", "POOL", types.str)
537
542
  .addOptionalParam("nftName", "Name of Policies NFT Token", "Ensuro Policies NFT", types.str)
538
543
  .addOptionalParam("nftSymbol", "Symbol of Policies NFT Token", "EPOL", types.str)
539
- .addOptionalParam("treasuryAddress", "Treasury Address", ethers.constants.AddressZero, types.address)
544
+ .addOptionalParam("treasuryAddress", "Treasury Address", ethers.ZeroAddress, types.address)
540
545
  .addParam("currencyAddress", "Currency Address", types.address)
541
546
  .addParam("accessAddress", "AccessManager Address", types.address)
542
547
  .setAction(deployPolicyPool);
@@ -692,7 +697,7 @@ function add_task() {
692
697
  .addOptionalParam(
693
698
  "component",
694
699
  "Address of the component if it's a component role",
695
- ethers.constants.AddressZero,
700
+ ethers.ZeroAddress,
696
701
  types.address
697
702
  )
698
703
  .setAction(grantRoleTask);
package/js/test-utils.js CHANGED
@@ -4,7 +4,7 @@ const { RiskModuleParameter } = require("../js/enums");
4
4
  const helpers = require("@nomicfoundation/hardhat-network-helpers");
5
5
 
6
6
  const { ethers } = hre;
7
- const { AddressZero } = ethers.constants;
7
+ const { ZeroAddress } = ethers;
8
8
 
9
9
  async function initCurrency(options, initial_targets, initial_balances) {
10
10
  const Currency = await ethers.getContractFactory(options.contractClass || "TestCurrency");
@@ -17,7 +17,7 @@ async function initCurrency(options, initial_targets, initial_balances) {
17
17
  initial_targets = initial_targets || [];
18
18
  await Promise.all(
19
19
  initial_targets.map(async function (user, index) {
20
- await currency.transfer(user.address, initial_balances[index]);
20
+ await currency.transfer(user, initial_balances[index]);
21
21
  })
22
22
  );
23
23
  return currency;
@@ -33,11 +33,11 @@ async function initCurrency(options, initial_targets, initial_balances) {
33
33
  async function initForkCurrency(currencyAddress, currencyOrigin, initialTargets, initialBalances) {
34
34
  const currency = await ethers.getContractAt("IERC20", currencyAddress);
35
35
  await helpers.impersonateAccount(currencyOrigin);
36
- await helpers.setBalance(currencyOrigin, ethers.utils.parseEther("100"));
36
+ await helpers.setBalance(currencyOrigin, ethers.parseEther("100"));
37
37
  const whale = await ethers.getSigner(currencyOrigin);
38
38
  await Promise.all(
39
39
  initialTargets.map(async function (user, index) {
40
- await currency.connect(whale).transfer(user.address, initialBalances[index]);
40
+ await currency.connect(whale).transfer(user, initialBalances[index]);
41
41
  })
42
42
  );
43
43
  return currency;
@@ -63,6 +63,11 @@ async function createRiskModule(
63
63
  extraArgs = extraArgs || [];
64
64
  extraConstructorArgs = extraConstructorArgs || [];
65
65
  const _A = pool._A || _W;
66
+ maxPayoutPerPolicy = maxPayoutPerPolicy !== undefined ? _A(maxPayoutPerPolicy) : _A(1000);
67
+ exposureLimit = exposureLimit !== undefined ? _A(exposureLimit) : _A(1000000);
68
+
69
+ const poolAddr = await ethers.resolveAddress(pool);
70
+ const paAddr = await ethers.resolveAddress(premiumsAccount);
66
71
  const rm = await hre.upgrades.deployProxy(
67
72
  contractFactory,
68
73
  [
@@ -70,18 +75,18 @@ async function createRiskModule(
70
75
  _W(collRatio) || _W(1),
71
76
  _W(ensuroPPFee) || _W(0),
72
77
  _W(srRoc) || _W("0.1"),
73
- _A(maxPayoutPerPolicy) || _A(1000),
74
- _A(exposureLimit) || _A(1000000),
78
+ maxPayoutPerPolicy,
79
+ exposureLimit,
75
80
  wallet || "0xdD2FD4581271e230360230F9337D5c0430Bf44C0", // Random address
76
81
  ...extraArgs,
77
82
  ],
78
83
  {
79
84
  kind: "uups",
80
- constructorArgs: [pool.address, premiumsAccount.address, ...extraConstructorArgs],
85
+ constructorArgs: [poolAddr, paAddr, ...extraConstructorArgs],
81
86
  }
82
87
  );
83
88
 
84
- await rm.deployed();
89
+ await rm.waitForDeployment();
85
90
 
86
91
  if (moc !== undefined && moc != 1.0) {
87
92
  moc = _W(moc);
@@ -120,7 +125,7 @@ async function addRiskModule(
120
125
  extraConstructorArgs,
121
126
  });
122
127
 
123
- await pool.addComponent(rm.address, 2);
128
+ await pool.addComponent(rm, 2);
124
129
  return rm;
125
130
  }
126
131
 
@@ -131,6 +136,7 @@ async function createEToken(
131
136
  const EToken = await ethers.getContractFactory("EToken");
132
137
  extraArgs = extraArgs || [];
133
138
  extraConstructorArgs = extraConstructorArgs || [];
139
+ const poolAddr = await ethers.resolveAddress(pool);
134
140
  const etk = await hre.upgrades.deployProxy(
135
141
  EToken,
136
142
  [
@@ -143,11 +149,11 @@ async function createEToken(
143
149
  {
144
150
  kind: "uups",
145
151
  unsafeAllow: ["delegatecall"], // This holds, because EToken is a reserve and uses delegatecall
146
- constructorArgs: [pool.address, ...extraConstructorArgs],
152
+ constructorArgs: [poolAddr, ...extraConstructorArgs],
147
153
  }
148
154
  );
149
155
 
150
- await etk.deployed();
156
+ await etk.waitForDeployment();
151
157
  return etk;
152
158
  }
153
159
 
@@ -163,7 +169,7 @@ async function addEToken(
163
169
  extraArgs,
164
170
  extraConstructorArgs,
165
171
  });
166
- await pool.addComponent(etk.address, 1);
172
+ await pool.addComponent(etk, 1);
167
173
  return etk;
168
174
  }
169
175
 
@@ -192,11 +198,13 @@ async function deployPool(options) {
192
198
  if (options.access === undefined) {
193
199
  // Deploy AccessManager
194
200
  accessManager = await hre.upgrades.deployProxy(AccessManager, [], { kind: "uups" });
195
- await accessManager.deployed();
201
+ await accessManager.waitForDeployment();
196
202
  } else {
197
203
  accessManager = await ethers.getContractAt("AccessManager", options.access);
198
204
  }
199
205
 
206
+ const currencyAddr = await ethers.resolveAddress(options.currency);
207
+ const amAddr = await ethers.resolveAddress(accessManager);
200
208
  const policyPool = await hre.upgrades.deployProxy(
201
209
  PolicyPool,
202
210
  [
@@ -205,12 +213,12 @@ async function deployPool(options) {
205
213
  options.treasuryAddress || randomAddress,
206
214
  ],
207
215
  {
208
- constructorArgs: [accessManager.address, options.currency],
216
+ constructorArgs: [amAddr, currencyAddr],
209
217
  kind: "uups",
210
218
  }
211
219
  );
212
220
 
213
- await policyPool.deployed();
221
+ await policyPool.waitForDeployment();
214
222
 
215
223
  for (const role of options.grantRoles || []) {
216
224
  await grantRole(hre, accessManager, role);
@@ -227,21 +235,24 @@ async function deployPool(options) {
227
235
 
228
236
  async function deployPremiumsAccount(pool, options, addToPool = true) {
229
237
  const PremiumsAccount = await ethers.getContractFactory("PremiumsAccount");
238
+ const poolAddr = await ethers.resolveAddress(pool);
239
+ const jrEtkAddr = options.jrEtk ? await ethers.resolveAddress(options.jrEtk) : ZeroAddress;
240
+ const srEtkAddr = options.srEtk ? await ethers.resolveAddress(options.srEtk) : ZeroAddress;
230
241
  const premiumsAccount = await hre.upgrades.deployProxy(PremiumsAccount, [], {
231
- constructorArgs: [pool.address, options.jrEtkAddr || AddressZero, options.srEtkAddr || AddressZero],
242
+ constructorArgs: [poolAddr, jrEtkAddr, srEtkAddr],
232
243
  kind: "uups",
233
244
  unsafeAllow: ["delegatecall"], // This holds, because EToken is a reserve and uses delegatecall
234
245
  });
235
246
 
236
- await premiumsAccount.deployed();
247
+ await premiumsAccount.waitForDeployment();
237
248
 
238
- if (addToPool) await pool.addComponent(premiumsAccount.address, 3);
249
+ if (addToPool) await pool.addComponent(premiumsAccount, 3);
239
250
 
240
251
  return premiumsAccount;
241
252
  }
242
253
 
243
254
  async function makePolicy(pool, rm, cust, payout, premium, lossProb, expiration, internalId, method = "newPolicy") {
244
- let tx = await rm.connect(cust)[method](payout, premium, lossProb, expiration, cust.address, internalId);
255
+ let tx = await rm.connect(cust)[method](payout, premium, lossProb, expiration, cust, internalId);
245
256
  let receipt = await tx.wait();
246
257
  const newPolicyEvt = getTransactionEvent(pool.interface, receipt, "NewPolicy");
247
258