@@ -18,6 +18,7 @@ import "src/test/integration/users/User_M1.t.sol";
18
18
abstract contract IntegrationBase is IntegrationDeployer , TypeImporter {
19
19
using StdStyle for * ;
20
20
using SlashingLib for * ;
21
+ using Math for uint256 ;
21
22
using Strings for * ;
22
23
using print for * ;
23
24
@@ -68,6 +69,35 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
68
69
return (staker, strategies, tokenBalances);
69
70
}
70
71
72
+ function _newBasicStaker () internal returns (User, IStrategy[] memory , uint [] memory ) {
73
+ string memory stakerName;
74
+
75
+ User staker;
76
+ IStrategy[] memory strategies;
77
+ uint [] memory tokenBalances;
78
+
79
+ if (! isUpgraded) {
80
+ stakerName = string .concat ("M2Staker " , cheats.toString (numStakers));
81
+
82
+ (staker, strategies, tokenBalances) = _randUser (stakerName);
83
+
84
+ stakersToMigrate.push (staker);
85
+ } else {
86
+ stakerName = string .concat ("staker " , cheats.toString (numStakers));
87
+
88
+ (staker, strategies, tokenBalances) = _randUser (stakerName);
89
+ }
90
+
91
+ assert_HasUnderlyingTokenBalances (staker, strategies, tokenBalances, "_newRandomStaker: failed to award token balances " );
92
+
93
+ numStakers++ ;
94
+ assembly { // TODO HACK
95
+ mstore (strategies, 1 )
96
+ mstore (tokenBalances, 1 )
97
+ }
98
+ return (staker, strategies, tokenBalances);
99
+ }
100
+
71
101
/**
72
102
* @dev Create a new operator according to configured random variants.
73
103
* This user will immediately deposit their randomized assets into eigenlayer.
@@ -835,6 +865,21 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
835
865
}
836
866
}
837
867
868
+ function assert_Snap_Slashed_SlashableStake (
869
+ User operator ,
870
+ OperatorSet memory operatorSet ,
871
+ SlashingParams memory params ,
872
+ string memory err
873
+ ) internal {
874
+ uint [] memory curSlashableStake = _getMinSlashableStake (operator, operatorSet, params.strategies);
875
+ uint [] memory prevSlashableStake = _getPrevMinSlashableStake (operator, operatorSet, params.strategies);
876
+
877
+ for (uint i = 0 ; i < params.strategies.length ; i++ ) {
878
+ uint expectedSlashed = prevSlashableStake[i].mulWadRoundUp (params.wadsToSlash[i]);
879
+ assertEq (curSlashableStake[i], prevSlashableStake[i] - expectedSlashed, err);
880
+ }
881
+ }
882
+
838
883
function assert_Snap_StakeBecameAllocated (
839
884
User operator ,
840
885
OperatorSet memory operatorSet ,
@@ -877,6 +922,59 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
877
922
}
878
923
}
879
924
925
+ function assert_Snap_Slashed_AllocatedStake (
926
+ User operator ,
927
+ OperatorSet memory operatorSet ,
928
+ SlashingParams memory params ,
929
+ string memory err
930
+ ) internal {
931
+ uint [] memory curAllocatedStake = _getAllocatedStake (operator, operatorSet, params.strategies);
932
+ uint [] memory prevAllocatedStake = _getPrevAllocatedStake (operator, operatorSet, params.strategies);
933
+
934
+ Magnitudes[] memory curMagnitudes = _getMagnitudes (operator, params.strategies);
935
+ Magnitudes[] memory prevMagnitudes = _getPrevMagnitudes (operator, params.strategies);
936
+
937
+ for (uint i = 0 ; i < curAllocatedStake.length ; i++ ) {
938
+ // uint expectedSlashed = prevAllocatedStake[i].mulDiv(params.wadsToSlash[i], WAD, Math.Rounding.Up);
939
+ uint actualSlashed = prevAllocatedStake[i] - curAllocatedStake[i];
940
+ uint expectedSlashed = prevAllocatedStake[i].mulWadRoundUp (params.wadsToSlash[i]);
941
+
942
+ emit log_named_uint ("prev enc mag " , prevMagnitudes[i].encumbered);
943
+ emit log_named_uint ("prev max mag " , prevMagnitudes[i].max);
944
+
945
+ emit log_named_uint ("cur enc mag " , curMagnitudes[i].encumbered);
946
+ emit log_named_uint ("cur max mag " , curMagnitudes[i].max);
947
+
948
+ emit log ("-- " );
949
+
950
+ emit log_named_uint ("prevStake " , prevAllocatedStake[i]);
951
+ emit log_named_uint ("curStake " , curAllocatedStake[i]);
952
+ emit log_named_uint ("opShares " , delegationManager.operatorShares (address (operator), params.strategies[0 ]));
953
+ emit log_named_uint ("expected slash " , expectedSlashed);
954
+ emit log_named_uint ("actual slash " , actualSlashed);
955
+ emit log_named_string ("eq? " , expectedSlashed == actualSlashed ? "true " : "false " );
956
+
957
+ emit log ("-- " );
958
+
959
+ emit log ("eq: " );
960
+
961
+ emit log_named_uint ("prevStake " , prevAllocatedStake[i]);
962
+ emit log_named_uint ("expected + cur " , curAllocatedStake[i] + expectedSlashed);
963
+
964
+ emit log ("eq: " );
965
+
966
+ emit log_named_uint ("curStake " , curAllocatedStake[i]);
967
+ emit log_named_uint ("prev - expected " , prevAllocatedStake[i] - expectedSlashed);
968
+
969
+ emit log ("-- " );
970
+
971
+ uint res = prevAllocatedStake[i] - expectedSlashed;
972
+ emit log_named_string ("result eq " , res == curAllocatedStake[i] ? "true " : "false " );
973
+
974
+ assertEq (curAllocatedStake[i], prevAllocatedStake[i] - expectedSlashed, err);
975
+ }
976
+ }
977
+
880
978
function assert_Snap_Added_EncumberedMagnitude (
881
979
User operator ,
882
980
IStrategy[] memory strategies ,
@@ -918,6 +1016,20 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
918
1016
}
919
1017
}
920
1018
1019
+ function assert_Snap_Slashed_EncumberedMagnitude (
1020
+ User operator ,
1021
+ SlashingParams memory params ,
1022
+ string memory err
1023
+ ) internal {
1024
+ Magnitudes[] memory curMagnitudes = _getMagnitudes (operator, params.strategies);
1025
+ Magnitudes[] memory prevMagnitudes = _getPrevMagnitudes (operator, params.strategies);
1026
+
1027
+ for (uint i = 0 ; i < params.strategies.length ; i++ ) {
1028
+ uint expectedSlashed = prevMagnitudes[i].encumbered.mulWadRoundUp (params.wadsToSlash[i]);
1029
+ assertEq (curMagnitudes[i].encumbered, prevMagnitudes[i].encumbered - expectedSlashed, err);
1030
+ }
1031
+ }
1032
+
921
1033
function assert_Snap_Added_AllocatableMagnitude (
922
1034
User operator ,
923
1035
IStrategy[] memory strategies ,
@@ -948,14 +1060,14 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
948
1060
function assert_Snap_Removed_AllocatableMagnitude (
949
1061
User operator ,
950
1062
IStrategy[] memory strategies ,
951
- uint64 [] memory magnitudeAllocated ,
1063
+ uint64 [] memory magnitudeRemoved ,
952
1064
string memory err
953
1065
) internal {
954
1066
Magnitudes[] memory curMagnitudes = _getMagnitudes (operator, strategies);
955
1067
Magnitudes[] memory prevMagnitudes = _getPrevMagnitudes (operator, strategies);
956
1068
957
1069
for (uint i = 0 ; i < strategies.length ; i++ ) {
958
- assertEq (curMagnitudes[i].allocatable, prevMagnitudes[i].allocatable - magnitudeAllocated [i], err);
1070
+ assertEq (curMagnitudes[i].allocatable, prevMagnitudes[i].allocatable - magnitudeRemoved [i], err);
959
1071
}
960
1072
}
961
1073
@@ -1009,6 +1121,21 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
1009
1121
}
1010
1122
}
1011
1123
1124
+ function assert_Snap_Slashed_Allocation (
1125
+ User operator ,
1126
+ OperatorSet memory operatorSet ,
1127
+ SlashingParams memory params ,
1128
+ string memory err
1129
+ ) internal {
1130
+ Allocation[] memory curAllocations = _getAllocations (operator, operatorSet, params.strategies);
1131
+ Allocation[] memory prevAllocations = _getPrevAllocations (operator, operatorSet, params.strategies);
1132
+
1133
+ for (uint i = 0 ; i < params.strategies.length ; i++ ) {
1134
+ uint expectedSlashed = prevAllocations[i].currentMagnitude.mulWadRoundUp (params.wadsToSlash[i]);
1135
+ assertEq (curAllocations[i].currentMagnitude, prevAllocations[i].currentMagnitude - expectedSlashed, err);
1136
+ }
1137
+ }
1138
+
1012
1139
function assert_Snap_Unchanged_MaxMagnitude (
1013
1140
User operator ,
1014
1141
IStrategy[] memory strategies ,
@@ -1022,6 +1149,20 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
1022
1149
}
1023
1150
}
1024
1151
1152
+ function assert_Snap_Slashed_MaxMagnitude (
1153
+ User operator ,
1154
+ SlashingParams memory params ,
1155
+ string memory err
1156
+ ) internal {
1157
+ Magnitudes[] memory curMagnitudes = _getMagnitudes (operator, params.strategies);
1158
+ Magnitudes[] memory prevMagnitudes = _getPrevMagnitudes (operator, params.strategies);
1159
+
1160
+ for (uint i = 0 ; i < params.strategies.length ; i++ ) {
1161
+ uint expectedSlashed = prevMagnitudes[i].max.mulWadRoundUp (params.wadsToSlash[i]);
1162
+ assertEq (curMagnitudes[i].max, prevMagnitudes[i].max - expectedSlashed, err);
1163
+ }
1164
+ }
1165
+
1025
1166
function assert_Snap_Allocations_Slashed (
1026
1167
SlashingParams memory slashingParams ,
1027
1168
OperatorSet memory operatorSet ,
@@ -1193,7 +1334,7 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
1193
1334
1194
1335
// For each strategy, check (prev - removed == cur)
1195
1336
for (uint i = 0 ; i < strategies.length ; i++ ) {
1196
- assertEq (prevShares[i] - removedShares [i], curShares [i], err);
1337
+ assertEq (prevShares[i], curShares [i] + removedShares [i], err);
1197
1338
}
1198
1339
}
1199
1340
@@ -1237,6 +1378,21 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
1237
1378
}
1238
1379
}
1239
1380
1381
+ function assert_Snap_Slashed_OperatorShares (
1382
+ User operator ,
1383
+ SlashingParams memory params ,
1384
+ string memory err
1385
+ ) internal {
1386
+ uint [] memory curShares = _getOperatorShares (operator, params.strategies);
1387
+ uint [] memory prevShares = _getPrevOperatorShares (operator, params.strategies);
1388
+
1389
+ for (uint i = 0 ; i < params.strategies.length ; i++ ) {
1390
+ // uint expectedSlashed = prevShares[i].mulDiv(params.wadsToSlash[i], WAD, Math.Rounding.Down);
1391
+ uint expectedSlashed = prevShares[i].mulWadRoundUp (params.wadsToSlash[i]);
1392
+ assertEq (curShares[i], prevShares[i] - expectedSlashed, err);
1393
+ }
1394
+ }
1395
+
1240
1396
/*******************************************************************************
1241
1397
SNAPSHOT ASSERTIONS: STAKER SHARES
1242
1398
*******************************************************************************/
@@ -1773,12 +1929,34 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
1773
1929
Magnitudes[] memory magnitudes = _getMagnitudes (operator, strategies);
1774
1930
1775
1931
for (uint i = 0 ; i < params.strategies.length ; i++ ) {
1776
- IStrategy strategy = params.strategies[i];
1777
1932
uint64 halfAvailable = uint64 (magnitudes[i].allocatable) / 2 ;
1778
1933
params.newMagnitudes[i] = allocations[i].currentMagnitude + halfAvailable;
1779
1934
}
1780
1935
}
1781
1936
1937
+ /// @dev Generate params to allocate a random portion of available magnitude to each strategy
1938
+ /// in the operator set. All strategies will have a nonzero allocation, and the minimum allocation
1939
+ /// will be 10% of available magnitude
1940
+ function _genAllocation_Rand (
1941
+ User operator ,
1942
+ OperatorSet memory operatorSet
1943
+ ) internal returns (AllocateParams memory params ) {
1944
+ params.operatorSet = operatorSet;
1945
+ params.strategies = allocationManager.getStrategiesInOperatorSet (operatorSet);
1946
+ params.newMagnitudes = new uint64 [](params.strategies.length );
1947
+
1948
+ Allocation[] memory allocations = _getAllocations (operator, operatorSet, params.strategies);
1949
+ Magnitudes[] memory magnitudes = _getMagnitudes (operator, params.strategies);
1950
+
1951
+ for (uint i = 0 ; i < params.strategies.length ; i++ ) {
1952
+ // minimum of 10%, maximum of 100%. increments of 10%.
1953
+ uint r = _randUint ({min: 1 , max: 10 });
1954
+ uint64 allocation = uint64 (magnitudes[i].allocatable) / uint64 (r);
1955
+
1956
+ params.newMagnitudes[i] = allocations[i].currentMagnitude + allocation;
1957
+ }
1958
+ }
1959
+
1782
1960
/// @dev Generates params for a half deallocation from all strategies the operator is allocated to in the operator set
1783
1961
function _genDeallocation_HalfRemaining (
1784
1962
User operator ,
@@ -1824,12 +2002,46 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
1824
2002
User operator ,
1825
2003
OperatorSet memory operatorSet ,
1826
2004
IStrategy[] memory strategies
1827
- ) internal view returns (AllocateParams memory params ) {
2005
+ ) internal pure returns (AllocateParams memory params ) {
1828
2006
params.operatorSet = operatorSet;
1829
2007
params.strategies = strategies;
1830
2008
params.newMagnitudes = new uint64 [](params.strategies.length );
1831
2009
}
1832
2010
2011
+ /// Generate random slashing between 1 and 99%
2012
+ function _genSlashing_Rand (
2013
+ User operator ,
2014
+ OperatorSet memory operatorSet
2015
+ ) internal returns (SlashingParams memory params ) {
2016
+ params.operator = address (operator);
2017
+ params.operatorSetId = operatorSet.id;
2018
+ params.description = "genSlashing_Half " ;
2019
+ params.strategies = allocationManager.getStrategiesInOperatorSet (operatorSet).sort ();
2020
+ params.wadsToSlash = new uint [](params.strategies.length );
2021
+
2022
+ /// 1% * rand(1, 99)
2023
+ uint slashWad = 1e16 * _randUint ({min: 1 , max: 99 });
2024
+
2025
+ for (uint i = 0 ; i < params.wadsToSlash.length ; i++ ) {
2026
+ params.wadsToSlash[i] = slashWad;
2027
+ }
2028
+ }
2029
+
2030
+ function _genSlashing_Half (
2031
+ User operator ,
2032
+ OperatorSet memory operatorSet
2033
+ ) internal view returns (SlashingParams memory params ) {
2034
+ params.operator = address (operator);
2035
+ params.operatorSetId = operatorSet.id;
2036
+ params.description = "genSlashing_Half " ;
2037
+ params.strategies = allocationManager.getStrategiesInOperatorSet (operatorSet).sort ();
2038
+ params.wadsToSlash = new uint [](params.strategies.length );
2039
+
2040
+ for (uint i = 0 ; i < params.wadsToSlash.length ; i++ ) {
2041
+ params.wadsToSlash[i] = 1e17 ;
2042
+ }
2043
+ }
2044
+
1833
2045
function _randWadToSlash () internal returns (uint ) {
1834
2046
return _randUint ({ min: 0.01 ether, max: 1 ether });
1835
2047
}
0 commit comments