Skip to content

Commit 57aea44

Browse files
committed
fix: added thaw request type to thaw request fulfilled event (TRST-R15)
1 parent 7d90ad2 commit 57aea44

File tree

4 files changed

+58
-12
lines changed

4 files changed

+58
-12
lines changed

packages/horizon/contracts/interfaces/internal/IHorizonStakingMain.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
pragma solidity 0.8.27;
44

55
import { IGraphPayments } from "../../interfaces/IGraphPayments.sol";
6+
import { IHorizonStakingTypes } from "./IHorizonStakingTypes.sol";
67

78
/**
89
* @title Inferface for the {HorizonStaking} contract.
@@ -280,13 +281,15 @@ interface IHorizonStakingMain {
280281
* @param owner The address of the owner of the thaw requests
281282
* @param thawRequestsFulfilled The number of thaw requests fulfilled
282283
* @param tokens The total amount of tokens being released
284+
* @param requestType The type of thaw request
283285
*/
284286
event ThawRequestsFulfilled(
285287
address indexed serviceProvider,
286288
address indexed verifier,
287289
address indexed owner,
288290
uint256 thawRequestsFulfilled,
289-
uint256 tokens
291+
uint256 tokens,
292+
IHorizonStakingTypes.ThawRequestType requestType
290293
);
291294

292295
// -- Events: governance --

packages/horizon/contracts/interfaces/internal/IHorizonStakingTypes.sol

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,19 @@ interface IHorizonStakingTypes {
180180
uint256 nThawRequests;
181181
uint256 thawingNonce;
182182
}
183+
184+
/**
185+
* @notice Results of the traversal of thaw requests.
186+
* @dev This struct is used to avoid stack too deep error in the `fulfillThawRequests` function.
187+
* @param requestsFulfilled The number of thaw requests fulfilled
188+
* @param tokensThawed The total amount of tokens thawed
189+
* @param tokensThawing The total amount of tokens thawing
190+
* @param sharesThawing The total amount of shares thawing
191+
*/
192+
struct TraverseThawRequestsResults {
193+
uint256 requestsFulfilled;
194+
uint256 tokensThawed;
195+
uint256 tokensThawing;
196+
uint256 sharesThawing;
197+
}
183198
}

packages/horizon/contracts/staking/HorizonStaking.sol

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,8 +1078,33 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
10781078
);
10791079
require(thawRequestList.count > 0, HorizonStakingNothingThawing());
10801080

1081+
TraverseThawRequestsResults memory results = _traverseThawRequests(params, thawRequestList);
1082+
1083+
emit ThawRequestsFulfilled(
1084+
params.serviceProvider,
1085+
params.verifier,
1086+
params.owner,
1087+
results.requestsFulfilled,
1088+
results.tokensThawed,
1089+
params.requestType
1090+
);
1091+
1092+
return (results.tokensThawed, results.tokensThawing, results.sharesThawing);
1093+
}
1094+
1095+
/**
1096+
* @notice Traverses a thaw request list and fulfills expired thaw requests.
1097+
* @param params The parameters for fulfilling thaw requests
1098+
* @param thawRequestList The list of thaw requests to traverse
1099+
* @return The results of the traversal
1100+
*/
1101+
function _traverseThawRequests(
1102+
FulfillThawRequestsParams memory params,
1103+
LinkedList.List storage thawRequestList
1104+
) private returns (TraverseThawRequestsResults memory) {
10811105
function(bytes32) view returns (bytes32) getNextItem = _getNextThawRequest(params.requestType);
10821106
function(bytes32) deleteItem = _getDeleteThawRequest(params.requestType);
1107+
10831108
bytes memory acc = abi.encode(
10841109
params.requestType,
10851110
uint256(0),
@@ -1099,14 +1124,14 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
10991124
data,
11001125
(ThawRequestType, uint256, uint256, uint256)
11011126
);
1102-
emit ThawRequestsFulfilled(
1103-
params.serviceProvider,
1104-
params.verifier,
1105-
params.owner,
1106-
thawRequestsFulfilled,
1107-
tokensThawed
1108-
);
1109-
return (tokensThawed, tokensThawing, sharesThawing);
1127+
1128+
return
1129+
TraverseThawRequestsResults({
1130+
requestsFulfilled: thawRequestsFulfilled,
1131+
tokensThawed: tokensThawed,
1132+
tokensThawing: tokensThawing,
1133+
sharesThawing: sharesThawing
1134+
});
11101135
}
11111136

11121137
/**

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,8 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
504504
verifier,
505505
serviceProvider,
506506
calcValues.thawRequestsFulfilledList.length,
507-
calcValues.tokensThawed
507+
calcValues.tokensThawed,
508+
IHorizonStakingTypes.ThawRequestType.Provision
508509
);
509510
vm.expectEmit(address(staking));
510511
emit IHorizonStakingMain.TokensDeprovisioned(serviceProvider, verifier, calcValues.tokensThawed);
@@ -617,7 +618,8 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
617618
verifier,
618619
serviceProvider,
619620
calcValues.thawRequestsFulfilledList.length,
620-
calcValues.tokensThawed
621+
calcValues.tokensThawed,
622+
IHorizonStakingTypes.ThawRequestType.Provision
621623
);
622624
vm.expectEmit(address(staking));
623625
emit IHorizonStakingMain.TokensDeprovisioned(serviceProvider, verifier, calcValues.tokensThawed);
@@ -1160,7 +1162,8 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
11601162
params.verifier,
11611163
msgSender,
11621164
calcValues.thawRequestsFulfilledList.length,
1163-
calcValues.tokensThawed
1165+
calcValues.tokensThawed,
1166+
params.thawRequestType
11641167
);
11651168
if (calcValues.tokensThawed != 0) {
11661169
vm.expectEmit();

0 commit comments

Comments
 (0)