Skip to content

Commit

Permalink
fix: added thaw request type to thaw request fulfilled event (TRST-R15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maikol committed Dec 12, 2024
1 parent 04fcd0a commit f6ce016
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pragma solidity 0.8.27;

import { IGraphPayments } from "../../interfaces/IGraphPayments.sol";
import { IHorizonStakingTypes } from "./IHorizonStakingTypes.sol";

/**
* @title Inferface for the {HorizonStaking} contract.
Expand Down Expand Up @@ -280,13 +281,15 @@ interface IHorizonStakingMain {
* @param owner The address of the owner of the thaw requests
* @param thawRequestsFulfilled The number of thaw requests fulfilled
* @param tokens The total amount of tokens being released
* @param requestType The type of thaw request
*/
event ThawRequestsFulfilled(
address indexed serviceProvider,
address indexed verifier,
address indexed owner,
uint256 thawRequestsFulfilled,
uint256 tokens
uint256 tokens,
IHorizonStakingTypes.ThawRequestType requestType
);

// -- Events: governance --
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,19 @@ interface IHorizonStakingTypes {
uint256 nThawRequests;
uint256 thawingNonce;
}

/**
* @notice Results of the traversal of thaw requests.
* @dev This struct is used to avoid stack too deep error in the `fulfillThawRequests` function.
* @param requestsFulfilled The number of thaw requests fulfilled
* @param tokensThawed The total amount of tokens thawed
* @param tokensThawing The total amount of tokens thawing
* @param sharesThawing The total amount of shares thawing
*/
struct TraverseThawRequestsResults {
uint256 requestsFulfilled;
uint256 tokensThawed;
uint256 tokensThawing;
uint256 sharesThawing;
}
}
41 changes: 33 additions & 8 deletions packages/horizon/contracts/staking/HorizonStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1078,8 +1078,33 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
);
require(thawRequestList.count > 0, HorizonStakingNothingThawing());

TraverseThawRequestsResults memory results = _traverseThawRequests(params, thawRequestList);

emit ThawRequestsFulfilled(
params.serviceProvider,
params.verifier,
params.owner,
results.requestsFulfilled,
results.tokensThawed,
params.requestType
);

return (results.tokensThawed, results.tokensThawing, results.sharesThawing);
}

/**
* @notice Traverses a thaw request list and fulfills expired thaw requests.
* @param params The parameters for fulfilling thaw requests
* @param thawRequestList The list of thaw requests to traverse
* @return The results of the traversal
*/
function _traverseThawRequests(
FulfillThawRequestsParams memory params,
LinkedList.List storage thawRequestList
) private returns (TraverseThawRequestsResults memory) {
function(bytes32) view returns (bytes32) getNextItem = _getNextThawRequest(params.requestType);
function(bytes32) deleteItem = _getDeleteThawRequest(params.requestType);

bytes memory acc = abi.encode(
params.requestType,
uint256(0),
Expand All @@ -1099,14 +1124,14 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
data,
(ThawRequestType, uint256, uint256, uint256)
);
emit ThawRequestsFulfilled(
params.serviceProvider,
params.verifier,
params.owner,
thawRequestsFulfilled,
tokensThawed
);
return (tokensThawed, tokensThawing, sharesThawing);

return
TraverseThawRequestsResults({
requestsFulfilled: thawRequestsFulfilled,
tokensThawed: tokensThawed,
tokensThawing: tokensThawing,
sharesThawing: sharesThawing
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,8 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
verifier,
serviceProvider,
calcValues.thawRequestsFulfilledList.length,
calcValues.tokensThawed
calcValues.tokensThawed,
IHorizonStakingTypes.ThawRequestType.Provision
);
vm.expectEmit(address(staking));
emit IHorizonStakingMain.TokensDeprovisioned(serviceProvider, verifier, calcValues.tokensThawed);
Expand Down Expand Up @@ -617,7 +618,8 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
verifier,
serviceProvider,
calcValues.thawRequestsFulfilledList.length,
calcValues.tokensThawed
calcValues.tokensThawed,
IHorizonStakingTypes.ThawRequestType.Provision
);
vm.expectEmit(address(staking));
emit IHorizonStakingMain.TokensDeprovisioned(serviceProvider, verifier, calcValues.tokensThawed);
Expand Down Expand Up @@ -1160,7 +1162,8 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
params.verifier,
msgSender,
calcValues.thawRequestsFulfilledList.length,
calcValues.tokensThawed
calcValues.tokensThawed,
params.thawRequestType
);
if (calcValues.tokensThawed != 0) {
vm.expectEmit();
Expand Down

0 comments on commit f6ce016

Please sign in to comment.