Skip to content

Commit db0c0ce

Browse files
authored
Merge branch 'dev' into feat(web)/dashboard-pixelart
2 parents a78bdff + 51ef929 commit db0c0ce

28 files changed

+478
-150
lines changed

contracts/deploy/00-home-chain-arbitrable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
1818
"0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003"; // General court, 3 jurors
1919
const weth = await deployments.get("WETH");
2020

21-
const disputeTemplateRegistry = await deployUpgradable(hre, "DisputeTemplateRegistry", {
21+
const disputeTemplateRegistry = await deployUpgradable(deployments, "DisputeTemplateRegistry", {
2222
from: deployer,
2323
args: [deployer],
2424
log: true,

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
5252
randomizerByChain.set(HomeChains[HomeChains[chainId]], randomizerMock.address);
5353
}
5454

55-
await deployUpgradable(hre, "PolicyRegistry", { from: deployer, args: [deployer], log: true });
55+
await deployUpgradable(deployments, "PolicyRegistry", { from: deployer, args: [deployer], log: true });
5656

5757
const randomizer = randomizerByChain.get(Number(await getChainId())) ?? AddressZero;
58-
const rng = await deployUpgradable(hre, "RandomizerRNG", { from: deployer, args: [randomizer, deployer], log: true });
58+
const rng = await deployUpgradable(deployments, "RandomizerRNG", {
59+
from: deployer,
60+
args: [randomizer, deployer],
61+
log: true,
62+
});
5963

60-
const disputeKit = await deployUpgradable(hre, "DisputeKitClassic", {
64+
const disputeKit = await deployUpgradable(deployments, "DisputeKitClassic", {
6165
from: deployer,
6266
args: [deployer, AddressZero],
6367
log: true,
@@ -72,7 +76,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
7276
const devnet = isDevnet(hre.network);
7377
const minStakingTime = devnet ? 180 : 1800;
7478
const maxFreezingTime = devnet ? 600 : 1800;
75-
const sortitionModule = await deployUpgradable(hre, "SortitionModule", {
79+
const sortitionModule = await deployUpgradable(deployments, "SortitionModule", {
7680
from: deployer,
7781
args: [deployer, klerosCoreAddress, minStakingTime, maxFreezingTime, rng.address, RNG_LOOKAHEAD],
7882
log: true,
@@ -84,7 +88,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
8488
const minStake = BigNumber.from(10).pow(20).mul(2);
8589
const alpha = 10000;
8690
const feeForJuror = BigNumber.from(10).pow(17);
87-
const klerosCore = await deployUpgradable(hre, "KlerosCore", {
91+
const klerosCore = await deployUpgradable(deployments, "KlerosCore", {
8892
from: deployer,
8993
args: [
9094
deployer,

contracts/deploy/00-rng.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
4848
}
4949

5050
const randomizer = randomizerByChain.get(Number(await getChainId())) ?? AddressZero;
51-
await deployUpgradable(hre, "RandomizerRNG", { from: deployer, args: [randomizer, deployer], log: true });
51+
await deployUpgradable(deployments, "RandomizerRNG", { from: deployer, args: [randomizer, deployer], log: true });
5252
const rng = await deploy("BlockHashRNG", {
5353
from: deployer,
5454
args: [],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
3030

3131
const homeChainId = (await homeChainProvider.getNetwork()).chainId;
3232
const homeChainIdAsBytes32 = hexZeroPad(hexlify(homeChainId), 32);
33-
await deployUpgradable(hre, "ForeignGatewayOnEthereum", {
33+
await deployUpgradable(deployments, "ForeignGatewayOnEthereum", {
3434
from: deployer,
3535
contract: "ForeignGateway",
3636
args: [deployer, veaOutbox.address, homeChainIdAsBytes32, homeGatewayAddress],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
3333

3434
const homeChainId = (await homeChainProvider.getNetwork()).chainId;
3535
const homeChainIdAsBytes32 = hexZeroPad(hexlify(homeChainId), 32);
36-
await deployUpgradable(hre, "ForeignGatewayOnGnosis", {
36+
await deployUpgradable(deployments, "ForeignGatewayOnGnosis", {
3737
from: deployer,
3838
contract: "ForeignGateway",
3939
args: [deployer, veaOutbox.address, homeChainIdAsBytes32, homeGatewayAddress],

contracts/deploy/02-home-gateway-to-ethereum.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
2323
const foreignChainName = await hre.companionNetworks.foreignGoerli.deployments.getNetworkName();
2424
console.log("Using ForeignGateway %s on chainId %s (%s)", foreignGateway.address, foreignChainId, foreignChainName);
2525

26-
await deployUpgradable(hre, "HomeGatewayToEthereum", {
26+
await deployUpgradable(deployments, "HomeGatewayToEthereum", {
2727
from: deployer,
2828
contract: "HomeGateway",
2929
args: [

contracts/deploy/02-home-gateway-to-gnosis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
2323
const foreignChainName = await hre.companionNetworks.foreignChiado.deployments.getNetworkName();
2424
console.log("Using ForeignGateway %s on chainId %s (%s)", foreignGateway.address, foreignChainId, foreignChainName);
2525

26-
await deployUpgradable(hre, "HomeGatewayToGnosis", {
26+
await deployUpgradable(deployments, "HomeGatewayToGnosis", {
2727
from: deployer,
2828
contract: "HomeGateway",
2929
args: [deployer, klerosCore.address, veaInbox.address, foreignChainId, foreignGateway.address, dai.address],

contracts/deploy/03-vea-mock.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
3030
console.log("Calculated future HomeGatewayToEthereum address for nonce %d: %s", nonce, homeGatewayAddress);
3131

3232
const homeChainIdAsBytes32 = hexZeroPad(hexlify(HardhatChain.HARDHAT), 32);
33-
const foreignGateway = await deployUpgradable(hre, "ForeignGatewayOnEthereum", {
33+
const foreignGateway = await deployUpgradable(deployments, "ForeignGatewayOnEthereum", {
3434
from: deployer,
3535
contract: "ForeignGateway",
3636
args: [deployer, vea.address, homeChainIdAsBytes32, homeGatewayAddress],
@@ -39,7 +39,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
3939
}); // nonce (implementation), nonce+1 (proxy)
4040
console.log("foreignGateway.address: ", foreignGateway.address);
4141

42-
await deployUpgradable(hre, "HomeGatewayToEthereum", {
42+
await deployUpgradable(deployments, "HomeGatewayToEthereum", {
4343
from: deployer,
4444
contract: "HomeGateway",
4545
args: [
@@ -62,7 +62,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
6262
await execute("ForeignGatewayOnEthereum", { from: deployer, log: true }, "changeCourtJurorFee", Courts.GENERAL, fee);
6363
// TODO: set up the correct fees for the lower courts
6464

65-
const disputeTemplateRegistry = await deployUpgradable(hre, "DisputeTemplateRegistry", {
65+
const disputeTemplateRegistry = await deployUpgradable(deployments, "DisputeTemplateRegistry", {
6666
from: deployer,
6767
args: [deployer],
6868
log: true,

contracts/deploy/upgrade-kleros-core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const deployUpgradeKlerosCore: DeployFunction = async (hre: HardhatRuntimeEnviro
2828
const sortitionModule = await deployments.get("SortitionModule");
2929

3030
console.log("Upgrading the KlerosCore...");
31-
await deployUpgradable(hre, "KlerosCore", {
31+
await deployUpgradable(deployments, "KlerosCore", {
3232
from: deployer,
3333
args: [
3434
deployer,

contracts/deploy/upgrade-sortition-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const deployUpgradeSortitionModule: DeployFunction = async (hre: HardhatRuntimeE
2424
const klerosCoreAddress = klerosCore.address;
2525

2626
console.log("Upgrading the SortitionModule...");
27-
await deployUpgradable(hre, "SortitionModule", {
27+
await deployUpgradable(deployments, "SortitionModule", {
2828
from: deployer,
2929
args: [
3030
deployer,
Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,70 @@
1-
import { DeployResult, DeployOptions } from "hardhat-deploy/types";
2-
import { HardhatRuntimeEnvironment } from "hardhat/types";
3-
4-
export function deployUpgradable(
5-
hre: HardhatRuntimeEnvironment,
6-
contract: string,
7-
options: DeployOptions
8-
): Promise<DeployResult> {
9-
const { deploy } = hre.deployments;
10-
const { args, ...otherOptions } = options;
11-
return deploy(contract, {
1+
import {
2+
DeployResult,
3+
DeployOptions,
4+
DeploymentsExtension,
5+
DeployOptionsBase,
6+
ProxyOptions,
7+
} from "hardhat-deploy/types";
8+
9+
// Rationale: https://github.com/kleros/kleros-v2/pull/1214#issue-1879116629
10+
const PROXY_OPTIONS: ProxyOptions = {
11+
proxyContract: "UUPSProxy",
12+
proxyArgs: ["{implementation}", "{data}"],
13+
checkProxyAdmin: false, // Not relevant for UUPSProxy
14+
checkABIConflict: false, // Not relevant for UUPSProxy
15+
upgradeFunction: {
16+
methodName: "upgradeToAndCall",
17+
upgradeArgs: ["{implementation}", "{data}"],
18+
},
19+
};
20+
21+
type DeployUpgradableOptions = {
22+
newImplementation?: string;
23+
initializer?: string;
24+
} & DeployOptionsBase;
25+
26+
export const deployUpgradable = async (
27+
deployments: DeploymentsExtension,
28+
proxy: string,
29+
options: DeployUpgradableOptions
30+
): Promise<DeployResult> => {
31+
const { deploy } = deployments;
32+
const { newImplementation, initializer, args: initializerArgs, ...otherOptions } = options;
33+
34+
const methodName = initializer ?? "initialize";
35+
const args = initializerArgs ?? [];
36+
37+
const contract: Partial<DeployOptions> = newImplementation
38+
? {
39+
contract: newImplementation,
40+
}
41+
: {};
42+
43+
const implementationName: Partial<ProxyOptions> = newImplementation
44+
? {
45+
implementationName: newImplementation + "_Implementation",
46+
}
47+
: {};
48+
49+
const fullOptions: DeployOptions = {
50+
...otherOptions,
51+
...contract,
1252
proxy: {
13-
proxyContract: "UUPSProxy",
14-
proxyArgs: ["{implementation}", "{data}"],
15-
checkProxyAdmin: false,
16-
checkABIConflict: false,
53+
...PROXY_OPTIONS,
54+
...implementationName,
1755
execute: {
1856
init: {
19-
methodName: "initialize",
20-
args: args ?? [],
57+
methodName,
58+
args,
2159
},
2260
onUpgrade: {
23-
methodName: "governor",
24-
args: [],
61+
methodName,
62+
args,
2563
},
2664
},
2765
},
28-
...otherOptions,
29-
});
30-
}
66+
};
67+
68+
// console.debug("fullOptions: ", JSON.stringify(fullOptions));
69+
return deploy(proxy, fullOptions);
70+
};

contracts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"graphql-request": "^6.1.0",
6464
"hardhat": "^2.15.0",
6565
"hardhat-contract-sizer": "^2.10.0",
66-
"hardhat-deploy": "^0.11.37",
66+
"hardhat-deploy": "^0.11.42",
6767
"hardhat-deploy-ethers": "^0.4.0-next.1",
6868
"hardhat-deploy-tenderly": "^0.2.0",
6969
"hardhat-docgen": "^1.3.0",

contracts/src/arbitration/KlerosCore.sol

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
108108
uint256 private constant ALPHA_DIVISOR = 1e4; // The number to divide `Court.alpha` by.
109109
uint256 private constant NON_PAYABLE_AMOUNT = (2 ** 256 - 2) / 2; // An amount higher than the supply of ETH.
110110
uint256 private constant SEARCH_ITERATIONS = 10; // Number of iterations to search for suitable parent court before jumping to the top court.
111-
IERC20 private constant NATIVE_CURRENCY = IERC20(address(0)); // The native currency, such as ETH on Arbitrum, Optimism and Ethereum L1.
112111

113112
address public governor; // The governor of the contract.
114113
IERC20 public pinakion; // The Pinakion token contract.
@@ -516,7 +515,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
516515
) external payable override returns (uint256 disputeID) {
517516
if (msg.value < arbitrationCost(_extraData)) revert ArbitrationFeesNotEnough();
518517

519-
return _createDispute(_numberOfChoices, _extraData, NATIVE_CURRENCY, msg.value);
518+
return _createDispute(_numberOfChoices, _extraData, Constants.NATIVE_CURRENCY, msg.value);
520519
}
521520

522521
/// @inheritdoc IArbitratorV2
@@ -553,7 +552,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
553552
Round storage round = dispute.rounds.push();
554553

555554
// Obtain the feeForJuror in the same currency as the _feeAmount
556-
uint256 feeForJuror = (_feeToken == NATIVE_CURRENCY)
555+
uint256 feeForJuror = (_feeToken == Constants.NATIVE_CURRENCY)
557556
? court.feeForJuror
558557
: convertEthToTokenAmount(_feeToken, court.feeForJuror);
559558
round.nbVotes = _feeAmount / feeForJuror;
@@ -810,7 +809,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
810809
}
811810
if (_params.repartition == _params.numberOfVotesInRound - 1 && _params.coherentCount == 0) {
812811
// No one was coherent, send the rewards to the governor.
813-
if (round.feeToken == NATIVE_CURRENCY) {
812+
if (round.feeToken == Constants.NATIVE_CURRENCY) {
814813
// The dispute fees were paid in ETH
815814
payable(governor).send(round.totalFeesForJurors);
816815
} else {
@@ -865,7 +864,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
865864
uint256 feeReward = ((round.totalFeesForJurors / _params.coherentCount) * degreeOfCoherence) / ALPHA_DIVISOR;
866865
round.sumFeeRewardPaid += feeReward;
867866
pinakion.safeTransfer(account, pnkReward);
868-
if (round.feeToken == NATIVE_CURRENCY) {
867+
if (round.feeToken == Constants.NATIVE_CURRENCY) {
869868
// The dispute fees were paid in ETH
870869
payable(account).send(feeReward);
871870
} else {
@@ -891,7 +890,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
891890
pinakion.safeTransfer(governor, leftoverPnkReward);
892891
}
893892
if (leftoverFeeReward != 0) {
894-
if (round.feeToken == NATIVE_CURRENCY) {
893+
if (round.feeToken == Constants.NATIVE_CURRENCY) {
895894
// The dispute fees were paid in ETH
896895
payable(governor).send(leftoverFeeReward);
897896
} else {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ contract DisputeKitSybilResistant is IDisputeKit, IEvidence, Initializable, UUPS
160160
/// @dev Initializer.
161161
/// @param _governor The governor's address.
162162
/// @param _core The KlerosCore arbitrator.
163+
/// @param _poh The Proof of Humanity registry.
163164
function initialize(address _governor, KlerosCore _core, IProofOfHumanity _poh) external reinitializer(1) {
164165
governor = _governor;
165166
core = _core;

contracts/src/arbitration/interfaces/IDisputeTemplateRegistry.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
pragma solidity 0.8.18;
44

5-
import "./IArbitratorV2.sol";
6-
75
/// @title IDisputeTemplate
86
/// @notice Dispute Template interface.
97
interface IDisputeTemplateRegistry {

contracts/src/gateway/ForeignGateway.sol

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pragma solidity 0.8.18;
1111
import "./interfaces/IForeignGateway.sol";
1212
import "../proxy/UUPSProxiable.sol";
1313
import "../proxy/Initializable.sol";
14+
import "../libraries/Constants.sol";
1415

1516
/// Foreign Gateway
1617
/// Counterpart of `HomeGateway`
@@ -37,7 +38,6 @@ contract ForeignGateway is IForeignGateway, UUPSProxiable, Initializable {
3738
// * Storage * //
3839
// ************************************* //
3940

40-
uint256 public constant DEFAULT_NB_OF_JURORS = 3; // The default number of jurors in a dispute.
4141
uint256 internal localDisputeID; // The disputeID must start from 1 as the KlerosV1 proxy governor depends on this implementation. We now also depend on localDisputeID not ever being zero.
4242
mapping(uint96 => uint256) public feeForJuror; // feeForJuror[v2CourtID], it mirrors the value on KlerosCore.
4343
address public governor;
@@ -78,6 +78,9 @@ contract ForeignGateway is IForeignGateway, UUPSProxiable, Initializable {
7878

7979
/// @dev Constructs the `PolicyRegistry` contract.
8080
/// @param _governor The governor's address.
81+
/// @param _veaOutbox The address of the VeaOutbox.
82+
/// @param _homeChainID The chainID of the home chain.
83+
/// @param _homeGateway The address of the home gateway.
8184
function initialize(
8285
address _governor,
8386
address _veaOutbox,
@@ -263,10 +266,10 @@ contract ForeignGateway is IForeignGateway, UUPSProxiable, Initializable {
263266
minJurors := mload(add(_extraData, 0x40))
264267
}
265268
if (feeForJuror[courtID] == 0) courtID = 0;
266-
if (minJurors == 0) minJurors = DEFAULT_NB_OF_JURORS;
269+
if (minJurors == 0) minJurors = Constants.DEFAULT_NB_OF_JURORS;
267270
} else {
268271
courtID = 0;
269-
minJurors = DEFAULT_NB_OF_JURORS;
272+
minJurors = Constants.DEFAULT_NB_OF_JURORS;
270273
}
271274
}
272275
}

contracts/src/gateway/HomeGateway.sol

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pragma solidity 0.8.18;
1111
import "./interfaces/IForeignGateway.sol";
1212
import "./interfaces/IHomeGateway.sol";
1313
import "../libraries/SafeERC20.sol";
14+
import "../libraries/Constants.sol";
1415
import "../proxy/UUPSProxiable.sol";
1516
import "../proxy/Initializable.sol";
1617

@@ -32,7 +33,6 @@ contract HomeGateway is IHomeGateway, UUPSProxiable, Initializable {
3233
// * Storage * //
3334
// ************************************* //
3435

35-
IERC20 public constant NATIVE_CURRENCY = IERC20(address(0)); // The native currency, such as ETH on Arbitrum, Optimism and Ethereum L1.
3636
address public governor;
3737
IArbitratorV2 public arbitrator;
3838
IVeaInbox public veaInbox;
@@ -64,6 +64,11 @@ contract HomeGateway is IHomeGateway, UUPSProxiable, Initializable {
6464

6565
/// @dev Constructs the `PolicyRegistry` contract.
6666
/// @param _governor The governor's address.
67+
/// @param _arbitrator The address of the arbitrator.
68+
/// @param _veaInbox The address of the vea inbox.
69+
/// @param _foreignChainID The ID of the foreign chain.
70+
/// @param _foreignGateway The address of the foreign gateway.
71+
/// @param _feeToken The address of the fee token.
6772
function initialize(
6873
address _governor,
6974
IArbitratorV2 _arbitrator,
@@ -128,7 +133,7 @@ contract HomeGateway is IHomeGateway, UUPSProxiable, Initializable {
128133

129134
/// @inheritdoc IHomeGateway
130135
function relayCreateDispute(RelayCreateDisputeParams memory _params) external payable override {
131-
require(feeToken == NATIVE_CURRENCY, "Fees paid in ERC20 only");
136+
require(feeToken == Constants.NATIVE_CURRENCY, "Fees paid in ERC20 only");
132137
require(_params.foreignChainID == foreignChainID, "Foreign chain ID not supported");
133138

134139
bytes32 disputeHash = keccak256(
@@ -166,7 +171,7 @@ contract HomeGateway is IHomeGateway, UUPSProxiable, Initializable {
166171

167172
/// @inheritdoc IHomeGateway
168173
function relayCreateDispute(RelayCreateDisputeParams memory _params, uint256 _feeAmount) external {
169-
require(feeToken != NATIVE_CURRENCY, "Fees paid in native currency only");
174+
require(feeToken != Constants.NATIVE_CURRENCY, "Fees paid in native currency only");
170175
require(_params.foreignChainID == foreignChainID, "Foreign chain ID not supported");
171176

172177
bytes32 disputeHash = keccak256(

0 commit comments

Comments
 (0)