Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove wsteth deposits #90

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 0 additions & 90 deletions src/CSAccounting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -307,39 +307,6 @@ contract CSAccounting is
return requiredForNextKeys - excess;
}

function getBondAmountByKeysCountWstETH(
uint256 keysCount
) public view returns (uint256) {
return
WSTETH.getWstETHByStETH(
CSBondCurve.getBondAmountByKeysCount(keysCount)
);
}

function getBondAmountByKeysCountWstETH(
uint256 keysCount,
BondCurve memory curve
) public view returns (uint256) {
return
WSTETH.getWstETHByStETH(
CSBondCurve.getBondAmountByKeysCount(keysCount, curve)
);
}

/// @notice Returns the required bond in wstETH (inc. missed and excess) for the given node operator to upload new keys.
/// @param nodeOperatorId id of the node operator to get required bond for.
/// @param additionalKeys number of new keys to add.
/// @return required bond in wstETH.
function getRequiredBondForNextKeysWstETH(
uint256 nodeOperatorId,
uint256 additionalKeys
) public view returns (uint256) {
return
WSTETH.getWstETHByStETH(
getRequiredBondForNextKeys(nodeOperatorId, additionalKeys)
);
}

/// @notice Stake user's ETH to Lido and make deposit in stETH to the bond
/// @dev if `from` is not the same as `msg.sender`, then `msg.sender` should be CSM
/// @param from address to stake ETH and deposit stETH from
Expand Down Expand Up @@ -416,63 +383,6 @@ contract CSAccounting is
return CSBondCore._depositStETH(from, nodeOperatorId, stETHAmount);
}

/// @notice Unwrap user's wstETH and make deposit in stETH to the bond for the given Node Operator
/// @dev if `from` is not the same as `msg.sender`, then `msg.sender` should be CSM
/// @param from address to unwrap wstETH from
/// @param nodeOperatorId id of the node operator to deposit stETH for
/// @param wstETHAmount amount of wstETH to deposit
/// @return stETH shares amount
function depositWstETH(
address from,
uint256 nodeOperatorId,
uint256 wstETHAmount
)
external
whenResumed
onlyExistingNodeOperator(nodeOperatorId)
returns (uint256)
{
// TODO: can it be two functions rather than one with `from` param and condition?
from = _validateDepositSender(from);
return CSBondCore._depositWstETH(from, nodeOperatorId, wstETHAmount);
}

/// @notice Unwrap user's wstETH and make deposit in stETH to the bond for the given Node Operator using the proper permit for the contract
/// @dev if `from` is not the same as `msg.sender`, then `msg.sender` should be CSM
/// @param from address to unwrap wstETH from
/// @param nodeOperatorId id of the node operator to deposit stETH for
/// @param wstETHAmount amount of wstETH to deposit
/// @param permit wstETH permit for the contract
/// @return stETH shares amount
function depositWstETHWithPermit(
address from,
uint256 nodeOperatorId,
uint256 wstETHAmount,
PermitInput calldata permit
)
external
whenResumed
onlyExistingNodeOperator(nodeOperatorId)
returns (uint256)
{
// TODO: can it be two functions rather than one with `from` param and condition?
from = _validateDepositSender(from);
// preventing revert for already used permit
if (WSTETH.allowance(from, address(this)) < permit.value) {
// solhint-disable-next-line func-named-parameters
WSTETH.permit(
from,
address(this),
permit.value,
permit.deadline,
permit.v,
permit.r,
permit.s
);
}
return CSBondCore._depositWstETH(from, nodeOperatorId, wstETHAmount);
}

/// @dev only CSM can pass `from` != `msg.sender`
function _validateDepositSender(
address from
Expand Down
21 changes: 1 addition & 20 deletions src/CSBondCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ abstract contract CSBondCoreBase {
address to,
uint256 amount
);
event BondDepositedWstETH(
uint256 indexed nodeOperatorId,
address from,
uint256 amount
);
event BondClaimedWstETH(
uint256 indexed nodeOperatorId,
address to,
Expand Down Expand Up @@ -53,7 +48,7 @@ abstract contract CSBondCoreBase {
/// It contains:
/// - store bond shares
/// - get bond shares and bond amount
/// - deposit ETH/stETH/wstETH
/// - deposit ETH/stETH
/// - claim ETH/stETH/wstETH
/// - burn
///
Expand Down Expand Up @@ -126,20 +121,6 @@ abstract contract CSBondCore is CSBondCoreBase {
emit BondDeposited(nodeOperatorId, from, amount);
}

/// @dev Transfers user's wstETH to the contract, unwrap and stores stETH shares as Node Operator's bond shares.
function _depositWstETH(
address from,
uint256 nodeOperatorId,
uint256 amount
) internal returns (uint256) {
WSTETH.transferFrom(from, address(this), amount);
uint256 stETHAmount = WSTETH.unwrap(amount);
uint256 shares = _sharesByEth(stETHAmount);
_increaseBond(nodeOperatorId, shares);
emit BondDepositedWstETH(nodeOperatorId, from, amount);
return shares;
}

function _increaseBond(uint256 nodeOperatorId, uint256 shares) private {
_bondShares[nodeOperatorId] += shares;
totalBondShares += shares;
Expand Down
110 changes: 0 additions & 110 deletions src/CSModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
error MaxSigningKeysCountExceeded();
}

contract CSModule is ICSModule, CSModuleBase, AccessControl, PausableUntil {

Check warning on line 149 in src/CSModule.sol

View workflow job for this annotation

GitHub Actions / Linters

Contract has 16 states declarations but allowed no more than 15
using QueueLib for QueueLib.Queue;

bytes32 public constant PAUSE_ROLE = keccak256("PAUSE_ROLE"); // 0x139c2898040ef16910dc9f44dc697df79363da767d8bc92f2e310312b816e46d
Expand Down Expand Up @@ -385,63 +385,6 @@
_addSigningKeys(id, keysCount, publicKeys, signatures);
}

/// @notice Adds a new node operator with wstETH bond
/// @param keysCount Count of signing keys
/// @param publicKeys Public keys to submit
/// @param signatures Signatures of public keys
function addNodeOperatorWstETH(
uint256 keysCount,
bytes calldata publicKeys,
bytes calldata signatures,
bytes32[] calldata eaProof
) external whenResumed {
// TODO: sanity checks

uint256 id = _createNodeOperator();
_processEarlyAdoption(id, eaProof);

accounting.depositWstETH(
msg.sender,
id,
accounting.getBondAmountByKeysCountWstETH(
keysCount,
accounting.getBondCurve(id)
)
);

_addSigningKeys(id, keysCount, publicKeys, signatures);
}

/// @notice Adds a new node operator with permit to use wstETH as bond
/// @param keysCount Count of signing keys
/// @param publicKeys Public keys to submit
/// @param signatures Signatures of public keys
/// @param permit Permit to use wstETH as bond
function addNodeOperatorWstETHWithPermit(
uint256 keysCount,
bytes calldata publicKeys,
bytes calldata signatures,
bytes32[] calldata eaProof,
ICSAccounting.PermitInput calldata permit
) external whenResumed {
// TODO: sanity checks

uint256 id = _createNodeOperator();
_processEarlyAdoption(id, eaProof);

accounting.depositWstETHWithPermit(
msg.sender,
id,
accounting.getBondAmountByKeysCountWstETH(
keysCount,
accounting.getBondCurve(id)
),
permit
);

_addSigningKeys(id, keysCount, publicKeys, signatures);
}

/// @notice Adds a new keys to the node operator with ETH bond
/// @param nodeOperatorId ID of the node operator
/// @param keysCount Count of signing keys
Expand Down Expand Up @@ -514,59 +457,6 @@
_addSigningKeys(nodeOperatorId, keysCount, publicKeys, signatures);
}

/// @notice Adds a new keys to the node operator with wstETH bond
/// @param nodeOperatorId ID of the node operator
/// @param keysCount Count of signing keys
/// @param publicKeys Public keys to submit
/// @param signatures Signatures of public keys
function addValidatorKeysWstETH(
uint256 nodeOperatorId,
uint256 keysCount,
bytes calldata publicKeys,
bytes calldata signatures
) external whenResumed {
// TODO: sanity checks

accounting.depositWstETH(
msg.sender,
nodeOperatorId,
accounting.getRequiredBondForNextKeysWstETH(
nodeOperatorId,
keysCount
)
);

_addSigningKeys(nodeOperatorId, keysCount, publicKeys, signatures);
}

/// @notice Adds a new keys to the node operator with permit to use wstETH as bond
/// @param nodeOperatorId ID of the node operator
/// @param keysCount Count of signing keys
/// @param publicKeys Public keys to submit
/// @param signatures Signatures of public keys
/// @param permit Permit to use wstETH as bond
function addValidatorKeysWstETHWithPermit(
uint256 nodeOperatorId,
uint256 keysCount,
bytes calldata publicKeys,
bytes calldata signatures,
ICSAccounting.PermitInput calldata permit
) external whenResumed {
// TODO: sanity checks

accounting.depositWstETHWithPermit(
msg.sender,
nodeOperatorId,
accounting.getRequiredBondForNextKeysWstETH(
nodeOperatorId,
keysCount
),
permit
);

_addSigningKeys(nodeOperatorId, keysCount, publicKeys, signatures);
}

/// @notice Proposes a new manager address for the node operator
/// @param nodeOperatorId ID of the node operator
/// @param proposedAddress Proposed manager address
Expand Down Expand Up @@ -793,7 +683,7 @@
/// @dev Empty due to oracle using CSM balance for distribution
function onRewardsMinted(
uint256 /*_totalShares*/
) external onlyRole(STAKING_ROUTER_ROLE) {}

Check warning on line 686 in src/CSModule.sol

View workflow job for this annotation

GitHub Actions / Linters

Code contains empty blocks

function _updateDepositableValidatorsCount(uint256 nodeOperatorId) private {
NodeOperator storage no = _nodeOperators[nodeOperatorId];
Expand Down Expand Up @@ -907,7 +797,7 @@
/// @param refundedValidatorsCount Count of refunded validators
function updateRefundedValidatorsCount(
uint256 nodeOperatorId,
uint256 refundedValidatorsCount

Check warning on line 800 in src/CSModule.sol

View workflow job for this annotation

GitHub Actions / Linters

Variable "refundedValidatorsCount" is unused
)
external
onlyRole(STAKING_ROUTER_ROLE)
Expand Down Expand Up @@ -966,7 +856,7 @@
function onExitedAndStuckValidatorsCountsUpdated()
external
onlyRole(STAKING_ROUTER_ROLE)
{

Check warning on line 859 in src/CSModule.sol

View workflow job for this annotation

GitHub Actions / Linters

Code contains empty blocks
// Nothing to do, rewards are distributed by a performance oracle.
}

Expand All @@ -976,8 +866,8 @@
/// @param stuckValidatorsKeysCount Count of stuck validators
function unsafeUpdateValidatorsCount(
uint256 nodeOperatorId,
uint256 exitedValidatorsKeysCount,

Check warning on line 869 in src/CSModule.sol

View workflow job for this annotation

GitHub Actions / Linters

Variable "exitedValidatorsKeysCount" is unused
uint256 stuckValidatorsKeysCount

Check warning on line 870 in src/CSModule.sol

View workflow job for this annotation

GitHub Actions / Linters

Variable "stuckValidatorsKeysCount" is unused
)
external
onlyRole(STAKING_ROUTER_ROLE)
Expand Down Expand Up @@ -1252,7 +1142,7 @@
function onWithdrawalCredentialsChanged()
external
onlyRole(STAKING_ROUTER_ROLE)
{

Check warning on line 1145 in src/CSModule.sol

View workflow job for this annotation

GitHub Actions / Linters

Code contains empty blocks
// TODO: implement it
}

Expand Down Expand Up @@ -1450,8 +1340,8 @@

(
uint256 nodeOperatorId,
uint256 start,

Check warning on line 1343 in src/CSModule.sol

View workflow job for this annotation

GitHub Actions / Linters

Variable "start" is unused
uint256 count,

Check warning on line 1344 in src/CSModule.sol

View workflow job for this annotation

GitHub Actions / Linters

Variable "count" is unused
uint256 nonce
) = Batch.deserialize(item);
NodeOperator storage no = _nodeOperators[nodeOperatorId];
Expand Down
27 changes: 0 additions & 27 deletions src/interfaces/ICSAccounting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,10 @@ interface ICSAccounting is ICSBondCore, ICSBondCurve, ICSBondLock {
uint256 additionalKeys
) external view returns (uint256);

function getBondAmountByKeysCountWstETH(
uint256 keysCount
) external view returns (uint256);

function getBondAmountByKeysCountWstETH(
uint256 keysCount,
BondCurve memory curve
) external view returns (uint256);

function getRequiredBondForNextKeysWstETH(
uint256 nodeOperatorId,
uint256 additionalKeys
) external view returns (uint256);

function getUnbondedKeysCount(
uint256 nodeOperatorId
) external view returns (uint256);

function depositWstETHWithPermit(
address from,
uint256 nodeOperatorId,
uint256 wstETHAmount,
PermitInput calldata permit
) external returns (uint256);

function depositWstETH(
address from,
uint256 nodeOperatorId,
uint256 wstETHAmount
) external returns (uint256);

function depositStETHWithPermit(
address from,
uint256 nodeOperatorId,
Expand Down
Loading
Loading