@evvm/testnet-contracts 2.2.3 → 3.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 (71) hide show
  1. package/LICENSE +145 -118
  2. package/README.md +162 -39
  3. package/contracts/core/Core.sol +1394 -0
  4. package/contracts/core/lib/CoreStorage.sol +171 -0
  5. package/contracts/nameService/NameService.sol +666 -586
  6. package/contracts/nameService/lib/IdentityValidation.sol +18 -3
  7. package/contracts/p2pSwap/P2PSwap.sol +439 -285
  8. package/contracts/staking/Estimator.sol +128 -40
  9. package/contracts/staking/Staking.sol +329 -322
  10. package/contracts/treasury/Treasury.sol +48 -37
  11. package/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +585 -198
  12. package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +425 -174
  13. package/contracts/treasuryTwoChains/lib/PayloadUtils.sol +2 -4
  14. package/interfaces/{IEvvm.sol → ICore.sol} +67 -29
  15. package/interfaces/IEstimator.sol +1 -1
  16. package/interfaces/INameService.sol +58 -52
  17. package/interfaces/IP2PSwap.sol +18 -17
  18. package/interfaces/IStaking.sol +22 -17
  19. package/interfaces/ITreasury.sol +2 -1
  20. package/interfaces/ITreasuryExternalChainStation.sol +15 -9
  21. package/interfaces/ITreasuryHostChainStation.sol +14 -11
  22. package/interfaces/IUserValidator.sol +6 -0
  23. package/library/Erc191TestBuilder.sol +350 -297
  24. package/library/EvvmService.sol +38 -27
  25. package/library/errors/CoreError.sol +116 -0
  26. package/library/errors/CrossChainTreasuryError.sol +36 -0
  27. package/library/errors/NameServiceError.sol +79 -0
  28. package/library/errors/StakingError.sol +79 -0
  29. package/library/errors/TreasuryError.sol +33 -0
  30. package/library/primitives/SignatureRecover.sol +33 -0
  31. package/library/structs/CoreStructs.sol +146 -0
  32. package/library/structs/ExternalChainStationStructs.sol +92 -0
  33. package/library/structs/HostChainStationStructs.sol +77 -0
  34. package/library/structs/NameServiceStructs.sol +47 -0
  35. package/library/structs/P2PSwapStructs.sol +127 -0
  36. package/library/structs/StakingStructs.sol +67 -0
  37. package/library/utils/AdvancedStrings.sol +84 -5
  38. package/library/utils/CAUtils.sol +29 -0
  39. package/library/utils/SignatureUtil.sol +34 -0
  40. package/library/utils/governance/Admin.sol +66 -0
  41. package/library/utils/governance/ProposalStructs.sol +49 -0
  42. package/library/utils/service/CoreExecution.sol +177 -0
  43. package/library/utils/service/StakingServiceUtils.sol +30 -3
  44. package/library/utils/signature/CoreHashUtils.sol +73 -0
  45. package/library/utils/signature/NameServiceHashUtils.sol +156 -0
  46. package/library/utils/signature/P2PSwapHashUtils.sol +65 -0
  47. package/library/utils/signature/StakingHashUtils.sol +41 -0
  48. package/library/utils/signature/TreasuryCrossChainHashUtils.sol +40 -0
  49. package/package.json +2 -1
  50. package/contracts/evvm/Evvm.sol +0 -1327
  51. package/contracts/evvm/lib/ErrorsLib.sol +0 -18
  52. package/contracts/evvm/lib/EvvmStorage.sol +0 -62
  53. package/contracts/evvm/lib/EvvmStructs.sol +0 -90
  54. package/contracts/evvm/lib/SignatureUtils.sol +0 -120
  55. package/contracts/nameService/lib/ErrorsLib.sol +0 -21
  56. package/contracts/nameService/lib/NameServiceStructs.sol +0 -69
  57. package/contracts/nameService/lib/SignatureUtils.sol +0 -245
  58. package/contracts/p2pSwap/lib/P2PSwapStructs.sol +0 -59
  59. package/contracts/p2pSwap/lib/SignatureUtils.sol +0 -98
  60. package/contracts/staking/lib/ErrorsLib.sol +0 -22
  61. package/contracts/staking/lib/SignatureUtils.sol +0 -39
  62. package/contracts/staking/lib/StakingStructs.sol +0 -94
  63. package/contracts/treasury/lib/ErrorsLib.sol +0 -11
  64. package/contracts/treasuryTwoChains/lib/ErrorsLib.sol +0 -48
  65. package/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +0 -80
  66. package/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +0 -87
  67. package/contracts/treasuryTwoChains/lib/SignatureUtils.sol +0 -79
  68. package/library/utils/GovernanceUtils.sol +0 -81
  69. package/library/utils/nonces/AsyncNonce.sol +0 -32
  70. package/library/utils/nonces/SyncNonce.sol +0 -27
  71. package/library/utils/service/EvvmPayments.sol +0 -79
@@ -0,0 +1,66 @@
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 {
7
+ ProposalStructs
8
+ } from "@evvm/testnet-contracts/library/utils/governance/ProposalStructs.sol";
9
+
10
+ /**
11
+ * @title Admin Governance Base Contract
12
+ * @author Mate labs
13
+ * @notice Time-delayed admin governance with propose/accept pattern
14
+ * @dev Abstract base using ProposalStructs.AddressTypeProposal. Recommended delay: 1 day (86400s).
15
+ */
16
+ abstract contract Admin {
17
+ /**
18
+ * @notice Admin proposal with time-delayed acceptance
19
+ * @dev Stores current, proposed, and acceptance time
20
+ */
21
+ ProposalStructs.AddressTypeProposal public admin;
22
+
23
+ /// @dev Thrown when caller is not current admin
24
+ error SenderIsNotAdmin();
25
+ /// @dev Thrown when proposal acceptance attempted early
26
+ error ProposalNotReady();
27
+
28
+ /**
29
+ * @notice Restricts function access to current admin
30
+ */
31
+ modifier onlyAdmin() {
32
+ if (msg.sender != admin.current) revert SenderIsNotAdmin();
33
+ _;
34
+ }
35
+
36
+ /**
37
+ * @notice Initializes admin governance with initial admin address
38
+ * @dev Sets admin.current without time delay. Only called during construction.
39
+ * @param initialAdmin Address of first admin
40
+ */
41
+ constructor(address initialAdmin) {
42
+ admin.current = initialAdmin;
43
+ }
44
+
45
+ /**
46
+ * @notice Proposes new admin with custom time delay
47
+ * @dev Sets admin.proposal and admin.timeToAccept (block.timestamp + delay). Only current admin.
48
+ * @param newAdmin Proposed new admin address
49
+ * @param delay Seconds before acceptance allowed
50
+ */
51
+ function proposeAdmin(address newAdmin, uint256 delay) external onlyAdmin {
52
+ admin.proposal = newAdmin;
53
+ admin.timeToAccept = block.timestamp + delay;
54
+ }
55
+
56
+ /**
57
+ * @notice Accepts admin proposal after time delay
58
+ * @dev Transfers admin role to proposed address. Reverts if block.timestamp < timeToAccept. Only current admin.
59
+ */
60
+ function acceptAdminProposal() external onlyAdmin {
61
+ if (block.timestamp < admin.timeToAccept) revert ProposalNotReady();
62
+ admin.current = admin.proposal;
63
+ admin.proposal = address(0);
64
+ admin.timeToAccept = 0;
65
+ }
66
+ }
@@ -0,0 +1,49 @@
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
+ /**
7
+ * @title Proposal Data Structures
8
+ * @author Mate labs
9
+ * @notice Time-delayed governance proposal structures for safe parameter changes
10
+ * @dev Three proposal types: AddressTypeProposal, UintTypeProposal, BoolTypeProposal. Standard delay: 1 day (86400s).
11
+ */
12
+ library ProposalStructs {
13
+ /**
14
+ * @notice Time-delayed address change proposal
15
+ * @dev Used for admin, executor, and contract address updates
16
+ * @param current Currently active address
17
+ * @param proposal Proposed new address
18
+ * @param timeToAccept Timestamp when proposal becomes acceptable
19
+ */
20
+ struct AddressTypeProposal {
21
+ address current;
22
+ address proposal;
23
+ uint256 timeToAccept;
24
+ }
25
+
26
+ /**
27
+ * @notice Time-delayed numeric value proposal
28
+ * @dev Used for fees, limits, rates, and thresholds
29
+ * @param current Currently active value
30
+ * @param proposal Proposed new value
31
+ * @param timeToAccept Timestamp when proposal becomes acceptable
32
+ */
33
+ struct UintTypeProposal {
34
+ uint256 current;
35
+ uint256 proposal;
36
+ uint256 timeToAccept;
37
+ }
38
+
39
+ /**
40
+ * @notice Time-delayed boolean flag proposal
41
+ * @dev Used for pause/unpause, enable/disable features. Not suitable for instant emergency stops.
42
+ * @param flag Current boolean state
43
+ * @param timeToAccept Timestamp when toggle allowed
44
+ */
45
+ struct BoolTypeProposal {
46
+ bool flag;
47
+ uint256 timeToAccept;
48
+ }
49
+ }
@@ -0,0 +1,177 @@
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 EVVM Payment Integration for Services
7
+ * @author Mate labs
8
+ * @notice Abstract contract providing Core.sol payment processing interface
9
+ * @dev Four payment types: requestPay (user-to-service with signature), requestDispersePay (batch user-to-service), makeCaPay (contract-authorized service-to-user), makeDisperseCaPay (batch CA).
10
+ */
11
+
12
+ import {ICore, CoreStructs} from "@evvm/testnet-contracts/interfaces/ICore.sol";
13
+
14
+ abstract contract CoreExecution {
15
+ /// @notice EVVM core contract reference
16
+ /// @dev Used for all payment operations
17
+ ICore internal core;
18
+
19
+ /**
20
+ * @notice Initializes EVVM payment integration
21
+ * @param _coreAddress Address of Core.sol contract
22
+ */
23
+ constructor(address _coreAddress) {
24
+ core = ICore(_coreAddress);
25
+ }
26
+
27
+ /**
28
+ * @notice Requests payment from user to service via Evvm.pay with signature validation
29
+ * @dev Calls core.pay(from, address(this), "", ...). Signature validated by State.validateAndConsumeNonce.
30
+ * @param from User paying (signer)
31
+ * @param token Token address
32
+ * @param amount Token amount
33
+ * @param priorityFee Executor fee
34
+ * @param nonce Sequential or async nonce
35
+ * @param isAsyncExec Nonce type (true=async, false=sync)
36
+ * @param signature User's ECDSA signature
37
+ */
38
+ function requestPay(
39
+ address from,
40
+ address token,
41
+ uint256 amount,
42
+ uint256 priorityFee,
43
+ uint256 nonce,
44
+ bool isAsyncExec,
45
+ bytes memory signature
46
+ ) internal virtual {
47
+ core.pay(
48
+ from,
49
+ address(this),
50
+ "",
51
+ token,
52
+ amount,
53
+ priorityFee,
54
+ address(this),
55
+ nonce,
56
+ isAsyncExec,
57
+ signature
58
+ );
59
+ }
60
+
61
+ /**
62
+ * @notice Requests batch payment from user via Evvm.dispersePay
63
+ * @dev Signature validated by Core.sol. Total amount must match sum of toData amounts.
64
+ * @param toData Array of (recipient, amount) pairs
65
+ * @param token Token address
66
+ * @param amount Total amount (must match sum)
67
+ * @param priorityFee Executor fee
68
+ * @param nonce Sequential or async nonce
69
+ * @param isAsyncExec Nonce type (true=async, false=sync)
70
+ * @param signature User's ECDSA signature
71
+ */
72
+ function requestDispersePay(
73
+ CoreStructs.DispersePayMetadata[] memory toData,
74
+ address token,
75
+ uint256 amount,
76
+ uint256 priorityFee,
77
+ uint256 nonce,
78
+ bool isAsyncExec,
79
+ bytes memory signature
80
+ ) internal virtual {
81
+ core.dispersePay(
82
+ address(this),
83
+ toData,
84
+ token,
85
+ amount,
86
+ priorityFee,
87
+ address(this),
88
+ nonce,
89
+ isAsyncExec,
90
+ signature
91
+ );
92
+ }
93
+
94
+ /**
95
+ * @notice Sends tokens from service to recipient via contract authorization (no signature)
96
+ * @dev Calls core.caPay(to, token, amount). Service must have sufficient Evvm balance.
97
+ * @param to Recipient address
98
+ * @param token Token address
99
+ * @param amount Token amount
100
+ */
101
+ function makeCaPay(
102
+ address to,
103
+ address token,
104
+ uint256 amount
105
+ ) internal virtual {
106
+ core.caPay(to, token, amount);
107
+ }
108
+
109
+ /**
110
+ * @notice Sends tokens to multiple recipients via contract authorization (batch)
111
+ * @dev Calls evvm.disperseCaPay. Total amount must match sum of toData amounts.
112
+ * @param toData Array of (recipient, amount) pairs
113
+ * @param token Token address
114
+ * @param amount Total amount (must match sum)
115
+ */
116
+ function makeDisperseCaPay(
117
+ CoreStructs.DisperseCaPayMetadata[] memory toData,
118
+ address token,
119
+ uint256 amount
120
+ ) internal virtual {
121
+ core.disperseCaPay(toData, token, amount);
122
+ }
123
+
124
+ /**
125
+ * @notice Reserves async nonce for user and this service exclusively
126
+ * @dev Calls core.reserveAsyncNonce(user, nonce, address(this)). Nonce can be revoked before use.
127
+ * @param nonce Async nonce number to reserve
128
+ */
129
+ function reserveAsyncNonceToService(uint256 nonce) external {
130
+ core.reserveAsyncNonce(nonce, address(this));
131
+ }
132
+
133
+ /**
134
+ * @notice Revokes reserved async nonce before use
135
+ * @dev Calls core.revokeAsyncNonce(user, nonce). Cannot revoke consumed nonces.
136
+ * @param user User address that reserved nonce
137
+ * @param nonce Async nonce number to revoke
138
+ */
139
+ function revokeAsyncNonceToService(address user, uint256 nonce) external {
140
+ core.revokeAsyncNonce(user, nonce);
141
+ }
142
+
143
+ /**
144
+ * @notice Gets next sequential sync nonce for user
145
+ * @dev View function returning core.getNextCurrentSyncNonce(user). Auto-increments after each use.
146
+ * @param user User address to query
147
+ * @return Next sync nonce for user
148
+ */
149
+ function getNextCurrentSyncNonce(
150
+ address user
151
+ ) external view returns (uint256) {
152
+ return core.getNextCurrentSyncNonce(user);
153
+ }
154
+
155
+ /**
156
+ * @notice Checks if async nonce was consumed
157
+ * @dev View function returning core.getIfUsedAsyncNonce(user, nonce). Reserved nonces return false until consumed.
158
+ * @param user User address to query
159
+ * @param nonce Async nonce to check
160
+ * @return true if consumed, false if available/reserved
161
+ */
162
+ function getIfUsedAsyncNonce(
163
+ address user,
164
+ uint256 nonce
165
+ ) external view returns (bool) {
166
+ return core.getIfUsedAsyncNonce(user, nonce);
167
+ }
168
+
169
+ /**
170
+ * @notice Updates Core.sol contract address for governance-controlled upgrades
171
+ * @dev Should be protected with onlyAdmin and time-delay (ProposalStructs pattern recommended).
172
+ * @param newCoreAddress New Core.sol contract address
173
+ */
174
+ function _changeCoreAddress(address newCoreAddress) internal virtual {
175
+ core = ICore(newCoreAddress);
176
+ }
177
+ }
@@ -1,31 +1,58 @@
1
1
  // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
2
  // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
3
  pragma solidity ^0.8.0;
4
+ /**
5
+ * @title Staking Utilities for EVVM Services
6
+ * @author Mate labs
7
+ * @notice Abstract contract for Staking.sol integration enabling services to stake and earn Fisher fees
8
+ * @dev Three-step staking: prepareServiceStaking → core.caPay(5083 PT * amount) → confirmServiceStaking. Cost: 5083 PT per staking token.
9
+ */
4
10
 
5
11
  import {IStaking} from "@evvm/testnet-contracts/interfaces/IStaking.sol";
6
- import {IEvvm} from "@evvm/testnet-contracts/interfaces/IEvvm.sol";
12
+ import {ICore} from "@evvm/testnet-contracts/interfaces/ICore.sol";
7
13
 
8
14
  abstract contract StakingServiceUtils {
15
+ /// @notice Staking contract reference
16
+ /// @dev Used for all staking operations
9
17
  IStaking internal staking;
10
18
 
19
+ /**
20
+ * @notice Initializes staking integration
21
+ * @param stakingAddress Address of Staking.sol
22
+ */
11
23
  constructor(address stakingAddress) {
12
24
  staking = IStaking(stakingAddress);
13
25
  }
14
26
 
27
+ /**
28
+ * @notice Stakes tokens for this service via 3-step atomic process
29
+ * @dev Calls prepareServiceStaking → core.caPay(PT, cost) → confirmServiceStaking. Requires 5083 PT * amountToStake in service Evvm balance.
30
+ * @param amountToStake Number of staking tokens to purchase
31
+ */
15
32
  function _makeStakeService(uint256 amountToStake) internal {
16
33
  staking.prepareServiceStaking(amountToStake);
17
- IEvvm(staking.getEvvmAddress()).caPay(
34
+ ICore(staking.getCoreAddress()).caPay(
18
35
  address(staking),
19
- IEvvm(staking.getEvvmAddress()).getPrincipalTokenAddress(),
36
+ ICore(staking.getCoreAddress()).getPrincipalTokenAddress(),
20
37
  staking.priceOfStaking() * amountToStake
21
38
  );
22
39
  staking.confirmServiceStaking();
23
40
  }
24
41
 
42
+ /**
43
+ * @notice Unstakes tokens from this service, burning them and refunding 5083 PT per token
44
+ * @dev Calls staking.serviceUnstaking(amount). PT refunded to service Evvm balance.
45
+ * @param amountToUnstake Number of staking tokens to release
46
+ */
25
47
  function _makeUnstakeService(uint256 amountToUnstake) internal {
26
48
  staking.serviceUnstaking(amountToUnstake);
27
49
  }
28
50
 
51
+ /**
52
+ * @notice Updates Staking.sol contract address for governance-controlled upgrades
53
+ * @dev Should be protected with onlyAdmin and time-delay. Existing stakes remain in old contract.
54
+ * @param newStakingAddress New Staking.sol contract address
55
+ */
29
56
  function _changeStakingAddress(address newStakingAddress) internal virtual {
30
57
  staking = IStaking(newStakingAddress);
31
58
  }
@@ -0,0 +1,73 @@
1
+ // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
+ // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
+ pragma solidity ^0.8.0;
4
+
5
+ import {
6
+ CoreStructs
7
+ } from "@evvm/testnet-contracts/library/structs/CoreStructs.sol";
8
+
9
+ /**
10
+ * @title EVVM Core Hash Utilities
11
+ * @author Mate labs
12
+ * @notice Generates deterministic hashes for Core contract payment operations.
13
+ * @dev Reconstructs data payloads for EIP-191 signature verification within the EVVM ecosystem.
14
+ */
15
+ library CoreHashUtils {
16
+
17
+ /**
18
+ * @notice Generates hash for single payment operation
19
+ * @dev Hash: keccak256("pay", to_address, to_identity, token, amount, priorityFee, executor)
20
+ * @param to_address Direct recipient address
21
+ * @param to_identity Username for NameService resolution
22
+ * @param token Token address
23
+ * @param amount Token amount
24
+ * @param priorityFee Fee for executor
25
+ * @return Hash for Core.sol validation
26
+ */
27
+ function hashDataForPay(
28
+ address to_address,
29
+ string memory to_identity,
30
+ address token,
31
+ uint256 amount,
32
+ uint256 priorityFee
33
+ ) public pure returns (bytes32) {
34
+ return
35
+ keccak256(
36
+ abi.encode(
37
+ "pay",
38
+ to_address,
39
+ to_identity,
40
+ token,
41
+ amount,
42
+ priorityFee
43
+ )
44
+ );
45
+ }
46
+
47
+ /**
48
+ * @notice Generates hash for batch payment operation
49
+ * @dev Hash: keccak256("dispersePay", toData, token, amount, priorityFee, executor). Single nonce for entire batch.
50
+ * @param toData Array of recipients and amounts
51
+ * @param token Token address
52
+ * @param amount Total amount (must equal sum)
53
+ * @param priorityFee Fee for executor
54
+ * @return Hash for Core.sol validation
55
+ */
56
+ function hashDataForDispersePay(
57
+ CoreStructs.DispersePayMetadata[] memory toData,
58
+ address token,
59
+ uint256 amount,
60
+ uint256 priorityFee
61
+ ) internal pure returns (bytes32) {
62
+ return
63
+ keccak256(
64
+ abi.encode(
65
+ "dispersePay",
66
+ toData,
67
+ token,
68
+ amount,
69
+ priorityFee
70
+ )
71
+ );
72
+ }
73
+ }
@@ -0,0 +1,156 @@
1
+ // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
+ // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
+ pragma solidity ^0.8.0;
4
+
5
+ import {
6
+ SignatureUtil
7
+ } from "@evvm/testnet-contracts/library/utils/SignatureUtil.sol";
8
+ import {
9
+ AdvancedStrings
10
+ } from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
11
+
12
+ /**
13
+ * @title NameServiceHashUtils
14
+ * @author Mate labs
15
+ * @notice Hash generation for NameService.sol operations (registration, marketplace, metadata)
16
+ * @dev Deterministic keccak256 hashes for 10 NameService operations. Used with Core.validateAndConsumeNonce.
17
+ */
18
+ library NameServiceHashUtils {
19
+ /**
20
+ * @notice Generates hash for username pre-registration (commit phase)
21
+ * @dev Hash: keccak256("preRegistrationUsername", hashUsername). Prevents front-running, valid 30 minutes.
22
+ * @param hashUsername Keccak256 of (username + lockNumber)
23
+ * @return Hash for Core.sol validation
24
+ */
25
+ function hashDataForPreRegistrationUsername(
26
+ bytes32 hashUsername
27
+ ) internal pure returns (bytes32) {
28
+ return keccak256(abi.encode("preRegistrationUsername", hashUsername));
29
+ }
30
+
31
+ /**
32
+ * @notice Generates hash for username registration (reveal phase)
33
+ * @dev Hash: keccak256("registrationUsername", username, lockNumber). Must match pre-reg within 30 minutes. Cost: 100x EVVM reward.
34
+ * @param username Username being registered
35
+ * @param lockNumber Random number from pre-registration
36
+ * @return Hash for Core.sol validation
37
+ */
38
+ function hashDataForRegistrationUsername(
39
+ string memory username,
40
+ uint256 lockNumber
41
+ ) internal pure returns (bytes32) {
42
+ return
43
+ keccak256(abi.encode("registrationUsername", username, lockNumber));
44
+ }
45
+
46
+ /**
47
+ * @notice Generates hash for creating marketplace offer
48
+ * @dev Hash: keccak256("makeOffer", username, amount, expirationDate). Locks PT with 0.5% fee.
49
+ * @param username Target username
50
+ * @param amount Principal Tokens offered (pre-fee)
51
+ * @param expirationDate Offer expiration timestamp
52
+ * @return Hash for Core.sol validation
53
+ */
54
+ function hashDataForMakeOffer(
55
+ string memory username,
56
+ uint256 amount,
57
+ uint256 expirationDate
58
+ ) internal pure returns (bytes32) {
59
+ return
60
+ keccak256(
61
+ abi.encode("makeOffer", username, amount, expirationDate)
62
+ );
63
+ }
64
+
65
+ /**
66
+ * @notice Generates hash for withdrawing marketplace offer
67
+ * @dev Hash: keccak256("withdrawOffer", username, offerId). Only offer creator can withdraw.
68
+ * @param username Username with the offer
69
+ * @param offerId Offer ID to withdraw
70
+ * @return Hash for Core.sol validation
71
+ */
72
+ function hashDataForWithdrawOffer(
73
+ string memory username,
74
+ uint256 offerId
75
+ ) internal pure returns (bytes32) {
76
+ return keccak256(abi.encode("withdrawOffer", username, offerId));
77
+ }
78
+
79
+ /**
80
+ * @notice Generates hash for accepting marketplace offer
81
+ * @dev Hash: keccak256("acceptOffer", username, offerId). Transfers ownership to offerer.
82
+ * @param username Username being sold
83
+ * @param offerId Offer ID to accept
84
+ * @return Hash for Core.sol validation
85
+ */
86
+ function hashDataForAcceptOffer(
87
+ string memory username,
88
+ uint256 offerId
89
+ ) internal pure returns (bytes32) {
90
+ return keccak256(abi.encode("acceptOffer", username, offerId));
91
+ }
92
+
93
+ /**
94
+ * @notice Generates hash for renewing username
95
+ * @dev Hash: keccak256("renewUsername", username). Can renew up to 100 years in advance.
96
+ * @param username Username to renew
97
+ * @return Hash for Core.sol validation
98
+ */
99
+ function hashDataForRenewUsername(
100
+ string memory username
101
+ ) internal pure returns (bytes32) {
102
+ return keccak256(abi.encode("renewUsername", username));
103
+ }
104
+
105
+ /**
106
+ * @notice Generates hash for adding custom metadata
107
+ * @dev Hash: keccak256("addCustomMetadata", identity, value). Cost: 10x EVVM reward.
108
+ * @param identity Username or identity
109
+ * @param value Metadata value to store
110
+ * @return Hash for Core.sol validation
111
+ */
112
+ function hashDataForAddCustomMetadata(
113
+ string memory identity,
114
+ string memory value
115
+ ) internal pure returns (bytes32) {
116
+ return keccak256(abi.encode("addCustomMetadata", identity, value));
117
+ }
118
+
119
+ /**
120
+ * @notice Generates hash for removing custom metadata
121
+ * @dev Hash: keccak256("removeCustomMetadata", identity, key). Cost: 10x EVVM reward.
122
+ * @param identity Username or identity
123
+ * @param key Metadata entry key to remove
124
+ * @return Hash for Core.sol validation
125
+ */
126
+ function hashDataForRemoveCustomMetadata(
127
+ string memory identity,
128
+ uint256 key
129
+ ) internal pure returns (bytes32) {
130
+ return keccak256(abi.encode("removeCustomMetadata", identity, key));
131
+ }
132
+
133
+ /**
134
+ * @notice Generates hash for flushing all metadata
135
+ * @dev Hash: keccak256("flushCustomMetadata", identity). Removes ALL custom metadata entries.
136
+ * @param identity Username or identity to flush
137
+ * @return Hash for Core.sol validation
138
+ */
139
+ function hashDataForFlushCustomMetadata(
140
+ string memory identity
141
+ ) internal pure returns (bytes32) {
142
+ return keccak256(abi.encode("flushCustomMetadata", identity));
143
+ }
144
+
145
+ /**
146
+ * @notice Generates hash for flushing username (complete deletion)
147
+ * @dev Hash: keccak256("flushUsername", username). Irreversible. Deletes all data and makes username available.
148
+ * @param username Username to delete
149
+ * @return Hash for Core.sol validation
150
+ */
151
+ function hashDataForFlushUsername(
152
+ string memory username
153
+ ) internal pure returns (bytes32) {
154
+ return keccak256(abi.encode("flushUsername", username));
155
+ }
156
+ }
@@ -0,0 +1,65 @@
1
+ // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
+ // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
+ pragma solidity ^0.8.0;
4
+
5
+ /**
6
+ * @title P2P Swap Hash Utilities Library
7
+ * @author Mate labs
8
+ * @notice Hash generation for P2PSwap.sol operations (makeOrder, cancelOrder, dispatchOrder)
9
+ * @dev All hashes validated via Core.sol with async nonces. Three operation types supported.
10
+ */
11
+ library P2PSwapHashUtils {
12
+ /**
13
+ * @notice Generates hash for makeOrder operation
14
+ * @dev Hash: keccak256("makeOrder", tokenA, tokenB, amountA, amountB). Uses async nonce.
15
+ * @param tokenA Token offered by seller
16
+ * @param tokenB Token requested by seller
17
+ * @param amountA Amount of tokenA offered
18
+ * @param amountB Amount of tokenB requested
19
+ * @return Hash for Core.sol validation
20
+ */
21
+ function hashDataForMakeOrder(
22
+ address tokenA,
23
+ address tokenB,
24
+ uint256 amountA,
25
+ uint256 amountB
26
+ ) internal pure returns (bytes32) {
27
+ return
28
+ keccak256(
29
+ abi.encode("makeOrder", tokenA, tokenB, amountA, amountB)
30
+ );
31
+ }
32
+
33
+ /**
34
+ * @notice Generates hash for cancelOrder operation
35
+ * @dev Hash: keccak256("cancelOrder", tokenA, tokenB, orderId). Only order owner can cancel.
36
+ * @param tokenA Token A in market pair
37
+ * @param tokenB Token B in market pair
38
+ * @param orderId Order ID to cancel
39
+ * @return Hash for Core.sol validation
40
+ */
41
+ function hashDataForCancelOrder(
42
+ address tokenA,
43
+ address tokenB,
44
+ uint256 orderId
45
+ ) internal pure returns (bytes32) {
46
+ return keccak256(abi.encode("cancelOrder", tokenA, tokenB, orderId));
47
+ }
48
+
49
+ /**
50
+ * @notice Generates hash for dispatchOrder operation
51
+ * @dev Hash: keccak256("dispatchOrder", tokenA, tokenB, orderId). Used by both fillProportionalFee and fillFixedFee.
52
+ * @param tokenA Token A in market pair
53
+ * @param tokenB Token B in market pair
54
+ * @param orderId Order ID to dispatch
55
+ * @return Hash for Core.sol validation
56
+ */
57
+ function hashDataForDispatchOrder(
58
+ address tokenA,
59
+ address tokenB,
60
+ uint256 orderId
61
+ ) internal pure returns (bytes32) {
62
+ return
63
+ keccak256(abi.encode("dispatchOrder", tokenA, tokenB, orderId));
64
+ }
65
+ }
@@ -0,0 +1,41 @@
1
+ // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
+ // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
+ pragma solidity ^0.8.0;
4
+
5
+ /**
6
+ * @title Staking Hash Utilities
7
+ * @author Mate labs
8
+ * @notice Hash functions for staking signature validation (presale/public)
9
+ * @dev Generates unique hashes with operation-specific prefixes. Used with Core.sol async nonces. Cost: 5083 PT per token.
10
+ */
11
+ library StakingHashUtils {
12
+ /**
13
+ * @notice Hashes presale staking operation parameters for signature validation
14
+ * @dev Hash: keccak256("presaleStaking", isStaking, amountOfStaking). Used with Core.sol async nonces. Max 2 tokens per user.
15
+ * @param isStaking true=stake, false=unstake
16
+ * @param amountOfStaking Number of staking tokens
17
+ * @return Hash for signature validation
18
+ */
19
+ function hashDataForPresaleStake(
20
+ bool isStaking,
21
+ uint256 amountOfStaking
22
+ ) internal pure returns (bytes32) {
23
+ return
24
+ keccak256(abi.encode("presaleStaking", isStaking, amountOfStaking));
25
+ }
26
+
27
+ /**
28
+ * @notice Hashes public staking operation parameters for signature validation
29
+ * @dev Hash: keccak256("publicStaking", isStaking, amountOfStaking). Used with Core.sol async nonces. Unlimited tokens per user.
30
+ * @param isStaking true=stake, false=unstake
31
+ * @param amountOfStaking Number of staking tokens
32
+ * @return Hash for signature validation
33
+ */
34
+ function hashDataForPublicStake(
35
+ bool isStaking,
36
+ uint256 amountOfStaking
37
+ ) internal pure returns (bytes32) {
38
+ return
39
+ keccak256(abi.encode("publicStaking", isStaking, amountOfStaking));
40
+ }
41
+ }