Skip to content

Commit

Permalink
Remove wsteth deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
skhomuti committed Mar 15, 2024
1 parent 19630fe commit 773733b
Show file tree
Hide file tree
Showing 10 changed files with 1 addition and 975 deletions.
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 @@ -385,63 +385,6 @@ contract CSModule is ICSModule, CSModuleBase, AccessControl, PausableUntil {
_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 @@ contract CSModule is ICSModule, CSModuleBase, AccessControl, PausableUntil {
_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
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

0 comments on commit 773733b

Please sign in to comment.