LRTUnstackingVault

建立於 差異永不過期
9 刪除
223 行
78 新增
288 行
// SPDX-License-Identifier: BUSL-1.1
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
pragma solidity 0.8.27;


import { UtilLib } from "./utils/UtilLib.sol";
import { UtilLib } from "./utils/UtilLib.sol";
import { LRTConstants } from "./utils/LRTConstants.sol";
import { LRTConstants } from "./utils/LRTConstants.sol";
import { LRTConfigRoleChecker, ILRTConfig } from "./utils/LRTConfigRoleChecker.sol";
import { LRTConfigRoleChecker, ILRTConfig } from "./utils/LRTConfigRoleChecker.sol";
import { INodeDelegator, IDelegationManagerTypes } from "./interfaces/INodeDelegator.sol";
import { INodeDelegator } from "./interfaces/INodeDelegator.sol";
import { IEigenPodManager } from "./external/eigenlayer/interfaces/IEigenPodManager.sol";
import { IStrategy } from "./external/eigenlayer/interfaces/IStrategy.sol";
import { IStrategy } from "./external/eigenlayer/interfaces/IStrategy.sol";
import { ILRTWithdrawalManager } from "./interfaces/ILRTWithdrawalManager.sol";
import { ILRTWithdrawalManager } from "./interfaces/ILRTWithdrawalManager.sol";
import { ILRTDepositPool } from "./interfaces/ILRTDepositPool.sol";
import { ILRTUnstakingVault } from "./interfaces/ILRTUnstakingVault.sol";
import { ILRTUnstakingVault } from "./interfaces/ILRTUnstakingVault.sol";
import { IStrategyManager } from "./external/eigenlayer/interfaces/IStrategyManager.sol";
import { IStrategyManager } from "./external/eigenlayer/interfaces/IStrategyManager.sol";
import { ILRTDepositPool } from "./interfaces/ILRTDepositPool.sol";
import { IDelegationManager } from "./external/eigenlayer/interfaces/IDelegationManager.sol";


import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol";
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import {
ReentrancyGuardUpgradeable
} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { SlashingLib } from "./external/eigenlayer/libraries/SlashingLib.sol";
import { SlashingLib } from "./external/eigenlayer/libraries/SlashingLib.sol";
import { IDelegationManager } from "contracts/external/eigenlayer/interfaces/IDelegationManager.sol";


/// @title LRTUnstakingVault Contract
/// @title LRTUnstakingVault Contract
/// @notice The contract that handles the unstaking of assets
/// @notice The contract that handles the unstaking of assets
contract LRTUnstakingVault is
contract LRTUnstakingVault is
ILRTUnstakingVault,
ILRTUnstakingVault,
LRTConfigRoleChecker,
LRTConfigRoleChecker,
PausableUpgradeable,
PausableUpgradeable,
ReentrancyGuardUpgradeable
ReentrancyGuardUpgradeable
{
{
using SafeERC20 for IERC20;
using SafeERC20 for IERC20;
using SlashingLib for *;
using SlashingLib for *;
using LRTConstants for ILRTConfig;
using LRTConstants for ILRTConfig;


// NOTE: For legacy withdrawal support, this can be made private after all pre slashing withdrawals are processed
// NOTE: For legacy withdrawal support, this can be made private after all pre slashing withdrawals are processed
// (asset => 0)
// (asset => 0)
mapping(address asset => uint256) public sharesUnstaking;
mapping(address asset => uint256) public sharesUnstaking;


mapping(bytes32 => bool) public trackedWithdrawal;
mapping(bytes32 => bool) public trackedWithdrawal;


uint256 public uncompletedWithdrawalCount;
uint256 public uncompletedWithdrawalCount;
uint256 public maxUncompletedWithdrawalCount;
uint256 public maxUncompletedWithdrawalCount;


// Portion of the vault reserved for servicing queued withdrawals; unavailable for instant withdrawals.
mapping(address asset => uint256 buffer) public queuedWithdrawalsBuffer;

modifier onlyLRTNodeDelegator() {
modifier onlyLRTNodeDelegator() {
ILRTDepositPool lrtDepositPool = ILRTDepositPool(lrtConfig.depositPool());
ILRTDepositPool lrtDepositPool = ILRTDepositPool(lrtConfig.getContract(LRTConstants.LRT_DEPOSIT_POOL));


if (lrtDepositPool.isNodeDelegator(msg.sender) != 1) {
if (lrtDepositPool.isNodeDelegator(msg.sender) != 1) {
revert CallerNotLRTNodeDelegator();
revert CallerNotLRTNodeDelegator();
}
}
_;
_;
}
}


modifier onlyLRTWithdrawalManager() {
modifier onlyLRTWithdrawalManager() {
if (msg.sender != lrtConfig.withdrawManager()) {
if (msg.sender != lrtConfig.withdrawManager()) {
revert CallerNotLRTWithdrawalManager();
revert CallerNotLRTWithdrawalManager();
}
}
_;
_;
}
}


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


/// @dev Initializes the contract
/// @dev Initializes the contract
/// @param lrtConfigAddr LRT config address
/// @param lrtConfigAddr LRT config address
function initialize(address lrtConfigAddr) external initializer {
function initialize(address lrtConfigAddr) external initializer {
UtilLib.checkNonZeroAddress(lrtConfigAddr);
UtilLib.checkNonZeroAddress(lrtConfigAddr);
__Pausable_init();
__Pausable_init();
__ReentrancyGuard_init();
__ReentrancyGuard_init();


lrtConfig = ILRTConfig(lrtConfigAddr);
lrtConfig = ILRTConfig(lrtConfigAddr);
emit UpdatedLRTConfig(lrtConfigAddr);
emit UpdatedLRTConfig(lrtConfigAddr);
}
}


/*//////////////////////////////////////////////////////////////
/*//////////////////////////////////////////////////////////////
receive functions
receive functions
//////////////////////////////////////////////////////////////*/
//////////////////////////////////////////////////////////////*/


receive() external payable {
receive() external payable {
emit EthReceived(msg.sender, msg.value);
emit EthReceived(msg.sender, msg.value);
}
}


/// @dev receive from LRTDepositPool
/// @dev receive from LRTDepositPool
function receiveFromLRTDepositPool() external payable { }
function receiveFromLRTDepositPool() external payable { }


/// @dev receive from NodeDelegator
/// @dev receive from NodeDelegator
function receiveFromNodeDelegator() external payable { }
function receiveFromNodeDelegator() external payable { }


/*//////////////////////////////////////////////////////////////
/*//////////////////////////////////////////////////////////////
write functions
write functions
//////////////////////////////////////////////////////////////*/
//////////////////////////////////////////////////////////////*/


/// @notice This is used by withdrawal manager when unlocking assets. The unlocked assets are pulled from the vault
/// @notice This is used by withdrawal manager when unlocking assets. The unlocked assets are pulled from the vault
/// and used to pay the user.
/// and used to pay the user.
/// @param asset The asset address.
/// @param asset The asset address.
/// @param amount The amount of asset to redeem.
/// @param amount The amount of asset to redeem.
function redeem(address asset, uint256 amount) external nonReentrant onlyLRTWithdrawalManager {
function redeem(address asset, uint256 amount) external nonReentrant onlyLRTWithdrawalManager {
if (asset == LRTConstants.ETH_TOKEN) {
if (asset == LRTConstants.ETH_TOKEN) {
ILRTWithdrawalManager(msg.sender).receiveFromLRTUnstakingVault{ value: amount }();
ILRTWithdrawalManager(msg.sender).receiveFromLRTUnstakingVault{ value: amount }();