@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.
- package/README.md +44 -24
- package/contracts/core/Core.sol +1392 -0
- package/contracts/core/lib/CoreStorage.sol +171 -0
- package/contracts/nameService/NameService.sol +613 -543
- package/contracts/nameService/lib/IdentityValidation.sol +15 -21
- package/contracts/p2pSwap/P2PSwap.sol +258 -145
- package/contracts/staking/Estimator.sol +25 -44
- package/contracts/staking/Staking.sol +284 -262
- package/contracts/treasury/Treasury.sol +40 -47
- 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} +58 -25
- package/interfaces/IEstimator.sol +1 -1
- package/interfaces/INameService.sol +46 -49
- package/interfaces/IP2PSwap.sol +16 -17
- package/interfaces/IStaking.sol +21 -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 +336 -471
- package/library/EvvmService.sol +27 -71
- 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/{contracts/treasury/lib/ErrorsLib.sol → library/errors/TreasuryError.sol} +9 -17
- 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 +62 -44
- package/library/utils/CAUtils.sol +29 -0
- package/library/utils/governance/Admin.sol +66 -0
- package/library/utils/governance/ProposalStructs.sol +49 -0
- package/library/utils/service/CoreExecution.sol +158 -0
- package/library/utils/service/StakingServiceUtils.sol +20 -37
- 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 +1 -1
- package/contracts/evvm/Evvm.sol +0 -1300
- package/contracts/evvm/lib/ErrorsLib.sol +0 -131
- package/contracts/evvm/lib/EvvmStorage.sol +0 -217
- package/contracts/evvm/lib/EvvmStructs.sol +0 -208
- package/contracts/evvm/lib/SignatureUtils.sol +0 -162
- package/contracts/nameService/lib/ErrorsLib.sol +0 -155
- package/contracts/nameService/lib/NameServiceStructs.sol +0 -125
- package/contracts/nameService/lib/SignatureUtils.sol +0 -420
- package/contracts/p2pSwap/lib/P2PSwapStructs.sol +0 -59
- package/contracts/p2pSwap/lib/SignatureUtils.sol +0 -98
- package/contracts/staking/lib/ErrorsLib.sol +0 -98
- package/contracts/staking/lib/SignatureUtils.sol +0 -105
- package/contracts/staking/lib/StakingStructs.sol +0 -106
- 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 -74
- package/library/utils/nonces/SyncNonce.sol +0 -71
- 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.
|
|
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
|
|
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 {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
|
-
|
|
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
|
-
* @dev
|
|
52
|
-
*
|
|
53
|
-
*
|
|
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
|
|
62
|
+
revert Error.DepositAmountMustBeGreaterThanZero();
|
|
65
63
|
|
|
66
|
-
if (amount != msg.value) revert
|
|
64
|
+
if (amount != msg.value) revert Error.InvalidDepositAmount();
|
|
67
65
|
|
|
68
|
-
|
|
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
|
|
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
|
-
|
|
75
|
+
core.addAmountToUser(msg.sender, token, amount);
|
|
79
76
|
}
|
|
80
77
|
}
|
|
81
78
|
|
|
82
79
|
/**
|
|
83
|
-
* @notice
|
|
84
|
-
* @dev
|
|
85
|
-
*
|
|
86
|
-
*
|
|
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 ==
|
|
94
|
-
revert
|
|
86
|
+
if (token == core.getPrincipalTokenAddress())
|
|
87
|
+
revert Error.PrincipalTokenIsNotWithdrawable();
|
|
95
88
|
|
|
96
|
-
if (
|
|
97
|
-
revert
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
118
|
-
return address(
|
|
110
|
+
function getCoreAddress() external view returns (address) {
|
|
111
|
+
return address(core);
|
|
119
112
|
}
|
|
120
113
|
}
|