-
Notifications
You must be signed in to change notification settings - Fork 1
/
ExchangeStorage.sol
226 lines (198 loc) · 5.23 KB
/
ExchangeStorage.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
pragma solidity >=0.4.22 <0.6.0;
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
contract ExchangeStorage is Ownable {
/**
* @dev The minimum fee rate that the maker will receive
* Note: 20% = 20 * 10^16
*/
uint256 constant internal minMakerFeeRate = 200000000000000000;
/**
* @dev The maximum fee rate that the maker will receive
* Note: 90% = 90 * 10^16
*/
uint256 constant internal maxMakerFeeRate = 900000000000000000;
/**
* @dev The minimum fee rate that the taker will pay
* Note: 0.1% = 0.1 * 10^16
*/
uint256 constant internal minTakerFeeRate = 1000000000000000;
/**
* @dev The maximum fee rate that the taker will pay
* Note: 1% = 1 * 10^16
*/
uint256 constant internal maxTakerFeeRate = 10000000000000000;
/**
* @dev The referrer will receive 10% from each taker fee.
* Note: 10% = 10 * 10^16
*/
uint256 constant internal referralFeeRate = 100000000000000000;
/**
* @dev The amount of percentage the maker will receive from each taker fee.
* Note: Initially: 50% = 50 * 10^16
*/
uint256 public makerFeeRate;
/**
* @dev The amount of percentage the will pay for taking an order.
* Note: Initially: 0.2% = 0.2 * 10^16
*/
uint256 public takerFeeRate;
/**
* @dev 2-level map: tokenAddress -> userAddress -> balance
*/
mapping(address => mapping(address => uint256)) internal balances;
/**
* @dev map: orderHash -> filled amount
*/
mapping(bytes32 => uint256) internal filled;
/**
* @dev map: orderHash -> isCancelled
*/
mapping(bytes32 => bool) internal cancelled;
/**
* @dev map: user -> userReferrer
*/
mapping(address => address) internal referrals;
/**
* @dev The address where all exchange fees (0,08%) are kept.
* Node: multisig wallet
*/
address public feeAccount;
/**
* @return return the balance of `token` for certain `user`
*/
function getBalance(
address user,
address token
)
public
view
returns (uint256)
{
return balances[token][user];
}
/**
* @return return the balance of multiple tokens for certain `user`
*/
function getBalances(
address user,
address[] memory token
)
public
view
returns(uint256[] memory balanceArray)
{
balanceArray = new uint256[](token.length);
for(uint256 index = 0; index < token.length; index++) {
balanceArray[index] = balances[token[index]][user];
}
}
/**
* @return return the filled amount of order specified by `orderHash`
*/
function getFill(
bytes32 orderHash
)
public
view
returns (uint256)
{
return filled[orderHash];
}
/**
* @return return the filled amount of multple orders specified by `orderHash` array
*/
function getFills(
bytes32[] memory orderHash
)
public
view
returns (uint256[] memory filledArray)
{
filledArray = new uint256[](orderHash.length);
for(uint256 index = 0; index < orderHash.length; index++) {
filledArray[index] = filled[orderHash[index]];
}
}
/**
* @return return true(false) if order specified by `orderHash` is(not) cancelled
*/
function getCancel(
bytes32 orderHash
)
public
view
returns (bool)
{
return cancelled[orderHash];
}
/**
* @return return array of true(false) if orders specified by `orderHash` array are(not) cancelled
*/
function getCancels(
bytes32[] memory orderHash
)
public
view
returns (bool[]memory cancelledArray)
{
cancelledArray = new bool[](orderHash.length);
for(uint256 index = 0; index < orderHash.length; index++) {
cancelledArray[index] = cancelled[orderHash[index]];
}
}
/**
* @return return the referrer address of `user`
*/
function getReferral(
address user
)
public
view
returns (address)
{
return referrals[user];
}
/**
* @return set new rate for the maker fee received
*/
function setMakerFeeRate(
uint256 newMakerFeeRate
)
external
onlyOwner
{
require(
newMakerFeeRate >= minMakerFeeRate &&
newMakerFeeRate <= maxMakerFeeRate,
"INVALID_MAKER_FEE_RATE"
);
makerFeeRate = newMakerFeeRate;
}
/**
* @return set new rate for the taker fee paid
*/
function setTakerFeeRate(
uint256 newTakerFeeRate
)
external
onlyOwner
{
require(
newTakerFeeRate >= minTakerFeeRate &&
newTakerFeeRate <= maxTakerFeeRate,
"INVALID_TAKER_FEE_RATE"
);
takerFeeRate = newTakerFeeRate;
}
/**
* @return set new fee account
*/
function setFeeAccount(
address newFeeAccount
)
external
onlyOwner
{
feeAccount = newFeeAccount;
}
}