@evvm/testnet-contracts 2.1.3 → 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 (52) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +355 -55
  3. package/contracts/evvm/Evvm.sol +39 -38
  4. package/contracts/evvm/lib/ErrorsLib.sol +2 -1
  5. package/contracts/evvm/lib/EvvmStorage.sol +2 -0
  6. package/contracts/evvm/lib/EvvmStructs.sol +27 -1
  7. package/contracts/evvm/lib/SignatureUtils.sol +14 -17
  8. package/contracts/nameService/NameService.sol +124 -366
  9. package/contracts/nameService/lib/ErrorsLib.sol +2 -8
  10. package/contracts/nameService/lib/IdentityValidation.sol +182 -0
  11. package/contracts/nameService/lib/NameServiceStructs.sol +69 -0
  12. package/contracts/nameService/lib/SignatureUtils.sol +47 -41
  13. package/contracts/p2pSwap/P2PSwap.sol +54 -535
  14. package/contracts/p2pSwap/lib/P2PSwapStructs.sol +59 -0
  15. package/contracts/p2pSwap/lib/SignatureUtils.sol +16 -18
  16. package/contracts/staking/Estimator.sol +7 -6
  17. package/contracts/staking/Staking.sol +70 -159
  18. package/contracts/staking/lib/ErrorsLib.sol +0 -1
  19. package/contracts/staking/lib/SignatureUtils.sol +7 -36
  20. package/contracts/staking/lib/StakingStructs.sol +94 -0
  21. package/contracts/treasury/Treasury.sol +18 -20
  22. package/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +88 -35
  23. package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +81 -47
  24. package/contracts/treasuryTwoChains/lib/ErrorsLib.sol +2 -0
  25. package/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +3 -14
  26. package/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +3 -7
  27. package/contracts/treasuryTwoChains/lib/SignatureUtils.sol +12 -14
  28. package/interfaces/IEstimator.sol +7 -50
  29. package/interfaces/IEvvm.sol +17 -91
  30. package/interfaces/INameService.sol +37 -88
  31. package/interfaces/IP2PSwap.sol +19 -15
  32. package/interfaces/IStaking.sol +20 -50
  33. package/interfaces/ITreasury.sol +1 -4
  34. package/interfaces/ITreasuryExternalChainStation.sol +11 -15
  35. package/interfaces/ITreasuryHostChainStation.sol +7 -10
  36. package/library/Erc191TestBuilder.sol +56 -57
  37. package/library/EvvmService.sol +40 -0
  38. package/library/primitives/IERC20.sol +79 -0
  39. package/library/primitives/Math.sol +415 -0
  40. package/library/primitives/SignatureRecover.sol +42 -0
  41. package/library/utils/AdvancedStrings.sol +89 -0
  42. package/library/utils/GovernanceUtils.sol +81 -0
  43. package/library/utils/SignatureUtil.sol +29 -0
  44. package/library/utils/nonces/AsyncNonce.sol +32 -0
  45. package/library/utils/nonces/SyncNonce.sol +27 -0
  46. package/library/utils/service/EvvmPayments.sol +77 -0
  47. package/library/utils/service/StakingServiceUtils.sol +32 -0
  48. package/package.json +11 -13
  49. package/contracts/evvm/EvvmLegacy.sol +0 -1553
  50. package/library/AdvancedStrings.sol +0 -77
  51. package/library/SignatureRecover.sol +0 -140
  52. package/library/StakingServiceHooks.sol +0 -116
@@ -77,7 +77,7 @@ import {NameService} from "@evvm/testnet-contracts/contracts/nameService/NameSer
77
77
  import {EvvmStorage} from "@evvm/testnet-contracts/contracts/evvm/lib/EvvmStorage.sol";
78
78
  import {ErrorsLib} from "@evvm/testnet-contracts/contracts/evvm/lib/ErrorsLib.sol";
79
79
  import {SignatureUtils} from "@evvm/testnet-contracts/contracts/evvm/lib/SignatureUtils.sol";
80
- import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
80
+ import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
81
81
 
82
82
  contract Evvm is EvvmStorage {
83
83
  /**
@@ -145,6 +145,8 @@ contract Evvm is EvvmStorage {
145
145
  address _stakingContractAddress,
146
146
  EvvmMetadata memory _evvmMetadata
147
147
  ) {
148
+ evvmMetadata = _evvmMetadata;
149
+
148
150
  stakingContractAddress = _stakingContractAddress;
149
151
 
150
152
  admin.current = _initialOwner;
@@ -156,8 +158,6 @@ contract Evvm is EvvmStorage {
156
158
  stakerList[_stakingContractAddress] = FLAG_IS_STAKER;
157
159
 
158
160
  breakerSetupNameServiceAddress = FLAG_IS_STAKER;
159
-
160
- evvmMetadata = _evvmMetadata;
161
161
  }
162
162
 
163
163
  /**
@@ -209,14 +209,14 @@ contract Evvm is EvvmStorage {
209
209
  * @dev Allows the admin to change the EVVM ID within a 1-day window after deployment
210
210
  */
211
211
  function setEvvmID(uint256 newEvvmID) external onlyAdmin {
212
- if (newEvvmID == 0) {
212
+ if (evvmMetadata.EvvmID != 0) {
213
213
  if (block.timestamp > windowTimeToChangeEvvmID)
214
214
  revert ErrorsLib.WindowToChangeEvvmIDExpired();
215
215
  }
216
216
 
217
217
  evvmMetadata.EvvmID = newEvvmID;
218
218
 
219
- windowTimeToChangeEvvmID = block.timestamp + 1 minutes;
219
+ windowTimeToChangeEvvmID = block.timestamp + 24 hours;
220
220
  }
221
221
 
222
222
  /**
@@ -365,22 +365,25 @@ contract Evvm is EvvmStorage {
365
365
  token,
366
366
  amount,
367
367
  priorityFee,
368
- priorityFlag ? nonce : nextSyncUsedNonce[from],
368
+ nonce,
369
369
  priorityFlag,
370
370
  executor,
371
371
  signature
372
372
  )
373
373
  ) revert ErrorsLib.InvalidSignature();
374
374
 
375
- if (executor != address(0)) {
376
- if (msg.sender != executor)
377
- revert ErrorsLib.SenderIsNotTheExecutor();
378
- }
375
+ if ((executor != address(0)) && (msg.sender != executor))
376
+ revert ErrorsLib.SenderIsNotTheExecutor();
379
377
 
380
- if (priorityFlag && asyncUsedNonce[from][nonce])
381
- revert ErrorsLib.InvalidAsyncNonce();
378
+ if (priorityFlag) {
379
+ if (asyncUsedNonce[from][nonce])
380
+ revert ErrorsLib.AsyncNonceAlreadyUsed();
381
+ } else {
382
+ if (nextSyncUsedNonce[from] != nonce)
383
+ revert ErrorsLib.SyncNonceMismatch();
384
+ }
382
385
 
383
- address to = !Strings.equal(to_identity, "")
386
+ address to = !AdvancedStrings.equal(to_identity, "")
384
387
  ? NameService(nameServiceAddress).verifyStrictAndGetOwnerOfIdentity(
385
388
  to_identity
386
389
  )
@@ -423,24 +426,15 @@ contract Evvm is EvvmStorage {
423
426
  *
424
427
  * Return Values:
425
428
  * - successfulTransactions: Count of completed payments
426
- * - failedTransactions: Count of failed payments
427
429
  * - results: Boolean array indicating success/failure for each payment
428
430
  *
429
431
  * @param payData Array of PayData structures containing payment details
430
432
  * @return successfulTransactions Number of payments that completed successfully
431
- * @return failedTransactions Number of payments that failed
432
433
  * @return results Boolean array with success status for each payment
433
434
  */
434
435
  function payMultiple(
435
436
  PayData[] memory payData
436
- )
437
- external
438
- returns (
439
- uint256 successfulTransactions,
440
- uint256 failedTransactions,
441
- bool[] memory results
442
- )
443
- {
437
+ ) external returns (uint256 successfulTransactions, bool[] memory results) {
444
438
  address to_aux;
445
439
  results = new bool[](payData.length);
446
440
  for (uint256 iteration = 0; iteration < payData.length; iteration++) {
@@ -453,9 +447,7 @@ contract Evvm is EvvmStorage {
453
447
  payData[iteration].token,
454
448
  payData[iteration].amount,
455
449
  payData[iteration].priorityFee,
456
- payData[iteration].priorityFlag
457
- ? payData[iteration].nonce
458
- : nextSyncUsedNonce[payData[iteration].from],
450
+ payData[iteration].nonce,
459
451
  payData[iteration].priorityFlag,
460
452
  payData[iteration].executor,
461
453
  payData[iteration].signature
@@ -464,7 +456,6 @@ contract Evvm is EvvmStorage {
464
456
 
465
457
  if (payData[iteration].executor != address(0)) {
466
458
  if (msg.sender != payData[iteration].executor) {
467
- failedTransactions++;
468
459
  results[iteration] = false;
469
460
  continue;
470
461
  }
@@ -482,7 +473,6 @@ contract Evvm is EvvmStorage {
482
473
  payData[iteration].nonce
483
474
  ] = true;
484
475
  } else {
485
- failedTransactions++;
486
476
  results[iteration] = false;
487
477
  continue;
488
478
  }
@@ -495,13 +485,12 @@ contract Evvm is EvvmStorage {
495
485
  ) {
496
486
  nextSyncUsedNonce[payData[iteration].from]++;
497
487
  } else {
498
- failedTransactions++;
499
488
  results[iteration] = false;
500
489
  continue;
501
490
  }
502
491
  }
503
492
 
504
- to_aux = !Strings.equal(payData[iteration].to_identity, "")
493
+ to_aux = !AdvancedStrings.equal(payData[iteration].to_identity, "")
505
494
  ? NameService(nameServiceAddress)
506
495
  .verifyStrictAndGetOwnerOfIdentity(
507
496
  payData[iteration].to_identity
@@ -512,7 +501,6 @@ contract Evvm is EvvmStorage {
512
501
  payData[iteration].priorityFee + payData[iteration].amount >
513
502
  balances[payData[iteration].from][payData[iteration].token]
514
503
  ) {
515
- failedTransactions++;
516
504
  results[iteration] = false;
517
505
  continue;
518
506
  }
@@ -525,7 +513,6 @@ contract Evvm is EvvmStorage {
525
513
  payData[iteration].amount
526
514
  )
527
515
  ) {
528
- failedTransactions++;
529
516
  results[iteration] = false;
530
517
  continue;
531
518
  } else {
@@ -541,7 +528,6 @@ contract Evvm is EvvmStorage {
541
528
  payData[iteration].priorityFee
542
529
  )
543
530
  ) {
544
- failedTransactions++;
545
531
  results[iteration] = false;
546
532
  continue;
547
533
  }
@@ -607,7 +593,7 @@ contract Evvm is EvvmStorage {
607
593
  token,
608
594
  amount,
609
595
  priorityFee,
610
- priorityFlag ? nonce : nextSyncUsedNonce[from],
596
+ nonce,
611
597
  priorityFlag,
612
598
  executor,
613
599
  signature
@@ -621,7 +607,10 @@ contract Evvm is EvvmStorage {
621
607
 
622
608
  if (priorityFlag) {
623
609
  if (asyncUsedNonce[from][nonce])
624
- revert ErrorsLib.InvalidAsyncNonce();
610
+ revert ErrorsLib.AsyncNonceAlreadyUsed();
611
+ } else {
612
+ if (nextSyncUsedNonce[from] != nonce)
613
+ revert ErrorsLib.SyncNonceMismatch();
625
614
  }
626
615
 
627
616
  if (balances[from][token] < amount + priorityFee)
@@ -633,7 +622,7 @@ contract Evvm is EvvmStorage {
633
622
  for (uint256 i = 0; i < toData.length; i++) {
634
623
  acomulatedAmount += toData[i].amount;
635
624
 
636
- if (!Strings.equal(toData[i].to_identity, "")) {
625
+ if (!AdvancedStrings.equal(toData[i].to_identity, "")) {
637
626
  if (
638
627
  NameService(nameServiceAddress).strictVerifyIfIdentityExist(
639
628
  toData[i].to_identity
@@ -665,6 +654,7 @@ contract Evvm is EvvmStorage {
665
654
  } else {
666
655
  nextSyncUsedNonce[from]++;
667
656
  }
657
+
668
658
  }
669
659
 
670
660
  /**
@@ -771,6 +761,7 @@ contract Evvm is EvvmStorage {
771
761
  if (isAddressStaker(msg.sender)) {
772
762
  _giveReward(msg.sender, 1);
773
763
  }
764
+
774
765
  }
775
766
 
776
767
  //░▒▓█Treasury exclusive functions██████████████████████████████████████████▓▒░
@@ -950,7 +941,9 @@ contract Evvm is EvvmStorage {
950
941
  */
951
942
  function proposeImplementation(address _newImpl) external onlyAdmin {
952
943
  proposalImplementation = _newImpl;
953
- timeToAcceptImplementation = block.timestamp + 30 days;
944
+ timeToAcceptImplementation =
945
+ block.timestamp +
946
+ TIME_TO_ACCEPT_IMPLEMENTATION;
954
947
  }
955
948
 
956
949
  /**
@@ -999,7 +992,7 @@ contract Evvm is EvvmStorage {
999
992
  }
1000
993
 
1001
994
  admin.proposal = _newOwner;
1002
- admin.timeToAccept = block.timestamp + 1 minutes;
995
+ admin.timeToAccept = block.timestamp + TIME_TO_ACCEPT_PROPOSAL;
1003
996
  }
1004
997
 
1005
998
  /**
@@ -1132,6 +1125,14 @@ contract Evvm is EvvmStorage {
1132
1125
  return evvmMetadata;
1133
1126
  }
1134
1127
 
1128
+ function getPrincipalTokenAddress() external view returns (address) {
1129
+ return evvmMetadata.principalTokenAddress;
1130
+ }
1131
+
1132
+ function getChainHostCoinAddress() external pure returns (address) {
1133
+ return address(0);
1134
+ }
1135
+
1135
1136
  /**
1136
1137
  * @notice Gets the unique identifier string for this EVVM instance
1137
1138
  * @dev Returns the EvvmID used for distinguishing different EVVM deployments
@@ -7,7 +7,8 @@ library ErrorsLib {
7
7
  error InvalidSignature();
8
8
  error SenderIsNotTheExecutor();
9
9
  error UpdateBalanceFailed();
10
- error InvalidAsyncNonce();
10
+ error SyncNonceMismatch();
11
+ error AsyncNonceAlreadyUsed();
11
12
  error NotAnStaker();
12
13
  error InsufficientBalance();
13
14
  error InvalidAmount(uint256, uint256);
@@ -20,6 +20,8 @@ import {EvvmStructs} from "./EvvmStructs.sol";
20
20
  abstract contract EvvmStorage is EvvmStructs {
21
21
  address constant ETH_ADDRESS = address(0);
22
22
  bytes1 constant FLAG_IS_STAKER = 0x01;
23
+ uint256 constant TIME_TO_ACCEPT_PROPOSAL = 1 days;
24
+ uint256 constant TIME_TO_ACCEPT_IMPLEMENTATION = 30 days;
23
25
 
24
26
  address nameServiceAddress;
25
27
 
@@ -28,6 +28,32 @@ abstract contract EvvmStructs {
28
28
  bytes signature;
29
29
  }
30
30
 
31
+ struct DispersePayData {
32
+ address from;
33
+ DispersePayMetadata[] toData;
34
+ address token;
35
+ uint256 totalAmount;
36
+ uint256 priorityFee;
37
+ uint256 nonce;
38
+ bool priorityFlag;
39
+ address executor;
40
+ bytes signature;
41
+ }
42
+
43
+ struct CaPayData {
44
+ address from;
45
+ address to;
46
+ address token;
47
+ uint256 amount;
48
+ }
49
+
50
+ struct DisperseCaPayData{
51
+ address from;
52
+ DisperseCaPayMetadata[] toData;
53
+ address token;
54
+ uint256 amount;
55
+ }
56
+
31
57
  struct DispersePayMetadata {
32
58
  uint256 amount;
33
59
  address to_address;
@@ -38,7 +64,7 @@ abstract contract EvvmStructs {
38
64
  uint256 amount;
39
65
  address toAddress;
40
66
  }
41
-
67
+
42
68
  struct EvvmMetadata {
43
69
  string EvvmName;
44
70
  uint256 EvvmID;
@@ -1,12 +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
-
4
- import {SignatureRecover} from "@evvm/testnet-contracts/library/SignatureRecover.sol";
5
- import {AdvancedStrings} from "@evvm/testnet-contracts/library/AdvancedStrings.sol";
6
- import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
7
-
8
3
  pragma solidity ^0.8.0;
9
4
 
5
+ import {SignatureUtil} from "@evvm/testnet-contracts/library/utils/SignatureUtil.sol";
6
+ import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
7
+
10
8
  library SignatureUtils {
11
9
  /**
12
10
  * @dev using EIP-191 (https://eips.ethereum.org/EIPS/eip-191) can be used to sign and
@@ -45,8 +43,8 @@ library SignatureUtils {
45
43
  bytes memory signature
46
44
  ) internal pure returns (bool) {
47
45
  return
48
- SignatureRecover.signatureVerification(
49
- Strings.toString(evvmID),
46
+ SignatureUtil.verifySignature(
47
+ evvmID,
50
48
  "pay",
51
49
  string.concat(
52
50
  _receiverAddress == address(0)
@@ -55,11 +53,11 @@ library SignatureUtils {
55
53
  ",",
56
54
  AdvancedStrings.addressToString(_token),
57
55
  ",",
58
- Strings.toString(_amount),
56
+ AdvancedStrings.uintToString(_amount),
59
57
  ",",
60
- Strings.toString(_priorityFee),
58
+ AdvancedStrings.uintToString(_priorityFee),
61
59
  ",",
62
- Strings.toString(_nonce),
60
+ AdvancedStrings.uintToString(_nonce),
63
61
  ",",
64
62
  _priorityFlag ? "true" : "false",
65
63
  ",",
@@ -97,19 +95,19 @@ library SignatureUtils {
97
95
  bytes memory signature
98
96
  ) internal pure returns (bool) {
99
97
  return
100
- SignatureRecover.signatureVerification(
101
- Strings.toString(evvmID),
98
+ SignatureUtil.verifySignature(
99
+ evvmID,
102
100
  "dispersePay",
103
101
  string.concat(
104
102
  AdvancedStrings.bytes32ToString(hashList),
105
103
  ",",
106
104
  AdvancedStrings.addressToString(_token),
107
105
  ",",
108
- Strings.toString(_amount),
106
+ AdvancedStrings.uintToString(_amount),
109
107
  ",",
110
- Strings.toString(_priorityFee),
108
+ AdvancedStrings.uintToString(_priorityFee),
111
109
  ",",
112
- Strings.toString(_nonce),
110
+ AdvancedStrings.uintToString(_nonce),
113
111
  ",",
114
112
  _priorityFlag ? "true" : "false",
115
113
  ",",
@@ -119,5 +117,4 @@ library SignatureUtils {
119
117
  signer
120
118
  );
121
119
  }
122
-
123
- }
120
+ }