@evvm/testnet-contracts 2.1.3 → 2.2.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.
Files changed (52) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +355 -55
  3. package/contracts/evvm/Evvm.sol +39 -38
  4. package/contracts/evvm/lib/ErrorsLib.sol +2 -1
  5. package/contracts/evvm/lib/EvvmStorage.sol +2 -0
  6. package/contracts/evvm/lib/EvvmStructs.sol +27 -1
  7. package/contracts/evvm/lib/SignatureUtils.sol +14 -17
  8. package/contracts/nameService/NameService.sol +124 -366
  9. package/contracts/nameService/lib/ErrorsLib.sol +2 -8
  10. package/contracts/nameService/lib/IdentityValidation.sol +182 -0
  11. package/contracts/nameService/lib/NameServiceStructs.sol +69 -0
  12. package/contracts/nameService/lib/SignatureUtils.sol +47 -41
  13. package/contracts/p2pSwap/P2PSwap.sol +54 -535
  14. package/contracts/p2pSwap/lib/P2PSwapStructs.sol +59 -0
  15. package/contracts/p2pSwap/lib/SignatureUtils.sol +16 -18
  16. package/contracts/staking/Estimator.sol +7 -6
  17. package/contracts/staking/Staking.sol +70 -159
  18. package/contracts/staking/lib/ErrorsLib.sol +0 -1
  19. package/contracts/staking/lib/SignatureUtils.sol +7 -36
  20. package/contracts/staking/lib/StakingStructs.sol +94 -0
  21. package/contracts/treasury/Treasury.sol +18 -20
  22. package/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +88 -35
  23. package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +81 -47
  24. package/contracts/treasuryTwoChains/lib/ErrorsLib.sol +2 -0
  25. package/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +3 -14
  26. package/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +3 -7
  27. package/contracts/treasuryTwoChains/lib/SignatureUtils.sol +12 -14
  28. package/interfaces/IEstimator.sol +7 -50
  29. package/interfaces/IEvvm.sol +17 -91
  30. package/interfaces/INameService.sol +37 -88
  31. package/interfaces/IP2PSwap.sol +19 -15
  32. package/interfaces/IStaking.sol +20 -50
  33. package/interfaces/ITreasury.sol +1 -4
  34. package/interfaces/ITreasuryExternalChainStation.sol +11 -15
  35. package/interfaces/ITreasuryHostChainStation.sol +7 -10
  36. package/library/Erc191TestBuilder.sol +56 -57
  37. package/library/EvvmService.sol +40 -0
  38. package/library/primitives/IERC20.sol +79 -0
  39. package/library/primitives/Math.sol +415 -0
  40. package/library/primitives/SignatureRecover.sol +42 -0
  41. package/library/utils/AdvancedStrings.sol +89 -0
  42. package/library/utils/GovernanceUtils.sol +81 -0
  43. package/library/utils/SignatureUtil.sol +29 -0
  44. package/library/utils/nonces/AsyncNonce.sol +32 -0
  45. package/library/utils/nonces/SyncNonce.sol +27 -0
  46. package/library/utils/service/EvvmPayments.sol +77 -0
  47. package/library/utils/service/StakingServiceUtils.sol +32 -0
  48. package/package.json +11 -13
  49. package/contracts/evvm/EvvmLegacy.sol +0 -1553
  50. package/library/AdvancedStrings.sol +0 -77
  51. package/library/SignatureRecover.sol +0 -140
  52. package/library/StakingServiceHooks.sol +0 -116
@@ -8,13 +8,7 @@ library ErrorsLib {
8
8
  error UserIsNotOwnerOfIdentity();
9
9
  error NonceAlreadyUsed();
10
10
  error InvalidSignatureOnNameService();
11
- /**
12
- * @dev Error thrown when a username is not valid.
13
- * 0x01 - Username is too short.
14
- * 0x02 - Username does not start with a letter.
15
- * 0x03 - Username contains invalid characters.
16
- */
17
- error InvalidUsername(bytes1);
11
+ error InvalidUsername();
18
12
  error UsernameAlreadyRegistered();
19
13
  error PreRegistrationNotValid();
20
14
  error MakeOfferVerificationFailed();
@@ -24,4 +18,4 @@ library ErrorsLib {
24
18
  error EmptyCustomMetadata();
25
19
  error InvalidKey();
26
20
  error FlushUsernameVerificationFailed();
27
- }
21
+ }
@@ -0,0 +1,182 @@
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
+ library IdentityValidation{
7
+ /**
8
+ * @notice Validates username format according to system rules
9
+ * @dev Username must be at least 4 characters, start with a letter, and contain only letters/digits
10
+ * @param username The username string to validate
11
+ */
12
+ function isValidUsername(string memory username) internal pure returns (bool) {
13
+ bytes memory usernameBytes = bytes(username);
14
+
15
+ // Check if username length is at least 4 characters
16
+ if (usernameBytes.length < 4) return false;
17
+
18
+ // Check if username begins with a letter
19
+ if (!_isLetter(usernameBytes[0]))
20
+ return false;
21
+
22
+
23
+ // Iterate through each character in the username
24
+ for (uint256 i = 0; i < usernameBytes.length; i++) {
25
+ // Check if character is not a digit or letter
26
+ if (!_isDigit(usernameBytes[i]) && !_isLetter(usernameBytes[i])) {
27
+ return false;
28
+
29
+ }
30
+ }
31
+ return true;
32
+ }
33
+
34
+ /**
35
+ * @notice Validates phone number format
36
+ * @dev Phone number must be 6-19 digits only
37
+ * @param _phoneNumber The phone number string to validate
38
+ * @return True if valid phone number format
39
+ */
40
+ function isValidPhoneNumberNumber(
41
+ string memory _phoneNumber
42
+ ) internal pure returns (bool) {
43
+ bytes memory _telephoneNumberBytes = bytes(_phoneNumber);
44
+ if (
45
+ _telephoneNumberBytes.length < 20 &&
46
+ _telephoneNumberBytes.length > 5
47
+ ) {
48
+ return false;
49
+ }
50
+ for (uint256 i = 0; i < _telephoneNumberBytes.length; i++) {
51
+ if (!_isDigit(_telephoneNumberBytes[i])) {
52
+ return false;
53
+ }
54
+ }
55
+ return true;
56
+ }
57
+
58
+ /**
59
+ * @notice Validates email address format
60
+ * @dev Checks for proper email structure: prefix(3+ chars) + @ + domain(3+ chars) + . + TLD(2+ chars)
61
+ * @param _email The email address string to validate
62
+ * @return True if valid email format
63
+ */
64
+ function isValidEmail(string memory _email) internal pure returns (bool) {
65
+ bytes memory _emailBytes = bytes(_email);
66
+ uint256 lengthCount = 0;
67
+ bytes1 flagVerify = 0x00;
68
+ for (uint point = 0; point < _emailBytes.length; point++) {
69
+ //step 1 0x00 prefix
70
+ if (flagVerify == 0x00) {
71
+ if (_isOnlyEmailPrefixCharacters(_emailBytes[point])) {
72
+ lengthCount++;
73
+ } else {
74
+ if (_isAAt(_emailBytes[point])) {
75
+ flagVerify = 0x01;
76
+ } else {
77
+ return false;
78
+ }
79
+ }
80
+ }
81
+
82
+ //step 2 0x01 count the prefix length
83
+ if (flagVerify == 0x01) {
84
+ if (lengthCount < 3) {
85
+ return false;
86
+ } else {
87
+ flagVerify = 0x02;
88
+ lengthCount = 0;
89
+ point++;
90
+ }
91
+ }
92
+
93
+ //step 3 0x02 domain name
94
+ if (flagVerify == 0x02) {
95
+ if (_isLetter(_emailBytes[point])) {
96
+ lengthCount++;
97
+ } else {
98
+ if (_isAPoint(_emailBytes[point])) {
99
+ flagVerify = 0x03;
100
+ } else {
101
+ return false;
102
+ }
103
+ }
104
+ }
105
+
106
+ //step 4 0x03 count the domain name length
107
+ if (flagVerify == 0x03) {
108
+ if (lengthCount < 3) {
109
+ return false;
110
+ } else {
111
+ flagVerify = 0x04;
112
+ lengthCount = 0;
113
+ point++;
114
+ }
115
+ }
116
+
117
+ //step 5 0x04 top level domain
118
+ if (flagVerify == 0x04) {
119
+ if (_isLetter(_emailBytes[point])) {
120
+ lengthCount++;
121
+ } else {
122
+ if (_isAPoint(_emailBytes[point])) {
123
+ if (lengthCount < 2) {
124
+ return false;
125
+ } else {
126
+ lengthCount = 0;
127
+ }
128
+ } else {
129
+ return false;
130
+ }
131
+ }
132
+ }
133
+ }
134
+
135
+ if (flagVerify != 0x04) {
136
+ return false;
137
+ }
138
+
139
+ return true;
140
+ }
141
+
142
+ /// @dev Checks if a byte represents a digit (0-9)
143
+ function _isDigit(bytes1 character) private pure returns (bool) {
144
+ return (character >= 0x30 && character <= 0x39); // ASCII range for digits 0-9
145
+ }
146
+
147
+ /// @dev Checks if a byte represents a letter (A-Z or a-z)
148
+ function _isLetter(bytes1 character) private pure returns (bool) {
149
+ return ((character >= 0x41 && character <= 0x5A) ||
150
+ (character >= 0x61 && character <= 0x7A)); // ASCII ranges for letters A-Z and a-z
151
+ }
152
+
153
+ /// @dev Checks if a byte represents any symbol character
154
+ function _isAnySimbol(bytes1 character) private pure returns (bool) {
155
+ return ((character >= 0x21 && character <= 0x2F) || /// @dev includes characters from "!" to "/"
156
+ (character >= 0x3A && character <= 0x40) || /// @dev includes characters from ":" to "@"
157
+ (character >= 0x5B && character <= 0x60) || /// @dev includes characters from "[" to "`"
158
+ (character >= 0x7B && character <= 0x7E)); /// @dev includes characters from "{" to "~"
159
+ }
160
+
161
+ /// @dev Checks if a byte is valid for email prefix (letters, digits, and specific symbols)
162
+ function _isOnlyEmailPrefixCharacters(
163
+ bytes1 character
164
+ ) private pure returns (bool) {
165
+ return (_isLetter(character) ||
166
+ _isDigit(character) ||
167
+ (character >= 0x21 && character <= 0x2F) || /// @dev includes characters from "!" to "/"
168
+ (character >= 0x3A && character <= 0x3F) || /// @dev includes characters from ":" to "?"
169
+ (character >= 0x5B && character <= 0x60) || /// @dev includes characters from "[" to "`"
170
+ (character >= 0x7B && character <= 0x7E)); /// @dev includes characters from "{" to "~"
171
+ }
172
+
173
+ /// @dev Checks if a byte represents a period/dot character (.)
174
+ function _isAPoint(bytes1 character) private pure returns (bool) {
175
+ return character == 0x2E;
176
+ }
177
+
178
+ /// @dev Checks if a byte represents an at symbol (@)
179
+ function _isAAt(bytes1 character) private pure returns (bool) {
180
+ return character == 0x40;
181
+ }
182
+ }
@@ -0,0 +1,69 @@
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
+ abstract contract NameServiceStructs {
7
+ /**
8
+ * @dev Struct for managing address change proposals with time delay
9
+ * @param current Currently active address
10
+ * @param proposal Proposed new address waiting for approval
11
+ * @param timeToAccept Timestamp when the proposal can be accepted
12
+ */
13
+ struct AddressTypeProposal {
14
+ address current;
15
+ address proposal;
16
+ uint256 timeToAccept;
17
+ }
18
+
19
+ /**
20
+ * @dev Struct for managing uint256 value proposals with time delay
21
+ * @param current Currently active value
22
+ * @param proposal Proposed new value waiting for approval
23
+ * @param timeToAccept Timestamp when the proposal can be accepted
24
+ */
25
+ struct UintTypeProposal {
26
+ uint256 current;
27
+ uint256 proposal;
28
+ uint256 timeToAccept;
29
+ }
30
+
31
+ /**
32
+ * @dev Struct for managing boolean flag changes with time delay
33
+ * @param flag Current boolean state
34
+ * @param timeToAcceptChange Timestamp when the flag change can be executed
35
+ */
36
+ struct BoolTypeProposal {
37
+ bool flag;
38
+ uint256 timeToAcceptChange;
39
+ }
40
+
41
+ /**
42
+ * @dev Core metadata for each registered identity/username
43
+ * @param owner Address that owns this identity
44
+ * @param expireDate Timestamp when the registration expires
45
+ * @param customMetadataMaxSlots Number of custom metadata entries stored
46
+ * @param offerMaxSlots Maximum number of offers that have been made
47
+ * @param flagNotAUsername Flag indicating if this is a pre-registration (0x01) or actual username (0x00)
48
+ */
49
+ struct IdentityBaseMetadata {
50
+ address owner;
51
+ uint256 expireDate;
52
+ uint256 customMetadataMaxSlots;
53
+ uint256 offerMaxSlots;
54
+ bytes1 flagNotAUsername;
55
+ }
56
+
57
+
58
+ /**
59
+ * @dev Metadata for marketplace offers on usernames
60
+ * @param offerer Address making the offer
61
+ * @param expireDate Timestamp when the offer expires
62
+ * @param amount Amount offered in Principal Tokens (after 0.5% marketplace fee deduction)
63
+ */
64
+ struct OfferMetadata {
65
+ address offerer;
66
+ uint256 expireDate;
67
+ uint256 amount;
68
+ }
69
+ }
@@ -1,12 +1,10 @@
1
1
  // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
2
  // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
-
4
- import {SignatureRecover} from "@evvm/testnet-contracts/library/SignatureRecover.sol";
5
- import {AdvancedStrings} from "@evvm/testnet-contracts/library/AdvancedStrings.sol";
6
- import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
7
-
8
3
  pragma solidity ^0.8.0;
9
4
 
5
+ import {SignatureUtil} from "@evvm/testnet-contracts/library/utils/SignatureUtil.sol";
6
+ import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
7
+
10
8
  library SignatureUtils {
11
9
  /**
12
10
  * @dev using EIP-191 (https://eips.ethereum.org/EIPS/eip-191) can be used to sign and
@@ -22,13 +20,13 @@ library SignatureUtils {
22
20
  bytes memory signature
23
21
  ) internal pure returns (bool) {
24
22
  return
25
- SignatureRecover.signatureVerification(
26
- Strings.toString(evvmID),
23
+ SignatureUtil.verifySignature(
24
+ evvmID,
27
25
  "preRegistrationUsername",
28
26
  string.concat(
29
27
  AdvancedStrings.bytes32ToString(_hashUsername),
30
28
  ",",
31
- Strings.toString(_nameServiceNonce)
29
+ AdvancedStrings.uintToString(_nameServiceNonce)
32
30
  ),
33
31
  signature,
34
32
  signer
@@ -44,15 +42,15 @@ library SignatureUtils {
44
42
  bytes memory signature
45
43
  ) internal pure returns (bool) {
46
44
  return
47
- SignatureRecover.signatureVerification(
48
- Strings.toString(evvmID),
45
+ SignatureUtil.verifySignature(
46
+ evvmID,
49
47
  "registrationUsername",
50
48
  string.concat(
51
49
  _username,
52
50
  ",",
53
- Strings.toString(_clowNumber),
51
+ AdvancedStrings.uintToString(_clowNumber),
54
52
  ",",
55
- Strings.toString(_nameServiceNonce)
53
+ AdvancedStrings.uintToString(_nameServiceNonce)
56
54
  ),
57
55
  signature,
58
56
  signer
@@ -69,17 +67,17 @@ library SignatureUtils {
69
67
  bytes memory signature
70
68
  ) internal pure returns (bool) {
71
69
  return
72
- SignatureRecover.signatureVerification(
73
- Strings.toString(evvmID),
70
+ SignatureUtil.verifySignature(
71
+ evvmID,
74
72
  "makeOffer",
75
73
  string.concat(
76
74
  _username,
77
75
  ",",
78
- Strings.toString(_dateExpire),
76
+ AdvancedStrings.uintToString(_dateExpire),
79
77
  ",",
80
- Strings.toString(_amount),
78
+ AdvancedStrings.uintToString(_amount),
81
79
  ",",
82
- Strings.toString(_nameServiceNonce)
80
+ AdvancedStrings.uintToString(_nameServiceNonce)
83
81
  ),
84
82
  signature,
85
83
  signer
@@ -95,15 +93,15 @@ library SignatureUtils {
95
93
  bytes memory signature
96
94
  ) internal pure returns (bool) {
97
95
  return
98
- SignatureRecover.signatureVerification(
99
- Strings.toString(evvmID),
96
+ SignatureUtil.verifySignature(
97
+ evvmID,
100
98
  "withdrawOffer",
101
99
  string.concat(
102
100
  _username,
103
101
  ",",
104
- Strings.toString(_offerId),
102
+ AdvancedStrings.uintToString(_offerId),
105
103
  ",",
106
- Strings.toString(_nameServiceNonce)
104
+ AdvancedStrings.uintToString(_nameServiceNonce)
107
105
  ),
108
106
  signature,
109
107
  signer
@@ -119,15 +117,15 @@ library SignatureUtils {
119
117
  bytes memory signature
120
118
  ) internal pure returns (bool) {
121
119
  return
122
- SignatureRecover.signatureVerification(
123
- Strings.toString(evvmID),
120
+ SignatureUtil.verifySignature(
121
+ evvmID,
124
122
  "acceptOffer",
125
123
  string.concat(
126
124
  _username,
127
125
  ",",
128
- Strings.toString(_offerId),
126
+ AdvancedStrings.uintToString(_offerId),
129
127
  ",",
130
- Strings.toString(_nameServiceNonce)
128
+ AdvancedStrings.uintToString(_nameServiceNonce)
131
129
  ),
132
130
  signature,
133
131
  signer
@@ -142,13 +140,13 @@ library SignatureUtils {
142
140
  bytes memory signature
143
141
  ) internal pure returns (bool) {
144
142
  return
145
- SignatureRecover.signatureVerification(
146
- Strings.toString(evvmID),
143
+ SignatureUtil.verifySignature(
144
+ evvmID,
147
145
  "renewUsername",
148
146
  string.concat(
149
147
  _username,
150
148
  ",",
151
- Strings.toString(_nameServiceNonce)
149
+ AdvancedStrings.uintToString(_nameServiceNonce)
152
150
  ),
153
151
  signature,
154
152
  signer
@@ -164,15 +162,15 @@ library SignatureUtils {
164
162
  bytes memory signature
165
163
  ) internal pure returns (bool) {
166
164
  return
167
- SignatureRecover.signatureVerification(
168
- Strings.toString(evvmID),
165
+ SignatureUtil.verifySignature(
166
+ evvmID,
169
167
  "addCustomMetadata",
170
168
  string.concat(
171
169
  _identity,
172
170
  ",",
173
171
  _value,
174
172
  ",",
175
- Strings.toString(_nameServiceNonce)
173
+ AdvancedStrings.uintToString(_nameServiceNonce)
176
174
  ),
177
175
  signature,
178
176
  signer
@@ -188,15 +186,15 @@ library SignatureUtils {
188
186
  bytes memory signature
189
187
  ) internal pure returns (bool) {
190
188
  return
191
- SignatureRecover.signatureVerification(
192
- Strings.toString(evvmID),
189
+ SignatureUtil.verifySignature(
190
+ evvmID,
193
191
  "removeCustomMetadata",
194
192
  string.concat(
195
193
  _username,
196
194
  ",",
197
- Strings.toString(_key),
195
+ AdvancedStrings.uintToString(_key),
198
196
  ",",
199
- Strings.toString(_nonce)
197
+ AdvancedStrings.uintToString(_nonce)
200
198
  ),
201
199
  signature,
202
200
  signer
@@ -211,10 +209,14 @@ library SignatureUtils {
211
209
  bytes memory signature
212
210
  ) internal pure returns (bool) {
213
211
  return
214
- SignatureRecover.signatureVerification(
215
- Strings.toString(evvmID),
212
+ SignatureUtil.verifySignature(
213
+ evvmID,
216
214
  "flushCustomMetadata",
217
- string.concat(_identity, ",", Strings.toString(_nonce)),
215
+ string.concat(
216
+ _identity,
217
+ ",",
218
+ AdvancedStrings.uintToString(_nonce)
219
+ ),
218
220
  signature,
219
221
  signer
220
222
  );
@@ -228,10 +230,14 @@ library SignatureUtils {
228
230
  bytes memory signature
229
231
  ) internal pure returns (bool) {
230
232
  return
231
- SignatureRecover.signatureVerification(
232
- Strings.toString(evvmID),
233
+ SignatureUtil.verifySignature(
234
+ evvmID,
233
235
  "flushUsername",
234
- string.concat(_username, ",", Strings.toString(_nonce)),
236
+ string.concat(
237
+ _username,
238
+ ",",
239
+ AdvancedStrings.uintToString(_nonce)
240
+ ),
235
241
  signature,
236
242
  signer
237
243
  );