Skip to content

Commit 5248888

Browse files
committed
staking: Rename delegationCapacity to delegationRatio
1 parent 0c44328 commit 5248888

File tree

7 files changed

+29
-27
lines changed

7 files changed

+29
-27
lines changed

cli/commands/protocol/get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const gettersList = {
1515
'staking-thawing-period': { contract: 'Staking', name: 'thawingPeriod' },
1616
'staking-dispute-epochs': { contract: 'Staking', name: 'channelDisputeEpochs' },
1717
'staking-max-allocation-epochs': { contract: 'Staking', name: 'maxAllocationEpochs' },
18-
'staking-delegation-capacity': { contract: 'Staking', name: 'delegationCapacity' },
18+
'staking-delegation-ratio': { contract: 'Staking', name: 'delegationRatio' },
1919
'staking-delegation-parameters-cooldown': {
2020
contract: 'Staking',
2121
name: 'delegationParametersCooldown',

cli/commands/protocol/set.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const settersList = {
1515
'staking-dispute-epochs': { contract: 'Staking', name: 'setChannelDisputeEpochs' },
1616
'staking-max-allocation-epochs': { contract: 'Staking', name: 'setMaxAllocationEpochs' },
1717
'staking-protocol-percentage': { contract: 'Staking', name: 'setProtocolPercentage' },
18-
'staking-delegation-capacity': { contract: 'Staking', name: 'setDelegationCapacity' },
18+
'staking-delegation-ratio': { contract: 'Staking', name: 'setDelegationRatio' },
1919
'staking-delegation-parameters-cooldown': {
2020
contract: 'Staking',
2121
name: 'setDelegationParametersCooldown',

contracts/staking/IStaking.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ interface IStaking {
6969

7070
function setRebateRatio(uint32 _alphaNumerator, uint32 _alphaDenominator) external;
7171

72-
function setDelegationCapacity(uint32 _delegationCapacity) external;
72+
function setDelegationRatio(uint32 _delegationRatio) external;
7373

7474
function setDelegationParameters(
7575
uint32 _indexingRewardCut,

contracts/staking/Staking.sol

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,14 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
277277
}
278278

279279
/**
280-
* @dev Set the delegation capacity multiplier.
281-
* @param _delegationCapacity Delegation capacity multiplier
282-
*/
283-
function setDelegationCapacity(uint32 _delegationCapacity) external override onlyGovernor {
284-
delegationCapacity = _delegationCapacity;
285-
emit ParameterUpdated("delegationCapacity");
280+
* @dev Set the delegation ratio.
281+
* If set to 10 it means the indexer can use up to 10x the indexer staked amount
282+
* from their delegated tokens
283+
* @param _delegationRatio Delegation capacity multiplier
284+
*/
285+
function setDelegationRatio(uint32 _delegationRatio) external override onlyGovernor {
286+
delegationRatio = _delegationRatio;
287+
emit ParameterUpdated("delegationRatio");
286288
}
287289

288290
/**
@@ -466,7 +468,7 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
466468
Stakes.Indexer memory indexerStake = stakes[_indexer];
467469
DelegationPool memory pool = delegationPools[_indexer];
468470

469-
uint256 tokensDelegatedMax = indexerStake.tokensStaked.mul(uint256(delegationCapacity));
471+
uint256 tokensDelegatedMax = indexerStake.tokensStaked.mul(uint256(delegationRatio));
470472
uint256 tokensDelegated = (pool.tokens < tokensDelegatedMax)
471473
? pool.tokens
472474
: tokensDelegatedMax;
@@ -478,7 +480,7 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
478480
// This means the indexer doesn't have available capacity to create new allocations.
479481
// We can reach this state when the indexer has funds allocated and then any
480482
// of these conditions happen:
481-
// - The delegationCapacity ratio is reduced.
483+
// - The delegationRatio ratio is reduced.
482484
// - The indexer stake is slashed.
483485
// - A delegator removes enough stake.
484486
if (tokensUsed > tokensCapacity) {

contracts/staking/StakingStorage.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ contract StakingV1Storage is Managed {
4949

5050
// -- Delegation --
5151

52-
// Set the delegation capacity multiplier
53-
// If delegation capacity is 100 GRT, and an Indexer has staked 5 GRT,
54-
// then they can accept 500 GRT as delegated stake
55-
uint32 public delegationCapacity;
52+
// Set the delegation capacity multiplier defined by the delegation ratio
53+
// If delegation ratio is 100, and an Indexer has staked 5 GRT,
54+
// then they can use up to 500 GRT from the delegated stake
55+
uint32 public delegationRatio;
5656

5757
// Time in blocks an indexer needs to wait to change delegation parameters
5858
uint32 public delegationParametersCooldown;

graph.config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ contracts:
7676
maxAllocationEpochs: 24 # Based on epoch length this is ~1 day (in epochs)
7777
- fn: "setThawingPeriod"
7878
thawingPeriod: 275 # ~1 hour (in blocks)
79-
- fn: "setDelegationCapacity"
80-
delegationCapacity: 1 # 100% (multiplier)
79+
- fn: "setDelegationRatio"
80+
delegationRatio: 1 # 100% (multiplier)
8181
- fn: "setProtocolPercentage"
8282
protocolPercentage: 10000 # 1% (in basis points)
8383
- fn: "setRebateRatio"

test/staking/delegation.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,16 @@ describe('Staking::Delegation', () => {
192192
})
193193

194194
describe('configuration', function () {
195-
describe('delegationCapacity', function () {
196-
const delegationCapacity = 5
195+
describe('delegationRatio', function () {
196+
const delegationRatio = 5
197197

198-
it('should set `delegationCapacity`', async function () {
199-
await staking.connect(governor.signer).setDelegationCapacity(delegationCapacity)
200-
expect(await staking.delegationCapacity()).eq(delegationCapacity)
198+
it('should set `delegationRatio`', async function () {
199+
await staking.connect(governor.signer).setDelegationRatio(delegationRatio)
200+
expect(await staking.delegationRatio()).eq(delegationRatio)
201201
})
202202

203-
it('reject set `delegationCapacity` if not allowed', async function () {
204-
const tx = staking.connect(me.signer).setDelegationCapacity(delegationCapacity)
203+
it('reject set `delegationRatio` if not allowed', async function () {
204+
const tx = staking.connect(me.signer).setDelegationRatio(delegationRatio)
205205
await expect(tx).revertedWith('Caller must be Controller governor')
206206
})
207207
})
@@ -438,7 +438,7 @@ describe('Staking::Delegation', () => {
438438

439439
it('revert allocate when capacity is not enough', async function () {
440440
// 1:2 delegation capacity
441-
await staking.connect(governor.signer).setDelegationCapacity(2)
441+
await staking.connect(governor.signer).setDelegationRatio(2)
442442

443443
// Delegate
444444
await staking.connect(delegator.signer).delegate(indexer.address, tokensToDelegate)
@@ -452,7 +452,7 @@ describe('Staking::Delegation', () => {
452452

453453
it('should allocate using full delegation capacity', async function () {
454454
// 1:10 delegation capacity
455-
await staking.connect(governor.signer).setDelegationCapacity(10)
455+
await staking.connect(governor.signer).setDelegationRatio(10)
456456

457457
// Delegate
458458
await staking.connect(delegator.signer).delegate(indexer.address, tokensToDelegate)
@@ -469,7 +469,7 @@ describe('Staking::Delegation', () => {
469469

470470
it('should send delegation cut of query fees to delegation pool', async function () {
471471
// 1:10 delegation capacity
472-
await staking.connect(governor.signer).setDelegationCapacity(10)
472+
await staking.connect(governor.signer).setDelegationRatio(10)
473473

474474
// Set delegation rules for the indexer
475475
const indexingRewardCut = toBN('800000') // indexer keep 80%

0 commit comments

Comments
 (0)