Skip to content
Open
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
4 changes: 2 additions & 2 deletions packages/foundry/src/interfaces/external/IWETH.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0
// Docgen-SOLC: 0.8.0
// Docgen-SOLC: 0.8.15

pragma solidity ^0.8.0;
pragma solidity ^0.8.15;

interface IWETH {
function deposit() external payable;
Expand Down
2 changes: 2 additions & 0 deletions packages/foundry/src/interfaces/vault/IAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { IPausable } from "../IPausable.sol";
interface IAdapter is IERC4626, IOwned, IPermit, IPausable {
function strategy() external view returns (address);

function convertAssetsToUnderlyingShares(uint256 assets) external returns (uint256);

function strategyConfig() external view returns (bytes memory);

function strategyDeposit(uint256 assets, uint256 shares) external;
Expand Down
29 changes: 29 additions & 0 deletions packages/foundry/src/vault/adapter/lido/ICurveFi.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: GPL-3.0
// Docgen-SOLC: 0.8.15

pragma solidity ^0.8.15;

interface ICurveFi {
function get_virtual_price() external view returns (uint256);

function add_liquidity(uint256[4] calldata amounts, uint256 min_mint_amount) external;

function remove_liquidity_imbalance(uint256[4] calldata amounts, uint256 max_burn_amount) external;

function remove_liquidity(uint256 _amount, uint256[4] calldata amounts) external;

function exchange(
int128 from,
int128 to,
uint256 _from_amount,
uint256 _min_to_amount
) external returns (uint256);

function calc_token_amount(uint256[2] calldata amounts, bool deposit) external view returns (uint256);

function get_dy(
int128 i,
int128 j,
uint256 dx
) external view returns (uint256);
}
344 changes: 344 additions & 0 deletions packages/foundry/src/vault/adapter/lido/ILido.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,344 @@
// SPDX-FileCopyrightText: 2020 Lido <info@lido.fi>

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.15;

import { ERC4626Upgradeable as ERC4626, IERC20, IERC20Metadata, ERC20, SafeERC20, Math, IStrategy, IAdapter } from "../abstracts/AdapterBase.sol";

/**
* @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 totalSupply() external view returns (uint256);

function getTotalShares() external view returns (uint256);

function asset() external view returns (address);

function initialize(
bytes memory adapterInitData,
address _wethAddress,
bytes memory lidoInitData
) external;

function getSharesByPooledEth(uint256 _ethAmount) external view returns (uint256);

function owner() external view returns (address);

function strategy() external view returns (address);

function harvestCooldown() external view returns (uint256);

function strategyConfig() external view returns (bytes memory);

function sharesOf(address _account) external view returns (uint256);

function balanceOf(address _account) external view returns (uint256);

function burnShares(address _account, uint256 _sharesAmount) external returns (uint256 newTotalShares);

/**
* @notice Stop pool routine operations
*/
function stop() external;

/**
* @notice Resume pool routine operations
*/
function resume() external;

function weth() external view returns (address);

/**
* @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
);

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 (bytes memory);

event WithdrawalCredentialsSet(bytes32 withdrawalCredentials);

/**
* @dev Sets the address of LidoExecutionLayerRewardsVault contract
* @param _executionLayerRewardsVault Execution layer rewards vault contract address
*/
function setELRewardsVault(address _executionLayerRewardsVault) external;

function token() external view returns (address);

// 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 VaultAPI is IERC20 {
function deposit(uint256 amount) external returns (uint256);

function withdraw(uint256 maxShares) external returns (uint256);

function pricePerShare() external view returns (uint256);

function totalAssets() external view returns (uint256);

function totalSupply() external view returns (uint256);

function getTotalShares() external view returns (uint256);

function balanceOf(address _account) external view returns (uint256);

function depositLimit() external view returns (uint256);

function token() external view returns (address);

function weth() external view returns (address);

function lastReport() external view returns (uint256);

function lockedProfit() external view returns (uint256);

function lockedProfitDegradation() external view returns (uint256);

function totalDebt() external view returns (uint256);
}
Loading