diff --git a/contracts/staking/Staking.sol b/contracts/staking/Staking.sol index 3e207cbbc..e40449bee 100644 --- a/contracts/staking/Staking.sol +++ b/contracts/staking/Staking.sol @@ -134,7 +134,7 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking { * An amount of `tokens` get unallocated from `subgraphDeploymentID`. * The `effectiveAllocation` are the tokens allocated from creation to closing. * This event also emits the POI (proof of indexing) submitted by the indexer. - * `isDelegator` is true if the sender was one of the indexer's delegators. + * `isPublic` is true if the sender was someone other than the indexer. */ event AllocationClosed( address indexed indexer, @@ -145,7 +145,7 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking { uint256 effectiveAllocation, address sender, bytes32 poi, - bool isDelegator + bool isPublic ); /** @@ -1176,9 +1176,7 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking { // Indexer or operator can close an allocation // Delegators are also allowed but only after maxAllocationEpochs passed bool isIndexer = _isAuth(alloc.indexer); - if (epochs > maxAllocationEpochs) { - require(isIndexer || isDelegator(alloc.indexer, msg.sender), "!auth-or-del"); - } else { + if (epochs <= maxAllocationEpochs) { require(isIndexer, "!auth"); } diff --git a/test/lib/testHelpers.ts b/test/lib/testHelpers.ts index 7fd322719..945e0ac37 100644 --- a/test/lib/testHelpers.ts +++ b/test/lib/testHelpers.ts @@ -84,6 +84,12 @@ export const advanceToNextEpoch = async (epochManager: EpochManager): Promise => { + for (let i = 0; i < n + 1; i++) { + await advanceToNextEpoch(epochManager) + } +} + export const evmSnapshot = async (): Promise => provider().send('evm_snapshot', []) export const evmRevert = async (id: number): Promise => provider().send('evm_revert', [id]) diff --git a/test/staking/allocation.test.ts b/test/staking/allocation.test.ts index 962efa969..df6aae039 100644 --- a/test/staking/allocation.test.ts +++ b/test/staking/allocation.test.ts @@ -15,6 +15,7 @@ import { toBN, toGRT, Account, + advanceEpochs, } from '../lib/testHelpers' const { AddressZero, HashZero } = constants @@ -581,16 +582,14 @@ describe('Staking:Allocation', () => { await staking.connect(me.signer).closeAllocation(allocationID, poi) }) - it('should close an allocation (by delegator)', async function () { + it('should close an allocation (by public)', async function () { + // Reject to close if public address and under max allocation epochs + const tx1 = staking.connect(me.signer).closeAllocation(allocationID, poi) + await expect(tx1).revertedWith(' { // Setup await grt.connect(governor.signer).mint(me.address, toGRT('1')) await grt.connect(me.signer).approve(staking.address, toGRT('1')) - await staking.connect(me.signer).delegate(indexer.address, toGRT('1')) - // Should close by delegator + // Should close by public const tx = staking.connect(me.signer).closeAllocation(allocationID, poi) await expect(tx) .emit(staking, 'AllocationClosed')