@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.
Files changed (71) hide show
  1. package/LICENSE +145 -118
  2. package/README.md +162 -39
  3. package/contracts/core/Core.sol +1394 -0
  4. package/contracts/core/lib/CoreStorage.sol +171 -0
  5. package/contracts/nameService/NameService.sol +666 -586
  6. package/contracts/nameService/lib/IdentityValidation.sol +18 -3
  7. package/contracts/p2pSwap/P2PSwap.sol +439 -285
  8. package/contracts/staking/Estimator.sol +128 -40
  9. package/contracts/staking/Staking.sol +329 -322
  10. package/contracts/treasury/Treasury.sol +48 -37
  11. package/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +585 -198
  12. package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +425 -174
  13. package/contracts/treasuryTwoChains/lib/PayloadUtils.sol +2 -4
  14. package/interfaces/{IEvvm.sol → ICore.sol} +67 -29
  15. package/interfaces/IEstimator.sol +1 -1
  16. package/interfaces/INameService.sol +58 -52
  17. package/interfaces/IP2PSwap.sol +18 -17
  18. package/interfaces/IStaking.sol +22 -17
  19. package/interfaces/ITreasury.sol +2 -1
  20. package/interfaces/ITreasuryExternalChainStation.sol +15 -9
  21. package/interfaces/ITreasuryHostChainStation.sol +14 -11
  22. package/interfaces/IUserValidator.sol +6 -0
  23. package/library/Erc191TestBuilder.sol +350 -297
  24. package/library/EvvmService.sol +38 -27
  25. package/library/errors/CoreError.sol +116 -0
  26. package/library/errors/CrossChainTreasuryError.sol +36 -0
  27. package/library/errors/NameServiceError.sol +79 -0
  28. package/library/errors/StakingError.sol +79 -0
  29. package/library/errors/TreasuryError.sol +33 -0
  30. package/library/primitives/SignatureRecover.sol +33 -0
  31. package/library/structs/CoreStructs.sol +146 -0
  32. package/library/structs/ExternalChainStationStructs.sol +92 -0
  33. package/library/structs/HostChainStationStructs.sol +77 -0
  34. package/library/structs/NameServiceStructs.sol +47 -0
  35. package/library/structs/P2PSwapStructs.sol +127 -0
  36. package/library/structs/StakingStructs.sol +67 -0
  37. package/library/utils/AdvancedStrings.sol +84 -5
  38. package/library/utils/CAUtils.sol +29 -0
  39. package/library/utils/SignatureUtil.sol +34 -0
  40. package/library/utils/governance/Admin.sol +66 -0
  41. package/library/utils/governance/ProposalStructs.sol +49 -0
  42. package/library/utils/service/CoreExecution.sol +177 -0
  43. package/library/utils/service/StakingServiceUtils.sol +30 -3
  44. package/library/utils/signature/CoreHashUtils.sol +73 -0
  45. package/library/utils/signature/NameServiceHashUtils.sol +156 -0
  46. package/library/utils/signature/P2PSwapHashUtils.sol +65 -0
  47. package/library/utils/signature/StakingHashUtils.sol +41 -0
  48. package/library/utils/signature/TreasuryCrossChainHashUtils.sol +40 -0
  49. package/package.json +2 -1
  50. package/contracts/evvm/Evvm.sol +0 -1327
  51. package/contracts/evvm/lib/ErrorsLib.sol +0 -18
  52. package/contracts/evvm/lib/EvvmStorage.sol +0 -62
  53. package/contracts/evvm/lib/EvvmStructs.sol +0 -90
  54. package/contracts/evvm/lib/SignatureUtils.sol +0 -120
  55. package/contracts/nameService/lib/ErrorsLib.sol +0 -21
  56. package/contracts/nameService/lib/NameServiceStructs.sol +0 -69
  57. package/contracts/nameService/lib/SignatureUtils.sol +0 -245
  58. package/contracts/p2pSwap/lib/P2PSwapStructs.sol +0 -59
  59. package/contracts/p2pSwap/lib/SignatureUtils.sol +0 -98
  60. package/contracts/staking/lib/ErrorsLib.sol +0 -22
  61. package/contracts/staking/lib/SignatureUtils.sol +0 -39
  62. package/contracts/staking/lib/StakingStructs.sol +0 -94
  63. package/contracts/treasury/lib/ErrorsLib.sol +0 -11
  64. package/contracts/treasuryTwoChains/lib/ErrorsLib.sol +0 -48
  65. package/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +0 -80
  66. package/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +0 -87
  67. package/contracts/treasuryTwoChains/lib/SignatureUtils.sol +0 -79
  68. package/library/utils/GovernanceUtils.sol +0 -81
  69. package/library/utils/nonces/AsyncNonce.sol +0 -32
  70. package/library/utils/nonces/SyncNonce.sol +0 -27
  71. package/library/utils/service/EvvmPayments.sol +0 -79
@@ -2,39 +2,50 @@
2
2
  // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
3
 
4
4
  pragma solidity ^0.8.0;
5
+ /**
6
+ * @title EVVM Service Base Contract
7
+ * @author Mate Labs
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.
10
+ */
5
11
 
6
- import {EvvmStructs} from "@evvm/testnet-contracts/interfaces/IEvvm.sol";
7
- import {SignatureUtil} from "@evvm/testnet-contracts/library/utils/SignatureUtil.sol";
8
- import {AsyncNonce} from "@evvm/testnet-contracts/library/utils/nonces/AsyncNonce.sol";
9
- import {StakingServiceUtils} from "@evvm/testnet-contracts/library/utils/service/StakingServiceUtils.sol";
10
- import {EvvmPayments} from "@evvm/testnet-contracts/library/utils/service/EvvmPayments.sol";
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";
11
18
 
12
- abstract contract EvvmService is
13
- AsyncNonce,
14
- StakingServiceUtils,
15
- EvvmPayments
16
- {
19
+ abstract contract EvvmService is CoreExecution, StakingServiceUtils {
20
+ /// @dev Thrown when signature validation fails
17
21
  error InvalidServiceSignature();
18
22
 
23
+ /**
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
28
+ */
19
29
  constructor(
20
- address evvmAddress,
30
+ address coreAddress,
21
31
  address stakingAddress
22
- ) StakingServiceUtils(stakingAddress) EvvmPayments(evvmAddress) {}
32
+ ) StakingServiceUtils(stakingAddress) CoreExecution(coreAddress) {}
23
33
 
24
- function validateServiceSignature(
25
- string memory functionName,
26
- string memory inputs,
27
- bytes memory signature,
28
- address expectedSigner
29
- ) internal view virtual {
30
- if (
31
- !SignatureUtil.verifySignature(
32
- evvm.getEvvmID(),
33
- functionName,
34
- inputs,
35
- signature,
36
- expectedSigner
37
- )
38
- ) revert InvalidServiceSignature();
34
+ /**
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
38
+ */
39
+ function getEvvmID() internal view returns (uint256) {
40
+ return core.getEvvmID();
41
+ }
42
+
43
+ /**
44
+ * @notice Gets Principal Token (MATE) address
45
+ * @dev Returns core.getPrincipalTokenAddress(). Used for payment operations.
46
+ * @return Address of Principal Token (MATE)
47
+ */
48
+ function getPrincipalTokenAddress() internal view returns (address) {
49
+ return core.getPrincipalTokenAddress();
39
50
  }
40
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
+ }
@@ -0,0 +1,33 @@
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 TreasuryError
7
+ * @author Mate Labs
8
+ * @notice Custom errors for Treasury.sol
9
+ * @dev Gas-efficient error definitions for deposit/withdrawal operations.
10
+ */
11
+
12
+ library TreasuryError {
13
+ //█ Balance Errors ███████████████████████████████████████████████████████████████████████████████
14
+
15
+ /// @dev Thrown when withdrawal amount > user balance
16
+ error InsufficientBalance();
17
+
18
+ //█ Withdrawal Restriction Errors ████████████████████████████████████████████████████████████████
19
+
20
+ /// @dev Thrown when attempting to withdraw Principal Token (must use EVVM pay operations)
21
+ error PrincipalTokenIsNotWithdrawable();
22
+
23
+ //█ Deposit Errors ███████████████████████████████████████████████████████████████████████████████
24
+
25
+ /// @dev Thrown when deposit amount != msg.value (ETH) or msg.value != 0 (ERC20)
26
+ error InvalidDepositAmount();
27
+
28
+ /// @dev Thrown when deposit amount == 0
29
+ error DepositAmountMustBeGreaterThanZero();
30
+
31
+ /// @dev Thrown when attempting to deposit both native coin and ERC20 simultaneously
32
+ error DepositCoinWithToken();
33
+ }
@@ -2,11 +2,33 @@
2
2
  // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
3
 
4
4
  pragma solidity ^0.8.0;
5
+ /**
6
+ * @title SignatureRecover
7
+ * @author Mate Labs
8
+ * @notice Library for recovering signer addresses from EIP-191 signed messages
9
+ * @dev Provides utilities for signature verification following the EIP-191 standard.
10
+ * This library is used throughout the EVVM ecosystem for gasless transaction validation.
11
+ *
12
+ * EIP-191 Format:
13
+ * The signed message follows the format:
14
+ * "\x19Ethereum Signed Message:\n" + message.length + message
15
+ *
16
+ * This library can be used by community-developed services to implement
17
+ * signature verification compatible with the EVVM ecosystem.
18
+ */
5
19
 
6
20
  import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
7
21
 
8
22
  library SignatureRecover {
9
23
 
24
+ /**
25
+ * @notice Recovers the signer address from an EIP-191 signed message
26
+ * @dev Uses ecrecover to extract the signer address from the signature components.
27
+ * The message is hashed with the EIP-191 prefix before recovery.
28
+ * @param message The original message that was signed (without prefix)
29
+ * @param signature 65-byte signature in the format (r, s, v)
30
+ * @return The address that signed the message, or address(0) if invalid
31
+ */
10
32
  function recoverSigner(
11
33
  string memory message,
12
34
  bytes memory signature
@@ -22,6 +44,17 @@ library SignatureRecover {
22
44
  return ecrecover(messageHash, v, r, s);
23
45
  }
24
46
 
47
+ /**
48
+ * @notice Splits a 65-byte signature into its r, s, and v components
49
+ * @dev Extracts signature components using assembly for gas efficiency.
50
+ * Handles both pre-EIP-155 and post-EIP-155 signature formats.
51
+ * @param signature 65-byte signature to split
52
+ * @return r First 32 bytes of the signature
53
+ * @return s Second 32 bytes of the signature
54
+ * @return v Recovery identifier (27 or 28)
55
+ * @custom:throws "Invalid signature length" if signature is not 65 bytes
56
+ * @custom:throws "Invalid signature value" if v is not 27 or 28
57
+ */
25
58
  function splitSignature(
26
59
  bytes memory signature
27
60
  ) internal pure returns (bytes32 r, bytes32 s, uint8 v) {
@@ -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
+ }