Skip to content

Commit

Permalink
add advancing index for nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
danoctavian committed Nov 7, 2024
1 parent 4c34cd3 commit e806829
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/ynEIGEN/withdrawalsProcessor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ contract WithdrawalsProcessor is Ownable {
uint256 minNodeShares;
uint96 maxNodeAllocation;
uint8 nodeCursor;
uint96 currentNodeAllocation;
}

// @todo - put ids in a struct
Expand Down Expand Up @@ -75,7 +74,6 @@ contract WithdrawalsProcessor is Ownable {

uint96 public maxNodeAllocation;
uint8 public nodeCursor;
uint96 public currentNodeAllocation;

//
// Constructor
Expand Down Expand Up @@ -122,14 +120,17 @@ contract WithdrawalsProcessor is Ownable {
uint256 _pendingWithdrawalRequests = withdrawalQueueManager.pendingRequestedRedemptionAmount() - totalQueuedWithdrawals;
if (_pendingWithdrawalRequests <= minPendingWithdrawalRequestAmount) revert PendingWithdrawalRequestsTooLow();

if (_pendingWithdrawalRequests > maxNodeAllocation) {
_pendingWithdrawalRequests = maxNodeAllocation;
}

uint256 _toBeQueued = _pendingWithdrawalRequests;

ITokenStakingNode[] memory _nodes = tokenStakingNodesManager.getAllNodes();
IERC20[] memory _assets = assetRegistry.getAssets();
QueuedWithdrawalsVars memory vars = QueuedWithdrawalsVars({
maxNodeAllocation: maxNodeAllocation,
nodeCursor: nodeCursor,
currentNodeAllocation: currentNodeAllocation,
queuedId: queuedId,
assetsLength: _assets.length,
nodesLength: _nodes.length,
Expand All @@ -141,9 +142,13 @@ contract WithdrawalsProcessor is Ownable {
IStrategy _strategy = ynStrategyManager.strategies(_assets[i]);
uint256 _pendingWithdrawalRequestsInShares = _unitToShares(_pendingWithdrawalRequests, _assets[i], _strategy);

for (uint256 j = 0; j < vars.nodesLength; ++j) {
uint256 j = 0;
for (j = 0; j < vars.nodesLength; ++j) {
uint256 _withdrawnShares;
address _node = address(_nodes[j]);

uint256 nodeIndex = (j + vars.nodeCursor) % vars.nodesLength;

address _node = address(_nodes[nodeIndex]);
uint256 _nodeShares = _strategy.shares(_node);
if (_nodeShares > _pendingWithdrawalRequestsInShares) {
_withdrawnShares =
Expand Down Expand Up @@ -172,19 +177,30 @@ contract WithdrawalsProcessor is Ownable {
batch[queuedId] = vars.queuedId;
queuedId = vars.queuedId;
totalQueuedWithdrawals += _toBeQueued;

vars.nodeCursor = uint8(j);
nodeCursor = vars.nodeCursor;

return true;
}
}

vars.nodeCursor = uint8(j);


_pendingWithdrawalRequests = _sharesToUnit(_pendingWithdrawalRequestsInShares, _assets[i], _strategy);
}



if (_pendingWithdrawalRequests < _toBeQueued) {
batch[queuedId] = vars.queuedId;
queuedId = vars.queuedId;
totalQueuedWithdrawals += _toBeQueued - _pendingWithdrawalRequests;
}

nodeCursor = vars.nodeCursor;

return false;
}

Expand Down Expand Up @@ -281,6 +297,10 @@ contract WithdrawalsProcessor is Ownable {
: assetRegistry.convertToUnitOfAccount(_asset, _amount);
}

function _min(uint256 a, uint256 b) private pure returns (uint256) {
return a < b ? a : b;
}

//
// Errors
//
Expand Down

0 comments on commit e806829

Please sign in to comment.