Skip to content
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

feat(DisputeKit): add flushing feature #1653

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions contracts/src/arbitration/KlerosCoreBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ abstract contract KlerosCoreBase is IArbitratorV2 {
Court[] public courts; // The courts.
IDisputeKit[] public disputeKits; // Array of dispute kits.
Dispute[] public disputes; // The disputes.
mapping(IDisputeKit => uint256) public disputeKitIDs; // Maps dispute kit's address to its index.
mapping(IERC20 => CurrencyRate) public currencyRates; // The price of each token in ETH.
bool public paused; // Whether asset withdrawals are paused.

Expand Down Expand Up @@ -216,6 +217,7 @@ abstract contract KlerosCoreBase is IArbitratorV2 {

// DISPUTE_KIT_CLASSIC
disputeKits.push(_disputeKit);
disputeKitIDs[_disputeKit] = DISPUTE_KIT_CLASSIC;

emit DisputeKitCreated(DISPUTE_KIT_CLASSIC, _disputeKit);

Expand Down Expand Up @@ -316,6 +318,7 @@ abstract contract KlerosCoreBase is IArbitratorV2 {
function addNewDisputeKit(IDisputeKit _disputeKitAddress) external onlyByGovernor {
uint256 disputeKitID = disputeKits.length;
disputeKits.push(_disputeKitAddress);
disputeKitIDs[_disputeKitAddress] = disputeKitID;
emit DisputeKitCreated(disputeKitID, _disputeKitAddress);
}

Expand Down Expand Up @@ -468,18 +471,19 @@ abstract contract KlerosCoreBase is IArbitratorV2 {
_setStake(msg.sender, _courtID, _newStake, false, OnError.Revert);
}

/// @dev Sets the stake of a specified account in a court, typically to apply a delayed stake or unstake inactive jurors.
/// @dev Sets the stake of a specified account in a court, typically to apply a delayed stake or unstake inactive/ineligible jurors.
/// @param _account The account whose stake is being set.
/// @param _courtID The ID of the court.
/// @param _newStake The new stake.
/// @param _alreadyTransferred Whether the PNKs have already been transferred to the contract.
function setStakeBySortitionModule(
function setStakeBySortitionModuleOrDK(
address _account,
uint96 _courtID,
uint256 _newStake,
bool _alreadyTransferred
) external {
if (msg.sender != address(sortitionModule)) revert SortitionModuleOnly();
if (msg.sender != address(sortitionModule) && disputeKitIDs[IDisputeKit(msg.sender)] == 0)
revert SortitionModuleOrDKOnly();
_setStake(_account, _courtID, _newStake, _alreadyTransferred, OnError.Return);
}

Expand Down Expand Up @@ -1144,7 +1148,7 @@ abstract contract KlerosCoreBase is IArbitratorV2 {
error GovernorOnly();
error GuardianOrGovernorOnly();
error DisputeKitOnly();
error SortitionModuleOnly();
error SortitionModuleOrDKOnly();
error UnsuccessfulCall();
error InvalidDisputKitParent();
error DepthLevelMax();
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/arbitration/SortitionModuleBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ abstract contract SortitionModuleBase is ISortitionModule {
DelayedStake storage delayedStake = delayedStakes[i];
// Delayed stake could've been manually removed already. In this case simply move on to the next item.
if (delayedStake.account != address(0)) {
core.setStakeBySortitionModule(
core.setStakeBySortitionModuleOrDK(
delayedStake.account,
delayedStake.courtID,
delayedStake.stake,
Expand Down Expand Up @@ -433,7 +433,7 @@ abstract contract SortitionModuleBase is ISortitionModule {
function setJurorInactive(address _account) external override onlyByCore {
uint96[] memory courtIDs = getJurorCourtIDs(_account);
for (uint256 j = courtIDs.length; j > 0; j--) {
core.setStakeBySortitionModule(_account, courtIDs[j - 1], 0, false);
core.setStakeBySortitionModuleOrDK(_account, courtIDs[j - 1], 0, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,20 @@ contract DisputeKitSybilResistant is IDisputeKit, Initializable, UUPSProxiable {
}
}

/// @dev Unstakes the jurors who are not eligible for drawing, so they don't interfere with the drawing process.
/// Can be called by anyone. The juror will be unstaked if he doesn't pass the check specific to this DK.
/// @param _juror The juror to unstake.
/// @param _courts The courts to unstake from. Note that each court must support this DK.
function flush(address _juror, uint96[] memory _courts) external {
require(!_proofOfHumanity(_juror), "The juror is eligible");
uint256 disputeKitID = core.disputeKitIDs(this);
for (uint256 i = 0; i < _courts.length; i++) {
uint96 courtID = _courts[i];
require(core.isSupported(courtID, disputeKitID), "DK not supported by court");
core.setStakeBySortitionModuleOrDK(_juror, courtID, 0, false);
}
}

// ************************************* //
// * Public Views * //
// ************************************* //
Expand Down
Loading