Skip to content

Commit

Permalink
chore: apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
tamtamchik committed Nov 27, 2024
1 parent d376ee3 commit f560380
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
41 changes: 29 additions & 12 deletions contracts/0.4.24/Lido.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ contract Lido is Versioned, StETHPermit, AragonApp {
/// @dev amount of external balance that is counted into total pooled eth
bytes32 internal constant EXTERNAL_BALANCE_POSITION =
0xc5293dc5c305f507c944e5c29ae510e33e116d6467169c2daa1ee0db9af5b91d; // keccak256("lido.Lido.externalBalance");
/// @dev maximum allowed external balance as a percentage of total pooled ether
/// @dev maximum allowed external balance as basis points of total pooled ether
/// this is a soft limit (can eventually hit the limit as a part of rebase)
bytes32 internal constant MAX_EXTERNAL_BALANCE_POSITION =
0x5248bc99214b4b9bfb04eed7603bdab7b47ab5b436236fcbf7bda3acc9aea148; // keccak256("lido.Lido.maxExternalBalanceBP")

Expand Down Expand Up @@ -348,7 +349,7 @@ contract Lido is Versioned, StETHPermit, AragonApp {
/**
* @notice Returns full info about current stake limit params and state
* @dev Might be used for the advanced integration requests.
* @return isStakingPaused staking pause state (equivalent to return of isStakingPaused())
* @return isStakingPaused_ staking pause state (equivalent to return of isStakingPaused())
* @return isStakingLimitSet whether the stake limit is set
* @return currentStakeLimit current stake limit (equivalent to return of getCurrentStakeLimit())
* @return maxStakeLimit max stake limit
Expand Down Expand Up @@ -491,12 +492,20 @@ contract Lido is Versioned, StETHPermit, AragonApp {
return _getBufferedEther();
}

/**
* @notice Get the amount of Ether held by external contracts
* @return amount of external ether in wei
*/
function getExternalEther() external view returns (uint256) {
return EXTERNAL_BALANCE_POSITION.getStorageUint256();
}

function getMaxExternalBalance() external view returns (uint256) {
return _getMaxExternalBalance();
/**
* @notice Get the maximum allowed external ether balance
* @return max external balance in wei
*/
function getMaxExternalEther() external view returns (uint256) {
return _getMaxExternalEther();
}

/**
Expand Down Expand Up @@ -594,7 +603,6 @@ contract Lido is Versioned, StETHPermit, AragonApp {
///
/// @param _receiver Address to receive the minted shares
/// @param _amountOfShares Amount of shares to mint
/// @return stethAmount The amount of stETH minted
///
/// @dev authentication goes through isMinter in StETH
function mintExternalShares(address _receiver, uint256 _amountOfShares) external {
Expand All @@ -606,7 +614,7 @@ contract Lido is Versioned, StETHPermit, AragonApp {
uint256 stethAmount = super.getPooledEthByShares(_amountOfShares);

uint256 newExternalBalance = EXTERNAL_BALANCE_POSITION.getStorageUint256().add(stethAmount);
uint256 maxExternalBalance = _getMaxExternalBalance();
uint256 maxExternalBalance = _getMaxExternalEther();

require(newExternalBalance <= maxExternalBalance, "EXTERNAL_BALANCE_LIMIT_EXCEEDED");

Expand Down Expand Up @@ -889,24 +897,33 @@ contract Lido is Versioned, StETHPermit, AragonApp {
}

/**
* @dev Gets the maximum allowed external balance as a percentage of total pooled ether
* @dev Gets the maximum allowed external balance as basis points of total pooled ether
* @return max external balance in wei
*/
function _getMaxExternalBalance() internal view returns (uint256) {
return _getTotalPooledEther().mul(MAX_EXTERNAL_BALANCE_POSITION.getStorageUint256()).div(TOTAL_BASIS_POINTS);
function _getMaxExternalEther() internal view returns (uint256) {
return _getPooledEther()
.mul(MAX_EXTERNAL_BALANCE_POSITION.getStorageUint256())
.div(TOTAL_BASIS_POINTS);
}

/**
* @dev Gets the total amount of Ether controlled by the system
* @dev Gets the total amount of Ether controlled by the protocol
* @return total balance in wei
*/
function _getTotalPooledEther() internal view returns (uint256) {
function _getPooledEther() internal view returns (uint256) {
return _getBufferedEther()
.add(CL_BALANCE_POSITION.getStorageUint256())
.add(EXTERNAL_BALANCE_POSITION.getStorageUint256())
.add(_getTransientBalance());
}

/**
* @dev Gets the total amount of Ether controlled by the protocol and external entities
* @return total balance in wei
*/
function _getTotalPooledEther() internal view returns (uint256) {
return _getPooledEther().add(EXTERNAL_BALANCE_POSITION.getStorageUint256());
}

/// @dev override isMinter from StETH to allow accounting to mint
function _isMinter(address _sender) internal view returns (bool) {
return _sender == getLidoLocator().accounting();
Expand Down
2 changes: 1 addition & 1 deletion contracts/0.8.25/interfaces/ILido.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface ILido {

function burnExternalShares(uint256) external;

function getMaxExternalBalance() external view returns (uint256);
function getMaxExternalEther() external view returns (uint256);

function getTotalShares() external view returns (uint256);

Expand Down
2 changes: 1 addition & 1 deletion contracts/0.8.25/vaults/VaultHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ abstract contract VaultHub is AccessControlEnumerableUpgradeable {
}

uint256 capVaultBalance = stETH.getPooledEthByShares(_shareLimit);
uint256 maxExternalBalance = stETH.getMaxExternalBalance();
uint256 maxExternalBalance = stETH.getMaxExternalEther();
if (capVaultBalance + stETH.getExternalEther() > maxExternalBalance) {
revert ExternalBalanceCapReached(address(_vault), capVaultBalance, maxExternalBalance);
}
Expand Down

0 comments on commit f560380

Please sign in to comment.