StakingFeePoolV2

Description:

Proxy contract enabling upgradeable smart contract patterns. Delegates calls to an implementation contract.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "contracts/DxpoolFeePoolV2.sol": {
      "content": "// SPDX-License-Identifier: MIT\r
pragma solidity ^0.8.10;\r
\r
/**\r
 * @dev Library for reading and writing primitive types to specific storage slots.\r
 *\r
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\r
 * This library helps with reading and writing to such slots without the need for inline assembly.\r
 *\r
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\r
 *\r
 * Example usage to set ERC1967 implementation slot:\r
 * ```solidity\r
 * contract ERC1967 {\r
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\r
 *\r
 *     function _getImplementation() internal view returns (address) {\r
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\r
 *     }\r
 *\r
 *     function _setImplementation(address newImplementation) internal {\r
 *         require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");\r
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\r
 *     }\r
 * }\r
 * ```\r
 *\r
 * _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._\r
 * _Available since v4.9 for `string`, `bytes`._\r
 */\r
library StorageSlotUpgradeable {\r
    struct AddressSlot {\r
        address value;\r
    }\r
\r
    struct BooleanSlot {\r
        bool value;\r
    }\r
\r
    struct Bytes32Slot {\r
        bytes32 value;\r
    }\r
\r
    struct Uint256Slot {\r
        uint256 value;\r
    }\r
\r
    struct StringSlot {\r
        string value;\r
    }\r
\r
    struct BytesSlot {\r
        bytes value;\r
    }\r
\r
    /**\r
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.\r
     */\r
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\r
        /// @solidity memory-safe-assembly\r
        assembly {\r
            r.slot := slot\r
        }\r
    }\r
\r
    /**\r
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.\r
     */\r
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\r
        /// @solidity memory-safe-assembly\r
        assembly {\r
            r.slot := slot\r
        }\r
    }\r
\r
    /**\r
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.\r
     */\r
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\r
        /// @solidity memory-safe-assembly\r
        assembly {\r
            r.slot := slot\r
        }\r
    }\r
\r
    /**\r
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.\r
     */\r
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\r
        /// @solidity memory-safe-assembly\r
        assembly {\r
            r.slot := slot\r
        }\r
    }\r
\r
    /**\r
     * @dev Returns an `StringSlot` with member `value` located at `slot`.\r
     */\r
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {\r
        /// @solidity memory-safe-assembly\r
        assembly {\r
            r.slot := slot\r
        }\r
    }\r
\r
    /**\r
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.\r
     */\r
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {\r
        /// @solidity memory-safe-assembly\r
        assembly {\r
            r.slot := store.slot\r
        }\r
    }\r
\r
    /**\r
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.\r
     */\r
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {\r
        /// @solidity memory-safe-assembly\r
        assembly {\r
            r.slot := slot\r
        }\r
    }\r
\r
    /**\r
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.\r
     */\r
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {\r
        /// @solidity memory-safe-assembly\r
        assembly {\r
            r.slot := store.slot\r
        }\r
    }\r
}\r
\r
/**\r
 * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.\r
 *\r
 * _Available since v4.8.3._\r
 */\r
interface IERC1967Upgradeable {\r
    /**\r
     * @dev Emitted when the implementation is upgraded.\r
     */\r
    event Upgraded(address indexed implementation);\r
\r
    /**\r
     * @dev Emitted when the admin account has changed.\r
     */\r
    event AdminChanged(address previousAdmin, address newAdmin);\r
\r
    /**\r
     * @dev Emitted when the beacon is changed.\r
     */\r
    event BeaconUpgraded(address indexed beacon);\r
}\r
\r
/**\r
 * @dev This is the interface that {BeaconProxy} expects of its beacon.\r
 */\r
interface IBeaconUpgradeable {\r
    /**\r
     * @dev Must return an address that can be used as a delegate call target.\r
     *\r
     * {BeaconProxy} will check that this address is a contract.\r
     */\r
    function implementation() external view returns (address);\r
}\r
\r
/**\r
 * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified\r
 * proxy whose upgrades are fully controlled by the current implementation.\r
 */\r
interface IERC1822ProxiableUpgradeable {\r
    /**\r
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation\r
     * address.\r
     *\r
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks\r
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this\r
     * function revert if invoked through a proxy.\r
     */\r
    function proxiableUUID() external view returns (bytes32);\r
}\r
\r
/**\r
 * @dev Collection of functions related to the address type\r
 */\r
library AddressUpgradeable {\r
    /**\r
     * @dev Returns true if `account` is a contract.\r
     *\r
     * [IMPORTANT]\r
     * ====\r
     * It is unsafe to assume that an address for which this function returns\r
     * false is an externally-owned account (EOA) and not a contract.\r
     *\r
     * Among others, `isContract` will return false for the following\r
     * types of addresses:\r
     *\r
     *  - an externally-owned account\r
     *  - a contract in construction\r
     *  - an address where a contract will be created\r
     *  - an address where a contract lived, but was destroyed\r
     *\r
     * Furthermore, `isContract` will also return true if the target contract within\r
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\r
     * which only has an effect at the end of a transaction.\r
     * ====\r
     *\r
     * [IMPORTANT]\r
     * ====\r
     * You shouldn't rely on `isContract` to protect against flash loan attacks!\r
     *\r
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\r
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\r
     * constructor.\r
     * ====\r
     */\r
    function isContract(address account) internal view returns (bool) {\r
        // This method relies on extcodesize/address.code.length, which returns 0\r
        // for contracts in construction, since the code is only stored at the end\r
        // of the constructor execution.\r
\r
        return account.code.length > 0;\r
    }\r
\r
    /**\r
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\r
     * `recipient`, forwarding all available gas and reverting on errors.\r
     *\r
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\r
     * of certain opcodes, possibly making contracts go over the 2300 gas limit\r
     * imposed by `transfer`, making them unable to receive funds via\r
     * `transfer`. {sendValue} removes this limitation.\r
     *\r
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\r
     *\r
     * IMPORTANT: because control is transferred to `recipient`, care must be\r
     * taken to not create reentrancy vulnerabilities. Consider using\r
     * {ReentrancyGuard} or the\r
     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\r
     */\r
    function sendValue(address payable recipient, uint256 amount) internal {\r
        require(address(this).balance >= amount, "Address: insufficient balance");\r
\r
        (bool success, ) = recipient.call{value: amount}("");\r
        require(success, "Address: unable to send value, recipient may have reverted");\r
    }\r
\r
    /**\r
     * @dev Performs a Solidity function call using a low level `call`. A\r
     * plain `call` is an unsafe replacement for a function call: use this\r
     * function instead.\r
     *\r
     * If `target` reverts with a revert reason, it is bubbled up by this\r
     * function (like regular Solidity function calls).\r
     *\r
     * Returns the raw returned data. To convert to the expected return value,\r
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\r
     *\r
     * Requirements:\r
     *\r
     * - `target` must be a contract.\r
     * - calling `target` with `data` must not revert.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\r
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\r
     * `errorMessage` as a fallback revert reason when `target` reverts.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCall(\r
        address target,\r
        bytes memory data,\r
        string memory errorMessage\r
    ) internal returns (bytes memory) {\r
        return functionCallWithValue(target, data, 0, errorMessage);\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r
     * but also transferring `value` wei to `target`.\r
     *\r
     * Requirements:\r
     *\r
     * - the calling contract must have an ETH balance of at least `value`.\r
     * - the called Solidity function must be `payable`.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\r
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\r
     * with `errorMessage` as a fallback revert reason when `target` reverts.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCallWithValue(\r
        address target,\r
        bytes memory data,\r
        uint256 value,\r
        string memory errorMessage\r
    ) internal returns (bytes memory) {\r
        require(address(this).balance >= value, "Address: insufficient balance for call");\r
        (bool success, bytes memory returndata) = target.call{value: value}(data);\r
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r
     * but performing a static call.\r
     *\r
     * _Available since v3.3._\r
     */\r
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\r
        return functionStaticCall(target, data, "Address: low-level static call failed");\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r
     * but performing a static call.\r
     *\r
     * _Available since v3.3._\r
     */\r
    function functionStaticCall(\r
        address target,\r
        bytes memory data,\r
        string memory errorMessage\r
    ) internal view returns (bytes memory) {\r
        (bool success, bytes memory returndata) = target.staticcall(data);\r
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r
     * but performing a delegate call.\r
     *\r
     * _Available since v3.4._\r
     */\r
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\r
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r
     * but performing a delegate call.\r
     *\r
     * _Available since v3.4._\r
     */\r
    function functionDelegateCall(\r
        address target,\r
        bytes memory data,\r
        string memory errorMessage\r
    ) internal returns (bytes memory) {\r
        (bool success, bytes memory returndata) = target.delegatecall(data);\r
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\r
    }\r
\r
    /**\r
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\r
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\r
     *\r
     * _Available since v4.8._\r
     */\r
    function verifyCallResultFromTarget(\r
        address target,\r
        bool success,\r
        bytes memory returndata,\r
        string memory errorMessage\r
    ) internal view returns (bytes memory) {\r
        if (success) {\r
            if (returndata.length == 0) {\r
                // only check isContract if the call was successful and the return data is empty\r
                // otherwise we already know that it was a contract\r
                require(isContract(target), "Address: call to non-contract");\r
            }\r
            return returndata;\r
        } else {\r
            _revert(returndata, errorMessage);\r
        }\r
    }\r
\r
    /**\r
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\r
     * revert reason or using the provided one.\r
     *\r
     * _Available since v4.3._\r
     */\r
    function verifyCallResult(\r
        bool success,\r
        bytes memory returndata,\r
        string memory errorMessage\r
    ) internal pure returns (bytes memory) {\r
        if (success) {\r
            return returndata;\r
        } else {\r
            _revert(returndata, errorMessage);\r
        }\r
    }\r
\r
    function _revert(bytes memory returndata, string memory errorMessage) private pure {\r
        // Look for revert reason and bubble it up if present\r
        if (returndata.length > 0) {\r
            // The easiest way to bubble the revert reason is using memory via assembly\r
            /// @solidity memory-safe-assembly\r
            assembly {\r
                let returndata_size := mload(returndata)\r
                revert(add(32, returndata), returndata_size)\r
            }\r
        } else {\r
            revert(errorMessage);\r
        }\r
    }\r
}\r
\r
\r
/**\r
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\r
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's constant to move constructor logic to an\r
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\r
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\r
 *\r
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\r
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in\r
 * case an upgrade adds a module that needs to be initialized.\r
 *\r
 * For example:\r
 *\r
 * [.hljs-theme-light.nopadding]\r
 * ```solidity\r
 * contract nft.sol is ERC20Upgradeable {\r
 *     function initialize() initializer public {\r
 *         __ERC20_init("nft.sol", "MTK");\r
 *     }\r
 * }\r
 *\r
 * contract MyTokenV2 is nft.sol, ERC20PermitUpgradeable {\r
 *     function initializeV2() reinitializer(2) public {\r
 *         __ERC20Permit_init("nft.sol");\r
 *     }\r
 * }\r
 * ```\r
 *\r
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\r
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\r
 *\r
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\r
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\r
 *\r
 * [CAUTION]\r
 * ====\r
 * Avoid leaving a contract uninitialized.\r
 *\r
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\r
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\r
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\r
 *\r
 * [.hljs-theme-light.nopadding]\r
 * ```\r
 * /// @custom:oz-upgrades-unsafe-allow constructor\r
 * constructor() {\r
 *     _disableInitializers();\r
 * }\r
 * ```\r
 * ====\r
 */\r
abstract contract Initializable {\r
    /**\r
     * @dev Indicates that the contract has been initialized.\r
     * @custom:oz-retyped-from bool\r
     */\r
    uint8 private _initialized;\r
\r
    /**\r
     * @dev Indicates that the contract is in the process of being initialized.\r
     */\r
    bool private _initializing;\r
\r
    /**\r
     * @dev Triggered when the contract has been initialized or reinitialized.\r
     */\r
    event Initialized(uint8 version);\r
\r
    /**\r
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\r
     * `onlyInitializing` functions can be used to initialize parent contracts.\r
     *\r
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\r
     * constructor.\r
     *\r
     * Emits an {Initialized} event.\r
     */\r
    modifier initializer() {\r
        bool isTopLevelCall = !_initializing;\r
        require(\r
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),\r
            "Initializable: contract is already initialized"\r
        );\r
        _initialized = 1;\r
        if (isTopLevelCall) {\r
            _initializing = true;\r
        }\r
        _;\r
        if (isTopLevelCall) {\r
            _initializing = false;\r
            emit Initialized(1);\r
        }\r
    }\r
\r
    /**\r
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\r
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\r
     * used to initialize parent contracts.\r
     *\r
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\r
     * are added through upgrades and that require initialization.\r
     *\r
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\r
     * cannot be nested. If one is invoked in the context of another, execution will revert.\r
     *\r
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\r
     * a contract, executing them in the right order is up to the developer or operator.\r
     *\r
     * WARNING: setting the version to 255 will prevent any future reinitialization.\r
     *\r
     * Emits an {Initialized} event.\r
     */\r
    modifier reinitializer(uint8 version) {\r
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");\r
        _initialized = version;\r
        _initializing = true;\r
        _;\r
        _initializing = false;\r
        emit Initialized(version);\r
    }\r
\r
    /**\r
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\r
     * {initializer} and {reinitializer} modifiers, directly or indirectly.\r
     */\r
    modifier onlyInitializing() {\r
        require(_initializing, "Initializable: contract is not initializing");\r
        _;\r
    }\r
\r
    /**\r
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\r
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\r
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\r
     * through proxies.\r
     *\r
     * Emits an {Initialized} event the first time it is successfully executed.\r
     */\r
    function _disableInitializers() internal virtual {\r
        require(!_initializing, "Initializable: contract is initializing");\r
        if (_initialized != type(uint8).max) {\r
            _initialized = type(uint8).max;\r
            emit Initialized(type(uint8).max);\r
        }\r
    }\r
\r
    /**\r
     * @dev Returns the highest version that has been initialized. See {reinitializer}.\r
     */\r
    function _getInitializedVersion() internal view returns (uint8) {\r
        return _initialized;\r
    }\r
\r
    /**\r
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\r
     */\r
    function _isInitializing() internal view returns (bool) {\r
        return _initializing;\r
    }\r
}\r
\r
\r
/**\r
 * @dev This abstract contract provides getters and event emitting update functions for\r
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.\r
 *\r
 * _Available since v4.1._\r
 */\r
abstract contract ERC1967UpgradeUpgradeable is Initializable, IERC1967Upgradeable {\r
    function __ERC1967Upgrade_init() internal onlyInitializing {\r
    }\r
\r
    function __ERC1967Upgrade_init_unchained() internal onlyInitializing {\r
    }\r
    // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1\r
    bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;\r
\r
    /**\r
     * @dev Storage slot with the address of the current implementation.\r
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is\r
     * validated in the constructor.\r
     */\r
    bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\r
\r
    /**\r
     * @dev Returns the current implementation address.\r
     */\r
    function _getImplementation() internal view returns (address) {\r
        return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;\r
    }\r
\r
    /**\r
     * @dev Stores a new address in the EIP1967 implementation slot.\r
     */\r
    function _setImplementation(address newImplementation) private {\r
        require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract");\r
        StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\r
    }\r
\r
    /**\r
     * @dev Perform implementation upgrade\r
     *\r
     * Emits an {Upgraded} event.\r
     */\r
    function _upgradeTo(address newImplementation) internal {\r
        _setImplementation(newImplementation);\r
        emit Upgraded(newImplementation);\r
    }\r
\r
    /**\r
     * @dev Perform implementation upgrade with additional setup call.\r
     *\r
     * Emits an {Upgraded} event.\r
     */\r
    function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {\r
        _upgradeTo(newImplementation);\r
        if (data.length > 0 || forceCall) {\r
            AddressUpgradeable.functionDelegateCall(newImplementation, data);\r
        }\r
    }\r
\r
    /**\r
     * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.\r
     *\r
     * Emits an {Upgraded} event.\r
     */\r
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {\r
        // Upgrades from old implementations will perform a rollback test. This test requires the new\r
        // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing\r
        // this special case will break upgrade paths from old UUPS implementation to new ones.\r
        if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {\r
            _setImplementation(newImplementation);\r
        } else {\r
            try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {\r
                require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");\r
            } catch {\r
                revert("ERC1967Upgrade: new implementation is not UUPS");\r
            }\r
            _upgradeToAndCall(newImplementation, data, forceCall);\r
        }\r
    }\r
\r
    /**\r
     * @dev Storage slot with the admin of the contract.\r
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is\r
     * validated in the constructor.\r
     */\r
    bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;\r
\r
    /**\r
     * @dev Returns the current admin.\r
     */\r
    function _getAdmin() internal view returns (address) {\r
        return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;\r
    }\r
\r
    /**\r
     * @dev Stores a new address in the EIP1967 admin slot.\r
     */\r
    function _setAdmin(address newAdmin) private {\r
        require(newAdmin != address(0), "ERC1967: new admin is the zero address");\r
        StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;\r
    }\r
\r
    /**\r
     * @dev Changes the admin of the proxy.\r
     *\r
     * Emits an {AdminChanged} event.\r
     */\r
    function _changeAdmin(address newAdmin) internal {\r
        emit AdminChanged(_getAdmin(), newAdmin);\r
        _setAdmin(newAdmin);\r
    }\r
\r
    /**\r
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.\r
     * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.\r
     */\r
    bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;\r
\r
    /**\r
     * @dev Returns the current beacon.\r
     */\r
    function _getBeacon() internal view returns (address) {\r
        return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;\r
    }\r
\r
    /**\r
     * @dev Stores a new beacon in the EIP1967 beacon slot.\r
     */\r
    function _setBeacon(address newBeacon) private {\r
        require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract");\r
        require(\r
            AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),\r
            "ERC1967: beacon implementation is not a contract"\r
        );\r
        StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;\r
    }\r
\r
    /**\r
     * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does\r
     * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).\r
     *\r
     * Emits a {BeaconUpgraded} event.\r
     */\r
    function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {\r
        _setBeacon(newBeacon);\r
        emit BeaconUpgraded(newBeacon);\r
        if (data.length > 0 || forceCall) {\r
            AddressUpgradeable.functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data);\r
        }\r
    }\r
\r
    /**\r
     * @dev This empty reserved space is put in place to allow future versions to add new\r
     * variables without shifting down storage in the inheritance chain.\r
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\r
     */\r
    uint256[50] private __gap;\r
}\r
\r
\r
/**\r
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an\r
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.\r
 *\r
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is\r
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing\r
 * `UUPSUpgradeable` with a custom implementation of upgrades.\r
 *\r
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.\r
 *\r
 * _Available since v4.1._\r
 */\r
abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {\r
    function __UUPSUpgradeable_init() internal onlyInitializing {\r
    }\r
\r
    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {\r
    }\r
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment\r
    address private immutable __self = address(this);\r
\r
    /**\r
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is\r
     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case\r
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a\r
     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to\r
     * fail.\r
     */\r
    modifier onlyProxy() {\r
        require(address(this) != __self, "Function must be called through delegatecall");\r
        require(_getImplementation() == __self, "Function must be called through active proxy");\r
        _;\r
    }\r
\r
    /**\r
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be\r
     * callable on the implementing contract but not through proxies.\r
     */\r
    modifier notDelegated() {\r
        require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");\r
        _;\r
    }\r
\r
    /**\r
     * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the\r
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.\r
     *\r
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks\r
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this\r
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.\r
     */\r
    function proxiableUUID() external view virtual override notDelegated returns (bytes32) {\r
        return _IMPLEMENTATION_SLOT;\r
    }\r
\r
    /**\r
     * @dev Upgrade the implementation of the proxy to `newImplementation`.\r
     *\r
     * Calls {_authorizeUpgrade}.\r
     *\r
     * Emits an {Upgraded} event.\r
     *\r
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall\r
     */\r
    function upgradeTo(address newImplementation) public virtual onlyProxy {\r
        _authorizeUpgrade(newImplementation);\r
        _upgradeToAndCallUUPS(newImplementation, new bytes(0), false);\r
    }\r
\r
    /**\r
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call\r
     * encoded in `data`.\r
     *\r
     * Calls {_authorizeUpgrade}.\r
     *\r
     * Emits an {Upgraded} event.\r
     *\r
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall\r
     */\r
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {\r
        _authorizeUpgrade(newImplementation);\r
        _upgradeToAndCallUUPS(newImplementation, data, true);\r
    }\r
\r
    /**\r
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by\r
     * {upgradeTo} and {upgradeToAndCall}.\r
     *\r
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.\r
     *\r
     * ```solidity\r
     * function _authorizeUpgrade(address) internal override onlyOwner {}\r
     * ```\r
     */\r
    function _authorizeUpgrade(address newImplementation) internal virtual;\r
\r
    /**\r
     * @dev This empty reserved space is put in place to allow future versions to add new\r
     * variables without shifting down storage in the inheritance chain.\r
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\r
     */\r
    uint256[50] private __gap;\r
}\r
\r
\r
/**\r
 * @dev Contract module that helps prevent reentrant calls to a function.\r
 *\r
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\r
 * available, which can be applied to functions to make sure there are no nested\r
 * (reentrant) calls to them.\r
 *\r
 * Note that because there is a single `nonReentrant` guard, functions marked as\r
 * `nonReentrant` may not call one another. This can be worked around by making\r
 * those functions `private`, and then adding `external` `nonReentrant` entry\r
 * points to them.\r
 *\r
 * TIP: If you would like to learn more about reentrancy and alternative ways\r
 * to protect against it, check out our blog post\r
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\r
 */\r
abstract contract ReentrancyGuard {\r
    // Booleans are more expensive than uint256 or any type that takes up a full\r
    // word because each write operation emits an extra SLOAD to first read the\r
    // slot's contents, replace the bits taken up by the boolean, and then write\r
    // back. This is the compiler's defense against contract upgrades and\r
    // pointer aliasing, and it cannot be disabled.\r
\r
    // The values being non-zero value makes deployment a bit more expensive,\r
    // but in exchange the refund on every call to nonReentrant will be lower in\r
    // amount. Since refunds are capped to a percentage of the total\r
    // transaction's gas, it is best to keep them low in cases like this one, to\r
    // increase the likelihood of the full refund coming into effect.\r
    uint256 private constant _NOT_ENTERED = 1;\r
    uint256 private constant _ENTERED = 2;\r
\r
    uint256 private _status;\r
\r
    constructor() {\r
        _status = _NOT_ENTERED;\r
    }\r
\r
    /**\r
     * @dev Prevents a contract from calling itself, directly or indirectly.\r
     * Calling a `nonReentrant` function from another `nonReentrant`\r
     * function is not supported. It is possible to prevent this from happening\r
     * by making the `nonReentrant` function external, and making it call a\r
     * `private` function that does the actual work.\r
     */\r
    modifier nonReentrant() {\r
        _nonReentrantBefore();\r
        _;\r
        _nonReentrantAfter();\r
    }\r
\r
    function _nonReentrantBefore() private {\r
        // On the first call to nonReentrant, _status will be _NOT_ENTERED\r
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");\r
\r
        // Any calls to nonReentrant after this point will fail\r
        _status = _ENTERED;\r
    }\r
\r
    function _nonReentrantAfter() private {\r
        // By storing the original value once again, a refund is triggered (see\r
        // https://eips.ethereum.org/EIPS/eip-2200)\r
        _status = _NOT_ENTERED;\r
    }\r
\r
    /**\r
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a\r
     * `nonReentrant` function in the call stack.\r
     */\r
    function _reentrancyGuardEntered() internal view returns (bool) {\r
        return _status == _ENTERED;\r
    }\r
}\r
\r
/**\r
 * @dev Collection of functions related to the address type\r
 */\r
library Address {\r
    /**\r
     * @dev Returns true if `account` is a contract.\r
     *\r
     * [IMPORTANT]\r
     * ====\r
     * It is unsafe to assume that an address for which this function returns\r
     * false is an externally-owned account (EOA) and not a contract.\r
     *\r
     * Among others, `isContract` will return false for the following\r
     * types of addresses:\r
     *\r
     *  - an externally-owned account\r
     *  - a contract in construction\r
     *  - an address where a contract will be created\r
     *  - an address where a contract lived, but was destroyed\r
     *\r
     * Furthermore, `isContract` will also return true if the target contract within\r
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\r
     * which only has an effect at the end of a transaction.\r
     * ====\r
     *\r
     * [IMPORTANT]\r
     * ====\r
     * You shouldn't rely on `isContract` to protect against flash loan attacks!\r
     *\r
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\r
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\r
     * constructor.\r
     * ====\r
     */\r
    function isContract(address account) internal view returns (bool) {\r
        // This method relies on extcodesize/address.code.length, which returns 0\r
        // for contracts in construction, since the code is only stored at the end\r
        // of the constructor execution.\r
\r
        return account.code.length > 0;\r
    }\r
\r
    /**\r
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\r
     * `recipient`, forwarding all available gas and reverting on errors.\r
     *\r
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\r
     * of certain opcodes, possibly making contracts go over the 2300 gas limit\r
     * imposed by `transfer`, making them unable to receive funds via\r
     * `transfer`. {sendValue} removes this limitation.\r
     *\r
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\r
     *\r
     * IMPORTANT: because control is transferred to `recipient`, care must be\r
     * taken to not create reentrancy vulnerabilities. Consider using\r
     * {ReentrancyGuard} or the\r
     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\r
     */\r
    function sendValue(address payable recipient, uint256 amount) internal {\r
        require(address(this).balance >= amount, "Address: insufficient balance");\r
\r
        (bool success, ) = recipient.call{value: amount}("");\r
        require(success, "Address: unable to send value, recipient may have reverted");\r
    }\r
\r
    /**\r
     * @dev Performs a Solidity function call using a low level `call`. A\r
     * plain `call` is an unsafe replacement for a function call: use this\r
     * function instead.\r
     *\r
     * If `target` reverts with a revert reason, it is bubbled up by this\r
     * function (like regular Solidity function calls).\r
     *\r
     * Returns the raw returned data. To convert to the expected return value,\r
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\r
     *\r
     * Requirements:\r
     *\r
     * - `target` must be a contract.\r
     * - calling `target` with `data` must not revert.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\r
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\r
     * `errorMessage` as a fallback revert reason when `target` reverts.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCall(\r
        address target,\r
        bytes memory data,\r
        string memory errorMessage\r
    ) internal returns (bytes memory) {\r
        return functionCallWithValue(target, data, 0, errorMessage);\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r
     * but also transferring `value` wei to `target`.\r
     *\r
     * Requirements:\r
     *\r
     * - the calling contract must have an ETH balance of at least `value`.\r
     * - the called Solidity function must be `payable`.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\r
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\r
     * with `errorMessage` as a fallback revert reason when `target` reverts.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCallWithValue(\r
        address target,\r
        bytes memory data,\r
        uint256 value,\r
        string memory errorMessage\r
    ) internal returns (bytes memory) {\r
        require(address(this).balance >= value, "Address: insufficient balance for call");\r
        (bool success, bytes memory returndata) = target.call{value: value}(data);\r
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r
     * but performing a static call.\r
     *\r
     * _Available since v3.3._\r
     */\r
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\r
        return functionStaticCall(target, data, "Address: low-level static call failed");\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r
     * but performing a static call.\r
     *\r
     * _Available since v3.3._\r
     */\r
    function functionStaticCall(\r
        address target,\r
        bytes memory data,\r
        string memory errorMessage\r
    ) internal view returns (bytes memory) {\r
        (bool success, bytes memory returndata) = target.staticcall(data);\r
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r
     * but performing a delegate call.\r
     *\r
     * _Available since v3.4._\r
     */\r
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\r
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r
     * but performing a delegate call.\r
     *\r
     * _Available since v3.4._\r
     */\r
    function functionDelegateCall(\r
        address target,\r
        bytes memory data,\r
        string memory errorMessage\r
    ) internal returns (bytes memory) {\r
        (bool success, bytes memory returndata) = target.delegatecall(data);\r
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\r
    }\r
\r
    /**\r
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\r
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\r
     *\r
     * _Available since v4.8._\r
     */\r
    function verifyCallResultFromTarget(\r
        address target,\r
        bool success,\r
        bytes memory returndata,\r
        string memory errorMessage\r
    ) internal view returns (bytes memory) {\r
        if (success) {\r
            if (returndata.length == 0) {\r
                // only check isContract if the call was successful and the return data is empty\r
                // otherwise we already know that it was a contract\r
                require(isContract(target), "Address: call to non-contract");\r
            }\r
            return returndata;\r
        } else {\r
            _revert(returndata, errorMessage);\r
        }\r
    }\r
\r
    /**\r
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\r
     * revert reason or using the provided one.\r
     *\r
     * _Available since v4.3._\r
     */\r
    function verifyCallResult(\r
        bool success,\r
        bytes memory returndata,\r
        string memory errorMessage\r
    ) internal pure returns (bytes memory) {\r
        if (success) {\r
            return returndata;\r
        } else {\r
            _revert(returndata, errorMessage);\r
        }\r
    }\r
\r
    function _revert(bytes memory returndata, string memory errorMessage) private pure {\r
        // Look for revert reason and bubble it up if present\r
        if (returndata.length > 0) {\r
            // The easiest way to bubble the revert reason is using memory via assembly\r
            /// @solidity memory-safe-assembly\r
            assembly {\r
                let returndata_size := mload(returndata)\r
                revert(add(32, returndata), returndata_size)\r
            }\r
        } else {\r
            revert(errorMessage);\r
        }\r
    }\r
}\r
\r
interface IDxpoolStakingFeePoolV2 {\r
    event ValidatorEntered(bytes validatorPubkey, address depositorAddress, uint256 ts);\r
    event ValidatorLeft(bytes validatorPubkey, address depositorAddress, uint256 ts);\r
    event ValidatorRewardClaimed(address depositorAddress, address withdrawAddress, uint256 rewardAmount);\r
    event ValidatorTransferred(bytes indexed validatorPubkey, address indexed from, address indexed to, uint256 ts);\r
    event OperatorChanged(address newOperator);\r
    event CommissionFeeRateChanged(uint256 newFeeRate);\r
    event CommissionClaimed(address withdrawAddress, uint256 collectedAmount);\r
\r
    // Only operation can do those operations\r
\r
    /**\r
     * @notice Add a validator to the pool\r
     * @dev operatorOnly.\r
     */\r
    function enterPool(bytes calldata validatorPubKey, address depositor, uint256 effectiveBalance) external;\r
\r
    /**\r
     * @notice Remove a validator from the pool\r
     * @dev operatorOnly.\r
     */\r
    function leavePool(bytes calldata validatorPubKey) external;\r
\r
    /**\r
     * @notice Add many validators to the pool\r
     * @dev operatorOnly.\r
     */\r
    function batchEnterPool(bytes calldata validatorPubKeys, address[] calldata depositorAddresses, uint256[] calldata effectiveBalances) external;\r
\r
    /**\r
     * @notice Remove many validators from the pool\r
     * @dev operatorOnly.\r
     */\r
    function batchLeavePool(bytes calldata validatorPubKeys) external;\r
\r
    /**\r
     * @notice Update validator shares\r
     * @dev operatorOnly.\r
     */\r
    function updateValidatorShares(bytes[] calldata validatorPubKeys, uint128[] calldata effectiveBalances) external;\r
\r
    // Only admin can do those operations\r
\r
    /**\r
     * @notice Set the contract commission fee rate\r
     * @dev adminOnly.\r
     */\r
    function setStakeCommissionFeeRate(uint256 stakeCommissionFeeRate) external;\r
\r
    /**\r
     * @notice Claim commission fees up to `amount`.\r
     * @dev adminOnly.\r
     */\r
    function claimStakeCommissionFee(address payable withdrawAddress, uint256 amount) external;\r
\r
    /**\r
     * @notice Change the contract operator\r
     * @dev adminOnly.\r
     */\r
    function changeOperator(address newOperator) external;\r
\r
    /**\r
     * @notice Disable withdrawal permission\r
     * @dev adminOnly.\r
     */\r
    function closePoolForWithdrawal() external;\r
\r
    /**\r
     * @notice Enable withdrawal permission\r
     * @dev adminOnly.\r
     */\r
    function openPoolForWithdrawal() external;\r
\r
    /**\r
     * @notice Transfer one or more validators to new fee pool owners.\r
     * @dev adminOnly.\r
     */\r
    function transferValidatorByAdmin(bytes calldata validatorPubKeys, address[] calldata toAddresses) external;\r
\r
    /**\r
     * @notice Admin function to help users recover funds from a lost or stolen wallet\r
     * @dev adminOnly.\r
     */\r
    function emergencyWithdraw(address[] calldata depositor, address[] calldata withdrawAddress, uint256 amount) external;\r
\r
\r
    /**\r
     * @notice Admin function to transfer balance into a cold wallet for safe.\r
     * @dev adminOnly.\r
     */\r
    function saveToColdWallet(address wallet, uint256 amount) external;\r
\r
    /**\r
     * @notice Admin function to transfer balance back from a cold wallet.\r
     * @dev adminOnly.\r
     */\r
    function loadFromColdWallet() external payable;\r
\r
    // EveryOne can use those functions\r
\r
    /**\r
     * @notice The amount of rewards a depositor can withdraw, and all rewards they have ever withdrawn\r
     */\r
    function getUserRewardInfo(address depositor) external view returns (uint256 totalRewards, uint256 unclaimedRewards, uint256 claimedRewards);\r
\r
    /**\r
     * @notice Allow a depositor (`msg.sender`) to collect their tip rewards from the pool.\r
     * @dev Emits an {ValidatorRewardCollected} event.\r
     */\r
    function claimReward(address payable withdrawAddress, uint256 amount) external;\r
\r
    /**\r
     * @notice The total shares in the pool\r
     */\r
    function getTotalShares() external view returns (uint256);\r
\r
    /**\r
     * @notice A summary of the pool's current state\r
     */\r
    function getPoolInfo() external view returns (\r
        uint256 lastRewardBlock,\r
        uint256 accRewardPerValidator,\r
        uint256 totalValidatorsCount,\r
        uint256 totalClaimedStakeCommissionFee,\r
        uint256 totalPaidToUserRewards,\r
        uint256 totalTransferredToColdWallet,\r
        bool isPoolOpenForWithdrawal\r
    );\r
\r
    /**\r
     * @notice A summary of the depositor's activity in the pool\r
     * @param user The depositor's address\r
     */\r
    function getUserInfo(address user) external view returns (\r
        uint256 validatorShares,\r
        uint256 totalReward,\r
        uint256 debit,\r
        uint256 claimedReward,\r
        uint256 lastCheckpoint\r
    );\r
\r
    /**\r
     * @notice A summary of pool stake commission fee\r
     */\r
    function getStakeCommissionFeeInfo() external view returns (\r
        uint256 totalStakeCommissionFee,\r
        uint256 unclaimedStakeCommissionFee,\r
        uint256 claimedStakeCommissionFee\r
    );\r
\r
    function justifyValidatorInPool(bytes calldata validatorPubKey) external view returns (\r
        bool inPool,\r
        uint64 shares,\r
        uint256 timestamp\r
    );\r
}\r
\r
// Storage Message\r
contract DxpoolStakingFeePoolStorage {\r
    // user struct\r
    struct DEPRECATED_UserInfo {\r
        uint128 validatorCount;\r
        uint128 totalReward;\r
        uint128 debit;\r
        uint128 claimedReward;\r
    }\r
\r
    // admin, operator address\r
    address internal adminAddress;\r
    address internal operatorAddress;\r
\r
    uint256 public totalClaimedStakeCommissionFee;\r
    uint256 public totalPaidToUserRewards;\r
    uint256 public totalTransferredToColdWallet;\r
\r
    uint256 internal totalShares;\r
    uint256 public   stakeCommissionFeeRate;\r
\r
    bool public isOpenForWithdrawal;\r
\r
    mapping(address => DEPRECATED_UserInfo) internal DEPRECATED_users;\r
    mapping(bytes => uint256) internal DEPRECATED_validatorOwnerAndJoinTime;\r
\r
    uint256 internal accRewardPerShare;\r
    uint256 internal accTotalStakeCommissionFee;\r
\r
    uint256 internal lastRewardBlock;\r
    uint256 internal lastPeriodReward;\r
}\r
\r
contract DxpoolStakingFeePoolStorageV2 {\r
    struct UserInfo {\r
        uint128 validatorShares;\r
        uint128 totalReward;\r
        uint128 debit;\r
        uint128 claimedReward;\r
        uint32  lastCheckpoint;\r
    }\r
\r
    mapping(address => UserInfo) internal users;\r
\r
    mapping(bytes32 => uint256) internal validatorHashedPubkeyToInfo;\r
}\r
\r
contract StakingFeePoolV2 is\r
IDxpoolStakingFeePoolV2,\r
DxpoolStakingFeePoolStorage,\r
Initializable,\r
UUPSUpgradeable,\r
ReentrancyGuard,\r
DxpoolStakingFeePoolStorageV2\r
{\r
    using Address for address payable;\r
\r
    uint64 constant SHARE_FRACTAL = 32e9;\r
\r
    uint256 constant PRECISION_FACTOR = 1e32;\r
\r
    uint256 constant COMMISSION_RATE_MAX = 1e4;\r
\r
    constructor() initializer {}\r
\r
    // initialize\r
    function initialize(address operatorAddress_, address adminAddress_) initializer external  {\r
        require(operatorAddress_ != address(0));\r
        require(adminAddress_ != address(0));\r
        adminAddress = adminAddress_;\r
        operatorAddress = operatorAddress_;\r
        totalShares = 0;\r
        stakeCommissionFeeRate = 2000;\r
        isOpenForWithdrawal = true;\r
\r
        accRewardPerShare = 0;\r
        accTotalStakeCommissionFee = 0;\r
        totalTransferredToColdWallet = 0;\r
        lastRewardBlock  = block.number;\r
        lastPeriodReward = getTotalRewards();\r
    }\r
\r
    function initialize_version_2() adminOnly external reinitializer(2) {\r
        accRewardPerShare *= 1e26;\r
\r
        accRewardPerShare /= SHARE_FRACTAL;\r
\r
        accTotalStakeCommissionFee *= 1e26;\r
    }\r
\r
    function migrateValidatorsFromV1(bytes[] calldata validatorPubKeys) external nonReentrant operatorOnly {\r
        // require(isOpenForWithdrawal == false, "Pool must be closed");\r
\r
        for (uint256 i = 0; i < validatorPubKeys.length; i++) {\r
            bytes memory pubKey = validatorPubKeys[i];\r
\r
            (address depositor, ,uint32 joinTime) = decodeValidatorInfo(DEPRECATED_validatorOwnerAndJoinTime[pubKey]);\r
            require(depositor != address(0), "Validator not in pool");\r
\r
            bytes32 hashedPubKey = hashValidatorPublicKey(pubKey);\r
            validatorHashedPubkeyToInfo[hashedPubKey] = encodeValidatorInfo(depositor, SHARE_FRACTAL, joinTime);\r
\r
            // delete old data\r
            delete DEPRECATED_validatorOwnerAndJoinTime[pubKey];\r
        }\r
    }\r
\r
\r
    function migrateUsersFromV1(address[] calldata userList) external nonReentrant operatorOnly {\r
        // require(isOpenForWithdrawal == false, "Pool must be closed");\r
\r
        for (uint256 i = 0; i < userList.length; i++) {\r
            address userAddress = userList[i];\r
\r
            // confirm exist user\r
            require(\r
                DEPRECATED_users[userAddress].validatorCount > 0 ||\r
                DEPRECATED_users[userAddress].totalReward > 0 ||\r
                DEPRECATED_users[userAddress].debit > 0 ||\r
                DEPRECATED_users[userAddress].claimedReward > 0,\r
                "User does not exist"\r
            );\r
\r
            // Copy user data\r
            users[userAddress].validatorShares = DEPRECATED_users[userAddress].validatorCount;\r
            users[userAddress].totalReward = DEPRECATED_users[userAddress].totalReward;\r
            users[userAddress].debit = DEPRECATED_users[userAddress].debit;\r
            users[userAddress].claimedReward = DEPRECATED_users[userAddress].claimedReward;\r
\r
            // initialize user lastCheckpoint\r
            users[userAddress].lastCheckpoint = uint32(block.timestamp);\r
\r
            totalShares -= users[userAddress].validatorShares;\r
            users[userAddress].validatorShares *= SHARE_FRACTAL;\r
            totalShares += users[userAddress].validatorShares;\r
\r
            // delete old user data\r
            delete DEPRECATED_users[userAddress];\r
        }\r
    }\r
\r
    function migrateFromV1Complete() external nonReentrant operatorOnly {\r
        // Update the reward calculations to reflect the new state after migration\r
        // This ensures all rewards are correctly accounted for in the new V4 format\r
        updatePool();\r
    }\r
\r
    // Only admin can update contract\r
    function _authorizeUpgrade(address) internal override adminOnly {}\r
\r
    // decode or encode validator information\r
    function decodeValidatorInfo(uint256 data) public pure returns (address, uint64, uint32) {\r
        address ownerAddress = address(uint160(data));\r
        uint64 shares = uint64((data >> 160) & ((1 << 64) - 1));\r
        uint32 joinPoolTimestamp = uint32(data >> 224);\r
        return (ownerAddress, shares, joinPoolTimestamp);\r
    }\r
\r
    function encodeValidatorInfo(address ownerAddress, uint64 shares, uint32 joinPoolTimestamp) public pure returns (uint256) {\r
        return uint256(uint160(ownerAddress)) | (uint256(shares) << 160) | uint256(joinPoolTimestamp) << 224;\r
    }\r
\r
    // get total rewards since contract created\r
    function getTotalRewards() public view returns (uint256) {\r
        return address(this).balance\r
        + totalTransferredToColdWallet\r
        + totalPaidToUserRewards\r
            + totalClaimedStakeCommissionFee;\r
    }\r
\r
    // get commission have earned from it\r
    function getAccStakeCommissionFee() public view returns (uint256) {\r
        uint256 currentPeriodReward = getTotalRewards();\r
\r
        return (\r
            accTotalStakeCommissionFee + PRECISION_FACTOR * (currentPeriodReward - lastPeriodReward)\r
        * stakeCommissionFeeRate / COMMISSION_RATE_MAX\r
        ) / PRECISION_FACTOR;\r
    }\r
\r
    // Compute a Reward by adding pending reward to user totalRewards\r
    function computeReward(address depositor) internal {\r
        uint256 userValidatorShares = users[depositor].validatorShares;\r
        if (userValidatorShares > 0) {\r
            uint256 pending = userValidatorShares * accRewardPerShare / PRECISION_FACTOR - users[depositor].debit;\r
            users[depositor].totalReward += uint128(pending);\r
        }\r
    }\r
\r
    function updatePool() internal {\r
        if (block.number <= lastRewardBlock || totalShares == 0) {\r
            return;\r
        }\r
\r
        uint256 currentPeriodReward = getTotalRewards();\r
\r
        accRewardPerShare += PRECISION_FACTOR * (currentPeriodReward - lastPeriodReward) / totalShares\r
            * (COMMISSION_RATE_MAX - stakeCommissionFeeRate) / COMMISSION_RATE_MAX;\r
\r
        accTotalStakeCommissionFee += PRECISION_FACTOR\r
            * (currentPeriodReward - lastPeriodReward) * stakeCommissionFeeRate / COMMISSION_RATE_MAX;\r
\r
        lastRewardBlock = block.number;\r
\r
        lastPeriodReward = currentPeriodReward;\r
    }\r
\r
    /**\r
    * Operator Functions\r
    */\r
    function enterPool(bytes calldata validatorPubKey, address depositor, uint256 effectiveBalance) external nonReentrant operatorOnly {\r
        // One validator joined, the previous time period ends.\r
        bytes32 hashedValidatorPubKey = hashValidatorPublicKey(validatorPubKey);\r
\r
        updatePool();\r
        _enterPool(hashedValidatorPubKey, depositor, effectiveBalance);\r
        emit ValidatorEntered(validatorPubKey, depositor, block.timestamp);\r
    }\r
\r
    function _enterPool(bytes32 hashedValidatorPubKey, address depositor, uint256 effectiveBalance) internal {\r
        require(validatorHashedPubkeyToInfo[hashedValidatorPubKey] == 0, "validator already in pool");\r
        require(depositor != address(0), "depositorAddress not be empty");\r
        require(effectiveBalance >= 32e9 && effectiveBalance <= 2048e9, "Effective balance must be between 32 and 2048 ether");\r
\r
        // compute reward\r
        computeReward(depositor);\r
\r
        users[depositor].validatorShares += uint64(effectiveBalance);\r
        totalShares += effectiveBalance;\r
        validatorHashedPubkeyToInfo[hashedValidatorPubKey] = encodeValidatorInfo(depositor, uint64(effectiveBalance), uint32(block.timestamp));\r
        users[depositor].debit = uint128(users[depositor].validatorShares * accRewardPerShare / PRECISION_FACTOR);\r
\r
        users[depositor].lastCheckpoint = uint32(block.timestamp);\r
    }\r
\r
    function leavePool(\r
        bytes calldata validatorPubKey\r
    ) external nonReentrant operatorOnly {\r
        bytes32 hashedValidatorPubKey = hashValidatorPublicKey(validatorPubKey);\r
        // One validator left, the previous time period ends.\r
        updatePool();\r
        address depositor = _leavePool(hashedValidatorPubKey);\r
        emit ValidatorLeft(validatorPubKey, depositor, block.timestamp);\r
    }\r
\r
    function _leavePool(\r
        bytes32 hashedValidatorPubKey\r
    ) internal returns (address depositorAddress) {\r
        (address depositor, uint64 shares, ) = decodeValidatorInfo(validatorHashedPubkeyToInfo[hashedValidatorPubKey]);\r
        require(depositor != address(0), "Validator not in pool");\r
\r
        computeReward(depositor);\r
\r
        totalShares -= shares;\r
        users[depositor].validatorShares -= shares;\r
        users[depositor].debit = uint128(users[depositor].validatorShares * accRewardPerShare / PRECISION_FACTOR);\r
\r
        delete validatorHashedPubkeyToInfo[hashedValidatorPubKey];\r
\r
        return depositor;\r
    }\r
\r
    function batchEnterPool(\r
        bytes calldata validatorPubkeyArray,\r
        address[] calldata depositorAddresses,\r
        uint256[] calldata effectiveBalances\r
    ) external nonReentrant operatorOnly {\r
        require(depositorAddresses.length == 1 || depositorAddresses.length * 48 == validatorPubkeyArray.length, "Invalid depositorAddresses length");\r
        require(effectiveBalances.length * 48 == validatorPubkeyArray.length, "Invalid balances length");\r
\r
        updatePool();\r
\r
        uint256 validatorCount = validatorPubkeyArray.length / 48;\r
        bytes32 hashedPubKey;\r
\r
        if (depositorAddresses.length == 1) {\r
            for(uint256 i = 0; i < validatorCount; i++) {\r
                hashedPubKey = hashValidatorPublicKey(validatorPubkeyArray[i*48:(i+1)*48]);\r
                _enterPool(hashedPubKey, depositorAddresses[0], effectiveBalances[i]);\r
                emit ValidatorEntered(validatorPubkeyArray[i*48:(i+1)*48], depositorAddresses[0], block.timestam

Tags:
Proxy, Staking, Upgradeable, Factory|addr:0xa151de4d73131e5f65570ab43e8338ca7b5fa131|verified:true|block:23388326|tx:0xa0c359b239c16f006b824c187ce03298a2829c4eec53aabe2fe553051d5d682e|first_check:1758191436

Submitted on: 2025-09-18 12:30:38

Comments

Log in to comment.

No comments yet.