@evvm/testnet-contracts 2.3.0 → 3.0.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 (67) hide show
  1. package/README.md +44 -24
  2. package/contracts/core/Core.sol +1392 -0
  3. package/contracts/core/lib/CoreStorage.sol +171 -0
  4. package/contracts/nameService/NameService.sol +613 -543
  5. package/contracts/nameService/lib/IdentityValidation.sol +15 -21
  6. package/contracts/p2pSwap/P2PSwap.sol +258 -145
  7. package/contracts/staking/Estimator.sol +25 -44
  8. package/contracts/staking/Staking.sol +284 -262
  9. package/contracts/treasury/Treasury.sol +40 -47
  10. package/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +585 -198
  11. package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +425 -174
  12. package/contracts/treasuryTwoChains/lib/PayloadUtils.sol +2 -4
  13. package/interfaces/{IEvvm.sol → ICore.sol} +58 -25
  14. package/interfaces/IEstimator.sol +1 -1
  15. package/interfaces/INameService.sol +46 -49
  16. package/interfaces/IP2PSwap.sol +16 -17
  17. package/interfaces/IStaking.sol +21 -17
  18. package/interfaces/ITreasury.sol +2 -1
  19. package/interfaces/ITreasuryExternalChainStation.sol +15 -9
  20. package/interfaces/ITreasuryHostChainStation.sol +14 -11
  21. package/interfaces/IUserValidator.sol +6 -0
  22. package/library/Erc191TestBuilder.sol +336 -471
  23. package/library/EvvmService.sol +27 -71
  24. package/library/errors/CoreError.sol +116 -0
  25. package/library/errors/CrossChainTreasuryError.sol +36 -0
  26. package/library/errors/NameServiceError.sol +79 -0
  27. package/library/errors/StakingError.sol +79 -0
  28. package/{contracts/treasury/lib/ErrorsLib.sol → library/errors/TreasuryError.sol} +9 -17
  29. package/library/structs/CoreStructs.sol +146 -0
  30. package/library/structs/ExternalChainStationStructs.sol +92 -0
  31. package/library/structs/HostChainStationStructs.sol +77 -0
  32. package/library/structs/NameServiceStructs.sol +47 -0
  33. package/library/structs/P2PSwapStructs.sol +127 -0
  34. package/library/structs/StakingStructs.sol +67 -0
  35. package/library/utils/AdvancedStrings.sol +62 -44
  36. package/library/utils/CAUtils.sol +29 -0
  37. package/library/utils/governance/Admin.sol +66 -0
  38. package/library/utils/governance/ProposalStructs.sol +49 -0
  39. package/library/utils/service/CoreExecution.sol +158 -0
  40. package/library/utils/service/StakingServiceUtils.sol +20 -37
  41. package/library/utils/signature/CoreHashUtils.sol +73 -0
  42. package/library/utils/signature/NameServiceHashUtils.sol +156 -0
  43. package/library/utils/signature/P2PSwapHashUtils.sol +65 -0
  44. package/library/utils/signature/StakingHashUtils.sol +41 -0
  45. package/library/utils/signature/TreasuryCrossChainHashUtils.sol +40 -0
  46. package/package.json +1 -1
  47. package/contracts/evvm/Evvm.sol +0 -1300
  48. package/contracts/evvm/lib/ErrorsLib.sol +0 -131
  49. package/contracts/evvm/lib/EvvmStorage.sol +0 -217
  50. package/contracts/evvm/lib/EvvmStructs.sol +0 -208
  51. package/contracts/evvm/lib/SignatureUtils.sol +0 -162
  52. package/contracts/nameService/lib/ErrorsLib.sol +0 -155
  53. package/contracts/nameService/lib/NameServiceStructs.sol +0 -125
  54. package/contracts/nameService/lib/SignatureUtils.sol +0 -420
  55. package/contracts/p2pSwap/lib/P2PSwapStructs.sol +0 -59
  56. package/contracts/p2pSwap/lib/SignatureUtils.sol +0 -98
  57. package/contracts/staking/lib/ErrorsLib.sol +0 -98
  58. package/contracts/staking/lib/SignatureUtils.sol +0 -105
  59. package/contracts/staking/lib/StakingStructs.sol +0 -106
  60. package/contracts/treasuryTwoChains/lib/ErrorsLib.sol +0 -48
  61. package/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +0 -80
  62. package/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +0 -87
  63. package/contracts/treasuryTwoChains/lib/SignatureUtils.sol +0 -79
  64. package/library/utils/GovernanceUtils.sol +0 -81
  65. package/library/utils/nonces/AsyncNonce.sol +0 -74
  66. package/library/utils/nonces/SyncNonce.sol +0 -71
  67. package/library/utils/service/EvvmPayments.sol +0 -144
@@ -1,71 +0,0 @@
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 SyncNonce
7
- * @author Mate Labs
8
- * @notice Abstract contract for synchronous (sequential) nonce management in EVVM services
9
- * @dev Provides replay protection using a sequential nonce system where nonces must be
10
- * used in strict ascending order starting from 0.
11
- *
12
- * Key Features:
13
- * - Sequential nonce enforcement (must use nonce N before N+1)
14
- * - Gas-efficient single uint256 counter per user
15
- * - Guarantees transaction ordering
16
- *
17
- * Use Cases:
18
- * - Operations requiring strict ordering guarantees
19
- * - Financial transactions where sequence matters
20
- * - State-dependent operations that must execute in order
21
- *
22
- * Trade-offs:
23
- * - Cannot submit parallel transactions (must wait for confirmation)
24
- * - Transaction N+1 cannot be mined before transaction N
25
- *
26
- * This contract is designed for use by community-developed services that need
27
- * strict sequential ordering for their operations.
28
- */
29
-
30
- abstract contract SyncNonce {
31
- /// @dev Thrown when the provided nonce does not match the expected next nonce
32
- error SyncNonceMismatch();
33
-
34
- /// @dev Mapping to track the next expected nonce for each user
35
- mapping(address user => uint256 nonce) private syncNonce;
36
-
37
- /**
38
- * @notice Increments the nonce counter for a user after successful operation
39
- * @dev Should be called after operation validation to advance the nonce
40
- * @param user Address of the user whose nonce counter should be incremented
41
- */
42
- function incrementSyncNonce(address user) internal virtual {
43
- syncNonce[user]++;
44
- }
45
-
46
- /**
47
- * @notice Verifies that the provided nonce matches the expected next nonce
48
- * @dev Reverts with SyncNonceMismatch if the nonce is not the expected value
49
- * @param user Address of the user to verify the nonce for
50
- * @param nonce The nonce value to verify
51
- * @custom:throws SyncNonceMismatch If nonce does not match the expected value
52
- */
53
- function verifySyncNonce(
54
- address user,
55
- uint256 nonce
56
- ) internal view virtual {
57
- if (syncNonce[user] != nonce) revert SyncNonceMismatch();
58
- }
59
-
60
- /**
61
- * @notice Gets the current (next expected) nonce for a user
62
- * @dev Public view function for external queries and transaction preparation
63
- * @param user Address of the user to query
64
- * @return The next nonce value that must be used by the user
65
- */
66
- function getNextCurrentSyncNonce(
67
- address user
68
- ) public view virtual returns (uint256) {
69
- return syncNonce[user];
70
- }
71
- }
@@ -1,144 +0,0 @@
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 EvvmPayments
7
- * @author Mate Labs
8
- * @notice Abstract contract providing EVVM payment integration for services
9
- * @dev This contract provides a standardized interface for interacting with
10
- * the EVVM core contract for payment operations. It supports:
11
- *
12
- * Payment Types:
13
- * - Single payments (pay): Transfer tokens from a user to the service
14
- * - Disperse payments (dispersePay): Batch payments from multiple sources
15
- * - Contract-authorized payments (caPay): Service-initiated token distributions
16
- * - Disperse CA payments: Batch service-initiated distributions
17
- *
18
- * This contract is designed for use by community-developed services that need
19
- * to process payments through the EVVM ecosystem.
20
- */
21
-
22
- import {IEvvm, EvvmStructs} from "@evvm/testnet-contracts/interfaces/IEvvm.sol";
23
-
24
- abstract contract EvvmPayments {
25
- /// @dev Reference to the EVVM core contract for payment operations
26
- IEvvm internal evvm;
27
-
28
- /**
29
- * @notice Initializes the EvvmPayments contract with the EVVM address
30
- * @param evvmAddress Address of the EVVM core contract
31
- */
32
- constructor(address evvmAddress) {
33
- evvm = IEvvm(evvmAddress);
34
- }
35
-
36
- /**
37
- * @notice Requests a payment from a user to this contract
38
- * @dev Calls the EVVM pay function to transfer tokens with signature verification
39
- * @param from Address of the user making the payment
40
- * @param token Address of the token being transferred
41
- * @param amount Amount of tokens to transfer
42
- * @param priorityFee Additional fee for priority processing
43
- * @param nonce Nonce for replay protection in EVVM
44
- * @param priorityFlag True for async nonce, false for sync nonce in EVVM
45
- * @param signature EIP-191 signature authorizing the payment
46
- */
47
- function requestPay(
48
- address from,
49
- address token,
50
- uint256 amount,
51
- uint256 priorityFee,
52
- uint256 nonce,
53
- bool priorityFlag,
54
- bytes memory signature
55
- ) internal virtual {
56
- evvm.pay(
57
- from,
58
- address(this),
59
- "",
60
- token,
61
- amount,
62
- priorityFee,
63
- nonce,
64
- priorityFlag,
65
- address(this),
66
- signature
67
- );
68
- }
69
-
70
- /**
71
- * @notice Requests a batch payment from the caller to multiple recipients
72
- * @dev Calls the EVVM dispersePay function for efficient batch transfers
73
- * @param toData Array of recipient addresses and amounts
74
- * @param token Address of the token being transferred
75
- * @param amount Total amount being transferred (for signature verification)
76
- * @param priorityFee Additional fee for priority processing
77
- * @param nonce Nonce for replay protection in EVVM
78
- * @param priorityFlag True for async nonce, false for sync nonce in EVVM
79
- * @param signature EIP-191 signature authorizing the batch payment
80
- */
81
- function requestDispersePay(
82
- EvvmStructs.DispersePayMetadata[] memory toData,
83
- address token,
84
- uint256 amount,
85
- uint256 priorityFee,
86
- uint256 nonce,
87
- bool priorityFlag,
88
- bytes memory signature
89
- ) internal virtual {
90
- evvm.dispersePay(
91
- address(this),
92
- toData,
93
- token,
94
- amount,
95
- priorityFee,
96
- nonce,
97
- priorityFlag,
98
- address(this),
99
- signature
100
- );
101
- }
102
-
103
- /**
104
- * @notice Sends tokens from this contract to a recipient (contract-authorized)
105
- * @dev Calls the EVVM caPay function for service-initiated token transfers.
106
- * This function does not require user signature as it's authorized by the contract.
107
- * @param to Address of the recipient
108
- * @param token Address of the token to transfer
109
- * @param amount Amount of tokens to transfer
110
- */
111
- function makeCaPay(
112
- address to,
113
- address token,
114
- uint256 amount
115
- ) internal virtual {
116
- evvm.caPay(to, token, amount);
117
- }
118
-
119
- /**
120
- * @notice Sends tokens from this contract to multiple recipients (batch CA pay)
121
- * @dev Calls the EVVM disperseCaPay for efficient batch distributions.
122
- * This function does not require user signatures.
123
- * @param toData Array of recipient addresses and amounts
124
- * @param token Address of the token to transfer
125
- * @param amount Total amount being distributed
126
- */
127
- function makeDisperseCaPay(
128
- EvvmStructs.DisperseCaPayMetadata[] memory toData,
129
- address token,
130
- uint256 amount
131
- ) internal virtual {
132
- evvm.disperseCaPay(toData, token, amount);
133
- }
134
-
135
- /**
136
- * @notice Updates the EVVM contract address
137
- * @dev Internal function for governance-controlled EVVM address changes.
138
- * Should be protected by time-delayed governance in implementing contracts.
139
- * @param newEvvmAddress Address of the new EVVM contract
140
- */
141
- function _changeEvvmAddress(address newEvvmAddress) internal virtual {
142
- evvm = IEvvm(newEvvmAddress);
143
- }
144
- }