Skip to content

Commit 7c1b558

Browse files
committed
fix: Support 1.0.3 eigen api
1 parent 3d19316 commit 7c1b558

File tree

11 files changed

+136
-133
lines changed

11 files changed

+136
-133
lines changed

src/StakingNode.sol

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ contract StakingNode is IStakingNode, StakingNodeEvents, ReentrancyGuardUpgradea
289289
address operator = delegationManager.delegatedTo(address(this));
290290

291291
// Get current shares before undelegating
292-
int256 shares = stakingNodesManager.eigenPodManager().podOwnerShares(address(this));
292+
int256 shares = stakingNodesManager.eigenPodManager().podOwnerDepositShares(address(this));
293293
withdrawalRoots = delegationManager.undelegate(address(this));
294294

295295
if (shares > 0) {
@@ -374,7 +374,7 @@ contract StakingNode is IStakingNode, StakingNodeEvents, ReentrancyGuardUpgradea
374374
bool[] memory receiveAsTokens = new bool[](withdrawals.length);
375375
IERC20V4[][] memory tokens = new IERC20V4[][](withdrawals.length);
376376
for (uint256 i = 0; i < withdrawals.length; i++) {
377-
if (withdrawals[i].shares.length != 1 || withdrawals[i].strategies.length != 1 || withdrawals[i].strategies[0] != beaconChainETHStrategy) {
377+
if (withdrawals[i].scaledShares.length != 1 || withdrawals[i].strategies.length != 1 || withdrawals[i].strategies[0] != beaconChainETHStrategy) {
378378
revert InvalidWithdrawal();
379379
}
380380
// Set receiveAsTokens to true to receive ETH when completeQueuedWithdrawals runs.
@@ -429,23 +429,28 @@ contract StakingNode is IStakingNode, StakingNodeEvents, ReentrancyGuardUpgradea
429429
uint256 totalWithdrawalAmount = 0;
430430

431431
// Create empty tokens array since we're not receiving as tokens
432-
IERC20[][] memory tokens = new IERC20[][](withdrawals.length);
432+
IERC20V4[][] memory tokens = new IERC20V4[][](withdrawals.length);
433433
bool[] memory receiveAsTokens = new bool[](withdrawals.length);
434434

435435
// Calculate total shares being withdrawn
436436
for (uint256 i = 0; i < withdrawals.length; i++) {
437-
if (withdrawals[i].shares.length != 1 || withdrawals[i].strategies.length != 1 || withdrawals[i].strategies[0] != beaconChainETHStrategy) {
437+
if (withdrawals[i].scaledShares.length != 1 || withdrawals[i].strategies.length != 1 || withdrawals[i].strategies[0] != beaconChainETHStrategy) {
438438
revert InvalidWithdrawal();
439439
}
440-
tokens[i] = new IERC20[](1);
440+
tokens[i] = new IERC20V4[](1);
441441
receiveAsTokens[i] = false;
442-
totalWithdrawalAmount += withdrawals[i].shares[0];
442+
totalWithdrawalAmount += withdrawals[i].scaledShares[0];
443443
}
444444

445445
IDelegationManager delegationManager = IDelegationManager(address(stakingNodesManager.delegationManager()));
446446

447447
// Complete withdrawals with receiveAsTokens = false
448-
delegationManager.completeQueuedWithdrawals(withdrawals, tokens, middlewareTimesIndexes, receiveAsTokens);
448+
delegationManager.completeQueuedWithdrawals(
449+
withdrawals,
450+
tokens,
451+
// middlewareTimesIndexes,
452+
receiveAsTokens
453+
);
449454

450455
// Decrease queued shares amount
451456
queuedSharesAmount -= totalWithdrawalAmount;
@@ -483,14 +488,14 @@ contract StakingNode is IStakingNode, StakingNodeEvents, ReentrancyGuardUpgradea
483488

484489
// We can assume that the Withdrawal queued by the undelegate() call made by the operator
485490
// is the LAST queued withdrawal since to call queueWithdrawals you require isSynchronized() == true.
486-
IDelegationManager.Withdrawal memory withdrawal = IDelegationManager.Withdrawal({
491+
IDelegationManagerTypes.Withdrawal memory withdrawal = IDelegationManagerTypes.Withdrawal({
487492
staker: thisNode,
488493
delegatedTo: delegatedTo,
489494
withdrawer: thisNode,
490495
nonce: delegationManager.cumulativeWithdrawalsQueued(thisNode) - 1, // must be the last withdrawal
491496
startBlock: undelegateBlockNumber,
492497
strategies: strategies,
493-
shares: shares
498+
scaledShares: shares
494499
});
495500

496501
// IMPORTANT: withdrawalRoot is not spoofable because nonce is a strictly increasing value that

src/ynEIGEN/TokenStakingNode.sol

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,23 +175,23 @@ contract TokenStakingNode is ITokenStakingNode, Initializable, ReentrancyGuardUp
175175
}
176176

177177
IDelegationManager _delegationManager = tokenStakingNodesManager.delegationManager();
178-
IERC20[][] memory _tokens = new IERC20[][](withdrawals.length);
178+
IERC20V4[][] memory _tokens = new IERC20V4[][](withdrawals.length);
179179
IStrategy[] memory _strategies = new IStrategy[](withdrawals.length);
180180
bool[] memory _receiveAsTokens = new bool[](withdrawals.length);
181181
IWrapper _wrapper = IYieldNestStrategyManager(tokenStakingNodesManager.yieldNestStrategyManager()).wrapper();
182182
address[] memory _dupTokens = new address[](withdrawals.length);
183183

184184
for (uint256 i = 0; i < withdrawals.length; i++) {
185-
if (withdrawals[i].shares.length != 1 || withdrawals[i].strategies.length != 1) {
185+
if (withdrawals[i].scaledShares.length != 1 || withdrawals[i].strategies.length != 1) {
186186
revert InvalidWithdrawal(i);
187187
}
188188
IStrategy _strategy = withdrawals[i].strategies[0];
189-
queuedShares[_strategy] -= withdrawals[i].shares[0];
189+
queuedShares[_strategy] -= withdrawals[i].scaledShares[0];
190190

191191
_strategies[i] = _strategy;
192-
_tokens[i] = new IERC20[](1);
192+
_tokens[i] = new IERC20V4[](1);
193193
_tokens[i][0] = _strategy.underlyingToken();
194-
IERC20 _token = _tokens[i][0];
194+
IERC20V4 _token = _tokens[i][0];
195195
_receiveAsTokens[i] = true;
196196
_dupTokens[i] = address(_token);
197197
}
@@ -203,7 +203,12 @@ contract TokenStakingNode is ITokenStakingNode, Initializable, ReentrancyGuardUp
203203
_balancesBefore[i] = IERC20(_dedupTokens[i]).balanceOf(address(this));
204204
}
205205

206-
_delegationManager.completeQueuedWithdrawals(withdrawals, _tokens, middlewareTimesIndexes, _receiveAsTokens);
206+
_delegationManager.completeQueuedWithdrawals(
207+
withdrawals,
208+
_tokens,
209+
// middlewareTimesIndexes,
210+
_receiveAsTokens
211+
);
207212

208213
for (uint256 i = 0; i < _dedupTokens.length; i++) {
209214
IERC20 _token = IERC20(_dedupTokens[i]);
@@ -262,21 +267,26 @@ contract TokenStakingNode is ITokenStakingNode, Initializable, ReentrancyGuardUp
262267
}
263268

264269
IDelegationManager delegationManager = IDelegationManager(address(tokenStakingNodesManager.delegationManager()));
265-
IERC20[][] memory _tokens = new IERC20[][](withdrawals.length);
270+
IERC20V4[][] memory _tokens = new IERC20V4[][](withdrawals.length);
266271
bool[] memory _receiveAsTokens = new bool[](withdrawals.length);
267272
// Decrease queued shares for each strategy
268273
for (uint256 i = 0; i < withdrawals.length; i++) {
269-
if (withdrawals[i].shares.length != 1 || withdrawals[i].strategies.length != 1) {
274+
if (withdrawals[i].scaledShares.length != 1 || withdrawals[i].strategies.length != 1) {
270275
revert InvalidWithdrawal(i);
271276
}
272-
queuedShares[withdrawals[i].strategies[0]] -= withdrawals[i].shares[0];
273-
_tokens[i] = new IERC20[](1);
277+
queuedShares[withdrawals[i].strategies[0]] -= withdrawals[i].scaledShares[0];
278+
_tokens[i] = new IERC20V4[](1);
274279
_tokens[i][0] = withdrawals[i].strategies[0].underlyingToken();
275280
_receiveAsTokens[i] = false;
276281
}
277282

278283
// Complete withdrawals with receiveAsTokens = false
279-
delegationManager.completeQueuedWithdrawals(withdrawals, _tokens, middlewareTimesIndexes, _receiveAsTokens);
284+
delegationManager.completeQueuedWithdrawals(
285+
withdrawals,
286+
_tokens,
287+
// middlewareTimesIndexes,
288+
_receiveAsTokens
289+
);
280290

281291
emit CompletedManyQueuedWithdrawals(withdrawals);
282292
}
@@ -328,13 +338,15 @@ contract TokenStakingNode is ITokenStakingNode, Initializable, ReentrancyGuardUp
328338
IDelegationManagerExtended delegationManager =
329339
IDelegationManagerExtended(address(tokenStakingNodesManager.delegationManager()));
330340

331-
(IStrategy[] memory strategies, uint256[] memory shares) = delegationManager.getDelegatableShares(address(this));
341+
(IStrategy[] memory strategies,) = delegationManager.getDepositedShares(address(this));
342+
343+
(uint256[] memory withdrawableShares,) = delegationManager.getWithdrawableShares(address(this), strategies);
332344

333345
withdrawalRoots = delegationManager.undelegate(address(this));
334346

335347
// Update queued shares for each strategy
336348
for (uint256 i = 0; i < strategies.length; i++) {
337-
queuedShares[strategies[i]] += shares[i];
349+
queuedShares[strategies[i]] += withdrawableShares[i];
338350
}
339351

340352
delegatedTo = address(0);
@@ -412,14 +424,14 @@ contract TokenStakingNode is ITokenStakingNode, Initializable, ReentrancyGuardUp
412424
singleStrategy[0] = strategies[i];
413425
singleShare[0] = queuedSharesAmounts[i];
414426

415-
IDelegationManager.Withdrawal memory withdrawal = IDelegationManager.Withdrawal({
427+
IDelegationManagerTypes.Withdrawal memory withdrawal = IDelegationManagerTypes.Withdrawal({
416428
staker: thisNode,
417429
delegatedTo: _delegatedTo,
418430
withdrawer: thisNode,
419431
nonce: withdrawalsNonceFromOperatorUndelegate + i,
420432
startBlock: undelegateBlockNumber,
421433
strategies: singleStrategy,
422-
shares: singleShare
434+
scaledShares: singleShare
423435
});
424436

425437
bytes32 withdrawalRoot = delegationManager.calculateWithdrawalRoot(withdrawal);

src/ynEIGEN/WithdrawalsProcessor.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {AccessControlUpgradeable} from
77
"lib/openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol";
88
import {Initializable} from "lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
99

10-
import {IDelegationManager} from "lib/eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";
10+
import {IDelegationManager, IDelegationManagerTypes} from "lib/eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";
1111
import {IStrategy} from "lib/eigenlayer-contracts/src/contracts/interfaces/IStrategy.sol";
1212

1313
import {IwstETH} from "../external/lido/IwstETH.sol";
@@ -340,14 +340,14 @@ contract WithdrawalsProcessor is IWithdrawalsProcessor, Initializable, AccessCon
340340
uint256[] memory _shares = new uint256[](1);
341341
_shares[0] = queuedWithdrawal_.shares;
342342

343-
IDelegationManager.Withdrawal memory _withdrawal = IDelegationManager.Withdrawal({
343+
IDelegationManagerTypes.Withdrawal memory _withdrawal = IDelegationManagerTypes.Withdrawal({
344344
staker: address(queuedWithdrawal_.node),
345345
delegatedTo: queuedWithdrawal_.delegatedTo,
346346
withdrawer: address(queuedWithdrawal_.node),
347347
nonce: queuedWithdrawal_.nonce,
348348
startBlock: queuedWithdrawal_.startBlock,
349349
strategies: _strategies,
350-
shares: _shares
350+
scaledShares: _shares
351351
});
352352
ITokenStakingNode(queuedWithdrawal_.node).completeQueuedWithdrawals(
353353
_withdrawal,

test/integration/StakingNode.t.sol

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,7 @@ contract StakingNodeDelegation is StakingNodeTestBase {
127127

128128
for (uint256 i = 0; i < operators.length; i++) {
129129
vm.prank(operators[i]);
130-
delegationManager.registerAsOperator(
131-
IDelegationManager.OperatorDetails({
132-
__deprecated_earningsReceiver: address(1),
133-
delegationApprover: address(0),
134-
stakerOptOutWindowBlocks: 1
135-
}),
136-
"ipfs://some-ipfs-hash"
137-
);
130+
delegationManager.registerAsOperator(address(0),0, "ipfs://some-ipfs-hash");
138131
}
139132

140133
nodeId = createStakingNodes(1)[0];
@@ -154,14 +147,6 @@ contract StakingNodeDelegation is StakingNodeTestBase {
154147
vm.prank(chainAddresses.eigenlayer.DELEGATION_PAUSER_ADDRESS);
155148
pauseDelegationManager.unpause(0);
156149

157-
// register as operator
158-
vm.prank(operator);
159-
delegationManager.registerAsOperator(
160-
address(0), // initDelegationApprover
161-
0, // allocationDelay
162-
"ipfs://some-ipfs-hash"
163-
);
164-
165150
vm.prank(actors.admin.STAKING_NODES_DELEGATOR);
166151
stakingNodeInstance.delegate(
167152
operator1, ISignatureUtils.SignatureWithExpiry({signature: "", expiry: 0}), bytes32(0)
@@ -319,8 +304,11 @@ contract StakingNodeDelegation is StakingNodeTestBase {
319304
address delegatedOperator1 = delegationManager.delegatedTo(address(stakingNodeInstance));
320305
assertEq(delegatedOperator1, operator1, "Delegation is not set to operator1.");
321306

307+
IStrategy[] memory strategies = new IStrategy[](1);
308+
strategies[0] = stakingNodeInstance.beaconChainETHStrategy();
309+
322310
assertEq(
323-
delegationManager.operatorShares(operator1, stakingNodeInstance.beaconChainETHStrategy()),
311+
delegationManager.getOperatorShares(operator1, strategies)[0],
324312
32 ether * validatorIndices.length,
325313
"Operator shares should be 32 ETH per validator"
326314
);
@@ -375,8 +363,11 @@ contract StakingNodeDelegation is StakingNodeTestBase {
375363
address delegatedOperator1 = delegationManager.delegatedTo(address(stakingNodeInstance));
376364
assertEq(delegatedOperator1, operator1, "Delegation is not set to operator1.");
377365

366+
IStrategy[] memory strategies = new IStrategy[](1);
367+
strategies[0] = stakingNodeInstance.beaconChainETHStrategy();
368+
378369
assertEq(
379-
delegationManager.operatorShares(operator1, stakingNodeInstance.beaconChainETHStrategy()),
370+
delegationManager.getOperatorShares(operator1, strategies)[0],
380371
32 ether * validatorIndices.length,
381372
"Operator shares should be 32 ETH per validator"
382373
);
@@ -427,7 +418,7 @@ contract StakingNodeDelegation is StakingNodeTestBase {
427418
IStrategy[] memory strategies = new IStrategy[](1);
428419
strategies[0] = stakingNodeInstance.beaconChainETHStrategy();
429420
// advance time to allow completion
430-
vm.roll(block.number + delegationManager.getWithdrawalDelay(strategies));
421+
vm.roll(block.number + delegationManager.minWithdrawalDelayBlocks() + 1);
431422
}
432423

433424
// complete queued withdrawals
@@ -473,8 +464,11 @@ contract StakingNodeDelegation is StakingNodeTestBase {
473464
address delegatedOperator1 = delegationManager.delegatedTo(address(stakingNodeInstance));
474465
assertEq(delegatedOperator1, operator1, "Delegation is not set to operator1.");
475466

467+
IStrategy[] memory strategies = new IStrategy[](1);
468+
strategies[0] = stakingNodeInstance.beaconChainETHStrategy();
469+
476470
assertEq(
477-
delegationManager.operatorShares(operator1, stakingNodeInstance.beaconChainETHStrategy()),
471+
delegationManager.getOperatorShares(operator1, strategies)[0],
478472
32 ether * validatorIndices.length,
479473
"Operator shares should be 32 ETH per validator"
480474
);
@@ -525,7 +519,7 @@ contract StakingNodeDelegation is StakingNodeTestBase {
525519
IStrategy[] memory strategies = new IStrategy[](1);
526520
strategies[0] = stakingNodeInstance.beaconChainETHStrategy();
527521
// advance time to allow completion
528-
vm.roll(block.number + delegationManager.getWithdrawalDelay(strategies));
522+
vm.roll(block.number + delegationManager.minWithdrawalDelayBlocks() + 1);
529523
}
530524

531525
// complete queued withdrawals
@@ -586,8 +580,11 @@ contract StakingNodeDelegation is StakingNodeTestBase {
586580
address delegatedOperator1 = delegationManager.delegatedTo(address(stakingNodeInstance));
587581
assertEq(delegatedOperator1, operator1, "Delegation is not set to operator1.");
588582

583+
IStrategy[] memory strategies = new IStrategy[](1);
584+
strategies[0] = stakingNodeInstance.beaconChainETHStrategy();
585+
589586
assertEq(
590-
delegationManager.operatorShares(operator1, stakingNodeInstance.beaconChainETHStrategy()),
587+
delegationManager.getOperatorShares(operator1, strategies)[0],
591588
32 ether * validatorIndices.length,
592589
"Operator shares should be 32 ETH per validator"
593590
);
@@ -654,7 +651,7 @@ contract StakingNodeDelegation is StakingNodeTestBase {
654651
IStrategy[] memory strategies = new IStrategy[](1);
655652
strategies[0] = stakingNodeInstance.beaconChainETHStrategy();
656653
// advance time to allow completion
657-
vm.roll(block.number + delegationManager.getWithdrawalDelay(strategies));
654+
vm.roll(block.number + delegationManager.minWithdrawalDelayBlocks() + 1);
658655
}
659656

660657
// complete queued withdrawals
@@ -705,8 +702,11 @@ contract StakingNodeDelegation is StakingNodeTestBase {
705702
address delegatedOperator2 = delegationManager.delegatedTo(address(stakingNodeInstance));
706703
assertEq(delegatedOperator2, operator2, "Delegation is not set to operator2.");
707704

705+
IStrategy[] memory strategies = new IStrategy[](1);
706+
strategies[0] = stakingNodeInstance.beaconChainETHStrategy();
707+
708708
assertEq(
709-
delegationManager.operatorShares(operator2, stakingNodeInstance.beaconChainETHStrategy()),
709+
delegationManager.getOperatorShares(operator2, strategies)[0],
710710
32 ether * validatorIndices.length,
711711
"Operator shares should be 32 ETH per validator"
712712
);
@@ -736,7 +736,7 @@ contract StakingNodeDelegation is StakingNodeTestBase {
736736
yneth.totalAssets(), initialTotalAssets, "Total assets should not change after delegation to operator2"
737737
);
738738

739-
assertEq(eigenPodManager.podOwnerShares(address(stakingNodeInstance)), 0, "Pod owner shares should be 0");
739+
assertEq(eigenPodManager.podOwnerDepositShares(address(stakingNodeInstance)), 0, "Pod owner shares should be 0");
740740

741741
_completeQueuedWithdrawalsAsShares(queuedWithdrawals, nodeId, initialOperator);
742742

@@ -747,14 +747,17 @@ contract StakingNodeDelegation is StakingNodeTestBase {
747747
"Total assets should not change after completing queued withdrawals"
748748
);
749749

750+
IStrategy[] memory strategies = new IStrategy[](1);
751+
strategies[0] = stakingNodeInstance.beaconChainETHStrategy();
752+
750753
assertEq(
751-
delegationManager.operatorShares(operator2, stakingNodeInstance.beaconChainETHStrategy()),
754+
delegationManager.getOperatorShares(operator2, strategies)[0],
752755
32 ether * validatorIndices.length,
753756
"Operator shares should be 32 ETH per validator"
754757
);
755758

756759
assertEq(
757-
eigenPodManager.podOwnerShares(address(stakingNodeInstance)),
760+
eigenPodManager.podOwnerDepositShares(address(stakingNodeInstance)),
758761
int256(32 ether * validatorIndices.length),
759762
"Pod owner shares should be 32 ETH per validator"
760763
);

0 commit comments

Comments
 (0)