Skip to content

Commit 76763b6

Browse files
committed
refactor: extracted some constants, tweaked contract size optimizations
1 parent 0a1642f commit 76763b6

File tree

8 files changed

+82
-75
lines changed

8 files changed

+82
-75
lines changed

contracts/deploy/01-foreign-gateway-on-ethereum.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import getContractAddress from "./utils/getContractAddress";
44
import { KlerosCore__factory } from "../typechain-types";
5-
import { ForeignChains, isSkipped } from "./utils";
5+
import { Courts, ForeignChains, isSkipped } from "./utils";
66
import { deployUpgradable } from "./utils/deployUpgradable";
77

88
const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
@@ -46,9 +46,8 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
4646
const coreDeployment = await hre.companionNetworks.home.deployments.get("KlerosCore");
4747
const core = await KlerosCore__factory.connect(coreDeployment.address, homeChainProvider);
4848
// TODO: set up the correct fees for the FORKING_COURT
49-
const courtId = await core.GENERAL_COURT();
50-
const fee = (await core.courts(courtId)).feeForJuror;
51-
await execute("ForeignGatewayOnEthereum", { from: deployer, log: true }, "changeCourtJurorFee", courtId, fee);
49+
const fee = (await core.courts(Courts.GENERAL)).feeForJuror;
50+
await execute("ForeignGatewayOnEthereum", { from: deployer, log: true }, "changeCourtJurorFee", Courts.GENERAL, fee);
5251
// TODO: set up the correct fees for the lower courts
5352
};
5453

contracts/deploy/01-foreign-gateway-on-gnosis.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
33
import { DeployFunction } from "hardhat-deploy/types";
44
import getContractAddress from "./utils/getContractAddress";
55
import { KlerosCore__factory } from "../typechain-types";
6-
import { ForeignChains, isSkipped } from "./utils";
6+
import { Courts, ForeignChains, isSkipped } from "./utils";
77
import { deployUpgradable } from "./utils/deployUpgradable";
88

99
const ONE_GWEI = parseUnits("1", "gwei");
@@ -50,9 +50,8 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
5050
const coreDeployment = await hre.companionNetworks.home.deployments.get("KlerosCore");
5151
const core = await KlerosCore__factory.connect(coreDeployment.address, homeChainProvider);
5252
// TODO: set up the correct fees for the FORKING_COURT
53-
const courtId = await core.GENERAL_COURT();
54-
const fee = (await core.courts(courtId)).feeForJuror;
55-
await execute("ForeignGatewayOnGnosis", { from: deployer, log: true }, "changeCourtJurorFee", courtId, fee);
53+
const fee = (await core.courts(Courts.GENERAL)).feeForJuror;
54+
await execute("ForeignGatewayOnGnosis", { from: deployer, log: true }, "changeCourtJurorFee", Courts.GENERAL, fee);
5655
// TODO: set up the correct fees for the lower courts
5756
};
5857

contracts/deploy/03-vea-mock.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DeployFunction } from "hardhat-deploy/types";
33
import getContractAddress from "./utils/getContractAddress";
44
import { KlerosCore__factory } from "../typechain-types";
55
import disputeTemplate from "../test/fixtures/DisputeTemplate.simple.json";
6-
import { HardhatChain, isSkipped } from "./utils";
6+
import { Courts, HardhatChain, isSkipped } from "./utils";
77
import { deployUpgradable } from "./utils/deployUpgradable";
88

99
// TODO: use deterministic deployments
@@ -58,9 +58,8 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
5858
const signer = (await hre.ethers.getSigners())[0];
5959
const core = await KlerosCore__factory.connect(klerosCore.address, signer);
6060
// TODO: set up the correct fees for the FORKING_COURT
61-
const courtId = await core.GENERAL_COURT();
62-
const fee = (await core.courts(courtId)).feeForJuror;
63-
await execute("ForeignGatewayOnEthereum", { from: deployer, log: true }, "changeCourtJurorFee", courtId, fee);
61+
const fee = (await core.courts(Courts.GENERAL)).feeForJuror;
62+
await execute("ForeignGatewayOnEthereum", { from: deployer, log: true }, "changeCourtJurorFee", Courts.GENERAL, fee);
6463
// TODO: set up the correct fees for the lower courts
6564

6665
const disputeTemplateRegistry = await deployUpgradable(hre, "DisputeTemplateRegistry", {

contracts/deploy/utils/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ export enum ForeignChains {
2020
HARDHAT = HardhatChain.HARDHAT,
2121
}
2222

23+
export enum Courts {
24+
FORKING = 0,
25+
GENERAL = 1,
26+
}
27+
2328
export const isSkipped = async (network: Network, skip: boolean) => {
2429
if (skip) {
2530
console.error(`Error: incompatible network ${network.name} for this deployment script`);

contracts/src/arbitration/KlerosCore.sol

+47-58
Large diffs are not rendered by default.

contracts/src/arbitration/SortitionModule.sol

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import "./interfaces/IDisputeKit.sol";
1616
import "../rng/RNG.sol";
1717
import "../proxy/UUPSProxiable.sol";
1818
import "../proxy/Initializable.sol";
19+
import "../libraries/Constants.sol";
1920

2021
/// @title SortitionModule
2122
/// @dev A factory of trees that keeps track of staked values for sortition.
@@ -254,7 +255,7 @@ contract SortitionModule is ISortitionModule, UUPSProxiable, Initializable {
254255
while (!finished) {
255256
// Tokens are also implicitly staked in parent courts through sortition module to increase the chance of being drawn.
256257
_set(bytes32(uint256(currenCourtID)), _value, stakePathID);
257-
if (currenCourtID == core.GENERAL_COURT()) {
258+
if (currenCourtID == Constants.GENERAL_COURT) {
258259
finished = true;
259260
} else {
260261
(currenCourtID, , , , , , ) = core.courts(currenCourtID);

contracts/src/libraries/Constants.sol

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity 0.8.18;
4+
5+
/// @title Constants
6+
library Constants {
7+
// Courts
8+
uint96 public constant FORKING_COURT = 0; // Index of the forking court.
9+
uint96 public constant GENERAL_COURT = 1; // Index of the default (general) court.
10+
11+
// Dispute Kits
12+
uint256 public constant NULL_DISPUTE_KIT = 0; // Null pattern to indicate a top-level DK which has no parent.
13+
uint256 public constant DISPUTE_KIT_CLASSIC = 1; // Index of the default DK. 0 index is skipped.
14+
15+
// Defaults
16+
uint256 public constant DEFAULT_NB_OF_JURORS = 3; // The default number of jurors in a dispute.
17+
}

contracts/test/arbitration/draw.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "../../typechain-types";
1212
import { expect } from "chai";
1313
import { DrawEvent } from "../../typechain-types/src/kleros-v1/kleros-liquid-xdai/XKlerosLiquidV2";
14+
import { Courts } from "../../deploy/utils";
1415

1516
/* eslint-disable no-unused-vars */
1617
/* eslint-disable no-unused-expressions */ // https://github.com/standard/standard/issues/690#issuecomment-278533482
@@ -67,10 +68,7 @@ describe("Draw Benchmark", async () => {
6768
arbitrable = (await ethers.getContract("ArbitrableExample")) as ArbitrableExample;
6869
sortitionModule = (await ethers.getContract("SortitionModule")) as SortitionModule;
6970

70-
parentCourtMinStake = await core
71-
.GENERAL_COURT()
72-
.then((courtId) => core.courts(courtId))
73-
.then((court) => court.minStake);
71+
parentCourtMinStake = await core.courts(Courts.GENERAL).then((court) => court.minStake);
7472

7573
childCourtMinStake = BigNumber.from(10).pow(20).mul(3); // 300 PNK
7674

0 commit comments

Comments
 (0)