@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
package/library/EvvmService.sol
CHANGED
|
@@ -3,93 +3,49 @@
|
|
|
3
3
|
|
|
4
4
|
pragma solidity ^0.8.0;
|
|
5
5
|
/**
|
|
6
|
-
* @title
|
|
6
|
+
* @title EVVM Service Base Contract
|
|
7
7
|
* @author Mate Labs
|
|
8
|
-
* @notice Abstract base contract for building services
|
|
9
|
-
* @dev
|
|
10
|
-
* It combines multiple utility contracts to offer:
|
|
11
|
-
*
|
|
12
|
-
* Core Capabilities:
|
|
13
|
-
* - Async nonce management for replay protection (AsyncNonce)
|
|
14
|
-
* - Staking utilities for service-level staking (StakingServiceUtils)
|
|
15
|
-
* - Payment processing through the EVVM core (EvvmPayments)
|
|
16
|
-
* - EIP-191 signature verification for gasless transactions
|
|
17
|
-
*
|
|
18
|
-
* Usage:
|
|
19
|
-
* Inherit from this contract and implement your service logic. All signature
|
|
20
|
-
* verification, payment processing, and nonce management are handled automatically.
|
|
21
|
-
*
|
|
22
|
-
* Example:
|
|
23
|
-
* ```solidity
|
|
24
|
-
* contract MyService is EvvmService {
|
|
25
|
-
* constructor(address evvm, address staking)
|
|
26
|
-
* EvvmService(evvm, staking) {}
|
|
27
|
-
*
|
|
28
|
-
* function myFunction(address user, ..., bytes memory sig) external {
|
|
29
|
-
* validateServiceSignature("myFunction", "...", sig, user);
|
|
30
|
-
* // Your logic here
|
|
31
|
-
* }
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
8
|
+
* @notice Abstract base contract for building EVVM services with payment, staking, and nonce management
|
|
9
|
+
* @dev Inherits StakingServiceUtils, CoreExecution, StateManagment. Signatures validated via Core.sol. Community can build custom services.
|
|
34
10
|
*/
|
|
35
11
|
|
|
36
|
-
import {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
import {
|
|
40
|
-
|
|
12
|
+
import {
|
|
13
|
+
CoreExecution
|
|
14
|
+
} from "@evvm/testnet-contracts/library/utils/service/CoreExecution.sol";
|
|
15
|
+
import {
|
|
16
|
+
StakingServiceUtils
|
|
17
|
+
} from "@evvm/testnet-contracts/library/utils/service/StakingServiceUtils.sol";
|
|
41
18
|
|
|
42
|
-
abstract contract EvvmService is
|
|
43
|
-
|
|
44
|
-
StakingServiceUtils,
|
|
45
|
-
EvvmPayments
|
|
46
|
-
{
|
|
47
|
-
/// @dev Thrown when a signature verification fails for a service operation
|
|
19
|
+
abstract contract EvvmService is CoreExecution, StakingServiceUtils {
|
|
20
|
+
/// @dev Thrown when signature validation fails
|
|
48
21
|
error InvalidServiceSignature();
|
|
49
22
|
|
|
50
23
|
/**
|
|
51
|
-
* @notice Initializes
|
|
52
|
-
* @
|
|
53
|
-
* @param
|
|
24
|
+
* @notice Initializes EVVM service with core contract references
|
|
25
|
+
* @dev Initializes StakingServiceUtils, CoreExecution, StateManagment in order
|
|
26
|
+
* @param coreAddress Address of Core.sol contract
|
|
27
|
+
* @param stakingAddress Address of Staking.sol contract
|
|
54
28
|
*/
|
|
55
29
|
constructor(
|
|
56
|
-
address
|
|
30
|
+
address coreAddress,
|
|
57
31
|
address stakingAddress
|
|
58
|
-
) StakingServiceUtils(stakingAddress)
|
|
32
|
+
) StakingServiceUtils(stakingAddress) CoreExecution(coreAddress) {}
|
|
59
33
|
|
|
60
34
|
/**
|
|
61
|
-
* @notice
|
|
62
|
-
* @dev
|
|
63
|
-
*
|
|
64
|
-
* @param functionName Name of the function being called (used in signature message)
|
|
65
|
-
* @param inputs Comma-separated string of function inputs (used in signature message)
|
|
66
|
-
* @param signature The EIP-191 signature to verify
|
|
67
|
-
* @param expectedSigner Address that should have signed the message
|
|
68
|
-
* @custom:throws InvalidServiceSignature If signature verification fails
|
|
35
|
+
* @notice Gets unique EVVM instance identifier for signature validation
|
|
36
|
+
* @dev Returns core.getEvvmID(). Prevents cross-chain replays.
|
|
37
|
+
* @return Unique EVVM instance identifier
|
|
69
38
|
*/
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
string memory inputs,
|
|
73
|
-
bytes memory signature,
|
|
74
|
-
address expectedSigner
|
|
75
|
-
) internal view virtual {
|
|
76
|
-
if (
|
|
77
|
-
!SignatureUtil.verifySignature(
|
|
78
|
-
evvm.getEvvmID(),
|
|
79
|
-
functionName,
|
|
80
|
-
inputs,
|
|
81
|
-
signature,
|
|
82
|
-
expectedSigner
|
|
83
|
-
)
|
|
84
|
-
) revert InvalidServiceSignature();
|
|
39
|
+
function getEvvmID() internal view returns (uint256) {
|
|
40
|
+
return core.getEvvmID();
|
|
85
41
|
}
|
|
86
42
|
|
|
87
43
|
/**
|
|
88
|
-
* @notice
|
|
89
|
-
* @dev Used
|
|
90
|
-
* @return
|
|
44
|
+
* @notice Gets Principal Token (MATE) address
|
|
45
|
+
* @dev Returns core.getPrincipalTokenAddress(). Used for payment operations.
|
|
46
|
+
* @return Address of Principal Token (MATE)
|
|
91
47
|
*/
|
|
92
|
-
function
|
|
93
|
-
return
|
|
48
|
+
function getPrincipalTokenAddress() internal view returns (address) {
|
|
49
|
+
return core.getPrincipalTokenAddress();
|
|
94
50
|
}
|
|
95
51
|
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
* @title CoreError - Error Definitions for EVVM Core
|
|
8
|
+
* @author Mate labs
|
|
9
|
+
* @notice Custom error definitions for Core.sol core contract
|
|
10
|
+
* @dev Custom errors are more gas-efficient than require
|
|
11
|
+
* statements with strings and provide better error
|
|
12
|
+
* handling in client applications.
|
|
13
|
+
*
|
|
14
|
+
* Error Categories:
|
|
15
|
+
* - Access Control: Unauthorized access attempts
|
|
16
|
+
* - Validation: Invalid inputs or state conditions
|
|
17
|
+
* - Balance Management: Insufficient funds or amounts
|
|
18
|
+
* - Time-Lock: Governance time delay mechanisms
|
|
19
|
+
* - Initialization: Setup and configuration errors
|
|
20
|
+
*
|
|
21
|
+
* Integration:
|
|
22
|
+
* - Used exclusively by Core.sol core contract
|
|
23
|
+
* - Includes payment and nonce validation errors
|
|
24
|
+
* - Provides clear failure reasons for users
|
|
25
|
+
*
|
|
26
|
+
* @custom:scope Exclusive to Core.sol contract
|
|
27
|
+
* @custom:security Clear failures without exposing state
|
|
28
|
+
*/
|
|
29
|
+
library CoreError {
|
|
30
|
+
//░▒▓█ Access Control Errors ████████████████████████████████████████████████▓▒░
|
|
31
|
+
|
|
32
|
+
/// @dev Thrown when non-admin calls admin-only function (onlyAdmin modifier)
|
|
33
|
+
error SenderIsNotAdmin();
|
|
34
|
+
|
|
35
|
+
/// @dev Thrown when proxy implementation == address(0)
|
|
36
|
+
error ImplementationIsNotActive();
|
|
37
|
+
|
|
38
|
+
/// @dev Thrown when EIP-191 signature invalid or signer mismatch
|
|
39
|
+
error InvalidSignature();
|
|
40
|
+
|
|
41
|
+
/// @dev Thrown when msg.sender != sender executor address
|
|
42
|
+
error SenderIsNotTheSenderExecutor();
|
|
43
|
+
|
|
44
|
+
/// @dev Thrown when non-treasury calls treasury-only function
|
|
45
|
+
error SenderIsNotTreasury();
|
|
46
|
+
|
|
47
|
+
/// @dev Thrown when non-proposed admin attempts acceptAdmin before timelock
|
|
48
|
+
error SenderIsNotTheProposedAdmin();
|
|
49
|
+
|
|
50
|
+
error OriginIsNotTheOriginExecutor();
|
|
51
|
+
|
|
52
|
+
/// @dev Thrown when EOA calls caPay/disperseCaPay (contract-only functions)
|
|
53
|
+
error NotAnCA();
|
|
54
|
+
|
|
55
|
+
//░▒▓█ Balance and Amount Errors ████████████████████████████████████████████▓▒░
|
|
56
|
+
|
|
57
|
+
/// @dev Thrown when balance < transfer amount
|
|
58
|
+
error InsufficientBalance();
|
|
59
|
+
|
|
60
|
+
/// @dev Thrown when amount validation fails (e.g., dispersePay total != sum)
|
|
61
|
+
error InvalidAmount();
|
|
62
|
+
|
|
63
|
+
//░▒▓█ Initialization and Setup Errors ██████████████████████████████████████▓▒░
|
|
64
|
+
|
|
65
|
+
/// @dev Thrown when one-time setup function called after breaker flag set
|
|
66
|
+
error BreakerExploded();
|
|
67
|
+
|
|
68
|
+
/// @dev Thrown when attempting EVVM ID change after 24h window
|
|
69
|
+
error WindowExpired();
|
|
70
|
+
|
|
71
|
+
/// @dev Thrown when address(0) provided (constructor, setup)
|
|
72
|
+
error AddressCantBeZero();
|
|
73
|
+
|
|
74
|
+
/// @dev Thrown when address validation fails in proposals
|
|
75
|
+
error IncorrectAddressInput();
|
|
76
|
+
|
|
77
|
+
//░▒▓█ Time-Lock Errors █████████████████████████████████████████████████████▓▒░
|
|
78
|
+
|
|
79
|
+
/// @dev Thrown when attempting time-locked action before delay (30d impl, 1d admin)
|
|
80
|
+
error TimeLockNotExpired();
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
/// @dev Thrown when async nonce already consumed
|
|
85
|
+
error AsyncNonceAlreadyUsed();
|
|
86
|
+
|
|
87
|
+
/// @dev Thrown when sync nonce != expected sequential nonce
|
|
88
|
+
error SyncNonceMismatch();
|
|
89
|
+
|
|
90
|
+
/// @dev Thrown when reserving already-reserved async nonce
|
|
91
|
+
error AsyncNonceAlreadyReserved();
|
|
92
|
+
|
|
93
|
+
/// @dev Thrown when revoking non-reserved async nonce
|
|
94
|
+
error AsyncNonceNotReserved();
|
|
95
|
+
|
|
96
|
+
/// @dev Thrown when using reserved async nonce (general check)
|
|
97
|
+
error AsyncNonceIsReserved();
|
|
98
|
+
|
|
99
|
+
/// @dev Thrown when UserValidator blocks user transaction
|
|
100
|
+
error UserCannotExecuteTransaction();
|
|
101
|
+
|
|
102
|
+
/// @dev Thrown when using async nonce reserved by different service
|
|
103
|
+
error AsyncNonceIsReservedByAnotherService();
|
|
104
|
+
|
|
105
|
+
/// @dev Thrown when accepting UserValidator proposal before timelock
|
|
106
|
+
error ProposalForUserValidatorNotReady();
|
|
107
|
+
|
|
108
|
+
/// @dev Thrown when validateAndConsumeNonce caller is EOA (contracts only)
|
|
109
|
+
error MsgSenderIsNotAContract();
|
|
110
|
+
|
|
111
|
+
/// @dev Thrown when accepting EVVM address proposal before timelock
|
|
112
|
+
error ProposalForEvvmAddressNotReady();
|
|
113
|
+
|
|
114
|
+
/// @dev Thrown when reserving nonce with service == address(0)
|
|
115
|
+
error InvalidServiceAddress();
|
|
116
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
* @title Cross-Chain Treasury Error Library
|
|
8
|
+
* @author Mate labs
|
|
9
|
+
* @notice Custom errors for cross-chain treasury operations
|
|
10
|
+
* @dev Gas-efficient errors for TreasuryHostChainStation and TreasuryExternalChainStation. Independent from Core.sol (own nonces).
|
|
11
|
+
*/
|
|
12
|
+
library CrossChainTreasuryError {
|
|
13
|
+
/// @dev Thrown when Core.sol balance < withdrawal amount (host chain only)
|
|
14
|
+
error InsufficientBalance();
|
|
15
|
+
|
|
16
|
+
/// @dev Thrown when attempting to withdraw/bridge Principal Token (MATE). Cannot leave host chain.
|
|
17
|
+
error PrincipalTokenIsNotWithdrawable();
|
|
18
|
+
|
|
19
|
+
/// @dev Thrown when deposit amount validation fails (bounds check or msg.value mismatch)
|
|
20
|
+
error InvalidDepositAmount();
|
|
21
|
+
|
|
22
|
+
/// @dev Thrown when deposit/bridge amount == 0
|
|
23
|
+
error DepositAmountMustBeGreaterThanZero();
|
|
24
|
+
|
|
25
|
+
/// @dev Thrown when msg.sender != Hyperlane mailbox in message handler
|
|
26
|
+
error MailboxNotAuthorized();
|
|
27
|
+
|
|
28
|
+
/// @dev Thrown when message sender address != authorized station (Hyperlane/LayerZero/Axelar validation)
|
|
29
|
+
error SenderNotAuthorized();
|
|
30
|
+
|
|
31
|
+
/// @dev Thrown when origin chain ID != configured chain (Hyperlane domain/LayerZero eid/Axelar chainName)
|
|
32
|
+
error ChainIdNotAuthorized();
|
|
33
|
+
|
|
34
|
+
/// @dev Thrown when setEvvmID called after grace period (windowTimeToChangeEvvmID)
|
|
35
|
+
error WindowToChangeEvvmIDExpired();
|
|
36
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
* @title NameServiceError - Error Definitions for NameService
|
|
8
|
+
* @author Mate labs
|
|
9
|
+
* @notice Custom errors for NameService.sol
|
|
10
|
+
* @dev Gas-efficient errors used exclusively by NameService.sol. Works with Core.sol (nonce validation and payments).
|
|
11
|
+
*/
|
|
12
|
+
library NameServiceError {
|
|
13
|
+
//█ Access Control Errors ███████████████████████████████████████████████████
|
|
14
|
+
|
|
15
|
+
/// @dev Thrown when non-admin calls admin-only function (onlyAdmin modifier)
|
|
16
|
+
error SenderIsNotAdmin();
|
|
17
|
+
|
|
18
|
+
/// @dev Thrown when non-owner attempts to modify username or accept offers
|
|
19
|
+
error UserIsNotOwnerOfIdentity();
|
|
20
|
+
|
|
21
|
+
/// @dev Thrown when non-creator attempts withdrawOffer
|
|
22
|
+
error UserIsNotOwnerOfOffer();
|
|
23
|
+
|
|
24
|
+
/// @dev Thrown when non-proposed admin attempts acceptNewAdmin before timelock
|
|
25
|
+
error SenderIsNotProposedAdmin();
|
|
26
|
+
|
|
27
|
+
//█ Validation Errors ███████████████████████████████████████████████████████
|
|
28
|
+
|
|
29
|
+
/// @dev Thrown when username format invalid (4+ chars, start with letter, alphanumeric)
|
|
30
|
+
error InvalidUsername();
|
|
31
|
+
|
|
32
|
+
/// @dev Thrown when amount == 0 (e.g., makeOffer requires value)
|
|
33
|
+
error AmountMustBeGreaterThanZero();
|
|
34
|
+
|
|
35
|
+
/// @dev Thrown when removing non-existent custom metadata key
|
|
36
|
+
error InvalidKey();
|
|
37
|
+
|
|
38
|
+
/// @dev Thrown when custom metadata value == empty string
|
|
39
|
+
error EmptyCustomMetadata();
|
|
40
|
+
|
|
41
|
+
/// @dev Thrown when admin proposal address/config invalid
|
|
42
|
+
error InvalidAdminProposal();
|
|
43
|
+
|
|
44
|
+
/// @dev Thrown when proposed EVVM address invalid
|
|
45
|
+
error InvalidEvvmAddress();
|
|
46
|
+
|
|
47
|
+
/// @dev Thrown when withdrawal amount invalid or > balance
|
|
48
|
+
error InvalidWithdrawAmount();
|
|
49
|
+
|
|
50
|
+
//█ Registration and Time-Based Errors █████████████████████████████████████
|
|
51
|
+
|
|
52
|
+
/// @dev Thrown when attempting to register already-taken username
|
|
53
|
+
error UsernameAlreadyRegistered();
|
|
54
|
+
|
|
55
|
+
/// @dev Thrown when pre-registration doesn't exist or expired (30min window)
|
|
56
|
+
error PreRegistrationNotValid();
|
|
57
|
+
|
|
58
|
+
/// @dev Thrown when timestamp < current time (offer expiration, future ops)
|
|
59
|
+
error CannotBeBeforeCurrentTime();
|
|
60
|
+
|
|
61
|
+
/// @dev Thrown when operating on expired username (after expireDate)
|
|
62
|
+
error OwnershipExpired();
|
|
63
|
+
|
|
64
|
+
/// @dev Thrown when renewing > 100 years in advance
|
|
65
|
+
error RenewalTimeLimitExceeded();
|
|
66
|
+
|
|
67
|
+
/// @dev Thrown when time-locked governance action attempted prematurely
|
|
68
|
+
error LockTimeNotExpired();
|
|
69
|
+
|
|
70
|
+
//█ Marketplace and Offer Errors ███████████████████████████████████████████
|
|
71
|
+
|
|
72
|
+
/// @dev Thrown when accepting/interacting with expired/non-existent offer (offerer == 0)
|
|
73
|
+
error OfferInactive();
|
|
74
|
+
|
|
75
|
+
//█ Identity Type Errors ██████████████████████████████████████████████████
|
|
76
|
+
|
|
77
|
+
/// @dev Thrown when username operation attempted on pre-registration (flagNotAUsername: 0x01=pre-reg, 0x00=username)
|
|
78
|
+
error IdentityIsNotAUsername();
|
|
79
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
* @title Staking Error Library
|
|
7
|
+
* @author Mate Labs
|
|
8
|
+
* @notice Custom errors for Staking.sol
|
|
9
|
+
* @dev Gas-efficient errors for Staking.sol. Core.sol validates signatures and processes payments.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
library StakingError {
|
|
13
|
+
///▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀
|
|
14
|
+
/// Access Control Errors
|
|
15
|
+
/// ▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀
|
|
16
|
+
|
|
17
|
+
/// @dev Thrown when non-admin calls admin-only function (onlyOwner)
|
|
18
|
+
error SenderIsNotAdmin();
|
|
19
|
+
|
|
20
|
+
/// @dev Thrown when non-goldenFisher attempts goldenStaking (sync nonces with Core.sol)
|
|
21
|
+
error SenderIsNotGoldenFisher();
|
|
22
|
+
|
|
23
|
+
/// @dev Thrown when non-proposed admin attempts acceptNewAdmin (1d delay)
|
|
24
|
+
error SenderIsNotProposedAdmin();
|
|
25
|
+
|
|
26
|
+
///▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀
|
|
27
|
+
/// Presale Staking Errors
|
|
28
|
+
///▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀
|
|
29
|
+
|
|
30
|
+
/// @dev Thrown when presale staking attempted while disabled (allowPresaleStaking.flag == false)
|
|
31
|
+
error PresaleStakingDisabled();
|
|
32
|
+
|
|
33
|
+
/// @dev Thrown when presale user tries to stake beyond 2-token cap
|
|
34
|
+
error UserPresaleStakerLimitExceeded();
|
|
35
|
+
|
|
36
|
+
/// @dev Thrown when non-whitelisted user attempts presaleStaking (max 800 presale stakers)
|
|
37
|
+
error UserIsNotPresaleStaker();
|
|
38
|
+
|
|
39
|
+
/// @dev Thrown when adding presale staker beyond 800 limit (LIMIT_PRESALE_STAKER)
|
|
40
|
+
error LimitPresaleStakersExceeded();
|
|
41
|
+
|
|
42
|
+
///▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀
|
|
43
|
+
/// Public Staking Errors
|
|
44
|
+
///▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀
|
|
45
|
+
|
|
46
|
+
/// @dev Thrown when public staking attempted while disabled (allowPublicStaking.flag == false). Uses Core.sol async nonces.
|
|
47
|
+
error PublicStakingDisabled();
|
|
48
|
+
|
|
49
|
+
///Service Staking Errors
|
|
50
|
+
|
|
51
|
+
/// @dev Thrown when EOA calls service-only function (onlyCA checks code size)
|
|
52
|
+
error AddressIsNotAService();
|
|
53
|
+
|
|
54
|
+
/// @dev Thrown when service stakes for wrong user (user must equal service address)
|
|
55
|
+
error UserAndServiceMismatch();
|
|
56
|
+
|
|
57
|
+
/// @dev Thrown when confirmServiceStaking caller != prepareServiceStaking caller
|
|
58
|
+
error AddressMismatch();
|
|
59
|
+
|
|
60
|
+
/// @dev Thrown when Principal Token transfer != PRICE_OF_STAKING * amountOfStaking (via Evvm.caPay)
|
|
61
|
+
/// @param requiredAmount Exact Principal Tokens needed
|
|
62
|
+
error ServiceDoesNotFulfillCorrectStakingAmount(uint256 requiredAmount);
|
|
63
|
+
|
|
64
|
+
/// @dev Thrown when confirm timestamp != prepare timestamp (atomic 3-step process required)
|
|
65
|
+
error ServiceDoesNotStakeInSameTx();
|
|
66
|
+
|
|
67
|
+
///▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀
|
|
68
|
+
/// Time Lock Errors
|
|
69
|
+
///▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀
|
|
70
|
+
|
|
71
|
+
/// @dev Thrown when re-staking before cooldown expires (secondsToUnlockStaking.current)
|
|
72
|
+
error AddressMustWaitToStakeAgain();
|
|
73
|
+
|
|
74
|
+
/// @dev Thrown when full unstake attempted before lock period (secondsToUnllockFullUnstaking.current = 5 days)
|
|
75
|
+
error AddressMustWaitToFullUnstake();
|
|
76
|
+
|
|
77
|
+
/// @dev Thrown when accepting governance proposal before 1-day delay (TIME_TO_ACCEPT_PROPOSAL)
|
|
78
|
+
error TimeToAcceptProposalNotReached();
|
|
79
|
+
}
|
|
@@ -3,39 +3,31 @@
|
|
|
3
3
|
|
|
4
4
|
pragma solidity ^0.8.0;
|
|
5
5
|
/**
|
|
6
|
-
* @title
|
|
6
|
+
* @title TreasuryError
|
|
7
7
|
* @author Mate Labs
|
|
8
|
-
* @notice
|
|
9
|
-
* @dev
|
|
10
|
-
* error types for deposit and withdrawal operations.
|
|
11
|
-
*
|
|
12
|
-
* Error Categories:
|
|
13
|
-
* - Balance Errors: Insufficient funds for operations
|
|
14
|
-
* - Deposit Errors: Invalid deposit amounts or configurations
|
|
15
|
-
* - Withdrawal Restrictions: Token withdrawal limitations
|
|
8
|
+
* @notice Custom errors for Treasury.sol
|
|
9
|
+
* @dev Gas-efficient error definitions for deposit/withdrawal operations.
|
|
16
10
|
*/
|
|
17
11
|
|
|
18
|
-
library
|
|
12
|
+
library TreasuryError {
|
|
19
13
|
//█ Balance Errors ███████████████████████████████████████████████████████████████████████████████
|
|
20
14
|
|
|
21
|
-
/// @dev Thrown when
|
|
15
|
+
/// @dev Thrown when withdrawal amount > user balance
|
|
22
16
|
error InsufficientBalance();
|
|
23
17
|
|
|
24
18
|
//█ Withdrawal Restriction Errors ████████████████████████████████████████████████████████████████
|
|
25
19
|
|
|
26
|
-
/// @dev Thrown when attempting to withdraw Principal
|
|
27
|
-
/// @notice Principal Tokens can only be transferred through EVVM pay operations, not direct withdrawal
|
|
20
|
+
/// @dev Thrown when attempting to withdraw Principal Token (must use EVVM pay operations)
|
|
28
21
|
error PrincipalTokenIsNotWithdrawable();
|
|
29
22
|
|
|
30
23
|
//█ Deposit Errors ███████████████████████████████████████████████████████████████████████████████
|
|
31
24
|
|
|
32
|
-
/// @dev Thrown when
|
|
33
|
-
/// or when msg.value is non-zero for ERC20 deposits
|
|
25
|
+
/// @dev Thrown when deposit amount != msg.value (ETH) or msg.value != 0 (ERC20)
|
|
34
26
|
error InvalidDepositAmount();
|
|
35
27
|
|
|
36
|
-
/// @dev Thrown when
|
|
28
|
+
/// @dev Thrown when deposit amount == 0
|
|
37
29
|
error DepositAmountMustBeGreaterThanZero();
|
|
38
30
|
|
|
39
|
-
/// @dev Thrown when attempting to deposit
|
|
31
|
+
/// @dev Thrown when attempting to deposit both native coin and ERC20 simultaneously
|
|
40
32
|
error DepositCoinWithToken();
|
|
41
33
|
}
|
|
@@ -0,0 +1,146 @@
|
|
|
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
|
+
* @title CoreStructs
|
|
8
|
+
* @author Mate labs
|
|
9
|
+
* @notice Data structures for Core.sol (payments, governance, metadata)
|
|
10
|
+
* @dev Payment structures with nonce validation. CA structures bypass nonces. Used by CoreStorage then Core.sol.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
library CoreStructs {
|
|
14
|
+
//░▒▓█ Payment Data Structures ██████████████████████████████████████████████████████▓▒░
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @notice Data structure for single payment operations
|
|
18
|
+
* @dev Used in pay() and batchPay(). Validated via State.validateAndConsumeNonce.
|
|
19
|
+
* @param from Payment sender (signer)
|
|
20
|
+
* @param to_address Direct recipient
|
|
21
|
+
* @param to_identity Username via NameService (priority over to_address)
|
|
22
|
+
* @param token Token address (address(0) = ETH)
|
|
23
|
+
* @param amount Token amount
|
|
24
|
+
* @param priorityFee Fee for staker
|
|
25
|
+
* @param senderExecutor Authorized senderExecutor (address(0) = any)
|
|
26
|
+
* @param nonce Replay protection nonce
|
|
27
|
+
* @param isAsyncExec Nonce type (false=sync, true=async)
|
|
28
|
+
* @param signature EIP-191 signature
|
|
29
|
+
*/
|
|
30
|
+
struct BatchData {
|
|
31
|
+
address from;
|
|
32
|
+
address to_address;
|
|
33
|
+
string to_identity;
|
|
34
|
+
address token;
|
|
35
|
+
uint256 amount;
|
|
36
|
+
uint256 priorityFee;
|
|
37
|
+
address senderExecutor;
|
|
38
|
+
uint256 nonce;
|
|
39
|
+
bool isAsyncExec;
|
|
40
|
+
bytes signature;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @notice Single-source multi-recipient payment data
|
|
45
|
+
* @dev Used in dispersePay(). Single nonce for entire batch.
|
|
46
|
+
* @param from Payment sender (signer)
|
|
47
|
+
* @param toData Recipients and amounts
|
|
48
|
+
* @param token Token address (address(0) = ETH)
|
|
49
|
+
* @param totalAmount Total distributed (must equal sum)
|
|
50
|
+
* @param priorityFee Fee for staker
|
|
51
|
+
* @param senderExecutor Authorized senderExecutor (address(0) = any)
|
|
52
|
+
* @param nonce Replay protection nonce
|
|
53
|
+
* @param isAsyncExec Nonce type (false=sync, true=async)
|
|
54
|
+
* @param signature EIP-191 signature
|
|
55
|
+
*/
|
|
56
|
+
struct DisperseBatchData {
|
|
57
|
+
address from;
|
|
58
|
+
DispersePayMetadata[] toData;
|
|
59
|
+
address token;
|
|
60
|
+
uint256 totalAmount;
|
|
61
|
+
uint256 priorityFee;
|
|
62
|
+
address senderExecutor;
|
|
63
|
+
uint256 nonce;
|
|
64
|
+
bool isAsyncExec;
|
|
65
|
+
bytes signature;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @notice Contract-to-address payment data
|
|
70
|
+
* @dev Used in caPay(). No nonce validation (contract-authorized).
|
|
71
|
+
* @param from Sending contract (must be CA)
|
|
72
|
+
* @param to Recipient address
|
|
73
|
+
* @param token Token address (address(0) = ETH)
|
|
74
|
+
* @param amount Token amount
|
|
75
|
+
*/
|
|
76
|
+
struct CaBatchData {
|
|
77
|
+
address from;
|
|
78
|
+
address to;
|
|
79
|
+
address token;
|
|
80
|
+
uint256 amount;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @notice Contract-based multi-recipient distribution
|
|
85
|
+
* @dev Used in disperseCaPay(). No nonce validation (contract-authorized).
|
|
86
|
+
* @param from Sending contract (must be CA)
|
|
87
|
+
* @param toData Recipients and amounts
|
|
88
|
+
* @param token Token address (address(0) = ETH)
|
|
89
|
+
* @param amount Total distributed (must equal sum)
|
|
90
|
+
*/
|
|
91
|
+
struct DisperseCaBatchData {
|
|
92
|
+
address from;
|
|
93
|
+
DisperseCaPayMetadata[] toData;
|
|
94
|
+
address token;
|
|
95
|
+
uint256 amount;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//░▒▓█ Payment Metadata Structures ██████████████████████████████████████████████████▓▒░
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @notice Recipient metadata for user-signed disperses
|
|
102
|
+
* @param amount Tokens to send
|
|
103
|
+
* @param to_address Direct recipient
|
|
104
|
+
* @param to_identity Username via NameService (priority)
|
|
105
|
+
*/
|
|
106
|
+
struct DispersePayMetadata {
|
|
107
|
+
uint256 amount;
|
|
108
|
+
address to_address;
|
|
109
|
+
string to_identity;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @notice Recipient metadata for contract disperses
|
|
114
|
+
* @param amount Tokens to send
|
|
115
|
+
* @param toAddress Recipient address
|
|
116
|
+
*/
|
|
117
|
+
struct DisperseCaPayMetadata {
|
|
118
|
+
uint256 amount;
|
|
119
|
+
address toAddress;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//░▒▓█ System Configuration Structures ██████████████████████████████████████████████▓▒░
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @notice Core metadata configuration for EVVM instance
|
|
126
|
+
* @dev EvvmID used for cross-chain replay protection. Reward halvings occur at eraTokens supply thresholds.
|
|
127
|
+
* @param EvvmName Human-readable instance name
|
|
128
|
+
* @param EvvmID Unique ID for signature verification
|
|
129
|
+
* @param principalTokenName Principal token name
|
|
130
|
+
* @param principalTokenSymbol Principal token symbol
|
|
131
|
+
* @param principalTokenAddress Virtual token address
|
|
132
|
+
* @param totalSupply Current PT supply
|
|
133
|
+
* @param eraTokens Supply threshold for next era
|
|
134
|
+
* @param reward Current reward per transaction
|
|
135
|
+
*/
|
|
136
|
+
struct EvvmMetadata {
|
|
137
|
+
string EvvmName;
|
|
138
|
+
uint256 EvvmID;
|
|
139
|
+
string principalTokenName;
|
|
140
|
+
string principalTokenSymbol;
|
|
141
|
+
address principalTokenAddress;
|
|
142
|
+
uint256 totalSupply;
|
|
143
|
+
uint256 eraTokens;
|
|
144
|
+
uint256 reward;
|
|
145
|
+
}
|
|
146
|
+
}
|