@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
@@ -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,90 +30,74 @@ 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 {Evvm} from "@evvm/testnet-contracts/contracts/evvm/Evvm.sol";
33
- import {
34
- ErrorsLib
35
- } from "@evvm/testnet-contracts/contracts/treasury/lib/ErrorsLib.sol";
36
-
37
40
  contract Treasury {
38
41
  /// @dev Reference to the EVVM core contract for balance management
39
- Evvm evvm;
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 = Evvm(_evvmAddress);
48
+ constructor(address _coreAddress) {
49
+ core = Core(_coreAddress);
47
50
  }
48
51
 
49
52
  /**
50
- * @notice Deposit ETH or ERC20 tokens into the EVVM ecosystem
51
- * @dev For ETH deposits: token must be address(0) and amount must equal msg.value
52
- * For ERC20 deposits: msg.value must be 0 and token must be a valid ERC20 contract
53
- * Deposited funds are credited to the user's EVVM balance and can be used for
54
- * gasless transactions within the ecosystem.
55
- * @param token ERC20 token address (use address(0) for ETH deposits)
56
- * @param amount Token amount to deposit (must match msg.value for ETH deposits)
57
- * @custom:throws DepositAmountMustBeGreaterThanZero If amount/msg.value is zero
58
- * @custom:throws InvalidDepositAmount If amount doesn't match msg.value (ETH) or msg.value != 0 (ERC20)
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).
59
57
  */
60
58
  function deposit(address token, uint256 amount) external payable {
61
59
  if (address(0) == token) {
62
60
  /// user is sending host native coin
63
61
  if (msg.value == 0)
64
- revert ErrorsLib.DepositAmountMustBeGreaterThanZero();
62
+ revert Error.DepositAmountMustBeGreaterThanZero();
65
63
 
66
- if (amount != msg.value) revert ErrorsLib.InvalidDepositAmount();
64
+ if (amount != msg.value) revert Error.InvalidDepositAmount();
67
65
 
68
- evvm.addAmountToUser(msg.sender, address(0), msg.value);
66
+ core.addAmountToUser(msg.sender, address(0), msg.value);
69
67
  } else {
70
68
  /// user is sending ERC20 tokens
71
69
 
72
- if (msg.value != 0) revert ErrorsLib.DepositCoinWithToken();
70
+ if (msg.value != 0) revert Error.DepositCoinWithToken();
73
71
 
74
- if (amount == 0)
75
- revert ErrorsLib.DepositAmountMustBeGreaterThanZero();
72
+ if (amount == 0) revert Error.DepositAmountMustBeGreaterThanZero();
76
73
 
77
74
  IERC20(token).transferFrom(msg.sender, address(this), amount);
78
- evvm.addAmountToUser(msg.sender, token, amount);
75
+ core.addAmountToUser(msg.sender, token, amount);
79
76
  }
80
77
  }
81
78
 
82
79
  /**
83
- * @notice Withdraw ETH or ERC20 tokens from the EVVM ecosystem
84
- * @dev Withdraws tokens from the user's EVVM balance back to their wallet.
85
- * Principal Tokens cannot be withdrawn through this function - they can
86
- * only be transferred via EVVM pay operations.
87
- * @param token Token address to withdraw (use address(0) for ETH)
88
- * @param amount Amount of tokens to withdraw
89
- * @custom:throws PrincipalTokenIsNotWithdrawable If attempting to withdraw Principal Tokens
90
- * @custom:throws InsufficientBalance If user's EVVM balance is less than withdrawal amount
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.
91
84
  */
92
85
  function withdraw(address token, uint256 amount) external {
93
- if (token == evvm.getPrincipalTokenAddress())
94
- revert ErrorsLib.PrincipalTokenIsNotWithdrawable();
86
+ if (token == core.getPrincipalTokenAddress())
87
+ revert Error.PrincipalTokenIsNotWithdrawable();
95
88
 
96
- if (evvm.getBalance(msg.sender, token) < amount)
97
- revert ErrorsLib.InsufficientBalance();
89
+ if (core.getBalance(msg.sender, token) < amount)
90
+ revert Error.InsufficientBalance();
98
91
 
99
92
  if (token == address(0)) {
100
93
  /// user is trying to withdraw native coin
101
94
 
102
- evvm.removeAmountFromUser(msg.sender, address(0), amount);
95
+ core.removeAmountFromUser(msg.sender, address(0), amount);
103
96
  SafeTransferLib.safeTransferETH(msg.sender, amount);
104
97
  } else {
105
98
  /// user is trying to withdraw ERC20 tokens
106
99
 
107
- evvm.removeAmountFromUser(msg.sender, token, amount);
100
+ core.removeAmountFromUser(msg.sender, token, amount);
108
101
  IERC20(token).transfer(msg.sender, amount);
109
102
  }
110
103
  }
@@ -114,7 +107,7 @@ contract Treasury {
114
107
  * @dev Used for verification and integration purposes
115
108
  * @return Address of the EVVM contract managing balances
116
109
  */
117
- function getEvvmAddress() external view returns (address) {
118
- return address(evvm);
110
+ function getCoreAddress() external view returns (address) {
111
+ return address(core);
119
112
  }
120
113
  }