@reality.eth/contracts 3.0.1 → 3.0.4
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/README.md +9 -3
- package/chains/chainid.network.json +7691 -1349
- package/chains/deployments/1/ETH/RealityETH-3.0.json +4 -1
- package/chains/deployments/1/SWISE/RealityETH_ERC20-3.0.json +7 -0
- package/chains/deployments/10/OETH/RealityETH-3.0.json +6 -0
- package/chains/deployments/100/GNO/RealityETH_ERC20-3.0.json +7 -0
- package/chains/deployments/100/SWISE/RealityETH_ERC20-3.0.json +7 -0
- package/chains/deployments/100/XDAI/RealityETH-3.0.json +3 -1
- package/chains/deployments/1337702/ETH/RealityETH-3.0.json +6 -0
- package/chains/deployments/4/ETH/RealityETH-3.0.json +3 -1
- package/chains/deployments/42/ETH/RealityETH-3.0.json +2 -1
- package/chains/deployments/56/DEXE/RealityETH_ERC20-3.0.json +7 -0
- package/chains/deployments/69/OETH/RealityETH-3.0.json +6 -0
- package/chains/deployments/77/XDAI/RealityETH-2.1-rc1.json +1 -3
- package/chains/deployments/777/CTH/RealityETH-3.0.json +6 -0
- package/chains/supported.json +23 -3
- package/development/contracts/Arbitrator.sol +7 -6
- package/development/contracts/BalanceHolder.sol +4 -2
- package/development/contracts/{BalanceHolderERC20.sol → BalanceHolder_ERC20.sol} +3 -2
- package/development/contracts/IArbitrator.sol +4 -7
- package/development/contracts/IArbitratorForeignProxy.sol +12 -0
- package/development/contracts/IBalanceHolder.sol +3 -1
- package/development/contracts/IBalanceHolder_ERC20.sol +11 -0
- package/development/contracts/IERC20.sol +1 -1
- package/development/contracts/IOwned.sol +1 -1
- package/development/contracts/IRealityETH.sol +63 -0
- package/development/contracts/IRealityETH_ERC20.sol +67 -0
- package/development/contracts/Owned.sol +4 -2
- package/development/contracts/RealityETH-3.0.sol +4 -82
- package/development/contracts/RealityETH_ERC20-3.0.sol +3 -3
- package/generated/chains.json +95 -22
- package/generated/contracts.json +89 -7
- package/generated/tokens.json +34 -2
- package/index.js +9 -4
- package/package.json +3 -3
- package/scripts/deploy.js +14 -3
- package/scripts/fetch_and_reformat_chains_json.js +31 -0
- package/scripts/{format_abi.js → format_json.js} +0 -0
- package/scripts/generate_chains_json.js +3 -0
- package/scripts/send_funds.js +52 -0
- package/tokens/CTH.json +7 -0
- package/tokens/DEXE.json +7 -0
- package/tokens/ETH.json +2 -1
- package/tokens/GNO.json +1 -0
- package/tokens/OETH.json +8 -0
- package/tokens/SWISE.json +8 -0
- package/development/contracts/IRealitio.sol +0 -44
- package/development/contracts/MultiSigWallet.sol +0 -391
- package/development/contracts/Realitio.sol +0 -756
- package/development/contracts/RealitioERC20.sol +0 -825
- package/development/contracts/RealitioSafeMath256.sol +0 -36
- package/development/contracts/RealitioSafeMath32.sol +0 -17
- package/development/contracts/Realitio_v2_1.sol +0 -819
- package/development/contracts/SplitterWallet.sol +0 -142
- package/tests/python/test_wallet.py +0 -185
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
pragma solidity ^0.4.25;
|
|
2
|
-
|
|
3
|
-
import './Owned.sol';
|
|
4
|
-
import './RealitioSafeMath256.sol';
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
This contract allows you to split ETH between up to 100 receivers.
|
|
8
|
-
|
|
9
|
-
Each receiver can withdraw their own share of the funds without the cooperation of the others.
|
|
10
|
-
They can also replace their own address with a different one.
|
|
11
|
-
|
|
12
|
-
The receivers can be added by the `owner` contract, for example a multisig wallet.
|
|
13
|
-
The same receiver can be added multiple times if you want an unequal distribution.
|
|
14
|
-
Transfer ownership to 0x0 if you want to lock the receiver list and prevent further changes.
|
|
15
|
-
|
|
16
|
-
This contract receives ETH normally, without using extra gas that could cause incoming payments to fail.
|
|
17
|
-
Anyone can then call allocate() to assign any unassigned balance to the receivers.
|
|
18
|
-
The `allocate()` call may leave a small amount of ETH unassigned due to rounding. This can be allocated in a future call.
|
|
19
|
-
|
|
20
|
-
Once funds are allocated, each party can withdraw their own funds by calling `withdraw()`.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
contract SplitterWallet is Owned {
|
|
24
|
-
|
|
25
|
-
// We sometimes loop over our recipient list, so set a maximum to avoid gas exhaustion
|
|
26
|
-
uint256 constant MAX_RECIPIENTS = 100;
|
|
27
|
-
|
|
28
|
-
using RealitioSafeMath256 for uint256;
|
|
29
|
-
|
|
30
|
-
mapping(address => uint256) public balanceOf;
|
|
31
|
-
|
|
32
|
-
// Sum of all balances in balanceOf
|
|
33
|
-
uint256 public balanceTotal;
|
|
34
|
-
|
|
35
|
-
// List of recipients. May contain duplicates to get paid twice.
|
|
36
|
-
address[] public recipients;
|
|
37
|
-
|
|
38
|
-
event LogWithdraw(
|
|
39
|
-
address indexed user,
|
|
40
|
-
uint256 amount
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
function _firstRecipientIndex(address addr)
|
|
44
|
-
internal
|
|
45
|
-
view returns (uint256)
|
|
46
|
-
{
|
|
47
|
-
uint256 i;
|
|
48
|
-
for(i=0; i<recipients.length; i++) {
|
|
49
|
-
if (recipients[i] == addr) {
|
|
50
|
-
return i;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
revert("Recipient not found");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/// @notice Add a recipient to the list
|
|
57
|
-
/// @param addr The address to add
|
|
58
|
-
/// @dev Doesn't check for duplicates, it's OK to add the same recipient twice for an unequal distribution
|
|
59
|
-
function addRecipient(address addr)
|
|
60
|
-
onlyOwner
|
|
61
|
-
external {
|
|
62
|
-
require(recipients.length < MAX_RECIPIENTS, "Too many recipients");
|
|
63
|
-
recipients.push(addr);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/// @notice Remove a recipient from the list
|
|
67
|
-
/// @param old_addr The address to remove
|
|
68
|
-
/// @dev If your address shows up more than once, removes the first occurance
|
|
69
|
-
function removeRecipient(address old_addr)
|
|
70
|
-
onlyOwner
|
|
71
|
-
external {
|
|
72
|
-
|
|
73
|
-
uint256 idx = _firstRecipientIndex(old_addr);
|
|
74
|
-
assert(recipients[idx] == old_addr);
|
|
75
|
-
|
|
76
|
-
// If you're not deleting the last item, copy the last item over to the thing you're deleting
|
|
77
|
-
uint256 last_idx = recipients.length - 1;
|
|
78
|
-
if (idx != last_idx) {
|
|
79
|
-
recipients[idx] = recipients[last_idx];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
recipients.length--;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/// @notice Replace your own address with a different one
|
|
86
|
-
/// @param new_addr The new address
|
|
87
|
-
/// @dev If your address shows up more than once, replaces the first occurance
|
|
88
|
-
function replaceSelf(address new_addr)
|
|
89
|
-
external {
|
|
90
|
-
uint256 idx = _firstRecipientIndex(msg.sender);
|
|
91
|
-
assert(recipients[idx] == msg.sender);
|
|
92
|
-
recipients[idx] = new_addr;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/// @notice Allocate any unallocated funds from the contract balance
|
|
96
|
-
/// @dev Any time the contract gets funds, they will appear as unallocated
|
|
97
|
-
/// @dev Assign them to the current recipients, and mark them as allocated
|
|
98
|
-
function allocate()
|
|
99
|
-
external {
|
|
100
|
-
|
|
101
|
-
uint256 unallocated = address(this).balance.sub(balanceTotal);
|
|
102
|
-
require(unallocated > 0, "No funds to allocate");
|
|
103
|
-
|
|
104
|
-
uint256 num_recipients = recipients.length;
|
|
105
|
-
|
|
106
|
-
// NB Rounding may leave some funds unallocated, we can claim them later
|
|
107
|
-
uint256 each = unallocated / num_recipients;
|
|
108
|
-
require(each > 0, "No money left to be allocated after rounding down");
|
|
109
|
-
|
|
110
|
-
uint256 i;
|
|
111
|
-
for (i=0; i<num_recipients; i++) {
|
|
112
|
-
address recip = recipients[i];
|
|
113
|
-
balanceOf[recip] = balanceOf[recip].add(each);
|
|
114
|
-
balanceTotal = balanceTotal.add(each);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
assert(address(this).balance >= balanceTotal);
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/// @notice Withdraw the address balance to the owner account
|
|
122
|
-
function withdraw()
|
|
123
|
-
external {
|
|
124
|
-
|
|
125
|
-
uint256 bal = balanceOf[msg.sender];
|
|
126
|
-
require(bal > 0, "Balance must be positive");
|
|
127
|
-
|
|
128
|
-
balanceTotal = balanceTotal.sub(bal);
|
|
129
|
-
balanceOf[msg.sender] = 0;
|
|
130
|
-
msg.sender.transfer(bal);
|
|
131
|
-
|
|
132
|
-
emit LogWithdraw(msg.sender, bal);
|
|
133
|
-
|
|
134
|
-
assert(address(this).balance >= balanceTotal);
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function()
|
|
139
|
-
external payable {
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
from unittest import TestCase, main
|
|
3
|
-
from rlp.utils import encode_hex, decode_hex
|
|
4
|
-
from ethereum.tools import tester as t
|
|
5
|
-
from ethereum.tools.tester import TransactionFailed
|
|
6
|
-
from ethereum.tools import keys
|
|
7
|
-
import time
|
|
8
|
-
from sha3 import keccak_256
|
|
9
|
-
from hashlib import sha256
|
|
10
|
-
from web3 import Web3
|
|
11
|
-
|
|
12
|
-
import os
|
|
13
|
-
|
|
14
|
-
# Command-line flag to skip tests we're not working on
|
|
15
|
-
WORKING_ONLY = os.environ.get('WORKING_ONLY', False)
|
|
16
|
-
|
|
17
|
-
DEPLOY_GAS = 4500000
|
|
18
|
-
|
|
19
|
-
class TestSplitter(TestCase):
|
|
20
|
-
|
|
21
|
-
def setUp(self):
|
|
22
|
-
|
|
23
|
-
self.c = t.Chain()
|
|
24
|
-
|
|
25
|
-
self.splitter_code = open('SplitterWallet.sol').read()
|
|
26
|
-
# Not sure what the right way is to get pyethereum to import the dependencies
|
|
27
|
-
# Pretty sure it's not this, but it does the job:
|
|
28
|
-
safemath_code_raw = open('RealitioSafeMath256.sol').read()
|
|
29
|
-
owned_code_raw = open('Owned.sol').read()
|
|
30
|
-
|
|
31
|
-
self.splitter_code = self.splitter_code.replace("import './Owned.sol';", owned_code_raw);
|
|
32
|
-
self.splitter_code = self.splitter_code.replace("import './RealitioSafeMath256.sol';", safemath_code_raw);
|
|
33
|
-
|
|
34
|
-
self.c.mine()
|
|
35
|
-
self.wallet0= self.c.contract(self.splitter_code, language='solidity', sender=t.k0, startgas=DEPLOY_GAS)
|
|
36
|
-
self.c.mine()
|
|
37
|
-
|
|
38
|
-
@unittest.skipIf(WORKING_ONLY, "Not under construction")
|
|
39
|
-
def test_recipient_limits(self):
|
|
40
|
-
|
|
41
|
-
for i in range(100):
|
|
42
|
-
self.wallet0.addRecipient(t.a1, startgas=80000)
|
|
43
|
-
if i % 30 == 0:
|
|
44
|
-
self.c.mine()
|
|
45
|
-
|
|
46
|
-
self.c.mine()
|
|
47
|
-
with self.assertRaises(TransactionFailed):
|
|
48
|
-
self.wallet0.addRecipient(t.a1, startgas=80000)
|
|
49
|
-
|
|
50
|
-
self.wallet0.removeRecipient(t.a1, startgas=80000)
|
|
51
|
-
self.wallet0.addRecipient(t.a1, startgas=80000)
|
|
52
|
-
|
|
53
|
-
@unittest.skipIf(WORKING_ONLY, "Not under construction")
|
|
54
|
-
def test_gas_worst_case(self):
|
|
55
|
-
|
|
56
|
-
for i in range(100):
|
|
57
|
-
self.wallet0.addRecipient(i+1, startgas=80000)
|
|
58
|
-
if i % 30 == 0:
|
|
59
|
-
self.c.mine()
|
|
60
|
-
|
|
61
|
-
self.assertEqual(self.wallet0.balanceTotal(), 0)
|
|
62
|
-
self.c.tx(t.k0, self.wallet0.address, 100000)
|
|
63
|
-
self.c.mine()
|
|
64
|
-
self.wallet0.allocate(startgas=3000000)
|
|
65
|
-
self.c.mine()
|
|
66
|
-
self.assertEqual(self.wallet0.balanceTotal(), 100000)
|
|
67
|
-
|
|
68
|
-
@unittest.skipIf(WORKING_ONLY, "Not under construction")
|
|
69
|
-
def test_recipient_permissions(self):
|
|
70
|
-
|
|
71
|
-
with self.assertRaises(TransactionFailed):
|
|
72
|
-
self.wallet0.addRecipient(t.a1, startgas=80000, sender=t.k2)
|
|
73
|
-
|
|
74
|
-
self.wallet0.addRecipient(t.a1, startgas=80000, sender=t.k0)
|
|
75
|
-
self.wallet0.addRecipient(t.a2, startgas=80000, sender=t.k0)
|
|
76
|
-
|
|
77
|
-
with self.assertRaises(TransactionFailed):
|
|
78
|
-
self.wallet0.replaceSelf(t.a2, startgas=80000, sender=t.k0)
|
|
79
|
-
|
|
80
|
-
self.wallet0.replaceSelf(t.a2, startgas=80000, sender=t.k2)
|
|
81
|
-
|
|
82
|
-
with self.assertRaises(TransactionFailed):
|
|
83
|
-
self.wallet0.removeRecipient(t.a2, startgas=80000, sender=t.k2)
|
|
84
|
-
|
|
85
|
-
with self.assertRaises(TransactionFailed):
|
|
86
|
-
self.wallet0.transferOwnership(t.a2, startgas=80000, sender=t.k2)
|
|
87
|
-
|
|
88
|
-
self.wallet0.transferOwnership(t.a2, startgas=80000, sender=t.k0)
|
|
89
|
-
|
|
90
|
-
with self.assertRaises(TransactionFailed):
|
|
91
|
-
self.wallet0.removeRecipient(t.a2, startgas=80000, sender=t.k1)
|
|
92
|
-
|
|
93
|
-
self.wallet0.removeRecipient(t.a2, startgas=80000, sender=t.k2)
|
|
94
|
-
|
|
95
|
-
@unittest.skipIf(WORKING_ONLY, "Not under construction")
|
|
96
|
-
def test_split(self):
|
|
97
|
-
|
|
98
|
-
self.assertEqual(self.wallet0.balanceOf(t.a1), 0)
|
|
99
|
-
self.assertEqual(self.wallet0.balanceTotal(), 0)
|
|
100
|
-
self.c.tx(t.k0, self.wallet0.address, 100000)
|
|
101
|
-
self.assertEqual(self.c.head_state.get_balance(self.wallet0.address), 100000)
|
|
102
|
-
self.assertEqual(self.wallet0.balanceOf(t.a1), 0)
|
|
103
|
-
|
|
104
|
-
self.wallet0.addRecipient(t.a1)
|
|
105
|
-
self.wallet0.allocate()
|
|
106
|
-
self.assertEqual(self.wallet0.balanceOf(t.a1), 100000)
|
|
107
|
-
self.assertEqual(self.c.head_state.get_balance(self.wallet0.address), 100000)
|
|
108
|
-
|
|
109
|
-
self.wallet0.withdraw(sender=t.k1)
|
|
110
|
-
self.assertEqual(self.wallet0.balanceOf(t.a1), 0)
|
|
111
|
-
self.assertEqual(self.c.head_state.get_balance(self.wallet0.address), 0)
|
|
112
|
-
|
|
113
|
-
with self.assertRaises(TransactionFailed):
|
|
114
|
-
self.wallet0.withdraw(sender=t.k1)
|
|
115
|
-
self.c.mine()
|
|
116
|
-
|
|
117
|
-
self.wallet0.addRecipient(t.a2)
|
|
118
|
-
|
|
119
|
-
self.assertEqual(self.wallet0.balanceTotal(), 0)
|
|
120
|
-
self.c.tx(t.k0, self.wallet0.address, 100000)
|
|
121
|
-
self.c.tx(t.k0, self.wallet0.address, 50000)
|
|
122
|
-
self.assertEqual(self.c.head_state.get_balance(self.wallet0.address), 150000)
|
|
123
|
-
self.wallet0.allocate()
|
|
124
|
-
self.assertEqual(self.c.head_state.get_balance(self.wallet0.address), 150000)
|
|
125
|
-
self.assertEqual(self.wallet0.balanceTotal(), 150000)
|
|
126
|
-
|
|
127
|
-
self.assertEqual(self.wallet0.balanceOf(t.a1), 75000)
|
|
128
|
-
self.assertEqual(self.wallet0.balanceOf(t.a2), 75000)
|
|
129
|
-
|
|
130
|
-
self.wallet0.withdraw(sender=t.k1)
|
|
131
|
-
self.assertEqual(self.c.head_state.get_balance(self.wallet0.address), 75000)
|
|
132
|
-
self.assertEqual(self.wallet0.balanceOf(t.a1), 0)
|
|
133
|
-
self.assertEqual(self.wallet0.balanceOf(t.a2), 75000)
|
|
134
|
-
self.assertEqual(self.wallet0.balanceTotal(), 75000)
|
|
135
|
-
self.wallet0.withdraw(sender=t.k2)
|
|
136
|
-
self.assertEqual(self.wallet0.balanceOf(t.a2), 0)
|
|
137
|
-
self.assertEqual(self.wallet0.balanceTotal(), 0)
|
|
138
|
-
|
|
139
|
-
self.c.tx(t.k0, self.wallet0.address, 3)
|
|
140
|
-
self.wallet0.allocate()
|
|
141
|
-
self.assertEqual(self.wallet0.balanceTotal(), 2)
|
|
142
|
-
self.assertEqual(self.wallet0.balanceOf(t.a1), 1)
|
|
143
|
-
self.assertEqual(self.wallet0.balanceOf(t.a2), 1)
|
|
144
|
-
self.wallet0.withdraw(sender=t.k1)
|
|
145
|
-
self.wallet0.withdraw(sender=t.k2)
|
|
146
|
-
self.assertEqual(self.wallet0.balanceTotal(), 0)
|
|
147
|
-
self.assertEqual(self.c.head_state.get_balance(self.wallet0.address), 1)
|
|
148
|
-
self.c.tx(t.k0, self.wallet0.address, 5)
|
|
149
|
-
self.wallet0.allocate()
|
|
150
|
-
self.assertEqual(self.wallet0.balanceTotal(), 6)
|
|
151
|
-
self.assertEqual(self.wallet0.balanceOf(t.a1), 3)
|
|
152
|
-
self.assertEqual(self.wallet0.balanceOf(t.a2), 3)
|
|
153
|
-
self.wallet0.withdraw(sender=t.k1)
|
|
154
|
-
self.wallet0.withdraw(sender=t.k2)
|
|
155
|
-
self.assertEqual(self.wallet0.balanceTotal(), 0)
|
|
156
|
-
self.assertEqual(self.c.head_state.get_balance(self.wallet0.address), 0)
|
|
157
|
-
|
|
158
|
-
@unittest.skipIf(WORKING_ONLY, "Not under construction")
|
|
159
|
-
def test_duplicate_recipients(self):
|
|
160
|
-
|
|
161
|
-
self.wallet0.addRecipient(t.a1)
|
|
162
|
-
self.wallet0.addRecipient(t.a2)
|
|
163
|
-
self.wallet0.addRecipient(t.a2)
|
|
164
|
-
|
|
165
|
-
self.assertEqual(self.wallet0.recipients(1), self.wallet0.recipients(2))
|
|
166
|
-
self.assertNotEqual(self.wallet0.recipients(0), self.wallet0.recipients(1))
|
|
167
|
-
|
|
168
|
-
self.wallet0.replaceSelf(t.a3, sender=t.k2)
|
|
169
|
-
# a1 a3 a2
|
|
170
|
-
|
|
171
|
-
self.wallet0.replaceSelf(t.a2, sender=t.k1)
|
|
172
|
-
# a2 a3 a2
|
|
173
|
-
|
|
174
|
-
self.assertEqual(self.wallet0.recipients(0), self.wallet0.recipients(2))
|
|
175
|
-
self.assertNotEqual(self.wallet0.recipients(0), self.wallet0.recipients(1))
|
|
176
|
-
self.assertNotEqual(self.wallet0.recipients(1), self.wallet0.recipients(2))
|
|
177
|
-
|
|
178
|
-
self.c.tx(t.k0, self.wallet0.address, 100)
|
|
179
|
-
self.wallet0.allocate(sender=t.k4)
|
|
180
|
-
self.assertEqual(self.wallet0.balanceOf(t.a3), 33)
|
|
181
|
-
self.assertEqual(self.wallet0.balanceOf(t.a2), 66)
|
|
182
|
-
self.assertEqual(self.wallet0.balanceTotal(), 99)
|
|
183
|
-
|
|
184
|
-
if __name__ == '__main__':
|
|
185
|
-
main()
|