@evvm/testnet-contracts 2.2.2 → 2.3.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 +145 -118
  2. package/README.md +135 -42
  3. package/contracts/evvm/Evvm.sol +154 -181
  4. package/contracts/evvm/lib/ErrorsLib.sol +119 -6
  5. package/contracts/evvm/lib/EvvmStorage.sol +164 -9
  6. package/contracts/evvm/lib/EvvmStructs.sol +124 -6
  7. package/contracts/evvm/lib/SignatureUtils.sol +103 -61
  8. package/contracts/nameService/NameService.sol +165 -155
  9. package/contracts/nameService/lib/ErrorsLib.sol +142 -8
  10. package/contracts/nameService/lib/IdentityValidation.sol +21 -0
  11. package/contracts/nameService/lib/NameServiceStructs.sol +75 -19
  12. package/contracts/nameService/lib/SignatureUtils.sol +235 -60
  13. package/contracts/p2pSwap/P2PSwap.sol +205 -164
  14. package/contracts/staking/Estimator.sol +131 -24
  15. package/contracts/staking/Staking.sol +98 -113
  16. package/contracts/staking/lib/ErrorsLib.sol +79 -3
  17. package/contracts/staking/lib/SignatureUtils.sol +82 -16
  18. package/contracts/staking/lib/StakingStructs.sol +12 -0
  19. package/contracts/treasury/Treasury.sol +30 -12
  20. package/contracts/treasury/lib/ErrorsLib.sol +30 -0
  21. package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +3 -3
  22. package/interfaces/IEvvm.sol +9 -4
  23. package/interfaces/INameService.sol +12 -3
  24. package/interfaces/IStaking.sol +2 -1
  25. package/library/Erc191TestBuilder.sol +188 -0
  26. package/library/EvvmService.sol +55 -0
  27. package/library/primitives/SignatureRecover.sol +33 -0
  28. package/library/utils/AdvancedStrings.sol +61 -0
  29. package/library/utils/SignatureUtil.sol +34 -0
  30. package/library/utils/nonces/AsyncNonce.sol +42 -0
  31. package/library/utils/nonces/SyncNonce.sol +44 -0
  32. package/library/utils/service/EvvmPayments.sol +68 -1
  33. package/library/utils/service/StakingServiceUtils.sol +44 -0
  34. package/package.json +2 -1
@@ -3,19 +3,153 @@
3
3
 
4
4
  pragma solidity ^0.8.0;
5
5
 
6
+ /**
7
+ * @title ErrorsLib
8
+ * @author Mate labs
9
+ * @notice Library containing custom error definitions exclusively for the NameService.sol contract
10
+ * @dev This library defines all custom errors used by the NameService.sol contract.
11
+ * Custom errors are more gas-efficient than require statements with strings
12
+ * and provide better error handling in client applications.
13
+ *
14
+ * Error Categories:
15
+ * - Access Control: Errors related to ownership and admin permissions
16
+ * - Validation: Errors for invalid usernames, signatures, and input validation
17
+ * - Registration: Errors specific to username registration and pre-registration
18
+ * - Marketplace: Errors for offer management and username trading
19
+ * - Metadata: Errors for custom metadata operations
20
+ * - Time-Lock: Errors for governance and renewal timing
21
+ *
22
+ * @custom:scope Exclusive to the NameService.sol contract
23
+ * @custom:security All errors provide clear failure reasons without exposing sensitive data
24
+ */
6
25
  library ErrorsLib {
26
+ //█ Access Control Errors ███████████████████████████████████████████████████
27
+
28
+ /**
29
+ * @notice Thrown when a function restricted to admin is called by a non-admin address
30
+ * @dev Used in functions with the `onlyAdmin` modifier
31
+ */
7
32
  error SenderIsNotAdmin();
33
+
34
+ /**
35
+ * @notice Thrown when an operation is attempted by someone other than the username owner
36
+ * @dev Used in functions that modify username data or accept offers
37
+ */
8
38
  error UserIsNotOwnerOfIdentity();
9
- error NonceAlreadyUsed();
39
+
40
+ /**
41
+ * @notice Thrown when an operation is attempted by someone other than the offer creator
42
+ * @dev Used in withdrawOffer to ensure only the offerer can withdraw their own offer
43
+ */
44
+ error UserIsNotOwnerOfOffer();
45
+
46
+ /**
47
+ * @notice Thrown when the proposed admin tries to accept before meeting requirements
48
+ * @dev Part of the time-delayed admin transfer mechanism
49
+ */
50
+ error SenderIsNotProposedAdmin();
51
+
52
+ //█ Validation Errors ███████████████████████████████████████████████████████
53
+
54
+ /**
55
+ * @notice Thrown when the provided EIP-191 signature is invalid or doesn't match the signer
56
+ * @dev Used in all operations requiring signature verification
57
+ */
10
58
  error InvalidSignatureOnNameService();
59
+
60
+ /**
61
+ * @notice Thrown when a username doesn't meet format requirements
62
+ * @dev Username must be 4+ characters, start with letter, contain only alphanumeric
63
+ */
11
64
  error InvalidUsername();
65
+
66
+ /**
67
+ * @notice Thrown when an amount parameter is zero but should be positive
68
+ * @dev Used in makeOffer to ensure offers have value
69
+ */
70
+ error AmountMustBeGreaterThanZero();
71
+
72
+ /**
73
+ * @notice Thrown when a custom metadata key is invalid
74
+ * @dev Used when trying to remove metadata with a key that doesn't exist
75
+ */
76
+ error InvalidKey();
77
+
78
+ /**
79
+ * @notice Thrown when attempting to add empty custom metadata
80
+ * @dev Custom metadata value cannot be an empty string
81
+ */
82
+ error EmptyCustomMetadata();
83
+
84
+ /**
85
+ * @notice Thrown when a proposed address or configuration is invalid
86
+ * @dev Used in admin proposal functions
87
+ */
88
+ error InvalidAdminProposal();
89
+
90
+ /**
91
+ * @notice Thrown when the EVVM address being proposed is invalid
92
+ * @dev Used when updating the EVVM contract integration address
93
+ */
94
+ error InvalidEvvmAddress();
95
+
96
+ /**
97
+ * @notice Thrown when the withdrawal amount is invalid or exceeds available balance
98
+ * @dev Used in token withdrawal functions
99
+ */
100
+ error InvalidWithdrawAmount();
101
+
102
+ //█ Registration and Time-Based Errors █████████████████████████████████████
103
+
104
+ /**
105
+ * @notice Thrown when attempting to register a username that is already taken
106
+ * @dev Usernames are unique and cannot be registered twice
107
+ */
12
108
  error UsernameAlreadyRegistered();
109
+
110
+ /**
111
+ * @notice Thrown when the pre-registration doesn't exist or has expired
112
+ * @dev Pre-registration must be completed within 30 minutes and by the same user
113
+ */
13
114
  error PreRegistrationNotValid();
14
- error MakeOfferVerificationFailed();
15
- error UserIsNotOwnerOfOffer();
16
- error AcceptOfferVerificationFailed();
17
- error RenewUsernameVerificationFailed();
18
- error EmptyCustomMetadata();
19
- error InvalidKey();
20
- error FlushUsernameVerificationFailed();
115
+
116
+ /**
117
+ * @notice Thrown when a timestamp/date is set to before the current time
118
+ * @dev Used for offer expiration dates and other future-dated operations
119
+ */
120
+ error CannotBeBeforeCurrentTime();
121
+
122
+ /**
123
+ * @notice Thrown when attempting operations on an expired username
124
+ * @dev Username ownership expires after the expireDate timestamp
125
+ */
126
+ error OwnershipExpired();
127
+
128
+ /**
129
+ * @notice Thrown when trying to renew a username beyond the maximum allowed period
130
+ * @dev Usernames can only be renewed up to 100 years in advance
131
+ */
132
+ error RenewalTimeLimitExceeded();
133
+
134
+ /**
135
+ * @notice Thrown when attempting to execute a time-locked action prematurely
136
+ * @dev Used in governance functions with time-delay requirements
137
+ */
138
+ error LockTimeNotExpired();
139
+
140
+ //█ Marketplace and Offer Errors ███████████████████████████████████████████
141
+
142
+ /**
143
+ * @notice Thrown when trying to accept or interact with an expired or non-existent offer
144
+ * @dev Offers expire at their expireDate timestamp or when offerer is address(0)
145
+ */
146
+ error OfferInactive();
147
+
148
+ //█ Identity Type Errors ██████████████████████████████████████████████████
149
+
150
+ /**
151
+ * @notice Thrown when an operation requiring a fully registered username is attempted on a pre-registration
152
+ * @dev Pre-registrations have flagNotAUsername = 0x01, full usernames have 0x00
153
+ */
154
+ error IdentityIsNotAUsername();
21
155
  }
@@ -3,6 +3,27 @@
3
3
 
4
4
  pragma solidity ^0.8.0;
5
5
 
6
+ /**
7
+ * @title IdentityValidation
8
+ * @author Mate labs
9
+ * @notice Library for validating usernames, emails, and phone numbers in the NameService system
10
+ * @dev Provides pure validation functions for identity-related strings used in NameService.sol.
11
+ * All validations are performed at the byte level for gas efficiency and precision.
12
+ *
13
+ * Validation Types:
14
+ * - Username: Alphanumeric identifiers with specific length and format requirements
15
+ * - Email: Standard email format validation with prefix, domain, and TLD checks
16
+ * - Phone Number: Numeric phone numbers with length constraints
17
+ *
18
+ * Character Validation:
19
+ * - Uses ASCII byte ranges for precise character classification
20
+ * - Supports letters (A-Z, a-z), digits (0-9), and specific symbols
21
+ * - All checks performed without external dependencies for security
22
+ *
23
+ * @custom:scope Exclusive to NameService.sol contract
24
+ * @custom:security All functions are pure with no external calls
25
+ * @custom:gas-optimization Byte-level operations for maximum efficiency
26
+ */
6
27
  library IdentityValidation{
7
28
  /**
8
29
  * @notice Validates username format according to system rules
@@ -3,12 +3,37 @@
3
3
 
4
4
  pragma solidity ^0.8.0;
5
5
 
6
+ /**
7
+ * @title NameServiceStructs
8
+ * @author Mate labs
9
+ * @notice Library of data structures used exclusively by the NameService.sol contract
10
+ * @dev This contract defines the type system for the NameService.sol contract,
11
+ * providing structured data types for identity management, marketplace operations,
12
+ * and governance proposals. These structures are not shared with external services.
13
+ *
14
+ * Structure Categories:
15
+ * - Identity Structures: IdentityBaseMetadata for username registration data
16
+ * - Marketplace Structures: OfferMetadata for username trading
17
+ * - Governance Structures: AddressTypeProposal, UintTypeProposal, BoolTypeProposal for time-delayed changes
18
+ *
19
+ * @custom:inheritance This contract is inherited by NameService.sol
20
+ * @custom:scope Exclusive to the NameService.sol contract
21
+ */
6
22
  abstract contract NameServiceStructs {
23
+ //░▒▓█ Governance Proposal Structures ███████████████████████████████████████████████▓▒░
24
+
7
25
  /**
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
26
+ * @notice Time-delayed proposal structure for address-type governance changes
27
+ * @dev Used for admin changes and EVVM contract address updates with 1-day delay
28
+ *
29
+ * Governance Flow:
30
+ * 1. Admin proposes new address -> sets proposal and timeToAccept
31
+ * 2. Time delay passes (1 day)
32
+ * 3. Proposed address calls accept -> current is updated, proposal is cleared
33
+ *
34
+ * @param current Currently active address with the role/privilege
35
+ * @param proposal Proposed new address awaiting acceptance after time delay
36
+ * @param timeToAccept Timestamp after which the proposal can be accepted
12
37
  */
13
38
  struct AddressTypeProposal {
14
39
  address current;
@@ -17,10 +42,13 @@ abstract contract NameServiceStructs {
17
42
  }
18
43
 
19
44
  /**
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
45
+ * @notice Time-delayed proposal structure for uint-type governance changes
46
+ * @dev Used for token withdrawal amount changes with time-delayed governance
47
+ * Follows the same pattern as AddressTypeProposal for consistency
48
+ *
49
+ * @param current Currently active value for the parameter
50
+ * @param proposal Proposed new value awaiting acceptance after time delay
51
+ * @param timeToAccept Timestamp after which the proposal can be accepted
24
52
  */
25
53
  struct UintTypeProposal {
26
54
  uint256 current;
@@ -29,8 +57,10 @@ abstract contract NameServiceStructs {
29
57
  }
30
58
 
31
59
  /**
32
- * @dev Struct for managing boolean flag changes with time delay
33
- * @param flag Current boolean state
60
+ * @notice Time-delayed proposal structure for boolean flag changes
61
+ * @dev Used for feature toggles and system state changes requiring governance
62
+ *
63
+ * @param flag Current boolean state of the feature/setting
34
64
  * @param timeToAcceptChange Timestamp when the flag change can be executed
35
65
  */
36
66
  struct BoolTypeProposal {
@@ -38,13 +68,26 @@ abstract contract NameServiceStructs {
38
68
  uint256 timeToAcceptChange;
39
69
  }
40
70
 
71
+ //░▒▓█ Identity Management Structures ███████████████████████████████████████████████▓▒░
72
+
41
73
  /**
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)
74
+ * @notice Core metadata for each registered identity/username
75
+ * @dev Stores essential registration information and ownership details
76
+ *
77
+ * Registration States:
78
+ * - flagNotAUsername = 0x01: Pre-registration (temporary reservation)
79
+ * - flagNotAUsername = 0x00: Full username registration (active identity)
80
+ *
81
+ * Ownership Model:
82
+ * - Owner has full control over the username
83
+ * - Ownership expires at expireDate (renewable up to 100 years)
84
+ * - Can be transferred through marketplace offers
85
+ *
86
+ * @param owner Address that owns this identity/username
87
+ * @param expireDate Timestamp when the registration expires (renewable)
88
+ * @param customMetadataMaxSlots Number of custom metadata entries stored for this identity
89
+ * @param offerMaxSlots Highest offer ID that has been created for this username
90
+ * @param flagNotAUsername 0x01 for pre-registration, 0x00 for full username
48
91
  */
49
92
  struct IdentityBaseMetadata {
50
93
  address owner;
@@ -54,11 +97,24 @@ abstract contract NameServiceStructs {
54
97
  bytes1 flagNotAUsername;
55
98
  }
56
99
 
100
+ //░▒▓█ Marketplace Structures ███████████████████████████████████████████████████████▓▒░
57
101
 
58
102
  /**
59
- * @dev Metadata for marketplace offers on usernames
60
- * @param offerer Address making the offer
61
- * @param expireDate Timestamp when the offer expires
103
+ * @notice Metadata for marketplace offers on usernames
104
+ * @dev Represents a locked offer to purchase a username at a specific price
105
+ *
106
+ * Offer Lifecycle:
107
+ * 1. Created: Tokens are locked in contract (after 0.5% marketplace fee deduction)
108
+ * 2. Active: Can be accepted by owner or withdrawn by offerer before expiration
109
+ * 3. Expired/Completed: offerer set to address(0), tokens released
110
+ *
111
+ * Fee Structure:
112
+ * - 0.5% marketplace fee deducted from offer amount
113
+ * - Remaining 99.5% locked for potential acceptance
114
+ * - Additional fees for stakers processing the transaction
115
+ *
116
+ * @param offerer Address that created and can withdraw this offer
117
+ * @param expireDate Timestamp when the offer expires and can no longer be accepted
62
118
  * @param amount Amount offered in Principal Tokens (after 0.5% marketplace fee deduction)
63
119
  */
64
120
  struct OfferMetadata {