@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.
- package/LICENSE +145 -118
- package/README.md +162 -39
- package/contracts/core/Core.sol +1394 -0
- package/contracts/core/lib/CoreStorage.sol +171 -0
- package/contracts/nameService/NameService.sol +666 -586
- package/contracts/nameService/lib/IdentityValidation.sol +18 -3
- package/contracts/p2pSwap/P2PSwap.sol +439 -285
- package/contracts/staking/Estimator.sol +128 -40
- package/contracts/staking/Staking.sol +329 -322
- package/contracts/treasury/Treasury.sol +48 -37
- package/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +585 -198
- package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +425 -174
- package/contracts/treasuryTwoChains/lib/PayloadUtils.sol +2 -4
- package/interfaces/{IEvvm.sol → ICore.sol} +67 -29
- package/interfaces/IEstimator.sol +1 -1
- package/interfaces/INameService.sol +58 -52
- package/interfaces/IP2PSwap.sol +18 -17
- package/interfaces/IStaking.sol +22 -17
- package/interfaces/ITreasury.sol +2 -1
- package/interfaces/ITreasuryExternalChainStation.sol +15 -9
- package/interfaces/ITreasuryHostChainStation.sol +14 -11
- package/interfaces/IUserValidator.sol +6 -0
- package/library/Erc191TestBuilder.sol +350 -297
- package/library/EvvmService.sol +38 -27
- package/library/errors/CoreError.sol +116 -0
- package/library/errors/CrossChainTreasuryError.sol +36 -0
- package/library/errors/NameServiceError.sol +79 -0
- package/library/errors/StakingError.sol +79 -0
- package/library/errors/TreasuryError.sol +33 -0
- package/library/primitives/SignatureRecover.sol +33 -0
- package/library/structs/CoreStructs.sol +146 -0
- package/library/structs/ExternalChainStationStructs.sol +92 -0
- package/library/structs/HostChainStationStructs.sol +77 -0
- package/library/structs/NameServiceStructs.sol +47 -0
- package/library/structs/P2PSwapStructs.sol +127 -0
- package/library/structs/StakingStructs.sol +67 -0
- package/library/utils/AdvancedStrings.sol +84 -5
- package/library/utils/CAUtils.sol +29 -0
- package/library/utils/SignatureUtil.sol +34 -0
- package/library/utils/governance/Admin.sol +66 -0
- package/library/utils/governance/ProposalStructs.sol +49 -0
- package/library/utils/service/CoreExecution.sol +177 -0
- package/library/utils/service/StakingServiceUtils.sol +30 -3
- package/library/utils/signature/CoreHashUtils.sol +73 -0
- package/library/utils/signature/NameServiceHashUtils.sol +156 -0
- package/library/utils/signature/P2PSwapHashUtils.sol +65 -0
- package/library/utils/signature/StakingHashUtils.sol +41 -0
- package/library/utils/signature/TreasuryCrossChainHashUtils.sol +40 -0
- package/package.json +2 -1
- package/contracts/evvm/Evvm.sol +0 -1327
- package/contracts/evvm/lib/ErrorsLib.sol +0 -18
- package/contracts/evvm/lib/EvvmStorage.sol +0 -62
- package/contracts/evvm/lib/EvvmStructs.sol +0 -90
- package/contracts/evvm/lib/SignatureUtils.sol +0 -120
- package/contracts/nameService/lib/ErrorsLib.sol +0 -21
- package/contracts/nameService/lib/NameServiceStructs.sol +0 -69
- package/contracts/nameService/lib/SignatureUtils.sol +0 -245
- package/contracts/p2pSwap/lib/P2PSwapStructs.sol +0 -59
- package/contracts/p2pSwap/lib/SignatureUtils.sol +0 -98
- package/contracts/staking/lib/ErrorsLib.sol +0 -22
- package/contracts/staking/lib/SignatureUtils.sol +0 -39
- package/contracts/staking/lib/StakingStructs.sol +0 -94
- package/contracts/treasury/lib/ErrorsLib.sol +0 -11
- package/contracts/treasuryTwoChains/lib/ErrorsLib.sol +0 -48
- package/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +0 -80
- package/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +0 -87
- package/contracts/treasuryTwoChains/lib/SignatureUtils.sol +0 -79
- package/library/utils/GovernanceUtils.sol +0 -81
- package/library/utils/nonces/AsyncNonce.sol +0 -32
- package/library/utils/nonces/SyncNonce.sol +0 -27
- 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.
|
|
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
|
|
33
|
+
* @title EVVM Treasury
|
|
25
34
|
* @author Mate labs
|
|
26
|
-
* @notice
|
|
27
|
-
* @dev
|
|
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
|
-
|
|
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
|
|
46
|
+
* @param _coreAddress Address of the EVVM core contract
|
|
44
47
|
*/
|
|
45
|
-
constructor(address
|
|
46
|
-
|
|
48
|
+
constructor(address _coreAddress) {
|
|
49
|
+
core = Core(_coreAddress);
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
/**
|
|
50
|
-
* @notice
|
|
51
|
-
* @
|
|
52
|
-
* @param
|
|
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
|
|
59
|
-
|
|
62
|
+
revert Error.DepositAmountMustBeGreaterThanZero();
|
|
63
|
+
|
|
64
|
+
if (amount != msg.value) revert Error.InvalidDepositAmount();
|
|
60
65
|
|
|
61
|
-
|
|
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
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
75
|
+
core.addAmountToUser(msg.sender, token, amount);
|
|
71
76
|
}
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
/**
|
|
75
|
-
* @notice
|
|
76
|
-
* @
|
|
77
|
-
* @param
|
|
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 ==
|
|
81
|
-
revert
|
|
86
|
+
if (token == core.getPrincipalTokenAddress())
|
|
87
|
+
revert Error.PrincipalTokenIsNotWithdrawable();
|
|
82
88
|
|
|
83
|
-
if (
|
|
84
|
-
revert
|
|
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
|
-
|
|
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
|
-
|
|
100
|
+
core.removeAmountFromUser(msg.sender, token, amount);
|
|
95
101
|
IERC20(token).transfer(msg.sender, amount);
|
|
96
102
|
}
|
|
97
103
|
}
|
|
98
104
|
|
|
99
|
-
|
|
100
|
-
|
|
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
|
}
|