NodeDelegator

创建于 差异永不过期
25 删除
581 行
31 添加
586 行
// SPDX-License-Identifier: BUSL-1.1
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
pragma solidity 0.8.27;


// openzeppelin or other standard contracts
// openzeppelin or other standard contracts
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import {
import {
ReentrancyGuardUpgradeable
ReentrancyGuardUpgradeable
} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
} 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";


// external libraries, interfaces, contracts
// external libraries, interfaces, contracts
import { IEigenPod } from "./external/eigenlayer/interfaces/IEigenPod.sol";
import { IEigenPod } from "./external/eigenlayer/interfaces/IEigenPod.sol";
import { IStrategyManager } from "./external/eigenlayer/interfaces/IStrategyManager.sol";
import { IStrategyManager } from "./external/eigenlayer/interfaces/IStrategyManager.sol";
import { IEigenPodManager, IETHPOSDeposit } from "./external/eigenlayer/interfaces/IEigenPodManager.sol";
import { IEigenPodManager, IETHPOSDeposit } from "./external/eigenlayer/interfaces/IEigenPodManager.sol";


// protocol libraries, interfaces, contracts
// protocol libraries, interfaces, contracts
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 } from "./utils/LRTConfigRoleChecker.sol";
import { LRTConfigRoleChecker } from "./utils/LRTConfigRoleChecker.sol";


import { ILRTConfig } from "./interfaces/ILRTConfig.sol";
import { ILRTConfig } from "./interfaces/ILRTConfig.sol";
import { IPubkeyRegistry } from "./interfaces/IPubkeyRegistry.sol";
import { IPubkeyRegistry } from "./interfaces/IPubkeyRegistry.sol";
import {
import {
INodeDelegator,
INodeDelegator,
BeaconChainProofs,
BeaconChainProofs,
IERC20,
IERC20,
IStrategy,
IStrategy,
IRewardsCoordinator,
IRewardsCoordinator,
IDelegationManagerTypes
IDelegationManagerTypes
} from "./interfaces/INodeDelegator.sol";
} from "./interfaces/INodeDelegator.sol";
import { ILRTUnstakingVault } from "./interfaces/ILRTUnstakingVault.sol";
import { ILRTUnstakingVault } from "./interfaces/ILRTUnstakingVault.sol";
import { ILRTDepositPool } from "./interfaces/ILRTDepositPool.sol";
import { ILRTDepositPool } from "./interfaces/ILRTDepositPool.sol";
import { NodeDelegatorHelper } from "./NodeDelegatorHelper.sol";
import { NodeDelegatorHelper } from "./NodeDelegatorHelper.sol";
import { IDelegationManager } from "contracts/external/eigenlayer/interfaces/IDelegationManager.sol";
import { IDelegationManager } from "contracts/external/eigenlayer/interfaces/IDelegationManager.sol";


/// @title NodeDelegator Contract
/// @title NodeDelegator Contract
/// @notice The contract that handles the depositing of assets into strategies
/// @notice The contract that handles the depositing of assets into strategies
contract NodeDelegator is INodeDelegator, LRTConfigRoleChecker, PausableUpgradeable, ReentrancyGuardUpgradeable {
contract NodeDelegator is INodeDelegator, LRTConfigRoleChecker, PausableUpgradeable, ReentrancyGuardUpgradeable {
using SafeERC20 for IERC20;
using SafeERC20 for IERC20;
using LRTConstants for ILRTConfig;
using LRTConstants for ILRTConfig;


/// @dev The EigenPod is created and owned by this contract
/// @dev The EigenPod is created and owned by this contract
IEigenPod public eigenPod;
IEigenPod public eigenPod;


/// @dev Tracks the balance staked to validators and has yet to have the credentials verified with EigenLayer.
/// @dev Tracks the balance staked to validators and has yet to have the credentials verified with EigenLayer.
uint256 public stakedButUnverifiedNativeETH;
uint256 public stakedButUnverifiedNativeETH;


/// @dev address of eigenlayer operator to which all restaked funds are delegated to
/// @dev address of eigenlayer operator to which all restaked funds are delegated to
/// @dev it is only possible to delegate fully to only one operator per NDC contract
/// @dev it is only possible to delegate fully to only one operator per NDC contract
address private __elOperatorDelegatedTo;
address private __elOperatorDelegatedTo;


/// @dev amount of eth expected to receive from extra eth staked for validators
/// @dev amount of eth expected to receive from extra eth staked for validators
uint256 private __legacyExtraStakeToReceive;
uint256 private __legacyExtraStakeToReceive;


uint256 private lastNonce;
uint256 private lastNonce;


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


function initialize2() external reinitializer(2) {
function initialize2() external reinitializer(2) {
lastNonce = _getNonce();
lastNonce = _getNonce();
}
}


/// @dev due to a bit heavy logic, eth transfer using `transfer()` and `send()` will fail
/// @dev due to a bit heavy logic, eth transfer using `transfer()` and `send()` will fail
/// @dev hence please use `call()` to send eth to this contract
/// @dev hence please use `call()` to send eth to this contract
receive() external payable {
receive() external payable {
emit ETHReceived(msg.sender, msg.value);
emit ETHReceived(msg.sender, msg.value);
}
}


/*//////////////////////////////////////////////////////////////
/*//////////////////////////////////////////////////////////////
EigenLayer Interactions
EigenLayer Interactions
//////////////////////////////////////////////////////////////*/
//////////////////////////////////////////////////////////////*/


/// @notice Deposits an asset lying in this NDC into its strategy
/// @notice Deposits an asset lying in this NDC into its strategy
/// @dev only supported assets can be deposited and only called by the LRT operator
/// @dev only supported assets can be deposited and only called by the LRT operator
/// @param asset the asset to deposit
/// @param asset the asset to deposit
function depositAssetIntoStrategy(address asset)
function depositAssetIntoStrategy(address asset)
external
external
override
override
nonReentrant
nonReentrant
whenNotPaused
whenNotPaused
onlySupportedAsset(asset)
onlySupportedAsset(asset)
onlyLRTOperator
onlyLRTOperator
{
{
address strategy = lrtConfig.assetStrategy(asset);
address strategy = lrtConfig.assetStrategy(asset);