@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
@@ -1,1327 +0,0 @@
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
- * @title EVVM (Ethereum Virtual Machine Virtualization) Core Contract
22
- * @author Mate labs
23
- * @notice Core payment processing and token management system for the EVVM ecosystem
24
- * @dev This contract serves as the central hub for:
25
- * - Multi-token payment processing with signature verification
26
- * - Staker reward distribution and incentive mechanisms
27
- * - Cross-chain bridge functionality (Fisher Bridge)
28
- * - Balance management across the EVVM ecosystem
29
- * - Integration with NameService for identity-based payments
30
- * - Treasury integration for privileged balance operations
31
- *
32
- * Key Features:
33
- * - Synchronous and asynchronous payment processing with nonce management
34
- * - Staker privilege system with enhanced rewards and transaction processing benefits
35
- * - Multi-recipient payment batching (payMultiple, dispersePay)
36
- * - Administrative payment distribution (caPay, disperseCaPay)
37
- * - Proxy pattern support with delegatecall fallback for upgradeability
38
- * - Cross-chain asset bridging capabilities through Fisher Bridge
39
- * - Deflationary tokenomics with era-based reward halving mechanism
40
- * - Treasury-controlled balance management for minting and burning operations
41
- *
42
- * Payment Types:
43
- * - `payNoStaker_*`: Standard payments for non-stakers with basic functionality
44
- * - `payStaker_*`: Enhanced payments for Principal Token stakers with priority fee rewards
45
- * - `payMultiple`: Batch payments to multiple recipients with individual success tracking
46
- * - `dispersePay`: Single-source multi-recipient distribution with signature verification
47
- * - `caPay`: Administrative token distribution for smart contracts
48
- * - Treasury functions: Direct balance manipulation for authorized operations
49
- *
50
- * Economic Model:
51
- * - Principal Token as principal token with reward distribution system
52
- * - Era-based reward halving when supply thresholds are reached
53
- * - Staker incentives through transaction processing rewards
54
- * - Random bonus rewards for triggering era transitions
55
- *
56
- * Security Features:
57
- * - Signature-based transaction authorization with EIP-191 compliance
58
- * - Dual nonce system: synchronous (sequential) and asynchronous (custom)
59
- * - Executor validation for delegated transaction processing
60
- * - Balance verification before transfers to prevent overdrafts
61
- * - Time-delayed governance for critical upgrades (30-day implementation, 1-day admin)
62
- * - Access control through admin and treasury authorization
63
- *
64
- * Integration Points:
65
- * - NameService: Identity resolution for username-based payments
66
- * - Staking Contract: Staker status management and reward distribution
67
- * - Treasury Contract: Privileged balance operations and token management
68
- * - Implementation Contract: Proxy pattern for contract upgradeability
69
- *
70
- * @custom:version 1.0.0
71
- * @custom:testnet This contract is deployed on testnet for development and testing
72
- * @custom:security Time-delayed governance, signature verification, access control
73
- * @custom:upgrade-pattern Transparent proxy with admin-controlled implementation
74
- */
75
-
76
- import {NameService} from "@evvm/testnet-contracts/contracts/nameService/NameService.sol";
77
- import {EvvmStorage} from "@evvm/testnet-contracts/contracts/evvm/lib/EvvmStorage.sol";
78
- import {ErrorsLib} from "@evvm/testnet-contracts/contracts/evvm/lib/ErrorsLib.sol";
79
- import {SignatureUtils} from "@evvm/testnet-contracts/contracts/evvm/lib/SignatureUtils.sol";
80
- import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
81
-
82
- contract Evvm is EvvmStorage {
83
- /**
84
- * @notice Access control modifier restricting function calls to the current admin
85
- * @dev Validates that msg.sender matches the current admin address before function execution
86
- *
87
- * Access Control:
88
- * - Only the current admin can call functions with this modifier
89
- * - Uses the admin.current address from the storage structure
90
- * - Reverts with no specific error message for unauthorized calls
91
- *
92
- * Usage:
93
- * - Applied to critical administrative functions
94
- * - Protects system configuration changes
95
- * - Prevents unauthorized upgrades and parameter modifications
96
- *
97
- * Security:
98
- * - Simple but effective access control mechanism
99
- * - Used for proxy upgrades, admin transfers, and system configuration
100
- * - Part of the time-delayed governance system for critical operations
101
- */
102
- modifier onlyAdmin() {
103
- if (msg.sender != admin.current) {
104
- revert();
105
- }
106
- _;
107
- }
108
-
109
- /**
110
- * @notice Initializes the EVVM contract with essential configuration and token distributions
111
- * @dev Sets up the core system parameters, admin roles, and initial Principal Token allocations
112
- *
113
- * Critical Initial Setup:
114
- * - Configures admin address with full administrative privileges
115
- * - Sets staking contract address for reward distribution and status management
116
- * - Stores EVVM metadata including principal token address and reward parameters
117
- * - Distributes initial MATE tokens to staking contract (2x reward amount)
118
- * - Registers staking contract as privileged staker with full benefits
119
- * - Activates breaker flag for one-time NameService and Treasury setup
120
- *
121
- * Token Distribution:
122
- * - Staking contract receives 2x current reward amount in MATE tokens
123
- * - Enables immediate reward distribution capabilities
124
- * - Provides operational liquidity for staking rewards
125
- *
126
- * Security Initialization:
127
- * - Sets admin.current for immediate administrative access
128
- * - Prepares system for NameService and Treasury integration
129
- * - Establishes staking privileges for the staking contract
130
- *
131
- * Post-Deployment Requirements:
132
- * - Must call `_setupNameServiceAndTreasuryAddress()` to complete integration
133
- * - NameService and Treasury addresses must be configured before full operation
134
- * - Implementation contract should be set for proxy functionality
135
- *
136
- * @param _initialOwner Address that will have administrative privileges over the contract
137
- * @param _stakingContractAddress Address of the staking contract for reward distribution and staker management
138
- * @param _evvmMetadata Metadata structure containing principal token address, reward amounts, and system parameters
139
- *
140
- * @custom:deployment Must be followed by NameService and Treasury setup
141
- * @custom:security Admin address has full control over system configuration
142
- */
143
- constructor(
144
- address _initialOwner,
145
- address _stakingContractAddress,
146
- EvvmMetadata memory _evvmMetadata
147
- ) {
148
- evvmMetadata = _evvmMetadata;
149
-
150
- stakingContractAddress = _stakingContractAddress;
151
-
152
- admin.current = _initialOwner;
153
-
154
- balances[_stakingContractAddress][evvmMetadata.principalTokenAddress] =
155
- getRewardAmount() *
156
- 2;
157
-
158
- stakerList[_stakingContractAddress] = FLAG_IS_STAKER;
159
-
160
- breakerSetupNameServiceAddress = FLAG_IS_STAKER;
161
- }
162
-
163
- /**
164
- * @notice One-time setup function to configure NameService and Treasury contract addresses
165
- * @dev Can only be called once due to breaker flag mechanism for security
166
- *
167
- * Critical Setup Process:
168
- * - Validates the breaker flag is active (prevents multiple calls)
169
- * - Sets the NameService contract address for identity resolution in payments
170
- * - Configures the Treasury contract address for privileged balance operations
171
- * - Provides initial Principal Token balance (10,000 MATE) to NameService for operations
172
- * - Registers NameService as a privileged staker for enhanced functionality and rewards
173
- *
174
- * Security Features:
175
- * - Single-use function protected by breaker flag
176
- * - Prevents unauthorized reconfiguration of critical system addresses
177
- * - Must be called during initial system deployment phase
178
- *
179
- * Initial Token Distribution:
180
- * - NameService receives 10,000 MATE tokens for operational expenses
181
- * - NameService gains staker privileges for transaction processing
182
- * - Enables identity-based payment resolution throughout the ecosystem
183
- *
184
- * @param _nameServiceAddress Address of the deployed NameService contract for identity resolution
185
- * @param _treasuryAddress Address of the Treasury contract for balance management operations
186
- *
187
- * @custom:security Single-use function - can only be called once
188
- * @custom:access-control No explicit access control - relies on deployment sequence
189
- * @custom:integration Critical for NameService and Treasury functionality
190
- */
191
- function _setupNameServiceAndTreasuryAddress(
192
- address _nameServiceAddress,
193
- address _treasuryAddress
194
- ) external {
195
- if (breakerSetupNameServiceAddress == 0x00) {
196
- revert();
197
- }
198
- nameServiceAddress = _nameServiceAddress;
199
- balances[nameServiceAddress][evvmMetadata.principalTokenAddress] =
200
- 10000 *
201
- 10 ** 18;
202
- stakerList[nameServiceAddress] = FLAG_IS_STAKER;
203
-
204
- treasuryAddress = _treasuryAddress;
205
- }
206
-
207
- /**
208
- * @notice Updates the EVVM ID with a new value, restricted to admin and time-limited
209
- * @dev Allows the admin to change the EVVM ID within a 1-day window after deployment
210
- */
211
- function setEvvmID(uint256 newEvvmID) external onlyAdmin {
212
- if (evvmMetadata.EvvmID != 0) {
213
- if (block.timestamp > windowTimeToChangeEvvmID)
214
- revert ErrorsLib.WindowToChangeEvvmIDExpired();
215
- }
216
-
217
- evvmMetadata.EvvmID = newEvvmID;
218
-
219
- windowTimeToChangeEvvmID = block.timestamp + 24 hours;
220
- }
221
-
222
- /**
223
- * @notice Fallback function implementing proxy pattern with delegatecall to implementation
224
- * @dev Routes all unrecognized function calls to the current implementation contract
225
- *
226
- * Proxy Mechanism:
227
- * - Forwards all calls not handled by this contract to the implementation
228
- * - Uses delegatecall to preserve storage context and msg.sender
229
- * - Allows for contract upgrades without changing the main contract address
230
- * - Maintains all state variables in the proxy contract storage
231
- *
232
- * Implementation Process:
233
- * 1. Validates that an implementation contract is set
234
- * 2. Copies all calldata to memory for forwarding
235
- * 3. Executes delegatecall to implementation with full gas allowance
236
- * 4. Copies the return data back from the implementation
237
- * 5. Returns the result or reverts based on implementation response
238
- *
239
- * Security Features:
240
- * - Reverts if no implementation is set (prevents undefined behavior)
241
- * - Preserves all gas for the implementation call
242
- * - Maintains exact return data and revert behavior from implementation
243
- * - Uses storage slot reading for gas efficiency
244
- *
245
- * Upgrade Compatibility:
246
- * - Enables seamless contract upgrades through implementation changes
247
- * - Preserves all existing state and user balances
248
- * - Allows new functionality addition without user migration
249
- * - Supports time-delayed upgrade governance for security
250
- *
251
- * @custom:security Requires valid implementation address
252
- * @custom:proxy Transparent proxy pattern implementation
253
- * @custom:upgrade-safe Preserves storage layout between upgrades
254
- */
255
- fallback() external {
256
- if (currentImplementation == address(0)) revert();
257
-
258
- assembly {
259
- /**
260
- * Copy the data of the call
261
- * copy s bytes of calldata from position
262
- * f to mem in position t
263
- * calldatacopy(t, f, s)
264
- */
265
- calldatacopy(0, 0, calldatasize())
266
-
267
- /**
268
- * 2. We make a delegatecall to the implementation
269
- * and we copy the result
270
- */
271
- let result := delegatecall(
272
- gas(), // Send all the available gas
273
- sload(currentImplementation.slot), // Address of the implementation
274
- 0, // Start of the memory where the data is
275
- calldatasize(), // Size of the data
276
- 0, // Where we will store the response
277
- 0 // Initial size of the response
278
- )
279
-
280
- /// Copy the response
281
- returndatacopy(0, 0, returndatasize())
282
-
283
- /// Handle the result
284
- switch result
285
- case 0 {
286
- revert(0, returndatasize()) // If it failed, revert
287
- }
288
- default {
289
- return(0, returndatasize()) // If it worked, return
290
- }
291
- }
292
- }
293
-
294
- /**
295
- * @notice Faucet function to add balance to a user's account for testing purposes
296
- * @dev This function is intended for testnet use only to provide tokens for testing
297
- * @param user The address of the user to receive the balance
298
- * @param token The address of the token contract to add balance for
299
- * @param quantity The amount of tokens to add to the user's balance
300
- */
301
- function addBalance(
302
- address user,
303
- address token,
304
- uint256 quantity
305
- ) external {
306
- balances[user][token] += quantity;
307
- }
308
-
309
- /**
310
- * @notice Faucet function to set point staker status for testing purposes
311
- * @dev This function is intended for testnet use only to configure staker points for testing
312
- * @param user The address of the user to set as point staker
313
- * @param answer The bytes1 value representing the staker status or answer
314
- */
315
- function setPointStaker(address user, bytes1 answer) external {
316
- stakerList[user] = answer;
317
- }
318
-
319
- //░▒▓█ Payment Functions ████████████████████████████████████████████████████████▓▒░
320
-
321
- /**
322
- * @notice Processes single payments
323
- *
324
- * Payment Flow:
325
- * - Validates signature authorization for the payment
326
- * (if synchronous nonce, uses nextSyncUsedNonce inside
327
- * the signature verification to verify the correct nonce)
328
- * - Checks executor permission if specified
329
- * - Validates synchronous nonce matches expected value
330
- * - Resolves recipient address (identity or direct address)
331
- * - If the fisher (msg.sender) is a staker:
332
- * - Transfers priority fee to the fisher
333
- * - Rewards the fisher with Principal tokens
334
- * - Updates balances and increments nonce
335
- *
336
- * @param from Address of the payment sender
337
- * @param to_address Direct recipient address (used if to_identity is empty)
338
- * @param to_identity Username/identity of recipient (resolved via NameService)
339
- * @param token Address of the token contract to transfer
340
- * @param amount Amount of tokens to transfer
341
- * @param priorityFee Additional fee for transaction priority (not used in non-staker payments)
342
- * @param nonce Transaction nonce
343
- * @param priorityFlag Execution type flag (false = sync nonce, true = async nonce)
344
- * @param executor Address authorized to execute this transaction (zero address = sender only)
345
- * @param signature Cryptographic signature authorizing this payment
346
- */
347
- function pay(
348
- address from,
349
- address to_address,
350
- string memory to_identity,
351
- address token,
352
- uint256 amount,
353
- uint256 priorityFee,
354
- uint256 nonce,
355
- bool priorityFlag,
356
- address executor,
357
- bytes memory signature
358
- ) external {
359
- if (
360
- !SignatureUtils.verifyMessageSignedForPay(
361
- evvmMetadata.EvvmID,
362
- from,
363
- to_address,
364
- to_identity,
365
- token,
366
- amount,
367
- priorityFee,
368
- nonce,
369
- priorityFlag,
370
- executor,
371
- signature
372
- )
373
- ) revert ErrorsLib.InvalidSignature();
374
-
375
- if ((executor != address(0)) && (msg.sender != executor))
376
- revert ErrorsLib.SenderIsNotTheExecutor();
377
-
378
- if (priorityFlag) {
379
- if (asyncUsedNonce[from][nonce])
380
- revert ErrorsLib.AsyncNonceAlreadyUsed();
381
- } else {
382
- if (nextSyncUsedNonce[from] != nonce)
383
- revert ErrorsLib.SyncNonceMismatch();
384
- }
385
-
386
- address to = !AdvancedStrings.equal(to_identity, "")
387
- ? NameService(nameServiceAddress).verifyStrictAndGetOwnerOfIdentity(
388
- to_identity
389
- )
390
- : to_address;
391
-
392
- if (!_updateBalance(from, to, token, amount))
393
- revert ErrorsLib.UpdateBalanceFailed();
394
-
395
- if (isAddressStaker(msg.sender)) {
396
- if (priorityFee > 0) {
397
- if (!_updateBalance(from, msg.sender, token, priorityFee))
398
- revert ErrorsLib.UpdateBalanceFailed();
399
- }
400
- _giveReward(msg.sender, 1);
401
- }
402
-
403
- if (priorityFlag) {
404
- asyncUsedNonce[from][nonce] = true;
405
- } else {
406
- nextSyncUsedNonce[from]++;
407
- }
408
- }
409
-
410
- /**
411
- * @notice Processes multiple payments in a single transaction batch
412
- * @dev Executes an array of payment operations with individual success/failure tracking
413
- *
414
- * Batch Processing Features:
415
- * - Processes each payment independently (partial success allowed)
416
- * - Returns detailed results for each transaction
417
- * - Supports both staker and non-staker payment types
418
- * - Handles both sync and async nonce types per payment
419
- * - Provides comprehensive transaction statistics
420
- *
421
- * Payment Validation:
422
- * - Each payment signature is verified independently
423
- * - Nonce management handled per payment type (sync/async)
424
- * - Identity resolution performed for each recipient
425
- * - Balance updates executed atomically per payment
426
- *
427
- * Return Values:
428
- * - successfulTransactions: Count of completed payments
429
- * - results: Boolean array indicating success/failure for each payment
430
- *
431
- * @param payData Array of PayData structures containing payment details
432
- * @return successfulTransactions Number of payments that completed successfully
433
- * @return results Boolean array with success status for each payment
434
- */
435
- function payMultiple(
436
- PayData[] memory payData
437
- ) external returns (uint256 successfulTransactions, bool[] memory results) {
438
- address to_aux;
439
- results = new bool[](payData.length);
440
- for (uint256 iteration = 0; iteration < payData.length; iteration++) {
441
- if (
442
- !SignatureUtils.verifyMessageSignedForPay(
443
- evvmMetadata.EvvmID,
444
- payData[iteration].from,
445
- payData[iteration].to_address,
446
- payData[iteration].to_identity,
447
- payData[iteration].token,
448
- payData[iteration].amount,
449
- payData[iteration].priorityFee,
450
- payData[iteration].nonce,
451
- payData[iteration].priorityFlag,
452
- payData[iteration].executor,
453
- payData[iteration].signature
454
- )
455
- ) revert ErrorsLib.InvalidSignature();
456
-
457
- if (payData[iteration].executor != address(0)) {
458
- if (msg.sender != payData[iteration].executor) {
459
- results[iteration] = false;
460
- continue;
461
- }
462
- }
463
-
464
- if (payData[iteration].priorityFlag) {
465
- /// @dev priorityFlag == true (async)
466
-
467
- if (
468
- !asyncUsedNonce[payData[iteration].from][
469
- payData[iteration].nonce
470
- ]
471
- ) {
472
- asyncUsedNonce[payData[iteration].from][
473
- payData[iteration].nonce
474
- ] = true;
475
- } else {
476
- results[iteration] = false;
477
- continue;
478
- }
479
- } else {
480
- /// @dev priorityFlag == false (sync)
481
-
482
- if (
483
- nextSyncUsedNonce[payData[iteration].from] ==
484
- payData[iteration].nonce
485
- ) {
486
- nextSyncUsedNonce[payData[iteration].from]++;
487
- } else {
488
- results[iteration] = false;
489
- continue;
490
- }
491
- }
492
-
493
- to_aux = !AdvancedStrings.equal(payData[iteration].to_identity, "")
494
- ? NameService(nameServiceAddress)
495
- .verifyStrictAndGetOwnerOfIdentity(
496
- payData[iteration].to_identity
497
- )
498
- : payData[iteration].to_address;
499
-
500
- if (
501
- payData[iteration].priorityFee + payData[iteration].amount >
502
- balances[payData[iteration].from][payData[iteration].token]
503
- ) {
504
- results[iteration] = false;
505
- continue;
506
- }
507
-
508
- if (
509
- !_updateBalance(
510
- payData[iteration].from,
511
- to_aux,
512
- payData[iteration].token,
513
- payData[iteration].amount
514
- )
515
- ) {
516
- results[iteration] = false;
517
- continue;
518
- } else {
519
- if (
520
- payData[iteration].priorityFee > 0 &&
521
- isAddressStaker(msg.sender)
522
- ) {
523
- if (
524
- !_updateBalance(
525
- payData[iteration].from,
526
- msg.sender,
527
- payData[iteration].token,
528
- payData[iteration].priorityFee
529
- )
530
- ) {
531
- results[iteration] = false;
532
- continue;
533
- }
534
- }
535
-
536
- successfulTransactions++;
537
- results[iteration] = true;
538
- }
539
- }
540
-
541
- if (isAddressStaker(msg.sender)) {
542
- _giveReward(msg.sender, successfulTransactions);
543
- }
544
- }
545
-
546
- /**
547
- * @notice Distributes tokens from a single sender to multiple recipients
548
- * @dev Efficient single-source multi-recipient payment distribution with signature verification
549
- *
550
- * Distribution Features:
551
- * - Single signature authorizes distribution to multiple recipients
552
- * - Supports both direct addresses and identity-based recipients
553
- * - Proportional amount distribution based on recipient configurations
554
- * - Integrated priority fee and staker reward system
555
- * - Supports both sync and async nonce management
556
- *
557
- * Verification Process:
558
- * - Validates single signature for entire distribution
559
- * - Checks total amount and priority fee against sender balance
560
- * - Ensures executor permissions and nonce validity
561
- * - Processes each recipient distribution atomically
562
- *
563
- * Staker Benefits:
564
- * - Executor receives priority fee (if staker)
565
- * - MATE reward based on number of successful distributions
566
- *
567
- * @param from Address of the payment sender
568
- * @param toData Array of recipient data with addresses/identities and amounts
569
- * @param token Address of the token contract to distribute
570
- * @param amount Total amount to distribute (must match sum of individual amounts)
571
- * @param priorityFee Fee amount for the transaction executor
572
- * @param nonce Transaction nonce for replay protection
573
- * @param priorityFlag True for async nonce, false for sync nonce
574
- * @param executor Address authorized to execute this distribution
575
- * @param signature Cryptographic signature authorizing this distribution
576
- */
577
- function dispersePay(
578
- address from,
579
- DispersePayMetadata[] memory toData,
580
- address token,
581
- uint256 amount,
582
- uint256 priorityFee,
583
- uint256 nonce,
584
- bool priorityFlag,
585
- address executor,
586
- bytes memory signature
587
- ) external {
588
- if (
589
- !SignatureUtils.verifyMessageSignedForDispersePay(
590
- evvmMetadata.EvvmID,
591
- from,
592
- sha256(abi.encode(toData)),
593
- token,
594
- amount,
595
- priorityFee,
596
- nonce,
597
- priorityFlag,
598
- executor,
599
- signature
600
- )
601
- ) revert ErrorsLib.InvalidSignature();
602
-
603
- if (executor != address(0)) {
604
- if (msg.sender != executor)
605
- revert ErrorsLib.SenderIsNotTheExecutor();
606
- }
607
-
608
- if (priorityFlag) {
609
- if (asyncUsedNonce[from][nonce])
610
- revert ErrorsLib.AsyncNonceAlreadyUsed();
611
- } else {
612
- if (nextSyncUsedNonce[from] != nonce)
613
- revert ErrorsLib.SyncNonceMismatch();
614
- }
615
-
616
- if (balances[from][token] < amount + priorityFee)
617
- revert ErrorsLib.InsufficientBalance();
618
-
619
- uint256 acomulatedAmount = 0;
620
- balances[from][token] -= (amount + priorityFee);
621
- address to_aux;
622
- for (uint256 i = 0; i < toData.length; i++) {
623
- acomulatedAmount += toData[i].amount;
624
-
625
- if (!AdvancedStrings.equal(toData[i].to_identity, "")) {
626
- if (
627
- NameService(nameServiceAddress).strictVerifyIfIdentityExist(
628
- toData[i].to_identity
629
- )
630
- ) {
631
- to_aux = NameService(nameServiceAddress).getOwnerOfIdentity(
632
- toData[i].to_identity
633
- );
634
- }
635
- } else {
636
- to_aux = toData[i].to_address;
637
- }
638
-
639
- balances[to_aux][token] += toData[i].amount;
640
- }
641
-
642
- if (acomulatedAmount != amount)
643
- revert ErrorsLib.InvalidAmount(acomulatedAmount, amount);
644
-
645
- if (isAddressStaker(msg.sender)) {
646
- _giveReward(msg.sender, 1);
647
- balances[msg.sender][token] += priorityFee;
648
- } else {
649
- balances[from][token] += priorityFee;
650
- }
651
-
652
- if (priorityFlag) {
653
- asyncUsedNonce[from][nonce] = true;
654
- } else {
655
- nextSyncUsedNonce[from]++;
656
- }
657
-
658
- }
659
-
660
- /**
661
- * @notice Contract-to-address payment function for authorized smart contracts
662
- * @dev Allows registered contracts to distribute tokens without signature verification
663
- *
664
- * Authorization Model:
665
- * - Only smart contracts (non-EOA addresses) can call this function
666
- * - Calling contract must have sufficient token balance
667
- * - No signature verification required (contract-level authorization)
668
- * - Used primarily for automated distributions and rewards
669
- *
670
- * Use Cases:
671
- * - Staking contract reward distributions
672
- * - NameService fee distributions
673
- * - Automated system payouts
674
- * - Cross-contract token transfers
675
- *
676
- * Security Features:
677
- * - Validates caller is a contract (has bytecode)
678
- * - Checks sufficient balance before transfer
679
- * - Direct balance manipulation for efficiency
680
- *
681
- * @param to Address of the token recipient
682
- * @param token Address of the token contract to transfer
683
- * @param amount Amount of tokens to transfer from calling contract
684
- */
685
- function caPay(address to, address token, uint256 amount) external {
686
- uint256 size;
687
- address from = msg.sender;
688
-
689
- assembly {
690
- /// @dev check the size of the opcode of the address
691
- size := extcodesize(from)
692
- }
693
-
694
- if (size == 0) revert ErrorsLib.NotAnCA();
695
-
696
- if (!_updateBalance(from, to, token, amount))
697
- revert ErrorsLib.UpdateBalanceFailed();
698
-
699
- if (isAddressStaker(msg.sender)) {
700
- _giveReward(msg.sender, 1);
701
- }
702
- }
703
-
704
- /**
705
- * @notice Contract-to-multiple-addresses payment distribution function
706
- * @dev Allows authorized contracts to distribute tokens to multiple recipients efficiently
707
- *
708
- * Batch Distribution Features:
709
- * - Single call distributes to multiple recipients
710
- * - Supports both direct addresses and identity resolution
711
- * - Validates total amount matches sum of individual distributions
712
- * - Optimized for contract-based automated distributions
713
- *
714
- * Authorization Model:
715
- * - Only smart contracts can call this function
716
- * - No signature verification required (contract authorization)
717
- * - Calling contract must have sufficient balance for total distribution
718
- *
719
- * Use Cases:
720
- * - Bulk reward distributions from staking contracts
721
- * - Multi-recipient fee distributions
722
- * - Batch payroll or dividend distributions
723
- * - Cross-contract multi-party settlements
724
- *
725
- * @param toData Array of recipient data containing addresses/identities and amounts
726
- * @param token Address of the token contract to distribute
727
- * @param amount Total amount to distribute (must equal sum of individual amounts)
728
- */
729
- function disperseCaPay(
730
- DisperseCaPayMetadata[] memory toData,
731
- address token,
732
- uint256 amount
733
- ) external {
734
- uint256 size;
735
- address from = msg.sender;
736
-
737
- assembly {
738
- /// @dev check the size of the opcode of the address
739
- size := extcodesize(from)
740
- }
741
-
742
- if (size == 0) revert ErrorsLib.NotAnCA();
743
-
744
- uint256 acomulatedAmount = 0;
745
- if (balances[msg.sender][token] < amount)
746
- revert ErrorsLib.InsufficientBalance();
747
-
748
- balances[msg.sender][token] -= amount;
749
-
750
- for (uint256 i = 0; i < toData.length; i++) {
751
- acomulatedAmount += toData[i].amount;
752
- if (acomulatedAmount > amount)
753
- revert ErrorsLib.InvalidAmount(acomulatedAmount, amount);
754
-
755
- balances[toData[i].toAddress][token] += toData[i].amount;
756
- }
757
-
758
- if (acomulatedAmount != amount)
759
- revert ErrorsLib.InvalidAmount(acomulatedAmount, amount);
760
-
761
- if (isAddressStaker(msg.sender)) {
762
- _giveReward(msg.sender, 1);
763
- }
764
-
765
- }
766
-
767
- //░▒▓█Treasury exclusive functions██████████████████████████████████████████▓▒░
768
-
769
- /**
770
- * @notice Adds tokens to a user's balance in the EVVM system
771
- * @dev Restricted function that can only be called by the authorized treasury contract
772
- *
773
- * Treasury Operations:
774
- * - Allows treasury to mint or credit tokens to user accounts
775
- * - Used for reward distributions, airdrops, or token bridging
776
- * - Direct balance manipulation bypasses normal transfer restrictions
777
- * - No signature verification required (treasury authorization)
778
- *
779
- * Access Control:
780
- * - Only the registered treasury contract can call this function
781
- * - Reverts with SenderIsNotTreasury error for unauthorized callers
782
- * - Provides centralized token distribution mechanism
783
- *
784
- * Use Cases:
785
- * - Cross-chain bridge token minting
786
- * - Administrative reward distributions
787
- * - System-level token allocations
788
- * - Emergency balance corrections
789
- *
790
- * @param user Address of the user to receive tokens
791
- * @param token Address of the token contract to add balance for
792
- * @param amount Amount of tokens to add to the user's balance
793
- *
794
- * @custom:access-control Only treasury contract
795
- * @custom:security No overflow protection needed due to controlled access
796
- */
797
- function addAmountToUser(
798
- address user,
799
- address token,
800
- uint256 amount
801
- ) external {
802
- if (msg.sender != treasuryAddress)
803
- revert ErrorsLib.SenderIsNotTreasury();
804
-
805
- balances[user][token] += amount;
806
- }
807
-
808
- /**
809
- * @notice Removes tokens from a user's balance in the EVVM system
810
- * @dev Restricted function that can only be called by the authorized treasury contract
811
- *
812
- * Treasury Operations:
813
- * - Allows treasury to burn or debit tokens from user accounts
814
- * - Used for cross-chain bridging, penalties, or system corrections
815
- * - Direct balance manipulation bypasses normal transfer protections
816
- * - Can potentially create negative balances if not carefully managed
817
- *
818
- * Access Control:
819
- * - Only the registered treasury contract can call this function
820
- * - Reverts with SenderIsNotTreasury error for unauthorized callers
821
- * - Provides centralized token withdrawal mechanism
822
- *
823
- * Use Cases:
824
- * - Cross-chain bridge token burning
825
- * - Administrative penalty applications
826
- * - System-level token reclamations
827
- * - Emergency balance corrections
828
- *
829
- * Security Considerations:
830
- * - No underflow protection: treasury must ensure sufficient balance
831
- * - Can result in unexpected negative balances if misused
832
- * - Treasury contract should implement additional validation
833
- *
834
- * @param user Address of the user to remove tokens from
835
- * @param token Address of the token contract to remove balance for
836
- * @param amount Amount of tokens to remove from the user's balance
837
- *
838
- * @custom:access-control Only treasury contract
839
- * @custom:security No underflow protection - treasury responsibility
840
- */
841
- function removeAmountFromUser(
842
- address user,
843
- address token,
844
- uint256 amount
845
- ) external {
846
- if (msg.sender != treasuryAddress)
847
- revert ErrorsLib.SenderIsNotTreasury();
848
-
849
- balances[user][token] -= amount;
850
- }
851
-
852
- //█ Internal Functions ███████████████████████████████████████████████████████████████████
853
-
854
- //█ Balance Management Functions █████████████████████████████████████████████
855
-
856
- /**
857
- * @notice Internal function to safely transfer tokens between addresses
858
- * @dev Performs balance validation and atomic transfer with overflow protection
859
- *
860
- * Transfer Process:
861
- * - Validates sender has sufficient balance
862
- * - Performs atomic balance updates using unchecked arithmetic
863
- * - Returns success/failure status for error handling
864
- *
865
- * Security Features:
866
- * - Balance validation prevents overdrafts
867
- * - Unchecked arithmetic for gas optimization (overflow impossible)
868
- * - Returns boolean for caller error handling
869
- *
870
- * @param from Address to transfer tokens from
871
- * @param to Address to transfer tokens to
872
- * @param token Address of the token contract
873
- * @param value Amount of tokens to transfer
874
- * @return success True if transfer completed, false if insufficient balance
875
- */
876
- function _updateBalance(
877
- address from,
878
- address to,
879
- address token,
880
- uint256 value
881
- ) internal returns (bool) {
882
- uint256 fromBalance = balances[from][token];
883
- if (fromBalance < value) {
884
- return false;
885
- } else {
886
- unchecked {
887
- balances[from][token] = fromBalance - value;
888
- balances[to][token] += value;
889
- }
890
- return true;
891
- }
892
- }
893
-
894
- /**
895
- * @notice Internal function to distribute Principal Token rewards to stakers
896
- * @dev Provides incentive distribution for transaction processing and staking participation
897
- *
898
- * Reward System:
899
- * - Calculates reward based on system reward rate and transaction count
900
- * - Directly increases principal token balance for gas efficiency
901
- * - Returns success status for error handling in calling functions
902
- *
903
- * Reward Calculation:
904
- * - Base reward per transaction: evvmMetadata.reward
905
- * - Total reward: base_reward × transaction_amount
906
- * - Added directly to user's Principal Token balance
907
- *
908
- * @param user Address of the staker to receive principal tokenrewards
909
- * @param amount Number of transactions or reward multiplier
910
- * @return success True if reward distribution completed successfully
911
- */
912
- function _giveReward(address user, uint256 amount) internal returns (bool) {
913
- uint256 principalReward = evvmMetadata.reward * amount;
914
- uint256 userBalance = balances[user][
915
- evvmMetadata.principalTokenAddress
916
- ];
917
-
918
- balances[user][evvmMetadata.principalTokenAddress] =
919
- userBalance +
920
- principalReward;
921
-
922
- return (userBalance + principalReward ==
923
- balances[user][evvmMetadata.principalTokenAddress]);
924
- }
925
-
926
- //█ Administrative Functions ██████████████████████████████████████████████████████████████
927
-
928
- //█ Proxy Management Functions █████████████████████████████████████████████
929
-
930
- /**
931
- * @notice Proposes a new implementation contract for the proxy with time delay
932
- * @dev Part of the time-delayed governance system for critical upgrades
933
- *
934
- * Upgrade Security:
935
- * - 30-day time delay for implementation changes
936
- * - Only admin can propose upgrades
937
- * - Allows time for community review and validation
938
- * - Can be rejected before acceptance deadline
939
- *
940
- * @param _newImpl Address of the new implementation contract
941
- */
942
- function proposeImplementation(address _newImpl) external onlyAdmin {
943
- proposalImplementation = _newImpl;
944
- timeToAcceptImplementation =
945
- block.timestamp +
946
- TIME_TO_ACCEPT_IMPLEMENTATION;
947
- }
948
-
949
- /**
950
- * @notice Cancels a pending implementation upgrade proposal
951
- * @dev Allows admin to reject proposed upgrades before the time delay expires
952
- */
953
- function rejectUpgrade() external onlyAdmin {
954
- proposalImplementation = address(0);
955
- timeToAcceptImplementation = 0;
956
- }
957
-
958
- /**
959
- * @notice Accepts a pending implementation upgrade after the time delay
960
- * @dev Executes the proxy upgrade to the new implementation contract
961
- */
962
- function acceptImplementation() external onlyAdmin {
963
- if (block.timestamp < timeToAcceptImplementation) revert();
964
- currentImplementation = proposalImplementation;
965
- proposalImplementation = address(0);
966
- timeToAcceptImplementation = 0;
967
- }
968
-
969
- //█ NameService Integration Functions ████████████████████████████████████████
970
-
971
- /**
972
- * @notice Updates the NameService contract address for identity resolution
973
- * @dev Allows admin to change the NameService integration address
974
- * @param _nameServiceAddress Address of the new NameService contract
975
- */
976
- function setNameServiceAddress(
977
- address _nameServiceAddress
978
- ) external onlyAdmin {
979
- nameServiceAddress = _nameServiceAddress;
980
- }
981
-
982
- //█ Admin Management Functions ███████████████████████████████████████████████
983
-
984
- /**
985
- * @notice Proposes a new admin address with 1-day time delay
986
- * @dev Part of the time-delayed governance system for admin changes
987
- * @param _newOwner Address of the proposed new admin
988
- */
989
- function proposeAdmin(address _newOwner) external onlyAdmin {
990
- if (_newOwner == address(0) || _newOwner == admin.current) {
991
- revert();
992
- }
993
-
994
- admin.proposal = _newOwner;
995
- admin.timeToAccept = block.timestamp + TIME_TO_ACCEPT_PROPOSAL;
996
- }
997
-
998
- /**
999
- * @notice Cancels a pending admin change proposal
1000
- * @dev Allows current admin to reject proposed admin changes
1001
- */
1002
- function rejectProposalAdmin() external onlyAdmin {
1003
- admin.proposal = address(0);
1004
- admin.timeToAccept = 0;
1005
- }
1006
-
1007
- /**
1008
- * @notice Accepts a pending admin proposal and becomes the new admin
1009
- * @dev Can only be called by the proposed admin after the time delay
1010
- */
1011
- function acceptAdmin() external {
1012
- if (block.timestamp < admin.timeToAccept) {
1013
- revert();
1014
- }
1015
- if (msg.sender != admin.proposal) {
1016
- revert();
1017
- }
1018
-
1019
- admin.current = admin.proposal;
1020
-
1021
- admin.proposal = address(0);
1022
- admin.timeToAccept = 0;
1023
- }
1024
-
1025
- //█ Reward System Functions ███████████████████████████████████████████████████████████████
1026
-
1027
- /**
1028
- * @notice Triggers a reward recalculation and era transition in the token economy
1029
- * @dev Implements deflationary tokenomics with halving mechanism and random rewards
1030
- *
1031
- * Era Transition Mechanism:
1032
- * - Activates when total supply exceeds current era token threshold
1033
- * - Moves half of remaining tokens to next era threshold
1034
- * - Halves the base reward amount for future transactions
1035
- * - Provides random Principal Token bonus to caller (1-5083x reward)
1036
- *
1037
- * Economic Impact:
1038
- * - Gradually reduces inflation through reward halving
1039
- * - Creates scarcity as era thresholds become harder to reach
1040
- * - Incentivizes early participation with higher rewards
1041
- * - Provides lottery-style bonus for triggering era transitions
1042
- *
1043
- * Requirements:
1044
- * - Total supply must exceed current era token threshold
1045
- * - Can be called by anyone when conditions are met
1046
- */
1047
- function recalculateReward() public {
1048
- if (evvmMetadata.totalSupply > evvmMetadata.eraTokens) {
1049
- evvmMetadata.eraTokens += ((evvmMetadata.totalSupply -
1050
- evvmMetadata.eraTokens) / 2);
1051
- balances[msg.sender][evvmMetadata.principalTokenAddress] +=
1052
- evvmMetadata.reward *
1053
- getRandom(1, 5083);
1054
- evvmMetadata.reward = evvmMetadata.reward / 2;
1055
- } else {
1056
- revert();
1057
- }
1058
- }
1059
-
1060
- /**
1061
- * @notice Generates a pseudo-random number within a specified range
1062
- * @dev Uses block timestamp and prevrandao for randomness (suitable for non-critical randomness)
1063
- *
1064
- * Randomness Source:
1065
- * - Combines block.timestamp and block.prevrandao
1066
- * - Suitable for reward bonuses and non-security-critical randomness
1067
- * - Not suitable for high-stakes randomness requiring true unpredictability
1068
- *
1069
- * @param min Minimum value (inclusive)
1070
- * @param max Maximum value (inclusive)
1071
- * @return Random number between min and max (inclusive)
1072
- */
1073
- function getRandom(
1074
- uint256 min,
1075
- uint256 max
1076
- ) internal view returns (uint256) {
1077
- return
1078
- min +
1079
- (uint256(
1080
- keccak256(abi.encodePacked(block.timestamp, block.prevrandao))
1081
- ) % (max - min + 1));
1082
- }
1083
-
1084
- //█ Staking Integration Functions █████████████████████████████████████████████████████████
1085
-
1086
- /**
1087
- * @notice Updates staker status for a user address
1088
- * @dev Can only be called by the authorized staking contract
1089
- *
1090
- * Staker Status Management:
1091
- * - Controls who can earn staking rewards and process transactions
1092
- * - Integrates with external staking contract for validation
1093
- * - Updates affect payment processing privileges and reward eligibility
1094
- *
1095
- * Access Control:
1096
- * - Only the registered staking contract can call this function
1097
- * - Ensures staker status changes are properly authorized
1098
- *
1099
- * @param user Address to update staker status for
1100
- * @param answer Bytes1 flag indicating staker status/type
1101
- */
1102
- function pointStaker(address user, bytes1 answer) public {
1103
- if (msg.sender != stakingContractAddress) {
1104
- revert();
1105
- }
1106
- stakerList[user] = answer;
1107
- }
1108
-
1109
- //█ View Functions ████████████████████████████████████████████████████████████████████████
1110
-
1111
- /**
1112
- * @notice Returns the complete EVVM metadata configuration
1113
- * @dev Provides access to system-wide configuration and economic parameters
1114
- *
1115
- * Metadata Contents:
1116
- * - Principal token address (Principal Token)
1117
- * - Current reward amount per transaction
1118
- * - Total supply tracking
1119
- * - Era tokens threshold for reward transitions
1120
- * - System configuration parameters
1121
- *
1122
- * @return Complete EvvmMetadata struct with all system parameters
1123
- */
1124
- function getEvvmMetadata() external view returns (EvvmMetadata memory) {
1125
- return evvmMetadata;
1126
- }
1127
-
1128
- function getPrincipalTokenAddress() external view returns (address) {
1129
- return evvmMetadata.principalTokenAddress;
1130
- }
1131
-
1132
- function getChainHostCoinAddress() external pure returns (address) {
1133
- return address(0);
1134
- }
1135
-
1136
- /**
1137
- * @notice Gets the unique identifier string for this EVVM instance
1138
- * @dev Returns the EvvmID used for distinguishing different EVVM deployments
1139
- * @return Unique EvvmID string
1140
- */
1141
- function getEvvmID() external view returns (uint256) {
1142
- return evvmMetadata.EvvmID;
1143
- }
1144
-
1145
- /**
1146
- * @notice Gets the acceptance deadline for pending token whitelist proposals
1147
- * @dev Returns timestamp when prepared tokens can be added to whitelist
1148
- * @return Timestamp when pending token can be whitelisted (0 if no pending proposal)
1149
- */
1150
- function getWhitelistTokenToBeAddedDateToSet()
1151
- external
1152
- view
1153
- returns (uint256)
1154
- {
1155
- return whitelistTokenToBeAdded_dateToSet;
1156
- }
1157
-
1158
- /**
1159
- * @notice Gets the current NameService contract address
1160
- * @dev Returns the address used for identity resolution in payments
1161
- * @return Address of the integrated NameService contract
1162
- */
1163
- function getNameServiceAddress() external view returns (address) {
1164
- return nameServiceAddress;
1165
- }
1166
-
1167
- /**
1168
- * @notice Gets the authorized staking contract address
1169
- * @dev Returns the address that can modify staker status and receive rewards
1170
- * @return Address of the integrated staking contract
1171
- */
1172
- function getStakingContractAddress() external view returns (address) {
1173
- return stakingContractAddress;
1174
- }
1175
-
1176
- /**
1177
- * @notice Gets the next synchronous nonce for a user
1178
- * @dev Returns the expected nonce for the next sync payment transaction
1179
- * @param user Address to check sync nonce for
1180
- * @return Next synchronous nonce value
1181
- */
1182
- function getNextCurrentSyncNonce(
1183
- address user
1184
- ) external view returns (uint256) {
1185
- return nextSyncUsedNonce[user];
1186
- }
1187
-
1188
- /**
1189
- * @notice Checks if a specific async nonce has been used by a user
1190
- * @dev Verifies nonce status to prevent replay attacks in async payments
1191
- * @param user Address to check nonce usage for
1192
- * @param nonce Specific nonce value to verify
1193
- * @return True if the nonce has been used, false if still available
1194
- */
1195
- function getIfUsedAsyncNonce(
1196
- address user,
1197
- uint256 nonce
1198
- ) external view returns (bool) {
1199
- return asyncUsedNonce[user][nonce];
1200
- }
1201
-
1202
- /**
1203
- * @notice Gets the next Fisher Bridge deposit nonce for a user
1204
- * @dev Returns the expected nonce for the next cross-chain deposit
1205
- * @param user Address to check deposit nonce for
1206
- * @return Next Fisher Bridge deposit nonce
1207
- */
1208
- function getNextFisherDepositNonce(
1209
- address user
1210
- ) external view returns (uint256) {
1211
- return nextFisherDepositNonce[user];
1212
- }
1213
-
1214
- /**
1215
- * @notice Gets the balance of a specific token for a user
1216
- * @dev Returns the current balance stored in the EVVM system
1217
- * @param user Address to check balance for
1218
- * @param token Token contract address to check
1219
- * @return Current token balance for the user
1220
- */
1221
- function getBalance(
1222
- address user,
1223
- address token
1224
- ) external view returns (uint) {
1225
- return balances[user][token];
1226
- }
1227
-
1228
- /**
1229
- * @notice Checks if an address is registered as a staker
1230
- * @dev Verifies staker status for transaction processing privileges and rewards
1231
- * @param user Address to check staker status for
1232
- * @return True if the address is a registered staker
1233
- */
1234
- function isAddressStaker(address user) public view returns (bool) {
1235
- return stakerList[user] == FLAG_IS_STAKER;
1236
- }
1237
-
1238
- /**
1239
- * @notice Gets the current era token threshold for reward transitions
1240
- * @dev Returns the token supply threshold that triggers the next reward halving
1241
- * @return Current era tokens threshold
1242
- */
1243
- function getEraPrincipalToken() public view returns (uint256) {
1244
- return evvmMetadata.eraTokens;
1245
- }
1246
-
1247
- /**
1248
- * @notice Gets the current Principal Token reward amount per transaction
1249
- * @dev Returns the base reward distributed to stakers for transaction processing
1250
- * @return Current reward amount in MATE tokens
1251
- */
1252
- function getRewardAmount() public view returns (uint256) {
1253
- return evvmMetadata.reward;
1254
- }
1255
-
1256
- /**
1257
- * @notice Gets the total supply of the principal token (MATE)
1258
- * @dev Returns the current total supply used for era transition calculations
1259
- * @return Total supply of MATE tokens
1260
- */
1261
- function getPrincipalTokenTotalSupply() public view returns (uint256) {
1262
- return evvmMetadata.totalSupply;
1263
- }
1264
-
1265
- /**
1266
- * @notice Gets the current active implementation contract address
1267
- * @dev Returns the implementation used by the proxy for delegatecalls
1268
- * @return Address of the current implementation contract
1269
- */
1270
- function getCurrentImplementation() public view returns (address) {
1271
- return currentImplementation;
1272
- }
1273
-
1274
- /**
1275
- * @notice Gets the proposed implementation contract address
1276
- * @dev Returns the implementation pending approval for proxy upgrade
1277
- * @return Address of the proposed implementation contract (zero if none)
1278
- */
1279
- function getProposalImplementation() public view returns (address) {
1280
- return proposalImplementation;
1281
- }
1282
-
1283
- /**
1284
- * @notice Gets the acceptance deadline for the pending implementation upgrade
1285
- * @dev Returns timestamp when the proposed implementation can be accepted
1286
- * @return Timestamp when implementation upgrade can be executed (0 if no pending proposal)
1287
- */
1288
- function getTimeToAcceptImplementation() public view returns (uint256) {
1289
- return timeToAcceptImplementation;
1290
- }
1291
-
1292
- /**
1293
- * @notice Gets the current admin address
1294
- * @dev Returns the address with administrative privileges over the contract
1295
- * @return Address of the current admin
1296
- */
1297
- function getCurrentAdmin() public view returns (address) {
1298
- return admin.current;
1299
- }
1300
-
1301
- /**
1302
- * @notice Gets the proposed admin address
1303
- * @dev Returns the address pending approval for admin privileges
1304
- * @return Address of the proposed admin (zero if no pending proposal)
1305
- */
1306
- function getProposalAdmin() public view returns (address) {
1307
- return admin.proposal;
1308
- }
1309
-
1310
- /**
1311
- * @notice Gets the acceptance deadline for the pending admin change
1312
- * @dev Returns timestamp when the proposed admin can accept the role
1313
- * @return Timestamp when admin change can be executed (0 if no pending proposal)
1314
- */
1315
- function getTimeToAcceptAdmin() public view returns (uint256) {
1316
- return admin.timeToAccept;
1317
- }
1318
-
1319
- /**
1320
- * @notice Gets the address of the token pending whitelist approval
1321
- * @dev Returns the token address that can be whitelisted after time delay
1322
- * @return Address of the token prepared for whitelisting (zero if none)
1323
- */
1324
- function getWhitelistTokenToBeAdded() public view returns (address) {
1325
- return whitelistTokenToBeAdded_address;
1326
- }
1327
- }