Skip to content

Commit 7cd08cb

Browse files
committed
chore: ensure contract size is below 24kB
Signed-off-by: Tomás Migone <[email protected]>
1 parent 01db6e5 commit 7cd08cb

File tree

10 files changed

+22
-73
lines changed

10 files changed

+22
-73
lines changed

packages/contracts/contracts/rewards/IRewardsIssuer.sol

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,4 @@ interface IRewardsIssuer {
3131
* @return Total tokens allocated to subgraph
3232
*/
3333
function getSubgraphAllocatedTokens(bytes32 _subgraphDeploymentId) external view returns (uint256);
34-
35-
/**
36-
* @notice Whether or not an allocation is active (i.e open)
37-
* @param _allocationId Allocation Id
38-
* @return Whether or not the allocation is active
39-
*/
40-
function isActiveAllocation(address _allocationId) external view returns (bool);
4134
}

packages/contracts/contracts/rewards/IRewardsManager.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface IRewardsManager {
3939

4040
function getAccRewardsPerAllocatedToken(bytes32 _subgraphDeploymentID) external view returns (uint256, uint256);
4141

42-
function getRewards(address _allocationID) external view returns (uint256);
42+
function getRewards(address _rewardsIssuer, address _allocationID) external view returns (uint256);
4343

4444
function calcRewards(uint256 _tokens, uint256 _accRewardsPerAllocatedToken) external pure returns (uint256);
4545

packages/contracts/contracts/rewards/RewardsManager.sol

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -322,32 +322,19 @@ contract RewardsManager is RewardsManagerV5Storage, GraphUpgradeable, IRewardsMa
322322
* @param _allocationID Allocation
323323
* @return Rewards amount for an allocation
324324
*/
325-
function getRewards(address _allocationID) external view override returns (uint256) {
326-
address rewardsIssuer = address(0);
327-
328-
// Check both the legacy and new allocations
329-
address[2] memory rewardsIssuers = [address(staking()), address(subgraphService)];
330-
for (uint256 i = 0; i < rewardsIssuers.length; i++) {
331-
if (rewardsIssuers[i] != address(0)) {
332-
if (IRewardsIssuer(rewardsIssuers[i]).isActiveAllocation(_allocationID)) {
333-
rewardsIssuer = address(rewardsIssuers[i]);
334-
break;
335-
}
336-
}
337-
}
338-
339-
// Bail if allo does not exist
340-
if (rewardsIssuer == address(0)) {
341-
return 0;
342-
}
325+
function getRewards(address _rewardsIssuer, address _allocationID) external view override returns (uint256) {
326+
require(
327+
_rewardsIssuer == address(staking()) || _rewardsIssuer == address(subgraphService),
328+
"Not a rewards issuer"
329+
);
343330

344331
(
345332
,
346333
bytes32 subgraphDeploymentId,
347334
uint256 tokens,
348335
uint256 alloAccRewardsPerAllocatedToken,
349336
uint256 accRewardsPending
350-
) = IRewardsIssuer(rewardsIssuer).getAllocationData(_allocationID);
337+
) = IRewardsIssuer(_rewardsIssuer).getAllocationData(_allocationID);
351338

352339
(uint256 accRewardsPerAllocatedToken, ) = getAccRewardsPerAllocatedToken(subgraphDeploymentId);
353340
return

packages/horizon/contracts/staking/HorizonStakingExtension.sol

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,6 @@ contract HorizonStakingExtension is HorizonStakingBase, IHorizonStakingExtension
274274
return __DEPRECATED_subgraphAllocations[subgraphDeploymentID];
275275
}
276276

277-
/**
278-
* @notice Return true if allocation is active.
279-
* @param allocationID Allocation identifier
280-
* @return True if allocation is active
281-
*/
282-
function isActiveAllocation(address allocationID) external view override returns (bool) {
283-
return _getAllocationState(allocationID) == AllocationState.Active;
284-
}
285-
286277
/**
287278
* @notice Get the total amount of tokens staked by the indexer.
288279
* @param indexer Address of the indexer

packages/subgraph-service/contracts/SubgraphService.sol

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -449,18 +449,6 @@ contract SubgraphService is
449449
return _subgraphAllocatedTokens[subgraphDeploymentId];
450450
}
451451

452-
/**
453-
* @notice Check if an allocation is open
454-
* @dev Implements {IRewardsIssuer.isAllocationActive}
455-
* @dev To be used by the {RewardsManager}.
456-
*
457-
* @param allocationId The allocation Id
458-
* @return Wether or not the allocation is active
459-
*/
460-
function isActiveAllocation(address allocationId) external view override returns (bool) {
461-
return _allocations[allocationId].isOpen();
462-
}
463-
464452
/**
465453
* @notice See {ISubgraphService.getLegacyAllocation}
466454
*/
@@ -475,13 +463,6 @@ contract SubgraphService is
475463
return _encodeAllocationProof(indexer, allocationId);
476464
}
477465

478-
/**
479-
* @notice See {ISubgraphService.isStaleAllocation}
480-
*/
481-
function isStaleAllocation(address allocationId) external view override returns (bool) {
482-
return _allocations.get(allocationId).isStale(maxPOIStaleness);
483-
}
484-
485466
/**
486467
* @notice See {ISubgraphService.isOverAllocated}
487468
*/

packages/subgraph-service/contracts/interfaces/ISubgraphService.sol

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,6 @@ interface ISubgraphService is IDataServiceFees {
241241
*/
242242
function encodeAllocationProof(address indexer, address allocationId) external view returns (bytes32);
243243

244-
/**
245-
* @notice Checks if an allocation is stale
246-
* @param allocationId The id of the allocation
247-
* @return True if the allocation is stale, false otherwise
248-
*/
249-
function isStaleAllocation(address allocationId) external view returns (bool);
250-
251244
/**
252245
* @notice Checks if an indexer is over-allocated
253246
* @param allocationId The id of the allocation

packages/subgraph-service/hardhat.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ if (process.env.BUILD_RUN !== 'true') {
1717

1818
const config: HardhatUserConfig = {
1919
...hardhatBaseConfig,
20+
solidity: {
21+
version: '0.8.27',
22+
settings: {
23+
optimizer: {
24+
enabled: true,
25+
runs: 50,
26+
},
27+
},
28+
},
2029
graph: {
2130
deployments: {
2231
...hardhatBaseConfig.graph?.deployments,

packages/subgraph-service/test/mocks/MockRewardsManager.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ contract MockRewardsManager is IRewardsManager {
6161

6262
function getAccRewardsPerAllocatedToken(bytes32) external view returns (uint256, uint256) {}
6363

64-
function getRewards(address) external view returns (uint256) {}
64+
function getRewards(address,address) external view returns (uint256) {}
6565

6666
function calcRewards(uint256, uint256) external pure returns (uint256) {}
6767

packages/subgraph-service/test/shared/SubgraphServiceShared.t.sol

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { ISubgraphService } from "../../contracts/interfaces/ISubgraphService.so
1111
import { HorizonStakingSharedTest } from "./HorizonStakingShared.t.sol";
1212

1313
abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest {
14+
using Allocation for Allocation.State;
15+
1416
/*
1517
* VARIABLES
1618
*/
@@ -101,13 +103,7 @@ abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest {
101103

102104
vm.expectEmit(address(subgraphService));
103105
emit IDataService.ServiceStarted(_indexer, _data);
104-
emit AllocationManager.AllocationCreated(
105-
_indexer,
106-
allocationId,
107-
subgraphDeploymentId,
108-
tokens,
109-
currentEpoch
110-
);
106+
emit AllocationManager.AllocationCreated(_indexer, allocationId, subgraphDeploymentId, tokens, currentEpoch);
111107

112108
// TODO: improve this
113109
uint256 accRewardsPerAllocatedToken = 0;
@@ -137,9 +133,9 @@ abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest {
137133

138134
function _stopService(address _indexer, bytes memory _data) internal {
139135
address allocationId = abi.decode(_data, (address));
140-
assertTrue(subgraphService.isActiveAllocation(allocationId));
141136

142137
Allocation.State memory allocation = subgraphService.getAllocation(allocationId);
138+
assertTrue(allocation.isOpen());
143139
uint256 previousSubgraphAllocatedTokens = subgraphService.getSubgraphAllocatedTokens(
144140
allocation.subgraphDeploymentId
145141
);

packages/subgraph-service/test/subgraphService/SubgraphService.t.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,8 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest {
149149
}
150150

151151
function _closeStaleAllocation(address _allocationId) internal {
152-
assertTrue(subgraphService.isActiveAllocation(_allocationId));
153-
154152
Allocation.State memory allocation = subgraphService.getAllocation(_allocationId);
153+
assertTrue(allocation.isOpen());
155154
uint256 previousSubgraphAllocatedTokens = subgraphService.getSubgraphAllocatedTokens(
156155
allocation.subgraphDeploymentId
157156
);

0 commit comments

Comments
 (0)