Skip to content
2 changes: 1 addition & 1 deletion contracts/deploy/00-home-chain-arbitration-neo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
deployer,
deployer,
pnk.target,
ZeroAddress, // KlerosCore is configured later
ZeroAddress, // jurorProsecutionModule is not implemented yet
disputeKit.address,
false,
[minStake, alpha, feeForJuror, jurorsForCourtJump],
Expand Down
34 changes: 34 additions & 0 deletions contracts/deploy/upgrade-dispute-kit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { deployUpgradable } from "./utils/deployUpgradable";
import { HomeChains, isSkipped } from "./utils";

const deployUpgradeDisputeKit: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts, getChainId } = hre;

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

try {
console.log("upgrading DisputeKitClassicNeo...");
await deployUpgradable(deployments, "DisputeKitClassicNeo", {
newImplementation: "DisputeKitGated",
initializer: "initialize",
from: deployer,
// Warning: do not reinitialize everything, only the new variables
args: [],
});
} catch (err) {
console.error(err);
throw err;
}
};

deployUpgradeDisputeKit.tags = ["Upgrade", "DisputeKit"];
deployUpgradeDisputeKit.skip = async ({ network }) => {
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
};

export default deployUpgradeDisputeKit;
31 changes: 8 additions & 23 deletions contracts/deploy/upgrade-kleros-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,21 @@ import { deployUpgradable } from "./utils/deployUpgradable";
import { HomeChains, isSkipped } from "./utils";

const deployUpgradeKlerosCore: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
const { ZeroAddress } = hre.ethers;
const { deployments, getNamedAccounts, getChainId } = hre;

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

try {
const pnk = await deployments.get("PNK");
const disputeKit = await deployments.get("DisputeKitClassic");
const minStake = 2n * 10n ** 20n;
const alpha = 10000;
const feeForJuror = 10n * 17n;
const sortitionModule = await deployments.get("SortitionModule");

console.log("upgrading the KlerosCore...");
await deployUpgradable(deployments, "KlerosCore", {
console.log("upgrading KlerosCoreNeo...");
await deployUpgradable(deployments, "KlerosCoreNeo", {
newImplementation: "KlerosCoreNeo",
initializer: "initialize",
from: deployer,
args: [
deployer,
pnk,
ZeroAddress,
disputeKit.address,
false,
[minStake, alpha, feeForJuror, 256], // minStake, alpha, feeForJuror, jurorsForCourtJump
[0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
ethers.toBeHex(5), // Extra data for sortition module will return the default value of K
sortitionModule.address,
],
// Warning: do not reinitialize everything, only the new variables
args: [],
});
} catch (err) {
console.error(err);
Expand Down
23 changes: 7 additions & 16 deletions contracts/deploy/upgrade-sortition-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,20 @@ import { HomeChains, isSkipped } from "./utils";

const deployUpgradeSortitionModule: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts, getChainId } = hre;
const RNG_LOOKAHEAD = 20;

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

try {
const rng = await deployments.get("RandomizerRNG");
const klerosCore = await deployments.get("KlerosCore");
const klerosCoreAddress = klerosCore.address;

console.log("upgrading the SortitionModule...");
await deployUpgradable(deployments, "SortitionModule", {
console.log("upgrading SortitionModuleNeo...");
await deployUpgradable(deployments, "SortitionModuleNeo", {
newImplementation: "SortitionModuleNeo",
initializer: "initialize",
from: deployer,
args: [
deployer,
klerosCoreAddress,
1800, // minStakingTime
1800, // maxFreezingTime
rng.address,
RNG_LOOKAHEAD,
],
// Warning: do not reinitialize everything, only the new variables
args: [],
});
} catch (err) {
console.error(err);
Expand Down
6 changes: 3 additions & 3 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const config: HardhatUserConfig = {
// Home chain ---------------------------------------------------------------------------------
arbitrumSepolia: {
chainId: 421614,
url: process.env.ARBITRUM_SEPOLIA_RPC ?? "https://sepolia-rollup.arbitrum.io/rpc",
url: process.env.ARBITRUM_SEPOLIA_RPC ?? `https://arbitrum-sepolia.infura.io/v3/${process.env.INFURA_API_KEY}`,
accounts:
(process.env.ARB_GOERLI_PRIVATE_KEY_WALLET_1 && [
process.env.ARB_GOERLI_PRIVATE_KEY_WALLET_1 as string,
Expand All @@ -121,7 +121,7 @@ const config: HardhatUserConfig = {
},
arbitrumSepoliaDevnet: {
chainId: 421614,
url: process.env.ARBITRUM_SEPOLIA_RPC ?? "https://sepolia-rollup.arbitrum.io/rpc",
url: process.env.ARBITRUM_SEPOLIA_RPC ?? `https://arbitrum-sepolia.infura.io/v3/${process.env.INFURA_API_KEY}`,
accounts:
(process.env.ARB_GOERLI_PRIVATE_KEY_WALLET_1 && [
process.env.ARB_GOERLI_PRIVATE_KEY_WALLET_1 as string,
Expand All @@ -147,7 +147,7 @@ const config: HardhatUserConfig = {
},
arbitrum: {
chainId: 42161,
url: "https://arb1.arbitrum.io/rpc",
url: process.env.ARBITRUM_RPC ?? `https://arbitrum-mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`,
accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
live: true,
saveDeployments: true,
Expand Down
8 changes: 3 additions & 5 deletions contracts/src/arbitration/KlerosCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@

pragma solidity 0.8.24;

import "./KlerosCoreBase.sol";
import {UUPSProxiable} from "../proxy/UUPSProxiable.sol";
import {Initializable} from "../proxy/Initializable.sol";
import {KlerosCoreBase, IDisputeKit, ISortitionModule, IERC20} from "./KlerosCoreBase.sol";

/// @title KlerosCore
/// Core arbitrator contract for Kleros v2.
/// Note that this contract trusts the PNK token, the dispute kit and the sortition module contracts.
contract KlerosCore is KlerosCoreBase, UUPSProxiable, Initializable {
contract KlerosCore is KlerosCoreBase {
// ************************************* //
// * Constructor * //
// ************************************* //
Expand Down Expand Up @@ -48,7 +46,7 @@ contract KlerosCore is KlerosCoreBase, UUPSProxiable, Initializable {
bytes memory _sortitionExtraData,
ISortitionModule _sortitionModuleAddress
) external reinitializer(1) {
_initialize(
__KlerosCoreBase_initialize(
_governor,
_guardian,
_pinakion,
Expand Down
8 changes: 5 additions & 3 deletions contracts/src/arbitration/KlerosCoreBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ pragma solidity 0.8.24;
import {IArbitrableV2, IArbitratorV2} from "./interfaces/IArbitratorV2.sol";
import {IDisputeKit} from "./interfaces/IDisputeKit.sol";
import {ISortitionModule} from "./interfaces/ISortitionModule.sol";
import {Initializable} from "../proxy/Initializable.sol";
import {UUPSProxiable} from "../proxy/UUPSProxiable.sol";
import {SafeERC20, IERC20} from "../libraries/SafeERC20.sol";
import "../libraries/Constants.sol";

/// @title KlerosCoreBase
/// Core arbitrator contract for Kleros v2.
/// Note that this contract trusts the PNK token, the dispute kit and the sortition module contracts.
abstract contract KlerosCoreBase is IArbitratorV2 {
abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable {
using SafeERC20 for IERC20;

// ************************************* //
Expand Down Expand Up @@ -193,7 +195,7 @@ abstract contract KlerosCoreBase is IArbitratorV2 {
// * Constructor * //
// ************************************* //

function _initialize(
function __KlerosCoreBase_initialize(
address _governor,
address _guardian,
IERC20 _pinakion,
Expand All @@ -204,7 +206,7 @@ abstract contract KlerosCoreBase is IArbitratorV2 {
uint256[4] memory _timesPerPeriod,
bytes memory _sortitionExtraData,
ISortitionModule _sortitionModuleAddress
) internal {
) internal onlyInitializing {
governor = _governor;
guardian = _guardian;
pinakion = _pinakion;
Expand Down
8 changes: 3 additions & 5 deletions contracts/src/arbitration/KlerosCoreNeo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@

pragma solidity 0.8.24;

import "./KlerosCoreBase.sol";
import {UUPSProxiable} from "../proxy/UUPSProxiable.sol";
import {Initializable} from "../proxy/Initializable.sol";
import {KlerosCoreBase, IDisputeKit, ISortitionModule, IERC20, OnError, StakingResult} from "./KlerosCoreBase.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

/// @title KlerosCoreNeo
/// Core arbitrator contract for Kleros v2.
/// Note that this contract trusts the PNK token, the dispute kit and the sortition module contracts.
contract KlerosCoreNeo is KlerosCoreBase, UUPSProxiable, Initializable {
contract KlerosCoreNeo is KlerosCoreBase {
// ************************************* //
// * Storage * //
// ************************************* //
Expand Down Expand Up @@ -58,7 +56,7 @@ contract KlerosCoreNeo is KlerosCoreBase, UUPSProxiable, Initializable {
ISortitionModule _sortitionModuleAddress,
IERC721 _jurorNft
) external reinitializer(2) {
super._initialize(
__KlerosCoreBase_initialize(
_governor,
_guardian,
_pinakion,
Expand Down
8 changes: 3 additions & 5 deletions contracts/src/arbitration/SortitionModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@

pragma solidity 0.8.24;

import "./SortitionModuleBase.sol";
import "../proxy/UUPSProxiable.sol";
import "../proxy/Initializable.sol";
import {SortitionModuleBase, KlerosCore, RNG} from "./SortitionModuleBase.sol";

/// @title SortitionModule
/// @dev A factory of trees that keeps track of staked values for sortition.
contract SortitionModule is SortitionModuleBase, UUPSProxiable, Initializable {
contract SortitionModule is SortitionModuleBase {
// ************************************* //
// * Constructor * //
// ************************************* //
Expand All @@ -41,7 +39,7 @@ contract SortitionModule is SortitionModuleBase, UUPSProxiable, Initializable {
RNG _rng,
uint256 _rngLookahead
) external reinitializer(1) {
super._initialize(_governor, _core, _minStakingTime, _maxDrawingTime, _rng, _rngLookahead);
__SortitionModuleBase_initialize(_governor, _core, _minStakingTime, _maxDrawingTime, _rng, _rngLookahead);
}

// ************************************* //
Expand Down
16 changes: 9 additions & 7 deletions contracts/src/arbitration/SortitionModuleBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@

pragma solidity 0.8.24;

import "./KlerosCore.sol";
import "./interfaces/ISortitionModule.sol";
import "./interfaces/IDisputeKit.sol";
import "../rng/RNG.sol";
import {KlerosCore} from "./KlerosCore.sol";
import {ISortitionModule} from "./interfaces/ISortitionModule.sol";
import {IDisputeKit} from "./interfaces/IDisputeKit.sol";
import {Initializable} from "../proxy/Initializable.sol";
import {UUPSProxiable} from "../proxy/UUPSProxiable.sol";
import {RNG} from "../rng/RNG.sol";
import "../libraries/Constants.sol";

/// @title SortitionModuleBase
/// @dev A factory of trees that keeps track of staked values for sortition.
abstract contract SortitionModuleBase is ISortitionModule {
abstract contract SortitionModuleBase is ISortitionModule, Initializable, UUPSProxiable {
// ************************************* //
// * Enums / Structs * //
// ************************************* //
Expand Down Expand Up @@ -89,14 +91,14 @@ abstract contract SortitionModuleBase is ISortitionModule {
// * Constructor * //
// ************************************* //

function _initialize(
function __SortitionModuleBase_initialize(
address _governor,
KlerosCore _core,
uint256 _minStakingTime,
uint256 _maxDrawingTime,
RNG _rng,
uint256 _rngLookahead
) internal {
) internal onlyInitializing {
governor = _governor;
core = _core;
minStakingTime = _minStakingTime;
Expand Down
8 changes: 3 additions & 5 deletions contracts/src/arbitration/SortitionModuleNeo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@

pragma solidity 0.8.24;

import "./SortitionModuleBase.sol";
import "../proxy/UUPSProxiable.sol";
import "../proxy/Initializable.sol";
import {SortitionModuleBase, KlerosCore, RNG, StakingResult} from "./SortitionModuleBase.sol";

/// @title SortitionModuleNeo
/// @dev A factory of trees that keeps track of staked values for sortition.
contract SortitionModuleNeo is SortitionModuleBase, UUPSProxiable, Initializable {
contract SortitionModuleNeo is SortitionModuleBase {
// ************************************* //
// * Storage * //
// ************************************* //
Expand Down Expand Up @@ -53,7 +51,7 @@ contract SortitionModuleNeo is SortitionModuleBase, UUPSProxiable, Initializable
uint256 _maxStakePerJuror,
uint256 _maxTotalStaked
) external reinitializer(2) {
super._initialize(_governor, _core, _minStakingTime, _maxDrawingTime, _rng, _rngLookahead);
__SortitionModuleBase_initialize(_governor, _core, _minStakingTime, _maxDrawingTime, _rng, _rngLookahead);
maxStakePerJuror = _maxStakePerJuror;
maxTotalStaked = _maxTotalStaked;
}
Expand Down
Loading