Skip to content

Commit

Permalink
fix: Use scaled shares instead of deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
fzavalia committed Feb 14, 2025
1 parent 596cfbf commit 0b29c9d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/ynEIGEN/TokenStakingNode.sol
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,31 @@ contract TokenStakingNode is ITokenStakingNode, Initializable, ReentrancyGuardUp

// `onlyWhenOperatorSynchronized` is used so we can assume that the operator is the same as the one in the DelegationManager.
address _operator = delegatedTo;
uint256 _withdrawableShares = 0;
uint256 _withdrawableShares;
bytes32 _withdrawalRoot;

if (_operator == address(0)) {
_fullWithdrawalRoots = _delegationManager.queueWithdrawals(_params);

// If the staker has not yet delegated to an operator, and given that this contract does not handle beacon chain strategies,
// we can assume that the withdrawal shares are equal to the deposit shares.
_withdrawableShares = _depositShares;
_withdrawalRoot = _fullWithdrawalRoots[0];
IDelegationManagerTypes.Withdrawal memory _queuedWithdrawal = _delegationManager.getQueuedWithdrawal(_withdrawalRoot);

// If the staker has not yet delegated to an operator, and given that this contract does not handle the beacon chain strategy.
// We can assume that the scaledShares can be used as the withdrawable shares because:
// - withdrawableShares = scaledShares * maxMagnitude * beaconChainSlashFactor.
// - scaledShares = withdrawableShares / (maxMagnitude * beaconChainSlashFactor).
// - scaledShares = withdrawableShares / (1 * 1). maxMagnitude is 1 when not delegated and beaconChainSlashFactor is 1 because it is not using the beacon chain strategy.
// - scaledShares = withdrawableShares.
_withdrawableShares = _queuedWithdrawal.scaledShares[0];
} else {
uint256[] memory operatorSharesBefore = _delegationManager.getOperatorShares(_operator, _params[0].strategies);
_fullWithdrawalRoots = _delegationManager.queueWithdrawals(_params);
_withdrawalRoot = _fullWithdrawalRoots[0];
uint256[] memory operatorSharesAfter = _delegationManager.getOperatorShares(_operator, _params[0].strategies);

// Operator shares are decreased by the amount of withdrawable shares so we can use the difference to update the queued shares.
_withdrawableShares = operatorSharesAfter[0] - operatorSharesBefore[0];
}

bytes32 _withdrawalRoot = _fullWithdrawalRoots[0];

queuedShares[_strategy] += _withdrawableShares;
maxMagnitudeByWithdrawalRoot[_withdrawalRoot] = _delegationManager.allocationManager().getMaxMagnitude(_operator, _strategy);
withdrawableSharesByWithdrawalRoot[_withdrawalRoot] = _withdrawableShares;
Expand Down

0 comments on commit 0b29c9d

Please sign in to comment.