@ensuro/core 2.4.0 → 2.5.0

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.
@@ -152,6 +152,11 @@ abstract contract Reserve is PolicyPoolComponent {
152
152
  } else {
153
153
  _assetEarnings(abi.decode(result, (int256)));
154
154
  }
155
+ /**
156
+ * WARNING: if you are doing a forced replacement of the AM and you want the new AM
157
+ * to inherit the storage (just fixing the code), make sure the code of the new AM doesn't clean
158
+ * the storage in the connect() method (as it is the recommended practice in normal changes of AM).
159
+ */
155
160
  } else {
156
161
  bytes memory result = am.functionDelegateCall(
157
162
  abi.encodeWithSelector(IAssetManager.deinvestAll.selector)
@@ -116,6 +116,10 @@ library TimeScaled {
116
116
  int256 amount,
117
117
  uint256 interestRate
118
118
  ) internal {
119
+ if (scaledAmount.amount == 0) {
120
+ add(scaledAmount, uint256(amount), interestRate);
121
+ return;
122
+ }
119
123
  updateScale(scaledAmount, interestRate);
120
124
  uint256 newScaledAmount = uint256(int256(getScaledAmount(scaledAmount, interestRate)) + amount);
121
125
  scaledAmount.scale = newScaledAmount
@@ -38,6 +38,11 @@ interface IAssetManager is IERC165 {
38
38
 
39
39
  /**
40
40
  * @dev Function called when an asset manager is plugged into a reserve. Useful for initialization tasks
41
+ *
42
+ * Since the asset manager for a reserve can be changed and they use the stoage of the reserve contract, you
43
+ * can't assume the storage starts clean (all zeros). This is because a previous AM, using the same hash for the
44
+ * diamondStorage might have left some data. So, in the connect method you should initialize the state setting to
45
+ * zero what's expected to be zero.
41
46
  */
42
47
  function connect() external;
43
48
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ensuro/core",
3
3
  "description": "Ensuro - Decentralized insurance protocol",
4
- "version": "2.4.0",
4
+ "version": "2.5.0",
5
5
  "files": [
6
6
  "**/*.sol",
7
7
  "/build/contracts/*.json",