diff --git a/src/contracts/core/DelegationManager.sol b/src/contracts/core/DelegationManager.sol index b719d0bf3..68b8c0c8e 100644 --- a/src/contracts/core/DelegationManager.sol +++ b/src/contracts/core/DelegationManager.sol @@ -516,8 +516,8 @@ contract DelegationManager is operator: operator, staker: staker, strategy: strategies[i], - existingShares: Shares(0), - addedOwnedShares: ownedShares[i], + existingShares: Shares.wrap(0), + addedShares: ownedShares[i].unwrap().wrapShares(), totalMagnitude: totalMagnitudes[i] }); } @@ -745,14 +745,13 @@ contract DelegationManager is Shares existingShares, Shares addedShares ) internal returns (uint256 newDepositScalingFactor) { - uint256 newDepositScalingFactor; if (existingShares.isZero()) { newDepositScalingFactor = WAD / totalMagnitude; } else { - newDepositScalingFactor = existingShares.calculateNewScalingFactor( - addedShares: addedShares, - oldStakerScalingFactor: depositScalingFactors[staker][strategy], - totalMagnitude: totalMagnitude + newDepositScalingFactor = existingShares.calculateNewDepositScalingFactor( + addedShares, + depositScalingFactors[staker][strategy], + totalMagnitude ); } @@ -866,8 +865,8 @@ contract DelegationManager is // forgefmt: disable-next-item ownedShares[i] = shares.toOwnedShares( - stakerScalingFactor: depositScalingFactors[staker][strategies[i]], - operatorMagnitude: totalMagnitude + depositScalingFactors[staker][strategies[i]], + totalMagnitude ); } } diff --git a/src/contracts/core/StrategyManager.sol b/src/contracts/core/StrategyManager.sol index bd3dd7ed4..a0fcb5dde 100644 --- a/src/contracts/core/StrategyManager.sol +++ b/src/contracts/core/StrategyManager.sol @@ -171,7 +171,8 @@ contract StrategyManager is IERC20 token, OwnedShares ownedShares ) external onlyDelegationManager { - _addOwnedShares(staker, token, strategy, ownedShares); + //TODO: fix + // _addShares(staker, token, strategy, ownedShares); } /// @notice Used by the DelegationManager to convert withdrawn shares to tokens and send them to a recipient @@ -238,7 +239,7 @@ contract StrategyManager is * @param staker The address to add shares to * @param token The token that is being deposited (used for indexing) * @param strategy The Strategy in which the `staker` is receiving shares - * @param shares The amount of shares to grant to the `staker` + * @param sharesToAdd The amount of shares to grant to the `staker` * @dev In particular, this function calls `delegation.increaseDelegatedShares(staker, strategy, shares)` to ensure that all * delegated shares are tracked, increases the stored share amount in `stakerStrategyShares[staker][strategy]`, and adds `strategy` * to the `staker`'s list of strategies, if it is not in the list already. @@ -293,7 +294,7 @@ contract StrategyManager is uint256 depositedShares = strategy.deposit(token, amount); // add the returned shares to the staker's existing shares for this strategy - _addShares(staker, token, strategy, depositedShares); + _addShares(staker, token, strategy, depositedShares.wrapShares()); return depositedShares.wrapShares(); } diff --git a/src/contracts/interfaces/IDelegationManager.sol b/src/contracts/interfaces/IDelegationManager.sol index 189acb111..4ee8390aa 100644 --- a/src/contracts/interfaces/IDelegationManager.sol +++ b/src/contracts/interfaces/IDelegationManager.sol @@ -348,7 +348,7 @@ interface IDelegationManager is ISignatureUtils { * @param strategy The strategy in which to increase the delegated shares. * @param existingShares The number of deposit shares the staker already has in the strategy. This is the shares amount stored in the * StrategyManager/EigenPodManager for the staker's shares. - * @param addedOwnedShares The number of shares to added to the staker's shares in the strategy. This amount will be scaled prior to adding + * @param addedShares The number of shares to added to the staker's shares in the strategy. This amount will be scaled prior to adding * to the operator's scaled shares. * * @dev *If the staker is actively delegated*, then increases the `staker`'s delegated scaled shares in `strategy`. @@ -359,7 +359,7 @@ interface IDelegationManager is ISignatureUtils { address staker, IStrategy strategy, Shares existingShares, - OwnedShares addedOwnedShares + Shares addedShares ) external; /** diff --git a/src/contracts/interfaces/IStrategyManager.sol b/src/contracts/interfaces/IStrategyManager.sol index c0967d9b4..29289688d 100644 --- a/src/contracts/interfaces/IStrategyManager.sol +++ b/src/contracts/interfaces/IStrategyManager.sol @@ -42,7 +42,7 @@ interface IStrategyManager is IShareManager { * @param token Is the token that `staker` deposited. * @param shares Is the number of new shares `staker` has been granted in `strategy`. */ - event Deposit(address staker, IERC20 token, IStrategy strategy, OwnedShares shares); + event Deposit(address staker, IERC20 token, IStrategy strategy, Shares shares); /// @notice Emitted when the `strategyWhitelister` is changed event StrategyWhitelisterChanged(address previousAddress, address newAddress); @@ -65,7 +65,7 @@ interface IStrategyManager is IShareManager { * WARNING: Depositing tokens that allow reentrancy (eg. ERC-777) into a strategy is not recommended. This can lead to attack vectors * where the token balance and corresponding strategy shares are not in sync upon reentrancy. */ - function depositIntoStrategy(IStrategy strategy, IERC20 token, uint256 amount) external returns (OwnedShares shares); + function depositIntoStrategy(IStrategy strategy, IERC20 token, uint256 amount) external returns (Shares shares); /** * @notice Used for depositing an asset into the specified strategy with the resultant shares credited to `staker`, @@ -94,7 +94,7 @@ interface IStrategyManager is IShareManager { address staker, uint256 expiry, bytes memory signature - ) external returns (OwnedShares shares); + ) external returns (Shares shares); /** * @notice Get all details on the staker's deposits and corresponding shares diff --git a/src/contracts/libraries/SlashingLib.sol b/src/contracts/libraries/SlashingLib.sol index 78605b196..76478f380 100644 --- a/src/contracts/libraries/SlashingLib.sol +++ b/src/contracts/libraries/SlashingLib.sol @@ -99,8 +99,8 @@ library SlashingLib { function toOwnedShares( Shares shares, - uint64 stakerScalingFactor, - uint64 operatorMagnitude + uint256 stakerScalingFactor, + uint256 operatorMagnitude ) internal pure returns (OwnedShares) { /** * ownedShares = shares * stakerScalingFactor * operatorMagnitude @@ -118,9 +118,9 @@ library SlashingLib { function calculateNewDepositScalingFactor( Shares currentShares, Shares addedShares, - uint64 stakerScalingFactor, - uint64 operatorMagnitude - ) internal pure returns (uint64) { + uint256 stakerScalingFactor, + uint256 operatorMagnitude + ) internal pure returns (uint256) { /** * Base Equations: * (1) newShares = currentShares + addedShares @@ -145,10 +145,10 @@ library SlashingLib { */ // Step 1: Calculate Numerator - OwnedShares currentOwnedShares = currentShares.toOwnedShares(stakerScalingFactor, operatorMagnitude); + uint256 currentOwnedShares = currentShares.toOwnedShares(stakerScalingFactor, operatorMagnitude).unwrap(); // Step 2: Compute currentShares + addedShares - uint256 ownedPlusAddedShares = currentOwnedShares.add(addedShares).unwrap(); + uint256 ownedPlusAddedShares = currentOwnedShares + addedShares.unwrap(); // Step 3: Calculate newStakerScalingFactor // Note: We divide by operatorMagnitude to preserve @@ -156,7 +156,7 @@ library SlashingLib { //TODO: figure out if we only need to do one divWad here uint256 newStakerScalingFactor = ownedPlusAddedShares - .divWad(currentShares.unwrap() + addedOwnedShares.unwrap()) + .divWad(currentShares.unwrap() + addedShares.unwrap()) .divWad(operatorMagnitude); return newStakerScalingFactor; @@ -168,6 +168,10 @@ library SlashingLib { return x.unwrap() + y; } + function add(Shares x, Shares y) internal pure returns (Shares) { + return (x.unwrap() + y.unwrap()).wrapShares(); + } + function add(DelegatedShares x, uint256 y) internal pure returns (uint256) { return x.unwrap() + y; } @@ -188,6 +192,10 @@ library SlashingLib { return x.unwrap() - y; } + function sub(Shares x, Shares y) internal pure returns (Shares) { + return (x.unwrap() - y.unwrap()).wrapShares(); + } + function sub(DelegatedShares x, uint256 y) internal pure returns (uint256) { return x.unwrap() - y; } @@ -216,6 +224,10 @@ library SlashingLib { return x.unwrap() == 0; } + function isZero(OwnedShares x) internal pure returns (bool) { + return x.unwrap() == 0; + } + function lte(Shares x, Shares y) internal pure returns (bool) { return x.unwrap() <= y.unwrap(); }