File size: 28,600 Bytes
f998fcd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 |
// This contract is part of Zellic’s smart contract dataset, which is a collection of publicly available contract code gathered as of March 2023.
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
interface ILSDStorage {
// Depoly status
function getDeployedStatus() external view returns (bool);
// Guardian
function getGuardian() external view returns (address);
function setGuardian(address _newAddress) external;
function confirmGuardian() external;
// Getters
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);
// Setters
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;
// Deleters
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;
// Arithmetic
function addUint(bytes32 _key, uint256 _amount) external;
function subUint(bytes32 _key, uint256 _amount) external;
}
/// @title Base settings / modifiers for each contract in LSD
abstract contract LSDBase {
// Calculate using this as the base
uint256 constant calcBase = 1 ether;
// Version of the contract
uint8 public version;
// The main storage contact where primary persistant storage is maintained
ILSDStorage lsdStorage;
/*** Modifiers ***********************************************************/
/**
* @dev Throws if called by any sender that doesn't match a LSD network contract
*/
modifier onlyLSDNetworkContract() {
require(
getBool(
keccak256(abi.encodePacked("contract.exists", msg.sender))
),
"Invalid contract"
);
_;
}
/**
* @dev Throws if called by any sender that doesn't match one of the supplied contract
*/
modifier onlyLSDContract(
string memory _contractName,
address _contractAddress
) {
require(
_contractAddress ==
getAddress(
keccak256(
abi.encodePacked("contract.address", _contractName)
)
),
"Invalid contract"
);
_;
}
/*** Methods **********************************************************************/
/// @dev Set the main LSD storage address
constructor(ILSDStorage _lsdStorageAddress) {
// Update the contract address
lsdStorage = ILSDStorage(_lsdStorageAddress);
}
/// @dev Get the address of a network contract by name
function getContractAddress(string memory _contractName)
internal
view
returns (address)
{
// Get the current contract address
address contractAddress = getAddress(
keccak256(abi.encodePacked("contract.address", _contractName))
);
// Check it
require(contractAddress != address(0x0), "Contract not found");
return contractAddress;
}
/// @dev Get the name of a network contract by address
function getContractName(address _contractAddress)
internal
view
returns (string memory)
{
// Get the contract name
string memory contractName = getString(
keccak256(abi.encodePacked("contract.name", _contractAddress))
);
// Check it
require(bytes(contractName).length > 0, "Contract not found");
// Return
return contractName;
}
/// @dev Get revert error message from a .call method
function getRevertMsg(bytes memory _returnData)
internal
pure
returns (string memory)
{
// If the _res length is less than 68, then the transaction failed silently (without a revert message)
if (_returnData.length < 68) return "Transaction reverted silently";
assembly {
// Slice the sighash
_returnData := add(_returnData, 0x04)
}
return abi.decode(_returnData, (string)); // All that remains is the revert string
}
/*** LSD Storage Methods ********************************************************/
// Note: Uused helpers have been removed to keep contract sizes down
/// @dev Storage get methods
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);
}
/// @dev Storage set methods
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);
}
/// @dev Storage delete methods
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);
}
/// @dev Storage arithmetic methods
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;
}
/**
* @title Liquid staking pool
*
* For the high-level description of the pool operation please refer to the paper.
* Pool manages withdrawal keys and fees. It receives ether submitted by users on the ETH 1 side
* and stakes it via the deposit_contract.sol contract. It doesn't hold ether on it's balance,
* only a small portion (buffer) of it.
* It also mints new tokens for rewards generated at the ETH 2.0 side.
*
* At the moment withdrawals are not possible in the beacon chain and there's no workaround.
* Pool will be upgraded to an actual implementation when withdrawals are enabled
* (Phase 1.5 or 2 of Eth2 launch, likely late 2022 or 2023).
*/
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);
/**
* @notice Stop pool routine operations
*/
function stop() external;
/**
* @notice Resume pool routine operations
*/
function resume() external;
/**
* @notice Stops accepting new Ether to the protocol
*
* @dev While accepting new Ether is stopped, calls to the `submit` function,
* as well as to the default payable function, will revert.
*
* Emits `StakingPaused` event.
*/
function pauseStaking() external;
/**
* @notice Resumes accepting new Ether to the protocol (if `pauseStaking` was called previously)
* NB: Staking could be rate-limited by imposing a limit on the stake amount
* at each moment in time, see `setStakingLimit()` and `removeStakingLimit()`
*
* @dev Preserves staking limit if it was set previously
*
* Emits `StakingResumed` event
*/
function resumeStaking() external;
/**
* @notice Sets the staking rate limit
*
* @dev Reverts if:
* - `_maxStakeLimit` == 0
* - `_maxStakeLimit` >= 2^96
* - `_maxStakeLimit` < `_stakeLimitIncreasePerBlock`
* - `_maxStakeLimit` / `_stakeLimitIncreasePerBlock` >= 2^32 (only if `_stakeLimitIncreasePerBlock` != 0)
*
* Emits `StakingLimitSet` event
*
* @param _maxStakeLimit max stake limit value
* @param _stakeLimitIncreasePerBlock stake limit increase per single block
*/
function setStakingLimit(
uint256 _maxStakeLimit,
uint256 _stakeLimitIncreasePerBlock
) external;
/**
* @notice Removes the staking rate limit
*
* Emits `StakingLimitRemoved` event
*/
function removeStakingLimit() external;
/**
* @notice Check staking state: whether it's paused or not
*/
function isStakingPaused() external view returns (bool);
/**
* @notice Returns how much Ether can be staked in the current block
* @dev Special return values:
* - 2^256 - 1 if staking is unlimited;
* - 0 if staking is paused or if limit is exhausted.
*/
function getCurrentStakeLimit() external view returns (uint256);
/**
* @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 isStakingLimitSet whether the stake limit is set
* @return currentStakeLimit current stake limit (equivalent to return of getCurrentStakeLimit())
* @return maxStakeLimit max stake limit
* @return maxStakeLimitGrowthBlocks blocks needed to restore max stake limit from the fully exhausted state
* @return prevStakeLimit previously reached stake limit
* @return prevStakeBlockNumber previously seen block number
*/
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();
/**
* @notice Set Lido protocol contracts (oracle, treasury, insurance fund).
* @param _oracle oracle contract
* @param _treasury treasury contract
* @param _insuranceFund insurance fund contract
*/
function setProtocolContracts(
address _oracle,
address _treasury,
address _insuranceFund
) external;
event ProtocolContactsSet(
address oracle,
address treasury,
address insuranceFund
);
/**
* @notice Set fee rate to `_feeBasisPoints` basis points.
* The fees are accrued when:
* - oracles report staking results (beacon chain balance increase)
* - validators gain execution layer rewards (priority fees and MEV)
* @param _feeBasisPoints Fee rate, in basis points
*/
function setFee(uint16 _feeBasisPoints) external;
/**
* @notice Set fee distribution
* @param _treasuryFeeBasisPoints basis points go to the treasury,
* @param _insuranceFeeBasisPoints basis points go to the insurance fund,
* @param _operatorsFeeBasisPoints basis points go to node operators.
* @dev The sum has to be 10 000.
*/
function setFeeDistribution(
uint16 _treasuryFeeBasisPoints,
uint16 _insuranceFeeBasisPoints,
uint16 _operatorsFeeBasisPoints
) external;
/**
* @notice Returns staking rewards fee rate
*/
function getFee() external view returns (uint16 feeBasisPoints);
/**
* @notice Returns fee distribution proportion
*/
function getFeeDistribution()
external
view
returns (
uint16 treasuryFeeBasisPoints,
uint16 insuranceFeeBasisPoints,
uint16 operatorsFeeBasisPoints
);
/**
* @dev burn shares
*/
function burnShares(address _account, uint256 _sharesAmount) external;
event FeeSet(uint16 feeBasisPoints);
event FeeDistributionSet(
uint16 treasuryFeeBasisPoints,
uint16 insuranceFeeBasisPoints,
uint16 operatorsFeeBasisPoints
);
/**
* @notice A payable function supposed to be called only by LidoExecutionLayerRewardsVault contract
* @dev We need a dedicated function because funds received by the default payable function
* are treated as a user deposit
*/
function receiveELRewards() external payable;
// The amount of ETH withdrawn from LidoExecutionLayerRewardsVault contract to Lido contract
event ELRewardsReceived(uint256 amount);
/**
* @dev Sets limit on amount of ETH to withdraw from execution layer rewards vault per LidoOracle report
* @param _limitPoints limit in basis points to amount of ETH to withdraw per LidoOracle report
*/
function setELRewardsWithdrawalLimit(uint16 _limitPoints) external;
// Percent in basis points of total pooled ether allowed to withdraw from LidoExecutionLayerRewardsVault per LidoOracle report
event ELRewardsWithdrawalLimitSet(uint256 limitPoints);
/**
* @notice Set credentials to withdraw ETH on ETH 2.0 side after the phase 2 is launched to `_withdrawalCredentials`
* @dev Note that setWithdrawalCredentials discards all unused signing keys as the signatures are invalidated.
* @param _withdrawalCredentials withdrawal credentials field as defined in the Ethereum PoS consensus specs
*/
function setWithdrawalCredentials(bytes32 _withdrawalCredentials) external;
/**
* @notice Returns current credentials to withdraw ETH on ETH 2.0 side after the phase 2 is launched
*/
function getWithdrawalCredentials() external view returns (bytes32);
event WithdrawalCredentialsSet(bytes32 withdrawalCredentials);
/**
* @dev Sets the address of LidoExecutionLayerRewardsVault contract
* @param _executionLayerRewardsVault Execution layer rewards vault contract address
*/
function setELRewardsVault(address _executionLayerRewardsVault) external;
// The `executionLayerRewardsVault` was set as the execution layer rewards vault for Lido
event ELRewardsVaultSet(address executionLayerRewardsVault);
/**
* @notice Ether on the ETH 2.0 side reported by the oracle
* @param _epoch Epoch id
* @param _eth2balance Balance in wei on the ETH 2.0 side
*/
function handleOracleReport(uint256 _epoch, uint256 _eth2balance) external;
// User functions
/**
* @notice Adds eth to the pool
* @return StETH Amount of StETH generated
*/
function submit(address _referral) external payable returns (uint256 StETH);
// Records a deposit made by a user
event Submitted(address indexed sender, uint256 amount, address referral);
// The `amount` of ether was sent to the deposit_contract.deposit function
event Unbuffered(uint256 amount);
// Requested withdrawal of `etherAmount` to `pubkeyHash` on the ETH 2.0 side, `tokenAmount` burned by `sender`,
// `sentFromBuffer` was sent on the current Ethereum side.
event Withdrawal(
address indexed sender,
uint256 tokenAmount,
uint256 sentFromBuffer,
bytes32 indexed pubkeyHash,
uint256 etherAmount
);
// Info functions
/**
* @notice Gets the amount of Ether controlled by the system
*/
function getTotalPooledEther() external view returns (uint256);
/**
* @notice Gets the amount of Ether temporary buffered on this contract balance
*/
function getBufferedEther() external view returns (uint256);
/**
* @notice Returns the key values related to Beacon-side
* @return depositedValidators - number of deposited validators
* @return beaconValidators - number of Lido's validators visible in the Beacon state, reported by oracles
* @return beaconBalance - total amount of Beacon-side Ether (sum of all the balances of Lido validators)
*/
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 {
// Events
event EtherDeposited(string indexed by, uint256 amount, uint256 time);
event EtherWithdrawn(string indexed by, uint256 amount, uint256 time);
// Construct
constructor(ILSDStorage _lsdStorageAddress) LSDBase(_lsdStorageAddress) {
// Version
version = 1;
}
// Accept an ETH deposit from a LSD contract
// Only accepts calls from LSD contracts.
function depositEther()
public
payable
override
onlyLSDContract("lsdDepositPool", msg.sender)
{
// Valid amount?
require(msg.value > 0, "No valid amount of ETH given to deposit");
// Emit ether deposited event
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) {
// Calls Uniswap Functions
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 ether withdrawn event
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());
}
} |