-
Notifications
You must be signed in to change notification settings - Fork 370
/
Copy pathIntegrationBase.t.sol
2878 lines (2387 loc) · 111 KB
/
IntegrationBase.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.27;
import "forge-std/Test.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "src/contracts/libraries/BeaconChainProofs.sol";
import "src/contracts/libraries/SlashingLib.sol";
import "src/test/integration/TypeImporter.t.sol";
import "src/test/integration/IntegrationDeployer.t.sol";
import "src/test/integration/TimeMachine.t.sol";
import "src/test/integration/users/User.t.sol";
import "src/test/integration/users/User_M1.t.sol";
abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
using StdStyle for *;
using SlashingLib for *;
using Math for uint256;
using Strings for *;
using print for *;
using ArrayLib for *;
uint numStakers = 0;
uint numOperators = 0;
uint numAVSs = 0;
// Lists of operators created before the m2 (not slashing) upgrade
//
// When we call _upgradeEigenLayerContracts, we iterate over
// these lists and migrate perform the standard migration actions
// for each user
User[] operatorsToMigrate;
User[] stakersToMigrate;
/**
* Gen/Init methods:
*/
/**
* @dev Create a new user according to configured random variants.
* This user is ready to deposit into some strategies and has some underlying token balances
*/
function _newRandomStaker() internal returns (User, IStrategy[] memory, uint[] memory) {
string memory stakerName;
User staker;
IStrategy[] memory strategies;
uint[] memory tokenBalances;
if (!isUpgraded) {
stakerName = string.concat("M2Staker", cheats.toString(numStakers));
(staker, strategies, tokenBalances) = _randUser(stakerName);
stakersToMigrate.push(staker);
} else {
stakerName = string.concat("staker", cheats.toString(numStakers));
(staker, strategies, tokenBalances) = _randUser(stakerName);
}
assert_HasUnderlyingTokenBalances(staker, strategies, tokenBalances, "_newRandomStaker: failed to award token balances");
numStakers++;
return (staker, strategies, tokenBalances);
}
function _newBasicStaker() internal returns (User, IStrategy[] memory, uint[] memory) {
string memory stakerName;
User staker;
IStrategy[] memory strategies;
uint[] memory tokenBalances;
if (!isUpgraded) {
stakerName = string.concat("M2Staker", cheats.toString(numStakers));
(staker, strategies, tokenBalances) = _randUser(stakerName);
stakersToMigrate.push(staker);
} else {
stakerName = string.concat("staker", cheats.toString(numStakers));
(staker, strategies, tokenBalances) = _randUser(stakerName);
}
assert_HasUnderlyingTokenBalances(staker, strategies, tokenBalances, "_newRandomStaker: failed to award token balances");
numStakers++;
assembly { // TODO HACK
mstore(strategies, 1)
mstore(tokenBalances, 1)
}
return (staker, strategies, tokenBalances);
}
/**
* @dev Create a new operator according to configured random variants.
* This user will immediately deposit their randomized assets into eigenlayer.
* @notice If forktype is mainnet and not upgraded, then the operator will only randomize LSTs assets and deposit them
* as ETH podowner shares are not available yet.
*/
function _newRandomOperator() internal returns (User, IStrategy[] memory, uint[] memory) {
User operator;
IStrategy[] memory strategies;
uint[] memory tokenBalances;
uint[] memory addedShares;
if (!isUpgraded) {
string memory operatorName = string.concat("M2Operator", numOperators.toString());
// Create an operator for M2.
// TODO: Allow this operator to have ETH
(operator, strategies, tokenBalances) = _randUser_NoETH(operatorName);
addedShares = _calculateExpectedShares(strategies, tokenBalances);
User_M2(payable(operator)).registerAsOperator_M2();
operator.depositIntoEigenlayer(strategies, tokenBalances); // Deposits interface doesn't change between M2 and slashing
operatorsToMigrate.push(operator);
} else {
string memory operatorName = string.concat("operator", numOperators.toString());
(operator, strategies, tokenBalances) = _randUser_NoETH(operatorName);
addedShares = _calculateExpectedShares(strategies, tokenBalances);
operator.registerAsOperator();
operator.depositIntoEigenlayer(strategies, tokenBalances);
// Roll past the allocation configuration delay
rollForward({blocks: ALLOCATION_CONFIGURATION_DELAY + 1});
assert_Snap_Added_Staker_DepositShares(operator, strategies, addedShares, "_newRandomOperator: failed to add delegatable shares");
}
assert_Snap_Added_OperatorShares(operator, strategies, addedShares, "_newRandomOperator: failed to award shares to operator");
assertTrue(delegationManager.isOperator(address(operator)), "_newRandomOperator: operator should be registered");
numOperators++;
return (operator, strategies, tokenBalances);
}
/// @dev Creates a new operator with no assets
function _newRandomOperator_NoAssets() internal returns (User) {
User operator;
if (!isUpgraded) {
string memory operatorName = string.concat("M2Operator", numOperators.toString());
// Create an operator for M2.
operator = _randUser_NoAssets(operatorName);
User_M2(payable(operator)).registerAsOperator_M2();
operatorsToMigrate.push(operator);
} else {
string memory operatorName = string.concat("operator", numOperators.toString());
operator = _randUser_NoAssets(operatorName);
operator.registerAsOperator();
// Roll past the allocation configuration delay
rollForward({blocks: ALLOCATION_CONFIGURATION_DELAY + 1});
}
assertTrue(delegationManager.isOperator(address(operator)), "_newRandomOperator: operator should be registered");
numOperators++;
return operator;
}
function _newRandomAVS() internal returns (AVS avs, OperatorSet[] memory operatorSets) {
string memory avsName = string.concat("avs", numAVSs.toString());
avs = _genRandAVS(avsName);
avs.updateAVSMetadataURI("https://example.com");
operatorSets = avs.createOperatorSets(_randomStrategies());
++numAVSs;
}
/// @dev Send a random amount of ETH (up to 10 gwei) to the destination via `call`,
/// triggering its fallback function. Sends a gwei-divisible amount as well as a
/// non-gwei-divisible amount.
///
/// Total sent == `gweiSent + remainderSent`
function _sendRandomETH(address destination) internal returns (uint64 gweiSent, uint remainderSent) {
gweiSent = uint64(_randUint({ min: 1 , max: 10 }));
remainderSent = _randUint({ min: 1, max: 100 });
uint totalSent = (gweiSent * GWEI_TO_WEI) + remainderSent;
cheats.deal(address(this), address(this).balance + totalSent);
bool r;
bytes memory d;
(r, d) = destination.call{ value: totalSent }("");
return (gweiSent, remainderSent);
}
/// @dev Choose a random subset of validators (selects AT LEAST ONE)
function _choose(uint40[] memory validators) internal returns (uint40[] memory) {
uint _rand = _randUint({ min: 1, max: validators.length ** 2 });
uint40[] memory result = new uint40[](validators.length);
uint newLen;
for (uint i = 0; i < validators.length; i++) {
// if bit set, add validator
if (_rand >> i & 1 == 1) {
result[newLen] = validators[i];
newLen++;
}
}
// Manually update length of result
assembly { mstore(result, newLen) }
return result;
}
function _getTokenName(IERC20 token) internal view returns (string memory) {
if (token == NATIVE_ETH) {
return "Native ETH";
}
return IERC20Metadata(address(token)).name();
}
/*******************************************************************************
COMMON ASSERTIONS
*******************************************************************************/
function assert_HasNoDelegatableShares(User user, string memory err) internal view {
(IStrategy[] memory strategies, uint[] memory shares) =
delegationManager.getDepositedShares(address(user));
assertEq(strategies.length, 0, err);
assertEq(strategies.length, shares.length, "assert_HasNoDelegatableShares: return length mismatch");
}
function assert_HasUnderlyingTokenBalances(
User user,
IStrategy[] memory strategies,
uint[] memory expectedBalances,
string memory err
) internal view {
for (uint i = 0; i < strategies.length; i++) {
IStrategy strat = strategies[i];
uint expectedBalance = expectedBalances[i];
uint tokenBalance;
if (strat == BEACONCHAIN_ETH_STRAT) {
tokenBalance = address(user).balance;
} else {
tokenBalance = strat.underlyingToken().balanceOf(address(user));
}
assertApproxEqAbs(expectedBalance, tokenBalance, 1, err);
}
}
function assert_HasNoUnderlyingTokenBalance(User user, IStrategy[] memory strategies, string memory err) internal view {
assert_HasUnderlyingTokenBalances(user, strategies, new uint[](strategies.length), err);
}
function assert_HasExpectedShares(
User user,
IStrategy[] memory strategies,
uint[] memory expectedShares,
string memory err
) internal view {
uint[] memory actualShares = _getStakerDepositShares(user, strategies);
for(uint i = 0; i < strategies.length; i++) {
assertApproxEqAbs(expectedShares[i], actualShares[i], 1, err);
}
}
function assert_HasOperatorShares(
User user,
IStrategy[] memory strategies,
uint[] memory expectedShares,
string memory err
) internal view {
for (uint i = 0; i < strategies.length; i++) {
uint actualShares = delegationManager.operatorShares(address(user), strategies[i]);
assertEq(expectedShares[i], actualShares, err);
}
}
/// @dev Asserts that ALL of the `withdrawalRoots` is in `delegationManager.pendingWithdrawals`
function assert_AllWithdrawalsPending(bytes32[] memory withdrawalRoots, string memory err) internal view {
for (uint i = 0; i < withdrawalRoots.length; i++) {
assert_WithdrawalPending(withdrawalRoots[i], err);
}
}
/// @dev Asserts that NONE of the `withdrawalRoots` is in `delegationManager.pendingWithdrawals`
function assert_NoWithdrawalsPending(bytes32[] memory withdrawalRoots, string memory err) internal view {
for (uint i = 0; i < withdrawalRoots.length; i++) {
assert_WithdrawalNotPending(withdrawalRoots[i], err);
}
}
/// @dev Asserts that the hash of each withdrawal corresponds to the provided withdrawal root
function assert_WithdrawalPending(bytes32 withdrawalRoot, string memory err) internal view {
assertTrue(delegationManager.pendingWithdrawals(withdrawalRoot), err);
}
function assert_WithdrawalNotPending(bytes32 withdrawalRoot, string memory err) internal view {
assertFalse(delegationManager.pendingWithdrawals(withdrawalRoot), err);
}
function assert_ValidWithdrawalHashes(
Withdrawal[] memory withdrawals,
bytes32[] memory withdrawalRoots,
string memory err
) internal view {
for (uint i = 0; i < withdrawals.length; i++) {
assert_ValidWithdrawalHash(withdrawals[i], withdrawalRoots[i], err);
}
}
function assert_ValidWithdrawalHash(
Withdrawal memory withdrawal,
bytes32 withdrawalRoot,
string memory err
) internal view {
assertEq(withdrawalRoot, delegationManager.calculateWithdrawalRoot(withdrawal), err);
}
function assert_PodBalance_Eq(
User staker,
uint expectedBalance,
string memory err
) internal view {
EigenPod pod = staker.pod();
assertEq(address(pod).balance, expectedBalance, err);
}
function assert_ProofsRemainingEqualsActive(
User staker,
string memory err
) internal view {
EigenPod pod = staker.pod();
assertEq(pod.currentCheckpoint().proofsRemaining, pod.activeValidatorCount(), err);
}
function assert_CheckpointPodBalance(
User staker,
uint64 expectedPodBalanceGwei,
string memory err
) internal view {
EigenPod pod = staker.pod();
assertEq(pod.currentCheckpoint().podBalanceGwei, expectedPodBalanceGwei, err);
}
function assert_MaxEqualsAllocatablePlusEncumbered(
User operator,
string memory err
) internal view {
Magnitudes[] memory mags = _getMagnitudes(operator, allStrats);
for (uint i = 0; i < allStrats.length; i++) {
Magnitudes memory m = mags[i];
assertEq(m.max, m.encumbered + m.allocatable, err);
}
}
function assert_CurMinSlashableEqualsMinAllocated(
User operator,
OperatorSet memory operatorSet,
IStrategy[] memory strategies,
string memory err
) internal view {
uint[] memory minSlashableStake = _getMinSlashableStake(operator, operatorSet, strategies);
uint[] memory minAllocatedStake = _getAllocatedStake(operator, operatorSet, strategies);
for (uint i = 0; i < strategies.length; i++) {
assertEq(minSlashableStake[i], minAllocatedStake[i], err);
}
}
function assert_MaxMagsEqualMaxMagsAtCurrentBlock(
User operator,
IStrategy[] memory strategies,
string memory err
) internal view {
uint64[] memory maxMagnitudes = _getMaxMagnitudes(operator, strategies);
uint64[] memory maxAtCurrentBlock = _getMaxMagnitudes(operator, strategies, uint32(block.number));
for (uint i = 0; i < strategies.length; i++) {
assertEq(maxMagnitudes[i], maxAtCurrentBlock[i], err);
}
}
function assert_CurrentMagnitude(
User operator,
AllocateParams memory params,
string memory err
) internal view {
Allocation[] memory allocations = _getAllocations(operator, params.operatorSet, params.strategies);
for (uint i = 0; i < allocations.length; i++) {
assertEq(allocations[i].currentMagnitude, params.newMagnitudes[i], err);
}
}
function assert_NoPendingModification(
User operator,
OperatorSet memory operatorSet,
IStrategy[] memory strategies,
string memory err
) internal view {
Allocation[] memory allocations = _getAllocations(operator, operatorSet, strategies);
for (uint i = 0; i < allocations.length; i++) {
assertEq(0, allocations[i].effectBlock, err);
}
}
function assert_HasPendingIncrease(
User operator,
AllocateParams memory params,
string memory err
) internal view {
uint32 delay = _getExistingAllocationDelay(operator);
Allocation[] memory allocations = _getAllocations(operator, params.operatorSet, params.strategies);
for (uint i = 0; i < allocations.length; i++) {
assertEq(allocations[i].effectBlock, uint32(block.number) + delay, err);
assertTrue(allocations[i].currentMagnitude != params.newMagnitudes[i], err);
assertGt(allocations[i].pendingDiff, 0, err);
}
}
function assert_HasPendingDecrease(
User operator,
AllocateParams memory params,
string memory err
) internal view {
uint32 deallocationDelay = allocationManager.DEALLOCATION_DELAY();
Allocation[] memory allocations = _getAllocations(operator, params.operatorSet, params.strategies);
for (uint i = 0; i < allocations.length; i++) {
assertEq(allocations[i].effectBlock, uint32(block.number) + deallocationDelay + 1, err);
assertTrue(allocations[i].currentMagnitude != params.newMagnitudes[i], err);
assertLt(allocations[i].pendingDiff, 0, err);
}
}
function assert_IsRegistered(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal view {
assertTrue(allocationManager.isMemberOfOperatorSet(address(operator), operatorSet), err);
}
function assert_IsSlashable(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal view {
assertTrue(allocationManager.isOperatorSlashable(address(operator), operatorSet), err);
}
function assert_NotSlashable(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal view {
assertFalse(allocationManager.isOperatorSlashable(address(operator), operatorSet), err);
}
function assert_IsAllocatedToSet(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal view {
assertTrue(allocationManager.getAllocatedSets(address(operator)).contains(operatorSet), err);
}
function assert_IsNotAllocated(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal view {
assertEq(allocationManager.getAllocatedStrategies(address(operator), operatorSet).length, 0, err);
}
function assert_IsAllocatedToSetStrats(
User operator,
OperatorSet memory operatorSet,
IStrategy[] memory strategies,
string memory err
) internal view {
IStrategy[] memory allocatedStrategies = allocationManager.getAllocatedStrategies(address(operator), operatorSet);
for (uint i = 0; i < strategies.length; i++) {
assertTrue(allocatedStrategies.contains(strategies[i]), err);
}
}
function assert_HasAllocatedStake(
User operator,
AllocateParams memory params,
string memory err
) internal view {
OperatorSet memory operatorSet = params.operatorSet;
IStrategy[] memory strategies = params.strategies;
uint64[] memory curMagnitudes = params.newMagnitudes;
uint64[] memory maxMagnitudes = _getMaxMagnitudes(operator, params.strategies);
uint[] memory operatorShares = _getOperatorShares(operator, params.strategies);
uint[] memory allocatedStake = _getAllocatedStake(operator, operatorSet, strategies);
for (uint i = 0; i < strategies.length; i++) {
uint expectedAllocated;
if (maxMagnitudes[i] == 0) {
expectedAllocated = 0;
} else {
uint slashableProportion = uint(curMagnitudes[i]).divWad(maxMagnitudes[i]);
expectedAllocated = operatorShares[i].mulWad(slashableProportion);
}
assertEq(expectedAllocated, allocatedStake[i], err);
}
}
function assert_HasSlashableStake(
User operator,
AllocateParams memory params,
string memory err
) internal view {
OperatorSet memory operatorSet = params.operatorSet;
IStrategy[] memory strategies = params.strategies;
uint64[] memory curMagnitudes = params.newMagnitudes;
uint64[] memory maxMagnitudes = _getMaxMagnitudes(operator, params.strategies);
uint[] memory operatorShares = _getOperatorShares(operator, params.strategies);
uint[] memory slashableStake = _getMinSlashableStake(operator, operatorSet, strategies);
for (uint i = 0; i < strategies.length; i++) {
uint expectedSlashable;
if (maxMagnitudes[i] == 0) {
expectedSlashable = 0;
} else {
uint slashableProportion = uint(curMagnitudes[i]).divWad(maxMagnitudes[i]);
expectedSlashable = operatorShares[i].mulWad(slashableProportion);
}
assertEq(expectedSlashable, slashableStake[i], err);
}
}
function assert_NoSlashableStake(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal view {
IStrategy[] memory strategies = allocationManager.getStrategiesInOperatorSet(operatorSet);
uint[] memory slashableStake = _getMinSlashableStake(operator, operatorSet, strategies);
for (uint i = 0; i < slashableStake.length; i++) {
assertEq(slashableStake[i], 0, err);
}
}
function assert_DSF_Reset(
User staker,
IStrategy[] memory strategies,
string memory err
) internal {
uint[] memory depositScalingFactors = _getDepositScalingFactors(staker, strategies);
for (uint i = 0; i < strategies.length; i++) {
assertEq(depositScalingFactors[i], WAD, err);
}
}
/*******************************************************************************
SNAPSHOT ASSERTIONS
TIME TRAVELERS ONLY BEYOND THIS POINT
*******************************************************************************/
/*******************************************************************************
SNAPSHOT ASSERTIONS: ALLOCATIONS
*******************************************************************************/
function assert_Snap_Became_Registered(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal {
bool curIsMemberOfSet = _getIsMemberOfSet(operator, operatorSet);
bool prevIsMemberOfSet = _getPrevIsMemberOfSet(operator, operatorSet);
assertFalse(prevIsMemberOfSet, err);
assertTrue(curIsMemberOfSet, err);
}
function assert_Snap_Became_Deregistered(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal {
bool curIsMemberOfSet = _getIsMemberOfSet(operator, operatorSet);
bool prevIsMemberOfSet = _getPrevIsMemberOfSet(operator, operatorSet);
assertTrue(prevIsMemberOfSet, err);
assertFalse(curIsMemberOfSet, err);
}
function assert_Snap_Unchanged_Registration(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal {
bool curIsMemberOfSet = _getIsMemberOfSet(operator, operatorSet);
bool prevIsMemberOfSet = _getPrevIsMemberOfSet(operator, operatorSet);
assertEq(prevIsMemberOfSet, curIsMemberOfSet, err);
}
function assert_Snap_Became_Slashable(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal {
bool curIsSlashable = _getIsSlashable(operator, operatorSet);
bool prevIsSlashable = _getPrevIsSlashable(operator, operatorSet);
assertFalse(prevIsSlashable, err);
assertTrue(curIsSlashable, err);
}
function assert_Snap_Remains_Slashable(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal {
bool curIsSlashable = _getIsSlashable(operator, operatorSet);
bool prevIsSlashable = _getPrevIsSlashable(operator, operatorSet);
assertTrue(prevIsSlashable, err);
assertTrue(curIsSlashable, err);
}
function assert_Snap_Unchanged_Slashability(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal {
bool curIsSlashable = _getIsSlashable(operator, operatorSet);
bool prevIsSlashable = _getPrevIsSlashable(operator, operatorSet);
assertEq(prevIsSlashable, curIsSlashable, err);
}
function assert_Snap_Unchanged_AllocatedStrats(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal {
IStrategy[] memory curAllocatedStrats = _getAllocatedStrats(operator, operatorSet);
IStrategy[] memory prevAllocatedStrats = _getPrevAllocatedStrats(operator, operatorSet);
assertEq(curAllocatedStrats.length, prevAllocatedStrats.length, err);
for (uint i = 0; i < curAllocatedStrats.length; i++) {
assertEq(address(curAllocatedStrats[i]), address(prevAllocatedStrats[i]), err);
}
}
function assert_Snap_Unchanged_StrategyAllocations(
User operator,
OperatorSet memory operatorSet,
IStrategy[] memory strategies,
string memory err
) internal {
Allocation[] memory curAllocations = _getAllocations(operator, operatorSet, strategies);
Allocation[] memory prevAllocations = _getPrevAllocations(operator, operatorSet, strategies);
for (uint i = 0; i < strategies.length; i++) {
Allocation memory curAllocation = curAllocations[i];
Allocation memory prevAllocation = prevAllocations[i];
assertEq(curAllocation.currentMagnitude, prevAllocation.currentMagnitude, err);
assertEq(curAllocation.pendingDiff, prevAllocation.pendingDiff, err);
assertEq(curAllocation.effectBlock, prevAllocation.effectBlock, err);
}
}
function assert_Snap_Added_AllocatedSet(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal {
OperatorSet[] memory curAllocatedSets = _getAllocatedSets(operator);
OperatorSet[] memory prevAllocatedSets = _getPrevAllocatedSets(operator);
assertEq(curAllocatedSets.length, prevAllocatedSets.length + 1, err);
assertFalse(prevAllocatedSets.contains(operatorSet), err);
assertTrue(curAllocatedSets.contains(operatorSet), err);
}
function assert_Snap_Unchanged_AllocatedSets(
User operator,
string memory err
) internal {
OperatorSet[] memory curAllocatedSets = _getAllocatedSets(operator);
OperatorSet[] memory prevAllocatedSets = _getPrevAllocatedSets(operator);
assertEq(curAllocatedSets.length, prevAllocatedSets.length, err);
}
function assert_Snap_Removed_AllocatedSet(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal {
OperatorSet[] memory curAllocatedSets = _getAllocatedSets(operator);
OperatorSet[] memory prevAllocatedSets = _getPrevAllocatedSets(operator);
assertEq(curAllocatedSets.length + 1, prevAllocatedSets.length, err);
assertTrue(prevAllocatedSets.contains(operatorSet), err);
assertFalse(curAllocatedSets.contains(operatorSet), err);
}
function assert_Snap_Added_RegisteredSet(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal {
OperatorSet[] memory curRegisteredSets = _getRegisteredSets(operator);
OperatorSet[] memory prevRegisteredSets = _getPrevRegisteredSets(operator);
assertEq(curRegisteredSets.length, prevRegisteredSets.length + 1, err);
assertFalse(prevRegisteredSets.contains(operatorSet), err);
assertTrue(curRegisteredSets.contains(operatorSet), err);
}
function assert_Snap_Removed_RegisteredSet(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal {
OperatorSet[] memory curRegisteredSets = _getRegisteredSets(operator);
OperatorSet[] memory prevRegisteredSets = _getPrevRegisteredSets(operator);
assertEq(curRegisteredSets.length + 1, prevRegisteredSets.length, err);
assertTrue(prevRegisteredSets.contains(operatorSet), err);
assertFalse(curRegisteredSets.contains(operatorSet), err);
}
function assert_Snap_Unchanged_RegisteredSet(
User operator,
string memory err
) internal {
OperatorSet[] memory curRegisteredSets = _getRegisteredSets(operator);
OperatorSet[] memory prevRegisteredSets = _getPrevRegisteredSets(operator);
assertEq(curRegisteredSets.length, prevRegisteredSets.length, err);
for (uint i = 0; i < curRegisteredSets.length; i++) {
assertEq(curRegisteredSets[i].avs, prevRegisteredSets[i].avs, err);
assertEq(curRegisteredSets[i].id, prevRegisteredSets[i].id, err);
}
}
function assert_Snap_Added_MemberOfSet(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal {
address[] memory curOperators = _getMembers(operatorSet);
address[] memory prevOperators = _getPrevMembers(operatorSet);
assertEq(curOperators.length, prevOperators.length + 1, err);
assertFalse(prevOperators.contains(address(operator)), err);
assertTrue(curOperators.contains(address(operator)), err);
}
function assert_Snap_Removed_MemberOfSet(
User operator,
OperatorSet memory operatorSet,
string memory err
) internal {
address[] memory curOperators = _getMembers(operatorSet);
address[] memory prevOperators = _getPrevMembers(operatorSet);
assertEq(curOperators.length + 1, prevOperators.length, err);
assertTrue(prevOperators.contains(address(operator)), err);
assertFalse(curOperators.contains(address(operator)), err);
}
function assert_Snap_Unchanged_MemberOfSet(
OperatorSet memory operatorSet,
string memory err
) internal {
address[] memory curOperators = _getMembers(operatorSet);
address[] memory prevOperators = _getPrevMembers(operatorSet);
assertEq(curOperators.length, prevOperators.length, err);
for (uint i = 0; i < curOperators.length; i++) {
assertEq(curOperators[i], prevOperators[i], err);
}
}
function assert_Snap_StakeBecameSlashable(
User operator,
OperatorSet memory operatorSet,
IStrategy[] memory strategies,
string memory err
) internal {
uint[] memory curSlashableStake = _getMinSlashableStake(operator, operatorSet, strategies);
uint[] memory prevSlashableStake = _getPrevMinSlashableStake(operator, operatorSet, strategies);
for (uint i = 0; i < strategies.length; i++) {
assertTrue(prevSlashableStake[i] < curSlashableStake[i], err);
}
}
function assert_Snap_StakeBecomeUnslashable(
User operator,
OperatorSet memory operatorSet,
IStrategy[] memory strategies,
string memory err
) internal {
uint[] memory curSlashableStake = _getMinSlashableStake(operator, operatorSet, strategies);
uint[] memory prevSlashableStake = _getPrevMinSlashableStake(operator, operatorSet, strategies);
for (uint i = 0; i < strategies.length; i++) {
assertTrue(prevSlashableStake[i] > curSlashableStake[i], err);
}
}
function assert_Snap_Added_SlashableStake(
User operator,
OperatorSet memory operatorSet,
IStrategy[] memory strategies,
uint[] memory slashableShares,
string memory err
) internal {
uint[] memory curSlashableStake = _getMinSlashableStake(operator, operatorSet, strategies);
uint[] memory prevSlashableStake = _getPrevMinSlashableStake(operator, operatorSet, strategies);
for (uint i = 0; i < strategies.length; i++) {
assertEq(curSlashableStake[i], prevSlashableStake[i] + slashableShares[i], err);
}
}
function assert_Snap_Unchanged_SlashableStake(
User operator,
OperatorSet memory operatorSet,
IStrategy[] memory strategies,
string memory err
) internal {
uint[] memory curSlashableStake = _getMinSlashableStake(operator, operatorSet, strategies);
uint[] memory prevSlashableStake = _getPrevMinSlashableStake(operator, operatorSet, strategies);
for (uint i = 0; i < strategies.length; i++) {
assertEq(curSlashableStake[i], prevSlashableStake[i], err);
}
}
function assert_Snap_Removed_SlashableStake(
User operator,
OperatorSet memory operatorSet,
IStrategy[] memory strategies,
uint[] memory removedSlashableShares,
string memory err
) internal {
uint[] memory curSlashableStake = _getMinSlashableStake(operator, operatorSet, strategies);
uint[] memory prevSlashableStake = _getPrevMinSlashableStake(operator, operatorSet, strategies);
for (uint i = 0; i < strategies.length; i++) {
assertEq(curSlashableStake[i] + removedSlashableShares[i], prevSlashableStake[i], err);
}
}
function assert_Snap_Slashed_SlashableStake(
User operator,
OperatorSet memory operatorSet,
SlashingParams memory params,
string memory err
) internal {
uint[] memory curSlashableStake = _getMinSlashableStake(operator, operatorSet, params.strategies);
uint[] memory prevSlashableStake = _getPrevMinSlashableStake(operator, operatorSet, params.strategies);
Magnitudes[] memory curMagnitudes = _getMagnitudes(operator, params.strategies);
Magnitudes[] memory prevMagnitudes = _getPrevMagnitudes(operator, params.strategies);
for (uint i = 0; i < params.strategies.length; i++) {
uint expectedSlashed = SlashingLib.calcSlashedAmount({
operatorShares: prevSlashableStake[i],
prevMaxMagnitude: prevMagnitudes[i].max,
newMaxMagnitude: curMagnitudes[i].max
});
assertEq(curSlashableStake[i], prevSlashableStake[i] - expectedSlashed, err);
}
}
function assert_Snap_StakeBecameAllocated(
User operator,
OperatorSet memory operatorSet,
IStrategy[] memory strategies,
string memory err
) internal {
uint[] memory curMinAllocatedStake = _getAllocatedStake(operator, operatorSet, strategies);
uint[] memory prevMinAllocatedStake = _getPrevAllocatedStake(operator, operatorSet, strategies);
for (uint i = 0; i < strategies.length; i++) {
assertGt(curMinAllocatedStake[i], prevMinAllocatedStake[i], err);
}
}
function assert_Snap_StakeBecameDeallocated(
User operator,
OperatorSet memory operatorSet,
IStrategy[] memory strategies,
string memory err
) internal {
uint[] memory curMinAllocatedStake = _getAllocatedStake(operator, operatorSet, strategies);
uint[] memory prevMinAllocatedStake = _getPrevAllocatedStake(operator, operatorSet, strategies);
for (uint i = 0; i < strategies.length; i++) {
assertLt(curMinAllocatedStake[i], prevMinAllocatedStake[i], err);
}
}
function assert_Snap_Unchanged_AllocatedStake(
User operator,
OperatorSet memory operatorSet,
IStrategy[] memory strategies,
string memory err
) internal {
uint[] memory curAllocatedStake = _getAllocatedStake(operator, operatorSet, strategies);
uint[] memory prevAllocatedStake = _getPrevAllocatedStake(operator, operatorSet, strategies);
for (uint i = 0; i < curAllocatedStake.length; i++) {
assertEq(curAllocatedStake[i], prevAllocatedStake[i], err);
}
}
function assert_Snap_Slashed_AllocatedStake(
User operator,
OperatorSet memory operatorSet,
SlashingParams memory params,
string memory err
) internal {
uint[] memory curAllocatedStake = _getAllocatedStake(operator, operatorSet, params.strategies);
uint[] memory prevAllocatedStake = _getPrevAllocatedStake(operator, operatorSet, params.strategies);
Magnitudes[] memory curMagnitudes = _getMagnitudes(operator, params.strategies);
Magnitudes[] memory prevMagnitudes = _getPrevMagnitudes(operator, params.strategies);
for (uint i = 0; i < curAllocatedStake.length; i++) {
uint expectedSlashed = SlashingLib.calcSlashedAmount({
operatorShares: prevAllocatedStake[i],
prevMaxMagnitude: prevMagnitudes[i].max,
newMaxMagnitude: curMagnitudes[i].max
});
assertEq(curAllocatedStake[i], prevAllocatedStake[i] - expectedSlashed, err);
}
}
function assert_Snap_Added_EncumberedMagnitude(
User operator,
IStrategy[] memory strategies,
uint64[] memory magnitudeAdded,
string memory err
) internal {
Magnitudes[] memory curMagnitudes = _getMagnitudes(operator, strategies);
Magnitudes[] memory prevMagnitudes = _getPrevMagnitudes(operator, strategies);
for (uint i = 0; i < strategies.length; i++) {
assertEq(curMagnitudes[i].encumbered, prevMagnitudes[i].encumbered + magnitudeAdded[i], err);
}
}
function assert_Snap_Unchanged_EncumberedMagnitude(
User operator,
IStrategy[] memory strategies,
string memory err
) internal {
Magnitudes[] memory curMagnitudes = _getMagnitudes(operator, strategies);
Magnitudes[] memory prevMagnitudes = _getPrevMagnitudes(operator, strategies);
for (uint i = 0; i < strategies.length; i++) {
assertEq(curMagnitudes[i].encumbered, prevMagnitudes[i].encumbered, err);
}
}
function assert_Snap_Removed_EncumberedMagnitude(
User operator,
IStrategy[] memory strategies,
uint64[] memory magnitudeRemoved,
string memory err
) internal {