Skip to content

Commit

Permalink
Feat: SM/StrategyBase Unit Tests + Formatting (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
ypatil12 authored Oct 10, 2024
1 parent 8f090f4 commit cfdf90e
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 201 deletions.
2 changes: 1 addition & 1 deletion script/deploy/holesky/M2_Deploy_From_Scratch.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ contract M2_Deploy_Holesky_From_Scratch is ExistingDeploymentParser {
eigenPodBeacon = new UpgradeableBeacon(address(eigenPodImplementation));
avsDirectoryImplementation = new AVSDirectory(delegationManager, DEALLOCATION_DELAY);
delegationManagerImplementation = new DelegationManager(avsDirectory, strategyManager, eigenPodManager, allocationManager, MIN_WITHDRAWAL_DELAY);
strategyManagerImplementation = new StrategyManager(delegationManager, eigenPodManager, avsDirectory);
strategyManagerImplementation = new StrategyManager(delegationManager);
eigenPodManagerImplementation = new EigenPodManager(
IETHPOSDeposit(ETHPOSDepositAddress),
eigenPodBeacon,
Expand Down
6 changes: 1 addition & 5 deletions script/deploy/local/Deploy_From_Scratch.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ contract DeployFromScratch is Script, Test {
// Second, deploy the *implementation* contracts, using the *proxy contracts* as inputs

delegationImplementation = new DelegationManager(avsDirectory, strategyManager, eigenPodManager, allocationManager, MIN_WITHDRAWAL_DELAY);
strategyManagerImplementation = new StrategyManager(delegation, eigenPodManager, avsDirectory);
strategyManagerImplementation = new StrategyManager(delegation);
avsDirectoryImplementation = new AVSDirectory(delegation, DEALLOCATION_DELAY);
eigenPodManagerImplementation = new EigenPodManager(
ethPOSDeposit,
Expand Down Expand Up @@ -468,10 +468,6 @@ contract DeployFromScratch is Script, Test {
strategyManagerContract.delegation() == delegation,
"strategyManager: delegation address not set correctly"
);
require(
strategyManagerContract.eigenPodManager() == eigenPodManager,
"strategyManager: eigenPodManager address not set correctly"
);
require(
eigenPodManagerContract.ethPOS() == ethPOSDeposit,
" eigenPodManager: ethPOSDeposit contract address not set correctly"
Expand Down
2 changes: 1 addition & 1 deletion script/deploy/mainnet/EigenPod_Minor_Upgrade_Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ contract EigenPod_Minor_Upgrade_Deploy is Script, Test {
string memory deployment_data = vm.readFile(m2DeploymentOutputPath);
delegation = DelegationManager(stdJson.readAddress(deployment_data, ".addresses.delegationManager"));
strategyManager = DelegationManager(address(delegation)).strategyManager();
eigenPodManager = strategyManager.eigenPodManager();
eigenPodManager = DelegationManager(address(delegation)).eigenPodManager();
eigenPodBeacon = eigenPodManager.eigenPodBeacon();
ethPOS = eigenPodManager.ethPOS();

Expand Down
4 changes: 0 additions & 4 deletions script/utils/ExistingDeploymentParser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,6 @@ contract ExistingDeploymentParser is Script, Test {
strategyManager.delegation() == delegationManager,
"strategyManager: delegationManager address not set correctly"
);
require(
strategyManager.eigenPodManager() == eigenPodManager,
"strategyManager: eigenPodManager address not set correctly"
);
// EPM
require(
address(eigenPodManager.ethPOS()) == ETHPOSDepositAddress,
Expand Down
7 changes: 2 additions & 5 deletions src/contracts/core/StrategyManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@ contract StrategyManager is

/**
* @param _delegation The delegation contract of EigenLayer.
* @param _eigenPodManager The contract that keeps track of EigenPod stakes for restaking beacon chain ether.
*/
constructor(
IDelegationManager _delegation,
IEigenPodManager _eigenPodManager,
IAVSDirectory _avsDirectory
) StrategyManagerStorage(_delegation, _eigenPodManager, _avsDirectory) {
IDelegationManager _delegation
) StrategyManagerStorage(_delegation) {
_disableInitializers();
}

Expand Down
11 changes: 3 additions & 8 deletions src/contracts/core/StrategyManagerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ abstract contract StrategyManagerStorage is IStrategyManager {

IDelegationManager public immutable delegation;

IEigenPodManager public immutable eigenPodManager;

IAVSDirectory public immutable avsDirectory;

// Mutatables

bytes32 internal __deprecated_DOMAIN_SEPARATOR;

Check warning

Code scanning / Slither

State variables that could be declared constant Warning

Expand Down Expand Up @@ -85,12 +81,11 @@ abstract contract StrategyManagerStorage is IStrategyManager {

/**
* @param _delegation The delegation contract of EigenLayer.
* @param _eigenPodManager The contract that keeps track of EigenPod stakes for restaking beacon chain ether.
*/
constructor(IDelegationManager _delegation, IEigenPodManager _eigenPodManager, IAVSDirectory _avsDirectory) {
constructor(
IDelegationManager _delegation
) {
delegation = _delegation;
eigenPodManager = _eigenPodManager;
avsDirectory = _avsDirectory;
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/contracts/interfaces/IStrategyManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ interface IStrategyManager is IStrategyManagerErrors, IStrategyManagerEvents, IS
/// @notice Returns the single, central Delegation contract of EigenLayer
function delegation() external view returns (IDelegationManager);

/// @notice Returns the EigenPodManager contract of EigenLayer
function eigenPodManager() external view returns (IEigenPodManager);

/// @notice Returns the address of the `strategyWhitelister`
function strategyWhitelister() external view returns (address);

Expand Down
28 changes: 22 additions & 6 deletions src/contracts/libraries/SlashingLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ library SlashingLib {
) internal {
if (existingDepositShares == 0) {
// if this is their first deposit for the operator, set the scaling factor to inverse of totalMagnitude
ssf.depositScalingFactor = uint256(WAD).divWad(ssf.getBeaconChainScalingFactor()).divWad(totalMagnitude);
/// forgefmt: disable-next-item
ssf.depositScalingFactor =
uint256(WAD)
.divWad(ssf.getBeaconChainScalingFactor())
.divWad(totalMagnitude);

return;
}
/**
Expand Down Expand Up @@ -133,9 +138,12 @@ library SlashingLib {
uint256 newShares = currentShares + addedShares;

// Step 3: Calculate newStakerDepositScalingFactor
uint256 newStakerDepositScalingFactor = newShares.divWad(existingDepositShares + addedShares).divWad(
totalMagnitude
).divWad(uint256(ssf.getBeaconChainScalingFactor()));
/// forgefmt: disable-next-item
uint256 newStakerDepositScalingFactor =
newShares
.divWad(existingDepositShares + addedShares)
.divWad(totalMagnitude)
.divWad(uint256(ssf.getBeaconChainScalingFactor()));

ssf.depositScalingFactor = newStakerDepositScalingFactor;
}
Expand All @@ -147,7 +155,11 @@ library SlashingLib {
StakerScalingFactors memory ssf,
uint64 magnitude
) internal pure returns (uint256 depositShares) {
depositShares = shares.divWad(ssf.getDepositScalingFactor()).divWad(uint256(ssf.getBeaconChainScalingFactor()))
/// forgefmt: disable-next-item
depositShares =
shares
.divWad(ssf.getDepositScalingFactor())
.divWad(uint256(ssf.getBeaconChainScalingFactor()))
.divWad(uint256(magnitude));
}

Expand All @@ -156,7 +168,11 @@ library SlashingLib {
StakerScalingFactors memory ssf,
uint64 magnitude
) internal pure returns (uint256 shares) {
shares = depositShares.mulWad(ssf.getDepositScalingFactor()).mulWad(uint256(ssf.getBeaconChainScalingFactor()))
/// forgefmt: disable-next-item
shares =
depositShares
.mulWad(ssf.getDepositScalingFactor())
.mulWad(uint256(ssf.getBeaconChainScalingFactor()))
.mulWad(uint256(magnitude));
}
}
4 changes: 1 addition & 3 deletions src/contracts/mixins/SignatureUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ abstract contract SignatureUtils is ISignatureUtils {

/// @dev Helper for checking if a signature is valid, reverts if not valid.
function _checkIsValidSignatureNow(address signer, bytes32 signableDigest, bytes memory signature) internal view {
if (!signer.isValidSignatureNow(signableDigest, signature)) {
revert InvalidSignature();
}
require(signer.isValidSignatureNow(signableDigest, signature), InvalidSignature());
}
}
2 changes: 1 addition & 1 deletion src/test/DepositWithdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ contract DepositWithdrawTests is EigenLayerTestHelper {

// Second, deploy the *implementation* contracts, using the *proxy contracts* as inputs
DelegationManager delegationImplementation = new DelegationManager(avsDirectory, strategyManager, eigenPodManager, allocationManager, MIN_WITHDRAWAL_DELAY);
StrategyManager strategyManagerImplementation = new StrategyManager(delegation, eigenPodManager, avsDirectory);
StrategyManager strategyManagerImplementation = new StrategyManager(delegation);
EigenPodManager eigenPodManagerImplementation = new EigenPodManager(ethPOSDeposit, eigenPodBeacon, strategyManager, delegation);
// Third, upgrade the proxy contracts to use the correct implementation contracts and initialize them.
eigenLayerProxyAdmin.upgradeAndCall(
Expand Down
2 changes: 1 addition & 1 deletion src/test/EigenLayerDeployer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ contract EigenLayerDeployer is Operators {
17.5 days // min alloc delay
);

StrategyManager strategyManagerImplementation = new StrategyManager(delegation, eigenPodManager, avsDirectory);
StrategyManager strategyManagerImplementation = new StrategyManager(delegation);
EigenPodManager eigenPodManagerImplementation = new EigenPodManager(
ethPOSDeposit,
eigenPodBeacon,
Expand Down
6 changes: 3 additions & 3 deletions src/test/integration/IntegrationDeployer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ abstract contract IntegrationDeployer is ExistingDeploymentParser {
eigenPodBeacon = new UpgradeableBeacon(address(eigenPodImplementation));
// Second, deploy the *implementation* contracts, using the *proxy contracts* as inputs
delegationManagerImplementation = new DelegationManager(avsDirectory, strategyManager, eigenPodManager, allocationManager, MIN_WITHDRAWAL_DELAY);
strategyManagerImplementation = new StrategyManager(delegationManager, eigenPodManager, avsDirectory);
strategyManagerImplementation = new StrategyManager(delegationManager);
eigenPodManagerImplementation = new EigenPodManager(
ethPOSDeposit,
eigenPodBeacon,
Expand Down Expand Up @@ -382,7 +382,7 @@ abstract contract IntegrationDeployer is ExistingDeploymentParser {

// First, deploy the *implementation* contracts, using the *proxy contracts* as inputs
delegationManagerImplementation = new DelegationManager(avsDirectory, strategyManager, eigenPodManager, allocationManager, MIN_WITHDRAWAL_DELAY);
strategyManagerImplementation = new StrategyManager(delegationManager, eigenPodManager, avsDirectory);
strategyManagerImplementation = new StrategyManager(delegationManager);
eigenPodManagerImplementation = new EigenPodManager(
ethPOSDeposit,
eigenPodBeacon,
Expand Down Expand Up @@ -469,7 +469,7 @@ abstract contract IntegrationDeployer is ExistingDeploymentParser {

// First, deploy the *implementation* contracts, using the *proxy contracts* as inputs
delegationManagerImplementation = new DelegationManager(avsDirectory, strategyManager, eigenPodManager, allocationManager, MIN_WITHDRAWAL_DELAY);
strategyManagerImplementation = new StrategyManager(delegationManager, eigenPodManager, avsDirectory);
strategyManagerImplementation = new StrategyManager(delegationManager);
eigenPodManagerImplementation = new EigenPodManager(
ethPOSDeposit,
eigenPodBeacon,
Expand Down
4 changes: 0 additions & 4 deletions src/test/integration/tests/Upgrade_Setup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ contract IntegrationMainnetFork_UpgradeSetup is IntegrationCheckUtils {
strategyManager.delegation() == delegationManager,
"strategyManager: delegationManager address not set correctly"
);
require(
strategyManager.eigenPodManager() == eigenPodManager,
"strategyManager: eigenPodManager address not set correctly"
);
// EPM
require(
eigenPodManager.eigenPodBeacon() == eigenPodBeacon,
Expand Down
3 changes: 2 additions & 1 deletion src/test/integration/users/User_M1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "src/test/integration/deprecatedInterfaces/mainnet/IEigenPod.sol";
import "src/test/integration/deprecatedInterfaces/mainnet/IEigenPodManager.sol";
import "src/test/integration/deprecatedInterfaces/mainnet/IStrategyManager.sol";
import "src/test/integration/users/User.t.sol";
import "src/contracts/mixins/SignatureUtils.sol";

interface IUserMainnetForkDeployer {
function delegationManager() external view returns (DelegationManager);
Expand Down Expand Up @@ -108,7 +109,7 @@ contract User_M1_AltMethods is User_M1 {
expiry
)
);
bytes32 domain_separator = keccak256(abi.encode(EIP712_DOMAIN_TYPEHASH, keccak256(bytes("EigenLayer")), block.chainid, address(strategyManager)));
bytes32 domain_separator = strategyManager.domainSeparator();
bytes32 digestHash =
keccak256(abi.encodePacked("\x19\x01", domain_separator, structHash));
bytes memory signature = bytes(abi.encodePacked(digestHash)); // dummy sig data
Expand Down
Loading

0 comments on commit cfdf90e

Please sign in to comment.