@reality.eth/contracts 3.0.48 → 4.0.0-rc.1
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.
- package/abi/solc-0.8.20/RealityETH-4.0.abi.json +1 -1
- package/abi/solc-0.8.20/RealityETHFreezableExample_ERC20-4.0.abi.json +1 -0
- package/abi/solc-0.8.20/RealityETHReopenable-4.0.abi.json +1 -0
- package/abi/solc-0.8.20/RealityETHReopenable_ERC20-4.0.abi.json +1 -0
- package/abi/solc-0.8.20/RealityETH_ERC20-4.0.abi.json +1 -1
- package/bytecode/RealityETH-4.0.bin +1 -1
- package/bytecode/RealityETHFreezableExample_ERC20-4.0.bin +1 -0
- package/bytecode/RealityETHReopenable-4.0.bin +1 -0
- package/bytecode/RealityETHReopenable_ERC20-4.0.bin +1 -0
- package/bytecode/RealityETH_ERC20-4.0.bin +1 -1
- package/chains/supported.json +1 -1
- package/development/contracts/IBalanceHolder.sol +1 -0
- package/development/contracts/IRealityETH.sol +6 -2
- package/development/contracts/{IRealityETHCore.sol → IRealityETHCore_Common.sol} +4 -23
- package/development/contracts/IRealityETHCore_ERC20.sol +3 -124
- package/development/contracts/IRealityETHCore_Native.sol +12 -0
- package/development/contracts/IRealityETHCreateTemplateAndAskQuestion.sol +8 -0
- package/development/contracts/IRealityETHHistoryVerification.sol +8 -0
- package/development/contracts/IRealityETHReopenable.sol +22 -0
- package/development/contracts/IRealityETHReopenable_ERC20.sol +23 -0
- package/development/contracts/IRealityETH_ERC20.sol +5 -1
- package/development/contracts/RealityETH-4.0.sol +12 -614
- package/development/contracts/RealityETHCore_Common.sol +535 -0
- package/development/contracts/RealityETHFreezableExample_ERC20-4.0.sol +17 -0
- package/development/contracts/RealityETHFreezable_ERC20.sol +39 -0
- package/development/contracts/RealityETHReopenable-4.0.sol +119 -0
- package/development/contracts/RealityETHReopenable_ERC20-4.0.sol +122 -0
- package/development/contracts/RealityETH_ERC20-4.0.sol +13 -614
- package/generated/chains.json +1 -1
- package/package.json +2 -2
- package/tests/python/test.py +186 -5
- package/development/contracts/BalanceHolder_ERC20.sol +0 -21
- package/development/contracts/IBalanceHolder_ERC20.sol +0 -11
package/generated/chains.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reality.eth/contracts",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-rc.1",
|
|
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",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"url": "https://github.com/RealityETH/monorepo/issues"
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://reality.eth.link",
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "03e4a48bc6ffcb5d327c5503fa1afb2eba3f97fb",
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"ethers": "^5.6.8"
|
|
40
40
|
}
|
package/tests/python/test.py
CHANGED
|
@@ -36,6 +36,11 @@ if "ERC20" in REALITYETH_CONTRACT:
|
|
|
36
36
|
else:
|
|
37
37
|
ERC20 = False
|
|
38
38
|
|
|
39
|
+
if "Freezable" in REALITYETH_CONTRACT:
|
|
40
|
+
IS_FREEZE_SUPPORTED = True
|
|
41
|
+
else:
|
|
42
|
+
IS_FREEZE_SUPPORTED = False
|
|
43
|
+
|
|
39
44
|
print("Version is "+str(VERNUM))
|
|
40
45
|
|
|
41
46
|
if VERNUM >= 2.1:
|
|
@@ -43,12 +48,27 @@ if VERNUM >= 2.1:
|
|
|
43
48
|
else:
|
|
44
49
|
CLAIM_FEE = 0
|
|
45
50
|
|
|
51
|
+
if VERNUM == 3.0:
|
|
52
|
+
IS_ANSWERED_TOO_SOON_SUPPORTED = True
|
|
53
|
+
elif VERNUM >= 4.0:
|
|
54
|
+
if "Reopenable" in REALITYETH_CONTRACT:
|
|
55
|
+
IS_ANSWERED_TOO_SOON_SUPPORTED = True
|
|
56
|
+
else:
|
|
57
|
+
IS_ANSWERED_TOO_SOON_SUPPORTED = False
|
|
58
|
+
else:
|
|
59
|
+
# TODO: Add special version
|
|
60
|
+
IS_ANSWERED_TOO_SOON_SUPPORTED = False
|
|
61
|
+
|
|
46
62
|
if VERNUM >= 4.0:
|
|
47
63
|
IS_COMMIT_REVEAL_SUPPORTED = False
|
|
64
|
+
IS_PROVE_HISTORY_SUPPORTED = True
|
|
48
65
|
else:
|
|
49
66
|
IS_COMMIT_REVEAL_SUPPORTED = True
|
|
67
|
+
IS_PROVE_HISTORY_SUPPORTED = False
|
|
50
68
|
|
|
51
69
|
print("IS_COMMIT_REVEAL_SUPPORTED is "+str(IS_COMMIT_REVEAL_SUPPORTED))
|
|
70
|
+
print("IS_ANSWERED_TOO_SOON_SUPPORTED is "+str(IS_ANSWERED_TOO_SOON_SUPPORTED))
|
|
71
|
+
print("CLAIM_FEE is "+str(CLAIM_FEE))
|
|
52
72
|
|
|
53
73
|
DEPLOY_GAS = 8000000
|
|
54
74
|
|
|
@@ -2406,7 +2426,7 @@ class TestRealitio(TestCase):
|
|
|
2406
2426
|
@unittest.skipIf(WORKING_ONLY, "Not under construction")
|
|
2407
2427
|
def test_reopen_question(self):
|
|
2408
2428
|
|
|
2409
|
-
if
|
|
2429
|
+
if not IS_ANSWERED_TOO_SOON_SUPPORTED:
|
|
2410
2430
|
print("Skipping test_reopen_question, not a feature of this contract")
|
|
2411
2431
|
return
|
|
2412
2432
|
|
|
@@ -2552,7 +2572,7 @@ class TestRealitio(TestCase):
|
|
|
2552
2572
|
@unittest.skipIf(WORKING_ONLY, "Not under construction")
|
|
2553
2573
|
def test_too_soon_bounty(self):
|
|
2554
2574
|
|
|
2555
|
-
if
|
|
2575
|
+
if not IS_ANSWERED_TOO_SOON_SUPPORTED:
|
|
2556
2576
|
print("Skipping test_reopen_question, not a feature of this contract")
|
|
2557
2577
|
return
|
|
2558
2578
|
|
|
@@ -2590,8 +2610,8 @@ class TestRealitio(TestCase):
|
|
|
2590
2610
|
print("Skipping test_too_soon_bonds_under_unrevealed_commit, contract does not support commit-reveal")
|
|
2591
2611
|
return
|
|
2592
2612
|
|
|
2593
|
-
if
|
|
2594
|
-
print("Skipping
|
|
2613
|
+
if not IS_ANSWERED_TOO_SOON_SUPPORTED:
|
|
2614
|
+
print("Skipping test_too_soon_bonds_under_unrevealed_commit , not a feature of this contract")
|
|
2595
2615
|
return
|
|
2596
2616
|
|
|
2597
2617
|
k0 = self.web3.eth.accounts[0]
|
|
@@ -2624,12 +2644,173 @@ class TestRealitio(TestCase):
|
|
|
2624
2644
|
|
|
2625
2645
|
self.assertEqual(self.rc0.functions.balanceOf(k3).call(), claimable)
|
|
2626
2646
|
|
|
2647
|
+
@unittest.skipIf(WORKING_ONLY, "Not under construction")
|
|
2648
|
+
def test_is_history_of_unfinalized_question_valid(self):
|
|
2649
|
+
|
|
2650
|
+
if not IS_PROVE_HISTORY_SUPPORTED:
|
|
2651
|
+
print("Skipping test_is_history_of_unfinalized_question_valid, not supported by this version")
|
|
2652
|
+
return
|
|
2653
|
+
|
|
2654
|
+
k2 = self.web3.eth.accounts[2]
|
|
2655
|
+
k3 = self.web3.eth.accounts[3]
|
|
2656
|
+
k4 = self.web3.eth.accounts[4]
|
|
2657
|
+
|
|
2658
|
+
if ERC20:
|
|
2659
|
+
self._issueTokens(k3, 100000, 50000)
|
|
2660
|
+
self._issueTokens(k4, 100000, 50000)
|
|
2661
|
+
|
|
2662
|
+
st = None
|
|
2663
|
+
st = self.submitAnswerReturnUpdatedState( st, self.question_id, 1001, 0, 20, k3)
|
|
2664
|
+
st = self.submitAnswerReturnUpdatedState( st, self.question_id, 1002, 20, 40, k3)
|
|
2665
|
+
st = self.submitAnswerReturnUpdatedState( st, self.question_id, 1001, 40, 80, k4)
|
|
2666
|
+
st = self.submitAnswerReturnUpdatedState( st, self.question_id, 1004, 80, 160, k3)
|
|
2667
|
+
st = self.submitAnswerReturnUpdatedState( st, self.question_id, 1003, 160, 320, k4)
|
|
2668
|
+
st = self.submitAnswerReturnUpdatedState( st, self.question_id, 1001, 320, 640, k4)
|
|
2669
|
+
|
|
2670
|
+
hashes = st['hash']
|
|
2671
|
+
addrs = st['addr']
|
|
2672
|
+
bonds = st['bond']
|
|
2673
|
+
answers = st['answer']
|
|
2674
|
+
|
|
2675
|
+
self.assertTrue(self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, hashes, addrs, bonds, answers).call())
|
|
2676
|
+
|
|
2677
|
+
bad_hashes = hashes.copy()
|
|
2678
|
+
bad_hashes[2] = bad_hashes[1]
|
|
2679
|
+
self.assertFalse(self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, bad_hashes, addrs, bonds, answers).call())
|
|
2680
|
+
|
|
2681
|
+
bad_addrs = addrs.copy()
|
|
2682
|
+
bad_addrs[2] = k2
|
|
2683
|
+
self.assertFalse(self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, hashes, bad_addrs, bonds, answers).call())
|
|
2684
|
+
|
|
2685
|
+
bad_bonds = bonds.copy()
|
|
2686
|
+
bad_bonds[1] = 987
|
|
2687
|
+
self.assertFalse(self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, hashes, addrs, bad_bonds, answers).call())
|
|
2688
|
+
|
|
2689
|
+
bad_answers = answers.copy()
|
|
2690
|
+
bad_answers[1] = to_answer_for_contract(987)
|
|
2691
|
+
self.assertFalse(self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, hashes, addrs, bonds, bad_answers).call())
|
|
2692
|
+
|
|
2693
|
+
# Supplying just the end of the list (lowest-bond answers) will fail
|
|
2694
|
+
self.assertFalse(self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, hashes[3:], addrs[3:], bonds[3:], answers[3:]).call())
|
|
2695
|
+
|
|
2696
|
+
# Supplying just the start of the list (highest-bond answers) will work
|
|
2697
|
+
self.assertTrue(self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, hashes[:3], addrs[:3], bonds[:3], answers[:3]).call())
|
|
2698
|
+
|
|
2699
|
+
# Any unevenness in the length of parameters passed will fail
|
|
2700
|
+
self.assertFalse(self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, hashes[:4], addrs[:3], bonds[:3], answers[:3]).call())
|
|
2701
|
+
self.assertFalse(self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, hashes[:3], addrs[:4], bonds[:3], answers[:3]).call())
|
|
2702
|
+
self.assertFalse(self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, hashes[:3], addrs[:3], bonds[:4], answers[:3]).call())
|
|
2703
|
+
self.assertFalse(self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, hashes[:3], addrs[:3], bonds[:3], answers[:4]).call())
|
|
2704
|
+
|
|
2705
|
+
self.assertFalse(self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, hashes[:2], addrs[:3], bonds[:3], answers[:3]).call())
|
|
2706
|
+
self.assertFalse(self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, hashes[:3], addrs[:2], bonds[:3], answers[:3]).call())
|
|
2707
|
+
self.assertFalse(self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, hashes[:3], addrs[:3], bonds[:2], answers[:3]).call())
|
|
2708
|
+
self.assertFalse(self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, hashes[:3], addrs[:3], bonds[:3], answers[:2]).call())
|
|
2709
|
+
|
|
2710
|
+
self._advance_clock(33)
|
|
2711
|
+
|
|
2712
|
+
# Once we finalize this will revert
|
|
2713
|
+
with self.assertRaises(TransactionFailed):
|
|
2714
|
+
self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, st['hash'], st['addr'], st['bond'], st['answer']).transact()
|
|
2715
|
+
|
|
2716
|
+
#@unittest.skipIf(WORKING_ONLY, "Not under construction")
|
|
2717
|
+
def test_frozen(self):
|
|
2718
|
+
|
|
2719
|
+
if not IS_FREEZE_SUPPORTED:
|
|
2720
|
+
print("Skipping test_frozen, not supported by this version")
|
|
2721
|
+
return
|
|
2722
|
+
|
|
2723
|
+
k0 = self.web3.eth.accounts[0]
|
|
2724
|
+
k3 = self.web3.eth.accounts[3]
|
|
2725
|
+
k4 = self.web3.eth.accounts[4]
|
|
2726
|
+
k5 = self.web3.eth.accounts[5]
|
|
2727
|
+
|
|
2728
|
+
if ERC20:
|
|
2729
|
+
self._issueTokens(k0, 1000000, 1000000)
|
|
2730
|
+
self._issueTokens(k3, 1000000, 1000000)
|
|
2731
|
+
self._issueTokens(k4, 1000000, 1000000)
|
|
2627
2732
|
|
|
2628
|
-
|
|
2733
|
+
# We'll set up a question that finalizes before the freeze date to check we can still get its result after the freeze
|
|
2734
|
+
txid = self.rc0.functions.askQuestionERC20(
|
|
2735
|
+
0,
|
|
2736
|
+
"my early question",
|
|
2737
|
+
self.arb0.address,
|
|
2738
|
+
30,
|
|
2739
|
+
0,
|
|
2740
|
+
0
|
|
2741
|
+
,1100
|
|
2742
|
+
).transact(self._txargs())
|
|
2743
|
+
early_question_id = calculate_question_id(self.rc0.address, 0, "my early question", self.arb0.address, 30, 0, 0, self.web3.eth.accounts[0], 0)
|
|
2744
|
+
st = None
|
|
2745
|
+
st = self.submitAnswerReturnUpdatedState( st, early_question_id, 1001, 0, 200, k3)
|
|
2746
|
+
st = self.submitAnswerReturnUpdatedState( st, early_question_id, 1001, 200, 400, k3)
|
|
2629
2747
|
|
|
2748
|
+
self.assertFalse(self.rc0.functions.isFinalized(early_question_id).call())
|
|
2749
|
+
# Can't get result as not finalized
|
|
2750
|
+
with self.assertRaises(TransactionFailed):
|
|
2751
|
+
self.assertEqual(self.rc0.functions.resultFor(early_question_id).call(), to_answer_for_contract(1001))
|
|
2630
2752
|
|
|
2753
|
+
self._advance_clock(40)
|
|
2754
|
+
self.assertTrue(self.rc0.functions.isFinalized(early_question_id).call())
|
|
2755
|
+
self.assertEqual(self.rc0.functions.resultFor(early_question_id).call(), to_answer_for_contract(1001))
|
|
2631
2756
|
|
|
2757
|
+
txid = self.rc0.functions.askQuestionERC20(
|
|
2758
|
+
0,
|
|
2759
|
+
"my question",
|
|
2760
|
+
self.arb0.address,
|
|
2761
|
+
30,
|
|
2762
|
+
0,
|
|
2763
|
+
0
|
|
2764
|
+
,1100
|
|
2765
|
+
).transact(self._txargs())
|
|
2766
|
+
question_id = calculate_question_id(self.rc0.address, 0, "my question", self.arb0.address, 30, 0, 0, self.web3.eth.accounts[0], 0)
|
|
2632
2767
|
|
|
2768
|
+
# Start with the series we used before and make sure it goes through
|
|
2769
|
+
st = None
|
|
2770
|
+
st = self.submitAnswerReturnUpdatedState( st, question_id, 1001, 0, 200, k3)
|
|
2771
|
+
st = self.submitAnswerReturnUpdatedState( st, question_id, 1001, 200, 400, k3)
|
|
2772
|
+
|
|
2773
|
+
freeze_ts = self.rc0.functions.freeze_ts().call()
|
|
2774
|
+
self.assertTrue(freeze_ts == 0, "Freeze timestamp should be zero before freeze")
|
|
2775
|
+
self.rc0.functions.setFreezeTimestamp(self._block_timestamp()).transact(self._txargs())
|
|
2776
|
+
freeze_ts = self.rc0.functions.freeze_ts().call()
|
|
2777
|
+
self.assertTrue(freeze_ts > 0, "Freeze timestamp should be not zero after freeze")
|
|
2778
|
+
|
|
2779
|
+
# You can no longer answer a question
|
|
2780
|
+
with self.assertRaises(TransactionFailed):
|
|
2781
|
+
self.submitAnswerReturnUpdatedState( st, question_id, 1001, 400, 800, k3)
|
|
2782
|
+
|
|
2783
|
+
# You can no longer request arbitration
|
|
2784
|
+
fee = self.arb0.functions.getDisputeFee(encode_hex("0x00")).call()
|
|
2785
|
+
txid = self.arb0.functions.requestArbitration(question_id, 0).transact(self._txargs(val=fee))
|
|
2786
|
+
with self.assertRaises(TransactionFailed):
|
|
2787
|
+
self.raiseOnZeroStatus(txid)
|
|
2788
|
+
|
|
2789
|
+
# The question will no longer finalize, even after the time has elapsed
|
|
2790
|
+
self.assertFalse(self.rc0.functions.isFinalized(question_id).call())
|
|
2791
|
+
self._advance_clock(40)
|
|
2792
|
+
self.assertFalse(self.rc0.functions.isFinalized(question_id).call())
|
|
2793
|
+
# Can't get result as not finalized
|
|
2794
|
+
with self.assertRaises(TransactionFailed):
|
|
2795
|
+
self.assertEqual(self.rc0.functions.resultFor(question_id).call(), to_answer_for_contract(1001))
|
|
2796
|
+
|
|
2797
|
+
# The question that was finalized before is still finalized
|
|
2798
|
+
self.assertTrue(self.rc0.functions.isFinalized(early_question_id).call())
|
|
2799
|
+
# You can still get the result
|
|
2800
|
+
self.assertEqual(self.rc0.functions.resultFor(early_question_id).call(), to_answer_for_contract(1001))
|
|
2801
|
+
|
|
2802
|
+
# You can no longer ask a new question
|
|
2803
|
+
with self.assertRaises(TransactionFailed):
|
|
2804
|
+
txid = self.rc0.functions.askQuestionERC20(
|
|
2805
|
+
0,
|
|
2806
|
+
"my question xyz",
|
|
2807
|
+
self.arb0.address,
|
|
2808
|
+
30,
|
|
2809
|
+
0,
|
|
2810
|
+
0
|
|
2811
|
+
,1100
|
|
2812
|
+
).transact(self._txargs())
|
|
2813
|
+
self.raiseOnZeroStatus(txid)
|
|
2633
2814
|
|
|
2634
2815
|
|
|
2635
2816
|
if __name__ == '__main__':
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
|
|
3
|
-
pragma solidity ^0.8.20;
|
|
4
|
-
|
|
5
|
-
import {IERC20} from "./IERC20.sol";
|
|
6
|
-
import {IBalanceHolder_ERC20} from "./IBalanceHolder_ERC20.sol";
|
|
7
|
-
|
|
8
|
-
contract BalanceHolder_ERC20 is IBalanceHolder_ERC20 {
|
|
9
|
-
IERC20 public token;
|
|
10
|
-
|
|
11
|
-
mapping(address => uint256) public balanceOf;
|
|
12
|
-
|
|
13
|
-
event LogWithdraw(address indexed user, uint256 amount);
|
|
14
|
-
|
|
15
|
-
function withdraw() public {
|
|
16
|
-
uint256 bal = balanceOf[msg.sender];
|
|
17
|
-
balanceOf[msg.sender] = 0;
|
|
18
|
-
require(token.transfer(msg.sender, bal));
|
|
19
|
-
emit LogWithdraw(msg.sender, bal);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
|
|
3
|
-
pragma solidity 0.8.20;
|
|
4
|
-
|
|
5
|
-
import "./IERC20.sol";
|
|
6
|
-
|
|
7
|
-
interface IBalanceHolder_ERC20 {
|
|
8
|
-
function withdraw() external;
|
|
9
|
-
function balanceOf(address) external view returns (uint256);
|
|
10
|
-
function token() external view returns (IERC20);
|
|
11
|
-
}
|