Skip to content
Next Next commit
feat: add sortition module
  • Loading branch information
jaybuidl authored and unknownunknown1 committed Apr 25, 2023
commit fd371c7c98f234cfd8a1d178f060794b0552ec64
48 changes: 17 additions & 31 deletions contracts/deploy/00-home-chain-arbitration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { BigNumber } from "ethers";
import getContractAddress from "../deploy-helpers/getContractAddress";

enum HomeChains {
ARBITRUM_ONE = 42161,
Expand All @@ -19,24 +20,16 @@ const randomizerByChain = new Map<HomeChains, string>([
[HomeChains.ARBITRUM_GOERLI, "0x923096Da90a3b60eb7E12723fA2E1547BA9236Bc"],
]);

const deployArbitration: DeployFunction = async (
hre: HardhatRuntimeEnvironment
) => {
const { deployments, getNamedAccounts, getChainId } = hre;
const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
const { deploy, execute } = deployments;
const { AddressZero } = hre.ethers.constants;
const RNG_LOOKAHEAD = 20;

// fallback to hardhat node signers on local network
const deployer =
(await getNamedAccounts()).deployer ??
(await hre.ethers.getSigners())[0].address;
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
const chainId = Number(await getChainId());
console.log(
"Deploying to %s with deployer %s",
HomeChains[chainId],
deployer
);
console.log("Deploying to %s with deployer %s", HomeChains[chainId], deployer);

if (chainId === HomeChains.HARDHAT) {
pnkByChain.set(
Expand Down Expand Up @@ -66,8 +59,7 @@ const deployArbitration: DeployFunction = async (
log: true,
});

const randomizer =
randomizerByChain.get(Number(await getChainId())) ?? AddressZero;
const randomizer = randomizerByChain.get(Number(await getChainId())) ?? AddressZero;
const rng = await deploy("RandomizerRNG", {
from: deployer,
args: [randomizer, deployer],
Expand All @@ -76,50 +68,44 @@ const deployArbitration: DeployFunction = async (

const disputeKit = await deploy("DisputeKitClassic", {
from: deployer,
args: [deployer, AddressZero, rng.address, RNG_LOOKAHEAD],
args: [deployer, AddressZero],
log: true,
});

const sortitionSumTreeLibrary = await deploy("SortitionSumTreeFactoryV2", {
const nonce = await ethers.provider.getTransactionCount(deployer);
const KlerosCoreAddress = getContractAddress(deployer, nonce + 1);
console.log("calculated future KlerosCore address for nonce %d: %s", nonce, KlerosCoreAddress);

const sortitionModule = await deploy("SortitionModule", {
from: deployer,
args: [KlerosCoreAddress, 1800, 1800, rng.address, RNG_LOOKAHEAD], // minStakingTime, maxFreezingTime
log: true,
});

const pnk = pnkByChain.get(chainId) ?? AddressZero;
const minStake = BigNumber.from(10).pow(20).mul(2);
const alpha = 10000;
const feeForJuror = BigNumber.from(10).pow(17);
const sortitionSumTreeK = 3;
const klerosCore = await deploy("KlerosCore", {
from: deployer,
libraries: {
SortitionSumTreeFactoryV2: sortitionSumTreeLibrary.address,
},
args: [
deployer,
pnk,
AddressZero,
disputeKit.address,
[1800, 1800], // minStakingTime, maxFreezingTime
false,
[minStake, alpha, feeForJuror, 256], // minStake, alpha, feeForJuror, jurorsForCourtJump
[0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
sortitionSumTreeK,
0xfa, // Extra data for sortition module will return the default value of K
sortitionModule.address,
],
log: true,
});

// execute DisputeKitClassic.changeCore() only if necessary
const currentCore = await hre.ethers
.getContractAt("DisputeKitClassic", disputeKit.address)
.then((dk) => dk.core());
const currentCore = await hre.ethers.getContractAt("DisputeKitClassic", disputeKit.address).then((dk) => dk.core());
if (currentCore !== klerosCore.address) {
await execute(
"DisputeKitClassic",
{ from: deployer, log: true },
"changeCore",
klerosCore.address
);
await execute("DisputeKitClassic", { from: deployer, log: true }, "changeCore", klerosCore.address);
}

await deploy("DisputeResolver", {
Expand Down
11 changes: 0 additions & 11 deletions contracts/src/arbitration/IDisputeKit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ interface IDisputeKit {
uint256 _nbVotes
) external;

/// @dev Passes the phase.
function passPhase() external;

/// @dev Draws the juror from the sortition tree. The drawn address is picked up by Kleros Core.
/// Note: Access restricted to Kleros Core only.
/// @param _coreDisputeID The ID of the dispute in Kleros Core, not in the Dispute Kit.
Expand Down Expand Up @@ -121,12 +118,4 @@ interface IDisputeKit {
uint256 _coreRoundID,
uint256 _voteID
) external view returns (address account, bytes32 commit, uint256 choice, bool voted);

/// @dev Returns the number of disputes without jurors in the dispute kit.
/// @return The number of disputes without jurors in the dispute kit.
function disputesWithoutJurors() external view returns (uint256);

/// @dev Returns true if the dispute kit is ready to Resolve, regardless of the number of disputes without jurors.
/// @return Whether the dispute kit is ready to resolve, regardless of the number of disputes without jurors.
function isResolving() external view returns (bool);
}
38 changes: 38 additions & 0 deletions contracts/src/arbitration/ISortitionModule.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8;

interface ISortitionModule {
enum Phase {
staking, // Stake sum trees can be updated. Pass after `minStakingTime` passes and there is at least one dispute without jurors.
generating, // Waiting for a random number. Pass as soon as it is ready.
drawing // Jurors can be drawn. Pass after all disputes have jurors or `maxDrawingTime` passes.
}

enum Result {
// TODO: find a better name
None,
True,
False
}

function createTree(bytes32 _key, bytes memory _extraData) external;

function set(uint96 _courtID, uint256 _value, address _account) external;

function setJurorInactive(address _account) external;

function notifyRandomNumber(uint256 _drawnNumber) external;

function draw(bytes32 _court, uint256 _coreDisputeID, uint256 _voteID) external view returns (address);

function createDisputeHook(uint256 _disputeID, uint256 _roundID) external;

function postDrawHook(uint256 _disputeID, uint256 _roundID) external;

function preStakeHook(
address _account,
uint96 _courtID,
uint256 _stake,
uint256 _penalty
) external returns (Result);
}
Loading