@evvm/testnet-contracts 1.0.0

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.
Files changed (34) hide show
  1. package/LICENSE +166 -0
  2. package/README.md +216 -0
  3. package/package.json +51 -0
  4. package/src/contracts/evvm/Evvm.sol +1327 -0
  5. package/src/contracts/evvm/EvvmLegacy.sol +1553 -0
  6. package/src/contracts/evvm/lib/ErrorsLib.sol +17 -0
  7. package/src/contracts/evvm/lib/EvvmStorage.sol +60 -0
  8. package/src/contracts/evvm/lib/EvvmStructs.sol +64 -0
  9. package/src/contracts/evvm/lib/SignatureUtils.sol +124 -0
  10. package/src/contracts/nameService/NameService.sol +1751 -0
  11. package/src/contracts/nameService/lib/ErrorsLib.sol +27 -0
  12. package/src/contracts/nameService/lib/SignatureUtils.sol +239 -0
  13. package/src/contracts/staking/Estimator.sol +358 -0
  14. package/src/contracts/staking/Staking.sol +1148 -0
  15. package/src/contracts/staking/lib/ErrorsLib.sol +19 -0
  16. package/src/contracts/staking/lib/SignatureUtils.sol +68 -0
  17. package/src/contracts/treasury/Treasury.sol +104 -0
  18. package/src/contracts/treasury/lib/ErrorsLib.sol +11 -0
  19. package/src/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +551 -0
  20. package/src/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +512 -0
  21. package/src/contracts/treasuryTwoChains/lib/ErrorsLib.sol +15 -0
  22. package/src/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +41 -0
  23. package/src/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +52 -0
  24. package/src/contracts/treasuryTwoChains/lib/SignatureUtils.sol +47 -0
  25. package/src/interfaces/IEstimator.sol +102 -0
  26. package/src/interfaces/IEvvm.sol +195 -0
  27. package/src/interfaces/INameService.sol +283 -0
  28. package/src/interfaces/IStaking.sol +202 -0
  29. package/src/interfaces/ITreasury.sol +17 -0
  30. package/src/interfaces/ITreasuryExternalChainStation.sol +262 -0
  31. package/src/interfaces/ITreasuryHostChainStation.sol +251 -0
  32. package/src/lib/AdvancedStrings.sol +77 -0
  33. package/src/lib/Erc191TestBuilder.sol +402 -0
  34. package/src/lib/SignatureRecover.sol +56 -0
@@ -0,0 +1,402 @@
1
+ // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
+ // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
+
4
+ pragma solidity ^0.8.0;
5
+ /**
6
+ * @title Erc191TestBuilder
7
+ * @author jistro.eth
8
+ * @notice this library is used to build ERC191 messages for foundry test scripts
9
+ * more info in
10
+ * https://book.getfoundry.sh/cheatcodes/create-wallet
11
+ * https://book.getfoundry.sh/cheatcodes/sign
12
+ */
13
+
14
+ import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
15
+ import {AdvancedStrings} from "./AdvancedStrings.sol";
16
+
17
+ library Erc191TestBuilder {
18
+ //-----------------------------------------------------------------------------------
19
+ // EVVM
20
+ //-----------------------------------------------------------------------------------
21
+ function buildMessageSignedForPay(
22
+ uint256 evvmID,
23
+ address _receiverAddress,
24
+ string memory _receiverIdentity,
25
+ address _token,
26
+ uint256 _amount,
27
+ uint256 _priorityFee,
28
+ uint256 _nonce,
29
+ bool _priority_boolean,
30
+ address _executor
31
+ ) internal pure returns (bytes32 messageHash) {
32
+ string memory messageToSign = string.concat(
33
+ Strings.toString(evvmID),
34
+ ",",
35
+ "pay",
36
+ ",",
37
+ _receiverAddress == address(0)
38
+ ? _receiverIdentity
39
+ : AdvancedStrings.addressToString(_receiverAddress),
40
+ ",",
41
+ AdvancedStrings.addressToString(_token),
42
+ ",",
43
+ Strings.toString(_amount),
44
+ ",",
45
+ Strings.toString(_priorityFee),
46
+ ",",
47
+ Strings.toString(_nonce),
48
+ ",",
49
+ _priority_boolean ? "true" : "false",
50
+ ",",
51
+ AdvancedStrings.addressToString(_executor)
52
+ );
53
+ messageHash = buildHashForSign(messageToSign);
54
+ }
55
+
56
+ function buildMessageSignedForDispersePay(
57
+ uint256 evvmID,
58
+ bytes32 hashList,
59
+ address _token,
60
+ uint256 _amount,
61
+ uint256 _priorityFee,
62
+ uint256 _nonce,
63
+ bool _priority_boolean,
64
+ address _executor
65
+ ) public pure returns (bytes32 messageHash) {
66
+ return
67
+ buildHashForSign(
68
+ string.concat(
69
+ Strings.toString(evvmID),
70
+ ",",
71
+ "dispersePay",
72
+ ",",
73
+ AdvancedStrings.bytes32ToString(hashList),
74
+ ",",
75
+ AdvancedStrings.addressToString(_token),
76
+ ",",
77
+ Strings.toString(_amount),
78
+ ",",
79
+ Strings.toString(_priorityFee),
80
+ ",",
81
+ Strings.toString(_nonce),
82
+ ",",
83
+ _priority_boolean ? "true" : "false",
84
+ ",",
85
+ AdvancedStrings.addressToString(_executor)
86
+ )
87
+ );
88
+ }
89
+
90
+ //-----------------------------------------------------------------------------------
91
+ // MATE NAME SERVICE
92
+ //-----------------------------------------------------------------------------------
93
+
94
+ function buildMessageSignedForPreRegistrationUsername(
95
+ uint256 evvmID,
96
+ bytes32 _hashUsername,
97
+ uint256 _nameServiceNonce
98
+ ) internal pure returns (bytes32 messageHash) {
99
+ return
100
+ buildHashForSign(
101
+ string.concat(
102
+ Strings.toString(evvmID),
103
+ ",",
104
+ "preRegistrationUsername",
105
+ ",",
106
+ AdvancedStrings.bytes32ToString(_hashUsername),
107
+ ",",
108
+ Strings.toString(_nameServiceNonce)
109
+ )
110
+ );
111
+ }
112
+
113
+ function buildMessageSignedForRegistrationUsername(
114
+ uint256 evvmID,
115
+ string memory _username,
116
+ uint256 _clowNumber,
117
+ uint256 _nameServiceNonce
118
+ ) internal pure returns (bytes32 messageHash) {
119
+ return
120
+ buildHashForSign(
121
+ string.concat(
122
+ Strings.toString(evvmID),
123
+ ",",
124
+ "registrationUsername",
125
+ ",",
126
+ _username,
127
+ ",",
128
+ Strings.toString(_clowNumber),
129
+ ",",
130
+ Strings.toString(_nameServiceNonce)
131
+ )
132
+ );
133
+ }
134
+
135
+ function buildMessageSignedForMakeOffer(
136
+ uint256 evvmID,
137
+ string memory _username,
138
+ uint256 _dateExpire,
139
+ uint256 _amount,
140
+ uint256 _nameServiceNonce
141
+ ) internal pure returns (bytes32 messageHash) {
142
+ return
143
+ buildHashForSign(
144
+ string.concat(
145
+ Strings.toString(evvmID),
146
+ ",",
147
+ "makeOffer",
148
+ ",",
149
+ _username,
150
+ ",",
151
+ Strings.toString(_dateExpire),
152
+ ",",
153
+ Strings.toString(_amount),
154
+ ",",
155
+ Strings.toString(_nameServiceNonce)
156
+ )
157
+ );
158
+ }
159
+
160
+ function buildMessageSignedForWithdrawOffer(
161
+ uint256 evvmID,
162
+ string memory _username,
163
+ uint256 _offerId,
164
+ uint256 _nameServiceNonce
165
+ ) internal pure returns (bytes32 messageHash) {
166
+ return
167
+ buildHashForSign(
168
+ string.concat(
169
+ Strings.toString(evvmID),
170
+ ",",
171
+ "withdrawOffer",
172
+ ",",
173
+ _username,
174
+ ",",
175
+ Strings.toString(_offerId),
176
+ ",",
177
+ Strings.toString(_nameServiceNonce)
178
+ )
179
+ );
180
+ }
181
+
182
+ function buildMessageSignedForAcceptOffer(
183
+ uint256 evvmID,
184
+ string memory _username,
185
+ uint256 _offerId,
186
+ uint256 _nameServiceNonce
187
+ ) internal pure returns (bytes32 messageHash) {
188
+ return
189
+ buildHashForSign(
190
+ string.concat(
191
+ Strings.toString(evvmID),
192
+ ",",
193
+ "acceptOffer",
194
+ ",",
195
+ _username,
196
+ ",",
197
+ Strings.toString(_offerId),
198
+ ",",
199
+ Strings.toString(_nameServiceNonce)
200
+ )
201
+ );
202
+ }
203
+
204
+ function buildMessageSignedForRenewUsername(
205
+ uint256 evvmID,
206
+ string memory _username,
207
+ uint256 _nameServiceNonce
208
+ ) internal pure returns (bytes32 messageHash) {
209
+ return
210
+ buildHashForSign(
211
+ string.concat(
212
+ Strings.toString(evvmID),
213
+ ",",
214
+ "renewUsername",
215
+ ",",
216
+ _username,
217
+ ",",
218
+ Strings.toString(_nameServiceNonce)
219
+ )
220
+ );
221
+ }
222
+
223
+ function buildMessageSignedForAddCustomMetadata(
224
+ uint256 evvmID,
225
+ string memory _username,
226
+ string memory _value,
227
+ uint256 _nameServiceNonce
228
+ ) internal pure returns (bytes32 messageHash) {
229
+ return
230
+ buildHashForSign(
231
+ string.concat(
232
+ Strings.toString(evvmID),
233
+ ",",
234
+ "addCustomMetadata",
235
+ ",",
236
+ _username,
237
+ ",",
238
+ _value,
239
+ ",",
240
+ Strings.toString(_nameServiceNonce)
241
+ )
242
+ );
243
+ }
244
+
245
+ function buildMessageSignedForRemoveCustomMetadata(
246
+ uint256 evvmID,
247
+ string memory _username,
248
+ uint256 _key,
249
+ uint256 _nonce
250
+ ) internal pure returns (bytes32 messageHash) {
251
+ return
252
+ buildHashForSign(
253
+ string.concat(
254
+ Strings.toString(evvmID),
255
+ ",",
256
+ "removeCustomMetadata",
257
+ ",",
258
+ _username,
259
+ ",",
260
+ Strings.toString(_key),
261
+ ",",
262
+ Strings.toString(_nonce)
263
+ )
264
+ );
265
+ }
266
+
267
+ function buildMessageSignedForFlushCustomMetadata(
268
+ uint256 evvmID,
269
+ string memory _username,
270
+ uint256 _nonce
271
+ ) internal pure returns (bytes32 messageHash) {
272
+ return
273
+ buildHashForSign(
274
+ string.concat(
275
+ Strings.toString(evvmID),
276
+ ",",
277
+ "flushCustomMetadata",
278
+ ",",
279
+ _username,
280
+ ",",
281
+ Strings.toString(_nonce)
282
+ )
283
+ );
284
+ }
285
+
286
+ function buildMessageSignedForFlushUsername(
287
+ uint256 evvmID,
288
+ string memory _username,
289
+ uint256 _nonce
290
+ ) internal pure returns (bytes32 messageHash) {
291
+ return
292
+ buildHashForSign(
293
+ string.concat(
294
+ Strings.toString(evvmID),
295
+ ",",
296
+ "flushUsername",
297
+ ",",
298
+ _username,
299
+ ",",
300
+ Strings.toString(_nonce)
301
+ )
302
+ );
303
+ }
304
+
305
+ //-----------------------------------------------------------------------------------
306
+ // staking functions
307
+ //-----------------------------------------------------------------------------------
308
+
309
+ function buildMessageSignedForPublicServiceStake(
310
+ uint256 evvmID,
311
+ address _serviceAddress,
312
+ bool _isStaking,
313
+ uint256 _amountOfStaking,
314
+ uint256 _nonce
315
+ ) internal pure returns (bytes32 messageHash) {
316
+ return
317
+ buildHashForSign(
318
+ string.concat(
319
+ Strings.toString(evvmID),
320
+ ",",
321
+ "publicServiceStaking",
322
+ ",",
323
+ AdvancedStrings.addressToString(_serviceAddress),
324
+ ",",
325
+ _isStaking ? "true" : "false",
326
+ ",",
327
+ Strings.toString(_amountOfStaking),
328
+ ",",
329
+ Strings.toString(_nonce)
330
+ )
331
+ );
332
+ }
333
+
334
+ function buildMessageSignedForPublicStaking(
335
+ uint256 evvmID,
336
+ bool _isStaking,
337
+ uint256 _amountOfStaking,
338
+ uint256 _nonce
339
+ ) internal pure returns (bytes32 messageHash) {
340
+ return
341
+ buildHashForSign(
342
+ string.concat(
343
+ Strings.toString(evvmID),
344
+ ",",
345
+ "publicStaking",
346
+ ",",
347
+ _isStaking ? "true" : "false",
348
+ ",",
349
+ Strings.toString(_amountOfStaking),
350
+ ",",
351
+ Strings.toString(_nonce)
352
+ )
353
+ );
354
+ }
355
+
356
+ function buildMessageSignedForPresaleStaking(
357
+ uint256 evvmID,
358
+ bool _isStaking,
359
+ uint256 _amountOfStaking,
360
+ uint256 _nonce
361
+ ) internal pure returns (bytes32 messageHash) {
362
+ return
363
+ buildHashForSign(
364
+ string.concat(
365
+ Strings.toString(evvmID),
366
+ ",",
367
+ "presaleStaking",
368
+ ",",
369
+ _isStaking ? "true" : "false",
370
+ ",",
371
+ Strings.toString(_amountOfStaking),
372
+ ",",
373
+ Strings.toString(_nonce)
374
+ )
375
+ );
376
+ }
377
+
378
+ //-----------------------------------------------------------------------------------
379
+ // General functions
380
+ //-----------------------------------------------------------------------------------
381
+
382
+ function buildHashForSign(
383
+ string memory messageToSign
384
+ ) internal pure returns (bytes32) {
385
+ return
386
+ keccak256(
387
+ abi.encodePacked(
388
+ "\x19Ethereum Signed Message:\n",
389
+ Strings.toString(bytes(messageToSign).length),
390
+ messageToSign
391
+ )
392
+ );
393
+ }
394
+
395
+ function buildERC191Signature(
396
+ uint8 v,
397
+ bytes32 r,
398
+ bytes32 s
399
+ ) internal pure returns (bytes memory) {
400
+ return abi.encodePacked(r, s, bytes1(v));
401
+ }
402
+ }
@@ -0,0 +1,56 @@
1
+ // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
+ // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
+
4
+ pragma solidity ^0.8.0;
5
+
6
+ import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
7
+
8
+ library SignatureRecover {
9
+ function signatureVerification(
10
+ string memory evvmID,
11
+ string memory functionName,
12
+ string memory inputs,
13
+ bytes memory signature,
14
+ address expectedSigner
15
+ ) internal pure returns (bool) {
16
+ return
17
+ recoverSigner(
18
+ string.concat(evvmID, ",", functionName, ",", inputs),
19
+ signature
20
+ ) == expectedSigner;
21
+ }
22
+
23
+
24
+ function recoverSigner(
25
+ string memory message,
26
+ bytes memory signature
27
+ ) internal pure returns (address) {
28
+ bytes32 messageHash = keccak256(
29
+ abi.encodePacked(
30
+ "\x19Ethereum Signed Message:\n",
31
+ Strings.toString(bytes(message).length),
32
+ message
33
+ )
34
+ );
35
+ (bytes32 r, bytes32 s, uint8 v) = splitSignature(signature);
36
+ return ecrecover(messageHash, v, r, s);
37
+ }
38
+
39
+ function splitSignature(
40
+ bytes memory signature
41
+ ) internal pure returns (bytes32 r, bytes32 s, uint8 v) {
42
+ require(signature.length == 65, "Invalid signature length");
43
+
44
+ assembly {
45
+ r := mload(add(signature, 32))
46
+ s := mload(add(signature, 64))
47
+ v := byte(0, mload(add(signature, 96)))
48
+ }
49
+
50
+ // Ensure signature is valid
51
+ if (v < 27) {
52
+ v += 27;
53
+ }
54
+ require(v == 27 || v == 28, "Invalid signature value");
55
+ }
56
+ }