@evvm/testnet-contracts 2.2.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +145 -118
- package/README.md +135 -42
- package/contracts/evvm/Evvm.sol +154 -181
- package/contracts/evvm/lib/ErrorsLib.sol +119 -6
- package/contracts/evvm/lib/EvvmStorage.sol +164 -9
- package/contracts/evvm/lib/EvvmStructs.sol +124 -6
- package/contracts/evvm/lib/SignatureUtils.sol +103 -61
- package/contracts/nameService/NameService.sol +165 -155
- package/contracts/nameService/lib/ErrorsLib.sol +142 -8
- package/contracts/nameService/lib/IdentityValidation.sol +21 -0
- package/contracts/nameService/lib/NameServiceStructs.sol +75 -19
- package/contracts/nameService/lib/SignatureUtils.sol +235 -60
- package/contracts/p2pSwap/P2PSwap.sol +205 -164
- package/contracts/staking/Estimator.sol +131 -24
- package/contracts/staking/Staking.sol +98 -113
- package/contracts/staking/lib/ErrorsLib.sol +79 -3
- package/contracts/staking/lib/SignatureUtils.sol +82 -16
- package/contracts/staking/lib/StakingStructs.sol +12 -0
- package/contracts/treasury/Treasury.sol +30 -12
- package/contracts/treasury/lib/ErrorsLib.sol +30 -0
- package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +3 -3
- package/interfaces/IEvvm.sol +9 -4
- package/interfaces/INameService.sol +12 -3
- package/interfaces/IStaking.sol +2 -1
- package/library/Erc191TestBuilder.sol +188 -0
- package/library/EvvmService.sol +55 -0
- package/library/primitives/SignatureRecover.sol +33 -0
- package/library/utils/AdvancedStrings.sol +61 -0
- package/library/utils/SignatureUtil.sol +34 -0
- package/library/utils/nonces/AsyncNonce.sol +42 -0
- package/library/utils/nonces/SyncNonce.sol +44 -0
- package/library/utils/service/EvvmPayments.sol +68 -1
- package/library/utils/service/StakingServiceUtils.sol +44 -0
- package/package.json +2 -1
package/contracts/evvm/Evvm.sol
CHANGED
|
@@ -73,11 +73,21 @@ pragma solidity ^0.8.0;
|
|
|
73
73
|
* @custom:upgrade-pattern Transparent proxy with admin-controlled implementation
|
|
74
74
|
*/
|
|
75
75
|
|
|
76
|
-
import {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
import {
|
|
80
|
-
|
|
76
|
+
import {
|
|
77
|
+
NameService
|
|
78
|
+
} from "@evvm/testnet-contracts/contracts/nameService/NameService.sol";
|
|
79
|
+
import {
|
|
80
|
+
EvvmStorage
|
|
81
|
+
} from "@evvm/testnet-contracts/contracts/evvm/lib/EvvmStorage.sol";
|
|
82
|
+
import {
|
|
83
|
+
ErrorsLib
|
|
84
|
+
} from "@evvm/testnet-contracts/contracts/evvm/lib/ErrorsLib.sol";
|
|
85
|
+
import {
|
|
86
|
+
SignatureUtils
|
|
87
|
+
} from "@evvm/testnet-contracts/contracts/evvm/lib/SignatureUtils.sol";
|
|
88
|
+
import {
|
|
89
|
+
AdvancedStrings
|
|
90
|
+
} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
|
|
81
91
|
|
|
82
92
|
contract Evvm is EvvmStorage {
|
|
83
93
|
/**
|
|
@@ -100,9 +110,8 @@ contract Evvm is EvvmStorage {
|
|
|
100
110
|
* - Part of the time-delayed governance system for critical operations
|
|
101
111
|
*/
|
|
102
112
|
modifier onlyAdmin() {
|
|
103
|
-
if (msg.sender != admin.current)
|
|
104
|
-
|
|
105
|
-
}
|
|
113
|
+
if (msg.sender != admin.current) revert ErrorsLib.SenderIsNotAdmin();
|
|
114
|
+
|
|
106
115
|
_;
|
|
107
116
|
}
|
|
108
117
|
|
|
@@ -114,12 +123,12 @@ contract Evvm is EvvmStorage {
|
|
|
114
123
|
* - Configures admin address with full administrative privileges
|
|
115
124
|
* - Sets staking contract address for reward distribution and status management
|
|
116
125
|
* - Stores EVVM metadata including principal token address and reward parameters
|
|
117
|
-
* - Distributes initial
|
|
126
|
+
* - Distributes initial Principal Tokens to staking contract (2x reward amount)
|
|
118
127
|
* - Registers staking contract as privileged staker with full benefits
|
|
119
128
|
* - Activates breaker flag for one-time NameService and Treasury setup
|
|
120
129
|
*
|
|
121
130
|
* Token Distribution:
|
|
122
|
-
* - Staking contract receives 2x current reward amount in
|
|
131
|
+
* - Staking contract receives 2x current reward amount in Principal Tokens
|
|
123
132
|
* - Enables immediate reward distribution capabilities
|
|
124
133
|
* - Provides operational liquidity for staking rewards
|
|
125
134
|
*
|
|
@@ -145,6 +154,10 @@ contract Evvm is EvvmStorage {
|
|
|
145
154
|
address _stakingContractAddress,
|
|
146
155
|
EvvmMetadata memory _evvmMetadata
|
|
147
156
|
) {
|
|
157
|
+
if (
|
|
158
|
+
_initialOwner == address(0) || _stakingContractAddress == address(0)
|
|
159
|
+
) revert ErrorsLib.AddressCantBeZero();
|
|
160
|
+
|
|
148
161
|
evvmMetadata = _evvmMetadata;
|
|
149
162
|
|
|
150
163
|
stakingContractAddress = _stakingContractAddress;
|
|
@@ -168,7 +181,7 @@ contract Evvm is EvvmStorage {
|
|
|
168
181
|
* - Validates the breaker flag is active (prevents multiple calls)
|
|
169
182
|
* - Sets the NameService contract address for identity resolution in payments
|
|
170
183
|
* - Configures the Treasury contract address for privileged balance operations
|
|
171
|
-
* - Provides initial Principal Token balance (10,000
|
|
184
|
+
* - Provides initial Principal Token balance (10,000 tokens) to NameService for operations
|
|
172
185
|
* - Registers NameService as a privileged staker for enhanced functionality and rewards
|
|
173
186
|
*
|
|
174
187
|
* Security Features:
|
|
@@ -177,7 +190,7 @@ contract Evvm is EvvmStorage {
|
|
|
177
190
|
* - Must be called during initial system deployment phase
|
|
178
191
|
*
|
|
179
192
|
* Initial Token Distribution:
|
|
180
|
-
* - NameService receives 10,000
|
|
193
|
+
* - NameService receives 10,000 Principal Tokens for operational expenses
|
|
181
194
|
* - NameService gains staker privileges for transaction processing
|
|
182
195
|
* - Enables identity-based payment resolution throughout the ecosystem
|
|
183
196
|
*
|
|
@@ -192,9 +205,12 @@ contract Evvm is EvvmStorage {
|
|
|
192
205
|
address _nameServiceAddress,
|
|
193
206
|
address _treasuryAddress
|
|
194
207
|
) external {
|
|
195
|
-
if (breakerSetupNameServiceAddress == 0x00)
|
|
196
|
-
revert();
|
|
197
|
-
|
|
208
|
+
if (breakerSetupNameServiceAddress == 0x00)
|
|
209
|
+
revert ErrorsLib.BreakerExploded();
|
|
210
|
+
|
|
211
|
+
if (_nameServiceAddress == address(0) || _treasuryAddress == address(0))
|
|
212
|
+
revert ErrorsLib.AddressCantBeZero();
|
|
213
|
+
|
|
198
214
|
nameServiceAddress = _nameServiceAddress;
|
|
199
215
|
balances[nameServiceAddress][evvmMetadata.principalTokenAddress] =
|
|
200
216
|
10000 *
|
|
@@ -211,7 +227,7 @@ contract Evvm is EvvmStorage {
|
|
|
211
227
|
function setEvvmID(uint256 newEvvmID) external onlyAdmin {
|
|
212
228
|
if (evvmMetadata.EvvmID != 0) {
|
|
213
229
|
if (block.timestamp > windowTimeToChangeEvvmID)
|
|
214
|
-
revert ErrorsLib.
|
|
230
|
+
revert ErrorsLib.WindowExpired();
|
|
215
231
|
}
|
|
216
232
|
|
|
217
233
|
evvmMetadata.EvvmID = newEvvmID;
|
|
@@ -253,7 +269,8 @@ contract Evvm is EvvmStorage {
|
|
|
253
269
|
* @custom:upgrade-safe Preserves storage layout between upgrades
|
|
254
270
|
*/
|
|
255
271
|
fallback() external {
|
|
256
|
-
if (currentImplementation == address(0))
|
|
272
|
+
if (currentImplementation == address(0))
|
|
273
|
+
revert ErrorsLib.ImplementationIsNotActive();
|
|
257
274
|
|
|
258
275
|
assembly {
|
|
259
276
|
/**
|
|
@@ -389,22 +406,17 @@ contract Evvm is EvvmStorage {
|
|
|
389
406
|
)
|
|
390
407
|
: to_address;
|
|
391
408
|
|
|
392
|
-
|
|
393
|
-
revert ErrorsLib.UpdateBalanceFailed();
|
|
409
|
+
_updateBalance(from, to, token, amount);
|
|
394
410
|
|
|
395
411
|
if (isAddressStaker(msg.sender)) {
|
|
396
412
|
if (priorityFee > 0) {
|
|
397
|
-
|
|
398
|
-
revert ErrorsLib.UpdateBalanceFailed();
|
|
413
|
+
_updateBalance(from, msg.sender, token, priorityFee);
|
|
399
414
|
}
|
|
400
415
|
_giveReward(msg.sender, 1);
|
|
401
416
|
}
|
|
402
417
|
|
|
403
|
-
if (priorityFlag)
|
|
404
|
-
|
|
405
|
-
} else {
|
|
406
|
-
nextSyncUsedNonce[from]++;
|
|
407
|
-
}
|
|
418
|
+
if (priorityFlag) asyncUsedNonce[from][nonce] = true;
|
|
419
|
+
else nextSyncUsedNonce[from]++;
|
|
408
420
|
}
|
|
409
421
|
|
|
410
422
|
/**
|
|
@@ -435,112 +447,87 @@ contract Evvm is EvvmStorage {
|
|
|
435
447
|
function payMultiple(
|
|
436
448
|
PayData[] memory payData
|
|
437
449
|
) external returns (uint256 successfulTransactions, bool[] memory results) {
|
|
450
|
+
|
|
451
|
+
bool isSenderStaker = isAddressStaker(msg.sender);
|
|
438
452
|
address to_aux;
|
|
453
|
+
PayData memory payment;
|
|
439
454
|
results = new bool[](payData.length);
|
|
455
|
+
|
|
440
456
|
for (uint256 iteration = 0; iteration < payData.length; iteration++) {
|
|
457
|
+
payment = payData[iteration];
|
|
441
458
|
if (
|
|
442
459
|
!SignatureUtils.verifyMessageSignedForPay(
|
|
443
460
|
evvmMetadata.EvvmID,
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
461
|
+
payment.from,
|
|
462
|
+
payment.to_address,
|
|
463
|
+
payment.to_identity,
|
|
464
|
+
payment.token,
|
|
465
|
+
payment.amount,
|
|
466
|
+
payment.priorityFee,
|
|
467
|
+
payment.nonce,
|
|
468
|
+
payment.priorityFlag,
|
|
469
|
+
payment.executor,
|
|
470
|
+
payment.signature
|
|
454
471
|
)
|
|
455
472
|
) revert ErrorsLib.InvalidSignature();
|
|
456
473
|
|
|
457
|
-
if (
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
474
|
+
if (
|
|
475
|
+
payment.executor != address(0) && msg.sender != payment.executor
|
|
476
|
+
) {
|
|
477
|
+
results[iteration] = false;
|
|
478
|
+
continue;
|
|
462
479
|
}
|
|
463
480
|
|
|
464
|
-
if (
|
|
481
|
+
if (payment.priorityFlag) {
|
|
465
482
|
/// @dev priorityFlag == true (async)
|
|
466
483
|
|
|
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 {
|
|
484
|
+
if (asyncUsedNonce[payment.from][payment.nonce]) {
|
|
476
485
|
results[iteration] = false;
|
|
477
486
|
continue;
|
|
478
487
|
}
|
|
479
488
|
} else {
|
|
480
489
|
/// @dev priorityFlag == false (sync)
|
|
481
490
|
|
|
482
|
-
if (
|
|
483
|
-
nextSyncUsedNonce[payData[iteration].from] ==
|
|
484
|
-
payData[iteration].nonce
|
|
485
|
-
) {
|
|
486
|
-
nextSyncUsedNonce[payData[iteration].from]++;
|
|
487
|
-
} else {
|
|
491
|
+
if (nextSyncUsedNonce[payment.from] != payment.nonce) {
|
|
488
492
|
results[iteration] = false;
|
|
489
493
|
continue;
|
|
490
494
|
}
|
|
491
495
|
}
|
|
492
496
|
|
|
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
497
|
if (
|
|
501
|
-
|
|
502
|
-
balances[
|
|
498
|
+
(isSenderStaker ? payment.priorityFee : 0) + payment.amount >
|
|
499
|
+
balances[payment.from][payment.token]
|
|
503
500
|
) {
|
|
504
501
|
results[iteration] = false;
|
|
505
502
|
continue;
|
|
506
503
|
}
|
|
507
504
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
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
|
-
}
|
|
505
|
+
to_aux = !AdvancedStrings.equal(payment.to_identity, "")
|
|
506
|
+
? NameService(nameServiceAddress)
|
|
507
|
+
.verifyStrictAndGetOwnerOfIdentity(payment.to_identity)
|
|
508
|
+
: payment.to_address;
|
|
535
509
|
|
|
536
|
-
|
|
537
|
-
results[iteration] = true;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
510
|
+
/// @dev Because of the previous check, _updateBalance can´t fail
|
|
540
511
|
|
|
541
|
-
|
|
542
|
-
|
|
512
|
+
_updateBalance(payment.from, to_aux, payment.token, payment.amount);
|
|
513
|
+
|
|
514
|
+
if (payment.priorityFee > 0 && isSenderStaker)
|
|
515
|
+
_updateBalance(
|
|
516
|
+
payment.from,
|
|
517
|
+
msg.sender,
|
|
518
|
+
payment.token,
|
|
519
|
+
payment.priorityFee
|
|
520
|
+
);
|
|
521
|
+
|
|
522
|
+
if (payment.priorityFlag)
|
|
523
|
+
asyncUsedNonce[payment.from][payment.nonce] = true;
|
|
524
|
+
else nextSyncUsedNonce[payment.from]++;
|
|
525
|
+
|
|
526
|
+
successfulTransactions++;
|
|
527
|
+
results[iteration] = true;
|
|
543
528
|
}
|
|
529
|
+
|
|
530
|
+
if (isSenderStaker) _giveReward(msg.sender, successfulTransactions);
|
|
544
531
|
}
|
|
545
532
|
|
|
546
533
|
/**
|
|
@@ -562,7 +549,7 @@ contract Evvm is EvvmStorage {
|
|
|
562
549
|
*
|
|
563
550
|
* Staker Benefits:
|
|
564
551
|
* - Executor receives priority fee (if staker)
|
|
565
|
-
* -
|
|
552
|
+
* - Principal Token reward based on number of successful distributions
|
|
566
553
|
*
|
|
567
554
|
* @param from Address of the payment sender
|
|
568
555
|
* @param toData Array of recipient data with addresses/identities and amounts
|
|
@@ -600,10 +587,8 @@ contract Evvm is EvvmStorage {
|
|
|
600
587
|
)
|
|
601
588
|
) revert ErrorsLib.InvalidSignature();
|
|
602
589
|
|
|
603
|
-
if (executor != address(0))
|
|
604
|
-
|
|
605
|
-
revert ErrorsLib.SenderIsNotTheExecutor();
|
|
606
|
-
}
|
|
590
|
+
if ((executor != address(0)) && (msg.sender != executor))
|
|
591
|
+
revert ErrorsLib.SenderIsNotTheExecutor();
|
|
607
592
|
|
|
608
593
|
if (priorityFlag) {
|
|
609
594
|
if (asyncUsedNonce[from][nonce])
|
|
@@ -613,11 +598,13 @@ contract Evvm is EvvmStorage {
|
|
|
613
598
|
revert ErrorsLib.SyncNonceMismatch();
|
|
614
599
|
}
|
|
615
600
|
|
|
616
|
-
|
|
601
|
+
bool isSenderStaker = isAddressStaker(msg.sender);
|
|
602
|
+
|
|
603
|
+
if (balances[from][token] < amount + (isSenderStaker ? priorityFee : 0))
|
|
617
604
|
revert ErrorsLib.InsufficientBalance();
|
|
618
605
|
|
|
619
606
|
uint256 acomulatedAmount = 0;
|
|
620
|
-
balances[from][token] -= (amount + priorityFee);
|
|
607
|
+
balances[from][token] -= (amount + (isSenderStaker ? priorityFee : 0));
|
|
621
608
|
address to_aux;
|
|
622
609
|
for (uint256 i = 0; i < toData.length; i++) {
|
|
623
610
|
acomulatedAmount += toData[i].amount;
|
|
@@ -629,8 +616,8 @@ contract Evvm is EvvmStorage {
|
|
|
629
616
|
)
|
|
630
617
|
) {
|
|
631
618
|
to_aux = NameService(nameServiceAddress).getOwnerOfIdentity(
|
|
632
|
-
|
|
633
|
-
|
|
619
|
+
toData[i].to_identity
|
|
620
|
+
);
|
|
634
621
|
}
|
|
635
622
|
} else {
|
|
636
623
|
to_aux = toData[i].to_address;
|
|
@@ -639,22 +626,15 @@ contract Evvm is EvvmStorage {
|
|
|
639
626
|
balances[to_aux][token] += toData[i].amount;
|
|
640
627
|
}
|
|
641
628
|
|
|
642
|
-
if (acomulatedAmount != amount)
|
|
643
|
-
revert ErrorsLib.InvalidAmount(acomulatedAmount, amount);
|
|
629
|
+
if (acomulatedAmount != amount) revert ErrorsLib.InvalidAmount();
|
|
644
630
|
|
|
645
|
-
if (
|
|
631
|
+
if (isSenderStaker) {
|
|
646
632
|
_giveReward(msg.sender, 1);
|
|
647
633
|
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
634
|
}
|
|
657
635
|
|
|
636
|
+
if (priorityFlag) asyncUsedNonce[from][nonce] = true;
|
|
637
|
+
else nextSyncUsedNonce[from]++;
|
|
658
638
|
}
|
|
659
639
|
|
|
660
640
|
/**
|
|
@@ -693,12 +673,9 @@ contract Evvm is EvvmStorage {
|
|
|
693
673
|
|
|
694
674
|
if (size == 0) revert ErrorsLib.NotAnCA();
|
|
695
675
|
|
|
696
|
-
|
|
697
|
-
revert ErrorsLib.UpdateBalanceFailed();
|
|
676
|
+
_updateBalance(from, to, token, amount);
|
|
698
677
|
|
|
699
|
-
if (isAddressStaker(msg.sender))
|
|
700
|
-
_giveReward(msg.sender, 1);
|
|
701
|
-
}
|
|
678
|
+
if (isAddressStaker(msg.sender)) _giveReward(msg.sender, 1);
|
|
702
679
|
}
|
|
703
680
|
|
|
704
681
|
/**
|
|
@@ -741,27 +718,21 @@ contract Evvm is EvvmStorage {
|
|
|
741
718
|
|
|
742
719
|
if (size == 0) revert ErrorsLib.NotAnCA();
|
|
743
720
|
|
|
744
|
-
uint256 acomulatedAmount = 0;
|
|
745
721
|
if (balances[msg.sender][token] < amount)
|
|
746
722
|
revert ErrorsLib.InsufficientBalance();
|
|
747
723
|
|
|
724
|
+
uint256 acomulatedAmount = 0;
|
|
725
|
+
|
|
748
726
|
balances[msg.sender][token] -= amount;
|
|
749
727
|
|
|
750
728
|
for (uint256 i = 0; i < toData.length; i++) {
|
|
751
729
|
acomulatedAmount += toData[i].amount;
|
|
752
|
-
if (acomulatedAmount > amount)
|
|
753
|
-
revert ErrorsLib.InvalidAmount(acomulatedAmount, amount);
|
|
754
|
-
|
|
755
730
|
balances[toData[i].toAddress][token] += toData[i].amount;
|
|
756
731
|
}
|
|
757
732
|
|
|
758
|
-
if (acomulatedAmount != amount)
|
|
759
|
-
revert ErrorsLib.InvalidAmount(acomulatedAmount, amount);
|
|
760
|
-
|
|
761
|
-
if (isAddressStaker(msg.sender)) {
|
|
762
|
-
_giveReward(msg.sender, 1);
|
|
763
|
-
}
|
|
733
|
+
if (acomulatedAmount != amount) revert ErrorsLib.InvalidAmount();
|
|
764
734
|
|
|
735
|
+
if (isAddressStaker(msg.sender)) _giveReward(msg.sender, 1);
|
|
765
736
|
}
|
|
766
737
|
|
|
767
738
|
//░▒▓█Treasury exclusive functions██████████████████████████████████████████▓▒░
|
|
@@ -871,23 +842,19 @@ contract Evvm is EvvmStorage {
|
|
|
871
842
|
* @param to Address to transfer tokens to
|
|
872
843
|
* @param token Address of the token contract
|
|
873
844
|
* @param value Amount of tokens to transfer
|
|
874
|
-
* @return success True if transfer completed, false if insufficient balance
|
|
875
845
|
*/
|
|
876
846
|
function _updateBalance(
|
|
877
847
|
address from,
|
|
878
848
|
address to,
|
|
879
849
|
address token,
|
|
880
850
|
uint256 value
|
|
881
|
-
) internal
|
|
851
|
+
) internal {
|
|
882
852
|
uint256 fromBalance = balances[from][token];
|
|
883
|
-
if (fromBalance < value)
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
balances[to][token] += value;
|
|
889
|
-
}
|
|
890
|
-
return true;
|
|
853
|
+
if (fromBalance < value) revert ErrorsLib.InsufficientBalance();
|
|
854
|
+
|
|
855
|
+
unchecked {
|
|
856
|
+
balances[from][token] = fromBalance - value;
|
|
857
|
+
balances[to][token] += value;
|
|
891
858
|
}
|
|
892
859
|
}
|
|
893
860
|
|
|
@@ -940,6 +907,7 @@ contract Evvm is EvvmStorage {
|
|
|
940
907
|
* @param _newImpl Address of the new implementation contract
|
|
941
908
|
*/
|
|
942
909
|
function proposeImplementation(address _newImpl) external onlyAdmin {
|
|
910
|
+
if (_newImpl == address(0)) revert ErrorsLib.IncorrectAddressInput();
|
|
943
911
|
proposalImplementation = _newImpl;
|
|
944
912
|
timeToAcceptImplementation =
|
|
945
913
|
block.timestamp +
|
|
@@ -960,25 +928,14 @@ contract Evvm is EvvmStorage {
|
|
|
960
928
|
* @dev Executes the proxy upgrade to the new implementation contract
|
|
961
929
|
*/
|
|
962
930
|
function acceptImplementation() external onlyAdmin {
|
|
963
|
-
if (block.timestamp < timeToAcceptImplementation)
|
|
931
|
+
if (block.timestamp < timeToAcceptImplementation)
|
|
932
|
+
revert ErrorsLib.TimeLockNotExpired();
|
|
933
|
+
|
|
964
934
|
currentImplementation = proposalImplementation;
|
|
965
935
|
proposalImplementation = address(0);
|
|
966
936
|
timeToAcceptImplementation = 0;
|
|
967
937
|
}
|
|
968
938
|
|
|
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
939
|
//█ Admin Management Functions ███████████████████████████████████████████████
|
|
983
940
|
|
|
984
941
|
/**
|
|
@@ -987,12 +944,14 @@ contract Evvm is EvvmStorage {
|
|
|
987
944
|
* @param _newOwner Address of the proposed new admin
|
|
988
945
|
*/
|
|
989
946
|
function proposeAdmin(address _newOwner) external onlyAdmin {
|
|
990
|
-
if (_newOwner == address(0) || _newOwner == admin.current)
|
|
991
|
-
revert();
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
947
|
+
if (_newOwner == address(0) || _newOwner == admin.current)
|
|
948
|
+
revert ErrorsLib.IncorrectAddressInput();
|
|
949
|
+
|
|
950
|
+
admin = AddressTypeProposal({
|
|
951
|
+
current: admin.current,
|
|
952
|
+
proposal: _newOwner,
|
|
953
|
+
timeToAccept: block.timestamp + TIME_TO_ACCEPT_PROPOSAL
|
|
954
|
+
});
|
|
996
955
|
}
|
|
997
956
|
|
|
998
957
|
/**
|
|
@@ -1000,8 +959,11 @@ contract Evvm is EvvmStorage {
|
|
|
1000
959
|
* @dev Allows current admin to reject proposed admin changes
|
|
1001
960
|
*/
|
|
1002
961
|
function rejectProposalAdmin() external onlyAdmin {
|
|
1003
|
-
admin
|
|
1004
|
-
|
|
962
|
+
admin = AddressTypeProposal({
|
|
963
|
+
current: admin.current,
|
|
964
|
+
proposal: address(0),
|
|
965
|
+
timeToAccept: 0
|
|
966
|
+
});
|
|
1005
967
|
}
|
|
1006
968
|
|
|
1007
969
|
/**
|
|
@@ -1009,17 +971,17 @@ contract Evvm is EvvmStorage {
|
|
|
1009
971
|
* @dev Can only be called by the proposed admin after the time delay
|
|
1010
972
|
*/
|
|
1011
973
|
function acceptAdmin() external {
|
|
1012
|
-
if (block.timestamp < admin.timeToAccept)
|
|
1013
|
-
revert();
|
|
1014
|
-
}
|
|
1015
|
-
if (msg.sender != admin.proposal) {
|
|
1016
|
-
revert();
|
|
1017
|
-
}
|
|
974
|
+
if (block.timestamp < admin.timeToAccept)
|
|
975
|
+
revert ErrorsLib.TimeLockNotExpired();
|
|
1018
976
|
|
|
1019
|
-
|
|
977
|
+
if (msg.sender != admin.proposal)
|
|
978
|
+
revert ErrorsLib.SenderIsNotTheProposedAdmin();
|
|
1020
979
|
|
|
1021
|
-
admin
|
|
1022
|
-
|
|
980
|
+
admin = AddressTypeProposal({
|
|
981
|
+
current: admin.proposal,
|
|
982
|
+
proposal: address(0),
|
|
983
|
+
timeToAccept: 0
|
|
984
|
+
});
|
|
1023
985
|
}
|
|
1024
986
|
|
|
1025
987
|
//█ Reward System Functions ███████████████████████████████████████████████████████████████
|
|
@@ -1100,9 +1062,8 @@ contract Evvm is EvvmStorage {
|
|
|
1100
1062
|
* @param answer Bytes1 flag indicating staker status/type
|
|
1101
1063
|
*/
|
|
1102
1064
|
function pointStaker(address user, bytes1 answer) public {
|
|
1103
|
-
if (msg.sender != stakingContractAddress)
|
|
1104
|
-
|
|
1105
|
-
}
|
|
1065
|
+
if (msg.sender != stakingContractAddress) revert();
|
|
1066
|
+
|
|
1106
1067
|
stakerList[user] = answer;
|
|
1107
1068
|
}
|
|
1108
1069
|
|
|
@@ -1125,10 +1086,22 @@ contract Evvm is EvvmStorage {
|
|
|
1125
1086
|
return evvmMetadata;
|
|
1126
1087
|
}
|
|
1127
1088
|
|
|
1089
|
+
/**
|
|
1090
|
+
* @notice Gets the address representing the Principal Token in balance mappings
|
|
1091
|
+
* @dev Returns the virtual address used to track Principal Token balances in the balances mapping
|
|
1092
|
+
* This is not an ERC20 contract address but a sentinel value for the EVVM-native token
|
|
1093
|
+
* @return Address used as the key for Principal Token balances
|
|
1094
|
+
*/
|
|
1128
1095
|
function getPrincipalTokenAddress() external view returns (address) {
|
|
1129
1096
|
return evvmMetadata.principalTokenAddress;
|
|
1130
1097
|
}
|
|
1131
1098
|
|
|
1099
|
+
/**
|
|
1100
|
+
* @notice Gets the address representing native chain currency (ETH/MATIC) in balance mappings
|
|
1101
|
+
* @dev Returns address(0) which is the standard sentinel for native blockchain tokens
|
|
1102
|
+
* Use this address as the token parameter when dealing with ETH or chain-native assets
|
|
1103
|
+
* @return address(0) representing the native chain currency
|
|
1104
|
+
*/
|
|
1132
1105
|
function getChainHostCoinAddress() external pure returns (address) {
|
|
1133
1106
|
return address(0);
|
|
1134
1107
|
}
|
|
@@ -1247,16 +1220,16 @@ contract Evvm is EvvmStorage {
|
|
|
1247
1220
|
/**
|
|
1248
1221
|
* @notice Gets the current Principal Token reward amount per transaction
|
|
1249
1222
|
* @dev Returns the base reward distributed to stakers for transaction processing
|
|
1250
|
-
* @return Current reward amount in
|
|
1223
|
+
* @return Current reward amount in Principal Tokens
|
|
1251
1224
|
*/
|
|
1252
1225
|
function getRewardAmount() public view returns (uint256) {
|
|
1253
1226
|
return evvmMetadata.reward;
|
|
1254
1227
|
}
|
|
1255
1228
|
|
|
1256
1229
|
/**
|
|
1257
|
-
* @notice Gets the total supply of the
|
|
1230
|
+
* @notice Gets the total supply of the Principal Token
|
|
1258
1231
|
* @dev Returns the current total supply used for era transition calculations
|
|
1259
|
-
* @return Total supply of
|
|
1232
|
+
* @return Total supply of Principal Tokens
|
|
1260
1233
|
*/
|
|
1261
1234
|
function getPrincipalTokenTotalSupply() public view returns (uint256) {
|
|
1262
1235
|
return evvmMetadata.totalSupply;
|