@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
@@ -20,8 +20,6 @@ contract PolicyPoolComponentMock is IPolicyPoolComponent {
20
20
  * @dev See {IERC165-supportsInterface}.
21
21
  */
22
22
  function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
23
- return
24
- interfaceId == type(IERC165).interfaceId ||
25
- interfaceId == type(IPolicyPoolComponent).interfaceId;
23
+ return interfaceId == type(IERC165).interfaceId || interfaceId == type(IPolicyPoolComponent).interfaceId;
26
24
  }
27
25
  }
@@ -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;
@@ -44,8 +42,8 @@ contract PolicyPoolMock is IPolicyPool {
44
42
 
45
43
  function newPolicy(
46
44
  Policy.PolicyData memory policy,
47
- address, /* caller */
48
- address, /* policyHolder */
45
+ address /* caller */,
46
+ address /* policyHolder */,
49
47
  uint96 internalId
50
48
  ) external override returns (uint256) {
51
49
  policy.id = (uint256(uint160(address(policy.riskModule))) << 96) + internalId;
@@ -57,10 +55,7 @@ contract PolicyPoolMock is IPolicyPool {
57
55
  function _resolvePolicy(Policy.PolicyData memory policy, uint256 payout) internal {
58
56
  require(policy.id != 0, "Policy not found");
59
57
  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
- );
58
+ require(msg.sender == address(policy.riskModule), "Only riskModule is authorized to resolve the policy");
64
59
  delete policies[policy.id];
65
60
  delete policyHashes[policy.id];
66
61
  emit PolicyResolved(IRiskModule(msg.sender), policy.id, payout);
@@ -74,10 +69,7 @@ contract PolicyPoolMock is IPolicyPool {
74
69
  _resolvePolicy(policy, 0);
75
70
  }
76
71
 
77
- function resolvePolicyFullPayout(Policy.PolicyData calldata policy, bool customerWon)
78
- external
79
- override
80
- {
72
+ function resolvePolicyFullPayout(Policy.PolicyData calldata policy, bool customerWon) external override {
81
73
  return _resolvePolicy(policy, customerWon ? policy.payout : 0);
82
74
  }
83
75
 
@@ -108,14 +100,7 @@ contract PolicyPoolMock is IPolicyPool {
108
100
  uint256 lossProb,
109
101
  uint40 expiration
110
102
  ) external {
111
- Policy.PolicyData memory policy = Policy.initialize(
112
- riskModule,
113
- rmParams,
114
- premium,
115
- payout,
116
- lossProb,
117
- expiration
118
- );
103
+ Policy.PolicyData memory policy = Policy.initialize(riskModule, rmParams, premium, payout, lossProb, expiration);
119
104
 
120
105
  emit NewPolicy(riskModule, policy);
121
106
  }
@@ -127,17 +112,12 @@ contract PolicyPoolMock is IPolicyPool {
127
112
  * and other contracts that have functions that can be called only from PolicyPool
128
113
  */
129
114
  contract PolicyPoolMockForward is ForwardProxy {
130
- uint256 public constant MAX_INT =
131
- 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
115
+ uint256 public constant MAX_INT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
132
116
 
133
117
  IERC20Metadata internal _currency;
134
118
  IAccessManager internal _access;
135
119
 
136
- constructor(
137
- address forwardTo,
138
- IERC20Metadata currency_,
139
- IAccessManager access_
140
- ) ForwardProxy(forwardTo) {
120
+ constructor(address forwardTo, IERC20Metadata currency_, IAccessManager access_) ForwardProxy(forwardTo) {
141
121
  _currency = currency_;
142
122
  _access = access_;
143
123
  }
@@ -20,9 +20,7 @@ contract RiskModuleMock is RiskModule {
20
20
 
21
21
  /// @custom:oz-upgrades-unsafe-allow constructor
22
22
  // solhint-disable-next-line no-empty-blocks
23
- constructor(IPolicyPool policyPool_, IPremiumsAccount premiumsAccount_)
24
- RiskModule(policyPool_, premiumsAccount_)
25
- {} // solhint-disable-line no-empty-blocks
23
+ constructor(IPolicyPool policyPool_, IPremiumsAccount premiumsAccount_) RiskModule(policyPool_, premiumsAccount_) {}
26
24
 
27
25
  /**
28
26
  * @dev Initializes the RiskModule
@@ -43,15 +41,7 @@ contract RiskModuleMock is RiskModule {
43
41
  uint256 exposureLimit_,
44
42
  address wallet_
45
43
  ) public initializer {
46
- __RiskModule_init(
47
- name_,
48
- collRatio_,
49
- ensuroPpFee_,
50
- srRoc_,
51
- maxPayoutPerPolicy_,
52
- exposureLimit_,
53
- wallet_
54
- );
44
+ __RiskModule_init(name_, collRatio_, ensuroPpFee_, srRoc_, maxPayoutPerPolicy_, exposureLimit_, wallet_);
55
45
  }
56
46
 
57
47
  function newPolicy(
@@ -66,10 +56,7 @@ contract RiskModuleMock is RiskModule {
66
56
  return _newPolicy(payout, premium, lossProb, expiration, payer, onBehalfOf, internalId).id;
67
57
  }
68
58
 
69
- function resolvePolicy(Policy.PolicyData calldata policy, uint256 payout)
70
- external
71
- onlyComponentRole(RESOLVER_ROLE)
72
- {
59
+ function resolvePolicy(Policy.PolicyData calldata policy, uint256 payout) external onlyComponentRole(RESOLVER_ROLE) {
73
60
  _policyPool.resolvePolicy(policy, payout);
74
61
  }
75
62
  }
@@ -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