@evvm/testnet-contracts 2.2.3 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/LICENSE +145 -118
  2. package/README.md +162 -39
  3. package/contracts/core/Core.sol +1394 -0
  4. package/contracts/core/lib/CoreStorage.sol +171 -0
  5. package/contracts/nameService/NameService.sol +666 -586
  6. package/contracts/nameService/lib/IdentityValidation.sol +18 -3
  7. package/contracts/p2pSwap/P2PSwap.sol +439 -285
  8. package/contracts/staking/Estimator.sol +128 -40
  9. package/contracts/staking/Staking.sol +329 -322
  10. package/contracts/treasury/Treasury.sol +48 -37
  11. package/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +585 -198
  12. package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +425 -174
  13. package/contracts/treasuryTwoChains/lib/PayloadUtils.sol +2 -4
  14. package/interfaces/{IEvvm.sol → ICore.sol} +67 -29
  15. package/interfaces/IEstimator.sol +1 -1
  16. package/interfaces/INameService.sol +58 -52
  17. package/interfaces/IP2PSwap.sol +18 -17
  18. package/interfaces/IStaking.sol +22 -17
  19. package/interfaces/ITreasury.sol +2 -1
  20. package/interfaces/ITreasuryExternalChainStation.sol +15 -9
  21. package/interfaces/ITreasuryHostChainStation.sol +14 -11
  22. package/interfaces/IUserValidator.sol +6 -0
  23. package/library/Erc191TestBuilder.sol +350 -297
  24. package/library/EvvmService.sol +38 -27
  25. package/library/errors/CoreError.sol +116 -0
  26. package/library/errors/CrossChainTreasuryError.sol +36 -0
  27. package/library/errors/NameServiceError.sol +79 -0
  28. package/library/errors/StakingError.sol +79 -0
  29. package/library/errors/TreasuryError.sol +33 -0
  30. package/library/primitives/SignatureRecover.sol +33 -0
  31. package/library/structs/CoreStructs.sol +146 -0
  32. package/library/structs/ExternalChainStationStructs.sol +92 -0
  33. package/library/structs/HostChainStationStructs.sol +77 -0
  34. package/library/structs/NameServiceStructs.sol +47 -0
  35. package/library/structs/P2PSwapStructs.sol +127 -0
  36. package/library/structs/StakingStructs.sol +67 -0
  37. package/library/utils/AdvancedStrings.sol +84 -5
  38. package/library/utils/CAUtils.sol +29 -0
  39. package/library/utils/SignatureUtil.sol +34 -0
  40. package/library/utils/governance/Admin.sol +66 -0
  41. package/library/utils/governance/ProposalStructs.sol +49 -0
  42. package/library/utils/service/CoreExecution.sol +177 -0
  43. package/library/utils/service/StakingServiceUtils.sol +30 -3
  44. package/library/utils/signature/CoreHashUtils.sol +73 -0
  45. package/library/utils/signature/NameServiceHashUtils.sol +156 -0
  46. package/library/utils/signature/P2PSwapHashUtils.sol +65 -0
  47. package/library/utils/signature/StakingHashUtils.sol +41 -0
  48. package/library/utils/signature/TreasuryCrossChainHashUtils.sol +40 -0
  49. package/package.json +2 -1
  50. package/contracts/evvm/Evvm.sol +0 -1327
  51. package/contracts/evvm/lib/ErrorsLib.sol +0 -18
  52. package/contracts/evvm/lib/EvvmStorage.sol +0 -62
  53. package/contracts/evvm/lib/EvvmStructs.sol +0 -90
  54. package/contracts/evvm/lib/SignatureUtils.sol +0 -120
  55. package/contracts/nameService/lib/ErrorsLib.sol +0 -21
  56. package/contracts/nameService/lib/NameServiceStructs.sol +0 -69
  57. package/contracts/nameService/lib/SignatureUtils.sol +0 -245
  58. package/contracts/p2pSwap/lib/P2PSwapStructs.sol +0 -59
  59. package/contracts/p2pSwap/lib/SignatureUtils.sol +0 -98
  60. package/contracts/staking/lib/ErrorsLib.sol +0 -22
  61. package/contracts/staking/lib/SignatureUtils.sol +0 -39
  62. package/contracts/staking/lib/StakingStructs.sol +0 -94
  63. package/contracts/treasury/lib/ErrorsLib.sol +0 -11
  64. package/contracts/treasuryTwoChains/lib/ErrorsLib.sol +0 -48
  65. package/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +0 -80
  66. package/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +0 -87
  67. package/contracts/treasuryTwoChains/lib/SignatureUtils.sol +0 -79
  68. package/library/utils/GovernanceUtils.sol +0 -81
  69. package/library/utils/nonces/AsyncNonce.sol +0 -32
  70. package/library/utils/nonces/SyncNonce.sol +0 -27
  71. package/library/utils/service/EvvmPayments.sol +0 -79
@@ -1,8 +1,17 @@
1
1
  // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
- // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
2
+ // Full license terms available at: https://www.core.info/docs/EVVMNoncommercialLicense
3
3
 
4
4
  pragma solidity ^0.8.0;
5
5
 
6
+ import {
7
+ TreasuryError as Error
8
+ } from "@evvm/testnet-contracts/library/errors/TreasuryError.sol";
9
+
10
+ import {Core} from "@evvm/testnet-contracts/contracts/core/Core.sol";
11
+
12
+ import {IERC20} from "@evvm/testnet-contracts/library/primitives/IERC20.sol";
13
+ import {SafeTransferLib} from "@solady/utils/SafeTransferLib.sol";
14
+
6
15
  /**
7
16
  ░██████████
8
17
  ░██
@@ -21,82 +30,84 @@ pragma solidity ^0.8.0;
21
30
  ██║ ███████╗███████║ ██║ ██║ ╚████║███████╗ ██║
22
31
  ╚═╝ ╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═══╝╚══════╝ ╚═╝
23
32
 
24
- * @title Treasury Contract
33
+ * @title EVVM Treasury
25
34
  * @author Mate labs
26
- * @notice Treasury for managing deposits and withdrawals in the EVVM ecosystem
27
- * @dev Secure vault for ETH and ERC20 tokens with EVVM integration and input validation
35
+ * @notice Vault for depositing and withdrawing assets in the EVVM ecosystem.
36
+ * @dev Handles ETH and ERC20 tokens, syncing balances with Core.sol.
37
+ * Principal Tokens are not withdrawable via this contract.
28
38
  */
29
39
 
30
- import {IERC20} from "@evvm/testnet-contracts/library/primitives/IERC20.sol";
31
- import {SafeTransferLib} from "@solady/utils/SafeTransferLib.sol";
32
- import {IEvvm} from "@evvm/testnet-contracts/interfaces/IEvvm.sol";
33
- import {
34
- ErrorsLib
35
- } from "@evvm/testnet-contracts/contracts/treasury/lib/ErrorsLib.sol";
36
-
37
40
  contract Treasury {
38
-
39
- IEvvm evvm;
41
+ /// @dev Reference to the EVVM core contract for balance management
42
+ Core core;
40
43
 
41
44
  /**
42
45
  * @notice Initialize Treasury with EVVM contract address
43
- * @param _evvmAddress Address of the EVVM core contract
46
+ * @param _coreAddress Address of the EVVM core contract
44
47
  */
45
- constructor(address _evvmAddress) {
46
- evvm = IEvvm(_evvmAddress);
48
+ constructor(address _coreAddress) {
49
+ core = Core(_coreAddress);
47
50
  }
48
51
 
49
52
  /**
50
- * @notice Deposit ETH or ERC20 tokens
51
- * @param token ERC20 token address (ignored for ETH deposits)
52
- * @param amount Token amount (ignored for ETH deposits)
53
+ * @notice Deposits ETH or ERC20 tokens into EVVM.
54
+ * @dev Credits the user's balance in Core.sol. ETH uses address(0).
55
+ * @param token Token address (address(0) for native ETH).
56
+ * @param amount Amount to deposit (must match msg.value for ETH).
53
57
  */
54
58
  function deposit(address token, uint256 amount) external payable {
55
59
  if (address(0) == token) {
56
60
  /// user is sending host native coin
57
61
  if (msg.value == 0)
58
- revert ErrorsLib.DepositAmountMustBeGreaterThanZero();
59
- if (amount != msg.value) revert ErrorsLib.InvalidDepositAmount();
62
+ revert Error.DepositAmountMustBeGreaterThanZero();
63
+
64
+ if (amount != msg.value) revert Error.InvalidDepositAmount();
60
65
 
61
- evvm.addAmountToUser(msg.sender, address(0), msg.value);
66
+ core.addAmountToUser(msg.sender, address(0), msg.value);
62
67
  } else {
63
68
  /// user is sending ERC20 tokens
64
69
 
65
- if (msg.value != 0) revert ErrorsLib.InvalidDepositAmount();
66
- if (amount == 0)
67
- revert ErrorsLib.DepositAmountMustBeGreaterThanZero();
70
+ if (msg.value != 0) revert Error.DepositCoinWithToken();
71
+
72
+ if (amount == 0) revert Error.DepositAmountMustBeGreaterThanZero();
68
73
 
69
74
  IERC20(token).transferFrom(msg.sender, address(this), amount);
70
- evvm.addAmountToUser(msg.sender, token, amount);
75
+ core.addAmountToUser(msg.sender, token, amount);
71
76
  }
72
77
  }
73
78
 
74
79
  /**
75
- * @notice Withdraw ETH or ERC20 tokens
76
- * @param token Token address (address(0) for ETH)
77
- * @param amount Amount to withdraw
80
+ * @notice Withdraws ETH or ERC20 tokens from EVVM.
81
+ * @dev Deducts from the user's balance in Core.sol. Principal Tokens cannot be withdrawn.
82
+ * @param token Token address to withdraw (address(0) for native ETH).
83
+ * @param amount Amount to withdraw.
78
84
  */
79
85
  function withdraw(address token, uint256 amount) external {
80
- if (token == evvm.getEvvmMetadata().principalTokenAddress)
81
- revert ErrorsLib.PrincipalTokenIsNotWithdrawable();
86
+ if (token == core.getPrincipalTokenAddress())
87
+ revert Error.PrincipalTokenIsNotWithdrawable();
82
88
 
83
- if (evvm.getBalance(msg.sender, token) < amount)
84
- revert ErrorsLib.InsufficientBalance();
89
+ if (core.getBalance(msg.sender, token) < amount)
90
+ revert Error.InsufficientBalance();
85
91
 
86
92
  if (token == address(0)) {
87
93
  /// user is trying to withdraw native coin
88
94
 
89
- evvm.removeAmountFromUser(msg.sender, address(0), amount);
95
+ core.removeAmountFromUser(msg.sender, address(0), amount);
90
96
  SafeTransferLib.safeTransferETH(msg.sender, amount);
91
97
  } else {
92
98
  /// user is trying to withdraw ERC20 tokens
93
99
 
94
- evvm.removeAmountFromUser(msg.sender, token, amount);
100
+ core.removeAmountFromUser(msg.sender, token, amount);
95
101
  IERC20(token).transfer(msg.sender, amount);
96
102
  }
97
103
  }
98
104
 
99
- function getEvvmAddress() external view returns (address) {
100
- return address(evvm);
105
+ /**
106
+ * @notice Returns the address of the connected EVVM core contract
107
+ * @dev Used for verification and integration purposes
108
+ * @return Address of the EVVM contract managing balances
109
+ */
110
+ function getCoreAddress() external view returns (address) {
111
+ return address(core);
101
112
  }
102
113
  }