@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
@@ -11,105 +11,86 @@ pragma solidity ^0.8.0;
11
11
  * https://book.getfoundry.sh/cheatcodes/sign
12
12
  */
13
13
 
14
- import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
14
+ import {
15
+ CoreStructs
16
+ } from "@evvm/testnet-contracts/library/structs/CoreStructs.sol";
17
+ import {
18
+ AdvancedStrings
19
+ } from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
20
+ import {
21
+ CoreHashUtils
22
+ } from "@evvm/testnet-contracts/library/utils/signature/CoreHashUtils.sol";
23
+ import {
24
+ NameServiceHashUtils
25
+ } from "@evvm/testnet-contracts/library/utils/signature/NameServiceHashUtils.sol";
26
+ import {
27
+ P2PSwapHashUtils
28
+ } from "@evvm/testnet-contracts/library/utils/signature/P2PSwapHashUtils.sol";
29
+ import {
30
+ StakingHashUtils
31
+ } from "@evvm/testnet-contracts/library/utils/signature/StakingHashUtils.sol";
15
32
 
16
33
  library Erc191TestBuilder {
17
34
  //-----------------------------------------------------------------------------------
18
35
  // EVVM
19
36
  //-----------------------------------------------------------------------------------
20
-
21
- /**
22
- * @notice Builds the message hash for a pay operation signature
23
- * @dev Creates an EIP-191 compatible hash for EVVM pay function
24
- * @param evvmID Unique identifier of the EVVM instance
25
- * @param _receiverAddress Address of the payment receiver (use address(0) if using identity)
26
- * @param _receiverIdentity String identity of receiver (used if address is zero)
27
- * @param _token Token address being transferred
28
- * @param _amount Amount of tokens to transfer
29
- * @param _priorityFee Priority fee for transaction processing
30
- * @param _nonce Nonce for replay protection
31
- * @param _priority_boolean True for async nonce, false for sync nonce
32
- * @param _executor Address authorized to execute the transaction
33
- * @return messageHash The EIP-191 formatted hash ready for signing
34
- */
37
+
35
38
  function buildMessageSignedForPay(
36
39
  uint256 evvmID,
37
- address _receiverAddress,
38
- string memory _receiverIdentity,
39
- address _token,
40
- uint256 _amount,
41
- uint256 _priorityFee,
42
- uint256 _nonce,
43
- bool _priority_boolean,
44
- address _executor
45
- ) internal pure returns (bytes32 messageHash) {
46
- string memory messageToSign = string.concat(
47
- AdvancedStrings.uintToString(evvmID),
48
- ",",
49
- "pay",
50
- ",",
51
- _receiverAddress == address(0)
52
- ? _receiverIdentity
53
- : AdvancedStrings.addressToString(_receiverAddress),
54
- ",",
55
- AdvancedStrings.addressToString(_token),
56
- ",",
57
- AdvancedStrings.uintToString(_amount),
58
- ",",
59
- AdvancedStrings.uintToString(_priorityFee),
60
- ",",
61
- AdvancedStrings.uintToString(_nonce),
62
- ",",
63
- _priority_boolean ? "true" : "false",
64
- ",",
65
- AdvancedStrings.addressToString(_executor)
66
- );
67
- messageHash = buildHashForSign(messageToSign);
40
+ address servicePointer,
41
+ address to_address,
42
+ string memory to_identity,
43
+ address token,
44
+ uint256 amount,
45
+ uint256 priorityFee,
46
+ address senderExecutor,
47
+ uint256 nonce,
48
+ bool isAsyncExec
49
+ ) internal pure returns (bytes32) {
50
+ return
51
+ buildHashForSign(
52
+ AdvancedStrings.buildSignaturePayload(
53
+ evvmID,
54
+ servicePointer,
55
+ CoreHashUtils.hashDataForPay(
56
+ to_address,
57
+ to_identity,
58
+ token,
59
+ amount,
60
+ priorityFee
61
+ ),
62
+ senderExecutor,
63
+ nonce,
64
+ isAsyncExec
65
+ )
66
+ );
68
67
  }
69
68
 
70
- /**
71
- * @notice Builds the message hash for a disperse pay operation signature
72
- * @dev Creates an EIP-191 compatible hash for EVVM dispersePay function
73
- * @param evvmID Unique identifier of the EVVM instance
74
- * @param hashList Hash of the recipient list for batch payment
75
- * @param _token Token address being transferred
76
- * @param _amount Total amount of tokens to transfer
77
- * @param _priorityFee Priority fee for transaction processing
78
- * @param _nonce Nonce for replay protection
79
- * @param _priority_boolean True for async nonce, false for sync nonce
80
- * @param _executor Address authorized to execute the transaction
81
- * @return messageHash The EIP-191 formatted hash ready for signing
82
- */
83
69
  function buildMessageSignedForDispersePay(
84
70
  uint256 evvmID,
85
- bytes32 hashList,
86
- address _token,
87
- uint256 _amount,
88
- uint256 _priorityFee,
89
- uint256 _nonce,
90
- bool _priority_boolean,
91
- address _executor
92
- ) public pure returns (bytes32 messageHash) {
71
+ address servicePointer,
72
+ CoreStructs.DispersePayMetadata[] memory toData,
73
+ address token,
74
+ uint256 amount,
75
+ uint256 priorityFee,
76
+ address senderExecutor,
77
+ uint256 nonce,
78
+ bool isAsyncExec
79
+ ) public pure returns (bytes32) {
93
80
  return
94
81
  buildHashForSign(
95
- string.concat(
96
- AdvancedStrings.uintToString(evvmID),
97
- ",",
98
- "dispersePay",
99
- ",",
100
- AdvancedStrings.bytes32ToString(hashList),
101
- ",",
102
- AdvancedStrings.addressToString(_token),
103
- ",",
104
- AdvancedStrings.uintToString(_amount),
105
- ",",
106
- AdvancedStrings.uintToString(_priorityFee),
107
- ",",
108
- AdvancedStrings.uintToString(_nonce),
109
- ",",
110
- _priority_boolean ? "true" : "false",
111
- ",",
112
- AdvancedStrings.addressToString(_executor)
82
+ AdvancedStrings.buildSignaturePayload(
83
+ evvmID,
84
+ servicePointer,
85
+ CoreHashUtils.hashDataForDispersePay(
86
+ toData,
87
+ token,
88
+ amount,
89
+ priorityFee
90
+ ),
91
+ senderExecutor,
92
+ nonce,
93
+ isAsyncExec
113
94
  )
114
95
  );
115
96
  }
@@ -118,300 +99,232 @@ library Erc191TestBuilder {
118
99
  // MATE NAME SERVICE
119
100
  //-----------------------------------------------------------------------------------
120
101
 
121
- /**
122
- * @notice Builds the message hash for username pre-registration
123
- * @dev Creates an EIP-191 compatible hash for NameService preRegistrationUsername
124
- * @param evvmID Unique identifier of the EVVM instance
125
- * @param _hashUsername Hash of username + random number for commit-reveal
126
- * @param _nameServiceNonce Nonce for NameService replay protection
127
- * @return messageHash The EIP-191 formatted hash ready for signing
128
- */
129
102
  function buildMessageSignedForPreRegistrationUsername(
130
103
  uint256 evvmID,
131
- bytes32 _hashUsername,
132
- uint256 _nameServiceNonce
133
- ) internal pure returns (bytes32 messageHash) {
104
+ address servicePointer,
105
+ bytes32 hashPreRegisteredUsername,
106
+ address originExecutor,
107
+ uint256 nonce
108
+ ) internal pure returns (bytes32) {
134
109
  return
135
110
  buildHashForSign(
136
- string.concat(
137
- AdvancedStrings.uintToString(evvmID),
138
- ",",
139
- "preRegistrationUsername",
140
- ",",
141
- AdvancedStrings.bytes32ToString(_hashUsername),
142
- ",",
143
- AdvancedStrings.uintToString(_nameServiceNonce)
111
+ AdvancedStrings.buildSignaturePayload(
112
+ evvmID,
113
+ servicePointer,
114
+ NameServiceHashUtils.hashDataForPreRegistrationUsername(
115
+ hashPreRegisteredUsername
116
+ ),
117
+ originExecutor,
118
+ nonce,
119
+ true
144
120
  )
145
121
  );
146
122
  }
147
123
 
148
- /**
149
- * @notice Builds the message hash for username registration
150
- * @dev Creates an EIP-191 compatible hash for NameService registrationUsername
151
- * @param evvmID Unique identifier of the EVVM instance
152
- * @param _username The username being registered
153
- * @param _clowNumber Random number from pre-registration
154
- * @param _nameServiceNonce Nonce for NameService replay protection
155
- * @return messageHash The EIP-191 formatted hash ready for signing
156
- */
157
124
  function buildMessageSignedForRegistrationUsername(
158
125
  uint256 evvmID,
159
- string memory _username,
160
- uint256 _clowNumber,
161
- uint256 _nameServiceNonce
162
- ) internal pure returns (bytes32 messageHash) {
126
+ address servicePointer,
127
+ string memory username,
128
+ uint256 lockNumber,
129
+ address originExecutor,
130
+ uint256 nonce
131
+ ) internal pure returns (bytes32) {
163
132
  return
164
133
  buildHashForSign(
165
- string.concat(
166
- AdvancedStrings.uintToString(evvmID),
167
- ",",
168
- "registrationUsername",
169
- ",",
170
- _username,
171
- ",",
172
- AdvancedStrings.uintToString(_clowNumber),
173
- ",",
174
- AdvancedStrings.uintToString(_nameServiceNonce)
134
+ AdvancedStrings.buildSignaturePayload(
135
+ evvmID,
136
+ servicePointer,
137
+ NameServiceHashUtils.hashDataForRegistrationUsername(
138
+ username,
139
+ lockNumber
140
+ ),
141
+ originExecutor,
142
+ nonce,
143
+ true
175
144
  )
176
145
  );
177
146
  }
178
147
 
179
- /**
180
- * @notice Builds the message hash for making a username offer
181
- * @dev Creates an EIP-191 compatible hash for NameService makeOffer
182
- * @param evvmID Unique identifier of the EVVM instance
183
- * @param _username Target username for the offer
184
- * @param _dateExpire Timestamp when the offer expires
185
- * @param _amount Amount being offered in Principal Tokens
186
- * @param _nameServiceNonce Nonce for NameService replay protection
187
- * @return messageHash The EIP-191 formatted hash ready for signing
188
- */
189
148
  function buildMessageSignedForMakeOffer(
190
149
  uint256 evvmID,
191
- string memory _username,
192
- uint256 _dateExpire,
193
- uint256 _amount,
194
- uint256 _nameServiceNonce
195
- ) internal pure returns (bytes32 messageHash) {
150
+ address servicePointer,
151
+ string memory username,
152
+ uint256 amount,
153
+ uint256 expirationDate,
154
+ address originExecutor,
155
+ uint256 nonce
156
+ ) internal pure returns (bytes32) {
196
157
  return
197
158
  buildHashForSign(
198
- string.concat(
199
- AdvancedStrings.uintToString(evvmID),
200
- ",",
201
- "makeOffer",
202
- ",",
203
- _username,
204
- ",",
205
- AdvancedStrings.uintToString(_dateExpire),
206
- ",",
207
- AdvancedStrings.uintToString(_amount),
208
- ",",
209
- AdvancedStrings.uintToString(_nameServiceNonce)
159
+ AdvancedStrings.buildSignaturePayload(
160
+ evvmID,
161
+ servicePointer,
162
+ NameServiceHashUtils.hashDataForMakeOffer(
163
+ username,
164
+ amount,
165
+ expirationDate
166
+ ),
167
+ originExecutor,
168
+ nonce,
169
+ true
210
170
  )
211
171
  );
212
172
  }
213
173
 
214
- /**
215
- * @notice Builds the message hash for withdrawing a username offer
216
- * @dev Creates an EIP-191 compatible hash for NameService withdrawOffer
217
- * @param evvmID Unique identifier of the EVVM instance
218
- * @param _username Username the offer was made for
219
- * @param _offerId ID of the offer to withdraw
220
- * @param _nameServiceNonce Nonce for NameService replay protection
221
- * @return messageHash The EIP-191 formatted hash ready for signing
222
- */
223
174
  function buildMessageSignedForWithdrawOffer(
224
175
  uint256 evvmID,
225
- string memory _username,
226
- uint256 _offerId,
227
- uint256 _nameServiceNonce
228
- ) internal pure returns (bytes32 messageHash) {
176
+ address servicePointer,
177
+ string memory username,
178
+ uint256 offerId,
179
+ address originExecutor,
180
+ uint256 nonce
181
+ ) internal pure returns (bytes32) {
229
182
  return
230
183
  buildHashForSign(
231
- string.concat(
232
- AdvancedStrings.uintToString(evvmID),
233
- ",",
234
- "withdrawOffer",
235
- ",",
236
- _username,
237
- ",",
238
- AdvancedStrings.uintToString(_offerId),
239
- ",",
240
- AdvancedStrings.uintToString(_nameServiceNonce)
184
+ AdvancedStrings.buildSignaturePayload(
185
+ evvmID,
186
+ servicePointer,
187
+ NameServiceHashUtils.hashDataForWithdrawOffer(
188
+ username,
189
+ offerId
190
+ ),
191
+ originExecutor,
192
+ nonce,
193
+ true
241
194
  )
242
195
  );
243
196
  }
244
197
 
245
- /**
246
- * @notice Builds the message hash for accepting a username offer
247
- * @dev Creates an EIP-191 compatible hash for NameService acceptOffer
248
- * @param evvmID Unique identifier of the EVVM instance
249
- * @param _username Username being sold
250
- * @param _offerId ID of the offer to accept
251
- * @param _nameServiceNonce Nonce for NameService replay protection
252
- * @return messageHash The EIP-191 formatted hash ready for signing
253
- */
254
198
  function buildMessageSignedForAcceptOffer(
255
199
  uint256 evvmID,
256
- string memory _username,
257
- uint256 _offerId,
258
- uint256 _nameServiceNonce
259
- ) internal pure returns (bytes32 messageHash) {
200
+ address servicePointer,
201
+ string memory username,
202
+ uint256 offerId,
203
+ address originExecutor,
204
+ uint256 nonce
205
+ ) internal pure returns (bytes32) {
260
206
  return
261
207
  buildHashForSign(
262
- string.concat(
263
- AdvancedStrings.uintToString(evvmID),
264
- ",",
265
- "acceptOffer",
266
- ",",
267
- _username,
268
- ",",
269
- AdvancedStrings.uintToString(_offerId),
270
- ",",
271
- AdvancedStrings.uintToString(_nameServiceNonce)
208
+ AdvancedStrings.buildSignaturePayload(
209
+ evvmID,
210
+ servicePointer,
211
+ NameServiceHashUtils.hashDataForAcceptOffer(
212
+ username,
213
+ offerId
214
+ ),
215
+ originExecutor,
216
+ nonce,
217
+ true
272
218
  )
273
219
  );
274
220
  }
275
221
 
276
- /**
277
- * @notice Builds the message hash for renewing a username
278
- * @dev Creates an EIP-191 compatible hash for NameService renewUsername
279
- * @param evvmID Unique identifier of the EVVM instance
280
- * @param _username Username to renew
281
- * @param _nameServiceNonce Nonce for NameService replay protection
282
- * @return messageHash The EIP-191 formatted hash ready for signing
283
- */
284
222
  function buildMessageSignedForRenewUsername(
285
223
  uint256 evvmID,
286
- string memory _username,
287
- uint256 _nameServiceNonce
288
- ) internal pure returns (bytes32 messageHash) {
224
+ address servicePointer,
225
+ string memory username,
226
+ address originExecutor,
227
+ uint256 nonce
228
+ ) internal pure returns (bytes32) {
289
229
  return
290
230
  buildHashForSign(
291
- string.concat(
292
- AdvancedStrings.uintToString(evvmID),
293
- ",",
294
- "renewUsername",
295
- ",",
296
- _username,
297
- ",",
298
- AdvancedStrings.uintToString(_nameServiceNonce)
231
+ AdvancedStrings.buildSignaturePayload(
232
+ evvmID,
233
+ servicePointer,
234
+ NameServiceHashUtils.hashDataForRenewUsername(username),
235
+ originExecutor,
236
+ nonce,
237
+ true
299
238
  )
300
239
  );
301
240
  }
302
241
 
303
- /**
304
- * @notice Builds the message hash for adding custom metadata
305
- * @dev Creates an EIP-191 compatible hash for NameService addCustomMetadata
306
- * @param evvmID Unique identifier of the EVVM instance
307
- * @param _username Username to add metadata to
308
- * @param _value Metadata value following schema format
309
- * @param _nameServiceNonce Nonce for NameService replay protection
310
- * @return messageHash The EIP-191 formatted hash ready for signing
311
- */
312
242
  function buildMessageSignedForAddCustomMetadata(
313
243
  uint256 evvmID,
314
- string memory _username,
315
- string memory _value,
316
- uint256 _nameServiceNonce
317
- ) internal pure returns (bytes32 messageHash) {
244
+ address servicePointer,
245
+ string memory username,
246
+ string memory value,
247
+ address originExecutor,
248
+ uint256 nonce
249
+ ) internal pure returns (bytes32) {
318
250
  return
319
251
  buildHashForSign(
320
- string.concat(
321
- AdvancedStrings.uintToString(evvmID),
322
- ",",
323
- "addCustomMetadata",
324
- ",",
325
- _username,
326
- ",",
327
- _value,
328
- ",",
329
- AdvancedStrings.uintToString(_nameServiceNonce)
252
+ AdvancedStrings.buildSignaturePayload(
253
+ evvmID,
254
+ servicePointer,
255
+ NameServiceHashUtils.hashDataForAddCustomMetadata(
256
+ username,
257
+ value
258
+ ),
259
+ originExecutor,
260
+ nonce,
261
+ true
330
262
  )
331
263
  );
332
264
  }
333
265
 
334
- /**
335
- * @notice Builds the message hash for removing custom metadata
336
- * @dev Creates an EIP-191 compatible hash for NameService removeCustomMetadata
337
- * @param evvmID Unique identifier of the EVVM instance
338
- * @param _username Username to remove metadata from
339
- * @param _key Index of the metadata entry to remove
340
- * @param _nonce Nonce for NameService replay protection
341
- * @return messageHash The EIP-191 formatted hash ready for signing
342
- */
343
266
  function buildMessageSignedForRemoveCustomMetadata(
344
267
  uint256 evvmID,
345
- string memory _username,
346
- uint256 _key,
347
- uint256 _nonce
348
- ) internal pure returns (bytes32 messageHash) {
268
+ address servicePointer,
269
+ string memory username,
270
+ uint256 key,
271
+ address originExecutor,
272
+ uint256 nonce
273
+ ) internal pure returns (bytes32) {
349
274
  return
350
275
  buildHashForSign(
351
- string.concat(
352
- AdvancedStrings.uintToString(evvmID),
353
- ",",
354
- "removeCustomMetadata",
355
- ",",
356
- _username,
357
- ",",
358
- AdvancedStrings.uintToString(_key),
359
- ",",
360
- AdvancedStrings.uintToString(_nonce)
276
+ AdvancedStrings.buildSignaturePayload(
277
+ evvmID,
278
+ servicePointer,
279
+ NameServiceHashUtils.hashDataForRemoveCustomMetadata(
280
+ username,
281
+ key
282
+ ),
283
+ originExecutor,
284
+ nonce,
285
+ true
361
286
  )
362
287
  );
363
288
  }
364
289
 
365
- /**
366
- * @notice Builds the message hash for flushing all custom metadata
367
- * @dev Creates an EIP-191 compatible hash for NameService flushCustomMetadata
368
- * @param evvmID Unique identifier of the EVVM instance
369
- * @param _username Username to flush metadata from
370
- * @param _nonce Nonce for NameService replay protection
371
- * @return messageHash The EIP-191 formatted hash ready for signing
372
- */
373
290
  function buildMessageSignedForFlushCustomMetadata(
374
291
  uint256 evvmID,
375
- string memory _username,
376
- uint256 _nonce
377
- ) internal pure returns (bytes32 messageHash) {
292
+ address servicePointer,
293
+ string memory username,
294
+ address originExecutor,
295
+ uint256 nonce
296
+ ) internal pure returns (bytes32) {
378
297
  return
379
298
  buildHashForSign(
380
- string.concat(
381
- AdvancedStrings.uintToString(evvmID),
382
- ",",
383
- "flushCustomMetadata",
384
- ",",
385
- _username,
386
- ",",
387
- AdvancedStrings.uintToString(_nonce)
299
+ AdvancedStrings.buildSignaturePayload(
300
+ evvmID,
301
+ servicePointer,
302
+ NameServiceHashUtils.hashDataForFlushCustomMetadata(
303
+ username
304
+ ),
305
+ originExecutor,
306
+ nonce,
307
+ true
388
308
  )
389
309
  );
390
310
  }
391
311
 
392
- /**
393
- * @notice Builds the message hash for flushing a username
394
- * @dev Creates an EIP-191 compatible hash for NameService flushUsername
395
- * @param evvmID Unique identifier of the EVVM instance
396
- * @param _username Username to completely remove
397
- * @param _nonce Nonce for NameService replay protection
398
- * @return messageHash The EIP-191 formatted hash ready for signing
399
- */
400
312
  function buildMessageSignedForFlushUsername(
401
313
  uint256 evvmID,
402
- string memory _username,
403
- uint256 _nonce
404
- ) internal pure returns (bytes32 messageHash) {
314
+ address servicePointer,
315
+ string memory username,
316
+ address originExecutor,
317
+ uint256 nonce
318
+ ) internal pure returns (bytes32) {
405
319
  return
406
320
  buildHashForSign(
407
- string.concat(
408
- AdvancedStrings.uintToString(evvmID),
409
- ",",
410
- "flushUsername",
411
- ",",
412
- _username,
413
- ",",
414
- AdvancedStrings.uintToString(_nonce)
321
+ AdvancedStrings.buildSignaturePayload(
322
+ evvmID,
323
+ servicePointer,
324
+ NameServiceHashUtils.hashDataForFlushUsername(username),
325
+ originExecutor,
326
+ nonce,
327
+ true
415
328
  )
416
329
  );
417
330
  }
@@ -420,99 +333,50 @@ library Erc191TestBuilder {
420
333
  // staking functions
421
334
  //-----------------------------------------------------------------------------------
422
335
 
423
- /**
424
- * @notice Builds the message hash for public service staking
425
- * @dev Creates an EIP-191 compatible hash for Staking publicServiceStaking
426
- * @param evvmID Unique identifier of the EVVM instance
427
- * @param _serviceAddress Address of the service to stake for
428
- * @param _isStaking True for staking, false for unstaking
429
- * @param _amountOfStaking Amount of staking units
430
- * @param _nonce Nonce for replay protection
431
- * @return messageHash The EIP-191 formatted hash ready for signing
432
- */
433
- function buildMessageSignedForPublicServiceStake(
336
+ function buildMessageSignedForPresaleStaking(
434
337
  uint256 evvmID,
435
- address _serviceAddress,
436
- bool _isStaking,
437
- uint256 _amountOfStaking,
438
- uint256 _nonce
439
- ) internal pure returns (bytes32 messageHash) {
338
+ address servicePointer,
339
+ bool isStaking,
340
+ uint256 amountOfStaking,
341
+ address originExecutor,
342
+ uint256 nonce
343
+ ) internal pure returns (bytes32) {
440
344
  return
441
345
  buildHashForSign(
442
- string.concat(
443
- AdvancedStrings.uintToString(evvmID),
444
- ",",
445
- "publicServiceStaking",
446
- ",",
447
- AdvancedStrings.addressToString(_serviceAddress),
448
- ",",
449
- _isStaking ? "true" : "false",
450
- ",",
451
- AdvancedStrings.uintToString(_amountOfStaking),
452
- ",",
453
- AdvancedStrings.uintToString(_nonce)
346
+ AdvancedStrings.buildSignaturePayload(
347
+ evvmID,
348
+ servicePointer,
349
+ StakingHashUtils.hashDataForPresaleStake(
350
+ isStaking,
351
+ amountOfStaking
352
+ ),
353
+ originExecutor,
354
+ nonce,
355
+ true
454
356
  )
455
357
  );
456
358
  }
457
359
 
458
- /**
459
- * @notice Builds the message hash for public staking
460
- * @dev Creates an EIP-191 compatible hash for Staking publicStaking
461
- * @param evvmID Unique identifier of the EVVM instance
462
- * @param _isStaking True for staking, false for unstaking
463
- * @param _amountOfStaking Amount of staking units
464
- * @param _nonce Nonce for replay protection
465
- * @return messageHash The EIP-191 formatted hash ready for signing
466
- */
467
360
  function buildMessageSignedForPublicStaking(
468
361
  uint256 evvmID,
469
- bool _isStaking,
470
- uint256 _amountOfStaking,
471
- uint256 _nonce
472
- ) internal pure returns (bytes32 messageHash) {
473
- return
474
- buildHashForSign(
475
- string.concat(
476
- AdvancedStrings.uintToString(evvmID),
477
- ",",
478
- "publicStaking",
479
- ",",
480
- _isStaking ? "true" : "false",
481
- ",",
482
- AdvancedStrings.uintToString(_amountOfStaking),
483
- ",",
484
- AdvancedStrings.uintToString(_nonce)
485
- )
486
- );
487
- }
488
-
489
- /**
490
- * @notice Builds the message hash for presale staking
491
- * @dev Creates an EIP-191 compatible hash for Staking presaleStaking
492
- * @param evvmID Unique identifier of the EVVM instance
493
- * @param _isStaking True for staking, false for unstaking
494
- * @param _amountOfStaking Amount of staking units
495
- * @param _nonce Nonce for replay protection
496
- * @return messageHash The EIP-191 formatted hash ready for signing
497
- */
498
- function buildMessageSignedForPresaleStaking(
499
- uint256 evvmID,
500
- bool _isStaking,
501
- uint256 _amountOfStaking,
502
- uint256 _nonce
503
- ) internal pure returns (bytes32 messageHash) {
362
+ address servicePointer,
363
+ bool isStaking,
364
+ uint256 amountOfStaking,
365
+ address originExecutor,
366
+ uint256 nonce
367
+ ) internal pure returns (bytes32) {
504
368
  return
505
369
  buildHashForSign(
506
- string.concat(
507
- AdvancedStrings.uintToString(evvmID),
508
- ",",
509
- "presaleStaking",
510
- ",",
511
- _isStaking ? "true" : "false",
512
- ",",
513
- AdvancedStrings.uintToString(_amountOfStaking),
514
- ",",
515
- AdvancedStrings.uintToString(_nonce)
370
+ AdvancedStrings.buildSignaturePayload(
371
+ evvmID,
372
+ servicePointer,
373
+ StakingHashUtils.hashDataForPublicStake(
374
+ isStaking,
375
+ amountOfStaking
376
+ ),
377
+ originExecutor,
378
+ nonce,
379
+ true
516
380
  )
517
381
  );
518
382
  }
@@ -521,111 +385,112 @@ library Erc191TestBuilder {
521
385
  // P2PSwap functions
522
386
  //-----------------------------------------------------------------------------------
523
387
 
524
- /**
525
- * @notice Builds the message hash for making a P2P swap order
526
- * @dev Creates an EIP-191 compatible hash for P2PSwap makeOrder
527
- * @param evvmID Unique identifier of the EVVM instance
528
- * @param _nonce Nonce for replay protection
529
- * @param _tokenA Token address being offered
530
- * @param _tokenB Token address being requested
531
- * @param _amountA Amount of tokenA being offered
532
- * @param _amountB Amount of tokenB being requested
533
- * @return messageHash The EIP-191 formatted hash ready for signing
534
- */
535
388
  function buildMessageSignedForMakeOrder(
536
389
  uint256 evvmID,
537
- uint256 _nonce,
538
- address _tokenA,
539
- address _tokenB,
540
- uint256 _amountA,
541
- uint256 _amountB
542
- ) internal pure returns (bytes32 messageHash) {
390
+ address servicePointer,
391
+ address originExecutor,
392
+ uint256 nonce,
393
+ address tokenA,
394
+ address tokenB,
395
+ uint256 amountA,
396
+ uint256 amountB
397
+ ) internal pure returns (bytes32) {
543
398
  return
544
399
  buildHashForSign(
545
- string.concat(
546
- AdvancedStrings.uintToString(evvmID),
547
- ",",
548
- "makeOrder",
549
- ",",
550
- AdvancedStrings.uintToString(_nonce),
551
- ",",
552
- AdvancedStrings.addressToString(_tokenA),
553
- ",",
554
- AdvancedStrings.addressToString(_tokenB),
555
- ",",
556
- AdvancedStrings.uintToString(_amountA),
557
- ",",
558
- AdvancedStrings.uintToString(_amountB)
400
+ AdvancedStrings.buildSignaturePayload(
401
+ evvmID,
402
+ servicePointer,
403
+ P2PSwapHashUtils.hashDataForMakeOrder(
404
+ tokenA,
405
+ tokenB,
406
+ amountA,
407
+ amountB
408
+ ),
409
+ originExecutor,
410
+ nonce,
411
+ true
559
412
  )
560
413
  );
561
414
  }
562
415
 
563
- /**
564
- * @notice Builds the message hash for canceling a P2P swap order
565
- * @dev Creates an EIP-191 compatible hash for P2PSwap cancelOrder
566
- * @param evvmID Unique identifier of the EVVM instance
567
- * @param _nonce Nonce for replay protection
568
- * @param _tokenA Token address that was offered
569
- * @param _tokenB Token address that was requested
570
- * @param _orderId ID of the order to cancel
571
- * @return messageHash The EIP-191 formatted hash ready for signing
572
- */
573
416
  function buildMessageSignedForCancelOrder(
574
417
  uint256 evvmID,
575
- uint256 _nonce,
576
- address _tokenA,
577
- address _tokenB,
578
- uint256 _orderId
579
- ) internal pure returns (bytes32 messageHash) {
418
+ address servicePointer,
419
+ address originExecutor,
420
+ uint256 nonce,
421
+ address tokenA,
422
+ address tokenB,
423
+ uint256 orderId
424
+ ) internal pure returns (bytes32) {
580
425
  return
581
426
  buildHashForSign(
582
- string.concat(
583
- AdvancedStrings.uintToString(evvmID),
584
- ",",
585
- "cancelOrder",
586
- ",",
587
- AdvancedStrings.uintToString(_nonce),
588
- ",",
589
- AdvancedStrings.addressToString(_tokenA),
590
- ",",
591
- AdvancedStrings.addressToString(_tokenB),
592
- ",",
593
- AdvancedStrings.uintToString(_orderId)
427
+ AdvancedStrings.buildSignaturePayload(
428
+ evvmID,
429
+ servicePointer,
430
+ P2PSwapHashUtils.hashDataForCancelOrder(
431
+ tokenA,
432
+ tokenB,
433
+ orderId
434
+ ),
435
+ originExecutor,
436
+ nonce,
437
+ true
594
438
  )
595
439
  );
596
440
  }
597
441
 
598
- /**
599
- * @notice Builds the message hash for dispatching (accepting) a P2P swap order
600
- * @dev Creates an EIP-191 compatible hash for P2PSwap dispatchOrder
601
- * @param evvmID Unique identifier of the EVVM instance
602
- * @param _nonce Nonce for replay protection
603
- * @param _tokenA Token address that was offered
604
- * @param _tokenB Token address that was requested
605
- * @param _orderId ID of the order to dispatch
606
- * @return messageHash The EIP-191 formatted hash ready for signing
607
- */
608
442
  function buildMessageSignedForDispatchOrder(
609
443
  uint256 evvmID,
610
- uint256 _nonce,
611
- address _tokenA,
612
- address _tokenB,
613
- uint256 _orderId
614
- ) internal pure returns (bytes32 messageHash) {
444
+ address servicePointer,
445
+ address originExecutor,
446
+ uint256 nonce,
447
+ address tokenA,
448
+ address tokenB,
449
+ uint256 orderId
450
+ ) internal pure returns (bytes32) {
451
+ return
452
+ buildHashForSign(
453
+ AdvancedStrings.buildSignaturePayload(
454
+ evvmID,
455
+ servicePointer,
456
+ P2PSwapHashUtils.hashDataForDispatchOrder(
457
+ tokenA,
458
+ tokenB,
459
+ orderId
460
+ ),
461
+ originExecutor,
462
+ nonce,
463
+ true
464
+ )
465
+ );
466
+ }
467
+
468
+ //-----------------------------------------------------------------------------------
469
+ // nonceConsumer functions
470
+ //-----------------------------------------------------------------------------------
471
+
472
+ function buildMessageSignedForStateTest(
473
+ uint256 evvmID,
474
+ address servicePointer,
475
+ string memory testA,
476
+ uint256 testB,
477
+ address testC,
478
+ bool testD,
479
+ address originExecutor,
480
+ uint256 nonce,
481
+ bool isAsyncExec
482
+ ) internal pure returns (bytes32) {
615
483
  return
616
484
  buildHashForSign(
617
- string.concat(
618
- AdvancedStrings.uintToString(evvmID),
619
- ",",
620
- "dispatchOrder",
621
- ",",
622
- AdvancedStrings.uintToString(_nonce),
623
- ",",
624
- AdvancedStrings.addressToString(_tokenA),
625
- ",",
626
- AdvancedStrings.addressToString(_tokenB),
627
- ",",
628
- AdvancedStrings.uintToString(_orderId)
485
+ AdvancedStrings.buildSignaturePayload(
486
+ evvmID,
487
+ servicePointer,
488
+ keccak256(
489
+ abi.encode("StateTest", testA, testB, testC, testD)
490
+ ),
491
+ originExecutor,
492
+ nonce,
493
+ isAsyncExec
629
494
  )
630
495
  );
631
496
  }