22
33pragma solidity 0.8.18 ;
44
5+ import "@openzeppelin/contracts/token/ERC20/ERC20.sol " ;
56import "../IArbitrable.sol " ;
67import "../../evidence/IMetaEvidence.sol " ;
7- import "../../libraries/SafeERC20.sol " ;
88
99/// @title ArbitrableExample
1010/// An example of an arbitrable contract which connects to the arbitator that implements the updated interface.
1111contract ArbitrableExample is IArbitrable , IMetaEvidence {
12- using SafeERC20 for IERC20 ;
13-
14- // ************************************* //
15- // * Enums / Structs * //
16- // ************************************* //
17-
1812 struct DisputeStruct {
1913 bool isRuled; // Whether the dispute has been ruled or not.
2014 uint256 ruling; // Ruling given by the arbitrator.
2115 uint256 numberOfRulingOptions; // The number of choices the arbitrator can give.
2216 }
2317
24- // ************************************* //
25- // * Storage * //
26- // ************************************* //
27-
2818 address public immutable governor;
2919 IArbitrator public arbitrator; // Arbitrator is set in constructor and never changed.
30- IERC20 public immutable weth; // The WETH token.
20+ ERC20 public immutable weth; // The WETH token.
3121 mapping (uint256 => uint256 ) public externalIDtoLocalID; // Maps external (arbitrator side) dispute IDs to local dispute IDs.
3222 DisputeStruct[] public disputes; // Stores the disputes' info. disputes[disputeID].
3323
@@ -39,11 +29,11 @@ contract ArbitrableExample is IArbitrable, IMetaEvidence {
3929 /// @param _arbitrator The arbitrator to rule on created disputes.
4030 /// @param _metaEvidenceID Unique identifier of meta-evidence.
4131 /// @param _metaEvidence The URI of the meta evidence object for evidence submissions requests.
42- constructor (IArbitrator _arbitrator , uint256 _metaEvidenceID , string memory _metaEvidence , IERC20 _weth ) {
32+ constructor (IArbitrator _arbitrator , uint256 _metaEvidenceID , string memory _metaEvidence , ERC20 _weth ) {
4333 governor = msg .sender ;
4434 arbitrator = _arbitrator;
4535 weth = _weth;
46- emit MetaEvidence (_metaEvidenceID, _metaEvidence );
36+ emit DisputeTemplate (disputeTemplates ++ , "" , _templateData );
4737 }
4838
4939 // ************************************* //
@@ -66,55 +56,56 @@ contract ArbitrableExample is IArbitrable, IMetaEvidence {
6656
6757 /// @dev Calls createDispute function of the specified arbitrator to create a dispute.
6858 /// 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.
69- /// @param _numberOfRulingOptions Number of ruling options. Must be greater than 1, otherwise there is nothing to choose from.
59+ /// @param _templateId The identifier of the dispute template. Should not be used with _templateUri.
60+ /// @param _action The action that requires arbitration.
7061 /// @param _arbitratorExtraData Extra data for the arbitrator.
71- /// @param _metaEvidenceID Unique identifier of meta-evidence.
72- /// @param _evidenceGroupID Unique identifier of the evidence group that is linked to this dispute.
7362 /// @return disputeID Dispute id (on arbitrator side) of the dispute created.
7463 function createDispute (
75- uint256 _numberOfRulingOptions ,
76- bytes calldata _arbitratorExtraData ,
77- uint256 _metaEvidenceID ,
78- uint256 _evidenceGroupID
64+ uint256 _templateId ,
65+ string calldata _action ,
66+ bytes calldata _arbitratorExtraData
7967 ) external payable returns (uint256 disputeID ) {
80- require (_numberOfRulingOptions > 1 , " Incorrect number of choices " );
68+ emit Action (_action );
8169
70+ uint256 numberOfRulingOptions = 2 ;
8271 uint256 localDisputeID = disputes.length ;
83- disputes.push (DisputeStruct ({isRuled: false , ruling: 0 , numberOfRulingOptions: _numberOfRulingOptions}));
72+ disputes.push (DisputeStruct ({isRuled: false , ruling: 0 , numberOfRulingOptions: numberOfRulingOptions}));
73+
74+ disputeID = arbitrator.createDispute {value: msg .value }(numberOfRulingOptions, _arbitratorExtraData);
8475
85- disputeID = arbitrator.createDispute {value: msg .value }(_numberOfRulingOptions, _arbitratorExtraData);
8676 externalIDtoLocalID[disputeID] = localDisputeID;
8777
88- emit Dispute (arbitrator, disputeID, _metaEvidenceID, _evidenceGroupID);
78+ uint256 externalDisputeID = uint256 (keccak256 (abi.encodePacked (_action)));
79+ emit DisputeRequest (arbitrator, disputeID, externalDisputeID, _templateId, "" );
8980 }
9081
91- /// @dev TRUSTED. Creates a dispute with the arbitrator and pays for the fees in WETH token.
92- /// Note that we don’t need to check that _feeInWeth is enough to pay arbitration fees as it’s the responsibility of the arbitrator contract.
93- /// @param _numberOfRulingOptions Number of ruling options. Must be greater than 1, otherwise there is nothing to choose from.
82+ /// @dev Calls createDispute function of the specified arbitrator to create a dispute.
83+ /// 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.
84+ /// @param _templateId The identifier of the dispute template. Should not be used with _templateUri.
85+ /// @param _action The action that requires arbitration.
9486 /// @param _arbitratorExtraData Extra data for the arbitrator.
95- /// @param _metaEvidenceID Unique identifier of meta-evidence.
96- /// @param _evidenceGroupID Unique identifier of the evidence group that is linked to this dispute.
9787 /// @param _feeInWeth Amount of fees in WETH for the arbitrator.
9888 /// @return disputeID Dispute id (on arbitrator side) of the dispute created.
9989 function createDispute (
100- uint256 _numberOfRulingOptions ,
90+ uint256 _templateId ,
91+ string calldata _action ,
10192 bytes calldata _arbitratorExtraData ,
102- uint256 _metaEvidenceID ,
103- uint256 _evidenceGroupID ,
10493 uint256 _feeInWeth
10594 ) external payable returns (uint256 disputeID ) {
106- require (_numberOfRulingOptions > 1 , " Incorrect number of choices " );
95+ emit Action (_action );
10796
97+ uint256 numberOfRulingOptions = 2 ;
10898 uint256 localDisputeID = disputes.length ;
109- disputes.push (DisputeStruct ({isRuled: false , ruling: 0 , numberOfRulingOptions: _numberOfRulingOptions }));
99+ disputes.push (DisputeStruct ({isRuled: false , ruling: 0 , numberOfRulingOptions: numberOfRulingOptions }));
110100
111101 require (weth.safeTransferFrom (msg .sender , address (this ), _feeInWeth), "Transfer failed " );
112102 require (weth.increaseAllowance (address (arbitrator), _feeInWeth), "Allowance increase failed " );
113103
114- disputeID = arbitrator.createDispute (_numberOfRulingOptions , _arbitratorExtraData, weth, _feeInWeth);
104+ disputeID = arbitrator.createDispute (numberOfRulingOptions , _arbitratorExtraData, weth, _feeInWeth);
115105 externalIDtoLocalID[disputeID] = localDisputeID;
116106
117- emit Dispute (arbitrator, disputeID, _metaEvidenceID, _evidenceGroupID);
107+ uint256 externalDisputeID = uint256 (keccak256 (abi.encodePacked (_action)));
108+ emit DisputeRequest (arbitrator, disputeID, externalDisputeID, _templateId, "" );
118109 }
119110
120111 /// @dev To be called by the arbitrator of the dispute, to declare the winning ruling.
@@ -130,6 +121,16 @@ contract ArbitrableExample is IArbitrable, IMetaEvidence {
130121 dispute.isRuled = true ;
131122 dispute.ruling = _ruling;
132123
133- emit Ruling (IArbitrator (msg .sender ), _externalDisputeID, dispute.ruling);
124+ emit Ruling (IArbitratorV2 (msg .sender ), _externalDisputeID, dispute.ruling);
125+ }
126+
127+ function changeMetaEvidence (uint256 _metaEvidenceID , string memory _metaEvidence ) external {
128+ require (msg .sender == governor, "Not authorized: governor only. " );
129+ emit MetaEvidence (_metaEvidenceID, _metaEvidence);
130+ }
131+
132+ function changeArbitrator (IArbitrator _arbitrator ) external {
133+ require (msg .sender == governor, "Not authorized: governor only. " );
134+ arbitrator = _arbitrator;
134135 }
135136}
0 commit comments