Skip to content

Commit e68d12d

Browse files
juanmardefagotmigone
authored andcommitted
fix: add extra parameters to contract events (OZ CR-XX)
Signed-off-by: Tomás Migone <[email protected]>
1 parent 07aeb21 commit e68d12d

File tree

9 files changed

+50
-18
lines changed

9 files changed

+50
-18
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,14 @@ interface IHorizonStakingMain {
189189
* @param verifier The address of the verifier
190190
* @param delegator The address of the delegator
191191
* @param tokens The amount of tokens undelegated
192+
* @param tokens The amount of shares undelegated
192193
*/
193194
event TokensUndelegated(
194195
address indexed serviceProvider,
195196
address indexed verifier,
196197
address indexed delegator,
197-
uint256 tokens
198+
uint256 tokens,
199+
uint256 shares
198200
);
199201

200202
/**

packages/horizon/contracts/staking/HorizonStaking.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
947947
pool.thawingNonce
948948
);
949949

950-
emit TokensUndelegated(_serviceProvider, _verifier, msg.sender, tokens);
950+
emit TokensUndelegated(_serviceProvider, _verifier, msg.sender, tokens, _shares);
951951
return thawRequestId;
952952
}
953953

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
10101010
calcValues.thawRequestId
10111011
);
10121012
vm.expectEmit();
1013-
emit IHorizonStakingMain.TokensUndelegated(serviceProvider, verifier, delegator, calcValues.tokens);
1013+
emit IHorizonStakingMain.TokensUndelegated(serviceProvider, verifier, delegator, calcValues.tokens, shares);
10141014
if (legacy) {
10151015
staking.undelegate(serviceProvider, shares);
10161016
} else if (thawRequestType == IHorizonStakingTypes.ThawRequestType.Delegation) {

packages/subgraph-service/contracts/SubgraphService.sol

+10-3
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ contract SubgraphService is
227227
_allocations.get(allocationId).indexer == indexer,
228228
SubgraphServiceAllocationNotAuthorized(indexer, allocationId)
229229
);
230-
_closeAllocation(allocationId);
230+
_closeAllocation(allocationId, false);
231231
emit ServiceStopped(indexer, data);
232232
}
233233

@@ -306,7 +306,7 @@ contract SubgraphService is
306306
Allocation.State memory allocation = _allocations.get(allocationId);
307307
require(allocation.isStale(maxPOIStaleness), SubgraphServiceCannotForceCloseAllocation(allocationId));
308308
require(!allocation.isAltruistic(), SubgraphServiceAllocationIsAltruistic(allocationId));
309-
_closeAllocation(allocationId);
309+
_closeAllocation(allocationId, true);
310310
}
311311

312312
/// @inheritdoc ISubgraphService
@@ -522,7 +522,14 @@ contract SubgraphService is
522522
}
523523
}
524524

525-
emit QueryFeesCollected(indexer, _signedRav.rav.payer, tokensCollected, tokensCurators);
525+
emit QueryFeesCollected(
526+
indexer,
527+
_signedRav.rav.payer,
528+
allocationId,
529+
subgraphDeploymentId,
530+
tokensCollected,
531+
tokensCurators
532+
);
526533
return tokensCollected;
527534
}
528535

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

+4
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ interface ISubgraphService is IDataServiceFees {
3434
* @notice Emitted when a subgraph service collects query fees from Graph Payments
3535
* @param serviceProvider The address of the service provider
3636
* @param payer The address paying for the query fees
37+
* @param allocationId The id of the allocation
38+
* @param subgraphDeploymentId The id of the subgraph deployment
3739
* @param tokensCollected The amount of tokens collected
3840
* @param tokensCurators The amount of tokens curators receive
3941
*/
4042
event QueryFeesCollected(
4143
address indexed serviceProvider,
4244
address indexed payer,
45+
address indexed allocationId,
46+
bytes32 subgraphDeploymentId,
4347
uint256 tokensCollected,
4448
uint256 tokensCurators
4549
);

packages/subgraph-service/contracts/utilities/AllocationManager.sol

+14-5
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,14 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca
9696
* @param allocationId The id of the allocation
9797
* @param subgraphDeploymentId The id of the subgraph deployment
9898
* @param tokens The amount of tokens allocated
99+
* @param forceClosed Whether the allocation was force closed
99100
*/
100101
event AllocationClosed(
101102
address indexed indexer,
102103
address indexed allocationId,
103104
bytes32 indexed subgraphDeploymentId,
104-
uint256 tokens
105+
uint256 tokens,
106+
bool forceClosed
105107
);
106108

107109
/**
@@ -335,9 +337,9 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca
335337
currentEpoch
336338
);
337339

338-
// Check if the indexer is over-allocated and close the allocation if necessary
340+
// Check if the indexer is over-allocated and force close the allocation if necessary
339341
if (_isOverAllocated(allocation.indexer, _delegationRatio)) {
340-
_closeAllocation(_allocationId);
342+
_closeAllocation(_allocationId, true);
341343
}
342344

343345
return tokensRewards;
@@ -415,8 +417,9 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca
415417
* Emits a {AllocationClosed} event
416418
*
417419
* @param _allocationId The id of the allocation to be closed
420+
* @param _forceClosed Whether the allocation was force closed
418421
*/
419-
function _closeAllocation(address _allocationId) internal {
422+
function _closeAllocation(address _allocationId, bool _forceClosed) internal {
420423
Allocation.State memory allocation = _allocations.get(_allocationId);
421424

422425
// Take rewards snapshot to prevent other allos from counting tokens from this allo
@@ -433,7 +436,13 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca
433436
_subgraphAllocatedTokens[allocation.subgraphDeploymentId] -
434437
allocation.tokens;
435438

436-
emit AllocationClosed(allocation.indexer, _allocationId, allocation.subgraphDeploymentId, allocation.tokens);
439+
emit AllocationClosed(
440+
allocation.indexer,
441+
_allocationId,
442+
allocation.subgraphDeploymentId,
443+
allocation.tokens,
444+
_forceClosed
445+
);
437446
}
438447

439448
/**

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest {
145145
_indexer,
146146
allocationId,
147147
allocation.subgraphDeploymentId,
148-
allocation.tokens
148+
allocation.tokens,
149+
false
149150
);
150151
emit IDataService.ServiceStopped(_indexer, _data);
151152

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

+14-5
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest {
160160
allocation.indexer,
161161
_allocationId,
162162
allocation.subgraphDeploymentId,
163-
allocation.tokens
163+
allocation.tokens,
164+
true
164165
);
165166

166167
// close stale allocation
@@ -278,9 +279,10 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest {
278279
bytes memory _data
279280
) private returns (uint256 paymentCollected) {
280281
IGraphTallyCollector.SignedRAV memory signedRav = abi.decode(_data, (IGraphTallyCollector.SignedRAV));
281-
Allocation.State memory allocation = subgraphService.getAllocation(
282-
address(uint160(uint256(signedRav.rav.collectionId)))
283-
);
282+
address allocationId = address(uint160(uint256(signedRav.rav.collectionId)));
283+
Allocation.State memory allocation = subgraphService.getAllocation(allocationId);
284+
bytes32 subgraphDeploymentId = allocation.subgraphDeploymentId;
285+
284286
address payer = graphTallyCollector.isAuthorized(signedRav.rav.payer, _recoverRAVSigner(signedRav))
285287
? signedRav.rav.payer
286288
: address(0);
@@ -298,7 +300,14 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest {
298300
uint256 tokensCurators = (paymentCollected - tokensProtocol).mulPPMRoundUp(queryFeeData.curationCut);
299301

300302
vm.expectEmit(address(subgraphService));
301-
emit ISubgraphService.QueryFeesCollected(_indexer, payer, paymentCollected, tokensCurators);
303+
emit ISubgraphService.QueryFeesCollected(
304+
_indexer,
305+
payer,
306+
allocationId,
307+
subgraphDeploymentId,
308+
paymentCollected,
309+
tokensCurators
310+
);
302311

303312
return paymentCollected;
304313
}

packages/subgraph-service/test/subgraphService/collect/indexing/indexing.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { IGraphPayments } from "@graphprotocol/horizon/contracts/interfaces/IGra
77

88
import { ISubgraphService } from "../../../../contracts/interfaces/ISubgraphService.sol";
99
import { SubgraphServiceTest } from "../../SubgraphService.t.sol";
10-
10+
import { Allocation } from "../../../../contracts/libraries/Allocation.sol";
1111
contract SubgraphServiceCollectIndexingTest is SubgraphServiceTest {
1212
/*
1313
* TESTS

0 commit comments

Comments
 (0)