@evvm/testnet-contracts 1.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 (34) hide show
  1. package/LICENSE +166 -0
  2. package/README.md +216 -0
  3. package/package.json +51 -0
  4. package/src/contracts/evvm/Evvm.sol +1327 -0
  5. package/src/contracts/evvm/EvvmLegacy.sol +1553 -0
  6. package/src/contracts/evvm/lib/ErrorsLib.sol +17 -0
  7. package/src/contracts/evvm/lib/EvvmStorage.sol +60 -0
  8. package/src/contracts/evvm/lib/EvvmStructs.sol +64 -0
  9. package/src/contracts/evvm/lib/SignatureUtils.sol +124 -0
  10. package/src/contracts/nameService/NameService.sol +1751 -0
  11. package/src/contracts/nameService/lib/ErrorsLib.sol +27 -0
  12. package/src/contracts/nameService/lib/SignatureUtils.sol +239 -0
  13. package/src/contracts/staking/Estimator.sol +358 -0
  14. package/src/contracts/staking/Staking.sol +1148 -0
  15. package/src/contracts/staking/lib/ErrorsLib.sol +19 -0
  16. package/src/contracts/staking/lib/SignatureUtils.sol +68 -0
  17. package/src/contracts/treasury/Treasury.sol +104 -0
  18. package/src/contracts/treasury/lib/ErrorsLib.sol +11 -0
  19. package/src/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +551 -0
  20. package/src/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +512 -0
  21. package/src/contracts/treasuryTwoChains/lib/ErrorsLib.sol +15 -0
  22. package/src/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +41 -0
  23. package/src/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +52 -0
  24. package/src/contracts/treasuryTwoChains/lib/SignatureUtils.sol +47 -0
  25. package/src/interfaces/IEstimator.sol +102 -0
  26. package/src/interfaces/IEvvm.sol +195 -0
  27. package/src/interfaces/INameService.sol +283 -0
  28. package/src/interfaces/IStaking.sol +202 -0
  29. package/src/interfaces/ITreasury.sol +17 -0
  30. package/src/interfaces/ITreasuryExternalChainStation.sol +262 -0
  31. package/src/interfaces/ITreasuryHostChainStation.sol +251 -0
  32. package/src/lib/AdvancedStrings.sol +77 -0
  33. package/src/lib/Erc191TestBuilder.sol +402 -0
  34. package/src/lib/SignatureRecover.sol +56 -0
@@ -0,0 +1,19 @@
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 ErrorsLib {
7
+ error SenderIsNotAdmin();
8
+ error SenderIsNotGoldenFisher();
9
+ error InvalidSignatureOnStaking();
10
+ error StakingNonceAlreadyUsed();
11
+ error PresaleStakingDisabled();
12
+ error UserPresaleStakerLimitExceeded();
13
+ error UserIsNotPresaleStaker();
14
+ error PublicStakingDisabled();
15
+ error AddressIsNotAService();
16
+ error UserAndServiceMismatch();
17
+ error UserMustWaitToStakeAgain();
18
+ error UserMustWaitToFullUnstake();
19
+ }
@@ -0,0 +1,68 @@
1
+ // SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
2
+ // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
+
4
+ import {SignatureRecover} from "@evvm/testnet-contracts/lib/SignatureRecover.sol";
5
+ import {AdvancedStrings} from "@evvm/testnet-contracts/lib/AdvancedStrings.sol";
6
+ import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
7
+
8
+ pragma solidity ^0.8.0;
9
+
10
+ library SignatureUtils {
11
+ /**
12
+ * @dev using EIP-191 (https://eips.ethereum.org/EIPS/eip-191) can be used to sign and
13
+ * verify messages, the next functions are used to verify the messages signed
14
+ * by the users
15
+ */
16
+
17
+ function verifyMessageSignedForStake(
18
+ uint256 evvmID,
19
+ address user,
20
+ bool isExternalStaking,
21
+ bool _isStaking,
22
+ uint256 _amountOfStaking,
23
+ uint256 _nonce,
24
+ bytes memory signature
25
+ ) internal pure returns (bool) {
26
+ return
27
+ SignatureRecover.signatureVerification(
28
+ Strings.toString(evvmID),
29
+ isExternalStaking ? "publicStaking" : "presaleStaking",
30
+ string.concat(
31
+ _isStaking ? "true" : "false",
32
+ ",",
33
+ Strings.toString(_amountOfStaking),
34
+ ",",
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)
63
+ ),
64
+ signature,
65
+ user
66
+ );
67
+ }
68
+ }
@@ -0,0 +1,104 @@
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
+ /**
7
+ ░██████████
8
+ ░██
9
+ ░█░██░███░███████░██████ ░███████░██ ░█░██░███░██ ░██
10
+ ░█░███ ░██ ░██ ░█░██ ░██ ░█░███ ░██ ░██
11
+ ░█░██ ░████████░███████░███████░██ ░█░██ ░██ ░██
12
+ ░█░██ ░██ ░██ ░██ ░█░██ ░██░██ ░██ ░███
13
+ ░█░██ ░███████░█████░█░███████ ░█████░█░██ ░█████░██
14
+ ░██
15
+ ░███████
16
+
17
+ ████████╗███████╗███████╗████████╗███╗ ██╗███████╗████████╗
18
+ ╚══██╔══╝██╔════╝██╔════╝╚══██╔══╝████╗ ██║██╔════╝╚══██╔══╝
19
+ ██║ █████╗ ███████╗ ██║ ██╔██╗ ██║█████╗ ██║
20
+ ██║ ██╔══╝ ╚════██║ ██║ ██║╚██╗██║██╔══╝ ██║
21
+ ██║ ███████╗███████║ ██║ ██║ ╚████║███████╗ ██║
22
+ ╚═╝ ╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═══╝╚══════╝ ╚═╝
23
+
24
+ * @title Treasury Contract
25
+ * @author jistro.eth
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
28
+ */
29
+
30
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
31
+ import {SafeTransferLib} from "@solady/utils/SafeTransferLib.sol";
32
+ import {Evvm} from "@evvm/testnet-contracts/contracts/evvm/Evvm.sol";
33
+ import {ErrorsLib} from "@evvm/testnet-contracts/contracts/treasury/lib/ErrorsLib.sol";
34
+
35
+ contract Treasury {
36
+ /// @notice Address of the EVVM core contract
37
+ address public evvmAddress;
38
+
39
+ /**
40
+ * @notice Initialize Treasury with EVVM contract address
41
+ * @param _evvmAddress Address of the EVVM core contract
42
+ */
43
+ constructor(address _evvmAddress) {
44
+ evvmAddress = _evvmAddress;
45
+ }
46
+
47
+ /**
48
+ * @notice Deposit ETH or ERC20 tokens
49
+ * @param token ERC20 token address (ignored for ETH deposits)
50
+ * @param amount Token amount (ignored for ETH deposits)
51
+ */
52
+ function deposit(address token, uint256 amount) external payable {
53
+ if (address(0) == token) {
54
+ /// user is sending host native coin
55
+ if (msg.value == 0)
56
+ revert ErrorsLib.DepositAmountMustBeGreaterThanZero();
57
+ if (amount != msg.value) revert ErrorsLib.InvalidDepositAmount();
58
+
59
+ Evvm(evvmAddress).addAmountToUser(
60
+ msg.sender,
61
+ address(0),
62
+ msg.value
63
+ );
64
+ } else {
65
+ /// user is sending ERC20 tokens
66
+
67
+ if (msg.value != 0) revert ErrorsLib.InvalidDepositAmount();
68
+ if (amount == 0)
69
+ revert ErrorsLib.DepositAmountMustBeGreaterThanZero();
70
+
71
+ IERC20(token).transferFrom(msg.sender, address(this), amount);
72
+ Evvm(evvmAddress).addAmountToUser(msg.sender, token, amount);
73
+ }
74
+ }
75
+
76
+ /**
77
+ * @notice Withdraw ETH or ERC20 tokens
78
+ * @param token Token address (address(0) for ETH)
79
+ * @param amount Amount to withdraw
80
+ */
81
+ function withdraw(address token, uint256 amount) external {
82
+ if (token == Evvm(evvmAddress).getEvvmMetadata().principalTokenAddress)
83
+ revert ErrorsLib.PrincipalTokenIsNotWithdrawable();
84
+
85
+ if (Evvm(evvmAddress).getBalance(msg.sender, token) < amount)
86
+ revert ErrorsLib.InsufficientBalance();
87
+
88
+ if (token == address(0)) {
89
+ /// user is trying to withdraw native coin
90
+
91
+ Evvm(evvmAddress).removeAmountFromUser(
92
+ msg.sender,
93
+ address(0),
94
+ amount
95
+ );
96
+ SafeTransferLib.safeTransferETH(msg.sender, amount);
97
+ } else {
98
+ /// user is trying to withdraw ERC20 tokens
99
+
100
+ Evvm(evvmAddress).removeAmountFromUser(msg.sender, token, amount);
101
+ IERC20(token).transfer(msg.sender, amount);
102
+ }
103
+ }
104
+ }
@@ -0,0 +1,11 @@
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 ErrorsLib {
7
+ error InsufficientBalance();
8
+ error PrincipalTokenIsNotWithdrawable();
9
+ error InvalidDepositAmount();
10
+ error DepositAmountMustBeGreaterThanZero();
11
+ }