ETH Price: $1,806.09 (-11.59%)
Gas: 15.6 Gwei
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

Advanced mode:
Parent Transaction Hash Method Block
From
To
View All Internal Transactions
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0x4D626206...4b5C34d0b
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
Aggregator

Compiler Version
v0.8.24+commit.e11b9ed9

Optimization Enabled:
Yes with 200 runs

Other Settings:
cancun EvmVersion
File 1 of 36 : Aggregator.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";

import {EGETH} from "src/EGETH.sol";
import {IAggregator, IAssetInfo, IAssets, IConfigAggregator} from "src/interfaces/IAggregator.sol";
import {LRTProtocolsManager} from "src/LRTProtocolsManager.sol";
import {IKelpLRTDepositPool} from "src/interfaces/kelp/IKelpLRTDepositPool.sol";
import {IRSETH} from "src/interfaces/kelp/IRSETH.sol";

/**
 * @title Builda ETH Restaking Aggregator
 *
 * Builda Aggregator is a restaking ETH aggregator that allows users to deposit ETH and LRT tokens to receive egETH in return.
 * The aggregator restake ETH into different Liquid Restaking protocols.
 * EgETH is a rebasing token that represents the user's share of the total value locked in the aggregator.
 * The token's main utility is to participate in crowdfundings on Builda.
 */
contract Aggregator is
    Initializable,
    UUPSUpgradeable,
    ReentrancyGuardUpgradeable,
    Ownable2StepUpgradeable,
    IAggregator
{
    //--------------------------------------------------------------------------------------
    //-------------------------------------  EVENTS  ---------------------------------------
    //--------------------------------------------------------------------------------------

    event Deposit(address indexed account, uint256 amount, address indexed token);
    event Withdraw(address indexed account, uint256 amount, address indexed token);
    event TargetWeightsUpdated(uint256 etherFiWeight, uint256 renzoWeight, uint256 kelpWeight);
    event Paused(address indexed account);
    event UnPaused(address indexed account);
    event EthTokenAddressUpdated(address ethAddress);
    event CurrentPooledEtherUpdated(uint256 totalPooledEther);

    //--------------------------------------------------------------------------------------
    //-------------------------------------  ERRORS  ---------------------------------------
    //--------------------------------------------------------------------------------------

    error Aggregator__NoDirectETHTransfer();
    error Aggregator__TokenNotAllowed();
    error Aggregator__AmountMustBeGreaterThanZero();
    error Aggregator__AmountExceedsMaxWithdrawal();
    error Aggregator__InsufficientAllowance();
    error Aggregator__InsufficientAmount();
    error Aggregator__InsufficientSharesAmount();
    error Aggregator__InvalidAmount();
    error Aggregator__MinimumDepositAmount();
    error Aggregator__InvalidAmountToMint();
    error Aggregator__BelowMinETHDeposit();
    error Aggregator__InvalidTotalWeight();
    error Aggregator__InvalidAddress();
    error Aggregator__ContractPaused();
    error Aggregator__OnlyAdmin();

    //--------------------------------------------------------------------------------------
    //---------------------------------  STATE-VARIABLES  ----------------------------------
    //--------------------------------------------------------------------------------------

    // native ETH as ERC20 for KelpDAO deposit
    address public ETH_TOKEN;

    // used to scale the weight of the LRT tokens & adjustement for calculations
    uint256 private constant SCALE_FACTOR = 1e18;
    uint256 private constant TOTAL_WEIGHT_BASIS = 1e3; // weight total

    /// @dev flag to control whether deposits/withdrawal are paused
    bool public paused;

    mapping(address => bool) public admins;

    EGETH public egETH;
    LRTProtocolsManager public lrtManager;
    address public bldTreasury;

    // LRT tokens currently allowed in the aggregator
    mapping(address token => bool isAllowed) public allowedTokens;

    /// @dev LRT tokens
    IAssetInfo public etherFiEETH;
    IAssetInfo public renzoEzETH;
    IAssetInfo public kelpRsETH;

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    //--------------------------------------------------------------------------------------
    //------------------------------------  MODIFIERS  -------------------------------------
    //--------------------------------------------------------------------------------------

    /// @dev Only allows execution if token is allowed
    modifier isAllowed(address _token) {
        if (!allowedTokens[_token]) {
            revert Aggregator__TokenNotAllowed();
        }
        _;
    }

    /// @dev Only allows execution if contract is not paused
    modifier notPaused() {
        if (paused) revert Aggregator__ContractPaused();
        _;
    }

    /// @dev Only allows execution if caller is an admin
    modifier onlyAdmin() {
        if (!admins[msg.sender]) revert Aggregator__OnlyAdmin();
        _;
    }

    //--------------------------------------------------------------------------------------
    //-------------------------------------  EXTERNAL  -------------------------------------
    //--------------------------------------------------------------------------------------

    /// @dev prohibit direct transfer to contract
    receive() external payable {
        revert Aggregator__NoDirectETHTransfer();
    }

    /// @dev prohibit direct transfer to contract
    fallback() external payable {
        revert Aggregator__NoDirectETHTransfer();
    }

    /**
     * @dev proxy initialization
     *
     * @param _configAggregator containing admin, treasury and egETH addresses
     * @param _lrtManager LRT protocols manager address
     * @param _assets containing etherFiEETH, renzoEzETH and kelpRsETH with their corresponding weights
     */
    function initialize(IConfigAggregator memory _configAggregator, address _lrtManager, IAssets memory _assets)
        external
        payable
        initializer
    {
        uint256 initialAmount = msg.value;
        if (initialAmount == 0) {
            revert Aggregator__AmountMustBeGreaterThanZero();
        }
        __Ownable_init(msg.sender);
        __ReentrancyGuard_init();
        __UUPSUpgradeable_init();
        bldTreasury = _configAggregator.treasury;
        egETH = EGETH(_configAggregator.egETH);
        lrtManager = LRTProtocolsManager(_lrtManager);
        etherFiEETH = _assets.etherFieEth;
        renzoEzETH = _assets.renzoEzEth;
        kelpRsETH = _assets.kelpRsETH;
        allowedTokens[address(_assets.etherFieEth.asset)] = true;
        allowedTokens[address(_assets.renzoEzEth.asset)] = true;
        allowedTokens[address(_assets.kelpRsETH.asset)] = true;
        admins[_configAggregator.admin] = true;

        // set the ETH token address
        ETH_TOKEN = _configAggregator.ethTokenAddress;

        // deposit ETH to LRT protocols
        _depositOnLRTProtocols(initialAmount);

        _mintInitialShares();
    }

    /**
     * @notice Deposits ETH to the aggregator and mints egETH, min: 0.01 ETH
     * ETH will be distributed to the different LRT protocols based on their target weights
     * LRT protocols will mint their respective LRT tokens and deposit them to the aggregator
     *
     * Requirements:
     *
     * - `msg.value` cannot be zero.
     * - `msg.value` must be equal or higher than the minimum deposit amount of ETH.
     */
    function depositETH() external payable nonReentrant notPaused {
        uint256 amount = msg.value;

        if (amount < minDepositETH()) {
            revert Aggregator__BelowMinETHDeposit();
        }

        // deposit ETH to LRT protocols relative to their target weight to mint their respective LRT tokens
        _depositOnLRTProtocols(amount);

        // mint egETH to the user
        egETH.mint(msg.sender, amount);
    }

    /**
     * @notice Deposits LRT to the aggregator and mints egETH
     *
     * @param asset LRT token address
     * @param amount LRT amount
     * @param minEgETHAmount Minimum egETH amount to mint
     *
     * Requirements:
     *
     * - `amount` cannot be zero.
     * - `asset` must be an allowed asset.
     * - `asset` allowance must be equal or higher than amount.
     * - Amount minted should be equal or higher than `minEgETHAmount`
     */
    function depositLRT(address asset, uint256 amount, uint256 minEgETHAmount)
        external
        nonReentrant
        isAllowed(asset)
        notPaused
    {
        if (amount == 0) {
            revert Aggregator__AmountMustBeGreaterThanZero();
        }

        if (IERC20(asset).allowance(msg.sender, address(this)) < amount) {
            revert Aggregator__InsufficientAllowance();
        }

        // update the price of rsETH
        lrtManager.updateRsETHPrice();

        uint256 previewEgETHAmount = _previewDepositLRT(asset, amount);

        uint256 rounding = 1e2;

        if ((previewEgETHAmount + rounding) < minEgETHAmount) {
            revert Aggregator__InvalidAmountToMint();
        }

        IERC20 _asset = IERC20(asset);

        // slither-disable-next-line reentrancy-no-eth
        SafeERC20.safeTransferFrom(_asset, msg.sender, address(this), amount);

        uint256 ethDeposited = convertLRTSharesToEth(asset, amount);
        emit Deposit(msg.sender, ethDeposited, asset);

        // update the total pooled ETH
        egETH.mint(msg.sender, previewEgETHAmount);
    }

    /**
     * @notice Withdraws LRT from the aggregator and burns egETH
     *
     * @param assetToWithdraw LRT token address
     * @param egShares egETH amount to burn
     *
     * Requirements:
     *
     * - `egShares` cannot be zero.
     * - `assetToWithdraw` must be an allowed asset.
     * - Balance of egETH must be equal or higher than `egShares`.
     * - egETH allowance must be equal or higher than amount of `egShares`.
     * - `egShares` must be equal or lower than the maximum amount of egETH that can be used to withdraw the given LRT token.
     */
    function withdrawLRT(address assetToWithdraw, uint256 egShares)
        external
        payable
        nonReentrant
        isAllowed(assetToWithdraw)
    {
        if (egShares == 0) {
            revert Aggregator__AmountMustBeGreaterThanZero();
        }
        // check if the user has enough egETH to withdraw
        if (balanceOf(msg.sender) < egShares) {
            revert Aggregator__InsufficientAmount();
        }

        // update the price of rsETH
        lrtManager.updateRsETHPrice();

        // check if the amount of egETH to withdraw is within the limit
        if (egShares > maxLRTWithdrawInEgETH(assetToWithdraw)) {
            revert Aggregator__AmountExceedsMaxWithdrawal();
        }
        // check if the user has enough allowance to withdraw
        if (egETH.allowance(msg.sender, address(this)) < egShares) {
            revert Aggregator__InsufficientAllowance();
        }

        IERC20 _asset = IERC20(assetToWithdraw);

        uint256 assetShares = convertEgETHToLRTShares(assetToWithdraw, egShares);

        egETH.burn(msg.sender, egShares);

        SafeERC20.safeTransfer(_asset, msg.sender, assetShares);
        emit Withdraw(msg.sender, egShares, assetToWithdraw);
    }

    /**
     * @notice Sets the target weights for the LRT tokens
     *
     * DAO will be able to adjust the target weights to rebalance the LRT tokens in the aggregator
     *
     * @param etherFiWeight EtherFi target weight
     * @param renzoWeight Renzo target weight
     * @param kelpWeight Kelp target weight
     *
     * Requirements:
     *
     * - `etherFiWeight`, `renzoWeight`, `kelpWeight` addition must be equal to 100%.
     */
    function setTargetWeights(uint256 etherFiWeight, uint256 renzoWeight, uint256 kelpWeight) external onlyAdmin {
        // check if the total weight is equal to 100%
        if (etherFiWeight + renzoWeight + kelpWeight != TOTAL_WEIGHT_BASIS) {
            revert Aggregator__InvalidTotalWeight();
        }
        etherFiEETH.targetWeight = etherFiWeight;
        renzoEzETH.targetWeight = renzoWeight;
        kelpRsETH.targetWeight = kelpWeight;
        emit TargetWeightsUpdated(etherFiWeight, renzoWeight, kelpWeight);
    }

    /**
     * @notice Sets the paused flag
     *
     * @param _paused Paused boolean flag
     */
    function setPaused(bool _paused) external onlyAdmin {
        paused = _paused;
        if (_paused) {
            emit Paused(msg.sender);
        } else {
            emit UnPaused(msg.sender);
        }
    }

    /**
     * @notice Change the EthTokenAddress for KelpDAO
     * @param ethAddress the ETH token address
     */
    function setEthTokenAddress(address ethAddress) external onlyOwner {
        if (ethAddress == address(0)) {
            revert Aggregator__InvalidAddress();
        }
        ETH_TOKEN = ethAddress;
        emit EthTokenAddressUpdated(ethAddress);
    }

    /**
     * @notice Get the implementation address
     * @return Implementation address
     */
    function getImplementation() external view returns (address) {
        return ERC1967Utils.getImplementation();
    }

    /**
     * @notice Preview the amount of egETH to mint for a given amount of ETH
     *
     * @param amount Amount of ETH to deposit
     * @return Amount of egETH to mint
     *
     * Requirements:
     *
     * - `amount` must be higher than zero.
     */
    function previewDepositETH(uint256 amount) external view returns (uint256) {
        return convertEthToEgETH(amount);
    }

    /**
     * @notice Preview the amount of egETH to mint for a given amount of LRT
     *
     * @param asset LRT token address
     * @param amount Amount of LRT to deposit
     * @return Amount of egETH to mint
     *
     * Requirements:
     *
     * - `amount` must be higher than zero.
     */
    function previewDepositLRT(address asset, uint256 amount) external view isAllowed(asset) returns (uint256) {
        return _previewDepositLRT(asset, amount);
    }

    /**
     * @notice Preview the amount of LRT to withdraw for a given amount of egETH
     *
     * @param asset LRT token address to withdraw
     * @param shares Amount of egETH
     * @return Amount of LRT to withdraw
     *
     * Requirements:
     *
     * - `shares` must be higher than zero.
     * - `shares` must be lower than the maximum amount of egETH that can be used to withdraw the given LRT token.
     */
    function previewWithdrawLRT(address asset, uint256 shares) external view isAllowed(asset) returns (uint256) {
        if (shares == 0) {
            return 0;
        }
        if (shares > maxLRTWithdrawInEgETH(asset)) {
            revert Aggregator__AmountExceedsMaxWithdrawal();
        }

        uint256 assetShares = convertEgETHToLRTShares(asset, shares);

        return assetShares;
    }

    /**
     * @notice Get the total amount of egETH minted
     * @return Total ETH
     */
    function totalPooledEther() external view returns (uint256) {
        return _totalPooledEther();
    }

    /**
     * @notice Get the current target weights
     * @return EtherFi target weight
     * @return Renzo target weight
     * @return Kelp target weight
     */
    function targetWeights() external view returns (uint256, uint256, uint256) {
        return (etherFiEETH.targetWeight, renzoEzETH.targetWeight, kelpRsETH.targetWeight);
    }

    //--------------------------------------------------------------------------------------
    //-------------------------------------  PUBLIC  ---------------------------------------
    //--------------------------------------------------------------------------------------

    /**
     * @notice Get the minimum deposit amount of ETH
     * @return Minimum deposit amount
     */
    function minDepositETH() public pure returns (uint256) {
        return 1e16;
    }

    /**
     * @notice Get the maximum amount of egETH that can be used to withdraw a given LRT token
     *
     * @param _asset LRT token address
     * @return Maximum amount of egETH that can be used to withdraw
     *
     */
    function maxLRTWithdrawInEgETH(address _asset) public view returns (uint256) {
        (uint256 eETHBalance, uint256 ezETHBalance, uint256 rsETHBalance) = totalAssets();
        if (_asset == address(etherFiEETH.asset)) {
            return convertLRTSharesToEgETH(_asset, eETHBalance);
        } else if (_asset == address(renzoEzETH.asset)) {
            return convertLRTSharesToEgETH(_asset, ezETHBalance);
        }
        return convertLRTSharesToEgETH(_asset, rsETHBalance);
    }

    /**
     * @notice Get the current egETH balance of an account
     *
     * @param _account Account address
     * @return egETH balance
     */
    function balanceOf(address _account) public view returns (uint256) {
        return egETH.balanceOf(_account);
    }

    /**
     * @notice Get the total amount of LRT tokens held by the aggregator
     *
     * @return EtherFi balance
     * @return Renzo balance
     * @return Kelp balance
     */
    function totalAssets() public view returns (uint256, uint256, uint256) {
        return (
            etherFiEETH.asset.balanceOf(address(this)),
            renzoEzETH.asset.balanceOf(address(this)),
            kelpRsETH.asset.balanceOf(address(this))
        );
    }

    /**
     * @notice Get the total amount of Ether backed by each LRT tokens held by the aggregator
     *
     * @return EtherFi balance
     * @return Renzo balance
     * @return Kelp balance
     */
    function totalCurrentTVLs() public view returns (uint256, uint256, uint256) {
        (uint256 etherFiShares, uint256 renzoShares, uint256 kelpShares) = totalAssets();
        return lrtManager.totalProtocolsEther(etherFiShares, kelpShares, renzoShares, renzoEzETH.asset.totalSupply());
    }

    /**
     * @notice ETH to egETH converter
     *
     * @param _amount ETH amount
     * @return egETH amount
     *
     * Requirements:
     *
     * - `_amount` must be higher than zero.
     */
    function convertEthToEgETH(uint256 _amount) public view returns (uint256) {
        if (_amount == 0) {
            return 0;
        }
        return _convertEthToEgETH(_amount);
    }

    /**
     * @notice ETH to LRT shares converter
     *
     * @param asset LRT token address
     * @param ethAmount ETH amount
     * @return LRT shares
     *
     * Requirements:
     *
     * - `ethAmount` must be higher than zero.
     * - `asset` must be an allowed asset.
     */
    function convertEthToLRTShares(address asset, uint256 ethAmount) public view isAllowed(asset) returns (uint256) {
        if (ethAmount == 0) {
            return 0;
        }

        if (asset == address(etherFiEETH.asset)) {
            return lrtManager.etherFiEthAndAmount(ethAmount);
        } else if (asset == address(renzoEzETH.asset)) {
            return lrtManager.ethToRenzoEth(ethAmount, renzoEzETH.asset.totalSupply());
        }
        return lrtManager.ethToKelpEth(ethAmount);
    }

    /**
     * @notice LRT shares to ETH converter
     *
     * @param asset LRT token address
     * @param shares LRT shares
     * @return ETH amount
     *
     * Requirements:
     *
     * - `shares` must be higher than zero.
     * - `asset` must be an allowed asset.
     */
    function convertLRTSharesToEth(address asset, uint256 shares) public view isAllowed(asset) returns (uint256) {
        if (shares == 0) {
            return 0;
        }

        if (asset == address(etherFiEETH.asset)) {
            return lrtManager.etherFiEthAndAmount(shares);
        } else if (asset == address(renzoEzETH.asset)) {
            return lrtManager.renzoEthAmount(shares, renzoEzETH.asset.totalSupply());
        }
        return lrtManager.kelpEthAmount(shares);
    }

    /**
     * @notice LRT shares to egETH converter
     *
     * @param asset LRT token address
     * @param shares LRT shares
     * @return egETH amount
     *
     * Requirements:
     *
     * - `shares` must be higher than zero.
     * - `asset` must be an allowed asset.
     */
    function convertLRTSharesToEgETH(address asset, uint256 shares) public view isAllowed(asset) returns (uint256) {
        if (shares == 0) {
            return 0;
        }
        uint256 amount = convertLRTSharesToEth(asset, shares);
        return amount;
        // return convertEthToEgETH(ethAmount);
    }

    /**
     * @notice egETH to LRT shares converter
     *
     * @param asset LRT token address
     * @param egShares egETH amount
     * @return LRT shares
     *
     * Requirements:
     *
     * - `egShares` must be higher than zero.
     * - `asset` must be an allowed asset.
     */
    function convertEgETHToLRTShares(address asset, uint256 egShares) public view isAllowed(asset) returns (uint256) {
        return convertEthToLRTShares(asset, egShares);
    }

    /**
     * @notice Get the current weights of the LRT tokens in the aggregator
     *
     * @return Current EtherFi weight
     * @return Current Renzo weight
     * @return Current Kelp weight
     */
    function currentWeights() public view returns (uint256, uint256, uint256) {
        (uint256 _etherFiShares, uint256 _renzoShares, uint256 _kelpShares) = totalAssets();
        uint256 totalEth = _totalPooledEther();

        // get individual weight for each LRT from shares
        (uint256 etherFiWeight, uint256 renzoWeight, uint256 kelpWeight) =
            _weightsFromShares(_etherFiShares, _renzoShares, _kelpShares, totalEth);

        return (etherFiWeight, renzoWeight, kelpWeight);
    }

    //--------------------------------------------------------------------------------------
    //-------------------------------------  INTERNAL  -------------------------------------
    //--------------------------------------------------------------------------------------

    // @dev Allows only the owner to upgrade the contract
    function _authorizeUpgrade(address _newImplementation) internal override onlyOwner {}

    //--------------------------------------------------------------------------------------
    //-------------------------------------  PRIVATE  --------------------------------------
    //--------------------------------------------------------------------------------------

    /**
     * @notice Mint initial egETH shares to the deployer of the contract
     * this is to avoid the initial minting of egETH to be gamed
     */
    function _mintInitialShares() private {
        uint256 sharesAmount = _totalPooledEther();
        egETH.mintInitialShares(msg.sender, sharesAmount);
    }

    /**
     * @notice Deposit ETH to the LRT protocols
     * The ETH amount is distributed to the LRT protocols based on their target weights
     *
     * @param _amount ETH amount
     */
    function _depositOnLRTProtocols(uint256 _amount) private {
        bool isPausedEtherFi = lrtManager.etherFiDeposit().paused();
        bool isPausedRenzo = lrtManager.renzoDeposit().paused();
        bool isPausedKelp = lrtManager.kelpDeposit().paused();

        if (isPausedEtherFi || isPausedRenzo || isPausedKelp) {
            revert Aggregator__ContractPaused();
        }

        uint256 etherFiAmount = _amount * etherFiEETH.targetWeight / TOTAL_WEIGHT_BASIS;
        uint256 renzoAmount = _amount * renzoEzETH.targetWeight / TOTAL_WEIGHT_BASIS;
        uint256 kelpAmount = _amount * kelpRsETH.targetWeight / TOTAL_WEIGHT_BASIS;
        lrtManager.etherFiDeposit().deposit{value: etherFiAmount}();
        lrtManager.renzoDeposit().depositETH{value: renzoAmount}();
        IKelpLRTDepositPool lrtKelpDeposit = lrtManager.kelpDeposit();
        uint256 minReceiveFromDeposit = lrtKelpDeposit.getRsETHAmountToMint(address(ETH_TOKEN), kelpAmount);
        lrtKelpDeposit.depositETH{value: kelpAmount}(minReceiveFromDeposit, "0");
        emit Deposit(msg.sender, _amount, address(0));
    }

    /**
     * @notice Get the total amount of ETH in the LRT protocols backed by LRT tokens in the aggregator
     * @return Total ETH
     */
    function _totalProtocolsEther() private view returns (uint256) {
        (uint256 etherFiShares, uint256 renzoShares, uint256 kelpShares) = totalAssets();
        return lrtManager.totalEthAmount(etherFiShares, kelpShares, renzoShares, renzoEzETH.asset.totalSupply());
    }

    /**
     * @notice Get the total amount of ETH in the LRT protocols backed by LRT tokens in the aggregator and ETH in the aggregator
     * @return Total ETH
     */
    function _totalPooledEther() private view returns (uint256) {
        return _totalProtocolsEther() + address(this).balance;
    }

    /**
     * @notice Preview the amount of egETH to mint for a given amount of LRT
     *
     * @param asset LRT token address
     * @param amount LRT amount
     * @return egETH amount
     */
    function _previewDepositLRT(address asset, uint256 amount) private view returns (uint256) {
        uint256 userAmountValue = convertLRTSharesToEth(asset, amount);
        return _convertEthToEgETH(userAmountValue);
    }

    /**
     * @notice Convert ETH to egETH
     * @param newETHAmount ETH amount to convert
     * @return egETH amount
     */
    function _convertEthToEgETH(uint256 newETHAmount) private view returns (uint256) {
        uint256 shares = egETH.getSharesByPooledEth(newETHAmount);
        uint256 ethAmount = egETH.getPooledEthByShares(shares);
        return ethAmount;
    }

    /**
     * @notice Preview the weights after a withdrawal
     *
     * @param asset LRT token address
     * @param amount amount of egETH
     * @return EtherFi after withdrawal weight
     * @return Renzo after withdrawal weight
     * @return Kelp after withdrawal weight
     */
    function _previewWeightsAfterWithdraw(address asset, uint256 amount)
        private
        view
        returns (uint256, uint256, uint256)
    {
        (uint256 _etherFiShares, uint256 _renzoShares, uint256 _kelpShares) = totalAssets();
        uint256 totalEth = _totalPooledEther();

        uint256 assetShares = convertEthToLRTShares(asset, amount);
        // uint256 assetShares = convertEgETHToLRTShares(asset, amount);

        if (asset == address(etherFiEETH.asset)) {
            _etherFiShares -= assetShares;
        } else if (asset == address(renzoEzETH.asset)) {
            _renzoShares -= assetShares;
        } else if (asset == address(kelpRsETH.asset)) {
            _kelpShares -= assetShares;
        }
        (uint256 etherFiWeight, uint256 renzoWeight, uint256 kelpWeight) =
            _weightsFromShares(_etherFiShares, _renzoShares, _kelpShares, (totalEth - amount));

        return (etherFiWeight, renzoWeight, kelpWeight);
    }

    /**
     * @notice Calculate the weights from the LRT shares and a ETH value
     *
     * @param etherFiShares EtherFi shares
     * @param renzoShares Renzo shares
     * @param kelpShares Kelp shares
     * @param totalEth Total ETH
     * @return EtherFi weight
     * @return Renzo weight
     * @return Kelp weight
     */
    function _weightsFromShares(uint256 etherFiShares, uint256 renzoShares, uint256 kelpShares, uint256 totalEth)
        private
        view
        returns (uint256, uint256, uint256)
    {
        // get individual eth value for each LRT
        uint256 eETHValue = lrtManager.etherFiEthAndAmount(etherFiShares);
        uint256 renzoValue = lrtManager.renzoEthAmount(renzoShares, renzoEzETH.asset.totalSupply());
        uint256 kelpValue = lrtManager.kelpEthAmount(kelpShares);

        // calculate weights based on a ETH value
        // uint256 etherFiWeight = eETHValue * TOTAL_WEIGHT_BASIS / totalEth;
        // uint256 renzoWeight = renzoValue * TOTAL_WEIGHT_BASIS / totalEth;
        // uint256 kelpWeight = kelpValue * TOTAL_WEIGHT_BASIS / totalEth;

        uint256 etherFiWeightRounded = roundedDiv(eETHValue * TOTAL_WEIGHT_BASIS, totalEth);
        uint256 renzoWeightRounded = roundedDiv(renzoValue * TOTAL_WEIGHT_BASIS, totalEth);
        uint256 kelpWeightRounded = roundedDiv(kelpValue * TOTAL_WEIGHT_BASIS, totalEth);

        return (etherFiWeightRounded, renzoWeightRounded, kelpWeightRounded);
    }

    /**
     * @dev Division, round to nearest integer (AKA round-half-up)
     * @param a What to divide
     * @param b Divide by this number
     */
    function roundedDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // Solidity automatically throws, but please emit reason
        require(b > 0, "div by 0");

        uint256 halfB = (b % 2 == 0) ? (b / 2) : (b / 2 + 1);
        return (a % b >= halfB) ? (a / b + 1) : (a / b);
    }
}

File 2 of 36 : ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC-20
 * applications.
 */
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
    mapping(address account => uint256) private _balances;

    mapping(address account => mapping(address spender => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the default value returned by this function, unless
     * it's overridden.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `value`.
     */
    function transfer(address to, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, value);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, value);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Skips emitting an {Approval} event indicating an allowance update. This is not
     * required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `value`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `value`.
     */
    function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, value);
        _transfer(from, to, value);
        return true;
    }

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _transfer(address from, address to, uint256 value) internal {
        if (from == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        if (to == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(from, to, value);
    }

    /**
     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
     * this function.
     *
     * Emits a {Transfer} event.
     */
    function _update(address from, address to, uint256 value) internal virtual {
        if (from == address(0)) {
            // Overflow check required: The rest of the code assumes that totalSupply never overflows
            _totalSupply += value;
        } else {
            uint256 fromBalance = _balances[from];
            if (fromBalance < value) {
                revert ERC20InsufficientBalance(from, fromBalance, value);
            }
            unchecked {
                // Overflow not possible: value <= fromBalance <= totalSupply.
                _balances[from] = fromBalance - value;
            }
        }

        if (to == address(0)) {
            unchecked {
                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                _totalSupply -= value;
            }
        } else {
            unchecked {
                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                _balances[to] += value;
            }
        }

        emit Transfer(from, to, value);
    }

    /**
     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
     * Relies on the `_update` mechanism
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _mint(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(address(0), account, value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
     * Relies on the `_update` mechanism.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead
     */
    function _burn(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        _update(account, address(0), value);
    }

    /**
     * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        _approve(owner, spender, value, true);
    }

    /**
     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
     *
     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
     * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
     * `Approval` event during `transferFrom` operations.
     *
     * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
     * true using the following override:
     *
     * ```solidity
     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
     *     super._approve(owner, spender, value, true);
     * }
     * ```
     *
     * Requirements are the same as {_approve}.
     */
    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
        if (owner == address(0)) {
            revert ERC20InvalidApprover(address(0));
        }
        if (spender == address(0)) {
            revert ERC20InvalidSpender(address(0));
        }
        _allowances[owner][spender] = value;
        if (emitEvent) {
            emit Approval(owner, spender, value);
        }
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `value`.
     *
     * Does not update the allowance value in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Does not emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            if (currentAllowance < value) {
                revert ERC20InsufficientAllowance(spender, currentAllowance, value);
            }
            unchecked {
                _approve(owner, spender, currentAllowance - value, false);
            }
        }
    }
}

File 3 of 36 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}

File 4 of 36 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC-20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    /**
     * @dev An operation with an ERC-20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
    }
}

File 5 of 36 : ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuardUpgradeable is Initializable {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    /// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
    struct ReentrancyGuardStorage {
        uint256 _status;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant ReentrancyGuardStorageLocation = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;

    function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) {
        assembly {
            $.slot := ReentrancyGuardStorageLocation
        }
    }

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        $._status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if ($._status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        $._status = ENTERED;
    }

    function _nonReentrantAfter() private {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        $._status = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        return $._status == ENTERED;
    }
}

File 6 of 36 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Storage of the initializable contract.
     *
     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
     * when using with upgradeable contracts.
     *
     * @custom:storage-location erc7201:openzeppelin.storage.Initializable
     */
    struct InitializableStorage {
        /**
         * @dev Indicates that the contract has been initialized.
         */
        uint64 _initialized;
        /**
         * @dev Indicates that the contract is in the process of being initialized.
         */
        bool _initializing;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

    /**
     * @dev The contract is already initialized.
     */
    error InvalidInitialization();

    /**
     * @dev The contract is not initializing.
     */
    error NotInitializing();

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint64 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        // Cache values to avoid duplicated sloads
        bool isTopLevelCall = !$._initializing;
        uint64 initialized = $._initialized;

        // Allowed calls:
        // - initialSetup: the contract is not in the initializing state and no previous version was
        //                 initialized
        // - construction: the contract is initialized at version 1 (no reininitialization) and the
        //                 current contract is just being deployed
        bool initialSetup = initialized == 0 && isTopLevelCall;
        bool construction = initialized == 1 && address(this).code.length == 0;

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._initialized = 1;
        if (isTopLevelCall) {
            $._initializing = true;
        }
        _;
        if (isTopLevelCall) {
            $._initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._initialized = version;
        $._initializing = true;
        _;
        $._initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        _checkInitializing();
        _;
    }

    /**
     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
     */
    function _checkInitializing() internal view virtual {
        if (!_isInitializing()) {
            revert NotInitializing();
        }
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing) {
            revert InvalidInitialization();
        }
        if ($._initialized != type(uint64).max) {
            $._initialized = type(uint64).max;
            emit Initialized(type(uint64).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint64) {
        return _getInitializableStorage()._initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _getInitializableStorage()._initializing;
    }

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    // solhint-disable-next-line var-name-mixedcase
    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
        assembly {
            $.slot := INITIALIZABLE_STORAGE
        }
    }
}

File 7 of 36 : ERC1967Utils.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Utils.sol)

pragma solidity ^0.8.20;

import {IBeacon} from "../beacon/IBeacon.sol";
import {IERC1967} from "../../interfaces/IERC1967.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots.
 */
library ERC1967Utils {
    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev The `implementation` of the proxy is invalid.
     */
    error ERC1967InvalidImplementation(address implementation);

    /**
     * @dev The `admin` of the proxy is invalid.
     */
    error ERC1967InvalidAdmin(address admin);

    /**
     * @dev The `beacon` of the proxy is invalid.
     */
    error ERC1967InvalidBeacon(address beacon);

    /**
     * @dev An upgrade function sees `msg.value > 0` that may be lost.
     */
    error ERC1967NonPayable();

    /**
     * @dev Returns the current implementation address.
     */
    function getImplementation() internal view returns (address) {
        return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the ERC-1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        if (newImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(newImplementation);
        }
        StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Performs implementation upgrade with additional setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) internal {
        _setImplementation(newImplementation);
        emit IERC1967.Upgraded(newImplementation);

        if (data.length > 0) {
            Address.functionDelegateCall(newImplementation, data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     *
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
     * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
     */
    function getAdmin() internal view returns (address) {
        return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the ERC-1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        if (newAdmin == address(0)) {
            revert ERC1967InvalidAdmin(address(0));
        }
        StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {IERC1967-AdminChanged} event.
     */
    function changeAdmin(address newAdmin) internal {
        emit IERC1967.AdminChanged(getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function getBeacon() internal view returns (address) {
        return StorageSlot.getAddressSlot(BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the ERC-1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        if (newBeacon.code.length == 0) {
            revert ERC1967InvalidBeacon(newBeacon);
        }

        StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;

        address beaconImplementation = IBeacon(newBeacon).implementation();
        if (beaconImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(beaconImplementation);
        }
    }

    /**
     * @dev Change the beacon and trigger a setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-BeaconUpgraded} event.
     *
     * CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
     * it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
     * efficiency.
     */
    function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
        _setBeacon(newBeacon);
        emit IERC1967.BeaconUpgraded(newBeacon);

        if (data.length > 0) {
            Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
     * if an upgrade doesn't perform an initialization call.
     */
    function _checkNonPayable() private {
        if (msg.value > 0) {
            revert ERC1967NonPayable();
        }
    }
}

File 8 of 36 : UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.20;

import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
    address private immutable __self = address(this);

    /**
     * @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
     * and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
     * while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
     * If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
     * be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
     * during an upgrade.
     */
    string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";

    /**
     * @dev The call is from an unauthorized context.
     */
    error UUPSUnauthorizedCallContext();

    /**
     * @dev The storage `slot` is unsupported as a UUID.
     */
    error UUPSUnsupportedProxiableUUID(bytes32 slot);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        _checkProxy();
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        _checkNotDelegated();
        _;
    }

    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual notDelegated returns (bytes32) {
        return ERC1967Utils.IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data);
    }

    /**
     * @dev Reverts if the execution is not performed via delegatecall or the execution
     * context is not of a proxy with an ERC1967-compliant implementation pointing to self.
     * See {_onlyProxy}.
     */
    function _checkProxy() internal view virtual {
        if (
            address(this) == __self || // Must be called through delegatecall
            ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
        ) {
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Reverts if the execution is performed via delegatecall.
     * See {notDelegated}.
     */
    function _checkNotDelegated() internal view virtual {
        if (address(this) != __self) {
            // Must not be called through delegatecall
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;

    /**
     * @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
     *
     * As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
     * is expected to be the implementation slot in ERC1967.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
        try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
            if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
                revert UUPSUnsupportedProxiableUUID(slot);
            }
            ERC1967Utils.upgradeToAndCall(newImplementation, data);
        } catch {
            // The implementation is not UUPS
            revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
        }
    }
}

File 9 of 36 : Ownable2StepUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)

pragma solidity ^0.8.20;

import {OwnableUpgradeable} from "./OwnableUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is specified at deployment time in the constructor for `Ownable`. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {
    /// @custom:storage-location erc7201:openzeppelin.storage.Ownable2Step
    struct Ownable2StepStorage {
        address _pendingOwner;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable2Step")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant Ownable2StepStorageLocation = 0x237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c00;

    function _getOwnable2StepStorage() private pure returns (Ownable2StepStorage storage $) {
        assembly {
            $.slot := Ownable2StepStorageLocation
        }
    }

    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);

    function __Ownable2Step_init() internal onlyInitializing {
    }

    function __Ownable2Step_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Returns the address of the pending owner.
     */
    function pendingOwner() public view virtual returns (address) {
        Ownable2StepStorage storage $ = _getOwnable2StepStorage();
        return $._pendingOwner;
    }

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        Ownable2StepStorage storage $ = _getOwnable2StepStorage();
        $._pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        Ownable2StepStorage storage $ = _getOwnable2StepStorage();
        delete $._pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        if (pendingOwner() != sender) {
            revert OwnableUnauthorizedAccount(sender);
        }
        _transferOwnership(sender);
    }
}

File 10 of 36 : EGETH.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";

import {IEGETH} from "src/interfaces/IEGETH.sol";
import {Aggregator} from "src/Aggregator.sol";

/**
 * @title egETH
 * @dev ERC20 rebasing token representing the Builda Aggregator LRT tokens balance
 * @notice This contract is used to manage the egETH token
 * Only the aggregator contract can call the mint and burn functions
 */
contract EGETH is Initializable, UUPSUpgradeable, Ownable2StepUpgradeable, IEGETH {
    //--------------------------------------------------------------------------------------
    //-------------------------------------  EVENTS  ---------------------------------------
    //--------------------------------------------------------------------------------------

    /**
     * @notice An executed shares transfer from `sender` to `recipient`.
     *
     * @dev emitted in pair with an ERC20-defined `Transfer` event.
     */
    event TransferShares(address indexed from, address indexed to, uint256 sharesValue);
    event Paused(address indexed account);
    event UnPaused(address indexed account);

    /**
     * @notice An executed `burnShares` request
     *
     * @dev Reports simultaneously burnt shares amount
     * and corresponding egETH amount.
     * The egETH amount is calculated twice: before and after the burning incurred rebase.
     *
     * @param account holder of the burnt shares
     * @param preRebaseTokenAmount amount of egETH the burnt shares corresponded to before the burn
     * @param postRebaseTokenAmount amount of egETH the burnt shares corresponded to after the burn
     * @param sharesAmount amount of burnt shares
     */
    event SharesBurnt(
        address indexed account, uint256 preRebaseTokenAmount, uint256 postRebaseTokenAmount, uint256 sharesAmount
    );

    //--------------------------------------------------------------------------------------
    //-------------------------------------  ERRORS  ---------------------------------------
    //--------------------------------------------------------------------------------------

    error EgETH__OnlyAdmin();
    error EgETH__OnlyAggregator();
    error EgETH__ContractPaused();

    //--------------------------------------------------------------------------------------
    //---------------------------------  STATE-VARIABLES  ----------------------------------
    //--------------------------------------------------------------------------------------
    uint256 internal constant INFINITE_ALLOWANCE = ~uint256(0);

    /**
     * @dev egETH balances are dynamic and are calculated based on the accounts' shares
     * and the total amount of Ether controlled by the protocol. Account shares aren't
     * normalized, so the contract also stores the sum of all shares to calculate
     * each account's token balance which equals to:
     *
     *   shares[account] * _getTotalPooledEther() / _getTotalShares()
     */
    mapping(address => uint256) private shares;

    /**
     * @dev the total amount of shares in existence.
     */
    uint256 private totalShares;

    /**
     * @dev Allowances are nominated in tokens, not token shares.
     */
    mapping(address => mapping(address => uint256)) private allowances;

    /**
     * @dev Aggregator address
     */
    address public aggregator;

    mapping(address => bool) public admins;
    bool public paused;

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    //--------------------------------------------------------------------------------------
    //------------------------------------  MODIFIERS  -------------------------------------
    //--------------------------------------------------------------------------------------

    /// @dev Only allows execution if contract is not paused
    modifier notPaused() {
        if (paused) revert EgETH__ContractPaused();
        _;
    }

    /// @dev Only allows execution if caller is an admin
    modifier onlyAdmin() {
        if (!admins[msg.sender]) revert EgETH__OnlyAdmin();
        _;
    }

    /// @dev Only allows execution if caller is the aggregator
    modifier onlyAggregator() {
        if (msg.sender != aggregator) revert EgETH__OnlyAggregator();
        _;
    }

    //--------------------------------------------------------------------------------------
    //-------------------------------------  EXTERNAL  -------------------------------------
    //--------------------------------------------------------------------------------------

    /**
     * @dev proxy initialization
     * @param _aggregator Builda Aggregator address
     * @param _admin Admin multisig address
     */
    function initialize(address _aggregator, address _admin) external initializer {
        __Ownable_init(msg.sender);
        __UUPSUpgradeable_init();
        aggregator = _aggregator;
        admins[_admin] = true;
        totalShares = 0;

        // call init
    }

    /**
     * @notice Creates from `_etherAmount` new shares and assigns them to `_recipient`, increasing the total amount of shares.
     * @dev This doesn't increase the token total supply.
     *
     * NB: The method doesn't check protocol pause relying on the aggregator.
     *
     * Requirements:
     *
     * - `_recipient` cannot be the zero address.
     * - the contract must not be paused.
     */
    function mint(address _recipient, uint256 _etherAmount) external onlyAggregator {
        uint256 sharesToMint = _etherAmount * _getTotalShares() / (_getTotalPooledEther() - _etherAmount);
        _mintShares(_recipient, sharesToMint);
    }

    /**
     * @notice Destroys shares from `_etherAmount` from `_account`'s holdings, decreasing the total amount of shares.
     * @dev This doesn't decrease the token total supply.
     *
     * Requirements:
     *
     * - `_account` cannot be the zero address.
     * - `_account` must hold at least `_sharesAmount` shares.
     * - the contract must not be paused.
     */
    function burn(address _account, uint256 _etherAmount) external onlyAggregator {
        uint256 sharesToBurn = getSharesByPooledEth(_etherAmount);
        _burnShares(_account, sharesToBurn);
    }

    function mintInitialShares(address _sender, uint256 _sharesAmount) external onlyAggregator {
        _mintShares(_sender, _sharesAmount);
        _emitTransferAfterMintingShares(msg.sender, _sharesAmount);
    }

    /// @dev Sets the paused flag
    function setPaused(bool _paused) external onlyAdmin {
        paused = _paused;
        if (_paused) {
            emit Paused(msg.sender);
        } else {
            emit UnPaused(msg.sender);
        }
    }

    /// @dev @dev Returns the name of the token
    function name() external pure returns (string memory) {
        return "Builda egETH";
    }

    /// @dev Returns the symbol of the token
    function symbol() external pure returns (string memory) {
        return "egETH";
    }
    /**
     * @return the number of decimals for getting user representation of a token amount.
     */

    function decimals() external pure returns (uint8) {
        return 18;
    }

    /**
     * @return the amount of tokens in existence.
     *
     * @dev Always equals to `_getTotalPooledEther()` since token amount
     * is pegged to the total amount of Ether controlled by the protocol.
     */
    function totalSupply() external view returns (uint256) {
        return _getTotalPooledEther();
    }

    /**
     * @return the amount of tokens owned by the `_account`.
     *
     * @dev Balances are dynamic and equal the `_account`'s share in the amount of the
     * total Ether controlled by the protocol. See `sharesOf`.
     */
    function balanceOf(address _account) external view returns (uint256) {
        return getPooledEthByShares(_sharesOf(_account));
    }

    /**
     * @notice Moves `_amount` tokens from the caller's account to the `_recipient` account.
     *
     * @return a boolean value indicating whether the operation succeeded.
     * Emits a `Transfer` event.
     * Emits a `TransferShares` event.
     *
     * Requirements:
     *
     * - `_recipient` cannot be the zero address.
     * - the caller must have a balance of at least `_amount`.
     * - the contract must not be paused.
     *
     * @dev The `_amount` argument is the amount of tokens, not shares.
     */
    function transfer(address _recipient, uint256 _amount) external returns (bool) {
        _transfer(msg.sender, _recipient, _amount);
        return true;
    }

    /**
     * @return the remaining number of tokens that `_spender` is allowed to spend
     * on behalf of `_owner` through `transferFrom`. This is zero by default.
     *
     * @dev This value changes when `approve` or `transferFrom` is called.
     */
    function allowance(address _owner, address _spender) external view returns (uint256) {
        return allowances[_owner][_spender];
    }

    /**
     * @notice Sets `_amount` as the allowance of `_spender` over the caller's tokens.
     *
     * @return a boolean value indicating whether the operation succeeded.
     * Emits an `Approval` event.
     *
     * Requirements:
     *
     * - `_spender` cannot be the zero address.
     *
     * @dev The `_amount` argument is the amount of tokens, not shares.
     */
    function approve(address _spender, uint256 _amount) external returns (bool) {
        _approve(msg.sender, _spender, _amount);
        return true;
    }

    /**
     * @notice Moves `_amount` tokens from `_sender` to `_recipient` using the
     * allowance mechanism. `_amount` is then deducted from the caller's
     * allowance.
     *
     * @return a boolean value indicating whether the operation succeeded.
     *
     * Emits a `Transfer` event.
     * Emits a `TransferShares` event.
     * Emits an `Approval` event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `_sender` and `_recipient` cannot be the zero addresses.
     * - `_sender` must have a balance of at least `_amount`.
     * - the caller must have allowance for `_sender`'s tokens of at least `_amount`.
     * - the contract must not be paused.
     *
     * @dev The `_amount` argument is the amount of tokens, not shares.
     */
    function transferFrom(address _sender, address _recipient, uint256 _amount) external returns (bool) {
        _spendAllowance(_sender, msg.sender, _amount);
        _transfer(_sender, _recipient, _amount);
        return true;
    }

    /**
     * @notice Atomically increases the allowance granted to `_spender` by the caller by `_addedValue`.
     *
     * This is an alternative to `approve` that can be used as a mitigation for
     * problems described in:
     * https://github.com/OpenZeppelin/openzeppelin-contracts/blob/b709eae01d1da91902d06ace340df6b324e6f049/contracts/token/ERC20/IERC20.sol#L57
     * Emits an `Approval` event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `_spender` cannot be the the zero address.
     */
    function increaseAllowance(address _spender, uint256 _addedValue) external returns (bool) {
        _approve(msg.sender, _spender, allowances[msg.sender][_spender] + _addedValue);
        return true;
    }

    /**
     * @notice Atomically decreases the allowance granted to `_spender` by the caller by `_subtractedValue`.
     *
     * This is an alternative to `approve` that can be used as a mitigation for
     * problems described in:
     * https://github.com/OpenZeppelin/openzeppelin-contracts/blob/b709eae01d1da91902d06ace340df6b324e6f049/contracts/token/ERC20/IERC20.sol#L57
     * Emits an `Approval` event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `_spender` cannot be the zero address.
     * - `_spender` must have allowance for the caller of at least `_subtractedValue`.
     */
    function decreaseAllowance(address _spender, uint256 _subtractedValue) external returns (bool) {
        uint256 currentAllowance = allowances[msg.sender][_spender];
        require(currentAllowance >= _subtractedValue, "ALLOWANCE_BELOW_ZERO");
        _approve(msg.sender, _spender, currentAllowance - _subtractedValue);
        return true;
    }

    /**
     * @return the total amount of shares in existence.
     *
     * @dev The sum of all accounts' shares can be an arbitrary number, therefore
     * it is necessary to store it in order to calculate each account's relative share.
     */
    function getTotalShares() external view returns (uint256) {
        return _getTotalShares();
    }

    /**
     * @return the amount of shares owned by `_account`.
     */
    function sharesOf(address _account) external view returns (uint256) {
        return _sharesOf(_account);
    }

    /**
     * @notice Moves `_sharesAmount` token shares from the caller's account to the `_recipient` account.
     *
     * @return amount of transferred tokens.
     * Emits a `TransferShares` event.
     * Emits a `Transfer` event.
     *
     * Requirements:
     *
     * - `_recipient` cannot be the zero address.
     * - the caller must have at least `_sharesAmount` shares.
     * - the contract must not be paused.
     *
     * @dev The `_sharesAmount` argument is the amount of shares, not tokens.
     */
    function transferShares(address _recipient, uint256 _sharesAmount) external returns (uint256) {
        _transferShares(msg.sender, _recipient, _sharesAmount);
        uint256 tokensAmount = getPooledEthByShares(_sharesAmount);
        _emitTransferEvents(msg.sender, _recipient, tokensAmount, _sharesAmount);
        return tokensAmount;
    }

    /**
     * @notice Moves `_sharesAmount` token shares from the `_sender` account to the `_recipient` account.
     *
     * @return amount of transferred tokens.
     * Emits a `TransferShares` event.
     * Emits a `Transfer` event.
     *
     * Requirements:
     *
     * - `_sender` and `_recipient` cannot be the zero addresses.
     * - `_sender` must have at least `_sharesAmount` shares.
     * - the caller must have allowance for `_sender`'s tokens of at least `getPooledEthByShares(_sharesAmount)`.
     * - the contract must not be paused.
     *
     * @dev The `_sharesAmount` argument is the amount of shares, not tokens.
     */
    function transferSharesFrom(address _sender, address _recipient, uint256 _sharesAmount)
        external
        returns (uint256)
    {
        uint256 tokensAmount = getPooledEthByShares(_sharesAmount);
        _spendAllowance(_sender, msg.sender, tokensAmount);
        _transferShares(_sender, _recipient, _sharesAmount);
        _emitTransferEvents(_sender, _recipient, tokensAmount, _sharesAmount);
        return tokensAmount;
    }

    /// @dev Returns the current implementation address
    function getImplementation() external view returns (address) {
        return ERC1967Utils.getImplementation();
    }

    //--------------------------------------------------------------------------------------
    //-------------------------------------  PUBLIC  ---------------------------------------
    //--------------------------------------------------------------------------------------

    /**
     * @return the amount of shares that corresponds to `_ethAmount` protocol-controlled Ether.
     */
    function getSharesByPooledEth(uint256 _ethAmount) public view returns (uint256) {
        return _ethAmount * _getTotalShares() / _getTotalPooledEther();
    }

    /**
     * @return the amount of Ether that corresponds to `_sharesAmount` token shares.
     */
    function getPooledEthByShares(uint256 _sharesAmount) public view returns (uint256) {
        return _sharesAmount * _getTotalPooledEther() / _getTotalShares();
    }

    //--------------------------------------------------------------------------------------
    //-------------------------------------  INTERNAL  -------------------------------------
    //--------------------------------------------------------------------------------------

    /// @dev Allows the owner to upgrade the contract
    function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}

    //--------------------------------------------------------------------------------------
    //-------------------------------------  PRIVATE  --------------------------------------
    //--------------------------------------------------------------------------------------

    /**
     * @return the total amount (in wei) of Ether controlled by the protocol.
     * @dev This is used for calculating tokens from shares and vice versa.
     * @dev This function is required to be implemented in a derived contract.
     */
    function _getTotalPooledEther() private view returns (uint256) {
        return Aggregator(payable(aggregator)).totalPooledEther();
    }

    /**
     * @notice Moves `_amount` tokens from `_sender` to `_recipient`.
     * Emits a `Transfer` event.
     * Emits a `TransferShares` event.
     */
    function _transfer(address _sender, address _recipient, uint256 _amount) private notPaused {
        uint256 _sharesToTransfer = getSharesByPooledEth(_amount);
        _transferShares(_sender, _recipient, _sharesToTransfer);
        _emitTransferEvents(_sender, _recipient, _amount, _sharesToTransfer);
    }

    /**
     * @notice Sets `_amount` as the allowance of `_spender` over the `_owner` s tokens.
     *
     * Emits an `Approval` event.
     *
     * NB: the method can be invoked even if the protocol paused.
     *
     * Requirements:
     *
     * - `_owner` cannot be the zero address.
     * - `_spender` cannot be the zero address.
     */
    function _approve(address _owner, address _spender, uint256 _amount) private {
        require(_owner != address(0), "APPROVE_FROM_ZERO_ADDR");
        require(_spender != address(0), "APPROVE_TO_ZERO_ADDR");

        allowances[_owner][_spender] = _amount;
        emit Approval(_owner, _spender, _amount);
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(address _owner, address _spender, uint256 _amount) private {
        uint256 currentAllowance = allowances[_owner][_spender];
        if (currentAllowance != INFINITE_ALLOWANCE) {
            require(currentAllowance >= _amount, "ALLOWANCE_EXCEEDED");
            _approve(_owner, _spender, currentAllowance - _amount);
        }
    }

    /**
     * @return the total amount of shares in existence.
     */
    function _getTotalShares() private view returns (uint256) {
        return totalShares;
    }

    /**
     * @return the amount of shares owned by `_account`.
     */
    function _sharesOf(address _account) private view returns (uint256) {
        return shares[_account];
    }

    /**
     * @notice Moves `_sharesAmount` shares from `_sender` to `_recipient`.
     *
     * Requirements:
     *
     * - `_sender` cannot be the zero address.
     * - `_recipient` cannot be the zero address or the `stETH` token contract itself
     * - `_sender` must hold at least `_sharesAmount` shares.
     * - the contract must not be paused.
     */
    function _transferShares(address _sender, address _recipient, uint256 _sharesAmount) private notPaused {
        require(_sender != address(0), "TRANSFER_FROM_ZERO_ADDR");
        require(_recipient != address(0), "TRANSFER_TO_ZERO_ADDR");
        require(_recipient != address(this), "TRANSFER_TO_EGETH_CONTRACT");

        uint256 currentSenderShares = shares[_sender];
        require(_sharesAmount <= currentSenderShares, "BALANCE_EXCEEDED");
        shares[_sender] = currentSenderShares - _sharesAmount;
        shares[_recipient] = shares[_recipient] + _sharesAmount;
    }

    /**
     * @notice Creates `_sharesAmount` shares and assigns them to `_recipient`, increasing the total amount of shares.
     * @dev This doesn't increase the token total supply.
     *
     * NB: The method doesn't check protocol pause relying on the aggregator.
     *
     * Requirements:
     *
     * - `_recipient` cannot be the zero address.
     * - the contract must not be paused.
     */
    function _mintShares(address _recipient, uint256 _sharesAmount) private returns (uint256 newTotalShares) {
        require(_recipient != address(0), "MINT_TO_ZERO_ADDR");

        newTotalShares = _getTotalShares() + _sharesAmount;
        totalShares = newTotalShares;

        shares[_recipient] = shares[_recipient] + _sharesAmount;

        // Notice: we're not emitting a Transfer event from the zero address here since shares mint
        // works by taking the amount of tokens corresponding to the minted shares from all other
        // token holders, proportionally to their share. The total supply of the token doesn't change
        // as the result. This is equivalent to performing a send from each other token holder's
        // address to `address`, but we cannot reflect this as it would require sending an unbounded
        // number of events.
    }

    /**
     * @notice Destroys `_sharesAmount` shares from `_account`'s holdings, decreasing the total amount of shares.
     * @dev This doesn't decrease the token total supply.
     *
     * Requirements:
     *
     * - `_account` cannot be the zero address.
     * - `_account` must hold at least `_sharesAmount` shares.
     * - the contract must not be paused.
     */
    function _burnShares(address _account, uint256 _sharesAmount) private returns (uint256 newTotalShares) {
        require(_account != address(0), "BURN_FROM_ZERO_ADDR");

        uint256 accountShares = shares[_account];

        require(_sharesAmount <= accountShares, "BALANCE_EXCEEDED");

        uint256 preRebaseTokenAmount = getPooledEthByShares(_sharesAmount);

        newTotalShares = _getTotalShares() - _sharesAmount;
        totalShares = newTotalShares;

        shares[_account] = accountShares - _sharesAmount;

        uint256 postRebaseTokenAmount = getPooledEthByShares(_sharesAmount);

        emit SharesBurnt(_account, preRebaseTokenAmount, postRebaseTokenAmount, _sharesAmount);

        // Notice: we're not emitting a Transfer event to the zero address here since shares burn
        // works by redistributing the amount of tokens corresponding to the burned shares between
        // all other token holders. The total supply of the token doesn't change as the result.
        // This is equivalent to performing a send from `address` to each other token holder address,
        // but we cannot reflect this as it would require sending an unbounded number of events.

        // We're emitting `SharesBurnt` event to provide an explicit rebase log record nonetheless.
    }

    /**
     * @dev Emits {Transfer} and {TransferShares} events
     */
    function _emitTransferEvents(address _from, address _to, uint256 _tokenAmount, uint256 _sharesAmount) private {
        emit Transfer(_from, _to, _tokenAmount);
        emit TransferShares(_from, _to, _sharesAmount);
    }

    /**
     * @dev Emits {Transfer} and {TransferShares} events where `from` is 0 address. Indicates mint events.
     */
    function _emitTransferAfterMintingShares(address _to, uint256 _sharesAmount) private {
        _emitTransferEvents(address(0), _to, getPooledEthByShares(_sharesAmount), _sharesAmount);
    }
}

File 11 of 36 : IAggregator.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

struct IAssetInfo {
    IERC20 asset;
    uint256 targetWeight; // Target weight in percentage (e.g., 450 for 45%)
}

struct IConfigAggregator {
    address admin;
    address treasury;
    address egETH;
    address ethTokenAddress;
}

struct IAssets {
    IAssetInfo etherFieEth;
    IAssetInfo renzoEzEth;
    IAssetInfo kelpRsETH;
}

interface IAggregator {
    function depositETH() external payable;
    function depositLRT(address asset, uint256 amount, uint256 minEgETHAmount) external;
    function withdrawLRT(address assetToWithdraw, uint256 bldShares) external payable;
    function setTargetWeights(uint256 etherFiWeight, uint256 renzoWeight, uint256 kelpWeight) external;
    function setPaused(bool _paused) external;
    function getImplementation() external view returns (address);
    function previewDepositETH(uint256 amount) external view returns (uint256);
    function previewDepositLRT(address asset, uint256 amount) external view returns (uint256);
    function previewWithdrawLRT(address asset, uint256 shares) external view returns (uint256);
    function totalPooledEther() external view returns (uint256);
    function targetWeights() external view returns (uint256, uint256, uint256);
    function maxLRTWithdrawInEgETH(address _asset) external view returns (uint256);
    function balanceOf(address _account) external view returns (uint256);
    function totalAssets() external view returns (uint256, uint256, uint256);
    function convertEthToEgETH(uint256 _amount) external view returns (uint256);
    function convertEthToLRTShares(address asset, uint256 ethAmount) external view returns (uint256);
    function convertLRTSharesToEth(address asset, uint256 shares) external view returns (uint256);
    function convertLRTSharesToEgETH(address asset, uint256 shares) external view returns (uint256);
    function convertEgETHToLRTShares(address asset, uint256 bldShares) external view returns (uint256);
    function currentWeights() external view returns (uint256, uint256, uint256);
}

File 12 of 36 : LRTProtocolsManager.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;

import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";

import {ILiquidityPool} from "src/interfaces/etherFi/ILiquidityPool.sol";
import {IRestakeManager} from "src/interfaces/renzo/IRestakeManager.sol";
import {IRenzoOracle} from "src/interfaces/renzo/IRenzoOracle.sol";
import {IKelpLRTDepositPool} from "src/interfaces/kelp/IKelpLRTDepositPool.sol";
import {IKLRTOracle} from "src/interfaces/kelp/IKLRTOracle.sol";

import {ILRTProtocolsManager} from "src/interfaces/ILRTProtocolsManager.sol";

/**
 * @title LRTProtocolsManager
 * @dev Manages interactions between the different LRT protocols
 * @notice This contract is used to manage the interactions between the different LRT protocols
 * Currently it supports EtherFi, Renzo and Kelp
 * Only the aggregator contract can call the functions in this contract
 */
contract LRTProtocolsManager is Initializable, UUPSUpgradeable, Ownable2StepUpgradeable, ILRTProtocolsManager {
    //--------------------------------------------------------------------------------------
    //--------------------------------------  ERRORS  --------------------------------------
    //--------------------------------------------------------------------------------------
    error OnlyAggregatorContract();

    //--------------------------------------------------------------------------------------
    //---------------------------------  STATE-VARIABLES  ----------------------------------
    //--------------------------------------------------------------------------------------
    uint256 private constant SCALE_FACTOR = 1e18;

    address public aggregator;

    // Protocols contracts
    IRestakeManager public renzoDeposit;
    ILiquidityPool public etherFiDeposit;
    IKelpLRTDepositPool public kelpDeposit;

    // Protocols oracles
    IKLRTOracle public kelpOracle;
    IRenzoOracle public renzoOracle;

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    //--------------------------------------------------------------------------------------
    //-------------------------------------  MODIFIERS  ------------------------------------
    //--------------------------------------------------------------------------------------

    /// @dev Only allows execution if caller is the aggregator
    modifier onlyAggregator() {
        if (msg.sender != aggregator) revert OnlyAggregatorContract();
        _;
    }

    //--------------------------------------------------------------------------------------
    //-------------------------------------  EXTERNAL  -------------------------------------
    //--------------------------------------------------------------------------------------

    /**
     * @dev proxy initialization
     * @param _aggregator Aggregator contract address
     * @param _etherFiDeposit EtherFi deposit contract address
     * @param _renzoDeposit Renzo deposit contract address
     * @param _kelpDeposit Kelp deposit contract address
     * @param _kelpOracle Kelp oracle contract address
     * @param _renzoOracle Renzo oracle contract address
     */
    function initialize(
        address _aggregator,
        address _etherFiDeposit,
        address _renzoDeposit,
        address _kelpDeposit,
        address _kelpOracle,
        address _renzoOracle
    ) external initializer {
        __Ownable_init(msg.sender);
        __UUPSUpgradeable_init();

        renzoDeposit = IRestakeManager(_renzoDeposit);
        etherFiDeposit = ILiquidityPool(_etherFiDeposit);
        kelpDeposit = IKelpLRTDepositPool(_kelpDeposit);

        kelpOracle = IKLRTOracle(_kelpOracle);
        renzoOracle = IRenzoOracle(_renzoOracle);
        aggregator = _aggregator;
    }

    /**
     * @dev Get the total TVL of all the protocols in ETH
     * @param _etherFiShares EtherFi shares
     * @param _renzoShares Renzo shares
     * @param _kelpShares Kelp shares
     * @return total TVL in ETH
     */
    function totalEthAmount(
        uint256 _etherFiShares,
        uint256 _kelpShares,
        uint256 _renzoShares,
        uint256 _ezETHTotalSupply
    ) external view onlyAggregator returns (uint256) {
        return etherFiEthAndAmount(_etherFiShares) + renzoEthAmount(_renzoShares, _ezETHTotalSupply)
            + kelpEthAmount(_kelpShares);
    }

    /**
     * @dev Get the total TVL of all the protocols in ETH
     * @param _etherFiShares ezETH shares
     * @param _kelpShares rsETH shares
     * @param _renzoShares ezETH shares
     * @param _ezETHTotalSupply ezETH total supply
     * @return eETH ETH TVL
     * @return ezETH ETH TVL
     * @return rsETH ETH TVL
     */
    function totalProtocolsEther(
        uint256 _etherFiShares,
        uint256 _kelpShares,
        uint256 _renzoShares,
        uint256 _ezETHTotalSupply
    ) external view onlyAggregator returns (uint256, uint256, uint256) {
        return (
            etherFiEthAndAmount(_etherFiShares),
            renzoEthAmount(_renzoShares, _ezETHTotalSupply),
            kelpEthAmount(_kelpShares)
        );
    }

    /**
     * @dev ETH to Renzo shares (ezETH) converter
     * @param _ethAmount ETH amount
     * @param _totalSupply Total supply of ezETH
     * @return ezETH shares
     */
    function ethToRenzoEth(uint256 _ethAmount, uint256 _totalSupply) external view onlyAggregator returns (uint256) {
        (,, uint256 ethTVL) = renzoDeposit.calculateTVLs();
        uint256 shares = (_ethAmount * _totalSupply) / ethTVL;
        return shares;
    }

    /**
     * @dev ETH to Kelp shares (rsETH) converter
     * @param _ethAmount ETH amount
     * @return rsETH shares
     */
    function ethToKelpEth(uint256 _ethAmount) external view onlyAggregator returns (uint256) {
        uint256 kelEthPrice = kelpOracle.rsETHPrice();
        return (_ethAmount * SCALE_FACTOR) / kelEthPrice;
    }

    /**
     * @dev Update Kelp shares price in ETH
     */
    function updateRsETHPrice() external onlyAggregator {
        kelpOracle.updateRSETHPrice();
    }

    // @dev Get the current implementation address
    function getImplementation() external view returns (address) {
        return ERC1967Utils.getImplementation();
    }

    //--------------------------------------------------------------------------------------
    //-------------------------------------  PUBLIC  ---------------------------------------
    //--------------------------------------------------------------------------------------

    /**
     * @dev ETH to EtherFi shares (eETH) converter
     * @param _ethAmount ETH amount
     * @return eETH shares
     */
    function etherFiEthAndAmount(uint256 _ethAmount) public view onlyAggregator returns (uint256) {
        uint256 shares = etherFiDeposit.sharesForAmount(_ethAmount);
        uint256 eETHAmount = etherFiDeposit.amountForShare(shares);
        return eETHAmount;
    }

    /**
     * @dev Get ETH amount of Renzo shares (ezETH)
     * @param shares Renzo shares
     * @param _totalSupply Total supply of ezETH
     * @return total TVL in ETH
     */
    function renzoEthAmount(uint256 shares, uint256 _totalSupply) public view onlyAggregator returns (uint256) {
        (,, uint256 ethTVL) = renzoDeposit.calculateTVLs();
        uint256 ethAmount = (ethTVL * shares) / _totalSupply;
        return ethAmount;
    }

    /**
     * @dev Get ETH amount of Kelp shares (rsETH)
     * @param shares Kelp shares
     * @return total TVL in ETH
     */
    function kelpEthAmount(uint256 shares) public view onlyAggregator returns (uint256) {
        uint256 ethAmount = (kelpOracle.rsETHPrice() * shares) / SCALE_FACTOR;
        return ethAmount;
    }

    //--------------------------------------------------------------------------------------
    //-------------------------------------  INTERNAL  -------------------------------------
    //--------------------------------------------------------------------------------------

    /// @dev Allows the owner to upgrade the contract
    function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
}

File 13 of 36 : IKelpLRTDepositPool.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.24;

import {IRSETH} from "./IRSETH.sol";

interface IKelpLRTDepositPool {
    function initialize(IRSETH _rsETH) external;
    function paused() external view returns (bool);
    function depositETH(uint256 minRSETHAmountExpected, string calldata referralId) external payable;
    function getRsETHAmountToMint(address asset, uint256 amount) external view returns (uint256);
}

File 14 of 36 : IRSETH.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.24;

import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";

interface IRSETH is IERC20 {
    function mint(address account, uint256 amount) external;

    function burnFrom(address account, uint256 amount) external;
}

File 15 of 36 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC-20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 16 of 36 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

File 17 of 36 : draft-IERC6093.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;

/**
 * @dev Standard ERC-20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
 */
interface IERC20Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC20InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC20InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     * @param allowance Amount of tokens a `spender` is allowed to operate with.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC20InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC20InvalidSpender(address spender);
}

/**
 * @dev Standard ERC-721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
     * Used in balance queries.
     * @param owner Address of the current owner of a token.
     */
    error ERC721InvalidOwner(address owner);

    /**
     * @dev Indicates a `tokenId` whose `owner` is the zero address.
     * @param tokenId Identifier number of a token.
     */
    error ERC721NonexistentToken(uint256 tokenId);

    /**
     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param tokenId Identifier number of a token.
     * @param owner Address of the current owner of a token.
     */
    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC721InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC721InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param tokenId Identifier number of a token.
     */
    error ERC721InsufficientApproval(address operator, uint256 tokenId);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC721InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC721InvalidOperator(address operator);
}

/**
 * @dev Standard ERC-1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
 */
interface IERC1155Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     * @param tokenId Identifier number of a token.
     */
    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC1155InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC1155InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param owner Address of the current owner of a token.
     */
    error ERC1155MissingApprovalForAll(address operator, address owner);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC1155InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC1155InvalidOperator(address operator);

    /**
     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
     * Used in batch transfers.
     * @param idsLength Length of the array of token identifiers
     * @param valuesLength Length of the array of token amounts
     */
    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}

File 18 of 36 : IERC1363.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1363.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}

File 19 of 36 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

import {Errors} from "./Errors.sol";

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert Errors.InsufficientBalance(address(this).balance, amount);
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert Errors.FailedCall();
        }
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {Errors.FailedCall} error.
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert Errors.InsufficientBalance(address(this).balance, value);
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
     * of an unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {Errors.FailedCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert Errors.FailedCall();
        }
    }
}

File 20 of 36 : IBeacon.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeacon {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {UpgradeableBeacon} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}

File 21 of 36 : IERC1967.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1967.sol)

pragma solidity ^0.8.20;

/**
 * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
 */
interface IERC1967 {
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);
}

File 22 of 36 : StorageSlot.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.24;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC-1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * Since version 5.1, this library also support writing and reading value types to and from transient storage.
 *
 *  * Example using transient storage:
 * ```solidity
 * contract Lock {
 *     // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
 *     bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;
 *
 *     modifier locked() {
 *         require(!_LOCK_SLOT.asBoolean().tload());
 *
 *         _LOCK_SLOT.asBoolean().tstore(true);
 *         _;
 *         _LOCK_SLOT.asBoolean().tstore(false);
 *     }
 * }
 * ```
 *
 * TIP: Consider using this library along with {SlotDerivation}.
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct Int256Slot {
        int256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Int256Slot` with member `value` located at `slot`.
     */
    function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev UDVT that represent a slot holding a address.
     */
    type AddressSlotType is bytes32;

    /**
     * @dev Cast an arbitrary slot to a AddressSlotType.
     */
    function asAddress(bytes32 slot) internal pure returns (AddressSlotType) {
        return AddressSlotType.wrap(slot);
    }

    /**
     * @dev UDVT that represent a slot holding a bool.
     */
    type BooleanSlotType is bytes32;

    /**
     * @dev Cast an arbitrary slot to a BooleanSlotType.
     */
    function asBoolean(bytes32 slot) internal pure returns (BooleanSlotType) {
        return BooleanSlotType.wrap(slot);
    }

    /**
     * @dev UDVT that represent a slot holding a bytes32.
     */
    type Bytes32SlotType is bytes32;

    /**
     * @dev Cast an arbitrary slot to a Bytes32SlotType.
     */
    function asBytes32(bytes32 slot) internal pure returns (Bytes32SlotType) {
        return Bytes32SlotType.wrap(slot);
    }

    /**
     * @dev UDVT that represent a slot holding a uint256.
     */
    type Uint256SlotType is bytes32;

    /**
     * @dev Cast an arbitrary slot to a Uint256SlotType.
     */
    function asUint256(bytes32 slot) internal pure returns (Uint256SlotType) {
        return Uint256SlotType.wrap(slot);
    }

    /**
     * @dev UDVT that represent a slot holding a int256.
     */
    type Int256SlotType is bytes32;

    /**
     * @dev Cast an arbitrary slot to a Int256SlotType.
     */
    function asInt256(bytes32 slot) internal pure returns (Int256SlotType) {
        return Int256SlotType.wrap(slot);
    }

    /**
     * @dev Load the value held at location `slot` in transient storage.
     */
    function tload(AddressSlotType slot) internal view returns (address value) {
        /// @solidity memory-safe-assembly
        assembly {
            value := tload(slot)
        }
    }

    /**
     * @dev Store `value` at location `slot` in transient storage.
     */
    function tstore(AddressSlotType slot, address value) internal {
        /// @solidity memory-safe-assembly
        assembly {
            tstore(slot, value)
        }
    }

    /**
     * @dev Load the value held at location `slot` in transient storage.
     */
    function tload(BooleanSlotType slot) internal view returns (bool value) {
        /// @solidity memory-safe-assembly
        assembly {
            value := tload(slot)
        }
    }

    /**
     * @dev Store `value` at location `slot` in transient storage.
     */
    function tstore(BooleanSlotType slot, bool value) internal {
        /// @solidity memory-safe-assembly
        assembly {
            tstore(slot, value)
        }
    }

    /**
     * @dev Load the value held at location `slot` in transient storage.
     */
    function tload(Bytes32SlotType slot) internal view returns (bytes32 value) {
        /// @solidity memory-safe-assembly
        assembly {
            value := tload(slot)
        }
    }

    /**
     * @dev Store `value` at location `slot` in transient storage.
     */
    function tstore(Bytes32SlotType slot, bytes32 value) internal {
        /// @solidity memory-safe-assembly
        assembly {
            tstore(slot, value)
        }
    }

    /**
     * @dev Load the value held at location `slot` in transient storage.
     */
    function tload(Uint256SlotType slot) internal view returns (uint256 value) {
        /// @solidity memory-safe-assembly
        assembly {
            value := tload(slot)
        }
    }

    /**
     * @dev Store `value` at location `slot` in transient storage.
     */
    function tstore(Uint256SlotType slot, uint256 value) internal {
        /// @solidity memory-safe-assembly
        assembly {
            tstore(slot, value)
        }
    }

    /**
     * @dev Load the value held at location `slot` in transient storage.
     */
    function tload(Int256SlotType slot) internal view returns (int256 value) {
        /// @solidity memory-safe-assembly
        assembly {
            value := tload(slot)
        }
    }

    /**
     * @dev Store `value` at location `slot` in transient storage.
     */
    function tstore(Int256SlotType slot, int256 value) internal {
        /// @solidity memory-safe-assembly
        assembly {
            tstore(slot, value)
        }
    }
}

File 23 of 36 : draft-IERC1822.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC1822.sol)

pragma solidity ^0.8.20;

/**
 * @dev ERC-1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822Proxiable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}

File 24 of 36 : OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    /// @custom:storage-location erc7201:openzeppelin.storage.Ownable
    struct OwnableStorage {
        address _owner;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;

    function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
        assembly {
            $.slot := OwnableStorageLocation
        }
    }

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    function __Ownable_init(address initialOwner) internal onlyInitializing {
        __Ownable_init_unchained(initialOwner);
    }

    function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        OwnableStorage storage $ = _getOwnableStorage();
        return $._owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        OwnableStorage storage $ = _getOwnableStorage();
        address oldOwner = $._owner;
        $._owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 25 of 36 : IEGETH.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

interface IEGETH is IERC20, IERC20Metadata {
    function mint(address _recipient, uint256 _sharesAmount) external;
    function burn(address _account, uint256 _sharesAmount) external;
    function approve(address _spender, uint256 _amount) external returns (bool);
    function allowance(address _owner, address _spender) external view returns (uint256);
    function increaseAllowance(address _spender, uint256 _addedValue) external returns (bool);
    function decreaseAllowance(address _spender, uint256 _subtractedValue) external returns (bool);
    function transfer(address _recipient, uint256 _amount) external returns (bool);
    function transferFrom(address _sender, address _recipient, uint256 _amount) external returns (bool);
    function balanceOf(address _account) external view returns (uint256);
    function sharesOf(address _account) external view returns (uint256);
    function totalSupply() external view returns (uint256);
    function getTotalShares() external view returns (uint256);
}

File 26 of 36 : ILiquidityPool.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

interface ILiquidityPool {
    struct PermitInput {
        uint256 value;
        uint256 deadline;
        uint8 v;
        bytes32 r;
        bytes32 s;
    }

    function totalValueOutOfLp() external view returns (uint256);

    function totalValueInLp() external view returns (uint256);

    function paused() external view returns (bool);

    function getTotalEtherClaimOf(address _user) external view returns (uint256);

    function getTotalPooledEther() external view returns (uint256);

    function sharesForAmount(uint256 _amount) external view returns (uint256);

    function sharesForWithdrawalAmount(uint256 _amount) external view returns (uint256);

    function amountForShare(uint256 _share) external view returns (uint256);

    function deposit() external payable returns (uint256);

    function deposit(address _referral) external payable returns (uint256);

    function setTokenAddress(address _eETH) external;

    function updateAdmin(address _newAdmin, bool _isAdmin) external;
}

File 27 of 36 : IRestakeManager.sol
//SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "./IDepositQueue.sol";

interface IRestakeManager {
    function depositQueue() external view returns (IDepositQueue);

    function paused() external view returns (bool);

    function depositETH() external payable;

    function calculateTVLs() external view returns (uint256, uint256, uint256);
}

File 28 of 36 : IRenzoOracle.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.24;

/// @dev This contract will be responsible for looking up values via Chainlink
/// Data retrieved will be verified for liveness via a max age on the oracle lookup.
/// All tokens should be denominated in the same base currency and contain the same decimals on the price lookup.
interface IRenzoOracle {
    /// @dev Given amount of current protocol value, new value being added, and supply of ezETH, determine amount to mint
    /// Values should be denominated in the same underlying currency with the same decimal precision
    function calculateMintAmount(uint256 _currentValueInProtocol, uint256 _newValueAdded, uint256 _existingEzETHSupply)
        external
        pure
        returns (uint256);

    // Given the amount of ezETH to burn, the supply of ezETH, and the total value in the protocol, determine amount of value to return to user
    function calculateRedeemAmount(
        uint256 _ezETHBeingBurned,
        uint256 _existingEzETHSupply,
        uint256 _currentValueInProtocol
    ) external pure returns (uint256);
}

File 29 of 36 : IKLRTOracle.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

interface IKLRTOracle {
    function rsETHPrice() external pure returns (uint256);
    function updateRSETHPrice() external;
}

File 30 of 36 : ILRTProtocolsManager.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;

interface ILRTProtocolsManager {
    function totalEthAmount(
        uint256 _etherFiShares,
        uint256 _kelpShares,
        uint256 _renzoShares,
        uint256 _ezETHTotalSupply
    ) external view returns (uint256);
    function totalProtocolsEther(
        uint256 _etherFiShares,
        uint256 _kelpShares,
        uint256 _renzoShares,
        uint256 _ezETHTotalSupply
    ) external view returns (uint256, uint256, uint256);

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

    function ethToRenzoEth(uint256 _ethAmount, uint256 _totalSupply) external view returns (uint256);

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

    function getImplementation() external view returns (address);

    function renzoEthAmount(uint256 shares, uint256 _totalSupply) external view returns (uint256);

    function kelpEthAmount(uint256 shares) external view returns (uint256);
}

File 31 of 36 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../token/ERC20/IERC20.sol";

File 32 of 36 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../utils/introspection/IERC165.sol";

File 33 of 36 : Errors.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

/**
 * @dev Collection of common custom errors used in multiple contracts
 *
 * IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
 * It is recommended to avoid relying on the error API for critical functionality.
 */
library Errors {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error InsufficientBalance(uint256 balance, uint256 needed);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedCall();

    /**
     * @dev The deployment failed.
     */
    error FailedDeployment();
}

File 34 of 36 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

File 35 of 36 : IDepositQueue.sol
//SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

interface IDepositQueue {
    function depositETHFromProtocol() external payable;

    function totalEarned(address tokenAddress) external view returns (uint256);
}

File 36 of 36 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

Settings
{
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "@openzeppelin/foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
    "@aave/protocol-v2/=lib/protocol-v2/",
    "@aave/core-v3/=lib/aave-v3-core/",
    "@uniswap/v3-core/=lib/v3-core/",
    "@uniswap/v3-periphery/=lib/v3-periphery/",
    "halmos-cheatcodes/=lib/halmos-cheatcodes/src/",
    "aave-v3-core/=lib/aave-v3-core/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
    "solidity-stringutils/=lib/openzeppelin-foundry-upgrades/lib/solidity-stringutils/",
    "v3-core/=lib/v3-core/",
    "v3-periphery/=lib/v3-periphery/contracts/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "cancun",
  "viaIR": false,
  "debug": {
    "revertStrings": "strip"
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

API
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[],"name":"Aggregator__AmountExceedsMaxWithdrawal","type":"error"},{"inputs":[],"name":"Aggregator__AmountMustBeGreaterThanZero","type":"error"},{"inputs":[],"name":"Aggregator__BelowMinETHDeposit","type":"error"},{"inputs":[],"name":"Aggregator__ContractPaused","type":"error"},{"inputs":[],"name":"Aggregator__InsufficientAllowance","type":"error"},{"inputs":[],"name":"Aggregator__InsufficientAmount","type":"error"},{"inputs":[],"name":"Aggregator__InsufficientSharesAmount","type":"error"},{"inputs":[],"name":"Aggregator__InvalidAddress","type":"error"},{"inputs":[],"name":"Aggregator__InvalidAmount","type":"error"},{"inputs":[],"name":"Aggregator__InvalidAmountToMint","type":"error"},{"inputs":[],"name":"Aggregator__InvalidTotalWeight","type":"error"},{"inputs":[],"name":"Aggregator__MinimumDepositAmount","type":"error"},{"inputs":[],"name":"Aggregator__NoDirectETHTransfer","type":"error"},{"inputs":[],"name":"Aggregator__OnlyAdmin","type":"error"},{"inputs":[],"name":"Aggregator__TokenNotAllowed","type":"error"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"ERC1967InvalidImplementation","type":"error"},{"inputs":[],"name":"ERC1967NonPayable","type":"error"},{"inputs":[],"name":"FailedCall","type":"error"},{"inputs":[{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"InsufficientBalance","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"UUPSUnauthorizedCallContext","type":"error"},{"inputs":[{"internalType":"bytes32","name":"slot","type":"bytes32"}],"name":"UUPSUnsupportedProxiableUUID","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"totalPooledEther","type":"uint256"}],"name":"CurrentPooledEtherUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"token","type":"address"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"ethAddress","type":"address"}],"name":"EthTokenAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"etherFiWeight","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"renzoWeight","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"kelpWeight","type":"uint256"}],"name":"TargetWeightsUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"}],"name":"UnPaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"token","type":"address"}],"name":"Withdraw","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"ETH_TOKEN","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UPGRADE_INTERFACE_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"admins","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"allowedTokens","outputs":[{"internalType":"bool","name":"isAllowed","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bldTreasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"egShares","type":"uint256"}],"name":"convertEgETHToLRTShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"convertEthToEgETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"ethAmount","type":"uint256"}],"name":"convertEthToLRTShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertLRTSharesToEgETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertLRTSharesToEth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentWeights","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"depositETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minEgETHAmount","type":"uint256"}],"name":"depositLRT","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"egETH","outputs":[{"internalType":"contract EGETH","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"etherFiEETH","outputs":[{"internalType":"contract IERC20","name":"asset","type":"address"},{"internalType":"uint256","name":"targetWeight","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getImplementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"admin","type":"address"},{"internalType":"address","name":"treasury","type":"address"},{"internalType":"address","name":"egETH","type":"address"},{"internalType":"address","name":"ethTokenAddress","type":"address"}],"internalType":"struct IConfigAggregator","name":"_configAggregator","type":"tuple"},{"internalType":"address","name":"_lrtManager","type":"address"},{"components":[{"components":[{"internalType":"contract IERC20","name":"asset","type":"address"},{"internalType":"uint256","name":"targetWeight","type":"uint256"}],"internalType":"struct IAssetInfo","name":"etherFieEth","type":"tuple"},{"components":[{"internalType":"contract IERC20","name":"asset","type":"address"},{"internalType":"uint256","name":"targetWeight","type":"uint256"}],"internalType":"struct IAssetInfo","name":"renzoEzEth","type":"tuple"},{"components":[{"internalType":"contract IERC20","name":"asset","type":"address"},{"internalType":"uint256","name":"targetWeight","type":"uint256"}],"internalType":"struct IAssetInfo","name":"kelpRsETH","type":"tuple"}],"internalType":"struct IAssets","name":"_assets","type":"tuple"}],"name":"initialize","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"kelpRsETH","outputs":[{"internalType":"contract IERC20","name":"asset","type":"address"},{"internalType":"uint256","name":"targetWeight","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lrtManager","outputs":[{"internalType":"contract LRTProtocolsManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"maxLRTWithdrawInEgETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minDepositETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"previewDepositETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"previewDepositLRT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewWithdrawLRT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renzoEzETH","outputs":[{"internalType":"contract IERC20","name":"asset","type":"address"},{"internalType":"uint256","name":"targetWeight","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"ethAddress","type":"address"}],"name":"setEthTokenAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_paused","type":"bool"}],"name":"setPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"etherFiWeight","type":"uint256"},{"internalType":"uint256","name":"renzoWeight","type":"uint256"},{"internalType":"uint256","name":"kelpWeight","type":"uint256"}],"name":"setTargetWeights","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"targetWeights","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalCurrentTVLs","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalPooledEther","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"assetToWithdraw","type":"address"},{"internalType":"uint256","name":"egShares","type":"uint256"}],"name":"withdrawLRT","outputs":[],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]

Deployed Bytecode

0x608060405260043610610254575f3560e01c806379ba509711610138578063b90c49ce116100b5578063e424c78711610079578063e424c78714610704578063e498b6f814610723578063e744092e14610737578063ec0f7e8b14610765578063f2fde38b14610784578063f6326fb3146107a357610272565b8063b90c49ce14610685578063c8d02e571461069f578063db5af729146106be578063df347995146106dd578063e30c3978146106f057610272565b80638ea4a70d116100fc5780638ea4a70d146105d3578063a3f0517d146105f6578063aaf10f4214610615578063ad3cb1cc14610629578063b599ba541461066657610272565b806379ba50971461054a5780637f78d6ab1461055e578063861864661461057d57806388b888161461059c5780638da5cb5b146105bf57610272565b806352d1902d116101d15780635f6debee116101955780635f6debee146104b2578063634b8079146104d1578063642865a0146104e457806369415b861461050357806370a0823114610517578063715018a61461053657610272565b806352d1902d1461040b578063586909591461041f57806358bc83371461043e5780635ae9d922146104745780635c975abb1461049357610272565b8063311e81f311610218578063311e81f314610368578063322db68a14610387578063429b62e51461039b5780634a1b6bad146103d95780634f1ef286146103f857610272565b806301e1d1141461028b5780630ad9e4b5146102bf57806316c38b3c1461030157806322d01ec6146103225780632b9c4ede1461034f57610272565b3661027257604051635f0b2fad60e11b815260040160405180910390fd5b604051635f0b2fad60e11b815260040160405180910390fd5b348015610296575f80fd5b5061029f6107ab565b604080519384526020840192909252908201526060015b60405180910390f35b3480156102ca575f80fd5b506006546007546102e2916001600160a01b03169082565b604080516001600160a01b0390931683526020830191909152016102b6565b34801561030c575f80fd5b5061032061031b366004612dd7565b6108f8565b005b34801561032d575f80fd5b5061034161033c366004612e06565b6109a3565b6040519081526020016102b6565b34801561035a575f80fd5b50662386f26fc10000610341565b348015610373575f80fd5b50610341610382366004612e06565b610a2b565b348015610392575f80fd5b5061029f610a77565b3480156103a6575f80fd5b506103c96103b5366004612e30565b60016020525f908152604090205460ff1681565b60405190151581526020016102b6565b3480156103e4575f80fd5b506103416103f3366004612e06565b610ab8565b610320610406366004612edc565b610b0c565b348015610416575f80fd5b50610341610b2b565b34801561042a575f80fd5b50610320610439366004612f7e565b610b46565b348015610449575f80fd5b505f5461045c906001600160a01b031681565b6040516001600160a01b0390911681526020016102b6565b34801561047f575f80fd5b5060045461045c906001600160a01b031681565b34801561049e575f80fd5b505f546103c990600160a01b900460ff1681565b3480156104bd575f80fd5b506103416104cc366004612fa7565b610c00565b6103206104df366004613015565b610c1e565b3480156104ef575f80fd5b506103416104fe366004612e06565b610e6e565b34801561050e575f80fd5b50610341611065565b348015610522575f80fd5b50610341610531366004612e30565b611073565b348015610541575f80fd5b506103206110df565b348015610555575f80fd5b506103206110f2565b348015610569575f80fd5b50610341610578366004612fa7565b61113c565b348015610588575f80fd5b50610341610597366004612e06565b611146565b3480156105a7575f80fd5b50600a54600b546102e2916001600160a01b03169082565b3480156105ca575f80fd5b5061045c611273565b3480156105de575f80fd5b506008546009546102e2916001600160a01b03169082565b348015610601575f80fd5b50610320610610366004612e30565b6112a7565b348015610620575f80fd5b5061045c611328565b348015610634575f80fd5b50610659604051806040016040528060058152602001640352e302e360dc1b81525081565b6040516102b69190613111565b348015610671575f80fd5b5060035461045c906001600160a01b031681565b348015610690575f80fd5b50600754600954600b5461029f565b3480156106aa575f80fd5b506103206106b9366004613143565b611347565b3480156106c9575f80fd5b5060025461045c906001600160a01b031681565b6103206106eb366004612e06565b6115e1565b3480156106fb575f80fd5b5061045c611856565b34801561070f575f80fd5b5061034161071e366004612e30565b61187e565b34801561072e575f80fd5b5061029f6118e5565b348015610742575f80fd5b506103c9610751366004612e30565b60056020525f908152604090205460ff1681565b348015610770575f80fd5b5061034161077f366004612e06565b6119f7565b34801561078f575f80fd5b5061032061079e366004612e30565b611a3b565b610320611ac0565b6006546040516370a0823160e01b81523060048201525f91829182916001600160a01b0316906370a0823190602401602060405180830381865afa1580156107f5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108199190613175565b6008546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa15801561085f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108839190613175565b600a546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa1580156108c9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108ed9190613175565b925092509250909192565b335f9081526001602052604090205460ff166109275760405163639f9b4d60e01b815260040160405180910390fd5b5f805482158015600160a01b0260ff60a01b19909216919091179091556109755760405133907f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258905f90a250565b60405133907fff2b959f2bcdb44c7ecb4b16dae055431019d7350607125cfc2b74a06632c90e905f90a25b50565b6001600160a01b0382165f90815260056020526040812054839060ff166109dd576040516304d1587160e01b815260040160405180910390fd5b825f036109ec575f9150610a24565b6109f58461187e565b831115610a155760405163c1f1da1f60e01b815260040160405180910390fd5b5f610a2085856119f7565b9250505b5092915050565b6001600160a01b0382165f90815260056020526040812054839060ff16610a65576040516304d1587160e01b815260040160405180910390fd5b610a6f8484611b9a565b949350505050565b5f805f805f80610a856107ab565b9250925092505f610a94611bb1565b90505f805f610aa587878787611bc5565b919c909b50909950975050505050505050565b6001600160a01b0382165f90815260056020526040812054839060ff16610af2576040516304d1587160e01b815260040160405180910390fd5b825f03610b01575f9150610a24565b5f610a208585610e6e565b610b14611de6565b610b1d82611e8a565b610b278282611e92565b5050565b5f610b34611f4e565b505f8051602061328183398151915290565b335f9081526001602052604090205460ff16610b755760405163639f9b4d60e01b815260040160405180910390fd5b6103e881610b8384866131a0565b610b8d91906131a0565b14610bab5760405163a16c715f60e01b815260040160405180910390fd5b60078390556009829055600b81905560408051848152602081018490529081018290527f48a3915bbcde9b52b846783837de456a846b77ea90f5468820e79d20384086249060600160405180910390a1505050565b5f815f03610c0f57505f919050565b610c1882611f97565b92915050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff16159067ffffffffffffffff165f81158015610c635750825b90505f8267ffffffffffffffff166001148015610c7f5750303b155b905081158015610c8d575080155b15610cab5760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff191660011785558315610cd557845460ff60401b1916600160401b1785555b345f819003610cf757604051635a0b6c2560e11b815260040160405180910390fd5b610d0033612052565b610d08612063565b610d10612073565b602089810151600480546001600160a01b03199081166001600160a01b03938416179091556040808d01516002805484169185169190911790556003805483168d85161790558a5180516006805485169186169182179055908501516007558b8501805180516008805487169188169190911790558601516009558c830180518051600a80548816918916919091179055870151600b555f92835260058752838320805460ff1990811660019081179092559251518716845284842080548416821790559051518616835283832080548316821790558f5186168352958690529181208054909216909417905560608c015183549091169116179055610e158161207b565b610e1d6126c4565b508315610e6457845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b5050505050505050565b6001600160a01b0382165f90815260056020526040812054839060ff16610ea8576040516304d1587160e01b815260040160405180910390fd5b825f03610eb7575f9150610a24565b6006546001600160a01b0390811690851603610f40576003546040516302fc502360e21b8152600481018590526001600160a01b0390911690630bf1408c906024015b602060405180830381865afa158015610f15573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f399190613175565b9150610a24565b6008546001600160a01b0390811690851603610ff957600354600854604080516318160ddd60e01b815290516001600160a01b039384169363349104769388939116916318160ddd916004808201926020929091908290030181865afa158015610fac573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fd09190613175565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401610efa565b6003546040516315ba026160e31b8152600481018590526001600160a01b039091169063add01308906024015b602060405180830381865afa158015611041573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a6f9190613175565b5f61106e611bb1565b905090565b6002546040516370a0823160e01b81526001600160a01b0383811660048301525f9216906370a0823190602401602060405180830381865afa1580156110bb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c189190613175565b6110e761272f565b6110f05f612761565b565b33806110fc611856565b6001600160a01b0316146111335760405163118cdaa760e01b81526001600160a01b03821660048201526024015b60405180910390fd5b6109a081612761565b5f610c1882610c00565b6001600160a01b0382165f90815260056020526040812054839060ff16611180576040516304d1587160e01b815260040160405180910390fd5b825f0361118f575f9150610a24565b6006546001600160a01b03908116908516036111d6576003546040516302fc502360e21b8152600481018590526001600160a01b0390911690630bf1408c90602401610efa565b6008546001600160a01b039081169085160361124257600354600854604080516318160ddd60e01b815290516001600160a01b039384169363de31ec6b9388939116916318160ddd916004808201926020929091908290030181865afa158015610fac573d5f803e3d5ffd5b6003546040516315dbc14160e11b8152600481018590526001600160a01b0390911690632bb7828290602401611026565b5f807f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c1993005b546001600160a01b031692915050565b6112af61272f565b6001600160a01b0381166112d55760405162cef13b60e31b815260040160405180910390fd5b5f80546001600160a01b0319166001600160a01b0383169081179091556040519081527f2d697855d7f823a347aa99f39b1e67108440aa1d3a5da93685d4f20a82fd11449060200160405180910390a150565b5f61106e5f80516020613281833981519152546001600160a01b031690565b61134f612799565b6001600160a01b0383165f90815260056020526040902054839060ff16611389576040516304d1587160e01b815260040160405180910390fd5b5f54600160a01b900460ff16156113b357604051637f4c0e9f60e11b815260040160405180910390fd5b825f036113d357604051635a0b6c2560e11b815260040160405180910390fd5b604051636eb1769f60e11b815233600482015230602482015283906001600160a01b0386169063dd62ed3e90604401602060405180830381865afa15801561141d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114419190613175565b101561146057604051630e31558960e41b815260040160405180910390fd5b60035f9054906101000a90046001600160a01b03166001600160a01b031663cbad576c6040518163ffffffff1660e01b81526004015f604051808303815f87803b1580156114ac575f80fd5b505af11580156114be573d5f803e3d5ffd5b505050505f6114cd8585611b9a565b90506064836114dc82846131a0565b10156114fb57604051633197e5b160e01b815260040160405180910390fd5b85611508813330896127d0565b5f6115138888610e6e565b9050876001600160a01b0316336001600160a01b03167fe31c7b8d08ee7db0afa68782e1028ef92305caeea8626633ad44d413e30f6b2f8360405161155a91815260200190565b60405180910390a36002546040516340c10f1960e01b8152336004820152602481018690526001600160a01b03909116906340c10f19906044015f604051808303815f87803b1580156115ab575f80fd5b505af11580156115bd573d5f803e3d5ffd5b5050505050505050506115dc60015f805160206132a183398151915255565b505050565b6115e9612799565b6001600160a01b0382165f90815260056020526040902054829060ff16611623576040516304d1587160e01b815260040160405180910390fd5b815f0361164357604051635a0b6c2560e11b815260040160405180910390fd5b8161164d33611073565b101561166c57604051638af7413f60e01b815260040160405180910390fd5b60035f9054906101000a90046001600160a01b03166001600160a01b031663cbad576c6040518163ffffffff1660e01b81526004015f604051808303815f87803b1580156116b8575f80fd5b505af11580156116ca573d5f803e3d5ffd5b505050506116d78361187e565b8211156116f75760405163c1f1da1f60e01b815260040160405180910390fd5b600254604051636eb1769f60e11b815233600482015230602482015283916001600160a01b03169063dd62ed3e90604401602060405180830381865afa158015611743573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117679190613175565b101561178657604051630e31558960e41b815260040160405180910390fd5b825f61179282856119f7565b600254604051632770a7eb60e21b8152336004820152602481018790529192506001600160a01b031690639dc29fac906044015f604051808303815f87803b1580156117dc575f80fd5b505af11580156117ee573d5f803e3d5ffd5b505050506117fd823383612850565b6040518481526001600160a01b0386169033907f56c54ba9bd38d8fd62012e42c7ee564519b09763c426d331b3661b537ead19b29060200160405180910390a3505050610b2760015f805160206132a183398151915255565b5f807f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c00611297565b5f805f8061188a6107ab565b60065492955090935091506001600160a01b03908116908616036118bb576118b28584610ab8565b95945050505050565b6008546001600160a01b03908116908616036118db576118b28583610ab8565b6118b28582610ab8565b5f805f805f806118f36107ab565b600354600854604080516318160ddd60e01b815290519598509396509194506001600160a01b039081169363e5b8db1d938893879389939116916318160ddd9160048083019260209291908290030181865afa158015611955573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119799190613175565b6040516001600160e01b031960e087901b1681526004810194909452602484019290925260448301526064820152608401606060405180830381865afa1580156119c5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119e991906131b3565b955095509550505050909192565b6001600160a01b0382165f90815260056020526040812054839060ff16611a31576040516304d1587160e01b815260040160405180910390fd5b610a6f8484611146565b611a4361272f565b7f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c0080546001600160a01b0319166001600160a01b0383169081178255611a87611273565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a35050565b611ac8612799565b5f54600160a01b900460ff1615611af257604051637f4c0e9f60e11b815260040160405180910390fd5b34662386f26fc10000811015611b1b57604051639fd28c1560e01b815260040160405180910390fd5b611b248161207b565b6002546040516340c10f1960e01b8152336004820152602481018390526001600160a01b03909116906340c10f19906044015f604051808303815f87803b158015611b6d575f80fd5b505af1158015611b7f573d5f803e3d5ffd5b50505050506110f060015f805160206132a183398151915255565b5f80611ba68484610e6e565b9050610a6f81611f97565b5f47611bbb612881565b61106e91906131a0565b6003546040516302fc502360e21b8152600481018690525f918291829182916001600160a01b0390911690630bf1408c90602401602060405180830381865afa158015611c14573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c389190613175565b600354600854604080516318160ddd60e01b815290519394505f936001600160a01b03938416936334910476938d939116916318160ddd916004808201926020929091908290030181865afa158015611c93573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611cb79190613175565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401602060405180830381865afa158015611cf6573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d1a9190613175565b6003546040516315ba026160e31b8152600481018a90529192505f916001600160a01b039091169063add0130890602401602060405180830381865afa158015611d66573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d8a9190613175565b90505f611da2611d9c6103e8866131de565b8961298b565b90505f611dba611db46103e8866131de565b8a61298b565b90505f611dd2611dcc6103e8866131de565b8b61298b565b929d919c50919a5098505050505050505050565b306001600160a01b037f0000000000000000000000000765e87cb293960b17461d6386e50bd0332f15d7161480611e6c57507f0000000000000000000000000765e87cb293960b17461d6386e50bd0332f15d76001600160a01b0316611e605f80516020613281833981519152546001600160a01b031690565b6001600160a01b031614155b156110f05760405163703e46dd60e11b815260040160405180910390fd5b6109a061272f565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611eec575060408051601f3d908101601f19168201909252611ee991810190613175565b60015b611f1457604051634c9c8ce360e01b81526001600160a01b038316600482015260240161112a565b5f805160206132818339815191528114611f4457604051632a87526960e21b81526004810182905260240161112a565b6115dc8383612a05565b306001600160a01b037f0000000000000000000000000765e87cb293960b17461d6386e50bd0332f15d716146110f05760405163703e46dd60e11b815260040160405180910390fd5b600254604051631920845160e01b8152600481018390525f9182916001600160a01b0390911690631920845190602401602060405180830381865afa158015611fe2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120069190613175565b600254604051630f451f7160e31b8152600481018390529192505f916001600160a01b0390911690637a28fb8890602401602060405180830381865afa158015611041573d5f803e3d5ffd5b61205a612a5a565b6109a081612aa3565b61206b612a5a565b6110f0612ad4565b6110f0612a5a565b60035460408051631cb82f2560e31b815290515f926001600160a01b03169163e5c179289160048083019260209291908290030181865afa1580156120c2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120e691906131f5565b6001600160a01b0316635c975abb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612121573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121459190613210565b90505f60035f9054906101000a90046001600160a01b03166001600160a01b031663e8ae19e76040518163ffffffff1660e01b8152600401602060405180830381865afa158015612198573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121bc91906131f5565b6001600160a01b0316635c975abb6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156121f7573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061221b9190613210565b90505f60035f9054906101000a90046001600160a01b03166001600160a01b031663a640552d6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561226e573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061229291906131f5565b6001600160a01b0316635c975abb6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156122cd573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906122f19190613210565b905082806122fc5750815b806123045750805b1561232257604051637f4c0e9f60e11b815260040160405180910390fd5b6007545f906103e89061233590876131de565b61233f919061323f565b90505f6103e86008600101548761235691906131de565b612360919061323f565b90505f6103e8600a600101548861237791906131de565b612381919061323f565b905060035f9054906101000a90046001600160a01b03166001600160a01b031663e5c179286040518163ffffffff1660e01b8152600401602060405180830381865afa1580156123d3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906123f791906131f5565b6001600160a01b031663d0e30db0846040518263ffffffff1660e01b815260040160206040518083038185885af1158015612434573d5f803e3d5ffd5b50505050506040513d601f19601f820116820180604052508101906124599190613175565b5060035f9054906101000a90046001600160a01b03166001600160a01b031663e8ae19e76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156124aa573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906124ce91906131f5565b6001600160a01b031663f6326fb3836040518263ffffffff1660e01b81526004015f604051808303818588803b158015612506575f80fd5b505af1158015612518573d5f803e3d5ffd5b50505050505f60035f9054906101000a90046001600160a01b03166001600160a01b031663a640552d6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561256e573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061259291906131f5565b5f8054604051635d2dda2160e11b81526001600160a01b0391821660048201526024810186905292935090919083169063ba5bb44290604401602060405180830381865afa1580156125e6573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061260a9190613175565b9050816001600160a01b03166372c51c0b84836040518363ffffffff1660e01b8152600401612654918152604060208201819052600190820152600360fc1b606082015260800190565b5f604051808303818588803b15801561266b575f80fd5b505af115801561267d573d5f803e3d5ffd5b50506040518c81525f93503392507fe31c7b8d08ee7db0afa68782e1028ef92305caeea8626633ad44d413e30f6b2f915060200160405180910390a3505050505050505050565b5f6126cd611bb1565b6002546040516226d96760e71b8152336004820152602481018390529192506001600160a01b03169063136cb380906044015f604051808303815f87803b158015612716575f80fd5b505af1158015612728573d5f803e3d5ffd5b5050505050565b33612738611273565b6001600160a01b0316146110f05760405163118cdaa760e01b815233600482015260240161112a565b7f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c0080546001600160a01b0319168155610b2782612adc565b5f805160206132a18339815191528054600119016127ca57604051633ee5aeb560e01b815260040160405180910390fd5b60029055565b6040516001600160a01b0384811660248301528381166044830152606482018390526128379186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050612b4c565b50505050565b60015f805160206132a183398151915255565b6040516001600160a01b038381166024830152604482018390526115dc91859182169063a9059cbb90606401612805565b5f805f8061288d6107ab565b600354600854604080516318160ddd60e01b815290519598509396509194506001600160a01b0390811693636dc62c52938893879389939116916318160ddd9160048083019260209291908290030181865afa1580156128ef573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129139190613175565b6040516001600160e01b031960e087901b1681526004810194909452602484019290925260448301526064820152608401602060405180830381865afa15801561295f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129839190613175565b935050505090565b5f808211612997575f80fd5b5f6129a3600284613252565b156129c3576129b360028461323f565b6129be9060016131a0565b6129ce565b6129ce60028461323f565b9050806129db8486613252565b10156129f0576129eb838561323f565b610a6f565b6129fa838561323f565b610a6f9060016131a0565b612a0e82612bad565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a2805115612a52576115dc8282612c10565b610b27612c79565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff166110f057604051631afcd79f60e31b815260040160405180910390fd5b612aab612a5a565b6001600160a01b03811661113357604051631e4fbdf760e01b81525f600482015260240161112a565b61283d612a5a565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930080546001600160a01b031981166001600160a01b03848116918217845560405192169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a3505050565b5f612b606001600160a01b03841683612c98565b905080515f14158015612b84575080806020019051810190612b829190613210565b155b156115dc57604051635274afe760e01b81526001600160a01b038416600482015260240161112a565b806001600160a01b03163b5f03612be257604051634c9c8ce360e01b81526001600160a01b038216600482015260240161112a565b5f8051602061328183398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b60605f80846001600160a01b031684604051612c2c9190613265565b5f60405180830381855af49150503d805f8114612c64576040519150601f19603f3d011682016040523d82523d5f602084013e612c69565b606091505b5091509150610a20858383612cac565b34156110f05760405163b398979f60e01b815260040160405180910390fd5b6060612ca583835f612d01565b9392505050565b606082612cc157612cbc82612da1565b612ca5565b8151158015612cd857506001600160a01b0384163b155b15610a2457604051639996b31560e01b81526001600160a01b038516600482015260240161112a565b606081471015612d2d5760405163cf47918160e01b81524760048201526024810183905260440161112a565b5f80856001600160a01b03168486604051612d489190613265565b5f6040518083038185875af1925050503d805f8114612d82576040519150601f19603f3d011682016040523d82523d5f602084013e612d87565b606091505b5091509150612d97868383612cac565b9695505050505050565b805115612db15780518082602001fd5b60405163d6bda27560e01b815260040160405180910390fd5b80151581146109a0575f80fd5b5f60208284031215612de7575f80fd5b8135612ca581612dca565b6001600160a01b03811681146109a0575f80fd5b5f8060408385031215612e17575f80fd5b8235612e2281612df2565b946020939093013593505050565b5f60208284031215612e40575f80fd5b8135612ca581612df2565b634e487b7160e01b5f52604160045260245ffd5b6040516080810167ffffffffffffffff81118282101715612e8257612e82612e4b565b60405290565b6040516060810167ffffffffffffffff81118282101715612e8257612e82612e4b565b604051601f8201601f1916810167ffffffffffffffff81118282101715612ed457612ed4612e4b565b604052919050565b5f8060408385031215612eed575f80fd5b8235612ef881612df2565b915060208381013567ffffffffffffffff80821115612f15575f80fd5b818601915086601f830112612f28575f80fd5b813581811115612f3a57612f3a612e4b565b612f4c601f8201601f19168501612eab565b91508082528784828501011115612f61575f80fd5b80848401858401375f848284010152508093505050509250929050565b5f805f60608486031215612f90575f80fd5b505081359360208301359350604090920135919050565b5f60208284031215612fb7575f80fd5b5035919050565b5f60408284031215612fce575f80fd5b6040516040810181811067ffffffffffffffff82111715612ff157612ff1612e4b565b604052905080823561300281612df2565b8152602092830135920191909152919050565b5f805f838503610160811215613029575f80fd5b6080811215613036575f80fd5b61303e612e5f565b853561304981612df2565b8152602086013561305981612df2565b6020820152604086013561306c81612df2565b6040820152606086013561307f81612df2565b60608201529350608085013561309481612df2565b925060c0609f19820112156130a7575f80fd5b506130b0612e88565b6130bd8660a08701612fbe565b81526130cc8660e08701612fbe565b60208201526130df866101208701612fbe565b6040820152809150509250925092565b5f5b838110156131095781810151838201526020016130f1565b50505f910152565b602081525f825180602084015261312f8160408501602087016130ef565b601f01601f19169190910160400192915050565b5f805f60608486031215613155575f80fd5b833561316081612df2565b95602085013595506040909401359392505050565b5f60208284031215613185575f80fd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b80820180821115610c1857610c1861318c565b5f805f606084860312156131c5575f80fd5b8351925060208401519150604084015190509250925092565b8082028115828204841417610c1857610c1861318c565b5f60208284031215613205575f80fd5b8151612ca581612df2565b5f60208284031215613220575f80fd5b8151612ca581612dca565b634e487b7160e01b5f52601260045260245ffd5b5f8261324d5761324d61322b565b500490565b5f826132605761326061322b565b500690565b5f82516132768184602087016130ef565b919091019291505056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a2646970667358221220680da9073a9de1eec0cb808d331d19288703ca734d13ac9b0cf05f47d4e4866964736f6c63430008180033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.