Skip to content

Commit ac47dd5

Browse files
committed
fix: added the arbitrator disputeID to the CrossChainDisputeIncoming event
Also simplified ArbitrableExample.createDispute().
1 parent 5153508 commit ac47dd5

11 files changed

+64
-42
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
1818
console.log("Deploying to %s with deployer %s", HomeChains[chainId], deployer);
1919

2020
const klerosCore = await deployments.get("KlerosCore");
21+
const extraData =
22+
"0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003"; // General court, 3 jurors
2123
const weth = await deployments.get("WETH");
2224

2325
await deploy("ArbitrableExample", {
2426
from: deployer,
25-
args: [klerosCore.address, disputeTemplate, weth.address],
27+
args: [klerosCore.address, disputeTemplate, extraData, weth.address],
2628
log: true,
2729
});
2830

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import getContractAddress from "../deploy-helpers/getContractAddress";
4+
import { KlerosCore__factory } from "../typechain-types";
45

56
enum ForeignChains {
67
ETHEREUM_MAINNET = 1,
@@ -45,13 +46,13 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
4546
});
4647

4748
// TODO: disable the gateway until fully initialized with the correct fees OR allow disputeCreators to add funds again if necessary.
48-
await execute(
49-
"ForeignGatewayOnEthereum",
50-
{ from: deployer, log: true },
51-
"changeCourtJurorFee",
52-
0,
53-
ethers.BigNumber.from(10).pow(17)
54-
);
49+
const coreDeployment = await hre.companionNetworks.home.deployments.get("KlerosCore");
50+
const core = await KlerosCore__factory.connect(coreDeployment.address, homeChainProvider);
51+
// TODO: set up the correct fees for the FORKING_COURT
52+
const courtId = await core.GENERAL_COURT();
53+
const fee = (await core.courts(courtId)).feeForJuror;
54+
await execute("ForeignGatewayOnGnosis", { from: deployer, log: true }, "changeCourtJurorFee", courtId, fee);
55+
// TODO: set up the correct fees for the lower courts
5556
};
5657

5758
deployForeignGateway.tags = ["ForeignGatewayOnEthereum"];

contracts/deploy/03-vea-mock.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import getContractAddress from "../deploy-helpers/getContractAddress";
4+
import { KlerosCore__factory } from "../typechain-types";
45
import disputeTemplate from "../../kleros-sdk/config/v2-disputetemplate/simple/NewDisputeTemplate.simple.json";
56

67
const HARDHAT_NETWORK = 31337;
@@ -51,17 +52,22 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
5152
log: true,
5253
}); // nonce+1
5354

54-
await execute(
55-
"ForeignGatewayOnEthereum",
56-
{ from: deployer, log: true },
57-
"changeCourtJurorFee",
58-
0,
59-
ethers.BigNumber.from(10).pow(17)
60-
);
55+
// TODO: disable the gateway until fully initialized with the correct fees OR allow disputeCreators to add funds again if necessary.
56+
const signer = (await hre.ethers.getSigners())[0];
57+
const core = await KlerosCore__factory.connect(klerosCore.address, signer);
58+
// TODO: set up the correct fees for the FORKING_COURT
59+
const courtId = await core.GENERAL_COURT();
60+
const fee = (await core.courts(courtId)).feeForJuror;
61+
await execute("ForeignGatewayOnEthereum", { from: deployer, log: true }, "changeCourtJurorFee", courtId, fee);
62+
// TODO: set up the correct fees for the lower courts
6163

64+
// TODO: debug why this extraData fails but "0x00" works
65+
// const extraData =
66+
// "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003"; // General court, 3 jurors
67+
const extraData = "0x00";
6268
await deploy("ArbitrableExample", {
6369
from: deployer,
64-
args: [foreignGateway.address, disputeTemplate, ethers.constants.AddressZero],
70+
args: [foreignGateway.address, disputeTemplate, extraData, ethers.constants.AddressZero],
6571
log: true,
6672
});
6773
};

contracts/deploy/04-foreign-arbitrable.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
3+
import disputeTemplate from "../../kleros-sdk/config/v2-disputetemplate/simple/NewDisputeTemplate.simple.json";
34

45
enum ForeignChains {
56
ETHEREUM_MAINNET = 1,
@@ -16,11 +17,13 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
1617
console.log("Deploying to chainId %s with deployer %s", chainId, deployer);
1718

1819
const foreignGateway = await deployments.get("ForeignGatewayOnEthereum");
19-
const metaEvidenceUri = `https://raw.githubusercontent.com/kleros/kleros-v2/master/contracts/deployments/${hre.network.name}/MetaEvidence_ArbitrableExample.json`;
20+
// TODO: add the dispute template
21+
const extraData =
22+
"0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003"; // General court, 3 jurors
2023
const weth = await deployments.get("WETH");
2124
await deploy("ArbitrableExample", {
2225
from: deployer,
23-
args: [foreignGateway.address, 0, metaEvidenceUri, weth.address],
26+
args: [foreignGateway.address, disputeTemplate, extraData, weth.address],
2427
log: true,
2528
});
2629
};

contracts/deploy/04-klerosliquid-to-v2-gnosis.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ const deployKlerosLiquid: DeployFunction = async (hre: HardhatRuntimeEnvironment
5454
const jurorsForCourtJump = 9999999;
5555
const sortitionSumTreeK = 3;
5656
const foreignGateway = await deployments.get("ForeignGatewayOnGnosis");
57+
const extraData =
58+
"0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003"; // General court, 3 jurors
5759
const weth = await deployments.get("WETH");
5860

5961
console.log("Using: \nwPNK at %s, \nForeignGateway at %s", wPnkAddress, foreignGateway.address, weth.address);
@@ -99,7 +101,7 @@ const deployKlerosLiquid: DeployFunction = async (hre: HardhatRuntimeEnvironment
99101
// const xKlerosLiquidV2 = await deployments.get("xKlerosLiquidV2");
100102
await deploy("ArbitrableExample", {
101103
from: deployer,
102-
args: [xKlerosLiquidV2.address, 0, disputeTemplate, weth.address],
104+
args: [xKlerosLiquidV2.address, 0, disputeTemplate, extraData, weth.address],
103105
log: true,
104106
maxFeePerGas: ONE_GWEI,
105107
maxPriorityFeePerGas: ONE_GWEI,

contracts/hardhat.config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const config: HardhatUserConfig = {
3737
saveDeployments: true,
3838
allowUnlimitedContractSize: true,
3939
tags: ["test", "local"],
40+
companionNetworks: {
41+
home: "hardhat",
42+
foreign: "hardhat",
43+
},
4044
},
4145
localhost: {
4246
url: `http://127.0.0.1:8545`,

contracts/src/arbitration/arbitrables/ArbitrableExample.sol

+19-20
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ contract ArbitrableExample is IArbitrableV2 {
2525
address public immutable governor;
2626
IArbitratorV2 public arbitrator; // Arbitrator is set in constructor.
2727
uint256 public disputeTemplates; // The number of dispute templates created.
28+
bytes public arbitratorExtraData; // Extra data to set up the arbitration.
2829
IERC20 public immutable weth; // The WETH token.
2930
mapping(uint256 => uint256) public externalIDtoLocalID; // Maps external (arbitrator side) dispute IDs to local dispute IDs.
3031
DisputeStruct[] public disputes; // Stores the disputes' info. disputes[disputeID].
@@ -37,9 +38,15 @@ contract ArbitrableExample is IArbitrableV2 {
3738
/// @param _arbitrator The arbitrator to rule on created disputes.
3839
/// @param _templateData The dispute template data.
3940
/// @param _weth The WETH token.
40-
constructor(IArbitratorV2 _arbitrator, string memory _templateData, IERC20 _weth) {
41+
constructor(
42+
IArbitratorV2 _arbitrator,
43+
string memory _templateData,
44+
bytes memory _arbitratorExtraData,
45+
IERC20 _weth
46+
) {
4147
governor = msg.sender;
4248
arbitrator = _arbitrator;
49+
arbitratorExtraData = _arbitratorExtraData;
4350
weth = _weth;
4451
emit DisputeTemplate(disputeTemplates++, "", _templateData);
4552
}
@@ -58,47 +65,39 @@ contract ArbitrableExample is IArbitrableV2 {
5865
arbitrator = _arbitrator;
5966
}
6067

68+
function changeArbitratorExtraData(bytes calldata _arbitratorExtraData) external {
69+
require(msg.sender == governor, "Not authorized: governor only.");
70+
arbitratorExtraData = _arbitratorExtraData;
71+
}
72+
6173
// ************************************* //
6274
// * State Modifiers * //
6375
// ************************************* //
6476

6577
/// @dev Calls createDispute function of the specified arbitrator to create a dispute.
6678
/// Note that we don’t need to check that msg.value is enough to pay arbitration fees as it’s the responsibility of the arbitrator contract.
67-
/// @param _templateId The identifier of the dispute template. Should not be used with _templateUri.
6879
/// @param _action The action that requires arbitration.
69-
/// @param _arbitratorExtraData Extra data for the arbitrator.
7080
/// @return disputeID Dispute id (on arbitrator side) of the dispute created.
71-
function createDispute(
72-
uint256 _templateId,
73-
string calldata _action,
74-
bytes calldata _arbitratorExtraData
75-
) external payable returns (uint256 disputeID) {
81+
function createDispute(string calldata _action) external payable returns (uint256 disputeID) {
7682
emit Action(_action);
7783

7884
uint256 numberOfRulingOptions = 2;
7985
uint256 localDisputeID = disputes.length;
8086
disputes.push(DisputeStruct({isRuled: false, ruling: 0, numberOfRulingOptions: numberOfRulingOptions}));
8187

82-
disputeID = arbitrator.createDispute{value: msg.value}(numberOfRulingOptions, _arbitratorExtraData);
88+
disputeID = arbitrator.createDispute{value: msg.value}(numberOfRulingOptions, arbitratorExtraData);
8389
externalIDtoLocalID[disputeID] = localDisputeID;
8490

8591
uint256 externalDisputeID = uint256(keccak256(abi.encodePacked(_action)));
86-
emit DisputeRequest(arbitrator, disputeID, externalDisputeID, _templateId, "");
92+
emit DisputeRequest(arbitrator, disputeID, externalDisputeID, disputeTemplates - 1, "");
8793
}
8894

8995
/// @dev Calls createDispute function of the specified arbitrator to create a dispute.
9096
/// Note that we don’t need to check that msg.value is enough to pay arbitration fees as it’s the responsibility of the arbitrator contract.
91-
/// @param _templateId The identifier of the dispute template. Should not be used with _templateUri.
9297
/// @param _action The action that requires arbitration.
93-
/// @param _arbitratorExtraData Extra data for the arbitrator.
9498
/// @param _feeInWeth Amount of fees in WETH for the arbitrator.
9599
/// @return disputeID Dispute id (on arbitrator side) of the dispute created.
96-
function createDispute(
97-
uint256 _templateId,
98-
string calldata _action,
99-
bytes calldata _arbitratorExtraData,
100-
uint256 _feeInWeth
101-
) external payable returns (uint256 disputeID) {
100+
function createDispute(string calldata _action, uint256 _feeInWeth) external payable returns (uint256 disputeID) {
102101
emit Action(_action);
103102

104103
uint256 numberOfRulingOptions = 2;
@@ -108,11 +107,11 @@ contract ArbitrableExample is IArbitrableV2 {
108107
require(weth.safeTransferFrom(msg.sender, address(this), _feeInWeth), "Transfer failed");
109108
require(weth.increaseAllowance(address(arbitrator), _feeInWeth), "Allowance increase failed");
110109

111-
disputeID = arbitrator.createDispute(numberOfRulingOptions, _arbitratorExtraData, weth, _feeInWeth);
110+
disputeID = arbitrator.createDispute(numberOfRulingOptions, arbitratorExtraData, weth, _feeInWeth);
112111
externalIDtoLocalID[disputeID] = localDisputeID;
113112

114113
uint256 externalDisputeID = uint256(keccak256(abi.encodePacked(_action)));
115-
emit DisputeRequest(arbitrator, disputeID, externalDisputeID, _templateId, "");
114+
emit DisputeRequest(arbitrator, disputeID, externalDisputeID, disputeTemplates - 1, "");
116115
}
117116

118117
/// @dev To be called by the arbitrator of the dispute, to declare the winning ruling.

contracts/src/gateway/HomeGateway.sol

+3
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ contract HomeGateway is IHomeGateway {
135135
_params.foreignChainID,
136136
_params.foreignArbitrable,
137137
_params.foreignDisputeID,
138+
disputeID,
138139
_params.externalDisputeID,
139140
_params.templateId,
140141
_params.templateUri
@@ -168,13 +169,15 @@ contract HomeGateway is IHomeGateway {
168169
disputeHashtoID[disputeHash] = disputeID;
169170
relayedData.relayer = msg.sender;
170171

172+
// Not strictly necessary for functionality, only to satisfy IArbitrableV2
171173
emit DisputeRequest(arbitrator, disputeID, _params.externalDisputeID, _params.templateId, _params.templateUri);
172174

173175
emit CrossChainDisputeIncoming(
174176
arbitrator,
175177
_params.foreignChainID,
176178
_params.foreignArbitrable,
177179
_params.foreignDisputeID,
180+
disputeID,
178181
_params.externalDisputeID,
179182
_params.templateId,
180183
_params.templateUri

contracts/src/gateway/interfaces/IHomeGateway.sol

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ interface IHomeGateway is IArbitrableV2, ISenderGateway {
1818
/// @param _arbitrableChainId The chain identifier where the Arbitrable contract is deployed.
1919
/// @param _arbitrable The address of the Arbitrable contract.
2020
/// @param _arbitrableDisputeID The identifier of the dispute in the Arbitrable contract.
21+
/// @param _arbitratorDisputeID The identifier of the dispute in the Arbitrator contract.
2122
/// @param _externalDisputeID An identifier created outside Kleros by the protocol requesting arbitration.
2223
/// @param _templateId The identifier of the dispute template. Should not be used with _templateUri.
2324
/// @param _templateUri IPFS path to the dispute template starting with '/ipfs/'. Should not be used with _templateId.
2425
event CrossChainDisputeIncoming(
25-
IArbitratorV2 indexed _arbitrator,
26+
IArbitratorV2 _arbitrator,
2627
uint256 _arbitrableChainId,
2728
address indexed _arbitrable,
2829
uint256 indexed _arbitrableDisputeID,
30+
uint256 indexed _arbitratorDisputeID,
2931
uint256 _externalDisputeID,
3032
uint256 _templateId,
3133
string _templateUri

contracts/test/arbitration/draw.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe("Draw Benchmark", async () => {
9494
}
9595

9696
// Create a dispute
97-
const tx = await arbitrable.functions["createDispute(uint256,string,bytes)"](0, "future of france", "0x00", {
97+
const tx = await arbitrable.functions["createDispute(string)"]("future of france", {
9898
value: arbitrationCost,
9999
});
100100
const trace = await network.provider.send("debug_traceTransaction", [tx.hash]);

contracts/test/integration/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe("Integration tests", async () => {
9696
expect(result.locked).to.equal(0);
9797
logJurorBalance(result);
9898
});
99-
const tx = await arbitrable.functions["createDispute(uint256,string,bytes)"](0, "future of france", "0x00", {
99+
const tx = await arbitrable.functions["createDispute(string)"]("future of france", {
100100
value: arbitrationCost,
101101
});
102102
const trace = await network.provider.send("debug_traceTransaction", [tx.hash]);

0 commit comments

Comments
 (0)