Skip to content

Commit 3463bb2

Browse files
committed
refactor: moved UUPSProxiable to the base contracts
1 parent b38dd0c commit 3463bb2

15 files changed

+80
-78
lines changed

contracts/deploy/00-home-chain-arbitration-neo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
7373
deployer,
7474
deployer,
7575
pnk.target,
76-
ZeroAddress, // KlerosCore is configured later
76+
ZeroAddress, // jurorProsecutionModule is not implemented yet
7777
disputeKit.address,
7878
false,
7979
[minStake, alpha, feeForJuror, jurorsForCourtJump],
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { HardhatRuntimeEnvironment } from "hardhat/types";
2+
import { DeployFunction } from "hardhat-deploy/types";
3+
import { deployUpgradable } from "./utils/deployUpgradable";
4+
import { HomeChains, isSkipped } from "./utils";
5+
6+
const deployUpgradeDisputeKit: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
7+
const { deployments, getNamedAccounts, getChainId } = hre;
8+
9+
// fallback to hardhat node signers on local network
10+
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
11+
const chainId = Number(await getChainId());
12+
console.log("upgrading on %s with deployer %s", HomeChains[chainId], deployer);
13+
14+
try {
15+
console.log("upgrading DisputeKitClassicNeo...");
16+
await deployUpgradable(deployments, "DisputeKitClassicNeo", {
17+
newImplementation: "DisputeKitGated",
18+
initializer: "initialize",
19+
from: deployer,
20+
// Warning: do not reinitialize everything, only the new variables
21+
args: [],
22+
});
23+
} catch (err) {
24+
console.error(err);
25+
throw err;
26+
}
27+
};
28+
29+
deployUpgradeDisputeKit.tags = ["Upgrade", "DisputeKit"];
30+
deployUpgradeDisputeKit.skip = async ({ network }) => {
31+
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
32+
};
33+
34+
export default deployUpgradeDisputeKit;

contracts/deploy/upgrade-kleros-core.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,21 @@ import { deployUpgradable } from "./utils/deployUpgradable";
44
import { HomeChains, isSkipped } from "./utils";
55

66
const deployUpgradeKlerosCore: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
7-
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
8-
const { ZeroAddress } = hre.ethers;
7+
const { deployments, getNamedAccounts, getChainId } = hre;
98

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

1514
try {
16-
const pnk = await deployments.get("PNK");
17-
const disputeKit = await deployments.get("DisputeKitClassic");
18-
const minStake = 2n * 10n ** 20n;
19-
const alpha = 10000;
20-
const feeForJuror = 10n * 17n;
21-
const sortitionModule = await deployments.get("SortitionModule");
22-
23-
console.log("upgrading the KlerosCore...");
24-
await deployUpgradable(deployments, "KlerosCore", {
15+
console.log("upgrading KlerosCoreNeo...");
16+
await deployUpgradable(deployments, "KlerosCoreNeo", {
17+
newImplementation: "KlerosCoreNeo",
18+
initializer: "initialize",
2519
from: deployer,
26-
args: [
27-
deployer,
28-
pnk,
29-
ZeroAddress,
30-
disputeKit.address,
31-
false,
32-
[minStake, alpha, feeForJuror, 256], // minStake, alpha, feeForJuror, jurorsForCourtJump
33-
[0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
34-
ethers.toBeHex(5), // Extra data for sortition module will return the default value of K
35-
sortitionModule.address,
36-
],
20+
// Warning: do not reinitialize everything, only the new variables
21+
args: [],
3722
});
3823
} catch (err) {
3924
console.error(err);

contracts/deploy/upgrade-sortition-module.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,20 @@ import { HomeChains, isSkipped } from "./utils";
55

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

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

1514
try {
16-
const rng = await deployments.get("RandomizerRNG");
17-
const klerosCore = await deployments.get("KlerosCore");
18-
const klerosCoreAddress = klerosCore.address;
19-
20-
console.log("upgrading the SortitionModule...");
21-
await deployUpgradable(deployments, "SortitionModule", {
15+
console.log("upgrading SortitionModuleNeo...");
16+
await deployUpgradable(deployments, "SortitionModuleNeo", {
17+
newImplementation: "SortitionModuleNeo",
18+
initializer: "initialize",
2219
from: deployer,
23-
args: [
24-
deployer,
25-
klerosCoreAddress,
26-
1800, // minStakingTime
27-
1800, // maxFreezingTime
28-
rng.address,
29-
RNG_LOOKAHEAD,
30-
],
20+
// Warning: do not reinitialize everything, only the new variables
21+
args: [],
3122
});
3223
} catch (err) {
3324
console.error(err);

contracts/hardhat.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const config: HardhatUserConfig = {
9595
// Home chain ---------------------------------------------------------------------------------
9696
arbitrumSepolia: {
9797
chainId: 421614,
98-
url: process.env.ARBITRUM_SEPOLIA_RPC ?? "https://sepolia-rollup.arbitrum.io/rpc",
98+
url: process.env.ARBITRUM_SEPOLIA_RPC ?? `https://arbitrum-sepolia.infura.io/v3/${process.env.INFURA_API_KEY}`,
9999
accounts:
100100
(process.env.ARB_GOERLI_PRIVATE_KEY_WALLET_1 && [
101101
process.env.ARB_GOERLI_PRIVATE_KEY_WALLET_1 as string,
@@ -121,7 +121,7 @@ const config: HardhatUserConfig = {
121121
},
122122
arbitrumSepoliaDevnet: {
123123
chainId: 421614,
124-
url: process.env.ARBITRUM_SEPOLIA_RPC ?? "https://sepolia-rollup.arbitrum.io/rpc",
124+
url: process.env.ARBITRUM_SEPOLIA_RPC ?? `https://arbitrum-sepolia.infura.io/v3/${process.env.INFURA_API_KEY}`,
125125
accounts:
126126
(process.env.ARB_GOERLI_PRIVATE_KEY_WALLET_1 && [
127127
process.env.ARB_GOERLI_PRIVATE_KEY_WALLET_1 as string,
@@ -147,7 +147,7 @@ const config: HardhatUserConfig = {
147147
},
148148
arbitrum: {
149149
chainId: 42161,
150-
url: "https://arb1.arbitrum.io/rpc",
150+
url: process.env.ARBITRUM_RPC ?? `https://arbitrum-mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`,
151151
accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
152152
live: true,
153153
saveDeployments: true,

contracts/src/arbitration/KlerosCore.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88

99
pragma solidity 0.8.24;
1010

11-
import "./KlerosCoreBase.sol";
12-
import {UUPSProxiable} from "../proxy/UUPSProxiable.sol";
11+
import {KlerosCoreBase, IDisputeKit, ISortitionModule, IERC20} from "./KlerosCoreBase.sol";
1312

1413
/// @title KlerosCore
1514
/// Core arbitrator contract for Kleros v2.
1615
/// Note that this contract trusts the PNK token, the dispute kit and the sortition module contracts.
17-
contract KlerosCore is KlerosCoreBase, UUPSProxiable {
16+
contract KlerosCore is KlerosCoreBase {
1817
// ************************************* //
1918
// * Constructor * //
2019
// ************************************* //

contracts/src/arbitration/KlerosCoreBase.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import {IArbitrableV2, IArbitratorV2} from "./interfaces/IArbitratorV2.sol";
1212
import {IDisputeKit} from "./interfaces/IDisputeKit.sol";
1313
import {ISortitionModule} from "./interfaces/ISortitionModule.sol";
1414
import {Initializable} from "../proxy/Initializable.sol";
15+
import {UUPSProxiable} from "../proxy/UUPSProxiable.sol";
1516
import {SafeERC20, IERC20} from "../libraries/SafeERC20.sol";
1617
import "../libraries/Constants.sol";
1718

1819
/// @title KlerosCoreBase
1920
/// Core arbitrator contract for Kleros v2.
2021
/// Note that this contract trusts the PNK token, the dispute kit and the sortition module contracts.
21-
abstract contract KlerosCoreBase is IArbitratorV2, Initializable {
22+
abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable {
2223
using SafeERC20 for IERC20;
2324

2425
// ************************************* //

contracts/src/arbitration/KlerosCoreNeo.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88

99
pragma solidity 0.8.24;
1010

11-
import "./KlerosCoreBase.sol";
12-
import {UUPSProxiable} from "../proxy/UUPSProxiable.sol";
11+
import {KlerosCoreBase, IDisputeKit, ISortitionModule, IERC20, OnError, StakingResult} from "./KlerosCoreBase.sol";
1312
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
1413

1514
/// @title KlerosCoreNeo
1615
/// Core arbitrator contract for Kleros v2.
1716
/// Note that this contract trusts the PNK token, the dispute kit and the sortition module contracts.
18-
contract KlerosCoreNeo is KlerosCoreBase, UUPSProxiable {
17+
contract KlerosCoreNeo is KlerosCoreBase {
1918
// ************************************* //
2019
// * Storage * //
2120
// ************************************* //

contracts/src/arbitration/SortitionModule.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
pragma solidity 0.8.24;
1212

13-
import "./SortitionModuleBase.sol";
14-
import "../proxy/UUPSProxiable.sol";
13+
import {SortitionModuleBase, KlerosCore, RNG} from "./SortitionModuleBase.sol";
1514

1615
/// @title SortitionModule
1716
/// @dev A factory of trees that keeps track of staked values for sortition.
18-
contract SortitionModule is SortitionModuleBase, UUPSProxiable {
17+
contract SortitionModule is SortitionModuleBase {
1918
// ************************************* //
2019
// * Constructor * //
2120
// ************************************* //

contracts/src/arbitration/SortitionModuleBase.sol

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010

1111
pragma solidity 0.8.24;
1212

13-
import "./KlerosCore.sol";
14-
import "./interfaces/ISortitionModule.sol";
15-
import "./interfaces/IDisputeKit.sol";
16-
import "../proxy/Initializable.sol";
17-
import "../rng/RNG.sol";
13+
import {KlerosCore} from "./KlerosCore.sol";
14+
import {ISortitionModule} from "./interfaces/ISortitionModule.sol";
15+
import {IDisputeKit} from "./interfaces/IDisputeKit.sol";
16+
import {Initializable} from "../proxy/Initializable.sol";
17+
import {UUPSProxiable} from "../proxy/UUPSProxiable.sol";
18+
import {RNG} from "../rng/RNG.sol";
1819
import "../libraries/Constants.sol";
1920

2021
/// @title SortitionModuleBase
2122
/// @dev A factory of trees that keeps track of staked values for sortition.
22-
abstract contract SortitionModuleBase is ISortitionModule, Initializable {
23+
abstract contract SortitionModuleBase is ISortitionModule, Initializable, UUPSProxiable {
2324
// ************************************* //
2425
// * Enums / Structs * //
2526
// ************************************* //

contracts/src/arbitration/SortitionModuleNeo.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
pragma solidity 0.8.24;
1212

13-
import "./SortitionModuleBase.sol";
14-
import "../proxy/UUPSProxiable.sol";
13+
import {SortitionModuleBase, KlerosCore, RNG, StakingResult} from "./SortitionModuleBase.sol";
1514

1615
/// @title SortitionModuleNeo
1716
/// @dev A factory of trees that keeps track of staked values for sortition.
18-
contract SortitionModuleNeo is SortitionModuleBase, UUPSProxiable {
17+
contract SortitionModuleNeo is SortitionModuleBase {
1918
// ************************************* //
2019
// * Storage * //
2120
// ************************************* //

contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88

99
pragma solidity 0.8.24;
1010

11-
import "./DisputeKitClassicBase.sol";
12-
import "../KlerosCore.sol";
13-
import "../../proxy/UUPSProxiable.sol";
11+
import {DisputeKitClassicBase, KlerosCore} from "./DisputeKitClassicBase.sol";
1412

1513
/// @title DisputeKitClassic
1614
/// Dispute kit implementation of the Kleros v1 features including:
1715
/// - a drawing system: proportional to staked PNK,
1816
/// - a vote aggregation system: plurality,
1917
/// - an incentive system: equal split between coherent votes,
2018
/// - an appeal system: fund 2 choices only, vote on any choice.
21-
contract DisputeKitClassic is DisputeKitClassicBase, UUPSProxiable {
19+
contract DisputeKitClassic is DisputeKitClassicBase {
2220
// ************************************* //
2321
// * Constructor * //
2422
// ************************************* //

contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88

99
pragma solidity 0.8.24;
1010

11-
import "../KlerosCore.sol";
12-
import "../interfaces/IDisputeKit.sol";
13-
import "../../proxy/Initializable.sol";
11+
import {KlerosCore, KlerosCoreBase, IDisputeKit, ISortitionModule} from "../KlerosCore.sol";
12+
import {Initializable} from "../../proxy/Initializable.sol";
13+
import {UUPSProxiable} from "../../proxy/UUPSProxiable.sol";
1414

1515
/// @title DisputeKitClassicBase
1616
/// Abstract Dispute kit classic implementation of the Kleros v1 features including:
1717
/// - a drawing system: proportional to staked PNK,
1818
/// - a vote aggregation system: plurality,
1919
/// - an incentive system: equal split between coherent votes,
2020
/// - an appeal system: fund 2 choices only, vote on any choice.
21-
abstract contract DisputeKitClassicBase is IDisputeKit, Initializable {
21+
abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxiable {
2222
// ************************************* //
2323
// * Structs * //
2424
// ************************************* //

contracts/src/arbitration/dispute-kits/DisputeKitGated.sol

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
pragma solidity 0.8.24;
1010

11-
import "./DisputeKitClassicBase.sol";
12-
import "../KlerosCore.sol";
13-
import "../../proxy/UUPSProxiable.sol";
11+
import {DisputeKitClassicBase, KlerosCore} from "./DisputeKitClassicBase.sol";
1412

1513
interface IERC20OrERC721 {
1614
/// @dev Returns the number of tokens in `owner` account.
@@ -33,7 +31,7 @@ interface IERC1155 {
3331
/// - a vote aggregation system: plurality,
3432
/// - an incentive system: equal split between coherent votes,
3533
/// - an appeal system: fund 2 choices only, vote on any choice.
36-
contract DisputeKitGated is DisputeKitClassicBase, UUPSProxiable {
34+
contract DisputeKitGated is DisputeKitClassicBase {
3735
// ************************************* //
3836
// * Storage * //
3937
// ************************************* //

contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
pragma solidity 0.8.24;
1010

11-
import "./DisputeKitClassicBase.sol";
12-
import "../KlerosCore.sol";
13-
import "../../proxy/UUPSProxiable.sol";
11+
import {DisputeKitClassicBase, KlerosCore} from "./DisputeKitClassicBase.sol";
1412

1513
interface IProofOfHumanity {
1614
/// @dev Return true if the submission is registered and not expired.
@@ -25,7 +23,7 @@ interface IProofOfHumanity {
2523
/// - a vote aggregation system: plurality,
2624
/// - an incentive system: equal split between coherent votes,
2725
/// - an appeal system: fund 2 choices only, vote on any choice.
28-
contract DisputeKitSybilResistant is DisputeKitClassicBase, UUPSProxiable {
26+
contract DisputeKitSybilResistant is DisputeKitClassicBase {
2927
// ************************************* //
3028
// * Storage * //
3129
// ************************************* //

0 commit comments

Comments
 (0)