|
|
|
|
|
|
|
pragma solidity ^0.8.9;
|
|
|
|
interface ILSDStorage {
|
|
|
|
function getDeployedStatus() external view returns (bool);
|
|
|
|
|
|
function getGuardian() external view returns (address);
|
|
|
|
function setGuardian(address _newAddress) external;
|
|
|
|
function confirmGuardian() external;
|
|
|
|
|
|
function getAddress(bytes32 _key) external view returns (address);
|
|
|
|
function getUint(bytes32 _key) external view returns (uint256);
|
|
|
|
function getString(bytes32 _key) external view returns (string memory);
|
|
|
|
function getBytes(bytes32 _key) external view returns (bytes memory);
|
|
|
|
function getBool(bytes32 _key) external view returns (bool);
|
|
|
|
function getInt(bytes32 _key) external view returns (int256);
|
|
|
|
function getBytes32(bytes32 _key) external view returns (bytes32);
|
|
|
|
|
|
function setAddress(bytes32 _key, address _value) external;
|
|
|
|
function setUint(bytes32 _key, uint256 _value) external;
|
|
|
|
function setString(bytes32 _key, string calldata _value) external;
|
|
|
|
function setBytes(bytes32 _key, bytes calldata _value) external;
|
|
|
|
function setBool(bytes32 _key, bool _value) external;
|
|
|
|
function setInt(bytes32 _key, int256 _value) external;
|
|
|
|
function setBytes32(bytes32 _key, bytes32 _value) external;
|
|
|
|
|
|
function deleteAddress(bytes32 _key) external;
|
|
|
|
function deleteUint(bytes32 _key) external;
|
|
|
|
function deleteString(bytes32 _key) external;
|
|
|
|
function deleteBytes(bytes32 _key) external;
|
|
|
|
function deleteBool(bytes32 _key) external;
|
|
|
|
function deleteInt(bytes32 _key) external;
|
|
|
|
function deleteBytes32(bytes32 _key) external;
|
|
|
|
|
|
function addUint(bytes32 _key, uint256 _amount) external;
|
|
|
|
function subUint(bytes32 _key, uint256 _amount) external;
|
|
}
|
|
|
|
|
|
|
|
abstract contract LSDBase {
|
|
|
|
uint256 constant calcBase = 1 ether;
|
|
|
|
|
|
uint8 public version;
|
|
|
|
|
|
ILSDStorage lsdStorage;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modifier onlyLSDNetworkContract() {
|
|
require(
|
|
getBool(
|
|
keccak256(abi.encodePacked("contract.exists", msg.sender))
|
|
),
|
|
"Invalid contract"
|
|
);
|
|
_;
|
|
}
|
|
|
|
|
|
|
|
|
|
modifier onlyLSDContract(
|
|
string memory _contractName,
|
|
address _contractAddress
|
|
) {
|
|
require(
|
|
_contractAddress ==
|
|
getAddress(
|
|
keccak256(
|
|
abi.encodePacked("contract.address", _contractName)
|
|
)
|
|
),
|
|
"Invalid contract"
|
|
);
|
|
_;
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(ILSDStorage _lsdStorageAddress) {
|
|
|
|
lsdStorage = ILSDStorage(_lsdStorageAddress);
|
|
}
|
|
|
|
|
|
function getContractAddress(string memory _contractName)
|
|
internal
|
|
view
|
|
returns (address)
|
|
{
|
|
|
|
address contractAddress = getAddress(
|
|
keccak256(abi.encodePacked("contract.address", _contractName))
|
|
);
|
|
|
|
require(contractAddress != address(0x0), "Contract not found");
|
|
return contractAddress;
|
|
}
|
|
|
|
|
|
function getContractName(address _contractAddress)
|
|
internal
|
|
view
|
|
returns (string memory)
|
|
{
|
|
|
|
string memory contractName = getString(
|
|
keccak256(abi.encodePacked("contract.name", _contractAddress))
|
|
);
|
|
|
|
require(bytes(contractName).length > 0, "Contract not found");
|
|
|
|
return contractName;
|
|
}
|
|
|
|
|
|
function getRevertMsg(bytes memory _returnData)
|
|
internal
|
|
pure
|
|
returns (string memory)
|
|
{
|
|
|
|
if (_returnData.length < 68) return "Transaction reverted silently";
|
|
assembly {
|
|
|
|
_returnData := add(_returnData, 0x04)
|
|
}
|
|
return abi.decode(_returnData, (string));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getAddress(bytes32 _key) internal view returns (address) {
|
|
return lsdStorage.getAddress(_key);
|
|
}
|
|
|
|
function getUint(bytes32 _key) internal view returns (uint256) {
|
|
return lsdStorage.getUint(_key);
|
|
}
|
|
|
|
function getString(bytes32 _key) internal view returns (string memory) {
|
|
return lsdStorage.getString(_key);
|
|
}
|
|
|
|
function getBytes(bytes32 _key) internal view returns (bytes memory) {
|
|
return lsdStorage.getBytes(_key);
|
|
}
|
|
|
|
function getBool(bytes32 _key) internal view returns (bool) {
|
|
return lsdStorage.getBool(_key);
|
|
}
|
|
|
|
function getInt(bytes32 _key) internal view returns (int256) {
|
|
return lsdStorage.getInt(_key);
|
|
}
|
|
|
|
function getBytes32(bytes32 _key) internal view returns (bytes32) {
|
|
return lsdStorage.getBytes32(_key);
|
|
}
|
|
|
|
|
|
function setAddress(bytes32 _key, address _value) internal {
|
|
lsdStorage.setAddress(_key, _value);
|
|
}
|
|
|
|
function setUint(bytes32 _key, uint256 _value) internal {
|
|
lsdStorage.setUint(_key, _value);
|
|
}
|
|
|
|
function setString(bytes32 _key, string memory _value) internal {
|
|
lsdStorage.setString(_key, _value);
|
|
}
|
|
|
|
function setBytes(bytes32 _key, bytes memory _value) internal {
|
|
lsdStorage.setBytes(_key, _value);
|
|
}
|
|
|
|
function setBool(bytes32 _key, bool _value) internal {
|
|
lsdStorage.setBool(_key, _value);
|
|
}
|
|
|
|
function setInt(bytes32 _key, int256 _value) internal {
|
|
lsdStorage.setInt(_key, _value);
|
|
}
|
|
|
|
function setBytes32(bytes32 _key, bytes32 _value) internal {
|
|
lsdStorage.setBytes32(_key, _value);
|
|
}
|
|
|
|
|
|
function deleteAddress(bytes32 _key) internal {
|
|
lsdStorage.deleteAddress(_key);
|
|
}
|
|
|
|
function deleteUint(bytes32 _key) internal {
|
|
lsdStorage.deleteUint(_key);
|
|
}
|
|
|
|
function deleteString(bytes32 _key) internal {
|
|
lsdStorage.deleteString(_key);
|
|
}
|
|
|
|
function deleteBytes(bytes32 _key) internal {
|
|
lsdStorage.deleteBytes(_key);
|
|
}
|
|
|
|
function deleteBool(bytes32 _key) internal {
|
|
lsdStorage.deleteBool(_key);
|
|
}
|
|
|
|
function deleteInt(bytes32 _key) internal {
|
|
lsdStorage.deleteInt(_key);
|
|
}
|
|
|
|
function deleteBytes32(bytes32 _key) internal {
|
|
lsdStorage.deleteBytes32(_key);
|
|
}
|
|
|
|
|
|
function addUint(bytes32 _key, uint256 _amount) internal {
|
|
lsdStorage.addUint(_key, _amount);
|
|
}
|
|
|
|
function subUint(bytes32 _key, uint256 _amount) internal {
|
|
lsdStorage.subUint(_key, _amount);
|
|
}
|
|
}
|
|
|
|
interface ILSDVaultWithdrawer {
|
|
function receiveVaultWithdrawalETH() external payable;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface ILido {
|
|
function name() external pure returns (string memory);
|
|
|
|
function symbol() external pure returns (string memory);
|
|
|
|
function decimals() external pure returns (string memory);
|
|
|
|
function totalSupply() external view returns (uint256);
|
|
|
|
function balanceOf(address _account) external view returns (uint256);
|
|
|
|
function transfer(address _recipient, uint256 _amount)
|
|
external
|
|
returns (bool);
|
|
|
|
function allowance(address _owner, address _spender)
|
|
external
|
|
view
|
|
returns (uint256);
|
|
|
|
function approve(address _spender, uint256 _amount) external returns (bool);
|
|
|
|
function transferFrom(
|
|
address _sender,
|
|
address _recipient,
|
|
uint256 _amount
|
|
) external returns (bool);
|
|
|
|
function increaseAllowance(address _spender, uint256 _addedValue)
|
|
external
|
|
returns (bool);
|
|
|
|
function decreaseAllowance(address _spender, uint256 _subtractedValue)
|
|
external
|
|
returns (bool);
|
|
|
|
function getTotalShares() external view returns (uint256);
|
|
|
|
function sharesOf(address _account) external view returns (uint256);
|
|
|
|
function getSharesByPooledEth(uint256 _ethAmount)
|
|
external
|
|
view
|
|
returns (uint256);
|
|
|
|
function getPooledEthByShares(uint256 _sharesAmount)
|
|
external
|
|
view
|
|
returns (uint256);
|
|
|
|
function transferShares(address _recipient, uint256 _sharesAmount)
|
|
external
|
|
returns (uint256);
|
|
|
|
|
|
|
|
|
|
function stop() external;
|
|
|
|
|
|
|
|
|
|
function resume() external;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function pauseStaking() external;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function resumeStaking() external;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setStakingLimit(
|
|
uint256 _maxStakeLimit,
|
|
uint256 _stakeLimitIncreasePerBlock
|
|
) external;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function removeStakingLimit() external;
|
|
|
|
|
|
|
|
|
|
function isStakingPaused() external view returns (bool);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getCurrentStakeLimit() external view returns (uint256);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getStakeLimitFullInfo()
|
|
external
|
|
view
|
|
returns (
|
|
bool isStakingPaused,
|
|
bool isStakingLimitSet,
|
|
uint256 currentStakeLimit,
|
|
uint256 maxStakeLimit,
|
|
uint256 maxStakeLimitGrowthBlocks,
|
|
uint256 prevStakeLimit,
|
|
uint256 prevStakeBlockNumber
|
|
);
|
|
|
|
event Stopped();
|
|
event Resumed();
|
|
|
|
event StakingPaused();
|
|
event StakingResumed();
|
|
event StakingLimitSet(
|
|
uint256 maxStakeLimit,
|
|
uint256 stakeLimitIncreasePerBlock
|
|
);
|
|
event StakingLimitRemoved();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setProtocolContracts(
|
|
address _oracle,
|
|
address _treasury,
|
|
address _insuranceFund
|
|
) external;
|
|
|
|
event ProtocolContactsSet(
|
|
address oracle,
|
|
address treasury,
|
|
address insuranceFund
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setFee(uint16 _feeBasisPoints) external;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setFeeDistribution(
|
|
uint16 _treasuryFeeBasisPoints,
|
|
uint16 _insuranceFeeBasisPoints,
|
|
uint16 _operatorsFeeBasisPoints
|
|
) external;
|
|
|
|
|
|
|
|
|
|
function getFee() external view returns (uint16 feeBasisPoints);
|
|
|
|
|
|
|
|
|
|
function getFeeDistribution()
|
|
external
|
|
view
|
|
returns (
|
|
uint16 treasuryFeeBasisPoints,
|
|
uint16 insuranceFeeBasisPoints,
|
|
uint16 operatorsFeeBasisPoints
|
|
);
|
|
|
|
|
|
|
|
|
|
function burnShares(address _account, uint256 _sharesAmount) external;
|
|
|
|
event FeeSet(uint16 feeBasisPoints);
|
|
|
|
event FeeDistributionSet(
|
|
uint16 treasuryFeeBasisPoints,
|
|
uint16 insuranceFeeBasisPoints,
|
|
uint16 operatorsFeeBasisPoints
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function receiveELRewards() external payable;
|
|
|
|
|
|
event ELRewardsReceived(uint256 amount);
|
|
|
|
|
|
|
|
|
|
|
|
function setELRewardsWithdrawalLimit(uint16 _limitPoints) external;
|
|
|
|
|
|
event ELRewardsWithdrawalLimitSet(uint256 limitPoints);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setWithdrawalCredentials(bytes32 _withdrawalCredentials) external;
|
|
|
|
|
|
|
|
|
|
function getWithdrawalCredentials() external view returns (bytes32);
|
|
|
|
event WithdrawalCredentialsSet(bytes32 withdrawalCredentials);
|
|
|
|
|
|
|
|
|
|
|
|
function setELRewardsVault(address _executionLayerRewardsVault) external;
|
|
|
|
|
|
event ELRewardsVaultSet(address executionLayerRewardsVault);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleOracleReport(uint256 _epoch, uint256 _eth2balance) external;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function submit(address _referral) external payable returns (uint256 StETH);
|
|
|
|
|
|
event Submitted(address indexed sender, uint256 amount, address referral);
|
|
|
|
|
|
event Unbuffered(uint256 amount);
|
|
|
|
|
|
|
|
event Withdrawal(
|
|
address indexed sender,
|
|
uint256 tokenAmount,
|
|
uint256 sentFromBuffer,
|
|
bytes32 indexed pubkeyHash,
|
|
uint256 etherAmount
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getTotalPooledEther() external view returns (uint256);
|
|
|
|
|
|
|
|
|
|
function getBufferedEther() external view returns (uint256);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getBeaconStat()
|
|
external
|
|
view
|
|
returns (
|
|
uint256 depositedValidators,
|
|
uint256 beaconValidators,
|
|
uint256 beaconBalance
|
|
);
|
|
}
|
|
|
|
interface IUniswapV2Router01 {
|
|
function factory() external pure returns (address);
|
|
function WETH() external pure returns (address);
|
|
|
|
function addLiquidity(
|
|
address tokenA,
|
|
address tokenB,
|
|
uint amountADesired,
|
|
uint amountBDesired,
|
|
uint amountAMin,
|
|
uint amountBMin,
|
|
address to,
|
|
uint deadline
|
|
) external returns (uint amountA, uint amountB, uint liquidity);
|
|
function addLiquidityETH(
|
|
address token,
|
|
uint amountTokenDesired,
|
|
uint amountTokenMin,
|
|
uint amountETHMin,
|
|
address to,
|
|
uint deadline
|
|
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
|
|
function removeLiquidity(
|
|
address tokenA,
|
|
address tokenB,
|
|
uint liquidity,
|
|
uint amountAMin,
|
|
uint amountBMin,
|
|
address to,
|
|
uint deadline
|
|
) external returns (uint amountA, uint amountB);
|
|
function removeLiquidityETH(
|
|
address token,
|
|
uint liquidity,
|
|
uint amountTokenMin,
|
|
uint amountETHMin,
|
|
address to,
|
|
uint deadline
|
|
) external returns (uint amountToken, uint amountETH);
|
|
function removeLiquidityWithPermit(
|
|
address tokenA,
|
|
address tokenB,
|
|
uint liquidity,
|
|
uint amountAMin,
|
|
uint amountBMin,
|
|
address to,
|
|
uint deadline,
|
|
bool approveMax, uint8 v, bytes32 r, bytes32 s
|
|
) external returns (uint amountA, uint amountB);
|
|
function removeLiquidityETHWithPermit(
|
|
address token,
|
|
uint liquidity,
|
|
uint amountTokenMin,
|
|
uint amountETHMin,
|
|
address to,
|
|
uint deadline,
|
|
bool approveMax, uint8 v, bytes32 r, bytes32 s
|
|
) external returns (uint amountToken, uint amountETH);
|
|
function swapExactTokensForTokens(
|
|
uint amountIn,
|
|
uint amountOutMin,
|
|
address[] calldata path,
|
|
address to,
|
|
uint deadline
|
|
) external returns (uint[] memory amounts);
|
|
function swapTokensForExactTokens(
|
|
uint amountOut,
|
|
uint amountInMax,
|
|
address[] calldata path,
|
|
address to,
|
|
uint deadline
|
|
) external returns (uint[] memory amounts);
|
|
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
|
|
external
|
|
payable
|
|
returns (uint[] memory amounts);
|
|
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
|
|
external
|
|
returns (uint[] memory amounts);
|
|
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
|
|
external
|
|
returns (uint[] memory amounts);
|
|
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
|
|
external
|
|
payable
|
|
returns (uint[] memory amounts);
|
|
|
|
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
|
|
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
|
|
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
|
|
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
|
|
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
|
|
}
|
|
|
|
interface IUniswapV2Router02 is IUniswapV2Router01 {
|
|
function removeLiquidityETHSupportingFeeOnTransferTokens(
|
|
address token,
|
|
uint liquidity,
|
|
uint amountTokenMin,
|
|
uint amountETHMin,
|
|
address to,
|
|
uint deadline
|
|
) external returns (uint amountETH);
|
|
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
|
|
address token,
|
|
uint liquidity,
|
|
uint amountTokenMin,
|
|
uint amountETHMin,
|
|
address to,
|
|
uint deadline,
|
|
bool approveMax, uint8 v, bytes32 r, bytes32 s
|
|
) external returns (uint amountETH);
|
|
|
|
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
|
|
uint amountIn,
|
|
uint amountOutMin,
|
|
address[] calldata path,
|
|
address to,
|
|
uint deadline
|
|
) external;
|
|
function swapExactETHForTokensSupportingFeeOnTransferTokens(
|
|
uint amountOutMin,
|
|
address[] calldata path,
|
|
address to,
|
|
uint deadline
|
|
) external payable;
|
|
function swapExactTokensForETHSupportingFeeOnTransferTokens(
|
|
uint amountIn,
|
|
uint amountOutMin,
|
|
address[] calldata path,
|
|
address to,
|
|
uint deadline
|
|
) external;
|
|
}
|
|
|
|
interface ILSDLIDOVault {
|
|
function depositEther() external payable;
|
|
|
|
function withdrawEther(uint256 _ethAmount, address _address) external;
|
|
|
|
function getStETHBalance() external view returns (uint256);
|
|
|
|
function claimToken(uint256 _amount) external;
|
|
|
|
function claimAll() external;
|
|
|
|
function getSharesOfStETH(uint256 _ethAmount) external returns (uint256);
|
|
}
|
|
|
|
contract LSDLIDOVault is LSDBase, ILSDLIDOVault {
|
|
|
|
event EtherDeposited(string indexed by, uint256 amount, uint256 time);
|
|
event EtherWithdrawn(string indexed by, uint256 amount, uint256 time);
|
|
|
|
|
|
constructor(ILSDStorage _lsdStorageAddress) LSDBase(_lsdStorageAddress) {
|
|
|
|
version = 1;
|
|
}
|
|
|
|
|
|
|
|
function depositEther()
|
|
public
|
|
payable
|
|
override
|
|
onlyLSDContract("lsdDepositPool", msg.sender)
|
|
{
|
|
|
|
require(msg.value > 0, "No valid amount of ETH given to deposit");
|
|
|
|
emit EtherDeposited("LSDDepositPool", msg.value, block.timestamp);
|
|
processDeposit();
|
|
}
|
|
|
|
function processDeposit() private {
|
|
ILido lido = ILido(getContractAddress("lido"));
|
|
lido.submit{value: msg.value}(address(this));
|
|
}
|
|
|
|
function getStETHBalance() public view override returns (uint256) {
|
|
ILido lido = ILido(getContractAddress("lido"));
|
|
return lido.balanceOf(address(this));
|
|
}
|
|
|
|
function getSharesOfStETH(
|
|
uint256 _ethAmount
|
|
) public view override returns (uint256) {
|
|
ILido lido = ILido(getContractAddress("lido"));
|
|
return lido.getSharesByPooledEth(_ethAmount);
|
|
}
|
|
|
|
function withdrawEther(
|
|
uint256 _ethAmount,
|
|
address _address
|
|
) public override onlyLSDContract("lsdDepositPool", msg.sender) {
|
|
|
|
IUniswapV2Router02 uniswapRouter = IUniswapV2Router02(
|
|
getContractAddress("uniswapRouter")
|
|
);
|
|
|
|
address[] memory path;
|
|
path = new address[](2);
|
|
path[0] = getContractAddress("lido");
|
|
path[1] = getContractAddress("weth");
|
|
|
|
uint256[] memory amounts = uniswapRouter.getAmountsIn(_ethAmount, path);
|
|
|
|
ILido lido = ILido(getContractAddress("lido"));
|
|
lido.approve(getContractAddress("uniswapRouter"), getStETHBalance());
|
|
|
|
require(amounts[0] <= getStETHBalance(), "Invalid Exchange");
|
|
|
|
uniswapRouter.swapTokensForExactETH(
|
|
_ethAmount,
|
|
amounts[0],
|
|
path,
|
|
_address,
|
|
block.timestamp + 40
|
|
);
|
|
|
|
|
|
emit EtherWithdrawn("LSDDepositPool", _ethAmount, block.timestamp);
|
|
}
|
|
|
|
receive() external payable {}
|
|
|
|
function claimToken(
|
|
uint256 _amount
|
|
) public override onlyLSDContract("lsdDaoContract", msg.sender) {
|
|
ILido lido = ILido(getContractAddress("lido"));
|
|
lido.transfer(msg.sender, _amount);
|
|
}
|
|
|
|
function claimAll() public override onlyLSDContract("lsdDaoContract", msg.sender){
|
|
ILido lido = ILido(getContractAddress("lido"));
|
|
lido.transfer(msg.sender, getStETHBalance());
|
|
}
|
|
} |