Skip to content

Commit d1c5cc7

Browse files
committed
fix: add a new mapping instead of splitting thaw requests (TRST-H02)
1 parent c59c186 commit d1c5cc7

File tree

4 files changed

+17
-51
lines changed

4 files changed

+17
-51
lines changed

packages/horizon/contracts/staking/HorizonStaking.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,23 +1181,23 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
11811181
* @param _thawRequestId The ID of the thaw request to delete.
11821182
*/
11831183
function _deleteProvisionThawRequest(bytes32 _thawRequestId) private {
1184-
delete _provisionThawRequests[_thawRequestId];
1184+
delete _thawRequests[ThawRequestType.Provision][_thawRequestId];
11851185
}
11861186

11871187
/**
11881188
* @notice Deletes a thaw request for a delegation.
11891189
* @param _thawRequestId The ID of the thaw request to delete.
11901190
*/
11911191
function _deleteDelegationThawRequest(bytes32 _thawRequestId) private {
1192-
delete _delegationThawRequests[_thawRequestId];
1192+
delete _thawRequests[ThawRequestType.Delegation][_thawRequestId];
11931193
}
11941194

11951195
/**
11961196
* @notice Deletes a thaw request for a delegation with a beneficiary.
11971197
* @param _thawRequestId The ID of the thaw request to delete.
11981198
*/
11991199
function _deleteDelegationWithBeneficiaryThawRequest(bytes32 _thawRequestId) private {
1200-
delete _delegationWithBeneficiaryThawRequests[_thawRequestId];
1200+
delete _thawRequests[ThawRequestType.DelegationWithBeneficiary][_thawRequestId];
12011201
}
12021202

12031203
/**

packages/horizon/contracts/staking/HorizonStakingBase.sol

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ abstract contract HorizonStakingBase is
323323
* @return The ID of the next thaw request in the list.
324324
*/
325325
function _getNextProvisionThawRequest(bytes32 _thawRequestId) internal view returns (bytes32) {
326-
return _provisionThawRequests[_thawRequestId].next;
326+
return _thawRequests[ThawRequestType.Provision][_thawRequestId].next;
327327
}
328328

329329
/**
@@ -332,7 +332,7 @@ abstract contract HorizonStakingBase is
332332
* @return The ID of the next thaw request in the list.
333333
*/
334334
function _getNextDelegationThawRequest(bytes32 _thawRequestId) internal view returns (bytes32) {
335-
return _delegationThawRequests[_thawRequestId].next;
335+
return _thawRequests[ThawRequestType.Delegation][_thawRequestId].next;
336336
}
337337

338338
/**
@@ -341,7 +341,7 @@ abstract contract HorizonStakingBase is
341341
* @return The ID of the next thaw request in the list.
342342
*/
343343
function _getNextDelegationWithBeneficiaryThawRequest(bytes32 _thawRequestId) internal view returns (bytes32) {
344-
return _delegationWithBeneficiaryThawRequests[_thawRequestId].next;
344+
return _thawRequests[ThawRequestType.DelegationWithBeneficiary][_thawRequestId].next;
345345
}
346346

347347
/**
@@ -360,15 +360,7 @@ abstract contract HorizonStakingBase is
360360
address _verifier,
361361
address _owner
362362
) internal view returns (LinkedList.List storage) {
363-
if (_requestType == ThawRequestType.Provision) {
364-
return _provisionThawRequestLists[_serviceProvider][_verifier][_owner];
365-
} else if (_requestType == ThawRequestType.Delegation) {
366-
return _delegationThawRequestLists[_serviceProvider][_verifier][_owner];
367-
} else if (_requestType == ThawRequestType.DelegationWithBeneficiary) {
368-
return _delegationWithBeneficiaryThawRequestLists[_serviceProvider][_verifier][_owner];
369-
} else {
370-
revert HorizonStakingInvalidThawRequestType();
371-
}
363+
return _thawRequestLists[_requestType][_serviceProvider][_verifier][_owner];
372364
}
373365

374366
/**
@@ -383,15 +375,7 @@ abstract contract HorizonStakingBase is
383375
ThawRequestType _requestType,
384376
bytes32 _thawRequestId
385377
) internal view returns (IHorizonStakingTypes.ThawRequest storage) {
386-
if (_requestType == ThawRequestType.Provision) {
387-
return _provisionThawRequests[_thawRequestId];
388-
} else if (_requestType == ThawRequestType.Delegation) {
389-
return _delegationThawRequests[_thawRequestId];
390-
} else if (_requestType == ThawRequestType.DelegationWithBeneficiary) {
391-
return _delegationWithBeneficiaryThawRequests[_thawRequestId];
392-
} else {
393-
revert("Unknown ThawRequestType");
394-
}
378+
return _thawRequests[_requestType][_thawRequestId];
395379
}
396380

397381
/**

packages/horizon/contracts/staking/HorizonStakingStorage.sol

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -148,32 +148,14 @@ abstract contract HorizonStakingV1Storage {
148148
internal _delegationFeeCut;
149149

150150
/// @dev Thaw requests
151-
/// Details for each thawing operation in the staking contract for both service providers.
152-
mapping(bytes32 thawRequestId => IHorizonStakingTypes.ThawRequest thawRequest) internal _provisionThawRequests;
151+
/// Details for each thawing operation in the staking contract (for both service providers and delegators).
152+
mapping(IHorizonStakingTypes.ThawRequestType thawRequestType => mapping(bytes32 thawRequestId => IHorizonStakingTypes.ThawRequest thawRequest))
153+
internal _thawRequests;
153154

154155
/// @dev Thaw request lists
155-
/// Metadata defining linked lists of thaw requests for each service provider (owner).
156-
mapping(address serviceProvider => mapping(address verifier => mapping(address owner => LinkedList.List list)))
157-
internal _provisionThawRequestLists;
158-
159-
/// @dev Thaw requests
160-
/// Details for each thawing operation in the staking contract for delegators.
161-
mapping(bytes32 thawRequestId => IHorizonStakingTypes.ThawRequest thawRequest) internal _delegationThawRequests;
162-
163-
/// @dev Thaw request lists
164-
/// Metadata defining linked lists of thaw requests for each delegator (owner).
165-
mapping(address serviceProvider => mapping(address verifier => mapping(address owner => LinkedList.List list)))
166-
internal _delegationThawRequestLists;
167-
168-
/// @dev Thaw requests
169-
/// Details for each thawing operation in the staking contract for both delegators undelegating to a beneficiary.
170-
mapping(bytes32 thawRequestId => IHorizonStakingTypes.ThawRequest thawRequest)
171-
internal _delegationWithBeneficiaryThawRequests;
172-
173-
/// @dev Thaw request lists
174-
/// Metadata defining linked lists of thaw requests for each delegator (owner) undelegating to a beneficiary.
175-
mapping(address serviceProvider => mapping(address verifier => mapping(address owner => LinkedList.List list)))
176-
internal _delegationWithBeneficiaryThawRequestLists;
156+
/// Metadata defining linked lists of thaw requests for each service provider or delegator (owner)
157+
mapping(IHorizonStakingTypes.ThawRequestType thawRequestType => mapping(address serviceProvider => mapping(address verifier => mapping(address owner => LinkedList.List list))))
158+
internal _thawRequestLists;
177159

178160
/// @dev Operator allow list
179161
/// Used for all verifiers except the subgraph data service.

packages/horizon/test/shared/horizon-staking/HorizonStakingShared.t.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,7 +1852,7 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
18521852
address operator,
18531853
bool legacy
18541854
) internal view returns (bool) {
1855-
uint256 slotNumber = legacy ? 21 : 35;
1855+
uint256 slotNumber = legacy ? 21 : 31;
18561856
uint256 slot;
18571857

18581858
if (legacy) {
@@ -1934,7 +1934,7 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
19341934
address verifier,
19351935
bool legacy
19361936
) internal view returns (DelegationPoolInternalTest memory) {
1937-
uint256 slotNumber = legacy ? 20 : 37;
1937+
uint256 slotNumber = legacy ? 20 : 33;
19381938
uint256 baseSlot;
19391939
if (legacy) {
19401940
baseSlot = uint256(keccak256(abi.encode(serviceProvider, slotNumber)));
@@ -1966,7 +1966,7 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
19661966
address delegator,
19671967
bool legacy
19681968
) internal view returns (DelegationInternal memory) {
1969-
uint256 slotNumber = legacy ? 20 : 37;
1969+
uint256 slotNumber = legacy ? 20 : 33;
19701970
uint256 baseSlot;
19711971

19721972
// DelegationPool

0 commit comments

Comments
 (0)