Skip to content

Commit 29ffe15

Browse files
authored
staking: make events more friendly for UIs to use the data (#184)
1 parent 2e15da9 commit 29ffe15

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

contracts/Staking.sol

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,50 @@ contract Staking is Governed {
6868

6969
// -- Events --
7070

71-
event StakeUpdate(address indexed indexNode, uint256 tokens, uint256 total);
71+
/**
72+
* @dev Emitted when `indexNode` deposited `tokens` amount as stake.
73+
*/
74+
event StakeDeposited(address indexed indexNode, uint256 tokens);
75+
76+
/**
77+
* @dev Emitted when `indexNode` unstaked and locked `tokens` amount `until` block.
78+
*/
7279
event StakeLocked(address indexed indexNode, uint256 tokens, uint256 until);
7380

74-
event AllocationUpdated(
81+
/**
82+
* @dev Emitted when `indexNode` was slashed for a total of `tokens` amount.
83+
* Tracks `reward` amount of tokens given to `beneficiary`.
84+
*/
85+
event StakeSlashed(
86+
address indexed indexNode,
87+
uint256 tokens,
88+
uint256 reward,
89+
address beneficiary
90+
);
91+
92+
/**
93+
* @dev Emitted when `indexNode` withdrew `tokens` amount from the stake.
94+
*/
95+
event StakeWithdrawn(address indexed indexNode, uint256 tokens);
96+
97+
/**
98+
* @dev Emitted when `indexNode` allocated `tokens` amount to `subgraphID`
99+
* during `epoch` and registered `channelID` as payment channel.
100+
*/
101+
event AllocationCreated(
75102
address indexed indexNode,
76103
bytes32 indexed subgraphID,
77104
uint256 epoch,
78105
uint256 tokens,
79106
address channelID
80107
);
81-
// TODO: consider adding curation reward
108+
109+
/**
110+
* @dev Emitted when `indexNode` settled an allocation of `tokens` amount to `subgraphID`
111+
* during `epoch` using `channelID` as payment channel.
112+
*
113+
* NOTE: `from` tracks the multisig contract from where it was settled.
114+
*/
82115
event AllocationSettled(
83116
address indexed indexNode,
84117
bytes32 indexed subgraphID,
@@ -88,6 +121,11 @@ contract Staking is Governed {
88121
address from
89122
);
90123

124+
/**
125+
* @dev Emitted when `indexNode` claimed a rebate on `subgraphID` during `epoch`
126+
* related to the `forEpoch` rebate pool.
127+
* The rebate is equivalent to `tokens` amount.
128+
*/
91129
event RebateClaimed(
92130
address indexed indexNode,
93131
bytes32 indexed subgraphID,
@@ -96,6 +134,9 @@ contract Staking is Governed {
96134
uint256 tokens
97135
);
98136

137+
/**
138+
* @dev Emitted when `caller` set `slasher` address as `enabled` to slash stakes.
139+
*/
99140
event SlasherUpdate(address indexed caller, address indexed slasher, bool enabled);
100141

101142
modifier onlySlasher {
@@ -251,7 +292,7 @@ contract Staking is Governed {
251292
);
252293
}
253294

254-
emit StakeUpdate(_indexNode, tokensToSlash, stake.tokensIndexNode);
295+
emit StakeSlashed(_indexNode, tokensToBurn, _reward, _beneficiary);
255296
}
256297

257298
/**
@@ -309,7 +350,7 @@ contract Staking is Governed {
309350
alloc.createdAtEpoch = epochManager.currentEpoch();
310351
channels[_channelID] = Channel(indexNode, _subgraphID);
311352

312-
emit AllocationUpdated(
353+
emit AllocationCreated(
313354
indexNode,
314355
_subgraphID,
315356
alloc.createdAtEpoch,
@@ -349,7 +390,7 @@ contract Staking is Governed {
349390

350391
require(token.transfer(indexNode, tokensToWithdraw), "Staking: cannot transfer tokens");
351392

352-
emit StakeUpdate(indexNode, tokensToWithdraw, stake.tokensIndexNode);
393+
emit StakeWithdrawn(indexNode, tokensToWithdraw);
353394
}
354395

355396
/**
@@ -402,7 +443,7 @@ contract Staking is Governed {
402443
Stakes.IndexNode storage stake = stakes[_indexNode];
403444
stake.deposit(_tokens);
404445

405-
emit StakeUpdate(_indexNode, _tokens, stake.tokensIndexNode);
446+
emit StakeDeposited(_indexNode, _tokens);
406447
}
407448

408449
/**

test/staking/general.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,9 @@ contract('Staking', ([me, other, governor, indexNode, channelOwner]) => {
200200
const { tx } = await this.stake(indexNodeStake)
201201
const tokens2 = await this.staking.getIndexNodeStakeTokens(indexNode)
202202
expect(tokens2).to.be.bignumber.eq(indexNodeStake.add(indexNodeStake))
203-
expectEvent.inTransaction(tx, this.staking.constructor, 'StakeUpdate', {
203+
expectEvent.inTransaction(tx, this.staking.constructor, 'StakeDeposited', {
204204
indexNode: indexNode,
205205
tokens: indexNodeStake,
206-
total: tokens2,
207206
})
208207
})
209208

@@ -314,7 +313,7 @@ contract('Staking', ([me, other, governor, indexNode, channelOwner]) => {
314313
context('when subgraph NOT allocated', function() {
315314
it('should allocate to subgraph', async function() {
316315
const { logs } = await this.allocate(this.indexNodeStake)
317-
expectEvent.inLogs(logs, 'AllocationUpdated', {
316+
expectEvent.inLogs(logs, 'AllocationCreated', {
318317
indexNode: indexNode,
319318
subgraphID: this.subgraphId,
320319
epoch: await this.epochManager.currentEpoch(),

0 commit comments

Comments
 (0)