1
1
// SPDX-License-Identifier: MIT
2
2
3
3
/**
4
- * @authors: [@unknownunknown1]
4
+ * @authors: [@unknownunknown1, @jaybuidl ]
5
5
* @reviewers: []
6
6
* @auditors: []
7
7
* @bounties: []
@@ -12,23 +12,16 @@ pragma solidity 0.8.18;
12
12
13
13
import {IArbitrableV2, IArbitratorV2} from "@kleros/kleros-v2-contracts/arbitration/interfaces/IArbitrableV2.sol " ;
14
14
import {EvidenceModule} from "@kleros/kleros-v2-contracts/arbitration/evidence/EvidenceModule.sol " ;
15
- import "@kleros/kleros-v2-contracts/arbitration/interfaces/IDisputeTemplateRegistry.sol " ;
16
- import "./interfaces/IRealitio.sol " ;
17
- import "./interfaces/IRealitioArbitrator.sol " ;
15
+ import {IDisputeTemplateRegistry} from "@kleros/kleros-v2-contracts/arbitration/interfaces/IDisputeTemplateRegistry.sol " ;
16
+ import {IRealitio} from "./interfaces/IRealitio.sol " ;
17
+ import {IRealitioArbitrator} from "./interfaces/IRealitioArbitrator.sol " ;
18
18
19
19
/// @title RealitioProxyV2
20
20
/// @dev Realitio proxy contract compatible with V2.
21
21
contract RealitioProxyV2 is IRealitioArbitrator , IArbitrableV2 {
22
- uint256 public constant REFUSE_TO_ARBITRATE_REALITIO = type (uint256 ).max; // Constant that represents "Refuse to rule" in realitio format.
23
-
24
- IRealitio public immutable override realitio; // Actual implementation of Realitio.
25
- string public override metadata; // Metadata for Realitio. See IRealitioArbitrator.
26
-
27
- address public governor; // The address that can make changes to the parameters of the contract.
28
- IDisputeTemplateRegistry public templateRegistry; // The dispute template registry.
29
- uint256 public templateId; // Dispute template identifier.
30
-
31
- uint256 private constant NUMBER_OF_RULING_OPTIONS = type (uint256 ).max; // The amount of non 0 choices the arbitrator can give.
22
+ // ************************************* //
23
+ // * Enums / Structs * //
24
+ // ************************************* //
32
25
33
26
enum Status {
34
27
None, // The question hasn't been requested arbitration yet.
@@ -54,15 +47,34 @@ contract RealitioProxyV2 is IRealitioArbitrator, IArbitrableV2 {
54
47
EvidenceModule evidenceModule; // The evidence module for the arbitrator.
55
48
}
56
49
50
+ // ************************************* //
51
+ // * Storage * //
52
+ // ************************************* //
53
+
54
+ uint256 private constant NUMBER_OF_RULING_OPTIONS = type (uint256 ).max; // Maximum, the number of choices in a Realitio question is unknown
55
+
56
+ IRealitio public immutable override realitio; // Actual implementation of Realitio.
57
+ string public override metadata; // Metadata for Realitio. See IRealitioArbitrator.
58
+ address public governor; // The address that can make changes to the parameters of the contract.
59
+ IDisputeTemplateRegistry public templateRegistry; // The dispute template registry.
60
+ uint256 public templateId; // Dispute template identifier.
57
61
mapping (uint256 => ArbitrationRequest) public arbitrationRequests; // Maps a question identifier in uint256 to its arbitration details. Example: arbitrationRequests[uint256(questionID)]
58
62
mapping (address => mapping (uint256 => uint256 )) public arbitratorDisputeIDToQuestionID; // Maps a dispute ID to the ID of the question (converted into uint) with the disputed request in the form arbitratorDisputeIDToQuestionID[arbitrator][disputeID].
59
63
ArbitrationParams[] public arbitrationParamsChanges;
60
64
61
- modifier onlyGovernor () {
65
+ // ************************************* //
66
+ // * Function Modifiers * //
67
+ // ************************************* //
68
+
69
+ modifier onlyGovernor () {
62
70
if (governor != msg .sender ) revert GovernorOnly ();
63
71
_;
64
72
}
65
73
74
+ // ************************************* //
75
+ // * Constructor * //
76
+ // ************************************* //
77
+
66
78
/// @dev Constructor
67
79
/// @param _governor The trusted governor of this contract.
68
80
/// @param _realitio The address of the Realitio contract.
@@ -98,6 +110,10 @@ contract RealitioProxyV2 is IRealitioArbitrator, IArbitrableV2 {
98
110
);
99
111
}
100
112
113
+ // ************************************* //
114
+ // * Governance * //
115
+ // ************************************* //
116
+
101
117
/// @dev Changes the governor of the Reality proxy.
102
118
/// @param _governor The address of the new governor.
103
119
function changeGovernor (address _governor ) external onlyGovernor {
@@ -129,32 +145,45 @@ contract RealitioProxyV2 is IRealitioArbitrator, IArbitrableV2 {
129
145
function changeTemplateRegistry (
130
146
IDisputeTemplateRegistry _templateRegistry ,
131
147
string memory _templateData ,
132
- string memory _templateDataMappings )
133
- external onlyGovernor {
148
+ string memory _templateDataMappings
149
+ ) external onlyGovernor {
134
150
templateRegistry = _templateRegistry;
135
151
templateId = templateRegistry.setDisputeTemplate ("" , _templateData, _templateDataMappings);
136
152
}
137
153
138
154
/// @dev Changes the dispute template.
139
155
/// @param _templateData The new template data for requests.
140
156
/// @param _templateDataMappings The new data mappings json.
141
- function changeDisputeTemplate (string memory _templateData , string memory _templateDataMappings ) external onlyGovernor {
157
+ function changeDisputeTemplate (
158
+ string memory _templateData ,
159
+ string memory _templateDataMappings
160
+ ) external onlyGovernor {
142
161
templateId = templateRegistry.setDisputeTemplate ("" , _templateData, _templateDataMappings);
143
162
}
144
163
164
+ // ************************************* //
165
+ // * State Modifiers * //
166
+ // ************************************* //
167
+
145
168
/// @dev Request arbitration from Kleros for given _questionID.
146
169
/// @param _questionID The question identifier in Realitio contract.
147
170
/// @param _maxPrevious If specified, reverts if a bond higher than this was submitted after you sent your transaction.
148
171
/// @return disputeID ID of the resulting dispute in arbitrator.
149
- function requestArbitration (bytes32 _questionID , uint256 _maxPrevious ) external payable returns (uint256 disputeID ) {
172
+ function requestArbitration (
173
+ bytes32 _questionID ,
174
+ uint256 _maxPrevious
175
+ ) external payable returns (uint256 disputeID ) {
150
176
ArbitrationRequest storage arbitrationRequest = arbitrationRequests[uint256 (_questionID)];
151
- if (arbitrationRequest.status != Status.None) revert ArbitrationAlreadyRequested ();
177
+ if (arbitrationRequest.status != Status.None) revert ArbitrationAlreadyRequested ();
152
178
uint256 arbitrationParamsIndex = arbitrationParamsChanges.length - 1 ;
153
179
IArbitratorV2 arbitrator = arbitrationParamsChanges[arbitrationParamsIndex].arbitrator;
154
180
bytes storage arbitratorExtraData = arbitrationParamsChanges[arbitrationParamsIndex].arbitratorExtraData;
155
181
156
182
// Notify Kleros
157
- disputeID = arbitrator.createDispute {value: msg .value }(NUMBER_OF_RULING_OPTIONS, arbitratorExtraData); /* If msg.value is greater than intended number of votes (specified in arbitratorExtraData),
183
+ disputeID = arbitrator.createDispute {value: msg .value }(
184
+ NUMBER_OF_RULING_OPTIONS,
185
+ arbitratorExtraData
186
+ ); /* If msg.value is greater than intended number of votes (specified in arbitratorExtraData),
158
187
Kleros will automatically spend excess for additional votes. */
159
188
arbitratorDisputeIDToQuestionID[address (arbitrator)][disputeID] = uint256 (_questionID);
160
189
@@ -177,9 +206,9 @@ contract RealitioProxyV2 is IRealitioArbitrator, IArbitrableV2 {
177
206
uint256 questionID = arbitratorDisputeIDToQuestionID[msg .sender ][_disputeID];
178
207
ArbitrationRequest storage arbitrationRequest = arbitrationRequests[questionID];
179
208
IArbitratorV2 arbitrator = arbitrationParamsChanges[arbitrationRequest.arbitrationParamsIndex].arbitrator;
180
-
181
- if (IArbitratorV2 (msg .sender ) != arbitrator) revert ArbitratorOnly ();
182
- if (arbitrationRequest.status != Status.Disputed) revert StatusNotDisputed ();
209
+
210
+ if (IArbitratorV2 (msg .sender ) != arbitrator) revert ArbitratorOnly ();
211
+ if (arbitrationRequest.status != Status.Disputed) revert StatusNotDisputed ();
183
212
184
213
arbitrationRequest.ruling = _ruling;
185
214
arbitrationRequest.status = Status.Ruled;
@@ -201,15 +230,24 @@ contract RealitioProxyV2 is IRealitioArbitrator, IArbitrableV2 {
201
230
address _lastAnswerer
202
231
) external {
203
232
ArbitrationRequest storage arbitrationRequest = arbitrationRequests[uint256 (_questionID)];
204
- if (arbitrationRequest.status != Status.Ruled) revert StatusNotRuled ();
233
+ if (arbitrationRequest.status != Status.Ruled) revert StatusNotRuled ();
205
234
206
235
arbitrationRequest.status = Status.Reported;
207
- // Realitio ruling is shifted by 1 compared to Kleros.
208
- uint256 realitioRuling = arbitrationRequest.ruling != 0 ? arbitrationRequest.ruling - 1 : REFUSE_TO_ARBITRATE_REALITIO;
209
-
210
- realitio.assignWinnerAndSubmitAnswerByArbitrator (_questionID, bytes32 (realitioRuling), arbitrationRequest.requester, _lastHistoryHash, _lastAnswerOrCommitmentID, _lastAnswerer);
236
+ uint256 realitioRuling = _klerosToRealitioRuling (arbitrationRequest.ruling);
237
+ realitio.assignWinnerAndSubmitAnswerByArbitrator (
238
+ _questionID,
239
+ bytes32 (realitioRuling),
240
+ arbitrationRequest.requester,
241
+ _lastHistoryHash,
242
+ _lastAnswerOrCommitmentID,
243
+ _lastAnswerer
244
+ );
211
245
}
212
246
247
+ // ************************************* //
248
+ // * Public Views * //
249
+ // ************************************* //
250
+
213
251
/// @dev Returns arbitration fee by calling arbitrationCost function in the arbitrator contract.
214
252
/// @return fee Arbitration fee that needs to be paid.
215
253
function getDisputeFee (bytes32 ) external view override returns (uint256 fee ) {
@@ -219,9 +257,26 @@ contract RealitioProxyV2 is IRealitioArbitrator, IArbitrableV2 {
219
257
return arbitrator.arbitrationCost (arbitratorExtraData);
220
258
}
221
259
260
+ // ************************************* //
261
+ // * Internal * //
262
+ // ************************************* //
263
+
264
+ /// @dev Converts Kleros ruling to Realitio ruling.
265
+ /// @param _klerosRuling The ruling from Kleros.
266
+ /// @return The ruling in Realitio format.
267
+ function _klerosToRealitioRuling (uint256 _klerosRuling ) internal pure returns (uint256 ) {
268
+ if (_klerosRuling == 0 ) return type (uint256 ).max; // Refuse to arbitrate
269
+ if (_klerosRuling == 1 ) return type (uint256 ).max - 1 ; // Answered Too Soon
270
+ return _klerosRuling - 1 ; // Normal answers are shifted by 1
271
+ }
272
+
273
+ // ************************************* //
274
+ // * Errors * //
275
+ // ************************************* //
276
+
222
277
error StatusNotDisputed ();
223
278
error StatusNotRuled ();
224
279
error ArbitrationAlreadyRequested ();
225
280
error ArbitratorOnly ();
226
281
error GovernorOnly ();
227
- }
282
+ }
0 commit comments