Skip to content

Commit 77cb6ed

Browse files
committed
feat: resolver migrated and deployed to chiado, interfaces natspec improved
1 parent ef6e263 commit 77cb6ed

File tree

10 files changed

+160
-55
lines changed

10 files changed

+160
-55
lines changed

contracts/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Refresh the list of deployed contracts by running `./scripts/generateDeployments
1111
#### Chiado
1212

1313
- [ArbitrableExample](https://blockscout.com/gnosis/chiado/address/0xc0fcc96BFd78e36550FCaB434A9EE1210B57225b)
14+
- [DisputeResolver](https://blockscout.com/gnosis/chiado/address/0x433eD78895df1df7668C40b3e82d54410331F942)
1415
- [ForeignGatewayOnGnosis](https://blockscout.com/gnosis/chiado/address/0x573bcD6ee4aEe152eCC9Cafd2c0820Dc548AF6cC)
1516
- [SortitionSumTreeFactory](https://blockscout.com/gnosis/chiado/address/0xc7e3BF90299f6BD9FA7c3703837A9CAbB5743636)
1617
- [TokenBridge](https://blockscout.com/gnosis/chiado/address/0xbb3c86f9918C3C1d83668fA84e79E876d147fFf2)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { parseUnits } from "ethers/lib/utils";
2+
import { HardhatRuntimeEnvironment } from "hardhat/types";
3+
import { DeployFunction } from "hardhat-deploy/types";
4+
5+
enum ForeignChains {
6+
GNOSIS_MAINNET = 100,
7+
GNOSIS_CHIADO = 10200,
8+
HARDHAT = 31337,
9+
}
10+
11+
const ONE_GWEI = parseUnits("1", "gwei");
12+
13+
const deployResolver: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
14+
const { deployments, getNamedAccounts, getChainId } = hre;
15+
const { deploy } = deployments;
16+
17+
// fallback to hardhat node signers on local network
18+
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
19+
const chainId = Number(await getChainId());
20+
console.log("Deploying to chainId %s with deployer %s", chainId, deployer);
21+
22+
const foreignGateway = await deployments.get("ForeignGatewayOnGnosis");
23+
24+
await deploy("DisputeResolver", {
25+
from: deployer,
26+
args: [foreignGateway.address],
27+
log: true,
28+
maxFeePerGas: ONE_GWEI,
29+
maxPriorityFeePerGas: ONE_GWEI,
30+
});
31+
};
32+
33+
deployResolver.tags = ["ResolverOnGnosis"];
34+
deployResolver.skip = async ({ getChainId }) => {
35+
const chainId = Number(await getChainId());
36+
return !ForeignChains[chainId];
37+
};
38+
39+
export default deployResolver;

contracts/src/arbitration/IArbitrable.sol

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import "./IArbitrator.sol";
1212
interface IArbitrable {
1313
/// @dev To be raised when a ruling is given.
1414
/// @param _arbitrator The arbitrator giving the ruling.
15-
/// @param _disputeID ID of the dispute in the Arbitrator contract.
15+
/// @param _disputeID The identifier of the dispute in the Arbitrator contract.
1616
/// @param _ruling The ruling which was given.
1717
event Ruling(IArbitrator indexed _arbitrator, uint256 indexed _disputeID, uint256 _ruling);
1818

19-
/// @dev Give a ruling for a dispute. Must be called by the arbitrator.
20-
/// The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
21-
/// @param _disputeID ID of the dispute in the Arbitrator contract.
22-
/// @param _ruling Ruling given by the arbitrator. Note that 0 is reserved for "Not able/wanting to make a decision".
19+
/// @dev Give a ruling for a dispute.
20+
/// Must be called by the arbitrator.
21+
/// The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
22+
/// @param _disputeID The identifier of the dispute in the Arbitrator contract.
23+
/// @param _ruling Ruling given by the arbitrator.
24+
/// Note that 0 is reserved for "Not able/wanting to make a decision".
2325
function rule(uint256 _disputeID, uint256 _ruling) external;
2426
}

contracts/src/arbitration/IArbitrableV2.sol

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: MIT
22

3-
pragma solidity ^0.8;
3+
pragma solidity 0.8.18;
44

55
import "./IArbitratorV2.sol";
66

@@ -11,17 +11,17 @@ import "./IArbitratorV2.sol";
1111
/// - Allow dispute creation. For this a function must call arbitrator.createDispute{value: _fee}(_choices,_extraData);
1212
interface IArbitrableV2 {
1313
/// @dev To be emitted when a new dispute template is created.
14-
/// @param _templateId The ID of the dispute template.
14+
/// @param _templateId The identifier of the dispute template.
1515
/// @param _templateTag An optional tag for the dispute template, such as "registration" or "removal".
1616
/// @param data The template data.
1717
event DisputeTemplate(uint256 indexed _templateId, string indexed _templateTag, string data);
1818

1919
/// @dev To be emitted when a dispute is created to link the correct meta-evidence to the disputeID.
2020
/// @param _arbitrator The arbitrator of the contract.
21-
/// @param _arbitrableDisputeID The ID of the dispute in the Arbitrable contract.
21+
/// @param _arbitrableDisputeID The identifier of the dispute in the Arbitrable contract.
2222
/// @param _externalDisputeID An identifier created outside Kleros by the protocol requesting arbitration.
23-
/// @param _templateId The ID of the dispute template. Should not be used with _templateUri.
24-
/// @param _templateUri IPFS path to the dispute template starting with '/ipfs/'. Should not be used with _templateId.
23+
/// @param _templateId The identifier of the dispute template. Should not be used with _templateUri.
24+
/// @param _templateUri The URI to the dispute template. For example on IPFS: starting with '/ipfs/'. Should not be used with _templateId.
2525
event DisputeRequest(
2626
IArbitratorV2 indexed _arbitrator,
2727
uint256 indexed _arbitrableDisputeID,
@@ -32,11 +32,11 @@ interface IArbitrableV2 {
3232

3333
/// @dev To be emitted when a dispute is created to link the correct meta-evidence to the disputeID.
3434
/// @param _arbitrator The arbitrator of the contract.
35-
/// @param _arbitrableChainId The chain ID of the Arbitrable contract.
35+
/// @param _arbitrableChainId The chain identifier where the Arbitrable contract is deployed.
3636
/// @param _arbitrable The address of the Arbitrable contract.
37-
/// @param _arbitrableDisputeID The ID of the dispute in the Arbitrable contract.
37+
/// @param _arbitrableDisputeID The identifier of the dispute in the Arbitrable contract.
3838
/// @param _externalDisputeID An identifier created outside Kleros by the protocol requesting arbitration.
39-
/// @param _templateId The ID of the dispute template. Should not be used with _templateUri.
39+
/// @param _templateId The identifier of the dispute template. Should not be used with _templateUri.
4040
/// @param _templateUri IPFS path to the dispute template starting with '/ipfs/'. Should not be used with _templateId.
4141
event CrossChainDisputeRequest(
4242
IArbitratorV2 indexed _arbitrator,
@@ -50,14 +50,14 @@ interface IArbitrableV2 {
5050

5151
/// @dev To be raised when a ruling is given.
5252
/// @param _arbitrator The arbitrator giving the ruling.
53-
/// @param _disputeID ID of the dispute in the Arbitrator contract.
53+
/// @param _disputeID The identifier of the dispute in the Arbitrator contract.
5454
/// @param _ruling The ruling which was given.
5555
event Ruling(IArbitratorV2 indexed _arbitrator, uint256 indexed _disputeID, uint256 _ruling);
5656

5757
/// @dev Give a ruling for a dispute.
5858
/// Must be called by the arbitrator.
5959
/// The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
60-
/// @param _disputeID ID of the dispute in the Arbitrator contract.
60+
/// @param _disputeID The identifier of the dispute in the Arbitrator contract.
6161
/// @param _ruling Ruling given by the arbitrator.
6262
/// Note that 0 is reserved for "Not able/wanting to make a decision".
6363
function rule(uint256 _disputeID, uint256 _ruling) external;

contracts/src/arbitration/IArbitrator.sol

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,33 @@ import "./IArbitrable.sol";
66

77
/// @title Arbitrator
88
/// Arbitrator interface that implements the new arbitration standard.
9-
/// Unlike the ERC-792 this standard doesn't have anything related to appeals, so each arbitrator can implement an appeal system that suits it the most.
9+
/// Unlike the ERC-792 this standard is not concerned with appeals, so each arbitrator can implement an appeal system that suits it the most.
1010
/// When developing arbitrator contracts we need to:
1111
/// - Define the functions for dispute creation (createDispute). Don't forget to store the arbitrated contract and the disputeID (which should be unique, may nbDisputes).
1212
/// - Define the functions for cost display (arbitrationCost).
1313
/// - Allow giving rulings. For this a function must call arbitrable.rule(disputeID, ruling).
1414
interface IArbitrator {
1515
/// @dev To be emitted when a dispute is created.
16-
/// @param _disputeID ID of the dispute.
16+
/// @param _disputeID The identifier of the dispute.
1717
/// @param _arbitrable The contract which created the dispute.
1818
event DisputeCreation(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);
1919

2020
/// @dev To be raised when a ruling is given.
2121
/// @param _arbitrable The arbitrable receiving the ruling.
22-
/// @param _disputeID ID of the dispute in the Arbitrator contract.
22+
/// @param _disputeID The identifier of the dispute in the Arbitrator contract.
2323
/// @param _ruling The ruling which was given.
2424
event Ruling(IArbitrable indexed _arbitrable, uint256 indexed _disputeID, uint256 _ruling);
2525

26-
/// @dev Create a dispute. Must be called by the arbitrable contract.
27-
/// Must pay at least arbitrationCost(_extraData).
26+
/// @dev Create a dispute.
27+
/// Must be called by the arbitrable contract.
28+
/// Must pay at least arbitrationCost(_extraData).
2829
/// @param _choices Amount of choices the arbitrator can make in this dispute.
2930
/// @param _extraData Can be used to give additional info on the dispute to be created.
30-
/// @return disputeID ID of the dispute created.
31+
/// @return disputeID The identifier of the dispute created.
3132
function createDispute(uint256 _choices, bytes calldata _extraData) external payable returns (uint256 disputeID);
3233

33-
/// @dev Compute the cost of arbitration. It is recommended not to increase it often, as it can be highly time and gas consuming for the arbitrated contracts to cope with fee augmentation.
34+
/// @dev Compute the cost of arbitration.
35+
/// It is recommended not to increase it often, as it can be highly time and gas consuming for the arbitrated contracts to cope with fee augmentation.
3436
/// @param _extraData Can be used to give additional info on the dispute to be created.
3537
/// @return cost Required cost of arbitration.
3638
function arbitrationCost(bytes calldata _extraData) external view returns (uint256 cost);

contracts/src/arbitration/IArbitratorV2.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: MIT
22

3-
pragma solidity ^0.8;
3+
pragma solidity 0.8.18;
44

55
import "./IArbitrableV2.sol";
66

@@ -13,13 +13,13 @@ import "./IArbitrableV2.sol";
1313
/// - Allow giving rulings. For this a function must call arbitrable.rule(disputeID, ruling).
1414
interface IArbitratorV2 {
1515
/// @dev To be emitted when a dispute is created.
16-
/// @param _disputeID Identifier of the dispute.
16+
/// @param _disputeID The identifier of the dispute in the Arbitrator contract.
1717
/// @param _arbitrable The contract which created the dispute.
1818
event DisputeCreation(uint256 indexed _disputeID, IArbitrableV2 indexed _arbitrable);
1919

2020
/// @dev To be raised when a ruling is given.
2121
/// @param _arbitrable The arbitrable receiving the ruling.
22-
/// @param _disputeID Identifier of the dispute in the Arbitrator contract.
22+
/// @param _disputeID The identifier of the dispute in the Arbitrator contract.
2323
/// @param _ruling The ruling which was given.
2424
event Ruling(IArbitrableV2 indexed _arbitrable, uint256 indexed _disputeID, uint256 _ruling);
2525

@@ -28,7 +28,7 @@ interface IArbitratorV2 {
2828
/// Must pay at least arbitrationCost(_extraData).
2929
/// @param _choices Amount of choices the arbitrator can make in this dispute.
3030
/// @param _extraData Can be used to give additional info on the dispute to be created.
31-
/// @return disputeID Identifier of the dispute created.
31+
/// @return disputeID The identifier of the dispute created.
3232
function createDispute(uint256 _choices, bytes calldata _extraData) external payable returns (uint256 disputeID);
3333

3434
/// @dev Compute the cost of arbitration.
@@ -39,7 +39,7 @@ interface IArbitratorV2 {
3939

4040
/// @dev Return the current ruling of a dispute.
4141
/// This is useful for parties to know if they should appeal.
42-
/// @param _disputeID ID of the dispute.
42+
/// @param _disputeID The identifer of the dispute.
4343
/// @return ruling The ruling which has been given or the one which will be given if there is no appeal.
4444
function currentRuling(uint _disputeID) external view returns (uint ruling);
4545
}
Lines changed: 83 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: MIT
22

3-
/// @custom:authors: [@ferittuncer, @unknownunknown1,@jaybuidl]
3+
/// @custom:authors: [@ferittuncer, @unknownunknown1, @jaybuidl]
44
/// @custom:reviewers: []
55
/// @custom:auditors: []
66
/// @custom:bounties: []
@@ -10,53 +10,85 @@ import "../IArbitrableV2.sol";
1010
pragma solidity 0.8.18;
1111

1212
/// @title DisputeResolver
13-
/// DisputeResolver contract adapted for V2 https://github.com/kleros/arbitrable-proxy-contracts/blob/master/contracts/ArbitrableProxy.sol.
13+
/// DisputeResolver contract adapted for V2 from https://github.com/kleros/arbitrable-proxy-contracts/blob/master/contracts/ArbitrableProxy.sol.
1414
contract DisputeResolver is IArbitrableV2 {
15+
// ************************************* //
16+
// * Enums / Structs * //
17+
// ************************************* //
18+
1519
struct DisputeStruct {
1620
bytes arbitratorExtraData; // Extra data for the dispute.
1721
bool isRuled; // True if the dispute has been ruled.
1822
uint256 ruling; // Ruling given to the dispute.
1923
uint256 numberOfRulingOptions; // The number of choices the arbitrator can give.
2024
}
2125

22-
IArbitratorV2 public immutable arbitrator; // Arbitrator is set in constructor and never changed.
26+
// ************************************* //
27+
// * Storage * //
28+
// ************************************* //
2329

30+
address public governor; // The governor.
31+
IArbitratorV2 public arbitrator; // The arbitrator.
2432
DisputeStruct[] public disputes; // Local disputes.
25-
mapping(uint256 => uint256) public arbitratorDisputeIDToLocalID; // Maps external (arbitrator side) dispute IDs to local dispute IDs.
33+
mapping(uint256 => uint256) public arbitratorDisputeIDToLocalID; // Maps arbitrator-side dispute IDs to local dispute IDs.
34+
35+
// ************************************* //
36+
// * Constructor * //
37+
// ************************************* //
2638

2739
/// @dev Constructor
2840
/// @param _arbitrator Target global arbitrator for any disputes.
2941
constructor(IArbitratorV2 _arbitrator) {
42+
governor = msg.sender;
3043
arbitrator = _arbitrator;
3144
}
3245

46+
// ************************************* //
47+
// * Governance * //
48+
// ************************************* //
49+
50+
/// @dev Changes the governor.
51+
/// @param _governor The address of the new governor.
52+
function changeGovernor(address _governor) external {
53+
require(governor == msg.sender, "Access not allowed: Governor only.");
54+
governor = _governor;
55+
}
56+
57+
function changeArbitrator(IArbitratorV2 _arbitrator) external {
58+
require(governor == msg.sender, "Access not allowed: Governor only.");
59+
arbitrator = _arbitrator;
60+
}
61+
62+
// ************************************* //
63+
// * State Modifiers * //
64+
// ************************************* //
65+
3366
/// @dev Calls createDispute function of the specified arbitrator to create a dispute.
3467
/// 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.
3568
/// @param _arbitratorExtraData Extra data for the arbitrator of the dispute.
36-
/// @param _template Dispute template.
69+
/// @param _disputeTemplate Dispute template.
3770
/// @param _numberOfRulingOptions Number of ruling options.
3871
/// @return disputeID Dispute id (on arbitrator side) of the created dispute.
39-
function createDispute(
72+
function createDisputeForTemplate(
4073
bytes calldata _arbitratorExtraData,
41-
string calldata _template,
74+
string calldata _disputeTemplate,
4275
uint256 _numberOfRulingOptions
4376
) external payable returns (uint256 disputeID) {
44-
require(_numberOfRulingOptions > 1, "Should be at least 2 ruling options.");
45-
46-
disputeID = arbitrator.createDispute{value: msg.value}(_numberOfRulingOptions, _arbitratorExtraData);
47-
uint256 localDisputeID = disputes.length;
48-
disputes.push(
49-
DisputeStruct({
50-
arbitratorExtraData: _arbitratorExtraData,
51-
isRuled: false,
52-
ruling: 0,
53-
numberOfRulingOptions: _numberOfRulingOptions
54-
})
55-
);
77+
return _createDispute(_arbitratorExtraData, _disputeTemplate, "", _numberOfRulingOptions);
78+
}
5679

57-
arbitratorDisputeIDToLocalID[disputeID] = localDisputeID;
58-
emit DisputeTemplate(localDisputeID, "", _template);
59-
emit DisputeRequest(arbitrator, disputeID, localDisputeID, localDisputeID, "");
80+
/// @dev Calls createDispute function of the specified arbitrator to create a dispute.
81+
/// 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.
82+
/// @param _arbitratorExtraData Extra data for the arbitrator of the dispute.
83+
/// @param _disputeTemplateUri The URI to the dispute template. For example on IPFS: starting with '/ipfs/'.
84+
/// @param _numberOfRulingOptions Number of ruling options.
85+
/// @return disputeID Dispute id (on arbitrator side) of the created dispute.
86+
function createDisputeForTemplateUri(
87+
bytes calldata _arbitratorExtraData,
88+
string calldata _disputeTemplateUri,
89+
uint256 _numberOfRulingOptions
90+
) external payable returns (uint256 disputeID) {
91+
return _createDispute(_arbitratorExtraData, "", _disputeTemplateUri, _numberOfRulingOptions);
6092
}
6193

6294
/// @dev To be called by the arbitrator of the dispute, to declare the winning ruling.
@@ -74,4 +106,33 @@ contract DisputeResolver is IArbitrableV2 {
74106

75107
emit Ruling(IArbitratorV2(msg.sender), _externalDisputeID, dispute.ruling);
76108
}
109+
110+
// ************************************* //
111+
// * Internal * //
112+
// ************************************* //
113+
114+
function _createDispute(
115+
bytes calldata _arbitratorExtraData,
116+
string memory _disputeTemplate,
117+
string memory _disputeUri,
118+
uint256 _numberOfRulingOptions
119+
) internal returns (uint256 disputeID) {
120+
require(_numberOfRulingOptions > 1, "Should be at least 2 ruling options.");
121+
122+
disputeID = arbitrator.createDispute{value: msg.value}(_numberOfRulingOptions, _arbitratorExtraData);
123+
uint256 localDisputeID = disputes.length;
124+
disputes.push(
125+
DisputeStruct({
126+
arbitratorExtraData: _arbitratorExtraData,
127+
isRuled: false,
128+
ruling: 0,
129+
numberOfRulingOptions: _numberOfRulingOptions
130+
})
131+
);
132+
arbitratorDisputeIDToLocalID[disputeID] = localDisputeID;
133+
134+
uint256 templateId = localDisputeID;
135+
emit DisputeTemplate(templateId, "", _disputeTemplate);
136+
emit DisputeRequest(arbitrator, disputeID, localDisputeID, templateId, _disputeUri);
137+
}
77138
}

0 commit comments

Comments
 (0)