-
Notifications
You must be signed in to change notification settings - Fork 19
/
API.sol
334 lines (286 loc) · 9.52 KB
/
API.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
pragma solidity ^0.4.24;
import "../math/SafeMath.sol";
interface TokenView {
function totalSupply() external view returns (uint);
function balanceOf(address _investor) external view returns (uint);
function valuePerToken() external view returns (uint);
function scalingFactor() external view returns (uint);
function assetIncome() external view returns (uint);
function getERC20() external view returns (address);
}
interface DBView {
function uintStorage(bytes32 _key) external view returns (uint);
function stringStorage(bytes32 _key) external view returns (string);
function addressStorage(bytes32 _key) external view returns (address);
function bytesStorage(bytes32 _key) external view returns (bytes);
function bytes32Storage(bytes32 _key) external view returns (bytes32);
function boolStorage(bytes32 _key) external view returns (bool);
function intStorage(bytes32 _key) external view returns (bool);
}
// @title A contract that gets variables from the _database
// @notice The API contract can only view the database. It has no write privileges
contract API {
using SafeMath for uint256;
DBView private database;
uint constant scalingFactor = 10e32;
constructor(address _database)
public {
database = DBView(_database);
}
function getContract(string _name)
public
view
returns (address) {
return database.addressStorage(keccak256(abi.encodePacked('contract', _name)));
}
function getAddr(bytes32 _key)
public
view
returns (address) {
return database.addressStorage(_key);
}
function getUint(bytes32 _key)
public
view
returns (uint) {
return database.uintStorage(_key);
}
function hashSB(string _a, bytes32 _b)
public
pure
returns (bytes32) {
return keccak256(abi.encodePacked(_a, _b));
}
function getMethodID(string _functionString)
public
pure
returns (bytes4) {
return bytes4(keccak256(abi.encodePacked(_functionString)));
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Crowdsale and Assets
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getAssetFundingToken(address _assetAddress)
public
view
returns(address) {
address fundingTokenAddress = TokenView(_assetAddress).getERC20();
return fundingTokenAddress;
}
// IF we decide not to store assetIncome
// function getAssetIncome(address _assetAddress)
// public
// view
// returns (uint) {
// TokenView asset = TokenView(_assetAddress);
// uint valuePerToken = asset.valuePerToken();
// return (valuePerToken * (asset.totalSupply())) / asset.scalingFactor();
// }
function getAssetROI(address _assetAddress)
public
view
returns (uint) {
TokenView assetToken = TokenView(_assetAddress);
return (assetToken.assetIncome() * 100) / assetToken.totalSupply();
}
function getCrowdsaleGoal(address _assetAddress)
public
view
returns(uint) {
uint fundingGoal = database.uintStorage(keccak256(abi.encodePacked("crowdsale.goal", _assetAddress)));
return fundingGoal;
}
function getCrowdsaleDeadline(address _assetAddress)
public
view
returns(uint) {
return database.uintStorage(keccak256(abi.encodePacked("crowdsale.deadline", _assetAddress)));
}
function crowdsaleFinalized(address _assetAddress)
public
view
returns(bool) {
return database.boolStorage(keccak256(abi.encodePacked("crowdsale.finalized", _assetAddress)));
}
function crowdsalePaid(address _assetAddress)
public
view
returns(bool) {
return database.boolStorage(keccak256(abi.encodePacked("crowdsale.paid", _assetAddress)));
}
function crowdsaleFailed(address _assetAddress)
public
view
returns(bool) {
return (now > getCrowdsaleDeadline(_assetAddress) && !crowdsaleFinalized(_assetAddress));
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Asset Manager and Operator
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getAssetManager(address _assetAddress)
public
view
returns(address) {
address managerAddress = database.addressStorage(keccak256(abi.encodePacked("asset.manager", _assetAddress)));
return managerAddress;
}
function getAssetManagerFee(address _assetAddress)
public
view
returns(uint) {
uint managerFee = database.uintStorage(keccak256(abi.encodePacked("asset.managerTokens", _assetAddress)));
return managerFee;
}
function getAssetPlatformFee(address _assetAddress)
public
view
returns(uint) {
uint platformFee = database.uintStorage(keccak256(abi.encodePacked("asset.platformTokens", _assetAddress)));
return platformFee;
}
function getAssetManagerEscrowID(address _assetAddress, address _manager)
public
pure
returns(bytes32) {
bytes32 managerEscrowID = keccak256(abi.encodePacked(_assetAddress, _manager));
return managerEscrowID;
}
function getAssetManagerEscrow(bytes32 _managerEscrowID)
public
view
returns (uint) {
return database.uintStorage(keccak256(abi.encodePacked("asset.escrow", _managerEscrowID)));
}
function getAssetManagerEscrowRemaining(bytes32 _managerEscrowID)
public
view
returns(uint) {
uint redeemed = getAssetManagerEscrowRedeemed(_managerEscrowID);
uint escrow = getAssetManagerEscrow(_managerEscrowID);
return escrow.sub(redeemed);
}
function getAssetManagerEscrowRedeemed(bytes32 _managerEscrowID)
public
view
returns(uint) {
uint escrowRedeemed = database.uintStorage(keccak256(abi.encodePacked("asset.escrowRedeemed", _managerEscrowID)));
return escrowRedeemed;
}
function generateOperatorID(string _operatorURI)
public
pure
returns(bytes32) {
bytes32 operatorID = keccak256(abi.encodePacked("operator.uri", _operatorURI));
return operatorID;
}
function getOperatorID(address _operatorAddress)
public
view
returns(bytes32) {
bytes32 operatorID = database.bytes32Storage(keccak256(abi.encodePacked("operator", _operatorAddress)));
return operatorID;
}
function getOperatorAddress(bytes32 _operatorID)
public
view
returns(address) {
address operatorAddress = database.addressStorage(keccak256(abi.encodePacked("operator", _operatorID)));
return operatorAddress;
}
function getOperatorIPFS(bytes32 _operatorID)
public
view
returns(string) {
return database.stringStorage(keccak256(abi.encodePacked("operator.ipfs", _operatorID)));
}
function getManagerAssetCount(address _manager)
public
view
returns(uint) {
return database.uintStorage(keccak256(abi.encodePacked("manager.assets", _manager)));
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Platform and Contract State
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Platform functions
function getPlatformToken()
public
view
returns(address) {
address tokenAddress = database.addressStorage(keccak256(abi.encodePacked("platform.token")));
return tokenAddress;
}
function getPlatformTokenFactory()
public
view
returns(address) {
address factoryAddress = database.addressStorage(keccak256(abi.encodePacked("platform.tokenFactory")));
return factoryAddress;
}
function getPlatformFee()
public
view
returns(uint) {
uint fee = database.uintStorage(keccak256(abi.encodePacked("platform.fee")));
return fee;
}
function getPlatformListingFeeToken()
public
view
returns(address) {
address tokenAddress = database.addressStorage(keccak256(abi.encodePacked("platform.listingFeeToken")));
return tokenAddress;
}
function getPlatformListingFee()
public
view
returns(uint) {
uint fee = database.uintStorage(keccak256(abi.encodePacked("platform.listingFee")));
return fee;
}
function getPlatformPercentage()
public
view
returns(uint) {
uint percentage = database.uintStorage(keccak256(abi.encodePacked("platform.percentage")));
return percentage;
}
function getPlatformAssetsWallet()
public
view
returns(address) {
address walletAddress = database.addressStorage(keccak256(abi.encodePacked("platform.wallet.assets")));
return walletAddress;
}
function getPlatformFundsWallet()
public
view
returns(address) {
address walletAddress = database.addressStorage(keccak256(abi.encodePacked("platform.wallet.funds")));
return walletAddress;
}
function getContractAddress(string _contractName)
public
view
returns(address) {
address contractAddress = database.addressStorage(keccak256(abi.encodePacked("contract", _contractName)));
return contractAddress;
}
function contractPaused(address _contract)
public
view
returns(bool) {
bool status = database.boolStorage(keccak256(abi.encodePacked("paused", _contract)));
return status;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Ownership
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function contractOwner(address _account)
public
view
returns(bool) {
bool status = database.boolStorage(keccak256(abi.encodePacked("owner", _account)));
return status;
}
}