Skip to content

Adding the juror's total stake for all courts in the StakeSet event back in #1935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions contracts/src/arbitration/SortitionModuleBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,35 @@ abstract contract SortitionModuleBase is ISortitionModule, Initializable, UUPSPr
// * Events * //
// ************************************* //

event StakeSet(address indexed _address, uint256 _courtID, uint256 _amount);
/// @notice Emitted when a juror stakes in a court.
/// @param _address The address of the juror.
/// @param _courtID The ID of the court.
/// @param _amount The amount of tokens staked in the court.
/// @param _amountAllCourts The amount of tokens staked in all courts.
event StakeSet(address indexed _address, uint256 _courtID, uint256 _amount, uint256 _amountAllCourts);

/// @notice Emitted when a juror's stake is delayed and tokens are not transferred yet.
/// @param _address The address of the juror.
/// @param _courtID The ID of the court.
/// @param _amount The amount of tokens staked in the court.
event StakeDelayedNotTransferred(address indexed _address, uint256 _courtID, uint256 _amount);
event StakeDelayedAlreadyTransferred(address indexed _address, uint256 _courtID, uint256 _amount);

/// @notice Emitted when a juror's stake is delayed and tokens are already deposited.
/// @param _address The address of the juror.
/// @param _courtID The ID of the court.
/// @param _amount The amount of tokens staked in the court.
event StakeDelayedAlreadyTransferredDeposited(address indexed _address, uint256 _courtID, uint256 _amount);

/// @notice Emitted when a juror's stake is delayed and tokens are already withdrawn.
/// @param _address The address of the juror.
/// @param _courtID The ID of the court.
/// @param _amount The amount of tokens withdrawn.
event StakeDelayedAlreadyTransferredWithdrawn(address indexed _address, uint96 indexed _courtID, uint256 _amount);

/// @notice Emitted when a juror's stake is locked.
/// @param _address The address of the juror.
/// @param _relativeAmount The amount of tokens locked.
/// @param _unlock Whether the stake is locked or unlocked.
event StakeLocked(address indexed _address, uint256 _relativeAmount, bool _unlock);

// ************************************* //
Expand Down Expand Up @@ -288,7 +313,7 @@ abstract contract SortitionModuleBase is ISortitionModule, Initializable, UUPSPr
// PNK deposit: tokens are transferred now.
delayedStake.alreadyTransferred = true;
pnkDeposit = _increaseStake(juror, _courtID, _newStake, currentStake);
emit StakeDelayedAlreadyTransferred(_account, _courtID, _newStake);
emit StakeDelayedAlreadyTransferredDeposited(_account, _courtID, _newStake);
} else {
// PNK withdrawal: tokens are not transferred yet.
emit StakeDelayedNotTransferred(_account, _courtID, _newStake);
Expand Down Expand Up @@ -318,7 +343,7 @@ abstract contract SortitionModuleBase is ISortitionModule, Initializable, UUPSPr
(currenCourtID, , , , , , ) = core.courts(currenCourtID); // Get the parent court.
}
}
emit StakeSet(_account, _courtID, _newStake);
emit StakeSet(_account, _courtID, _newStake, juror.stakedPnk);
return (pnkDeposit, pnkWithdrawal, StakingResult.Successful);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ contract SortitionModuleUniversity is ISortitionModuleUniversity, UUPSProxiable,
// * Events * //
// ************************************* //

event StakeSet(address indexed _address, uint256 _courtID, uint256 _amount);
/// @notice Emitted when a juror stakes in a court.
/// @param _address The address of the juror.
/// @param _courtID The ID of the court.
/// @param _amount The amount of tokens staked in the court.
/// @param _amountAllCourts The amount of tokens staked in all courts.
event StakeSet(address indexed _address, uint256 _courtID, uint256 _amount, uint256 _amountAllCourts);

/// @notice Emitted when a juror's stake is locked.
/// @param _address The address of the juror.
/// @param _relativeAmount The amount of tokens locked.
/// @param _unlock Whether the stake is locked or unlocked.
event StakeLocked(address indexed _address, uint256 _relativeAmount, bool _unlock);

// ************************************* //
Expand Down Expand Up @@ -163,7 +173,7 @@ contract SortitionModuleUniversity is ISortitionModuleUniversity, UUPSProxiable,
(currentCourtID, , , , , , ) = core.courts(currentCourtID);
}
}
emit StakeSet(_account, _courtID, _newStake);
emit StakeSet(_account, _courtID, _newStake, juror.stakedPnk);
return (pnkDeposit, pnkWithdrawal, StakingResult.Successful);
}

Expand Down
36 changes: 18 additions & 18 deletions contracts/test/arbitration/staking-neo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe("Staking", async () => {
await pnk.connect(juror).approve(core.target, PNK(1000));
await expect(await core.connect(juror).setStake(1, PNK(1000)))
.to.emit(sortition, "StakeSet")
.withArgs(juror.address, 1, PNK(1000));
.withArgs(juror.address, 1, PNK(1000), PNK(1000));
expect(await sortition.totalStaked()).to.be.equal(PNK(1000));
});
});
Expand All @@ -201,17 +201,17 @@ describe("Staking", async () => {
it("Should be able to unstake", async () => {
expect(await core.connect(juror).setStake(1, PNK(500)))
.to.emit(sortition, "StakeSet")
.withArgs(juror.address, 1, PNK(500));
.withArgs(juror.address, 1, PNK(500), PNK(500));
expect(await sortition.totalStaked()).to.be.equal(PNK(500));

expect(await core.connect(juror).setStake(1, PNK(1001)))
.to.emit(sortition, "StakeSet")
.withArgs(juror.address, 1, PNK(1001));
.withArgs(juror.address, 1, PNK(1001), PNK(1001));
expect(await sortition.totalStaked()).to.be.equal(PNK(1001));

expect(await core.connect(juror).setStake(1, PNK(0)))
.to.emit(sortition, "StakeSet")
.withArgs(juror.address, 1, PNK(0));
.withArgs(juror.address, 1, PNK(0), PNK(0));
expect(await sortition.totalStaked()).to.be.equal(PNK(0));
});
});
Expand All @@ -230,7 +230,7 @@ describe("Staking", async () => {
await drawAndReachStakingPhaseFromGenerating();
expect(await sortition.executeDelayedStakes(10))
.to.emit(sortition, "StakeSet")
.withArgs(juror.address, 1, PNK(0));
.withArgs(juror.address, 1, PNK(0), PNK(0));
});
});
});
Expand Down Expand Up @@ -272,14 +272,14 @@ describe("Staking", async () => {
await core.connect(juror).setStake(1, PNK(1000));
await createDisputeAndReachGeneratingPhaseFromStaking();
expect(await core.connect(juror).setStake(1, PNK(2000)))
.to.emit(sortition, "StakeDelayedAlreadyTransferred")
.to.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
.withArgs(juror.address, 1, PNK(2000))
.to.not.emit(sortition, "StakeSet");
expect(await sortition.totalStaked()).to.be.equal(PNK(1000));
await drawAndReachStakingPhaseFromGenerating();
expect(await sortition.executeDelayedStakes(10))
.to.emit(sortition, "StakeSet")
.withArgs(juror.address, 1, PNK(2000));
.withArgs(juror.address, 1, PNK(2000), PNK(2000));
expect(await sortition.totalStaked()).to.be.equal(PNK(2000));
});
});
Expand Down Expand Up @@ -309,7 +309,7 @@ describe("Staking", async () => {
await pnk.connect(juror).approve(core.target, PNK(1000));
await expect(await core.connect(juror).setStake(1, PNK(1000)))
.to.emit(sortition, "StakeSet")
.withArgs(juror.address, 1, PNK(1000));
.withArgs(juror.address, 1, PNK(1000), PNK(1000));
expect(await sortition.totalStaked()).to.be.equal(PNK(3000));
});
});
Expand All @@ -334,13 +334,13 @@ describe("Staking", async () => {
it("Should be able to stake exactly maxTotalStaked", async () => {
await pnk.connect(juror).approve(core.target, PNK(1000));
await expect(await core.connect(juror).setStake(1, PNK(1000)))
.to.emit(sortition, "StakeDelayedAlreadyTransferred")
.to.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
.withArgs(juror.address, 1, PNK(1000));
expect(await sortition.totalStaked()).to.be.equal(PNK(2000)); // Not updated until the delayed stake is executed
await drawAndReachStakingPhaseFromGenerating();
await expect(await sortition.executeDelayedStakes(10))
.to.emit(sortition, "StakeSet")
.withArgs(juror.address, 1, PNK(1000));
.withArgs(juror.address, 1, PNK(1000), PNK(1000));
expect(await sortition.totalStaked()).to.be.equal(PNK(3000));
});
});
Expand Down Expand Up @@ -430,7 +430,7 @@ describe("Staking", async () => {
await pnk.approve(core.target, PNK(1000));
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0);
await expect(core.setStake(2, PNK(3000)))
.to.emit(sortition, "StakeDelayedAlreadyTransferred")
.to.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
.withArgs(deployer, 2, PNK(3000));
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([PNK(5000), 0, PNK(2000), 2]); // stake does not change
});
Expand All @@ -456,9 +456,9 @@ describe("Staking", async () => {
it("Should execute the delayed stakes", async () => {
await expect(await sortition.executeDelayedStakes(10))
.to.emit(sortition, "StakeSet")
.withArgs(deployer, 2, PNK(3000))
.withArgs(deployer, 2, PNK(3000), PNK(5000))
.to.not.emit(sortition, "StakeDelayedNotTransferred")
.to.not.emit(sortition, "StakeDelayedAlreadyTransferred")
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredWithdrawn");
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
PNK(5000),
Expand Down Expand Up @@ -524,7 +524,7 @@ describe("Staking", async () => {
it("Should execute the delayed stakes by withdrawing PNK and reducing the stakes", async () => {
await expect(await sortition.executeDelayedStakes(10))
.to.emit(sortition, "StakeSet")
.withArgs(deployer, 2, PNK(1000));
.withArgs(deployer, 2, PNK(1000), PNK(3000));
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
PNK(3000),
PNK(300), // we're the only juror so we are drawn 3 times
Expand Down Expand Up @@ -613,7 +613,7 @@ describe("Staking", async () => {
it("Should execute the delayed stakes but the stakes should remain the same", async () => {
await expect(await sortition.executeDelayedStakes(10))
.to.emit(sortition, "StakeSet")
.withArgs(deployer, 2, PNK(2000));
.withArgs(deployer, 2, PNK(2000), PNK(4000));
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
PNK(4000),
PNK(300), // we're the only juror so we are drawn 3 times
Expand Down Expand Up @@ -653,7 +653,7 @@ describe("Staking", async () => {
await pnk.approve(core.target, PNK(1000));
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0);
await expect(core.setStake(2, PNK(3000)))
.to.emit(sortition, "StakeDelayedAlreadyTransferred")
.to.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
.withArgs(deployer, 2, PNK(3000));
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([PNK(5000), 0, PNK(2000), 2]); // stake does not change
});
Expand Down Expand Up @@ -704,9 +704,9 @@ describe("Staking", async () => {
it("Should execute the delayed stakes but the stakes should remain the same", async () => {
await expect(sortition.executeDelayedStakes(10))
.to.emit(await sortition, "StakeSet")
.withArgs(deployer, 2, PNK(2000))
.withArgs(deployer, 2, PNK(2000), PNK(4000))
.to.not.emit(sortition, "StakeDelayedNotTransferred")
.to.not.emit(sortition, "StakeDelayedAlreadyTransferred")
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredWithdrawn");
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
PNK(4000),
Expand Down
16 changes: 8 additions & 8 deletions contracts/test/arbitration/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe("Staking", async () => {
await pnk.approve(core.target, PNK(1000));
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0);
await expect(core.setStake(2, PNK(3000)))
.to.emit(sortition, "StakeDelayedAlreadyTransferred")
.to.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
.withArgs(deployer, 2, PNK(3000));
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([PNK(5000), 0, PNK(2000), 2]); // stake does not change
});
Expand All @@ -113,9 +113,9 @@ describe("Staking", async () => {
it("Should execute the delayed stakes", async () => {
await expect(sortition.executeDelayedStakes(10))
.to.emit(sortition, "StakeSet")
.withArgs(deployer, 2, PNK(3000))
.withArgs(deployer, 2, PNK(3000), PNK(5000))
.to.not.emit(sortition, "StakeDelayedNotTransferred")
.to.not.emit(sortition, "StakeDelayedAlreadyTransferred")
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredWithdrawn");
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
PNK(5000),
Expand Down Expand Up @@ -179,7 +179,7 @@ describe("Staking", async () => {
it("Should execute the delayed stakes by withdrawing PNK and reducing the stakes", async () => {
await expect(sortition.executeDelayedStakes(10))
.to.emit(sortition, "StakeSet")
.withArgs(deployer, 2, PNK(1000));
.withArgs(deployer, 2, PNK(1000), PNK(3000));
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
PNK(3000),
PNK(300), // we're the only juror so we are drawn 3 times
Expand Down Expand Up @@ -266,7 +266,7 @@ describe("Staking", async () => {
it("Should execute the delayed stakes but the stakes should remain the same", async () => {
await expect(sortition.executeDelayedStakes(10))
.to.emit(sortition, "StakeSet")
.withArgs(deployer, 2, PNK(2000));
.withArgs(deployer, 2, PNK(2000), PNK(4000));
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
PNK(4000),
PNK(300), // we're the only juror so we are drawn 3 times
Expand Down Expand Up @@ -304,7 +304,7 @@ describe("Staking", async () => {
await pnk.approve(core.target, PNK(1000));
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0);
await expect(core.setStake(2, PNK(3000)))
.to.emit(sortition, "StakeDelayedAlreadyTransferred")
.to.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
.withArgs(deployer, 2, PNK(3000));
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([PNK(5000), 0, PNK(2000), 2]); // stake does not change
});
Expand Down Expand Up @@ -355,9 +355,9 @@ describe("Staking", async () => {
it("Should execute the delayed stakes but the stakes should remain the same", async () => {
await expect(sortition.executeDelayedStakes(10))
.to.emit(sortition, "StakeSet")
.withArgs(deployer, 2, PNK(2000))
.withArgs(deployer, 2, PNK(2000), PNK(4000))
.to.not.emit(sortition, "StakeDelayedNotTransferred")
.to.not.emit(sortition, "StakeDelayedAlreadyTransferred")
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredDeposited")
.to.not.emit(sortition, "StakeDelayedAlreadyTransferredWithdrawn");
expect(await sortition.getJurorBalance(deployer, 2)).to.be.deep.equal([
PNK(4000),
Expand Down
14 changes: 7 additions & 7 deletions contracts/test/foundry/KlerosCore.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {TestERC20} from "../../src/token/TestERC20.sol";
import {ArbitrableExample, IArbitrableV2} from "../../src/arbitration/arbitrables/ArbitrableExample.sol";
import {DisputeTemplateRegistry} from "../../src/arbitration/DisputeTemplateRegistry.sol";
import "../../src/libraries/Constants.sol";
import {IKlerosCore, KlerosCoreSnapshotProxy} from "../../src/snapshot-proxy/KlerosCoreSnapshotProxy.sol";
import {IKlerosCore, KlerosCoreSnapshotProxy} from "../../src/arbitration/view/KlerosCoreSnapshotProxy.sol";

contract KlerosCoreTest is Test {
event Initialized(uint64 version);
Expand Down Expand Up @@ -861,7 +861,7 @@ contract KlerosCoreTest is Test {

vm.prank(staker1);
vm.expectEmit(true, true, true, true);
emit SortitionModuleBase.StakeSet(staker1, GENERAL_COURT, 1001);
emit SortitionModuleBase.StakeSet(staker1, GENERAL_COURT, 1001, 1001);
core.setStake(GENERAL_COURT, 1001);

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

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

vm.prank(staker1);
vm.expectEmit(true, true, true, true);
emit SortitionModuleBase.StakeDelayedAlreadyTransferred(staker1, GENERAL_COURT, 1500);
emit SortitionModuleBase.StakeDelayedAlreadyTransferredDeposited(staker1, GENERAL_COURT, 1500);
core.setStake(GENERAL_COURT, 1500);

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

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

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

vm.expectEmit(true, true, true, true);
emit SortitionModuleBase.StakeSet(staker1, newCourtID, 0);
emit SortitionModuleBase.StakeSet(staker1, newCourtID, 0, 19000);
vm.expectEmit(true, true, true, true);
emit SortitionModuleBase.StakeSet(staker1, GENERAL_COURT, 0);
emit SortitionModuleBase.StakeSet(staker1, GENERAL_COURT, 0, 0);
core.execute(disputeID, 0, 3);

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