Skip to content

Commit 7db331d

Browse files
committed
chore: reduce contract sizes to fit 24kb HorizonStaking and SubgraphService
1 parent 4799228 commit 7db331d

File tree

10 files changed

+5
-249
lines changed

10 files changed

+5
-249
lines changed

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

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -433,18 +433,6 @@ interface IHorizonStakingMain {
433433
*/
434434
error HorizonStakingInsufficientDelegationTokens(uint256 tokens, uint256 minTokens);
435435

436-
/**
437-
* @notice Thrown when the minimum token amount required for undelegation with beneficiary is not met.
438-
* @param tokens The actual token amount
439-
* @param minTokens The minimum required token amount
440-
*/
441-
error HorizonStakingInsufficientUndelegationTokens(uint256 tokens, uint256 minTokens);
442-
443-
/**
444-
* @notice Thrown when attempting to undelegate with a beneficiary that is the zero address.
445-
*/
446-
error HorizonStakingInvalidBeneficiaryZeroAddress();
447-
448436
/**
449437
* @notice Thrown when attempting to redelegate with a serivce provider that is the zero address.
450438
*/
@@ -754,33 +742,6 @@ interface IHorizonStakingMain {
754742
*/
755743
function undelegate(address serviceProvider, address verifier, uint256 shares) external returns (bytes32);
756744

757-
/**
758-
* @notice Undelegate tokens from a provision and start thawing them.
759-
* The tokens will be withdrawable by the `beneficiary` after the thawing period.
760-
*
761-
* Note that undelegating tokens from a provision is a two step process:
762-
* - First the tokens are thawed using this function.
763-
* - Then after the thawing period, the tokens are removed from the provision using {withdrawDelegated}.
764-
*
765-
* Requirements:
766-
* - `shares` cannot be zero.
767-
* - `beneficiary` cannot be the zero address.
768-
*
769-
* Emits a {TokensUndelegated} and {ThawRequestCreated} event.
770-
*
771-
* @param serviceProvider The service provider address
772-
* @param verifier The verifier address
773-
* @param shares The amount of shares to undelegate
774-
* @param beneficiary The address where the tokens will be withdrawn after thawing
775-
* @return The ID of the thaw request
776-
*/
777-
// function undelegateWithBeneficiary(
778-
// address serviceProvider,
779-
// address verifier,
780-
// uint256 shares,
781-
// address beneficiary
782-
// ) external returns (bytes32);
783-
784745
/**
785746
* @notice Withdraw undelegated tokens from a provision after thawing.
786747
* @dev The parameter `nThawRequests` can be set to a non zero value to fulfill a specific number of thaw
@@ -799,28 +760,6 @@ interface IHorizonStakingMain {
799760
*/
800761
function withdrawDelegated(address serviceProvider, address verifier, uint256 nThawRequests) external;
801762

802-
/**
803-
* @notice Withdraw undelegated with beneficiary tokens from a provision after thawing.
804-
* @dev The parameter `nThawRequests` can be set to a non zero value to fulfill a specific number of thaw
805-
* requests in the event that fulfilling all of them results in a gas limit error.
806-
* @dev If the delegation pool was completely slashed before withdrawing, calling this function will fulfill
807-
* the thaw requests with an amount equal to zero.
808-
*
809-
* Requirements:
810-
* - Must have previously initiated a thaw request using {undelegateWithBeneficiary}.
811-
*
812-
* Emits {ThawRequestFulfilled}, {ThawRequestsFulfilled} and {DelegatedTokensWithdrawn} events.
813-
*
814-
* @param serviceProvider The service provider address
815-
* @param verifier The verifier address
816-
* @param nThawRequests The number of thaw requests to fulfill. Set to 0 to fulfill all thaw requests.
817-
*/
818-
// function withdrawDelegatedWithBeneficiary(
819-
// address serviceProvider,
820-
// address verifier,
821-
// uint256 nThawRequests
822-
// ) external;
823-
824763
/**
825764
* @notice Re-delegate undelegated tokens from a provision after thawing to a `newServiceProvider` and `newVerifier`.
826765
* @dev The parameter `nThawRequests` can be set to a non zero value to fulfill a specific number of thaw

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ interface IHorizonStakingTypes {
138138
*/
139139
enum ThawRequestType {
140140
Provision,
141-
Delegation,
142-
DelegationWithBeneficiary
141+
Delegation
143142
}
144143

145144
/**

packages/horizon/contracts/staking/HorizonStaking.sol

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
4444
/// @dev Minimum amount of delegation.
4545
uint256 private constant MIN_DELEGATION = 1e18;
4646

47-
/// @dev Minimum amount of undelegation with beneficiary.
48-
uint256 private constant MIN_UNDELEGATION_WITH_BENEFICIARY = 10e18;
49-
5047
/**
5148
* @notice Checks that the caller is authorized to operate over a provision.
5249
* @param serviceProvider The address of the service provider.
@@ -307,19 +304,6 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
307304
return _undelegate(ThawRequestType.Delegation, serviceProvider, verifier, shares, msg.sender);
308305
}
309306

310-
/**
311-
* @notice See {IHorizonStakingMain-undelegate}.
312-
*/
313-
// function undelegateWithBeneficiary(
314-
// address serviceProvider,
315-
// address verifier,
316-
// uint256 shares,
317-
// address beneficiary
318-
// ) external override notPaused returns (bytes32) {
319-
// require(beneficiary != address(0), HorizonStakingInvalidBeneficiaryZeroAddress());
320-
// return _undelegate(ThawRequestType.DelegationWithBeneficiary, serviceProvider, verifier, shares, beneficiary);
321-
// }
322-
323307
/**
324308
* @notice See {IHorizonStakingMain-withdrawDelegated}.
325309
*/
@@ -339,25 +323,6 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
339323
);
340324
}
341325

342-
/**
343-
* @notice See {IHorizonStakingMain-withdrawDelegatedWithBeneficiary}.
344-
*/
345-
// function withdrawDelegatedWithBeneficiary(
346-
// address serviceProvider,
347-
// address verifier,
348-
// uint256 nThawRequests
349-
// ) external override notPaused {
350-
// _withdrawDelegated(
351-
// ThawRequestType.DelegationWithBeneficiary,
352-
// serviceProvider,
353-
// verifier,
354-
// address(0),
355-
// address(0),
356-
// 0,
357-
// nThawRequests
358-
// );
359-
// }
360-
361326
/**
362327
* @notice See {IHorizonStakingMain-redelegate}.
363328
*/
@@ -935,16 +900,6 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
935900
// Thawing pool is reset/initialized when the pool is empty: prov.tokensThawing == 0
936901
uint256 tokens = (_shares * (pool.tokens - pool.tokensThawing)) / pool.shares;
937902

938-
// Since anyone can undelegate for any beneficiary, we require a minimum amount to prevent
939-
// malicious actors from flooding the thaw request list with tiny amounts and causing a
940-
// denial of service attack by hitting the MAX_THAW_REQUESTS limit
941-
if (_requestType == ThawRequestType.DelegationWithBeneficiary) {
942-
require(
943-
tokens >= MIN_UNDELEGATION_WITH_BENEFICIARY,
944-
HorizonStakingInsufficientUndelegationTokens(tokens, MIN_UNDELEGATION_WITH_BENEFICIARY)
945-
);
946-
}
947-
948903
// Thawing shares are rounded down to protect the pool and avoid taking extra tokens from other participants.
949904
uint256 thawingShares = pool.tokensThawing == 0 ? tokens : ((tokens * pool.sharesThawing) / pool.tokensThawing);
950905
uint64 thawingUntil = uint64(block.timestamp + uint256(_provisions[_serviceProvider][_verifier].thawingPeriod));
@@ -1208,8 +1163,6 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
12081163
return _deleteProvisionThawRequest;
12091164
} else if (_requestType == ThawRequestType.Delegation) {
12101165
return _deleteDelegationThawRequest;
1211-
} else if (_requestType == ThawRequestType.DelegationWithBeneficiary) {
1212-
return _deleteDelegationWithBeneficiaryThawRequest;
12131166
} else {
12141167
revert HorizonStakingInvalidThawRequestType();
12151168
}
@@ -1231,14 +1184,6 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
12311184
delete _thawRequests[ThawRequestType.Delegation][_thawRequestId];
12321185
}
12331186

1234-
/**
1235-
* @notice Deletes a thaw request for a delegation with a beneficiary.
1236-
* @param _thawRequestId The ID of the thaw request to delete.
1237-
*/
1238-
function _deleteDelegationWithBeneficiaryThawRequest(bytes32 _thawRequestId) private {
1239-
delete _thawRequests[ThawRequestType.DelegationWithBeneficiary][_thawRequestId];
1240-
}
1241-
12421187
/**
12431188
* @notice See {IHorizonStakingMain-setOperator}.
12441189
* @dev Note that this function handles the special case where the verifier is the subgraph data service,

packages/horizon/contracts/staking/HorizonStakingBase.sol

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ abstract contract HorizonStakingBase is
310310
return _getNextProvisionThawRequest;
311311
} else if (_requestType == ThawRequestType.Delegation) {
312312
return _getNextDelegationThawRequest;
313-
} else if (_requestType == ThawRequestType.DelegationWithBeneficiary) {
314-
return _getNextDelegationWithBeneficiaryThawRequest;
315313
} else {
316314
revert HorizonStakingInvalidThawRequestType();
317315
}
@@ -335,15 +333,6 @@ abstract contract HorizonStakingBase is
335333
return _thawRequests[ThawRequestType.Delegation][_thawRequestId].next;
336334
}
337335

338-
/**
339-
* @notice Retrieves the next thaw request for a delegation with a beneficiary.
340-
* @param _thawRequestId The ID of the current thaw request.
341-
* @return The ID of the next thaw request in the list.
342-
*/
343-
function _getNextDelegationWithBeneficiaryThawRequest(bytes32 _thawRequestId) internal view returns (bytes32) {
344-
return _thawRequests[ThawRequestType.DelegationWithBeneficiary][_thawRequestId].next;
345-
}
346-
347336
/**
348337
* @notice Retrieves the thaw request list for the given request type.
349338
* @dev Uses the `ThawRequestType` to determine which mapping to access.

packages/horizon/foundry.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ test = 'test'
66
cache_path = 'cache_forge'
77
fs_permissions = [{ access = "read", path = "./"}]
88
optimizer = true
9-
optimizer_runs = 200
9+
optimizer_runs = 50

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

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -908,17 +908,6 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
908908
__undelegate(IHorizonStakingTypes.ThawRequestType.Delegation, serviceProvider, verifier, shares, false, caller);
909909
}
910910

911-
function _undelegateWithBeneficiary(address serviceProvider, address verifier, uint256 shares, address beneficiary) internal {
912-
__undelegate(
913-
IHorizonStakingTypes.ThawRequestType.DelegationWithBeneficiary,
914-
serviceProvider,
915-
verifier,
916-
shares,
917-
false,
918-
beneficiary
919-
);
920-
}
921-
922911
function _undelegate(address serviceProvider, uint256 shares) internal {
923912
(, address caller, ) = vm.readCallers();
924913
__undelegate(
@@ -992,8 +981,6 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
992981
staking.undelegate(serviceProvider, shares);
993982
} else if (thawRequestType == IHorizonStakingTypes.ThawRequestType.Delegation) {
994983
staking.undelegate(serviceProvider, verifier, shares);
995-
} else if (thawRequestType == IHorizonStakingTypes.ThawRequestType.DelegationWithBeneficiary) {
996-
staking.undelegateWithBeneficiary(serviceProvider, verifier, shares, beneficiary);
997984
} else {
998985
revert("Invalid thaw request type");
999986
}
@@ -1053,24 +1040,6 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
10531040
__withdrawDelegated(params);
10541041
}
10551042

1056-
function _withdrawDelegatedWithBeneficiary(
1057-
address serviceProvider,
1058-
address verifier,
1059-
uint256 nThawRequests
1060-
) internal {
1061-
Params_WithdrawDelegated memory params = Params_WithdrawDelegated({
1062-
thawRequestType: IHorizonStakingTypes.ThawRequestType.DelegationWithBeneficiary,
1063-
serviceProvider: serviceProvider,
1064-
verifier: verifier,
1065-
newServiceProvider: address(0),
1066-
newVerifier: address(0),
1067-
minSharesForNewProvider: 0,
1068-
nThawRequests: nThawRequests,
1069-
legacy: false
1070-
});
1071-
__withdrawDelegated(params);
1072-
}
1073-
10741043
function _redelegate(
10751044
address serviceProvider,
10761045
address verifier,
@@ -1197,8 +1166,6 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
11971166
);
11981167
} else if (params.thawRequestType == IHorizonStakingTypes.ThawRequestType.Delegation) {
11991168
staking.withdrawDelegated(params.serviceProvider, params.verifier, params.nThawRequests);
1200-
} else if (params.thawRequestType == IHorizonStakingTypes.ThawRequestType.DelegationWithBeneficiary) {
1201-
staking.withdrawDelegatedWithBeneficiary(params.serviceProvider, params.verifier, params.nThawRequests);
12021169
} else {
12031170
revert("Invalid thaw request type");
12041171
}

packages/horizon/test/staking/delegation/undelegate.t.sol

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,6 @@ contract HorizonStakingUndelegateTest is HorizonStakingTest {
5757
_undelegate(users.indexer, subgraphDataServiceAddress, delegation.shares);
5858
}
5959

60-
function testUndelegate_WithBeneficiary(
61-
uint256 amount,
62-
uint256 delegationAmount,
63-
address beneficiary
64-
) public useIndexer useProvision(amount, 0, 0) useDelegation(delegationAmount) {
65-
vm.assume(beneficiary != address(0));
66-
vm.assume(delegationAmount >= MIN_UNDELEGATION_WITH_BENEFICIARY);
67-
resetPrank(users.delegator);
68-
DelegationInternal memory delegation = _getStorage_Delegation(users.indexer, subgraphDataServiceAddress, users.delegator, false);
69-
_undelegateWithBeneficiary(users.indexer, subgraphDataServiceAddress, delegation.shares, beneficiary);
70-
}
71-
7260
function testUndelegate_RevertWhen_InsuficientTokens(
7361
uint256 amount,
7462
uint256 delegationAmount,
@@ -255,15 +243,4 @@ contract HorizonStakingUndelegateTest is HorizonStakingTest {
255243
resetPrank(users.delegator);
256244
_undelegate(users.indexer, subgraphDataServiceAddress, delegation.shares - delegation.shares / 2);
257245
}
258-
259-
function testUndelegate_RevertIf_BeneficiaryIsZero(
260-
uint256 amount,
261-
uint256 delegationAmount
262-
) public useIndexer useProvision(amount, 0, 0) useDelegation(delegationAmount) {
263-
resetPrank(users.delegator);
264-
DelegationInternal memory delegation = _getStorage_Delegation(users.indexer, subgraphDataServiceAddress, users.delegator, false);
265-
bytes memory expectedError = abi.encodeWithSelector(IHorizonStakingMain.HorizonStakingInvalidBeneficiaryZeroAddress.selector);
266-
vm.expectRevert(expectedError);
267-
staking.undelegateWithBeneficiary(users.indexer, subgraphDataServiceAddress, delegation.shares, address(0));
268-
}
269246
}

packages/horizon/test/staking/delegation/withdraw.t.sol

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -155,63 +155,4 @@ contract HorizonStakingWithdrawDelegationTest is HorizonStakingTest {
155155
resetPrank(users.delegator);
156156
_withdrawDelegated(users.indexer, subgraphDataServiceAddress, 0);
157157
}
158-
159-
function testWithdrawDelegation_WithBeneficiary(
160-
uint256 delegationAmount,
161-
address beneficiary
162-
)
163-
public
164-
useIndexer
165-
useProvision(10_000_000 ether, 0, MAX_THAWING_PERIOD)
166-
useDelegation(delegationAmount)
167-
{
168-
vm.assume(beneficiary != address(0));
169-
vm.assume(beneficiary != address(staking));
170-
vm.assume(delegationAmount >= MIN_UNDELEGATION_WITH_BENEFICIARY);
171-
// Skip beneficiary if balance will overflow
172-
vm.assume(token.balanceOf(beneficiary) < type(uint256).max - delegationAmount);
173-
174-
// Delegator undelegates to beneficiary
175-
resetPrank(users.delegator);
176-
DelegationInternal memory delegation = _getStorage_Delegation(users.indexer, subgraphDataServiceAddress, users.delegator, false);
177-
_undelegateWithBeneficiary(users.indexer, subgraphDataServiceAddress, delegation.shares, beneficiary);
178-
179-
// Thawing period ends
180-
LinkedList.List memory thawingRequests = staking.getThawRequestList(IHorizonStakingTypes.ThawRequestType.Delegation, users.indexer, subgraphDataServiceAddress, beneficiary);
181-
ThawRequest memory thawRequest = staking.getThawRequest(IHorizonStakingTypes.ThawRequestType.Delegation, thawingRequests.tail);
182-
skip(thawRequest.thawingUntil + 1);
183-
184-
// Beneficiary withdraws delegated tokens
185-
resetPrank(beneficiary);
186-
_withdrawDelegatedWithBeneficiary(users.indexer, subgraphDataServiceAddress, 1);
187-
}
188-
189-
function testWithdrawDelegation_RevertWhen_PreviousOwnerAttemptsToWithdraw(
190-
uint256 delegationAmount,
191-
address beneficiary
192-
)
193-
public
194-
useIndexer
195-
useProvision(10_000_000 ether, 0, MAX_THAWING_PERIOD)
196-
useDelegation(delegationAmount)
197-
{
198-
vm.assume(beneficiary != address(0));
199-
vm.assume(beneficiary != users.delegator);
200-
vm.assume(delegationAmount >= MIN_UNDELEGATION_WITH_BENEFICIARY);
201-
202-
// Delegator undelegates to beneficiary
203-
resetPrank(users.delegator);
204-
DelegationInternal memory delegation = _getStorage_Delegation(users.indexer, subgraphDataServiceAddress, users.delegator, false);
205-
_undelegateWithBeneficiary(users.indexer, subgraphDataServiceAddress, delegation.shares, beneficiary);
206-
207-
// Thawing period ends
208-
LinkedList.List memory thawingRequests = staking.getThawRequestList(IHorizonStakingTypes.ThawRequestType.Delegation, users.indexer, subgraphDataServiceAddress, users.delegator);
209-
ThawRequest memory thawRequest = staking.getThawRequest(IHorizonStakingTypes.ThawRequestType.Delegation, thawingRequests.tail);
210-
skip(thawRequest.thawingUntil + 1);
211-
212-
// Delegator attempts to withdraw delegated tokens, should revert since beneficiary is the thaw request owner
213-
bytes memory expectedError = abi.encodeWithSelector(IHorizonStakingMain.HorizonStakingNothingThawing.selector);
214-
vm.expectRevert(expectedError);
215-
staking.withdrawDelegated(users.indexer, subgraphDataServiceAddress, 1);
216-
}
217158
}

packages/horizon/test/utils/Constants.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ abstract contract Constants {
1414
uint64 internal constant MAX_THAWING_PERIOD = 28 days;
1515
uint32 internal constant THAWING_PERIOD_IN_BLOCKS = 300;
1616
uint256 internal constant MIN_DELEGATION = 1e18;
17-
uint256 internal constant MIN_UNDELEGATION_WITH_BENEFICIARY = 10e18;
1817
// Epoch manager
1918
uint256 internal constant EPOCH_LENGTH = 1;
2019
// Rewards manager

0 commit comments

Comments
 (0)