Skip to content

Commit 190e625

Browse files
committed
feat: remove/deprecate delegation parameters cooldown
1 parent 59240bd commit 190e625

File tree

10 files changed

+24
-132
lines changed

10 files changed

+24
-132
lines changed

cli/commands/contracts/staking.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ export const setDelegationParameters = async (
9797
const staking = cli.contracts.Staking
9898

9999
logger.info(`Setting the following delegation parameters for indexer ${cli.walletAddress}
100-
indexingRewardCut = ${indexingRewardCut}
101-
queryFeeCut = ${queryFeeCut}
102-
cooldownBlocks = ${cooldownBlocks}
100+
indexingRewardCut = ${indexingRewardCut}
101+
queryFeeCut = ${queryFeeCut}
102+
cooldownBlocks (deprecated) = ${cooldownBlocks}
103103
`)
104104
await sendTransaction(cli.wallet, staking, 'setDelegationParameters', [
105105
indexingRewardCut,
@@ -305,7 +305,7 @@ export const stakingCommand = {
305305
demandOption: true,
306306
})
307307
.option('cooldownBlocks', {
308-
description: 'Period that need to pass to update delegation parameters',
308+
description: 'Period that need to pass to update delegation parameters (deprecated)',
309309
type: 'number',
310310
})
311311
},

contracts/l2/staking/L2Staking.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ contract L2Staking is Staking, IL2StakingBase {
9999

100100
// Initialize the delegation pool the first time
101101
if (__delegationPools[_indexer].updatedAtBlock == 0) {
102-
_setDelegationParameters(_indexer, MAX_PPM, MAX_PPM, __delegationParametersCooldown);
102+
_setDelegationParameters(_indexer, MAX_PPM, MAX_PPM);
103103
}
104104

105105
emit StakeDeposited(_indexer, _amount);

contracts/staking/IStakingBase.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ interface IStakingBase is IStakingData {
9090
address indexed indexer,
9191
uint32 indexingRewardCut,
9292
uint32 queryFeeCut,
93-
uint32 cooldownBlocks
93+
uint32 cooldownBlocksDeprecated
9494
);
9595

9696
/**
@@ -274,12 +274,11 @@ interface IStakingBase is IStakingData {
274274
* @notice Set the delegation parameters for the caller.
275275
* @param _indexingRewardCut Percentage of indexing rewards left for the indexer
276276
* @param _queryFeeCut Percentage of query fees left for the indexer
277-
* @param _cooldownBlocks Period that need to pass to update delegation parameters
278277
*/
279278
function setDelegationParameters(
280279
uint32 _indexingRewardCut,
281280
uint32 _queryFeeCut,
282-
uint32 _cooldownBlocks
281+
uint32 // _cooldownBlocks, deprecated
283282
) external;
284283

285284
/**

contracts/staking/IStakingData.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface IStakingData {
2929
* @dev Delegation pool information. One per indexer.
3030
*/
3131
struct DelegationPool {
32-
uint32 cooldownBlocks; // Blocks to wait before updating parameters
32+
uint32 cooldownBlocksDeprecated; // Blocks to wait before updating parameters (deprecated)
3333
uint32 indexingRewardCut; // in PPM
3434
uint32 queryFeeCut; // in PPM
3535
uint256 updatedAtBlock; // Block when the pool was last updated

contracts/staking/IStakingExtension.sol

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface IStakingExtension is IStakingData {
2020
* the original DelegationPool in IStakingData.sol contains a nested mapping.
2121
*/
2222
struct DelegationPoolReturn {
23-
uint32 cooldownBlocks; // Blocks to wait before updating parameters
23+
uint32 cooldownBlocksDeprecated; // Blocks to wait before updating parameters (deprecated)
2424
uint32 indexingRewardCut; // in PPM
2525
uint32 queryFeeCut; // in PPM
2626
uint256 updatedAtBlock; // Block when the pool was last updated
@@ -85,14 +85,6 @@ interface IStakingExtension is IStakingData {
8585
*/
8686
function setDelegationRatio(uint32 _delegationRatio) external;
8787

88-
/**
89-
* @notice Set the minimum time in blocks an indexer needs to wait to change delegation parameters.
90-
* Indexers can set a custom amount time for their own cooldown, but it must be greater than this.
91-
* @dev This function is only callable by the governor
92-
* @param _blocks Number of blocks to set the delegation parameters cooldown period
93-
*/
94-
function setDelegationParametersCooldown(uint32 _blocks) external;
95-
9688
/**
9789
* @notice Set the time, in epochs, a Delegator needs to wait to withdraw tokens after undelegating.
9890
* @dev This function is only callable by the governor
@@ -191,13 +183,6 @@ interface IStakingExtension is IStakingData {
191183
*/
192184
function delegationRatio() external view returns (uint32);
193185

194-
/**
195-
* @notice Getter for delegationParametersCooldown:
196-
* Minimum time in blocks an indexer needs to wait to change delegation parameters
197-
* @return Delegation parameters cooldown in blocks
198-
*/
199-
function delegationParametersCooldown() external view returns (uint32);
200-
201186
/**
202187
* @notice Getter for delegationUnbondingPeriod:
203188
* Time in epochs a delegator needs to wait to withdraw delegated stake

contracts/staking/Staking.sol

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -554,14 +554,13 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M
554554
* @notice Set the delegation parameters for the caller.
555555
* @param _indexingRewardCut Percentage of indexing rewards left for the indexer
556556
* @param _queryFeeCut Percentage of query fees left for the indexer
557-
* @param _cooldownBlocks Period that need to pass to update delegation parameters
558557
*/
559558
function setDelegationParameters(
560559
uint32 _indexingRewardCut,
561560
uint32 _queryFeeCut,
562-
uint32 _cooldownBlocks
561+
uint32 // _cooldownBlocks, deprecated
563562
) public override {
564-
_setDelegationParameters(msg.sender, _indexingRewardCut, _queryFeeCut, _cooldownBlocks);
563+
_setDelegationParameters(msg.sender, _indexingRewardCut, _queryFeeCut);
565564
}
566565

567566
/**
@@ -671,41 +670,24 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M
671670
* @param _indexer Indexer to set delegation parameters
672671
* @param _indexingRewardCut Percentage of indexing rewards left for delegators
673672
* @param _queryFeeCut Percentage of query fees left for delegators
674-
* @param _cooldownBlocks Period that need to pass to update delegation parameters
675673
*/
676674
function _setDelegationParameters(
677675
address _indexer,
678676
uint32 _indexingRewardCut,
679-
uint32 _queryFeeCut,
680-
uint32 _cooldownBlocks
677+
uint32 _queryFeeCut
681678
) internal {
682679
// Incentives must be within bounds
683680
require(_queryFeeCut <= MAX_PPM, ">queryFeeCut");
684681
require(_indexingRewardCut <= MAX_PPM, ">indexingRewardCut");
685682

686-
// Cooldown period set by indexer cannot be below protocol global setting
687-
require(_cooldownBlocks >= __delegationParametersCooldown, "<cooldown");
688-
689-
// Verify the cooldown period passed
690683
DelegationPool storage pool = __delegationPools[_indexer];
691-
require(
692-
pool.updatedAtBlock == 0 ||
693-
pool.updatedAtBlock.add(uint256(pool.cooldownBlocks)) <= block.number,
694-
"!cooldown"
695-
);
696684

697685
// Update delegation params
698686
pool.indexingRewardCut = _indexingRewardCut;
699687
pool.queryFeeCut = _queryFeeCut;
700-
pool.cooldownBlocks = _cooldownBlocks;
701688
pool.updatedAtBlock = block.number;
702689

703-
emit DelegationParametersUpdated(
704-
_indexer,
705-
_indexingRewardCut,
706-
_queryFeeCut,
707-
_cooldownBlocks
708-
);
690+
emit DelegationParametersUpdated(_indexer, _indexingRewardCut, _queryFeeCut, 0);
709691
}
710692

711693
/**
@@ -728,7 +710,7 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M
728710

729711
// Initialize the delegation pool the first time
730712
if (__delegationPools[_indexer].updatedAtBlock == 0) {
731-
_setDelegationParameters(_indexer, MAX_PPM, MAX_PPM, __delegationParametersCooldown);
713+
_setDelegationParameters(_indexer, MAX_PPM, MAX_PPM);
732714
}
733715

734716
emit StakeDeposited(_indexer, _tokens);

contracts/staking/StakingExtension.sol

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,16 @@ contract StakingExtension is StakingV4Storage, GraphUpgradeable, IStakingExtensi
4141
* initialize() function, so it uses the same access control check to ensure it is
4242
* being called by the Staking implementation as part of the proxy upgrade process.
4343
* @param _delegationUnbondingPeriod Delegation unbonding period in blocks
44-
* @param _cooldownBlocks Minimum time between changes to delegation parameters, in blocks
4544
* @param _delegationRatio Delegation capacity multiplier (e.g. 10 means 10x the indexer stake)
4645
* @param _delegationTaxPercentage Percentage of delegated tokens to burn as delegation tax, expressed in parts per million
4746
*/
4847
function initialize(
4948
uint32 _delegationUnbondingPeriod,
50-
uint32 _cooldownBlocks,
49+
uint32, //_cooldownBlocks, deprecated
5150
uint32 _delegationRatio,
5251
uint32 _delegationTaxPercentage
5352
) external onlyImpl {
5453
_setDelegationUnbondingPeriod(_delegationUnbondingPeriod);
55-
_setDelegationParametersCooldown(_cooldownBlocks);
5654
_setDelegationRatio(_delegationRatio);
5755
_setDelegationTaxPercentage(_delegationTaxPercentage);
5856
}
@@ -77,16 +75,6 @@ contract StakingExtension is StakingV4Storage, GraphUpgradeable, IStakingExtensi
7775
_setDelegationRatio(_delegationRatio);
7876
}
7977

80-
/**
81-
* @notice Set the minimum time in blocks an indexer needs to wait to change delegation parameters.
82-
* Indexers can set a custom amount time for their own cooldown, but it must be greater than this.
83-
* @dev This function is only callable by the governor
84-
* @param _blocks Number of blocks to set the delegation parameters cooldown period
85-
*/
86-
function setDelegationParametersCooldown(uint32 _blocks) external override onlyGovernor {
87-
_setDelegationParametersCooldown(_blocks);
88-
}
89-
9078
/**
9179
* @notice Set the time, in epochs, a Delegator needs to wait to withdraw tokens after undelegating.
9280
* @dev This function is only callable by the governor
@@ -240,15 +228,6 @@ contract StakingExtension is StakingV4Storage, GraphUpgradeable, IStakingExtensi
240228
return __delegationRatio;
241229
}
242230

243-
/**
244-
* @notice Getter for delegationParametersCooldown:
245-
* Minimum time in blocks an indexer needs to wait to change delegation parameters
246-
* @return Delegation parameters cooldown in blocks
247-
*/
248-
function delegationParametersCooldown() external view override returns (uint32) {
249-
return __delegationParametersCooldown;
250-
}
251-
252231
/**
253232
* @notice Getter for delegationUnbondingPeriod:
254233
* Time in epochs a delegator needs to wait to withdraw delegated stake
@@ -282,7 +261,7 @@ contract StakingExtension is StakingV4Storage, GraphUpgradeable, IStakingExtensi
282261
DelegationPool storage pool = __delegationPools[_indexer];
283262
return
284263
DelegationPoolReturn(
285-
pool.cooldownBlocks, // Blocks to wait before updating parameters
264+
0, // Blocks to wait before updating parameters (deprecated)
286265
pool.indexingRewardCut, // in PPM
287266
pool.queryFeeCut, // in PPM
288267
pool.updatedAtBlock, // Block when the pool was last updated
@@ -508,15 +487,6 @@ contract StakingExtension is StakingV4Storage, GraphUpgradeable, IStakingExtensi
508487
emit ParameterUpdated("delegationRatio");
509488
}
510489

511-
/**
512-
* @dev Internal: Set the time in blocks an indexer needs to wait to change delegation parameters.
513-
* @param _blocks Number of blocks to set the delegation parameters cooldown period
514-
*/
515-
function _setDelegationParametersCooldown(uint32 _blocks) private {
516-
__delegationParametersCooldown = _blocks;
517-
emit ParameterUpdated("delegationParametersCooldown");
518-
}
519-
520490
/**
521491
* @dev Internal: Set the period for undelegation of stake from indexer.
522492
* @param _delegationUnbondingPeriod Period in epochs to wait for token withdrawals after undelegating

contracts/staking/StakingStorage.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ contract StakingV1Storage is Managed {
6969
/// then they can use up to 500 GRT from the delegated stake
7070
uint32 internal __delegationRatio;
7171

72-
/// @dev Time in blocks an indexer needs to wait to change delegation parameters
73-
uint32 internal __delegationParametersCooldown;
72+
/// @dev Time in blocks an indexer needs to wait to change delegation parameters (deprecated)
73+
uint32 internal __DEPRECATED_delegationParametersCooldown;
7474

7575
/// @dev Time in epochs a delegator needs to wait to withdraw delegated stake
7676
uint32 internal __delegationUnbondingPeriod; // in epochs

test/rewards/rewards.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ describe('Rewards', () => {
601601
.setDelegationParameters(
602602
delegationParams.indexingRewardCut,
603603
delegationParams.queryFeeCut,
604-
delegationParams.cooldownBlocks,
604+
0,
605605
)
606606

607607
// Delegate
@@ -793,7 +793,7 @@ describe('Rewards', () => {
793793
const delegationParams = {
794794
indexingRewardCut: toBN('823000'), // 82.30%
795795
queryFeeCut: toBN('80000'), // 8%
796-
cooldownBlocks: 5,
796+
cooldownBlocks: 0,
797797
}
798798
const tokensToDelegate = toGRT('2000')
799799

test/staking/delegation.test.ts

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -222,20 +222,6 @@ describe('Staking::Delegation', () => {
222222
})
223223
})
224224

225-
describe('delegationParametersCooldown', function () {
226-
const cooldown = 5
227-
228-
it('should set `delegationParametersCooldown`', async function () {
229-
await staking.connect(governor.signer).setDelegationParametersCooldown(cooldown)
230-
expect(await staking.delegationParametersCooldown()).eq(cooldown)
231-
})
232-
233-
it('reject set `delegationParametersCooldown` if not allowed', async function () {
234-
const tx = staking.connect(me.signer).setDelegationParametersCooldown(cooldown)
235-
await expect(tx).revertedWith('Only Controller governor')
236-
})
237-
})
238-
239225
describe('delegationTaxPercentage', function () {
240226
it('should set `delegationTaxPercentage`', async function () {
241227
for (const newValue of [toBN('0'), toBN('5'), MAX_PPM]) {
@@ -259,60 +245,34 @@ describe('Staking::Delegation', () => {
259245
describe('delegationParameters', function () {
260246
const indexingRewardCut = toBN('50000')
261247
const queryFeeCut = toBN('80000')
262-
const cooldownBlocks = 5
263-
264-
it('reject to set if under cooldown period', async function () {
265-
// Set parameters
266-
await staking
267-
.connect(indexer.signer)
268-
.setDelegationParameters(indexingRewardCut, queryFeeCut, cooldownBlocks)
269-
270-
// Try to set before cooldown period passed
271-
const tx = staking
272-
.connect(indexer.signer)
273-
.setDelegationParameters(indexingRewardCut, queryFeeCut, cooldownBlocks)
274-
await expect(tx).revertedWith('!cooldown')
275-
})
276-
277-
it('reject to set if cooldown below the global configuration', async function () {
278-
// Set global cooldown parameter
279-
await staking.connect(governor.signer).setDelegationParametersCooldown(cooldownBlocks)
280-
281-
// Try to set delegation cooldown below global cooldown parameter
282-
const tx = staking
283-
.connect(indexer.signer)
284-
.setDelegationParameters(indexingRewardCut, queryFeeCut, cooldownBlocks - 1)
285-
await expect(tx).revertedWith('<cooldown')
286-
})
287248

288249
it('reject to set parameters out of bound', async function () {
289250
// Indexing reward out of bounds
290251
const tx1 = staking
291252
.connect(indexer.signer)
292-
.setDelegationParameters(MAX_PPM.add('1'), queryFeeCut, cooldownBlocks)
253+
.setDelegationParameters(MAX_PPM.add('1'), queryFeeCut, 0)
293254
await expect(tx1).revertedWith('>indexingRewardCut')
294255

295256
// Query fee out of bounds
296257
const tx2 = staking
297258
.connect(indexer.signer)
298-
.setDelegationParameters(indexingRewardCut, MAX_PPM.add('1'), cooldownBlocks)
259+
.setDelegationParameters(indexingRewardCut, MAX_PPM.add('1'), 0)
299260
await expect(tx2).revertedWith('>queryFeeCut')
300261
})
301262

302263
it('should set parameters', async function () {
303264
// Set parameters
304265
const tx = staking
305266
.connect(indexer.signer)
306-
.setDelegationParameters(indexingRewardCut, queryFeeCut, cooldownBlocks)
267+
.setDelegationParameters(indexingRewardCut, queryFeeCut, 0)
307268
await expect(tx)
308269
.emit(staking, 'DelegationParametersUpdated')
309-
.withArgs(indexer.address, indexingRewardCut, queryFeeCut, cooldownBlocks)
270+
.withArgs(indexer.address, indexingRewardCut, queryFeeCut, 0)
310271

311272
// State updated
312273
const params = await staking.delegationPools(indexer.address)
313274
expect(params.indexingRewardCut).eq(indexingRewardCut)
314275
expect(params.queryFeeCut).eq(queryFeeCut)
315-
expect(params.cooldownBlocks).eq(cooldownBlocks)
316276
expect(params.updatedAtBlock).eq(await latestBlock())
317277
})
318278

@@ -321,7 +281,6 @@ describe('Staking::Delegation', () => {
321281
const beforeParams = await staking.delegationPools(indexer.address)
322282
expect(beforeParams.indexingRewardCut).eq(0)
323283
expect(beforeParams.queryFeeCut).eq(0)
324-
expect(beforeParams.cooldownBlocks).eq(0)
325284
expect(beforeParams.updatedAtBlock).eq(0)
326285

327286
// Indexer stake tokens
@@ -334,7 +293,6 @@ describe('Staking::Delegation', () => {
334293
const afterParams = await staking.delegationPools(indexer.address)
335294
expect(afterParams.indexingRewardCut).eq(MAX_PPM)
336295
expect(afterParams.queryFeeCut).eq(MAX_PPM)
337-
expect(afterParams.cooldownBlocks).eq(0)
338296
expect(afterParams.updatedAtBlock).eq(await latestBlock())
339297
})
340298

@@ -343,7 +301,6 @@ describe('Staking::Delegation', () => {
343301
const beforeParams = await staking.delegationPools(indexer.address)
344302
expect(beforeParams.indexingRewardCut).eq(0)
345303
expect(beforeParams.queryFeeCut).eq(0)
346-
expect(beforeParams.cooldownBlocks).eq(0)
347304
expect(beforeParams.updatedAtBlock).eq(0)
348305

349306
// Indexer stake tokens
@@ -356,7 +313,6 @@ describe('Staking::Delegation', () => {
356313
const afterParams = await staking.delegationPools(indexer.address)
357314
expect(afterParams.indexingRewardCut).eq(MAX_PPM)
358315
expect(afterParams.queryFeeCut).eq(MAX_PPM)
359-
expect(afterParams.cooldownBlocks).eq(0)
360316
expect(afterParams.updatedAtBlock).eq(await latestBlock())
361317
})
362318
})

0 commit comments

Comments
 (0)