Skip to content

Commit 0f5c5bf

Browse files
authored
governance: emit parameter updated (#196)
* governance: emit event on each protocol parameter update * governance: update parameter name * staking: add rebate and curation fees to settle event
1 parent 5e1295c commit 0f5c5bf

File tree

9 files changed

+49
-20
lines changed

9 files changed

+49
-20
lines changed

contracts/Curation.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ contract Curation is Governed, BancorFormula {
124124
);
125125

126126
defaultReserveRatio = _defaultReserveRatio;
127+
emit ParameterUpdated("defaultReserveRatio");
127128
}
128129

129130
/**
@@ -133,6 +134,7 @@ contract Curation is Governed, BancorFormula {
133134
*/
134135
function setStaking(address _staking) external onlyGovernor {
135136
staking = _staking;
137+
emit ParameterUpdated("staking");
136138
}
137139

138140
/**
@@ -151,6 +153,7 @@ contract Curation is Governed, BancorFormula {
151153
function _setMinimumCurationStake(uint256 _minimumCurationStake) private {
152154
require(_minimumCurationStake > 0, "Minimum curation stake cannot be 0");
153155
minimumCurationStake = _minimumCurationStake;
156+
emit ParameterUpdated("minimumCurationStake");
154157
}
155158

156159
/**

contracts/DisputeManager.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ contract DisputeManager is Governed {
238238
*/
239239
function setArbitrator(address _arbitrator) external onlyGovernor {
240240
arbitrator = _arbitrator;
241+
emit ParameterUpdated("arbitrator");
241242
}
242243

243244
/**
@@ -247,6 +248,7 @@ contract DisputeManager is Governed {
247248
*/
248249
function setMinimumDeposit(uint256 _minimumDeposit) external onlyGovernor {
249250
minimumDeposit = _minimumDeposit;
251+
emit ParameterUpdated("minimumDeposit");
250252
}
251253

252254
/**
@@ -258,6 +260,7 @@ contract DisputeManager is Governed {
258260
// Must be within 0% to 100% (inclusive)
259261
require(_percentage <= MAX_PPM, "Reward percentage must be below or equal to MAX_PPM");
260262
fishermanRewardPercentage = _percentage;
263+
emit ParameterUpdated("fishermanRewardPercentage");
261264
}
262265

263266
/**
@@ -268,6 +271,7 @@ contract DisputeManager is Governed {
268271
// Must be within 0% to 100% (inclusive)
269272
require(_percentage <= MAX_PPM, "Slashing percentage must be below or equal to MAX_PPM");
270273
slashingPercentage = _percentage;
274+
emit ParameterUpdated("slashingPercentage");
271275
}
272276

273277
/**
@@ -277,6 +281,7 @@ contract DisputeManager is Governed {
277281
*/
278282
function setStaking(Staking _staking) external onlyGovernor {
279283
staking = _staking;
284+
emit ParameterUpdated("staking");
280285
}
281286

282287
/**

contracts/Governed.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ contract Governed {
1111
address public governor;
1212

1313
event OwnershipTransferred(address indexed from, address indexed to);
14+
event ParameterUpdated(string param);
1415

1516
modifier onlyGovernor {
1617
require(msg.sender == governor, "Only Governor can call");

contracts/Staking.sol

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ contract Staking is Governed {
4343
// Need to pass this period to claim fees in rebate pool
4444
uint256 public channelDisputeEpochs;
4545

46-
// Need to pass this period for delegators to settle
47-
uint256 public maxSettlementEpochs;
46+
// Maximum allocation time
47+
uint256 public maxAllocationEpochs;
4848

4949
// Time in blocks to unstake
5050
uint256 public thawingPeriod; // in blocks
@@ -121,7 +121,9 @@ contract Staking is Governed {
121121
uint256 epoch,
122122
uint256 tokens,
123123
address channelID,
124-
address from
124+
address from,
125+
uint256 curationFees,
126+
uint256 rebateFees
125127
);
126128

127129
/**
@@ -173,6 +175,7 @@ contract Staking is Governed {
173175
*/
174176
function setCuration(Curation _curation) external onlyGovernor {
175177
curation = _curation;
178+
emit ParameterUpdated("curation");
176179
}
177180

178181
/**
@@ -183,6 +186,7 @@ contract Staking is Governed {
183186
// Must be within 0% to 100% (inclusive)
184187
require(_percentage <= MAX_PPM, "Curation percentage must be below or equal to MAX_PPM");
185188
curationPercentage = _percentage;
189+
emit ParameterUpdated("curationPercentage");
186190
}
187191

188192
/**
@@ -191,14 +195,16 @@ contract Staking is Governed {
191195
*/
192196
function setChannelDisputeEpochs(uint256 _channelDisputeEpochs) external onlyGovernor {
193197
channelDisputeEpochs = _channelDisputeEpochs;
198+
emit ParameterUpdated("channelDisputeEpochs");
194199
}
195200

196201
/**
197-
* @dev Set the max settlement time allowed for indexers
198-
* @param _maxSettlementEpochs Settlement duration limit in epochs
202+
* @dev Set the max allocation time allowed for indexers
203+
* @param _maxAllocationEpochs Allocation duration limit in epochs
199204
*/
200-
function setMaxSettlementEpochs(uint256 _maxSettlementEpochs) external onlyGovernor {
201-
maxSettlementEpochs = _maxSettlementEpochs;
205+
function setMaxAllocationEpochs(uint256 _maxAllocationEpochs) external onlyGovernor {
206+
maxAllocationEpochs = _maxAllocationEpochs;
207+
emit ParameterUpdated("maxAllocationEpochs");
202208
}
203209

204210
/**
@@ -217,6 +223,7 @@ contract Staking is Governed {
217223
*/
218224
function setThawingPeriod(uint256 _thawingPeriod) external onlyGovernor {
219225
thawingPeriod = _thawingPeriod;
226+
emit ParameterUpdated("thawingPeriod");
220227
}
221228

222229
/**
@@ -313,6 +320,10 @@ contract Staking is Governed {
313320
emit StakeSlashed(_indexer, _tokens, _reward, _beneficiary);
314321
}
315322

323+
/**
324+
* @dev Deposit tokens on the indexer stake
325+
* @param _tokens Amount of tokens to stake
326+
*/
316327
function stake(uint256 _tokens) external {
317328
address indexer = msg.sender;
318329

@@ -523,7 +534,7 @@ contract Staking is Governed {
523534
indexer,
524535
subgraphID,
525536
rebateFees,
526-
alloc.getTokensEffectiveAllocation(epochs, maxSettlementEpochs)
537+
alloc.getTokensEffectiveAllocation(epochs, maxAllocationEpochs)
527538
);
528539

529540
// Close channel
@@ -541,7 +552,16 @@ contract Staking is Governed {
541552
curation.collect(subgraphID, curationFees);
542553
}
543554

544-
emit AllocationSettled(indexer, subgraphID, currentEpoch, _tokens, _channelID, _from);
555+
emit AllocationSettled(
556+
indexer,
557+
subgraphID,
558+
currentEpoch,
559+
_tokens,
560+
_channelID,
561+
_from,
562+
rebateFees,
563+
curationFees
564+
);
545565
}
546566

547567
/**

migrations/2_deploy_contracts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ module.exports = async (deployer, network, accounts) => {
6060
log(' Configuring Contracts')
6161
log(' ---------------------')
6262
await executeAndLog(
63-
staking.setMaxSettlementEpochs(config.staking.maxSettlementEpochs),
64-
' > Staking -> Set maxSettlementEpochs: ',
63+
staking.setMaxAllocationEpochs(config.staking.maxAllocationEpochs),
64+
' > Staking -> Set maxAllocationEpochs: ',
6565
)
6666
await executeAndLog(
6767
staking.setThawingPeriod(config.staking.thawingPeriod),

migrations/deploy.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = {
1919
},
2020
staking: {
2121
channelDisputeEpochs: 1,
22-
maxSettlementEpochs: 5,
22+
maxAllocationEpochs: 5,
2323
thawingPeriod: 20, // in blocks
2424
},
2525
token: {

test/lib/deployment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function deployServiceRegistry(owner) {
4747
async function deployStakingContract(owner, graphToken, epochManager, curation, params) {
4848
const contract = await Staking.new(owner, graphToken, epochManager, curation, params)
4949
await contract.setChannelDisputeEpochs(defaults.staking.channelDisputeEpochs, { from: owner })
50-
await contract.setMaxSettlementEpochs(defaults.staking.maxSettlementEpochs, { from: owner })
50+
await contract.setMaxAllocationEpochs(defaults.staking.maxAllocationEpochs, { from: owner })
5151
await contract.setThawingPeriod(defaults.staking.thawingPeriod, { from: owner })
5252
return contract
5353
}

test/lib/testHelpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ module.exports = {
286286
},
287287
staking: {
288288
channelDisputeEpochs: 1,
289-
maxSettlementEpochs: 5,
289+
maxAllocationEpochs: 5,
290290
thawingPeriod: 20, // in blocks
291291
},
292292
token: {

test/staking/general.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,17 @@ contract('Staking', ([me, other, governor, indexer, slasher, fisherman]) => {
130130
})
131131
})
132132

133-
describe('maxSettlementEpochs', function() {
134-
it('should set `maxSettlementEpochs`', async function() {
133+
describe('maxAllocationEpochs', function() {
134+
it('should set `maxAllocationEpochs`', async function() {
135135
const newValue = new BN(5)
136-
await this.staking.setMaxSettlementEpochs(newValue, { from: governor })
137-
expect(await this.staking.maxSettlementEpochs()).to.be.bignumber.eq(newValue)
136+
await this.staking.setMaxAllocationEpochs(newValue, { from: governor })
137+
expect(await this.staking.maxAllocationEpochs()).to.be.bignumber.eq(newValue)
138138
})
139139

140-
it('reject set `maxSettlementEpochs` if not allowed', async function() {
140+
it('reject set `maxAllocationEpochs` if not allowed', async function() {
141141
const newValue = new BN(5)
142142
await expectRevert(
143-
this.staking.setMaxSettlementEpochs(newValue, { from: other }),
143+
this.staking.setMaxAllocationEpochs(newValue, { from: other }),
144144
'Only Governor can call',
145145
)
146146
})

0 commit comments

Comments
 (0)