@reality.eth/contracts 3.0.22 → 3.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,335 @@
1
+ // SPDX-License-Identifier: GPL-3.0-only
2
+
3
+ pragma solidity ^0.8.10;
4
+
5
+ interface IBalanceHolder {
6
+ function withdraw ( ) external;
7
+ function balanceOf ( address ) external view returns ( uint256 );
8
+ }
9
+
10
+ interface IRealityETH is IBalanceHolder {
11
+ event LogAnswerReveal (bytes32 indexed question_id, address indexed user, bytes32 indexed answer_hash, bytes32 answer, uint256 nonce, uint256 bond);
12
+ event LogCancelArbitration (bytes32 indexed question_id);
13
+ event LogClaim (bytes32 indexed question_id, address indexed user, uint256 amount);
14
+ event LogFinalize (bytes32 indexed question_id, bytes32 indexed answer);
15
+ event LogFundAnswerBounty (bytes32 indexed question_id, uint256 bounty_added, uint256 bounty, address indexed user);
16
+ event LogMinimumBond (bytes32 indexed question_id, uint256 min_bond);
17
+ event LogNewAnswer (bytes32 answer, bytes32 indexed question_id, bytes32 history_hash, address indexed user, uint256 bond, uint256 ts, bool is_commitment);
18
+ event LogNewQuestion (bytes32 indexed question_id, address indexed user, uint256 template_id, string question, bytes32 indexed content_hash, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce, uint256 created);
19
+ event LogNewTemplate (uint256 indexed template_id, address indexed user, string question_text);
20
+ event LogNotifyOfArbitrationRequest (bytes32 indexed question_id, address indexed user);
21
+ event LogReopenQuestion (bytes32 indexed question_id, bytes32 indexed reopened_question_id);
22
+ event LogSetQuestionFee (address arbitrator, uint256 amount);
23
+
24
+ function assignWinnerAndSubmitAnswerByArbitrator (bytes32 question_id, bytes32 answer, address payee_if_wrong, bytes32 last_history_hash, bytes32 last_answer_or_commitment_id, address last_answerer) external;
25
+ function cancelArbitration (bytes32 question_id) external;
26
+ function claimMultipleAndWithdrawBalance (bytes32[] calldata question_ids, uint256[] calldata lengths, bytes32[] calldata hist_hashes, address[] calldata addrs, uint256[] calldata bonds, bytes32[] calldata answers) external;
27
+ function claimWinnings (bytes32 question_id, bytes32[] calldata history_hashes, address[] calldata addrs, uint256[] calldata bonds, bytes32[] calldata answers) external;
28
+ function createTemplate (string calldata content) external returns (uint256);
29
+ function notifyOfArbitrationRequest (bytes32 question_id, address requester, uint256 max_previous) external;
30
+ function setQuestionFee (uint256 fee) external;
31
+ function submitAnswerByArbitrator (bytes32 question_id, bytes32 answer, address answerer) external;
32
+ function submitAnswerReveal (bytes32 question_id, bytes32 answer, uint256 nonce, uint256 bond) external;
33
+ function askQuestion (uint256 template_id, string calldata question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce) external payable returns (bytes32);
34
+ function askQuestionWithMinBond (uint256 template_id, string calldata question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce, uint256 min_bond) external payable returns (bytes32);
35
+ function createTemplateAndAskQuestion (string calldata content, string calldata question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce) external payable returns (bytes32);
36
+ function fundAnswerBounty (bytes32 question_id) external payable;
37
+ function reopenQuestion (uint256 template_id, string calldata question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce, uint256 min_bond, bytes32 reopens_question_id) external payable returns (bytes32);
38
+ function submitAnswer (bytes32 question_id, bytes32 answer, uint256 max_previous) external payable;
39
+ function submitAnswerCommitment (bytes32 question_id, bytes32 answer_hash, uint256 max_previous, address _answerer) external payable;
40
+ function submitAnswerFor (bytes32 question_id, bytes32 answer, uint256 max_previous, address answerer) external payable;
41
+ function arbitrator_question_fees (address) external view returns (uint256);
42
+ function commitments (bytes32) external view returns (uint32 reveal_ts, bool is_revealed, bytes32 revealed_answer);
43
+ function getArbitrator (bytes32 question_id) external view returns (address);
44
+ function getBestAnswer (bytes32 question_id) external view returns (bytes32);
45
+ function getBond (bytes32 question_id) external view returns (uint256);
46
+ function getBounty (bytes32 question_id) external view returns (uint256);
47
+ function getContentHash (bytes32 question_id) external view returns (bytes32);
48
+ function getFinalAnswer (bytes32 question_id) external view returns (bytes32);
49
+ function getFinalAnswerIfMatches (bytes32 question_id, bytes32 content_hash, address arbitrator, uint32 min_timeout, uint256 min_bond) external view returns (bytes32);
50
+ function getFinalizeTS (bytes32 question_id) external view returns (uint32);
51
+ function getHistoryHash (bytes32 question_id) external view returns (bytes32);
52
+ function getMinBond (bytes32 question_id) external view returns (uint256);
53
+ function getOpeningTS (bytes32 question_id) external view returns (uint32);
54
+ function getTimeout (bytes32 question_id) external view returns (uint32);
55
+ function isFinalized (bytes32 question_id) external view returns (bool);
56
+ function isPendingArbitration (bytes32 question_id) external view returns (bool);
57
+ function isSettledTooSoon (bytes32 question_id) external view returns (bool);
58
+ function question_claims (bytes32) external view returns (address payee, uint256 last_bond, uint256 queued_funds);
59
+ function questions (bytes32) external view returns (bytes32 content_hash, address arbitrator, uint32 opening_ts, uint32 timeout, uint32 finalize_ts, bool is_pending_arbitration, uint256 bounty, bytes32 best_answer, bytes32 history_hash, uint256 bond, uint256 min_bond);
60
+ function reopened_questions (bytes32) external view returns (bytes32);
61
+ function reopener_questions (bytes32) external view returns (bool);
62
+ function resultFor (bytes32 question_id) external view returns (bytes32);
63
+ function resultForOnceSettled (bytes32 question_id) external view returns (bytes32);
64
+ function template_hashes (uint256) external view returns (bytes32);
65
+ function templates (uint256) external view returns (uint256);
66
+ }
67
+
68
+ /**
69
+ * @title ERC20 interface
70
+ * @dev see https://github.com/ethereum/EIPs/issues/20
71
+ */
72
+ interface IERC20 {
73
+ function totalSupply() external view returns (uint256);
74
+
75
+ function balanceOf(address who) external view returns (uint256);
76
+
77
+ function allowance(address owner, address spender) external view returns (uint256);
78
+
79
+ function transfer(address to, uint256 value) external returns (bool);
80
+
81
+ function approve(address spender, uint256 value) external returns (bool);
82
+
83
+ function transferFrom(address from, address to, uint256 value) external returns (bool);
84
+
85
+ function decimals() external returns (uint8);
86
+
87
+ function name() external returns (string memory);
88
+
89
+ function symbol() external returns (string memory);
90
+
91
+ event Transfer(address indexed from, address indexed to, uint256 value);
92
+
93
+ event Approval(address indexed owner, address indexed spender, uint256 value);
94
+ }
95
+
96
+ interface IOwned {
97
+ function owner ( ) external view returns ( address );
98
+ function transferOwnership ( address newOwner ) external;
99
+ }
100
+
101
+ contract Owned is IOwned {
102
+ address public owner;
103
+
104
+ constructor() {
105
+ owner = msg.sender;
106
+ }
107
+
108
+ modifier onlyOwner {
109
+ require(msg.sender == owner);
110
+ _;
111
+ }
112
+
113
+ function transferOwnership(address newOwner)
114
+ onlyOwner
115
+ external {
116
+ owner = newOwner;
117
+ }
118
+ }
119
+
120
+ interface IArbitrator {
121
+ function metadata ( ) external view returns ( string memory );
122
+ function arbitration_bounties ( bytes32 ) external view returns ( uint256 );
123
+ function realitio ( ) external view returns ( IRealityETH );
124
+ function realitycheck ( ) external view returns ( IRealityETH );
125
+ function setRealitio ( address addr ) external;
126
+ function setDisputeFee ( uint256 fee ) external;
127
+ function setCustomDisputeFee ( bytes32 question_id, uint256 fee ) external;
128
+ function getDisputeFee ( bytes32 question_id ) external view returns ( uint256 );
129
+ function setQuestionFee ( uint256 fee ) external;
130
+ function submitAnswerByArbitrator ( bytes32 question_id, bytes32 answer, address answerer ) external;
131
+ function requestArbitration ( bytes32 question_id, uint256 max_previous ) external payable returns ( bool );
132
+ function withdraw ( address addr ) external;
133
+ function withdrawERC20 ( IERC20 _token, address addr ) external;
134
+ function callWithdraw ( ) external;
135
+ function setMetaData ( string memory _metadata ) external;
136
+ }
137
+
138
+ contract Arbitrator is Owned, IArbitrator {
139
+
140
+ IRealityETH public realitio;
141
+
142
+ mapping(bytes32 => uint256) public arbitration_bounties;
143
+
144
+ uint256 dispute_fee;
145
+ mapping(bytes32 => uint256) custom_dispute_fees;
146
+
147
+ string public metadata;
148
+
149
+ event LogRequestArbitration(
150
+ bytes32 indexed question_id,
151
+ uint256 fee_paid,
152
+ address requester,
153
+ uint256 remaining
154
+ );
155
+
156
+ event LogSetRealitio(
157
+ address realitio
158
+ );
159
+
160
+ event LogSetQuestionFee(
161
+ uint256 fee
162
+ );
163
+
164
+
165
+ event LogSetDisputeFee(
166
+ uint256 fee
167
+ );
168
+
169
+ event LogSetCustomDisputeFee(
170
+ bytes32 indexed question_id,
171
+ uint256 fee
172
+ );
173
+
174
+ /// @notice Constructor. Sets the deploying address as owner.
175
+ constructor() {
176
+ owner = msg.sender;
177
+ }
178
+
179
+ /// @notice Returns the Realitio contract address - deprecated in favour of realitio()
180
+ function realitycheck()
181
+ external view returns(IRealityETH) {
182
+ return realitio;
183
+ }
184
+
185
+ /// @notice Set the Reality Check contract address
186
+ /// @param addr The address of the Reality Check contract
187
+ function setRealitio(address addr)
188
+ onlyOwner
189
+ public {
190
+ realitio = IRealityETH(addr);
191
+ emit LogSetRealitio(addr);
192
+ }
193
+
194
+ /// @notice Set the default fee
195
+ /// @param fee The default fee amount
196
+ function setDisputeFee(uint256 fee)
197
+ onlyOwner
198
+ public {
199
+ dispute_fee = fee;
200
+ emit LogSetDisputeFee(fee);
201
+ }
202
+
203
+ /// @notice Set a custom fee for this particular question
204
+ /// @param question_id The question in question
205
+ /// @param fee The fee amount
206
+ function setCustomDisputeFee(bytes32 question_id, uint256 fee)
207
+ onlyOwner
208
+ public {
209
+ custom_dispute_fees[question_id] = fee;
210
+ emit LogSetCustomDisputeFee(question_id, fee);
211
+ }
212
+
213
+ /// @notice Return the dispute fee for the specified question. 0 indicates that we won't arbitrate it.
214
+ /// @param question_id The question in question
215
+ /// @dev Uses a general default, but can be over-ridden on a question-by-question basis.
216
+ function getDisputeFee(bytes32 question_id)
217
+ public view returns (uint256) {
218
+ return (custom_dispute_fees[question_id] > 0) ? custom_dispute_fees[question_id] : dispute_fee;
219
+ }
220
+
221
+ /// @notice Set a fee for asking a question with us as the arbitrator
222
+ /// @param fee The fee amount
223
+ /// @dev Default is no fee. Unlike the dispute fee, 0 is an acceptable setting.
224
+ /// You could set an impossibly high fee if you want to prevent us being used as arbitrator unless we submit the question.
225
+ /// (Submitting the question ourselves is not implemented here.)
226
+ /// This fee can be used as a revenue source, an anti-spam measure, or both.
227
+ function setQuestionFee(uint256 fee)
228
+ onlyOwner
229
+ public {
230
+ realitio.setQuestionFee(fee);
231
+ emit LogSetQuestionFee(fee);
232
+ }
233
+
234
+ /// @notice Submit the arbitrator's answer to a question.
235
+ /// @param question_id The question in question
236
+ /// @param answer The answer
237
+ /// @param answerer The answerer. If arbitration changed the answer, it should be the payer. If not, the old answerer.
238
+ function submitAnswerByArbitrator(bytes32 question_id, bytes32 answer, address answerer)
239
+ onlyOwner
240
+ public {
241
+ delete arbitration_bounties[question_id];
242
+ realitio.submitAnswerByArbitrator(question_id, answer, answerer);
243
+ }
244
+
245
+ /// @notice Submit the arbitrator's answer to a question, assigning the winner automatically.
246
+ /// @param question_id The question in question
247
+ /// @param answer The answer
248
+ /// @param payee_if_wrong The account to by credited as winner if the last answer given is wrong, usually the account that paid the arbitrator
249
+ /// @param last_history_hash The history hash before the final one
250
+ /// @param last_answer_or_commitment_id The last answer given, or the commitment ID if it was a commitment.
251
+ /// @param last_answerer The address that supplied the last answer
252
+ function assignWinnerAndSubmitAnswerByArbitrator(bytes32 question_id, bytes32 answer, address payee_if_wrong, bytes32 last_history_hash, bytes32 last_answer_or_commitment_id, address last_answerer)
253
+ onlyOwner
254
+ public {
255
+ delete arbitration_bounties[question_id];
256
+ realitio.assignWinnerAndSubmitAnswerByArbitrator(question_id, answer, payee_if_wrong, last_history_hash, last_answer_or_commitment_id, last_answerer);
257
+ }
258
+
259
+ /// @notice Cancel a previous arbitration request
260
+ /// @dev This is intended for situations where the arbitration is happening non-atomically and the fee or something change.
261
+ /// @param question_id The question in question
262
+ function cancelArbitration(bytes32 question_id)
263
+ onlyOwner
264
+ public {
265
+ realitio.cancelArbitration(question_id);
266
+ }
267
+
268
+ /// @notice Request arbitration, freezing the question until we send submitAnswerByArbitrator
269
+ /// @dev The bounty can be paid only in part, in which case the last person to pay will be considered the payer
270
+ /// Will trigger an error if the notification fails, eg because the question has already been finalized
271
+ /// @param question_id The question in question
272
+ /// @param max_previous If specified, reverts if a bond higher than this was submitted after you sent your transaction.
273
+ function requestArbitration(bytes32 question_id, uint256 max_previous)
274
+ external payable returns (bool) {
275
+
276
+ uint256 arbitration_fee = getDisputeFee(question_id);
277
+ require(arbitration_fee > 0, "The arbitrator must have set a non-zero fee for the question");
278
+
279
+ arbitration_bounties[question_id] += msg.value;
280
+ uint256 paid = arbitration_bounties[question_id];
281
+
282
+ if (paid >= arbitration_fee) {
283
+ realitio.notifyOfArbitrationRequest(question_id, msg.sender, max_previous);
284
+ emit LogRequestArbitration(question_id, msg.value, msg.sender, 0);
285
+ return true;
286
+ } else {
287
+ require(!realitio.isFinalized(question_id), "The question must not have been finalized");
288
+ emit LogRequestArbitration(question_id, msg.value, msg.sender, arbitration_fee - paid);
289
+ return false;
290
+ }
291
+
292
+ }
293
+
294
+ /// @notice Withdraw any accumulated ETH fees to the specified address
295
+ /// @param addr The address to which the balance should be sent
296
+ function withdraw(address addr)
297
+ onlyOwner
298
+ public {
299
+ payable(addr).transfer(address(this).balance);
300
+ }
301
+
302
+ /// @notice Withdraw any accumulated token fees to the specified address
303
+ /// @param addr The address to which the balance should be sent
304
+ /// @dev Only needed if the Realitio contract used is using an ERC20 token
305
+ /// @dev Also only normally useful if a per-question fee is set, otherwise we only have ETH.
306
+ function withdrawERC20(IERC20 _token, address addr)
307
+ onlyOwner
308
+ public {
309
+ uint256 bal = _token.balanceOf(address(this));
310
+ IERC20(_token).transfer(addr, bal);
311
+ }
312
+
313
+ receive()
314
+ external payable {
315
+ }
316
+
317
+ /// @notice Withdraw any accumulated question fees from the specified address into this contract
318
+ /// @dev Funds can then be liberated from this contract with our withdraw() function
319
+ /// @dev This works in the same way whether the realitio contract is using ETH or an ERC20 token
320
+ function callWithdraw()
321
+ onlyOwner
322
+ public {
323
+ realitio.withdraw();
324
+ }
325
+
326
+ /// @notice Set a metadata string, expected to be JSON, containing things like arbitrator TOS address
327
+ function setMetaData(string memory _metadata)
328
+ onlyOwner
329
+ external {
330
+ metadata = _metadata;
331
+ }
332
+
333
+ }
334
+
335
+
@@ -269,7 +269,7 @@
269
269
  },
270
270
  "280": {
271
271
  "chainId": "0x118",
272
- "chainName": "ZKSync Goerli Alpha",
272
+ "chainName": "ZKSync Goerli",
273
273
  "nativeCurrency": {
274
274
  "name": "Ether",
275
275
  "symbol": "WETH",
@@ -280,9 +280,9 @@
280
280
  "https://zksync2-testnet.zksync.dev"
281
281
  ],
282
282
  "hostedRPC": "https://zksync2-testnet.zksync.dev",
283
- "graphURL": "https://api.thegraph.com/subgraphs/name/realityeth/realityeth-zksync-goerli",
283
+ "graphURL": "https://api.thegraph.com/subgraphs/name/realityeth/realityeth-zksync-goerli-2",
284
284
  "blockExplorerUrls": [
285
- "https://zksync2-testnet.zkscan.io/",
285
+ "https://goerli.explorer.zksync.io/",
286
286
  "https://zksync2-testnet.zkscan.io"
287
287
  ]
288
288
  },
@@ -0,0 +1,335 @@
1
+ // SPDX-License-Identifier: GPL-3.0-only
2
+
3
+ pragma solidity ^0.8.10;
4
+
5
+ interface IBalanceHolder {
6
+ function withdraw ( ) external;
7
+ function balanceOf ( address ) external view returns ( uint256 );
8
+ }
9
+
10
+ interface IRealityETH is IBalanceHolder {
11
+ event LogAnswerReveal (bytes32 indexed question_id, address indexed user, bytes32 indexed answer_hash, bytes32 answer, uint256 nonce, uint256 bond);
12
+ event LogCancelArbitration (bytes32 indexed question_id);
13
+ event LogClaim (bytes32 indexed question_id, address indexed user, uint256 amount);
14
+ event LogFinalize (bytes32 indexed question_id, bytes32 indexed answer);
15
+ event LogFundAnswerBounty (bytes32 indexed question_id, uint256 bounty_added, uint256 bounty, address indexed user);
16
+ event LogMinimumBond (bytes32 indexed question_id, uint256 min_bond);
17
+ event LogNewAnswer (bytes32 answer, bytes32 indexed question_id, bytes32 history_hash, address indexed user, uint256 bond, uint256 ts, bool is_commitment);
18
+ event LogNewQuestion (bytes32 indexed question_id, address indexed user, uint256 template_id, string question, bytes32 indexed content_hash, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce, uint256 created);
19
+ event LogNewTemplate (uint256 indexed template_id, address indexed user, string question_text);
20
+ event LogNotifyOfArbitrationRequest (bytes32 indexed question_id, address indexed user);
21
+ event LogReopenQuestion (bytes32 indexed question_id, bytes32 indexed reopened_question_id);
22
+ event LogSetQuestionFee (address arbitrator, uint256 amount);
23
+
24
+ function assignWinnerAndSubmitAnswerByArbitrator (bytes32 question_id, bytes32 answer, address payee_if_wrong, bytes32 last_history_hash, bytes32 last_answer_or_commitment_id, address last_answerer) external;
25
+ function cancelArbitration (bytes32 question_id) external;
26
+ function claimMultipleAndWithdrawBalance (bytes32[] calldata question_ids, uint256[] calldata lengths, bytes32[] calldata hist_hashes, address[] calldata addrs, uint256[] calldata bonds, bytes32[] calldata answers) external;
27
+ function claimWinnings (bytes32 question_id, bytes32[] calldata history_hashes, address[] calldata addrs, uint256[] calldata bonds, bytes32[] calldata answers) external;
28
+ function createTemplate (string calldata content) external returns (uint256);
29
+ function notifyOfArbitrationRequest (bytes32 question_id, address requester, uint256 max_previous) external;
30
+ function setQuestionFee (uint256 fee) external;
31
+ function submitAnswerByArbitrator (bytes32 question_id, bytes32 answer, address answerer) external;
32
+ function submitAnswerReveal (bytes32 question_id, bytes32 answer, uint256 nonce, uint256 bond) external;
33
+ function askQuestion (uint256 template_id, string calldata question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce) external payable returns (bytes32);
34
+ function askQuestionWithMinBond (uint256 template_id, string calldata question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce, uint256 min_bond) external payable returns (bytes32);
35
+ function createTemplateAndAskQuestion (string calldata content, string calldata question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce) external payable returns (bytes32);
36
+ function fundAnswerBounty (bytes32 question_id) external payable;
37
+ function reopenQuestion (uint256 template_id, string calldata question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce, uint256 min_bond, bytes32 reopens_question_id) external payable returns (bytes32);
38
+ function submitAnswer (bytes32 question_id, bytes32 answer, uint256 max_previous) external payable;
39
+ function submitAnswerCommitment (bytes32 question_id, bytes32 answer_hash, uint256 max_previous, address _answerer) external payable;
40
+ function submitAnswerFor (bytes32 question_id, bytes32 answer, uint256 max_previous, address answerer) external payable;
41
+ function arbitrator_question_fees (address) external view returns (uint256);
42
+ function commitments (bytes32) external view returns (uint32 reveal_ts, bool is_revealed, bytes32 revealed_answer);
43
+ function getArbitrator (bytes32 question_id) external view returns (address);
44
+ function getBestAnswer (bytes32 question_id) external view returns (bytes32);
45
+ function getBond (bytes32 question_id) external view returns (uint256);
46
+ function getBounty (bytes32 question_id) external view returns (uint256);
47
+ function getContentHash (bytes32 question_id) external view returns (bytes32);
48
+ function getFinalAnswer (bytes32 question_id) external view returns (bytes32);
49
+ function getFinalAnswerIfMatches (bytes32 question_id, bytes32 content_hash, address arbitrator, uint32 min_timeout, uint256 min_bond) external view returns (bytes32);
50
+ function getFinalizeTS (bytes32 question_id) external view returns (uint32);
51
+ function getHistoryHash (bytes32 question_id) external view returns (bytes32);
52
+ function getMinBond (bytes32 question_id) external view returns (uint256);
53
+ function getOpeningTS (bytes32 question_id) external view returns (uint32);
54
+ function getTimeout (bytes32 question_id) external view returns (uint32);
55
+ function isFinalized (bytes32 question_id) external view returns (bool);
56
+ function isPendingArbitration (bytes32 question_id) external view returns (bool);
57
+ function isSettledTooSoon (bytes32 question_id) external view returns (bool);
58
+ function question_claims (bytes32) external view returns (address payee, uint256 last_bond, uint256 queued_funds);
59
+ function questions (bytes32) external view returns (bytes32 content_hash, address arbitrator, uint32 opening_ts, uint32 timeout, uint32 finalize_ts, bool is_pending_arbitration, uint256 bounty, bytes32 best_answer, bytes32 history_hash, uint256 bond, uint256 min_bond);
60
+ function reopened_questions (bytes32) external view returns (bytes32);
61
+ function reopener_questions (bytes32) external view returns (bool);
62
+ function resultFor (bytes32 question_id) external view returns (bytes32);
63
+ function resultForOnceSettled (bytes32 question_id) external view returns (bytes32);
64
+ function template_hashes (uint256) external view returns (bytes32);
65
+ function templates (uint256) external view returns (uint256);
66
+ }
67
+
68
+ /**
69
+ * @title ERC20 interface
70
+ * @dev see https://github.com/ethereum/EIPs/issues/20
71
+ */
72
+ interface IERC20 {
73
+ function totalSupply() external view returns (uint256);
74
+
75
+ function balanceOf(address who) external view returns (uint256);
76
+
77
+ function allowance(address owner, address spender) external view returns (uint256);
78
+
79
+ function transfer(address to, uint256 value) external returns (bool);
80
+
81
+ function approve(address spender, uint256 value) external returns (bool);
82
+
83
+ function transferFrom(address from, address to, uint256 value) external returns (bool);
84
+
85
+ function decimals() external returns (uint8);
86
+
87
+ function name() external returns (string memory);
88
+
89
+ function symbol() external returns (string memory);
90
+
91
+ event Transfer(address indexed from, address indexed to, uint256 value);
92
+
93
+ event Approval(address indexed owner, address indexed spender, uint256 value);
94
+ }
95
+
96
+ interface IOwned {
97
+ function owner ( ) external view returns ( address );
98
+ function transferOwnership ( address newOwner ) external;
99
+ }
100
+
101
+ contract Owned is IOwned {
102
+ address public owner;
103
+
104
+ constructor() {
105
+ owner = msg.sender;
106
+ }
107
+
108
+ modifier onlyOwner {
109
+ require(msg.sender == owner);
110
+ _;
111
+ }
112
+
113
+ function transferOwnership(address newOwner)
114
+ onlyOwner
115
+ external {
116
+ owner = newOwner;
117
+ }
118
+ }
119
+
120
+ interface IArbitrator {
121
+ function metadata ( ) external view returns ( string memory );
122
+ function arbitration_bounties ( bytes32 ) external view returns ( uint256 );
123
+ function realitio ( ) external view returns ( IRealityETH );
124
+ function realitycheck ( ) external view returns ( IRealityETH );
125
+ function setRealitio ( address addr ) external;
126
+ function setDisputeFee ( uint256 fee ) external;
127
+ function setCustomDisputeFee ( bytes32 question_id, uint256 fee ) external;
128
+ function getDisputeFee ( bytes32 question_id ) external view returns ( uint256 );
129
+ function setQuestionFee ( uint256 fee ) external;
130
+ function submitAnswerByArbitrator ( bytes32 question_id, bytes32 answer, address answerer ) external;
131
+ function requestArbitration ( bytes32 question_id, uint256 max_previous ) external payable returns ( bool );
132
+ function withdraw ( address addr ) external;
133
+ function withdrawERC20 ( IERC20 _token, address addr ) external;
134
+ function callWithdraw ( ) external;
135
+ function setMetaData ( string memory _metadata ) external;
136
+ }
137
+
138
+ contract Arbitrator is Owned, IArbitrator {
139
+
140
+ IRealityETH public realitio;
141
+
142
+ mapping(bytes32 => uint256) public arbitration_bounties;
143
+
144
+ uint256 dispute_fee;
145
+ mapping(bytes32 => uint256) custom_dispute_fees;
146
+
147
+ string public metadata;
148
+
149
+ event LogRequestArbitration(
150
+ bytes32 indexed question_id,
151
+ uint256 fee_paid,
152
+ address requester,
153
+ uint256 remaining
154
+ );
155
+
156
+ event LogSetRealitio(
157
+ address realitio
158
+ );
159
+
160
+ event LogSetQuestionFee(
161
+ uint256 fee
162
+ );
163
+
164
+
165
+ event LogSetDisputeFee(
166
+ uint256 fee
167
+ );
168
+
169
+ event LogSetCustomDisputeFee(
170
+ bytes32 indexed question_id,
171
+ uint256 fee
172
+ );
173
+
174
+ /// @notice Constructor. Sets the deploying address as owner.
175
+ constructor() {
176
+ owner = msg.sender;
177
+ }
178
+
179
+ /// @notice Returns the Realitio contract address - deprecated in favour of realitio()
180
+ function realitycheck()
181
+ external view returns(IRealityETH) {
182
+ return realitio;
183
+ }
184
+
185
+ /// @notice Set the Reality Check contract address
186
+ /// @param addr The address of the Reality Check contract
187
+ function setRealitio(address addr)
188
+ onlyOwner
189
+ public {
190
+ realitio = IRealityETH(addr);
191
+ emit LogSetRealitio(addr);
192
+ }
193
+
194
+ /// @notice Set the default fee
195
+ /// @param fee The default fee amount
196
+ function setDisputeFee(uint256 fee)
197
+ onlyOwner
198
+ public {
199
+ dispute_fee = fee;
200
+ emit LogSetDisputeFee(fee);
201
+ }
202
+
203
+ /// @notice Set a custom fee for this particular question
204
+ /// @param question_id The question in question
205
+ /// @param fee The fee amount
206
+ function setCustomDisputeFee(bytes32 question_id, uint256 fee)
207
+ onlyOwner
208
+ public {
209
+ custom_dispute_fees[question_id] = fee;
210
+ emit LogSetCustomDisputeFee(question_id, fee);
211
+ }
212
+
213
+ /// @notice Return the dispute fee for the specified question. 0 indicates that we won't arbitrate it.
214
+ /// @param question_id The question in question
215
+ /// @dev Uses a general default, but can be over-ridden on a question-by-question basis.
216
+ function getDisputeFee(bytes32 question_id)
217
+ public view returns (uint256) {
218
+ return (custom_dispute_fees[question_id] > 0) ? custom_dispute_fees[question_id] : dispute_fee;
219
+ }
220
+
221
+ /// @notice Set a fee for asking a question with us as the arbitrator
222
+ /// @param fee The fee amount
223
+ /// @dev Default is no fee. Unlike the dispute fee, 0 is an acceptable setting.
224
+ /// You could set an impossibly high fee if you want to prevent us being used as arbitrator unless we submit the question.
225
+ /// (Submitting the question ourselves is not implemented here.)
226
+ /// This fee can be used as a revenue source, an anti-spam measure, or both.
227
+ function setQuestionFee(uint256 fee)
228
+ onlyOwner
229
+ public {
230
+ realitio.setQuestionFee(fee);
231
+ emit LogSetQuestionFee(fee);
232
+ }
233
+
234
+ /// @notice Submit the arbitrator's answer to a question.
235
+ /// @param question_id The question in question
236
+ /// @param answer The answer
237
+ /// @param answerer The answerer. If arbitration changed the answer, it should be the payer. If not, the old answerer.
238
+ function submitAnswerByArbitrator(bytes32 question_id, bytes32 answer, address answerer)
239
+ onlyOwner
240
+ public {
241
+ delete arbitration_bounties[question_id];
242
+ realitio.submitAnswerByArbitrator(question_id, answer, answerer);
243
+ }
244
+
245
+ /// @notice Submit the arbitrator's answer to a question, assigning the winner automatically.
246
+ /// @param question_id The question in question
247
+ /// @param answer The answer
248
+ /// @param payee_if_wrong The account to by credited as winner if the last answer given is wrong, usually the account that paid the arbitrator
249
+ /// @param last_history_hash The history hash before the final one
250
+ /// @param last_answer_or_commitment_id The last answer given, or the commitment ID if it was a commitment.
251
+ /// @param last_answerer The address that supplied the last answer
252
+ function assignWinnerAndSubmitAnswerByArbitrator(bytes32 question_id, bytes32 answer, address payee_if_wrong, bytes32 last_history_hash, bytes32 last_answer_or_commitment_id, address last_answerer)
253
+ onlyOwner
254
+ public {
255
+ delete arbitration_bounties[question_id];
256
+ realitio.assignWinnerAndSubmitAnswerByArbitrator(question_id, answer, payee_if_wrong, last_history_hash, last_answer_or_commitment_id, last_answerer);
257
+ }
258
+
259
+ /// @notice Cancel a previous arbitration request
260
+ /// @dev This is intended for situations where the arbitration is happening non-atomically and the fee or something change.
261
+ /// @param question_id The question in question
262
+ function cancelArbitration(bytes32 question_id)
263
+ onlyOwner
264
+ public {
265
+ realitio.cancelArbitration(question_id);
266
+ }
267
+
268
+ /// @notice Request arbitration, freezing the question until we send submitAnswerByArbitrator
269
+ /// @dev The bounty can be paid only in part, in which case the last person to pay will be considered the payer
270
+ /// Will trigger an error if the notification fails, eg because the question has already been finalized
271
+ /// @param question_id The question in question
272
+ /// @param max_previous If specified, reverts if a bond higher than this was submitted after you sent your transaction.
273
+ function requestArbitration(bytes32 question_id, uint256 max_previous)
274
+ external payable returns (bool) {
275
+
276
+ uint256 arbitration_fee = getDisputeFee(question_id);
277
+ require(arbitration_fee > 0, "The arbitrator must have set a non-zero fee for the question");
278
+
279
+ arbitration_bounties[question_id] += msg.value;
280
+ uint256 paid = arbitration_bounties[question_id];
281
+
282
+ if (paid >= arbitration_fee) {
283
+ realitio.notifyOfArbitrationRequest(question_id, msg.sender, max_previous);
284
+ emit LogRequestArbitration(question_id, msg.value, msg.sender, 0);
285
+ return true;
286
+ } else {
287
+ require(!realitio.isFinalized(question_id), "The question must not have been finalized");
288
+ emit LogRequestArbitration(question_id, msg.value, msg.sender, arbitration_fee - paid);
289
+ return false;
290
+ }
291
+
292
+ }
293
+
294
+ /// @notice Withdraw any accumulated ETH fees to the specified address
295
+ /// @param addr The address to which the balance should be sent
296
+ function withdraw(address addr)
297
+ onlyOwner
298
+ public {
299
+ payable(addr).transfer(address(this).balance);
300
+ }
301
+
302
+ /// @notice Withdraw any accumulated token fees to the specified address
303
+ /// @param addr The address to which the balance should be sent
304
+ /// @dev Only needed if the Realitio contract used is using an ERC20 token
305
+ /// @dev Also only normally useful if a per-question fee is set, otherwise we only have ETH.
306
+ function withdrawERC20(IERC20 _token, address addr)
307
+ onlyOwner
308
+ public {
309
+ uint256 bal = _token.balanceOf(address(this));
310
+ IERC20(_token).transfer(addr, bal);
311
+ }
312
+
313
+ receive()
314
+ external payable {
315
+ }
316
+
317
+ /// @notice Withdraw any accumulated question fees from the specified address into this contract
318
+ /// @dev Funds can then be liberated from this contract with our withdraw() function
319
+ /// @dev This works in the same way whether the realitio contract is using ETH or an ERC20 token
320
+ function callWithdraw()
321
+ onlyOwner
322
+ public {
323
+ realitio.withdraw();
324
+ }
325
+
326
+ /// @notice Set a metadata string, expected to be JSON, containing things like arbitrator TOS address
327
+ function setMetaData(string memory _metadata)
328
+ onlyOwner
329
+ external {
330
+ metadata = _metadata;
331
+ }
332
+
333
+ }
334
+
335
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reality.eth/contracts",
3
- "version": "3.0.22",
3
+ "version": "3.0.23",
4
4
  "description": "Collection of smart contracts for the Realitio fact verification platform",
5
5
  "scripts": {
6
6
  "generate-chains": "node scripts/generate_chains_json.js",
@@ -30,7 +30,7 @@
30
30
  "url": "https://github.com/RealityETH/monorepo/issues"
31
31
  },
32
32
  "homepage": "https://reality.eth.link",
33
- "gitHead": "f5f4349ac42ad43c41c012eb187e33869aa69fd5",
33
+ "gitHead": "d115d0f9e969993975ef156c559d6f247c783b81",
34
34
  "dependencies": {
35
35
  "ethers": "^5.6.8"
36
36
  }