@evvm/testnet-contracts 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +355 -55
  3. package/contracts/evvm/Evvm.sol +28 -31
  4. package/contracts/evvm/lib/ErrorsLib.sol +2 -1
  5. package/contracts/evvm/lib/EvvmStructs.sol +27 -1
  6. package/contracts/evvm/lib/SignatureUtils.sol +2 -5
  7. package/contracts/nameService/NameService.sol +118 -363
  8. package/contracts/nameService/lib/ErrorsLib.sol +1 -7
  9. package/contracts/nameService/lib/IdentityValidation.sol +182 -0
  10. package/contracts/nameService/lib/NameServiceStructs.sol +69 -0
  11. package/contracts/nameService/lib/SignatureUtils.sol +11 -4
  12. package/contracts/p2pSwap/P2PSwap.sol +41 -154
  13. package/contracts/p2pSwap/lib/P2PSwapStructs.sol +59 -0
  14. package/contracts/p2pSwap/lib/SignatureUtils.sol +1 -2
  15. package/contracts/staking/Estimator.sol +7 -6
  16. package/contracts/staking/Staking.sol +46 -146
  17. package/contracts/staking/lib/SignatureUtils.sol +1 -2
  18. package/contracts/staking/lib/StakingStructs.sol +94 -0
  19. package/contracts/treasury/Treasury.sol +18 -20
  20. package/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +88 -35
  21. package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +81 -47
  22. package/contracts/treasuryTwoChains/lib/ErrorsLib.sol +2 -0
  23. package/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +3 -14
  24. package/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +3 -7
  25. package/contracts/treasuryTwoChains/lib/SignatureUtils.sol +5 -7
  26. package/interfaces/IEstimator.sol +7 -50
  27. package/interfaces/IEvvm.sol +17 -91
  28. package/interfaces/INameService.sol +37 -88
  29. package/interfaces/IP2PSwap.sol +19 -15
  30. package/interfaces/IStaking.sol +20 -50
  31. package/interfaces/ITreasury.sol +1 -4
  32. package/interfaces/ITreasuryExternalChainStation.sol +11 -15
  33. package/interfaces/ITreasuryHostChainStation.sol +7 -10
  34. package/library/Erc191TestBuilder.sol +0 -1
  35. package/library/EvvmService.sol +14 -78
  36. package/library/primitives/IERC20.sol +79 -0
  37. package/library/utils/GovernanceUtils.sol +81 -0
  38. package/library/utils/{service/AsyncNonceService.sol → nonces/AsyncNonce.sol} +9 -11
  39. package/library/utils/nonces/SyncNonce.sol +27 -0
  40. package/library/utils/service/EvvmPayments.sol +77 -0
  41. package/library/utils/service/StakingServiceUtils.sol +15 -20
  42. package/package.json +11 -13
  43. package/library/utils/service/MakeServicePaymentOnEvvm.sol +0 -49
  44. package/library/utils/service/SyncNonceService.sol +0 -18
@@ -8,13 +8,7 @@ library ErrorsLib {
8
8
  error UserIsNotOwnerOfIdentity();
9
9
  error NonceAlreadyUsed();
10
10
  error InvalidSignatureOnNameService();
11
- /**
12
- * @dev Error thrown when a username is not valid.
13
- * 0x01 - Username is too short.
14
- * 0x02 - Username does not start with a letter.
15
- * 0x03 - Username contains invalid characters.
16
- */
17
- error InvalidUsername(bytes1);
11
+ error InvalidUsername();
18
12
  error UsernameAlreadyRegistered();
19
13
  error PreRegistrationNotValid();
20
14
  error MakeOfferVerificationFailed();
@@ -0,0 +1,182 @@
1
+ // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
+ // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
+
4
+ pragma solidity ^0.8.0;
5
+
6
+ library IdentityValidation{
7
+ /**
8
+ * @notice Validates username format according to system rules
9
+ * @dev Username must be at least 4 characters, start with a letter, and contain only letters/digits
10
+ * @param username The username string to validate
11
+ */
12
+ function isValidUsername(string memory username) internal pure returns (bool) {
13
+ bytes memory usernameBytes = bytes(username);
14
+
15
+ // Check if username length is at least 4 characters
16
+ if (usernameBytes.length < 4) return false;
17
+
18
+ // Check if username begins with a letter
19
+ if (!_isLetter(usernameBytes[0]))
20
+ return false;
21
+
22
+
23
+ // Iterate through each character in the username
24
+ for (uint256 i = 0; i < usernameBytes.length; i++) {
25
+ // Check if character is not a digit or letter
26
+ if (!_isDigit(usernameBytes[i]) && !_isLetter(usernameBytes[i])) {
27
+ return false;
28
+
29
+ }
30
+ }
31
+ return true;
32
+ }
33
+
34
+ /**
35
+ * @notice Validates phone number format
36
+ * @dev Phone number must be 6-19 digits only
37
+ * @param _phoneNumber The phone number string to validate
38
+ * @return True if valid phone number format
39
+ */
40
+ function isValidPhoneNumberNumber(
41
+ string memory _phoneNumber
42
+ ) internal pure returns (bool) {
43
+ bytes memory _telephoneNumberBytes = bytes(_phoneNumber);
44
+ if (
45
+ _telephoneNumberBytes.length < 20 &&
46
+ _telephoneNumberBytes.length > 5
47
+ ) {
48
+ return false;
49
+ }
50
+ for (uint256 i = 0; i < _telephoneNumberBytes.length; i++) {
51
+ if (!_isDigit(_telephoneNumberBytes[i])) {
52
+ return false;
53
+ }
54
+ }
55
+ return true;
56
+ }
57
+
58
+ /**
59
+ * @notice Validates email address format
60
+ * @dev Checks for proper email structure: prefix(3+ chars) + @ + domain(3+ chars) + . + TLD(2+ chars)
61
+ * @param _email The email address string to validate
62
+ * @return True if valid email format
63
+ */
64
+ function isValidEmail(string memory _email) internal pure returns (bool) {
65
+ bytes memory _emailBytes = bytes(_email);
66
+ uint256 lengthCount = 0;
67
+ bytes1 flagVerify = 0x00;
68
+ for (uint point = 0; point < _emailBytes.length; point++) {
69
+ //step 1 0x00 prefix
70
+ if (flagVerify == 0x00) {
71
+ if (_isOnlyEmailPrefixCharacters(_emailBytes[point])) {
72
+ lengthCount++;
73
+ } else {
74
+ if (_isAAt(_emailBytes[point])) {
75
+ flagVerify = 0x01;
76
+ } else {
77
+ return false;
78
+ }
79
+ }
80
+ }
81
+
82
+ //step 2 0x01 count the prefix length
83
+ if (flagVerify == 0x01) {
84
+ if (lengthCount < 3) {
85
+ return false;
86
+ } else {
87
+ flagVerify = 0x02;
88
+ lengthCount = 0;
89
+ point++;
90
+ }
91
+ }
92
+
93
+ //step 3 0x02 domain name
94
+ if (flagVerify == 0x02) {
95
+ if (_isLetter(_emailBytes[point])) {
96
+ lengthCount++;
97
+ } else {
98
+ if (_isAPoint(_emailBytes[point])) {
99
+ flagVerify = 0x03;
100
+ } else {
101
+ return false;
102
+ }
103
+ }
104
+ }
105
+
106
+ //step 4 0x03 count the domain name length
107
+ if (flagVerify == 0x03) {
108
+ if (lengthCount < 3) {
109
+ return false;
110
+ } else {
111
+ flagVerify = 0x04;
112
+ lengthCount = 0;
113
+ point++;
114
+ }
115
+ }
116
+
117
+ //step 5 0x04 top level domain
118
+ if (flagVerify == 0x04) {
119
+ if (_isLetter(_emailBytes[point])) {
120
+ lengthCount++;
121
+ } else {
122
+ if (_isAPoint(_emailBytes[point])) {
123
+ if (lengthCount < 2) {
124
+ return false;
125
+ } else {
126
+ lengthCount = 0;
127
+ }
128
+ } else {
129
+ return false;
130
+ }
131
+ }
132
+ }
133
+ }
134
+
135
+ if (flagVerify != 0x04) {
136
+ return false;
137
+ }
138
+
139
+ return true;
140
+ }
141
+
142
+ /// @dev Checks if a byte represents a digit (0-9)
143
+ function _isDigit(bytes1 character) private pure returns (bool) {
144
+ return (character >= 0x30 && character <= 0x39); // ASCII range for digits 0-9
145
+ }
146
+
147
+ /// @dev Checks if a byte represents a letter (A-Z or a-z)
148
+ function _isLetter(bytes1 character) private pure returns (bool) {
149
+ return ((character >= 0x41 && character <= 0x5A) ||
150
+ (character >= 0x61 && character <= 0x7A)); // ASCII ranges for letters A-Z and a-z
151
+ }
152
+
153
+ /// @dev Checks if a byte represents any symbol character
154
+ function _isAnySimbol(bytes1 character) private pure returns (bool) {
155
+ return ((character >= 0x21 && character <= 0x2F) || /// @dev includes characters from "!" to "/"
156
+ (character >= 0x3A && character <= 0x40) || /// @dev includes characters from ":" to "@"
157
+ (character >= 0x5B && character <= 0x60) || /// @dev includes characters from "[" to "`"
158
+ (character >= 0x7B && character <= 0x7E)); /// @dev includes characters from "{" to "~"
159
+ }
160
+
161
+ /// @dev Checks if a byte is valid for email prefix (letters, digits, and specific symbols)
162
+ function _isOnlyEmailPrefixCharacters(
163
+ bytes1 character
164
+ ) private pure returns (bool) {
165
+ return (_isLetter(character) ||
166
+ _isDigit(character) ||
167
+ (character >= 0x21 && character <= 0x2F) || /// @dev includes characters from "!" to "/"
168
+ (character >= 0x3A && character <= 0x3F) || /// @dev includes characters from ":" to "?"
169
+ (character >= 0x5B && character <= 0x60) || /// @dev includes characters from "[" to "`"
170
+ (character >= 0x7B && character <= 0x7E)); /// @dev includes characters from "{" to "~"
171
+ }
172
+
173
+ /// @dev Checks if a byte represents a period/dot character (.)
174
+ function _isAPoint(bytes1 character) private pure returns (bool) {
175
+ return character == 0x2E;
176
+ }
177
+
178
+ /// @dev Checks if a byte represents an at symbol (@)
179
+ function _isAAt(bytes1 character) private pure returns (bool) {
180
+ return character == 0x40;
181
+ }
182
+ }
@@ -0,0 +1,69 @@
1
+ // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
+ // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
+
4
+ pragma solidity ^0.8.0;
5
+
6
+ abstract contract NameServiceStructs {
7
+ /**
8
+ * @dev Struct for managing address change proposals with time delay
9
+ * @param current Currently active address
10
+ * @param proposal Proposed new address waiting for approval
11
+ * @param timeToAccept Timestamp when the proposal can be accepted
12
+ */
13
+ struct AddressTypeProposal {
14
+ address current;
15
+ address proposal;
16
+ uint256 timeToAccept;
17
+ }
18
+
19
+ /**
20
+ * @dev Struct for managing uint256 value proposals with time delay
21
+ * @param current Currently active value
22
+ * @param proposal Proposed new value waiting for approval
23
+ * @param timeToAccept Timestamp when the proposal can be accepted
24
+ */
25
+ struct UintTypeProposal {
26
+ uint256 current;
27
+ uint256 proposal;
28
+ uint256 timeToAccept;
29
+ }
30
+
31
+ /**
32
+ * @dev Struct for managing boolean flag changes with time delay
33
+ * @param flag Current boolean state
34
+ * @param timeToAcceptChange Timestamp when the flag change can be executed
35
+ */
36
+ struct BoolTypeProposal {
37
+ bool flag;
38
+ uint256 timeToAcceptChange;
39
+ }
40
+
41
+ /**
42
+ * @dev Core metadata for each registered identity/username
43
+ * @param owner Address that owns this identity
44
+ * @param expireDate Timestamp when the registration expires
45
+ * @param customMetadataMaxSlots Number of custom metadata entries stored
46
+ * @param offerMaxSlots Maximum number of offers that have been made
47
+ * @param flagNotAUsername Flag indicating if this is a pre-registration (0x01) or actual username (0x00)
48
+ */
49
+ struct IdentityBaseMetadata {
50
+ address owner;
51
+ uint256 expireDate;
52
+ uint256 customMetadataMaxSlots;
53
+ uint256 offerMaxSlots;
54
+ bytes1 flagNotAUsername;
55
+ }
56
+
57
+
58
+ /**
59
+ * @dev Metadata for marketplace offers on usernames
60
+ * @param offerer Address making the offer
61
+ * @param expireDate Timestamp when the offer expires
62
+ * @param amount Amount offered in Principal Tokens (after 0.5% marketplace fee deduction)
63
+ */
64
+ struct OfferMetadata {
65
+ address offerer;
66
+ uint256 expireDate;
67
+ uint256 amount;
68
+ }
69
+ }
@@ -1,11 +1,10 @@
1
1
  // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
2
  // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
+ pragma solidity ^0.8.0;
3
4
 
4
5
  import {SignatureUtil} from "@evvm/testnet-contracts/library/utils/SignatureUtil.sol";
5
6
  import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
6
7
 
7
- pragma solidity ^0.8.0;
8
-
9
8
  library SignatureUtils {
10
9
  /**
11
10
  * @dev using EIP-191 (https://eips.ethereum.org/EIPS/eip-191) can be used to sign and
@@ -213,7 +212,11 @@ library SignatureUtils {
213
212
  SignatureUtil.verifySignature(
214
213
  evvmID,
215
214
  "flushCustomMetadata",
216
- string.concat(_identity, ",", AdvancedStrings.uintToString(_nonce)),
215
+ string.concat(
216
+ _identity,
217
+ ",",
218
+ AdvancedStrings.uintToString(_nonce)
219
+ ),
217
220
  signature,
218
221
  signer
219
222
  );
@@ -230,7 +233,11 @@ library SignatureUtils {
230
233
  SignatureUtil.verifySignature(
231
234
  evvmID,
232
235
  "flushUsername",
233
- string.concat(_username, ",", AdvancedStrings.uintToString(_nonce)),
236
+ string.concat(
237
+ _username,
238
+ ",",
239
+ AdvancedStrings.uintToString(_nonce)
240
+ ),
234
241
  signature,
235
242
  signer
236
243
  );
@@ -36,77 +36,25 @@ pragma solidity ^0.8.0;
36
36
  * - Staker Rewards: 10% (configurable)
37
37
  */
38
38
 
39
- import {Evvm} from "@evvm/testnet-contracts/contracts/evvm/Evvm.sol";
40
39
  import {Staking} from "@evvm/testnet-contracts/contracts/staking/Staking.sol";
41
- import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
42
- import {EvvmStructs} from "@evvm/testnet-contracts/contracts/evvm/lib/EvvmStructs.sol";
43
- import {StakingServiceUtils} from "@evvm/testnet-contracts/library/utils/service/StakingServiceUtils.sol";
44
40
  import {SignatureUtils} from "@evvm/testnet-contracts/contracts/p2pSwap/lib/SignatureUtils.sol";
45
-
46
- contract P2PSwap is StakingServiceUtils {
41
+ import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
42
+ import {P2PSwapStructs} from "@evvm/testnet-contracts/contracts/p2pSwap/lib/P2PSwapStructs.sol";
43
+ import {EvvmStructs} from "@evvm/testnet-contracts/interfaces/IEvvm.sol";
44
+ import {EvvmService} from "@evvm/testnet-contracts/library/EvvmService.sol";
45
+
46
+ contract P2PSwap is
47
+ EvvmService,
48
+ P2PSwapStructs
49
+ {
47
50
  address owner;
48
51
  address owner_proposal;
49
52
  uint256 owner_timeToAccept;
50
53
 
51
- address evvmAddress;
52
- address stakingAddress;
53
-
54
54
  address constant MATE_TOKEN_ADDRESS =
55
55
  0x0000000000000000000000000000000000000001;
56
56
  address constant ETH_ADDRESS = 0x0000000000000000000000000000000000000000;
57
57
 
58
- struct MarketInformation {
59
- address tokenA;
60
- address tokenB;
61
- uint256 maxSlot;
62
- uint256 ordersAvailable;
63
- }
64
-
65
- struct Order {
66
- address seller;
67
- uint256 amountA;
68
- uint256 amountB;
69
- }
70
-
71
- struct OrderForGetter {
72
- uint256 marketId;
73
- uint256 orderId;
74
- address seller;
75
- uint256 amountA;
76
- uint256 amountB;
77
- }
78
-
79
- struct Percentage {
80
- uint256 seller;
81
- uint256 service;
82
- uint256 mateStaker;
83
- }
84
-
85
- struct MetadataMakeOrder {
86
- uint256 nonce;
87
- address tokenA;
88
- address tokenB;
89
- uint256 amountA;
90
- uint256 amountB;
91
- }
92
-
93
- struct MetadataCancelOrder {
94
- uint256 nonce;
95
- address tokenA;
96
- address tokenB;
97
- uint256 orderId;
98
- bytes signature;
99
- }
100
-
101
- struct MetadataDispatchOrder {
102
- uint256 nonce;
103
- address tokenA;
104
- address tokenB;
105
- uint256 orderId;
106
- uint256 amountOfTokenBToFill;
107
- bytes signature;
108
- }
109
-
110
58
  Percentage rewardPercentage;
111
59
  Percentage rewardPercentage_proposal;
112
60
  uint256 rewardPercentage_timeToAcceptNewChange;
@@ -126,8 +74,6 @@ contract P2PSwap is StakingServiceUtils {
126
74
 
127
75
  uint256 marketCount;
128
76
 
129
- mapping(address user => mapping(uint256 nonce => bool isUsed)) nonceP2PSwap;
130
-
131
77
  mapping(address tokenA => mapping(address tokenB => uint256 id)) marketId;
132
78
 
133
79
  mapping(uint256 id => MarketInformation info) marketMetadata;
@@ -140,8 +86,9 @@ contract P2PSwap is StakingServiceUtils {
140
86
  address _evvmAddress,
141
87
  address _stakingAddress,
142
88
  address _owner
143
- ) StakingServiceUtils(_stakingAddress) {
144
- evvmAddress = _evvmAddress;
89
+ )
90
+ EvvmService(_evvmAddress, _stakingAddress)
91
+ {
145
92
  owner = _owner;
146
93
  maxLimitFillFixedFee = 0.001 ether;
147
94
  percentageFee = 500;
@@ -150,7 +97,6 @@ contract P2PSwap is StakingServiceUtils {
150
97
  service: 4000,
151
98
  mateStaker: 1000
152
99
  });
153
- stakingAddress = _stakingAddress;
154
100
  }
155
101
 
156
102
  function makeOrder(
@@ -164,7 +110,7 @@ contract P2PSwap is StakingServiceUtils {
164
110
  ) external returns (uint256 market, uint256 orderId) {
165
111
  if (
166
112
  !SignatureUtils.verifyMessageSignedForMakeOrder(
167
- Evvm(evvmAddress).getEvvmID(),
113
+ evvm.getEvvmID(),
168
114
  user,
169
115
  metadata.nonce,
170
116
  metadata.tokenA,
@@ -177,11 +123,9 @@ contract P2PSwap is StakingServiceUtils {
177
123
  revert("Invalid signature");
178
124
  }
179
125
 
180
- if (nonceP2PSwap[user][metadata.nonce]) {
181
- revert("Nonce already used");
182
- }
126
+ verifyAsyncNonce(user, metadata.nonce);
183
127
 
184
- makePay(
128
+ requestPay(
185
129
  user,
186
130
  metadata.tokenA,
187
131
  _nonce_Evvm,
@@ -219,7 +163,7 @@ contract P2PSwap is StakingServiceUtils {
219
163
  metadata.amountB
220
164
  );
221
165
 
222
- if (Evvm(evvmAddress).isAddressStaker(msg.sender)) {
166
+ if (evvm.isAddressStaker(msg.sender)) {
223
167
  if (_priorityFee_Evvm > 0) {
224
168
  // send the executor the priorityFee
225
169
  makeCaPay(msg.sender, metadata.tokenA, _priorityFee_Evvm);
@@ -230,12 +174,12 @@ contract P2PSwap is StakingServiceUtils {
230
174
  msg.sender,
231
175
  MATE_TOKEN_ADDRESS,
232
176
  _priorityFee_Evvm > 0
233
- ? (Evvm(evvmAddress).getRewardAmount() * 3)
234
- : (Evvm(evvmAddress).getRewardAmount() * 2)
177
+ ? (evvm.getRewardAmount() * 3)
178
+ : (evvm.getRewardAmount() * 2)
235
179
  );
236
180
  }
237
181
 
238
- nonceP2PSwap[user][metadata.nonce] = true;
182
+ markAsyncNonceAsUsed(user, metadata.nonce);
239
183
  }
240
184
 
241
185
  function cancelOrder(
@@ -248,7 +192,7 @@ contract P2PSwap is StakingServiceUtils {
248
192
  ) external {
249
193
  if (
250
194
  !SignatureUtils.verifyMessageSignedForCancelOrder(
251
- Evvm(evvmAddress).getEvvmID(),
195
+ evvm.getEvvmID(),
252
196
  user,
253
197
  metadata.nonce,
254
198
  metadata.tokenA,
@@ -262,9 +206,7 @@ contract P2PSwap is StakingServiceUtils {
262
206
 
263
207
  uint256 market = findMarket(metadata.tokenA, metadata.tokenB);
264
208
 
265
- if (nonceP2PSwap[user][metadata.nonce]) {
266
- revert("Invalid nonce");
267
- }
209
+ verifyAsyncNonce(user, metadata.nonce);
268
210
 
269
211
  if (
270
212
  market == 0 ||
@@ -274,7 +216,7 @@ contract P2PSwap is StakingServiceUtils {
274
216
  }
275
217
 
276
218
  if (_priorityFee_Evvm > 0) {
277
- makePay(
219
+ requestPay(
278
220
  user,
279
221
  MATE_TOKEN_ADDRESS,
280
222
  _nonce_Evvm,
@@ -293,18 +235,17 @@ contract P2PSwap is StakingServiceUtils {
293
235
 
294
236
  ordersInsideMarket[market][metadata.orderId].seller = address(0);
295
237
 
296
- if (Evvm(evvmAddress).isAddressStaker(msg.sender)) {
238
+ if (evvm.isAddressStaker(msg.sender)) {
297
239
  makeCaPay(
298
240
  msg.sender,
299
241
  MATE_TOKEN_ADDRESS,
300
242
  _priorityFee_Evvm > 0
301
- ? ((Evvm(evvmAddress).getRewardAmount() * 3) +
302
- _priorityFee_Evvm)
303
- : (Evvm(evvmAddress).getRewardAmount() * 2)
243
+ ? ((evvm.getRewardAmount() * 3) + _priorityFee_Evvm)
244
+ : (evvm.getRewardAmount() * 2)
304
245
  );
305
246
  }
306
247
  marketMetadata[market].ordersAvailable--;
307
- nonceP2PSwap[user][metadata.nonce] = true;
248
+ markAsyncNonceAsUsed(user, metadata.nonce);
308
249
  }
309
250
 
310
251
  function dispatchOrder_fillPropotionalFee(
@@ -317,7 +258,7 @@ contract P2PSwap is StakingServiceUtils {
317
258
  ) external {
318
259
  if (
319
260
  !SignatureUtils.verifyMessageSignedForDispatchOrder(
320
- Evvm(evvmAddress).getEvvmID(),
261
+ evvm.getEvvmID(),
321
262
  user,
322
263
  metadata.nonce,
323
264
  metadata.tokenA,
@@ -331,9 +272,7 @@ contract P2PSwap is StakingServiceUtils {
331
272
 
332
273
  uint256 market = findMarket(metadata.tokenA, metadata.tokenB);
333
274
 
334
- if (nonceP2PSwap[user][metadata.nonce]) {
335
- revert("Invalid nonce");
336
- }
275
+ verifyAsyncNonce(user, metadata.nonce);
337
276
 
338
277
  if (
339
278
  market == 0 ||
@@ -353,7 +292,7 @@ contract P2PSwap is StakingServiceUtils {
353
292
  revert("Insuficient amountOfTokenToFill");
354
293
  }
355
294
 
356
- makePay(
295
+ requestPay(
357
296
  user,
358
297
  metadata.tokenB,
359
298
  _nonce_Evvm,
@@ -412,20 +351,20 @@ contract P2PSwap is StakingServiceUtils {
412
351
  ordersInsideMarket[market][metadata.orderId].amountA
413
352
  );
414
353
 
415
- if (Evvm(evvmAddress).isAddressStaker(msg.sender)) {
354
+ if (evvm.isAddressStaker(msg.sender)) {
416
355
  makeCaPay(
417
356
  msg.sender,
418
357
  MATE_TOKEN_ADDRESS,
419
358
  metadata.amountOfTokenBToFill >
420
359
  ordersInsideMarket[market][metadata.orderId].amountB + fee
421
- ? Evvm(evvmAddress).getRewardAmount() * 5
422
- : Evvm(evvmAddress).getRewardAmount() * 4
360
+ ? evvm.getRewardAmount() * 5
361
+ : evvm.getRewardAmount() * 4
423
362
  );
424
363
  }
425
364
 
426
365
  ordersInsideMarket[market][metadata.orderId].seller = address(0);
427
366
  marketMetadata[market].ordersAvailable--;
428
- nonceP2PSwap[user][metadata.nonce] = true;
367
+ markAsyncNonceAsUsed(user, metadata.nonce);
429
368
  }
430
369
 
431
370
  function dispatchOrder_fillFixedFee(
@@ -439,7 +378,7 @@ contract P2PSwap is StakingServiceUtils {
439
378
  ) external {
440
379
  if (
441
380
  !SignatureUtils.verifyMessageSignedForDispatchOrder(
442
- Evvm(evvmAddress).getEvvmID(),
381
+ evvm.getEvvmID(),
443
382
  user,
444
383
  metadata.nonce,
445
384
  metadata.tokenA,
@@ -453,9 +392,7 @@ contract P2PSwap is StakingServiceUtils {
453
392
 
454
393
  uint256 market = findMarket(metadata.tokenA, metadata.tokenB);
455
394
 
456
- if (nonceP2PSwap[user][metadata.nonce]) {
457
- revert("Invalid nonce");
458
- }
395
+ verifyAsyncNonce(user, metadata.nonce);
459
396
 
460
397
  if (
461
398
  market == 0 ||
@@ -476,7 +413,7 @@ contract P2PSwap is StakingServiceUtils {
476
413
  revert("Insuficient amountOfTokenBToFill");
477
414
  }
478
415
 
479
- makePay(
416
+ requestPay(
480
417
  user,
481
418
  metadata.tokenB,
482
419
  _nonce_Evvm,
@@ -539,20 +476,20 @@ contract P2PSwap is StakingServiceUtils {
539
476
  ordersInsideMarket[market][metadata.orderId].amountA
540
477
  );
541
478
 
542
- if (Evvm(evvmAddress).isAddressStaker(msg.sender)) {
479
+ if (evvm.isAddressStaker(msg.sender)) {
543
480
  makeCaPay(
544
481
  msg.sender,
545
482
  MATE_TOKEN_ADDRESS,
546
483
  metadata.amountOfTokenBToFill >
547
484
  ordersInsideMarket[market][metadata.orderId].amountB + fee
548
- ? Evvm(evvmAddress).getRewardAmount() * 5
549
- : Evvm(evvmAddress).getRewardAmount() * 4
485
+ ? evvm.getRewardAmount() * 5
486
+ : evvm.getRewardAmount() * 4
550
487
  );
551
488
  }
552
489
 
553
490
  ordersInsideMarket[market][metadata.orderId].seller = address(0);
554
491
  marketMetadata[market].ordersAvailable--;
555
- nonceP2PSwap[user][metadata.nonce] = true;
492
+ markAsyncNonceAsUsed(user, metadata.nonce);
556
493
  }
557
494
 
558
495
  //devolver el 0.05% del monto de la orden
@@ -585,49 +522,6 @@ contract P2PSwap is StakingServiceUtils {
585
522
  return marketCount;
586
523
  }
587
524
 
588
- //◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
589
- // Tools for Evvm
590
- //◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
591
-
592
- function makePay(
593
- address _user_Evvm,
594
- address _token_Evvm,
595
- uint256 _nonce_Evvm,
596
- uint256 _ammount_Evvm,
597
- uint256 _priorityFee_Evvm,
598
- bool _priority_Evvm,
599
- bytes memory _signature_Evvm
600
- ) internal {
601
- Evvm(evvmAddress).pay(
602
- _user_Evvm,
603
- address(this),
604
- "",
605
- _token_Evvm,
606
- _ammount_Evvm,
607
- _priorityFee_Evvm,
608
- _nonce_Evvm,
609
- _priority_Evvm,
610
- address(this),
611
- _signature_Evvm
612
- );
613
- }
614
-
615
- function makeCaPay(
616
- address _user_Evvm,
617
- address _token_Evvm,
618
- uint256 _ammount_Evvm
619
- ) internal {
620
- Evvm(evvmAddress).caPay(_user_Evvm, _token_Evvm, _ammount_Evvm);
621
- }
622
-
623
- function makeDisperseCaPay(
624
- EvvmStructs.DisperseCaPayMetadata[] memory toData,
625
- address token,
626
- uint256 amount
627
- ) internal {
628
- Evvm(evvmAddress).disperseCaPay(toData, token, amount);
629
- }
630
-
631
525
  //◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
632
526
  // Admin tools
633
527
  //◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
@@ -825,7 +719,7 @@ contract P2PSwap is StakingServiceUtils {
825
719
  function stake(uint256 amount) external {
826
720
  if (
827
721
  msg.sender != owner ||
828
- amount * Staking(stakingAddress).priceOfStaking() >
722
+ amount * staking.priceOfStaking() >
829
723
  balancesOfContract[0x0000000000000000000000000000000000000001]
830
724
  ) revert();
831
725
 
@@ -922,13 +816,6 @@ contract P2PSwap is StakingServiceUtils {
922
816
  return markets;
923
817
  }
924
818
 
925
- function checkIfANonceP2PSwapIsUsed(
926
- address user,
927
- uint256 nonce
928
- ) public view returns (bool) {
929
- return nonceP2PSwap[user][nonce];
930
- }
931
-
932
819
  function getBalanceOfContract(
933
820
  address token
934
821
  ) external view returns (uint256) {