@evvm/testnet-contracts 2.1.2 → 2.2.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 (32) hide show
  1. package/README.md +195 -17
  2. package/contracts/evvm/Evvm.sol +13 -10
  3. package/contracts/evvm/lib/EvvmStorage.sol +2 -0
  4. package/contracts/evvm/lib/SignatureUtils.sol +12 -13
  5. package/contracts/nameService/NameService.sol +11 -8
  6. package/contracts/nameService/lib/ErrorsLib.sol +1 -1
  7. package/contracts/nameService/lib/SignatureUtils.sol +38 -39
  8. package/contracts/p2pSwap/P2PSwap.sol +14 -382
  9. package/contracts/p2pSwap/lib/SignatureUtils.sol +15 -16
  10. package/contracts/staking/Estimator.sol +4 -4
  11. package/contracts/staking/Staking.sol +28 -17
  12. package/contracts/staking/lib/ErrorsLib.sol +0 -1
  13. package/contracts/staking/lib/SignatureUtils.sol +6 -34
  14. package/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +3 -3
  15. package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +3 -3
  16. package/contracts/treasuryTwoChains/lib/SignatureUtils.sol +7 -7
  17. package/interfaces/IStaking.sol +1 -1
  18. package/library/Erc191TestBuilder.sol +57 -57
  19. package/library/EvvmService.sol +104 -0
  20. package/library/primitives/Math.sol +415 -0
  21. package/library/primitives/SignatureRecover.sol +42 -0
  22. package/library/utils/AdvancedStrings.sol +89 -0
  23. package/library/utils/SignatureUtil.sol +29 -0
  24. package/library/utils/service/AsyncNonceService.sol +34 -0
  25. package/library/utils/service/MakeServicePaymentOnEvvm.sol +49 -0
  26. package/library/utils/service/StakingServiceUtils.sol +37 -0
  27. package/library/utils/service/SyncNonceService.sol +18 -0
  28. package/package.json +16 -4
  29. package/contracts/evvm/EvvmLegacy.sol +0 -1553
  30. package/library/AdvancedStrings.sol +0 -77
  31. package/library/SignatureRecover.sol +0 -140
  32. package/library/StakingServiceHooks.sol +0 -116
@@ -1,9 +1,8 @@
1
1
  // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
2
  // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
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";
4
+ import {SignatureUtil} from "@evvm/testnet-contracts/library/utils/SignatureUtil.sol";
5
+ import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
7
6
 
8
7
  pragma solidity ^0.8.0;
9
8
 
@@ -25,19 +24,19 @@ library SignatureUtils {
25
24
  bytes memory signature
26
25
  ) internal pure returns (bool) {
27
26
  return
28
- SignatureRecover.signatureVerification(
29
- Strings.toString(evvmID),
27
+ SignatureUtil.verifySignature(
28
+ evvmID,
30
29
  "makeOrder",
31
30
  string.concat(
32
- Strings.toString(_nonce),
31
+ AdvancedStrings.uintToString(_nonce),
33
32
  ",",
34
33
  AdvancedStrings.addressToString(_tokenA),
35
34
  ",",
36
35
  AdvancedStrings.addressToString(_tokenB),
37
36
  ",",
38
- Strings.toString(_amountA),
37
+ AdvancedStrings.uintToString(_amountA),
39
38
  ",",
40
- Strings.toString(_amountB)
39
+ AdvancedStrings.uintToString(_amountB)
41
40
  ),
42
41
  signature,
43
42
  signer
@@ -54,17 +53,17 @@ library SignatureUtils {
54
53
  bytes memory signature
55
54
  ) internal pure returns (bool) {
56
55
  return
57
- SignatureRecover.signatureVerification(
58
- Strings.toString(evvmID),
56
+ SignatureUtil.verifySignature(
57
+ evvmID,
59
58
  "cancelOrder",
60
59
  string.concat(
61
- Strings.toString(_nonce),
60
+ AdvancedStrings.uintToString(_nonce),
62
61
  ",",
63
62
  AdvancedStrings.addressToString(_tokenA),
64
63
  ",",
65
64
  AdvancedStrings.addressToString(_tokenB),
66
65
  ",",
67
- Strings.toString(_orderId)
66
+ AdvancedStrings.uintToString(_orderId)
68
67
  ),
69
68
  signature,
70
69
  signer
@@ -81,17 +80,17 @@ library SignatureUtils {
81
80
  bytes memory signature
82
81
  ) internal pure returns (bool) {
83
82
  return
84
- SignatureRecover.signatureVerification(
85
- Strings.toString(evvmID),
83
+ SignatureUtil.verifySignature(
84
+ evvmID,
86
85
  "dispatchOrder",
87
86
  string.concat(
88
- Strings.toString(_nonce),
87
+ AdvancedStrings.uintToString(_nonce),
89
88
  ",",
90
89
  AdvancedStrings.addressToString(_tokenA),
91
90
  ",",
92
91
  AdvancedStrings.addressToString(_tokenB),
93
92
  ",",
94
- Strings.toString(_orderId)
93
+ AdvancedStrings.uintToString(_orderId)
95
94
  ),
96
95
  signature,
97
96
  signer
@@ -180,7 +180,7 @@ contract Estimator {
180
180
  address _proposal
181
181
  ) external onlyActivator {
182
182
  activator.proposal = _proposal;
183
- activator.timeToAccept = block.timestamp + 1 days;
183
+ activator.timeToAccept = block.timestamp + 1 minutes;
184
184
  }
185
185
 
186
186
  function cancelActivatorProposal() external onlyActivator {
@@ -200,7 +200,7 @@ contract Estimator {
200
200
  address _proposal
201
201
  ) external onlyAdmin {
202
202
  evvmAddress.proposal = _proposal;
203
- evvmAddress.timeToAccept = block.timestamp + 1 days;
203
+ evvmAddress.timeToAccept = block.timestamp + 1 minutes;
204
204
  }
205
205
 
206
206
  function cancelEvvmAddressProposal() external onlyAdmin {
@@ -220,7 +220,7 @@ contract Estimator {
220
220
  address _proposal
221
221
  ) external onlyAdmin {
222
222
  addressStaking.proposal = _proposal;
223
- addressStaking.timeToAccept = block.timestamp + 1 days;
223
+ addressStaking.timeToAccept = block.timestamp + 1 minutes;
224
224
  }
225
225
 
226
226
  function cancelAddressStakingProposal() external onlyAdmin {
@@ -240,7 +240,7 @@ contract Estimator {
240
240
  address _proposal
241
241
  ) external onlyAdmin {
242
242
  admin.proposal = _proposal;
243
- admin.timeToAccept = block.timestamp + 1 days;
243
+ admin.timeToAccept = block.timestamp + 1 minutes;
244
244
  }
245
245
 
246
246
  function cancelAdminProposal() external onlyAdmin {
@@ -42,6 +42,7 @@ pragma solidity ^0.8.0;
42
42
  */
43
43
 
44
44
  import {Evvm} from "@evvm/testnet-contracts/contracts/evvm/Evvm.sol";
45
+ import {SignatureUtil} from "@evvm/testnet-contracts/library/utils/SignatureUtil.sol";
45
46
  import {NameService} from "@evvm/testnet-contracts/contracts/nameService/NameService.sol";
46
47
  import {Estimator} from "@evvm/testnet-contracts/contracts/staking/Estimator.sol";
47
48
  import {ErrorsLib} from "@evvm/testnet-contracts/contracts/staking/lib/ErrorsLib.sol";
@@ -135,6 +136,8 @@ contract Staking {
135
136
  bool IsAService;
136
137
  }
137
138
 
139
+ uint256 constant TIME_TO_ACCEPT_PROPOSAL = 1 days;
140
+
138
141
  /// @dev Address of the EVVM core contract
139
142
  address private EVVM_ADDRESS;
140
143
 
@@ -211,12 +214,12 @@ contract Staking {
211
214
 
212
215
  goldenFisher.actual = initialGoldenFisher;
213
216
 
214
- allowPublicStaking.flag = true;
215
- allowPresaleStaking.flag = false;
217
+ allowPublicStaking.flag = false;
218
+ allowPresaleStaking.flag = true;
216
219
 
217
220
  secondsToUnlockStaking.actual = 0;
218
221
 
219
- secondsToUnllockFullUnstaking.actual = 21 days;
222
+ secondsToUnllockFullUnstaking.actual = 5 days;
220
223
 
221
224
  breakerSetupEstimatorAndEvvm = 0x01;
222
225
  }
@@ -411,12 +414,12 @@ contract Staking {
411
414
  * @notice Prepares a service/contract account for staking by recording pre-staking state
412
415
  * @dev First step in the service staking process. Must be followed by payment via caPay and confirmServiceStaking in the same transaction
413
416
  * @param amountOfStaking Amount of staking tokens the service intends to stake
414
- *
417
+ *
415
418
  * Service Staking Process:
416
419
  * 1. Call prepareServiceStaking(amount) - Records balances and metadata
417
- * 2. Use EVVM.caPay() to transfer the required Principal Tokens to this contract
420
+ * 2. Use EVVM.caPay() to transfer the required Principal Tokens to this contract
418
421
  * 3. Call confirmServiceStaking() - Validates payment and completes staking
419
- *
422
+ *
420
423
  * @dev All three steps MUST occur in the same transaction or the staking will fail
421
424
  * @dev CRITICAL WARNING: If the process is not completed properly (especially if caPay is called
422
425
  * but confirmServiceStaking is not), the Principal Tokens will remain locked in the staking
@@ -442,13 +445,13 @@ contract Staking {
442
445
  /**
443
446
  * @notice Confirms and completes the service staking operation after payment verification
444
447
  * @dev Final step in service staking. Validates that payment was made correctly and completes the staking process
445
- *
448
+ *
446
449
  * Validation checks:
447
450
  * - Service balance decreased by the exact staking cost
448
- * - Staking contract balance increased by the exact staking cost
451
+ * - Staking contract balance increased by the exact staking cost
449
452
  * - Operation occurs in the same transaction as prepareServiceStaking
450
453
  * - Caller matches the service that initiated the preparation
451
- *
454
+ *
452
455
  * @dev Only callable by the same contract that called prepareServiceStaking
453
456
  * @dev Must be called in the same transaction as prepareServiceStaking
454
457
  */
@@ -499,7 +502,7 @@ contract Staking {
499
502
  * @notice Allows a service/contract account to unstake their staking tokens
500
503
  * @dev Simplified unstaking process for services - no signature or payment required, just direct unstaking
501
504
  * @param amountOfStaking Amount of staking tokens to unstake
502
- *
505
+ *
503
506
  * @dev The service will receive Principal Tokens equal to: amountOfStaking * PRICE_OF_STAKING
504
507
  * @dev Subject to the same time locks as regular unstaking (21 days for full unstake)
505
508
  * @dev Only callable by contract accounts (services), not EOAs
@@ -761,7 +764,7 @@ contract Staking {
761
764
  */
762
765
  function proposeAdmin(address _newAdmin) external onlyOwner {
763
766
  admin.proposal = _newAdmin;
764
- admin.timeToAccept = block.timestamp + 1 days;
767
+ admin.timeToAccept = block.timestamp + TIME_TO_ACCEPT_PROPOSAL;
765
768
  }
766
769
 
767
770
  /**
@@ -795,7 +798,7 @@ contract Staking {
795
798
  */
796
799
  function proposeGoldenFisher(address _goldenFisher) external onlyOwner {
797
800
  goldenFisher.proposal = _goldenFisher;
798
- goldenFisher.timeToAccept = block.timestamp + 1 days;
801
+ goldenFisher.timeToAccept = block.timestamp + TIME_TO_ACCEPT_PROPOSAL;
799
802
  }
800
803
 
801
804
  /**
@@ -829,7 +832,9 @@ contract Staking {
829
832
  uint256 _secondsToUnlockStaking
830
833
  ) external onlyOwner {
831
834
  secondsToUnlockStaking.proposal = _secondsToUnlockStaking;
832
- secondsToUnlockStaking.timeToAccept = block.timestamp + 1 days;
835
+ secondsToUnlockStaking.timeToAccept =
836
+ block.timestamp +
837
+ TIME_TO_ACCEPT_PROPOSAL;
833
838
  }
834
839
 
835
840
  /**
@@ -863,7 +868,9 @@ contract Staking {
863
868
  uint256 _secondsToUnllockFullUnstaking
864
869
  ) external onlyOwner {
865
870
  secondsToUnllockFullUnstaking.proposal = _secondsToUnllockFullUnstaking;
866
- secondsToUnllockFullUnstaking.timeToAccept = block.timestamp + 1 days;
871
+ secondsToUnllockFullUnstaking.timeToAccept =
872
+ block.timestamp +
873
+ TIME_TO_ACCEPT_PROPOSAL;
867
874
  }
868
875
 
869
876
  /**
@@ -894,7 +901,9 @@ contract Staking {
894
901
  * @dev Initiates the time-delayed process to enable/disable public staking
895
902
  */
896
903
  function prepareChangeAllowPublicStaking() external onlyOwner {
897
- allowPublicStaking.timeToAccept = block.timestamp + 1 days;
904
+ allowPublicStaking.timeToAccept =
905
+ block.timestamp +
906
+ TIME_TO_ACCEPT_PROPOSAL;
898
907
  }
899
908
 
900
909
  /**
@@ -924,7 +933,9 @@ contract Staking {
924
933
  * @dev Initiates the time-delayed process to enable/disable presale staking
925
934
  */
926
935
  function prepareChangeAllowPresaleStaking() external onlyOwner {
927
- allowPresaleStaking.timeToAccept = block.timestamp + 1 days;
936
+ allowPresaleStaking.timeToAccept =
937
+ block.timestamp +
938
+ TIME_TO_ACCEPT_PROPOSAL;
928
939
  }
929
940
 
930
941
  /**
@@ -956,7 +967,7 @@ contract Staking {
956
967
  */
957
968
  function proposeEstimator(address _estimator) external onlyOwner {
958
969
  estimator.proposal = _estimator;
959
- estimator.timeToAccept = block.timestamp + 1 days;
970
+ estimator.timeToAccept = block.timestamp + TIME_TO_ACCEPT_PROPOSAL;
960
971
  }
961
972
 
962
973
  /**
@@ -20,4 +20,3 @@ library ErrorsLib {
20
20
  error ServiceDoesNotStakeInSameTx();
21
21
  error AddressMismatch();
22
22
  }
23
-
@@ -1,9 +1,8 @@
1
1
  // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
2
  // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
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";
4
+ import {SignatureUtil} from "@evvm/testnet-contracts/library/utils/SignatureUtil.sol";
5
+ import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
7
6
 
8
7
  pragma solidity ^0.8.0;
9
8
 
@@ -24,42 +23,15 @@ library SignatureUtils {
24
23
  bytes memory signature
25
24
  ) internal pure returns (bool) {
26
25
  return
27
- SignatureRecover.signatureVerification(
28
- Strings.toString(evvmID),
26
+ SignatureUtil.verifySignature(
27
+ evvmID,
29
28
  isExternalStaking ? "publicStaking" : "presaleStaking",
30
29
  string.concat(
31
30
  _isStaking ? "true" : "false",
32
31
  ",",
33
- Strings.toString(_amountOfStaking),
32
+ AdvancedStrings.uintToString(_amountOfStaking),
34
33
  ",",
35
- Strings.toString(_nonce)
36
- ),
37
- signature,
38
- user
39
- );
40
- }
41
-
42
- function verifyMessageSignedForPublicServiceStake(
43
- uint256 evvmID,
44
- address user,
45
- address serviceAddress,
46
- bool _isStaking,
47
- uint256 _amountOfStaking,
48
- uint256 _nonce,
49
- bytes memory signature
50
- ) internal pure returns (bool) {
51
- return
52
- SignatureRecover.signatureVerification(
53
- Strings.toString(evvmID),
54
- "publicServiceStaking",
55
- string.concat(
56
- AdvancedStrings.addressToString(serviceAddress),
57
- ",",
58
- _isStaking ? "true" : "false",
59
- ",",
60
- Strings.toString(_amountOfStaking),
61
- ",",
62
- Strings.toString(_nonce)
34
+ AdvancedStrings.uintToString(_nonce)
63
35
  ),
64
36
  signature,
65
37
  user
@@ -588,7 +588,7 @@ contract TreasuryExternalChainStation is
588
588
  if (_newOwner == address(0) || _newOwner == admin.current) revert();
589
589
 
590
590
  admin.proposal = _newOwner;
591
- admin.timeToAccept = block.timestamp + 1 days;
591
+ admin.timeToAccept = block.timestamp + 1 minutes;
592
592
  }
593
593
 
594
594
  /// @notice Cancels a pending admin change proposal
@@ -625,7 +625,7 @@ contract TreasuryExternalChainStation is
625
625
  ) revert();
626
626
 
627
627
  fisherExecutor.proposal = _newFisherExecutor;
628
- fisherExecutor.timeToAccept = block.timestamp + 1 days;
628
+ fisherExecutor.timeToAccept = block.timestamp + 1 minutes;
629
629
  }
630
630
 
631
631
  /// @notice Cancels a pending Fisher executor change proposal
@@ -661,7 +661,7 @@ contract TreasuryExternalChainStation is
661
661
  hostChainAddressChangeProposal = ChangeHostChainAddressParams({
662
662
  porposeAddress_AddressType: hostChainStationAddress,
663
663
  porposeAddress_StringType: hostChainStationAddressString,
664
- timeToAccept: block.timestamp + 1 days
664
+ timeToAccept: block.timestamp + 1 minutes
665
665
  });
666
666
  }
667
667
 
@@ -506,7 +506,7 @@ contract TreasuryHostChainStation is
506
506
  if (_newOwner == address(0) || _newOwner == admin.current) revert();
507
507
 
508
508
  admin.proposal = _newOwner;
509
- admin.timeToAccept = block.timestamp + 1 days;
509
+ admin.timeToAccept = block.timestamp + 1 minutes;
510
510
  }
511
511
 
512
512
  /// @notice Cancels a pending admin change proposal
@@ -543,7 +543,7 @@ contract TreasuryHostChainStation is
543
543
  ) revert();
544
544
 
545
545
  fisherExecutor.proposal = _newFisherExecutor;
546
- fisherExecutor.timeToAccept = block.timestamp + 1 days;
546
+ fisherExecutor.timeToAccept = block.timestamp + 1 minutes;
547
547
  }
548
548
 
549
549
  /// @notice Cancels a pending Fisher executor change proposal
@@ -579,7 +579,7 @@ contract TreasuryHostChainStation is
579
579
  externalChainAddressChangeProposal = ChangeExternalChainAddressParams({
580
580
  porposeAddress_AddressType: externalChainStationAddress,
581
581
  porposeAddress_StringType: externalChainStationAddressString,
582
- timeToAccept: block.timestamp + 1 days
582
+ timeToAccept: block.timestamp + 1 minutes
583
583
  });
584
584
  }
585
585
 
@@ -1,8 +1,8 @@
1
1
  // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
2
  // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
3
 
4
- import {SignatureRecover} from "@evvm/testnet-contracts/library/SignatureRecover.sol";
5
- import {AdvancedStrings} from "@evvm/testnet-contracts/library/AdvancedStrings.sol";
4
+ import {SignatureUtil} from "@evvm/testnet-contracts/library/utils/SignatureUtil.sol";
5
+ import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
6
6
  import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
7
7
 
8
8
  pragma solidity ^0.8.0;
@@ -60,19 +60,19 @@ library SignatureUtils {
60
60
  bytes memory signature
61
61
  ) internal pure returns (bool) {
62
62
  return
63
- SignatureRecover.signatureVerification(
64
- Strings.toString(evvmID),
63
+ SignatureUtil.verifySignature(
64
+ evvmID,
65
65
  "fisherBridge",
66
66
  string.concat(
67
67
  AdvancedStrings.addressToString(addressToReceive),
68
68
  ",",
69
- Strings.toString(nonce),
69
+ AdvancedStrings.uintToString(nonce),
70
70
  ",",
71
71
  AdvancedStrings.addressToString(tokenAddress),
72
72
  ",",
73
- Strings.toString(priorityFee),
73
+ AdvancedStrings.uintToString(priorityFee),
74
74
  ",",
75
- Strings.toString(amount)
75
+ AdvancedStrings.uintToString(amount)
76
76
  ),
77
77
  signature,
78
78
  signer
@@ -3,7 +3,7 @@
3
3
 
4
4
  pragma solidity ^0.8.4;
5
5
 
6
- interface Staking {
6
+ interface IStaking {
7
7
  struct BoolTypeProposal {
8
8
  bool flag;
9
9
  uint256 timeToAccept;