Skip to content

Commit 9b77f32

Browse files
authored
Merge pull request #1935 from kleros/feat/add-stakeset-total
Adding the juror's total stake for all courts in the StakeSet event back in
2 parents 89c1bda + ba85c09 commit 9b77f32

File tree

14 files changed

+110
-102
lines changed

14 files changed

+110
-102
lines changed

contracts/src/arbitration/SortitionModuleBase.sol

+29-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,35 @@ abstract contract SortitionModuleBase is ISortitionModule, Initializable, UUPSPr
8181
// * Events * //
8282
// ************************************* //
8383

84-
event StakeSet(address indexed _address, uint256 _courtID, uint256 _amount);
84+
/// @notice Emitted when a juror stakes in a court.
85+
/// @param _address The address of the juror.
86+
/// @param _courtID The ID of the court.
87+
/// @param _amount The amount of tokens staked in the court.
88+
/// @param _amountAllCourts The amount of tokens staked in all courts.
89+
event StakeSet(address indexed _address, uint256 _courtID, uint256 _amount, uint256 _amountAllCourts);
90+
91+
/// @notice Emitted when a juror's stake is delayed and tokens are not transferred yet.
92+
/// @param _address The address of the juror.
93+
/// @param _courtID The ID of the court.
94+
/// @param _amount The amount of tokens staked in the court.
8595
event StakeDelayedNotTransferred(address indexed _address, uint256 _courtID, uint256 _amount);
86-
event StakeDelayedAlreadyTransferred(address indexed _address, uint256 _courtID, uint256 _amount);
96+
97+
/// @notice Emitted when a juror's stake is delayed and tokens are already deposited.
98+
/// @param _address The address of the juror.
99+
/// @param _courtID The ID of the court.
100+
/// @param _amount The amount of tokens staked in the court.
101+
event StakeDelayedAlreadyTransferredDeposited(address indexed _address, uint256 _courtID, uint256 _amount);
102+
103+
/// @notice Emitted when a juror's stake is delayed and tokens are already withdrawn.
104+
/// @param _address The address of the juror.
105+
/// @param _courtID The ID of the court.
106+
/// @param _amount The amount of tokens withdrawn.
87107
event StakeDelayedAlreadyTransferredWithdrawn(address indexed _address, uint96 indexed _courtID, uint256 _amount);
108+
109+
/// @notice Emitted when a juror's stake is locked.
110+
/// @param _address The address of the juror.
111+
/// @param _relativeAmount The amount of tokens locked.
112+
/// @param _unlock Whether the stake is locked or unlocked.
88113
event StakeLocked(address indexed _address, uint256 _relativeAmount, bool _unlock);
89114

90115
// ************************************* //
@@ -288,7 +313,7 @@ abstract contract SortitionModuleBase is ISortitionModule, Initializable, UUPSPr
288313
// PNK deposit: tokens are transferred now.
289314
delayedStake.alreadyTransferred = true;
290315
pnkDeposit = _increaseStake(juror, _courtID, _newStake, currentStake);
291-
emit StakeDelayedAlreadyTransferred(_account, _courtID, _newStake);
316+
emit StakeDelayedAlreadyTransferredDeposited(_account, _courtID, _newStake);
292317
} else {
293318
// PNK withdrawal: tokens are not transferred yet.
294319
emit StakeDelayedNotTransferred(_account, _courtID, _newStake);
@@ -318,7 +343,7 @@ abstract contract SortitionModuleBase is ISortitionModule, Initializable, UUPSPr
318343
(currenCourtID, , , , , , ) = core.courts(currenCourtID); // Get the parent court.
319344
}
320345
}
321-
emit StakeSet(_account, _courtID, _newStake);
346+
emit StakeSet(_account, _courtID, _newStake, juror.stakedPnk);
322347
return (pnkDeposit, pnkWithdrawal, StakingResult.Successful);
323348
}
324349

contracts/src/arbitration/university/SortitionModuleUniversity.sol

+12-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,17 @@ contract SortitionModuleUniversity is ISortitionModuleUniversity, UUPSProxiable,
4747
// * Events * //
4848
// ************************************* //
4949

50-
event StakeSet(address indexed _address, uint256 _courtID, uint256 _amount);
50+
/// @notice Emitted when a juror stakes in a court.
51+
/// @param _address The address of the juror.
52+
/// @param _courtID The ID of the court.
53+
/// @param _amount The amount of tokens staked in the court.
54+
/// @param _amountAllCourts The amount of tokens staked in all courts.
55+
event StakeSet(address indexed _address, uint256 _courtID, uint256 _amount, uint256 _amountAllCourts);
56+
57+
/// @notice Emitted when a juror's stake is locked.
58+
/// @param _address The address of the juror.
59+
/// @param _relativeAmount The amount of tokens locked.
60+
/// @param _unlock Whether the stake is locked or unlocked.
5161
event StakeLocked(address indexed _address, uint256 _relativeAmount, bool _unlock);
5262

5363
// ************************************* //
@@ -163,7 +173,7 @@ contract SortitionModuleUniversity is ISortitionModuleUniversity, UUPSProxiable,
163173
(currentCourtID, , , , , , ) = core.courts(currentCourtID);
164174
}
165175
}
166-
emit StakeSet(_account, _courtID, _newStake);
176+
emit StakeSet(_account, _courtID, _newStake, juror.stakedPnk);
167177
return (pnkDeposit, pnkWithdrawal, StakingResult.Successful);
168178
}
169179

contracts/test/arbitration/staking-neo.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ describe("Staking", async () => {
183183
await pnk.connect(juror).approve(core.target, PNK(1000));
184184
await expect(await core.connect(juror).setStake(1, PNK(1000)))
185185
.to.emit(sortition, "StakeSet")
186-
.withArgs(juror.address, 1, PNK(1000));
186+
.withArgs(juror.address, 1, PNK(1000), PNK(1000));
187187
expect(await sortition.totalStaked()).to.be.equal(PNK(1000));
188188
});
189189
});
@@ -201,17 +201,17 @@ describe("Staking", async () => {
201201
it("Should be able to unstake", async () => {
202202
expect(await core.connect(juror).setStake(1, PNK(500)))
203203
.to.emit(sortition, "StakeSet")
204-
.withArgs(juror.address, 1, PNK(500));
204+
.withArgs(juror.address, 1, PNK(500), PNK(500));
205205
expect(await sortition.totalStaked()).to.be.equal(PNK(500));
206206

207207
expect(await core.connect(juror).setStake(1, PNK(1001)))
208208
.to.emit(sortition, "StakeSet")
209-
.withArgs(juror.address, 1, PNK(1001));
209+
.withArgs(juror.address, 1, PNK(1001), PNK(1001));
210210
expect(await sortition.totalStaked()).to.be.equal(PNK(1001));
211211

212212
expect(await core.connect(juror).setStake(1, PNK(0)))
213213
.to.emit(sortition, "StakeSet")
214-
.withArgs(juror.address, 1, PNK(0));
214+
.withArgs(juror.address, 1, PNK(0), PNK(0));
215215
expect(await sortition.totalStaked()).to.be.equal(PNK(0));
216216
});
217217
});
@@ -230,7 +230,7 @@ describe("Staking", async () => {
230230
await drawAndReachStakingPhaseFromGenerating();
231231
expect(await sortition.executeDelayedStakes(10))
232232
.to.emit(sortition, "StakeSet")
233-
.withArgs(juror.address, 1, PNK(0));
233+
.withArgs(juror.address, 1, PNK(0), PNK(0));
234234
});
235235
});
236236
});
@@ -272,14 +272,14 @@ describe("Staking", async () => {
272272
await core.connect(juror).setStake(1, PNK(1000));
273273
await createDisputeAndReachGeneratingPhaseFromStaking();
274274
expect(await core.connect(juror).setStake(1, PNK(2000)))
275-
.to.emit(sortition, "StakeDelayedAlreadyTransferred")
275+
.to.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
276276
.withArgs(juror.address, 1, PNK(2000))
277277
.to.not.emit(sortition, "StakeSet");
278278
expect(await sortition.totalStaked()).to.be.equal(PNK(1000));
279279
await drawAndReachStakingPhaseFromGenerating();
280280
expect(await sortition.executeDelayedStakes(10))
281281
.to.emit(sortition, "StakeSet")
282-
.withArgs(juror.address, 1, PNK(2000));
282+
.withArgs(juror.address, 1, PNK(2000), PNK(2000));
283283
expect(await sortition.totalStaked()).to.be.equal(PNK(2000));
284284
});
285285
});
@@ -309,7 +309,7 @@ describe("Staking", async () => {
309309
await pnk.connect(juror).approve(core.target, PNK(1000));
310310
await expect(await core.connect(juror).setStake(1, PNK(1000)))
311311
.to.emit(sortition, "StakeSet")
312-
.withArgs(juror.address, 1, PNK(1000));
312+
.withArgs(juror.address, 1, PNK(1000), PNK(1000));
313313
expect(await sortition.totalStaked()).to.be.equal(PNK(3000));
314314
});
315315
});
@@ -334,13 +334,13 @@ describe("Staking", async () => {
334334
it("Should be able to stake exactly maxTotalStaked", async () => {
335335
await pnk.connect(juror).approve(core.target, PNK(1000));
336336
await expect(await core.connect(juror).setStake(1, PNK(1000)))
337-
.to.emit(sortition, "StakeDelayedAlreadyTransferred")
337+
.to.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
338338
.withArgs(juror.address, 1, PNK(1000));
339339
expect(await sortition.totalStaked()).to.be.equal(PNK(2000)); // Not updated until the delayed stake is executed
340340
await drawAndReachStakingPhaseFromGenerating();
341341
await expect(await sortition.executeDelayedStakes(10))
342342
.to.emit(sortition, "StakeSet")
343-
.withArgs(juror.address, 1, PNK(1000));
343+
.withArgs(juror.address, 1, PNK(1000), PNK(1000));
344344
expect(await sortition.totalStaked()).to.be.equal(PNK(3000));
345345
});
346346
});
@@ -430,7 +430,7 @@ describe("Staking", async () => {
430430
await pnk.approve(core.target, PNK(1000));
431431
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0);
432432
await expect(core.setStake(2, PNK(3000)))
433-
.to.emit(sortition, "StakeDelayedAlreadyTransferred")
433+
.to.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
434434
.withArgs(deployer, 2, PNK(3000));
435435
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([PNK(5000), 0, PNK(2000), 2]); // stake does not change
436436
});
@@ -456,9 +456,9 @@ describe("Staking", async () => {
456456
it("Should execute the delayed stakes", async () => {
457457
await expect(await sortition.executeDelayedStakes(10))
458458
.to.emit(sortition, "StakeSet")
459-
.withArgs(deployer, 2, PNK(3000))
459+
.withArgs(deployer, 2, PNK(3000), PNK(5000))
460460
.to.not.emit(sortition, "StakeDelayedNotTransferred")
461-
.to.not.emit(sortition, "StakeDelayedAlreadyTransferred")
461+
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
462462
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredWithdrawn");
463463
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
464464
PNK(5000),
@@ -524,7 +524,7 @@ describe("Staking", async () => {
524524
it("Should execute the delayed stakes by withdrawing PNK and reducing the stakes", async () => {
525525
await expect(await sortition.executeDelayedStakes(10))
526526
.to.emit(sortition, "StakeSet")
527-
.withArgs(deployer, 2, PNK(1000));
527+
.withArgs(deployer, 2, PNK(1000), PNK(3000));
528528
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
529529
PNK(3000),
530530
PNK(300), // we're the only juror so we are drawn 3 times
@@ -613,7 +613,7 @@ describe("Staking", async () => {
613613
it("Should execute the delayed stakes but the stakes should remain the same", async () => {
614614
await expect(await sortition.executeDelayedStakes(10))
615615
.to.emit(sortition, "StakeSet")
616-
.withArgs(deployer, 2, PNK(2000));
616+
.withArgs(deployer, 2, PNK(2000), PNK(4000));
617617
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
618618
PNK(4000),
619619
PNK(300), // we're the only juror so we are drawn 3 times
@@ -653,7 +653,7 @@ describe("Staking", async () => {
653653
await pnk.approve(core.target, PNK(1000));
654654
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0);
655655
await expect(core.setStake(2, PNK(3000)))
656-
.to.emit(sortition, "StakeDelayedAlreadyTransferred")
656+
.to.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
657657
.withArgs(deployer, 2, PNK(3000));
658658
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([PNK(5000), 0, PNK(2000), 2]); // stake does not change
659659
});
@@ -704,9 +704,9 @@ describe("Staking", async () => {
704704
it("Should execute the delayed stakes but the stakes should remain the same", async () => {
705705
await expect(sortition.executeDelayedStakes(10))
706706
.to.emit(await sortition, "StakeSet")
707-
.withArgs(deployer, 2, PNK(2000))
707+
.withArgs(deployer, 2, PNK(2000), PNK(4000))
708708
.to.not.emit(sortition, "StakeDelayedNotTransferred")
709-
.to.not.emit(sortition, "StakeDelayedAlreadyTransferred")
709+
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
710710
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredWithdrawn");
711711
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
712712
PNK(4000),

contracts/test/arbitration/staking.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe("Staking", async () => {
8787
await pnk.approve(core.target, PNK(1000));
8888
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0);
8989
await expect(core.setStake(2, PNK(3000)))
90-
.to.emit(sortition, "StakeDelayedAlreadyTransferred")
90+
.to.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
9191
.withArgs(deployer, 2, PNK(3000));
9292
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([PNK(5000), 0, PNK(2000), 2]); // stake does not change
9393
});
@@ -113,9 +113,9 @@ describe("Staking", async () => {
113113
it("Should execute the delayed stakes", async () => {
114114
await expect(sortition.executeDelayedStakes(10))
115115
.to.emit(sortition, "StakeSet")
116-
.withArgs(deployer, 2, PNK(3000))
116+
.withArgs(deployer, 2, PNK(3000), PNK(5000))
117117
.to.not.emit(sortition, "StakeDelayedNotTransferred")
118-
.to.not.emit(sortition, "StakeDelayedAlreadyTransferred")
118+
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
119119
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredWithdrawn");
120120
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
121121
PNK(5000),
@@ -179,7 +179,7 @@ describe("Staking", async () => {
179179
it("Should execute the delayed stakes by withdrawing PNK and reducing the stakes", async () => {
180180
await expect(sortition.executeDelayedStakes(10))
181181
.to.emit(sortition, "StakeSet")
182-
.withArgs(deployer, 2, PNK(1000));
182+
.withArgs(deployer, 2, PNK(1000), PNK(3000));
183183
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
184184
PNK(3000),
185185
PNK(300), // we're the only juror so we are drawn 3 times
@@ -266,7 +266,7 @@ describe("Staking", async () => {
266266
it("Should execute the delayed stakes but the stakes should remain the same", async () => {
267267
await expect(sortition.executeDelayedStakes(10))
268268
.to.emit(sortition, "StakeSet")
269-
.withArgs(deployer, 2, PNK(2000));
269+
.withArgs(deployer, 2, PNK(2000), PNK(4000));
270270
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
271271
PNK(4000),
272272
PNK(300), // we're the only juror so we are drawn 3 times
@@ -304,7 +304,7 @@ describe("Staking", async () => {
304304
await pnk.approve(core.target, PNK(1000));
305305
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0);
306306
await expect(core.setStake(2, PNK(3000)))
307-
.to.emit(sortition, "StakeDelayedAlreadyTransferred")
307+
.to.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
308308
.withArgs(deployer, 2, PNK(3000));
309309
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([PNK(5000), 0, PNK(2000), 2]); // stake does not change
310310
});
@@ -355,9 +355,9 @@ describe("Staking", async () => {
355355
it("Should execute the delayed stakes but the stakes should remain the same", async () => {
356356
await expect(sortition.executeDelayedStakes(10))
357357
.to.emit(sortition, "StakeSet")
358-
.withArgs(deployer, 2, PNK(2000))
358+
.withArgs(deployer, 2, PNK(2000), PNK(4000))
359359
.to.not.emit(sortition, "StakeDelayedNotTransferred")
360-
.to.not.emit(sortition, "StakeDelayedAlreadyTransferred")
360+
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
361361
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredWithdrawn");
362362
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
363363
PNK(4000),

contracts/test/foundry/KlerosCore.t.sol

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {TestERC20} from "../../src/token/TestERC20.sol";
1717
import {ArbitrableExample, IArbitrableV2} from "../../src/arbitration/arbitrables/ArbitrableExample.sol";
1818
import {DisputeTemplateRegistry} from "../../src/arbitration/DisputeTemplateRegistry.sol";
1919
import "../../src/libraries/Constants.sol";
20-
import {IKlerosCore, KlerosCoreSnapshotProxy} from "../../src/snapshot-proxy/KlerosCoreSnapshotProxy.sol";
20+
import {IKlerosCore, KlerosCoreSnapshotProxy} from "../../src/arbitration/view/KlerosCoreSnapshotProxy.sol";
2121

2222
contract KlerosCoreTest is Test {
2323
event Initialized(uint64 version);
@@ -861,7 +861,7 @@ contract KlerosCoreTest is Test {
861861

862862
vm.prank(staker1);
863863
vm.expectEmit(true, true, true, true);
864-
emit SortitionModuleBase.StakeSet(staker1, GENERAL_COURT, 1001);
864+
emit SortitionModuleBase.StakeSet(staker1, GENERAL_COURT, 1001, 1001);
865865
core.setStake(GENERAL_COURT, 1001);
866866

867867
(uint256 totalStaked, uint256 totalLocked, uint256 stakedInCourt, uint256 nbCourts) = sortitionModule
@@ -887,7 +887,7 @@ contract KlerosCoreTest is Test {
887887
// Increase stake one more time to verify the correct behavior
888888
vm.prank(staker1);
889889
vm.expectEmit(true, true, true, true);
890-
emit SortitionModuleBase.StakeSet(staker1, GENERAL_COURT, 2000);
890+
emit SortitionModuleBase.StakeSet(staker1, GENERAL_COURT, 2000, 2000);
891891
core.setStake(GENERAL_COURT, 2000);
892892

893893
(totalStaked, totalLocked, stakedInCourt, nbCourts) = sortitionModule.getJurorBalance(staker1, GENERAL_COURT);
@@ -1010,7 +1010,7 @@ contract KlerosCoreTest is Test {
10101010

10111011
vm.prank(staker1);
10121012
vm.expectEmit(true, true, true, true);
1013-
emit SortitionModuleBase.StakeDelayedAlreadyTransferred(staker1, GENERAL_COURT, 1500);
1013+
emit SortitionModuleBase.StakeDelayedAlreadyTransferredDeposited(staker1, GENERAL_COURT, 1500);
10141014
core.setStake(GENERAL_COURT, 1500);
10151015

10161016
uint256 delayedStakeId = sortitionModule.delayedStakeWriteIndex();
@@ -1197,7 +1197,7 @@ contract KlerosCoreTest is Test {
11971197
assertEq(pinakion.balanceOf(address(core)), 1800, "Wrong token balance of the core");
11981198

11991199
vm.expectEmit(true, true, true, true);
1200-
emit SortitionModuleBase.StakeSet(staker1, GENERAL_COURT, 1800);
1200+
emit SortitionModuleBase.StakeSet(staker1, GENERAL_COURT, 1800, 1800);
12011201
sortitionModule.executeDelayedStakes(20); // Deliberately ask for more iterations than needed
12021202

12031203
assertEq(sortitionModule.delayedStakeWriteIndex(), 3, "Wrong delayedStakeWriteIndex");
@@ -2402,9 +2402,9 @@ contract KlerosCoreTest is Test {
24022402
uint256 governorTokenBalance = pinakion.balanceOf(governor);
24032403

24042404
vm.expectEmit(true, true, true, true);
2405-
emit SortitionModuleBase.StakeSet(staker1, newCourtID, 0);
2405+
emit SortitionModuleBase.StakeSet(staker1, newCourtID, 0, 19000);
24062406
vm.expectEmit(true, true, true, true);
2407-
emit SortitionModuleBase.StakeSet(staker1, GENERAL_COURT, 0);
2407+
emit SortitionModuleBase.StakeSet(staker1, GENERAL_COURT, 0, 0);
24082408
core.execute(disputeID, 0, 3);
24092409

24102410
assertEq(pinakion.balanceOf(address(core)), 0, "Wrong token balance of the core");

0 commit comments

Comments
 (0)