Skip to content
Merged
9 changes: 5 additions & 4 deletions contracts/deploy/00-home-chain-arbitration-neo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)

await deployUpgradable(deployments, "EvidenceModule", { from: deployer, args: [deployer], log: true });

const jumpDisputeKitID = 1; // Classic DK
const disputeKit = await deployUpgradable(deployments, "DisputeKitClassicNeo", {
from: deployer,
contract: "DisputeKitClassic",
args: [deployer, ZeroAddress, weth.target],
args: [deployer, ZeroAddress, weth.target, jumpDisputeKitID],
log: true,
});

Expand Down Expand Up @@ -124,21 +125,21 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
// Extra dispute kits
const disputeKitShutter = await deployUpgradable(deployments, "DisputeKitShutter", {
from: deployer,
args: [deployer, core.target, weth.target],
args: [deployer, core.target, weth.target, jumpDisputeKitID],
log: true,
});
await core.addNewDisputeKit(disputeKitShutter.address);

const disputeKitGated = await deployUpgradable(deployments, "DisputeKitGated", {
from: deployer,
args: [deployer, core.target, weth.target],
args: [deployer, core.target, weth.target, jumpDisputeKitID],
log: true,
});
await core.addNewDisputeKit(disputeKitGated.address);

const disputeKitGatedShutter = await deployUpgradable(deployments, "DisputeKitGatedShutter", {
from: deployer,
args: [deployer, core.target, weth.target],
args: [deployer, core.target, weth.target, jumpDisputeKitID],
log: true,
});
await core.addNewDisputeKit(disputeKitGatedShutter.address);
Expand Down
9 changes: 5 additions & 4 deletions contracts/deploy/00-home-chain-arbitration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
log: true,
});

const jumpDisputeKitID = 1; // Classic DK
const disputeKit = await deployUpgradable(deployments, "DisputeKitClassic", {
from: deployer,
args: [deployer, ZeroAddress, weth.target],
args: [deployer, ZeroAddress, weth.target, jumpDisputeKitID],
log: true,
});

Expand Down Expand Up @@ -105,23 +106,23 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
// Extra dispute kits
const disputeKitShutter = await deployUpgradable(deployments, "DisputeKitShutter", {
from: deployer,
args: [deployer, core.target, weth.target],
args: [deployer, core.target, weth.target, jumpDisputeKitID],
log: true,
});
await core.addNewDisputeKit(disputeKitShutter.address);
await core.enableDisputeKits(Courts.GENERAL, [2], true); // enable disputeKitShutter on the General Court

const disputeKitGated = await deployUpgradable(deployments, "DisputeKitGated", {
from: deployer,
args: [deployer, core.target, weth.target],
args: [deployer, core.target, weth.target, jumpDisputeKitID],
log: true,
});
await core.addNewDisputeKit(disputeKitGated.address);
await core.enableDisputeKits(Courts.GENERAL, [3], true); // enable disputeKitGated on the General Court

const disputeKitGatedShutter = await deployUpgradable(deployments, "DisputeKitGatedShutter", {
from: deployer,
args: [deployer, core.target, weth.target],
args: [deployer, core.target, weth.target, jumpDisputeKitID],
log: true,
});
await core.addNewDisputeKit(disputeKitGatedShutter.address);
Expand Down
7 changes: 5 additions & 2 deletions contracts/src/arbitration/KlerosCoreBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,11 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
courtJump = true;

if (!courts[newCourtID].supportedDisputeKits[newDisputeKitID]) {
// Switch to classic dispute kit if parent court doesn't support the current one.
newDisputeKitID = DISPUTE_KIT_CLASSIC;
newDisputeKitID = disputeKits[_round.disputeKitID].getJumpDisputeKitID();
if (!courts[newCourtID].supportedDisputeKits[newDisputeKitID]) {
// Switch to classic dispute kit if parent court doesn't support the jump DK.
newDisputeKitID = DISPUTE_KIT_CLASSIC;
}
disputeKitJump = true;
}
}
Expand Down
16 changes: 11 additions & 5 deletions contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {DisputeKitClassicBase, KlerosCore} from "./DisputeKitClassicBase.sol";
/// - an incentive system: equal split between coherent votes,
/// - an appeal system: fund 2 choices only, vote on any choice.
contract DisputeKitClassic is DisputeKitClassicBase {
string public constant override version = "0.12.0";
string public constant override version = "0.13.0";

// ************************************* //
// * Constructor * //
Expand All @@ -26,12 +26,18 @@ contract DisputeKitClassic is DisputeKitClassicBase {
/// @param _owner The owner's address.
/// @param _core The KlerosCore arbitrator.
/// @param _wNative The wrapped native token address, typically wETH.
function initialize(address _owner, KlerosCore _core, address _wNative) external reinitializer(1) {
__DisputeKitClassicBase_initialize(_owner, _core, _wNative);
/// @param _jumpDisputeKitID The ID of the dispute kit to switch to after the court jump.
function initialize(
address _owner,
KlerosCore _core,
address _wNative,
uint256 _jumpDisputeKitID
) external reinitializer(1) {
__DisputeKitClassicBase_initialize(_owner, _core, _wNative, _jumpDisputeKitID);
}

function reinitialize(address _wNative) external reinitializer(9) {
wNative = _wNative;
function reinitialize(uint256 _jumpDisputeKitID) external reinitializer(10) {
jumpDisputeKitID = _jumpDisputeKitID;
}

// ************************ //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {KlerosCore, KlerosCoreBase, IDisputeKit, ISortitionModule} from "../Kler
import {Initializable} from "../../proxy/Initializable.sol";
import {UUPSProxiable} from "../../proxy/UUPSProxiable.sol";
import {SafeSend} from "../../libraries/SafeSend.sol";
import {ONE_BASIS_POINT} from "../../libraries/Constants.sol";
import {ONE_BASIS_POINT, DISPUTE_KIT_CLASSIC} from "../../libraries/Constants.sol";

/// @title DisputeKitClassicBase
/// Abstract Dispute kit classic implementation of the Kleros v1 features including:
Expand Down Expand Up @@ -68,6 +68,7 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
public alreadyDrawn; // True if the address has already been drawn, false by default. To be added to the Round struct when fully redeploying rather than upgrading.
mapping(uint256 coreDisputeID => bool) public coreDisputeIDToActive; // True if this dispute kit is active for this core dispute ID.
address public wNative; // The wrapped native token for safeSend().
uint256 public jumpDisputeKitID; // The ID of the dispute kit in Kleros Core disputeKits array that the dispute should switch to after the court jump, in case the new court doesn't support this dispute kit.

// ************************************* //
// * Events * //
Expand Down Expand Up @@ -147,14 +148,17 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
/// @param _owner The owner's address.
/// @param _core The KlerosCore arbitrator.
/// @param _wNative The wrapped native token address, typically wETH.
/// @param _jumpDisputeKitID The ID of the dispute kit to switch to after the court jump.
function __DisputeKitClassicBase_initialize(
address _owner,
KlerosCore _core,
address _wNative
address _wNative,
uint256 _jumpDisputeKitID
) internal onlyInitializing {
owner = _owner;
core = _core;
wNative = _wNative;
jumpDisputeKitID = _jumpDisputeKitID;
}

// ************************ //
Expand All @@ -176,6 +180,12 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
owner = _owner;
}

/// @dev Changes the dispute kit ID used for the jump.
/// @param _jumpDisputeKitID The new value for the `jumpDisputeKitID` storage variable.
function changeJumpDisputeKitID(uint256 _jumpDisputeKitID) external onlyByOwner {
jumpDisputeKitID = _jumpDisputeKitID;
}

/// @dev Changes the `core` storage variable.
/// @param _core The new value for the `core` storage variable.
function changeCore(address _core) external onlyByOwner {
Expand Down Expand Up @@ -639,6 +649,11 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
return (_currentNbVotes * 2) + 1;
}

function getJumpDisputeKitID() external view returns (uint256) {
// Fall back to classic DK in case the jump ID is not defined.
return jumpDisputeKitID == 0 ? DISPUTE_KIT_CLASSIC : jumpDisputeKitID;
}

/// @dev Returns true if the specified voter was active in this round.
/// @param _coreDisputeID The ID of the dispute in Kleros Core, not in the Dispute Kit.
/// @param _coreRoundID The ID of the round in Kleros Core, not in the Dispute Kit.
Expand Down
16 changes: 11 additions & 5 deletions contracts/src/arbitration/dispute-kits/DisputeKitGated.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface IBalanceHolderERC1155 {
/// - an incentive system: equal split between coherent votes,
/// - an appeal system: fund 2 choices only, vote on any choice.
contract DisputeKitGated is DisputeKitClassicBase {
string public constant override version = "0.12.0";
string public constant override version = "0.13.0";

// ************************************* //
// * Constructor * //
Expand All @@ -42,12 +42,18 @@ contract DisputeKitGated is DisputeKitClassicBase {
/// @param _owner The owner's address.
/// @param _core The KlerosCore arbitrator.
/// @param _wNative The wrapped native token address, typically wETH.
function initialize(address _owner, KlerosCore _core, address _wNative) external reinitializer(1) {
__DisputeKitClassicBase_initialize(_owner, _core, _wNative);
/// @param _jumpDisputeKitID The ID of the dispute kit to switch to after the court jump.
function initialize(
address _owner,
KlerosCore _core,
address _wNative,
uint256 _jumpDisputeKitID
) external reinitializer(1) {
__DisputeKitClassicBase_initialize(_owner, _core, _wNative, _jumpDisputeKitID);
}

function reinitialize(address _wNative) external reinitializer(9) {
wNative = _wNative;
function reinitialize(uint256 _jumpDisputeKitID) external reinitializer(10) {
jumpDisputeKitID = _jumpDisputeKitID;
}

// ************************ //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface IBalanceHolderERC1155 {
/// - an incentive system: equal split between coherent votes,
/// - an appeal system: fund 2 choices only, vote on any choice.
contract DisputeKitGatedShutter is DisputeKitClassicBase {
string public constant override version = "0.12.0";
string public constant override version = "0.13.0";

// ************************************* //
// * Events * //
Expand Down Expand Up @@ -61,12 +61,18 @@ contract DisputeKitGatedShutter is DisputeKitClassicBase {
/// @param _owner The owner's address.
/// @param _core The KlerosCore arbitrator.
/// @param _wNative The wrapped native token address, typically wETH.
function initialize(address _owner, KlerosCore _core, address _wNative) external reinitializer(1) {
__DisputeKitClassicBase_initialize(_owner, _core, _wNative);
/// @param _jumpDisputeKitID The ID of the dispute kit to switch to after the court jump.
function initialize(
address _owner,
KlerosCore _core,
address _wNative,
uint256 _jumpDisputeKitID
) external reinitializer(1) {
__DisputeKitClassicBase_initialize(_owner, _core, _wNative, _jumpDisputeKitID);
}

function reinitialize(address _wNative) external reinitializer(9) {
wNative = _wNative;
function reinitialize(uint256 _jumpDisputeKitID) external reinitializer(10) {
jumpDisputeKitID = _jumpDisputeKitID;
}

// ************************ //
Expand Down
16 changes: 11 additions & 5 deletions contracts/src/arbitration/dispute-kits/DisputeKitShutter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {DisputeKitClassicBase, KlerosCore} from "./DisputeKitClassicBase.sol";
/// - an incentive system: equal split between coherent votes,
/// - an appeal system: fund 2 choices only, vote on any choice.
contract DisputeKitShutter is DisputeKitClassicBase {
string public constant override version = "0.12.0";
string public constant override version = "0.13.0";

// ************************************* //
// * Events * //
Expand Down Expand Up @@ -45,12 +45,18 @@ contract DisputeKitShutter is DisputeKitClassicBase {
/// @param _owner The owner's address.
/// @param _core The KlerosCore arbitrator.
/// @param _wNative The wrapped native token address, typically wETH.
function initialize(address _owner, KlerosCore _core, address _wNative) external reinitializer(1) {
__DisputeKitClassicBase_initialize(_owner, _core, _wNative);
/// @param _jumpDisputeKitID The ID of the dispute kit to switch to after the court jump.
function initialize(
address _owner,
KlerosCore _core,
address _wNative,
uint256 _jumpDisputeKitID
) external reinitializer(1) {
__DisputeKitClassicBase_initialize(_owner, _core, _wNative, _jumpDisputeKitID);
}

function reinitialize(address _wNative) external reinitializer(9) {
wNative = _wNative;
function reinitialize(uint256 _jumpDisputeKitID) external reinitializer(10) {
jumpDisputeKitID = _jumpDisputeKitID;
}

// ************************ //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface IProofOfHumanity {
/// - an incentive system: equal split between coherent votes,
/// - an appeal system: fund 2 choices only, vote on any choice.
contract DisputeKitSybilResistant is DisputeKitClassicBase {
string public constant override version = "0.12.0";
string public constant override version = "0.13.0";

// ************************************* //
// * Storage * //
Expand All @@ -40,13 +40,15 @@ contract DisputeKitSybilResistant is DisputeKitClassicBase {
/// @param _core The KlerosCore arbitrator.
/// @param _poh The Proof of Humanity registry.
/// @param _wNative The wrapped native token address, typically wETH.
/// @param _jumpDisputeKitID The ID of the dispute kit to switch to after the court jump.
function initialize(
address _owner,
KlerosCore _core,
IProofOfHumanity _poh,
address _wNative
address _wNative,
uint256 _jumpDisputeKitID
) external reinitializer(1) {
__DisputeKitClassicBase_initialize(_owner, _core, _wNative);
__DisputeKitClassicBase_initialize(_owner, _core, _wNative, _jumpDisputeKitID);
poh = _poh;
singleDrawPerJuror = true;
}
Expand Down
4 changes: 4 additions & 0 deletions contracts/src/arbitration/interfaces/IDisputeKit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ interface IDisputeKit {
uint256 _currentNbVotes
) external view returns (uint256); // TODO: remove previousDisputeKit

/// @dev Returns the dispute kid ID for Kleros Core, that will be used after court jump.
/// @return The ID of the dispute kit in Kleros Core disputeKits array.
function getJumpDisputeKitID() external view returns (uint256);

/// @dev Returns true if the specified voter was active in this round.
/// @param _coreDisputeID The ID of the dispute in Kleros Core, not in the Dispute Kit.
/// @param _coreRoundID The ID of the round in Kleros Core, not in the Dispute Kit.
Expand Down
22 changes: 14 additions & 8 deletions contracts/test/foundry/KlerosCore.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ contract KlerosCoreTest is Test {
UUPSProxy proxyCore = new UUPSProxy(address(coreLogic), "");

bytes memory initDataDk = abi.encodeWithSignature(
"initialize(address,address,address)",
"initialize(address,address,address,uint256)",
owner,
address(proxyCore),
address(wNative)
address(wNative),
DISPUTE_KIT_CLASSIC
);

UUPSProxy proxyDk = new UUPSProxy(address(dkLogic), initDataDk);
Expand Down Expand Up @@ -235,6 +236,8 @@ contract KlerosCoreTest is Test {
assertEq(pinakion.allowance(staker2, address(core)), 1 ether, "Wrong allowance for staker2");

assertEq(disputeKit.owner(), msg.sender, "Wrong DK owner");
assertEq(disputeKit.getJumpDisputeKitID(), DISPUTE_KIT_CLASSIC, "Wrong jump DK");
assertEq(disputeKit.jumpDisputeKitID(), DISPUTE_KIT_CLASSIC, "Wrong jump DK storage var");
assertEq(address(disputeKit.core()), address(core), "Wrong core in DK");

assertEq(sortitionModule.owner(), msg.sender, "Wrong SM owner");
Expand Down Expand Up @@ -289,10 +292,11 @@ contract KlerosCoreTest is Test {
UUPSProxy proxyCore = new UUPSProxy(address(coreLogic), "");

bytes memory initDataDk = abi.encodeWithSignature(
"initialize(address,address,address)",
"initialize(address,address,address,uint256)",
owner,
address(proxyCore),
address(wNative)
address(wNative),
DISPUTE_KIT_CLASSIC
);

UUPSProxy proxyDk = new UUPSProxy(address(dkLogic), initDataDk);
Expand Down Expand Up @@ -2115,10 +2119,11 @@ contract KlerosCoreTest is Test {
DisputeKitClassic dkLogic = new DisputeKitClassic();
// Create a new DK and court to check the switch
bytes memory initDataDk = abi.encodeWithSignature(
"initialize(address,address,address)",
"initialize(address,address,address,uint256)",
owner,
address(core),
address(wNative)
address(wNative),
DISPUTE_KIT_CLASSIC
);

UUPSProxy proxyDk = new UUPSProxy(address(dkLogic), initDataDk);
Expand Down Expand Up @@ -2939,10 +2944,11 @@ contract KlerosCoreTest is Test {
DisputeKitClassic dkLogic = new DisputeKitClassic();
// Create a new DK to check castVote.
bytes memory initDataDk = abi.encodeWithSignature(
"initialize(address,address,address)",
"initialize(address,address,address,uint256)",
owner,
address(core),
address(wNative)
address(wNative),
DISPUTE_KIT_CLASSIC
);

UUPSProxy proxyDk = new UUPSProxy(address(dkLogic), initDataDk);
Expand Down
Loading