Skip to content

Commit 5b33321

Browse files
authored
fix: keep structs for storage layout compatability (#31)
Signed-off-by: Reinis Martinsons <[email protected]>
1 parent 3f84f27 commit 5b33321

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/optimistic-oracle-v2/implementation/ManagedOptimisticOracleV2.sol

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ contract ManagedOptimisticOracleV2 is ManagedOptimisticOracleV2Interface, Optimi
2525
BondRange range;
2626
}
2727

28+
struct CustomBond {
29+
uint256 amount;
30+
// isSet is not used anymore as amount cannot be set to 0, but it is kept for storage layout compatibility.
31+
bool isSet;
32+
}
33+
34+
struct CustomLiveness {
35+
uint256 liveness;
36+
// isSet is not used anymore as liveness cannot be set to 0, but it is kept for storage layout compatibility.
37+
bool isSet;
38+
}
39+
2840
// Config admin role is used to manage request managers and set other default parameters.
2941
bytes32 public constant CONFIG_ADMIN_ROLE = keccak256("CONFIG_ADMIN_ROLE");
3042

@@ -36,10 +48,10 @@ contract ManagedOptimisticOracleV2 is ManagedOptimisticOracleV2Interface, Optimi
3648
AddressWhitelistInterface public requesterWhitelist;
3749

3850
// Custom bonds set by request managers for specific request and currency combinations.
39-
mapping(bytes32 managedRequestId => mapping(IERC20 currency => uint256 customBond)) public customBonds;
51+
mapping(bytes32 managedRequestId => mapping(IERC20 currency => CustomBond)) public customBonds;
4052

4153
// Custom liveness values set by request managers for specific requests.
42-
mapping(bytes32 managedRequestId => uint256 customLiveness) public customLivenessValues;
54+
mapping(bytes32 managedRequestId => CustomLiveness) public customLivenessValues;
4355

4456
// Custom proposer whitelists set by request managers for specific requests.
4557
mapping(bytes32 managedRequestId => AddressWhitelistInterface) public customProposerWhitelists;
@@ -206,7 +218,7 @@ contract ManagedOptimisticOracleV2 is ManagedOptimisticOracleV2Interface, Optimi
206218
require(_getCollateralWhitelist().isOnWhitelist(address(currency)), UnsupportedCurrency());
207219
_validateBond(currency, bond);
208220
bytes32 managedRequestId = getManagedRequestId(requester, identifier, ancillaryData);
209-
customBonds[managedRequestId][currency] = bond;
221+
customBonds[managedRequestId][currency].amount = bond;
210222
emit CustomBondSet(managedRequestId, requester, identifier, ancillaryData, currency, bond);
211223
}
212224

@@ -227,7 +239,7 @@ contract ManagedOptimisticOracleV2 is ManagedOptimisticOracleV2Interface, Optimi
227239
) external nonReentrant onlyRequestManager {
228240
_validateLiveness(customLiveness);
229241
bytes32 managedRequestId = getManagedRequestId(requester, identifier, ancillaryData);
230-
customLivenessValues[managedRequestId] = customLiveness;
242+
customLivenessValues[managedRequestId].liveness = customLiveness;
231243
emit CustomLivenessSet(managedRequestId, requester, identifier, ancillaryData, customLiveness);
232244
}
233245

@@ -277,11 +289,11 @@ contract ManagedOptimisticOracleV2 is ManagedOptimisticOracleV2Interface, Optimi
277289
// Apply the custom bond and liveness overrides if set.
278290
Request storage request = _getRequest(requester, identifier, timestamp, ancillaryData);
279291
bytes32 managedRequestId = getManagedRequestId(requester, identifier, ancillaryData);
280-
uint256 customBond = customBonds[managedRequestId][request.currency];
292+
uint256 customBond = customBonds[managedRequestId][request.currency].amount;
281293
if (customBond != 0) {
282294
request.requestSettings.bond = customBond;
283295
}
284-
uint256 customLiveness = customLivenessValues[managedRequestId];
296+
uint256 customLiveness = customLivenessValues[managedRequestId].liveness;
285297
if (customLiveness != 0) {
286298
request.requestSettings.customLiveness = customLiveness;
287299
}

0 commit comments

Comments
 (0)