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/L1Vault.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
import { AccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { ILRTDepositPool } from "contracts/interfaces/ILRTDepositPool.sol";
import { IRSETH } from "contracts/interfaces/IRSETH.sol";
import { IRSETH_OFTAdapter, SendParam, MessagingFee } from "contracts/interfaces/IRSETH_OFTAdapter.sol";
import { UtilLib } from "contracts/utils/UtilLib.sol";
import { IWETH } from "contracts/external/weth/IWETH.sol";
import { IWstETH } from "contracts/external/lido/IWstETH.sol";
/**
* @title L1Vault
* @notice This contract is the receiver of the ETH and LST token deposits from
* the L2 bridger. It will mint the rsETH tokens and send them to the RsETHTokenWrapper
* on the corresponding L2 chain after bridging. There should be exactly one L1Vault for
* each L2 chain.
*/
contract L1Vault is Initializable, ReentrancyGuardUpgradeable, AccessControlUpgradeable {
using SafeERC20 for IERC20;
/// @notice The address of the LRT deposit pool
ILRTDepositPool public lrtDepositPool;
/// @notice The address of the rsETH token
IRSETH public rsETH;
/// @notice The address of the RsETHTokenWrapper on the corresponding L2 chain
IRSETH_OFTAdapter public oftAdapter;
bytes32 public constant MANAGER_ROLE = keccak256("MANAGER_ROLE");
bytes32 public constant TIMELOCK_ROLE = keccak256("TIMELOCK_ROLE");
/// @notice The LayerZero ID of the corresponding L2 chain
uint32 public dstLzChainId;
/// @notice The address of the RsETHTokenWrapper on the corresponding L2 chain (intended target contract)
address public l2Receiver;
/// @notice Description to identify for which L2 chain this L1Vault contract is used
string public description;
/// @notice The identifier for ETH in the LRT deposit pool
address public constant ETH_IDENTIFIER = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
/// @notice The address of the wstETH token
address public wstETH;
/// @notice The address of the WETH token
address public constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
/// @notice Custom errors
error InvalidMinRSETHAmountExpected();
error InsufficientRsETHBalance();
error InvalidMinAmount();
error InvalidLzChainId();
error EmptyDescription();
error InsufficientNativeFee();
error NoWstETHBalance();
error NoWETHBalance();
/// @notice Events
event ETHDepositForL1Vault(uint256 depositAmount, uint256 rsethMintAmount);
event AssetDepositForL1Vault(address indexed asset, uint256 depositAmount, uint256 rsethMintAmount);
event BridgedRsETHToL2(uint32 lzChainId, address l2Receiver, uint256 amount, uint256 minAmount);
event LRTDepositPoolSet(address lrtDepositPool);
event RsETHSet(address rsETH);
event OFTAdapterSet(address oftAdapter);
event DstLzChainIdSet(uint32 dstLzChainId);
event L2ReceiverSet(address l2Receiver);
event DescriptionSet(string description);
event WstETHSet(address wstETH);
event WstETHUnwrapped(uint256 stETHAmount);
event WETHUnwrapped(uint256 wethAmount);
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
/**
* @dev Reinitializes the L1Vault contract
* @param _wstETH The address of the wstETH token
*/
function reinitialize(address _wstETH) external reinitializer(2) onlyRole(DEFAULT_ADMIN_ROLE) {
UtilLib.checkNonZeroAddress(_wstETH);
wstETH = _wstETH;
emit WstETHSet(_wstETH);
}
/**
* @dev Initializes the L1Vault contract
* @param _admin The address of the admin
* @param _manager The address of the manager
* @param _lrtDepositPool The address of the LRT deposit pool
* @param _rsETH The address of the rsETH token
* @param _oftAdapter The address of the OFT adapter
* @param _dstLzChainId The LayerZero ID of the corresponding L2 chain
* @param _l2Receiver The address of the RsETHTokenWrapper on the corresponding L2 chain
* @param _description The description to identify the L1Vault for which L2 chain
*/
function initialize(
address _admin,
address _manager,
address _lrtDepositPool,
address _rsETH,
address _oftAdapter,
uint32 _dstLzChainId,
address _l2Receiver,
string memory _description
)
external
initializer
{
UtilLib.checkNonZeroAddress(_lrtDepositPool);
UtilLib.checkNonZeroAddress(_rsETH);
UtilLib.checkNonZeroAddress(_admin);
UtilLib.checkNonZeroAddress(_manager);
UtilLib.checkNonZeroAddress(_oftAdapter);
UtilLib.checkNonZeroAddress(_l2Receiver);
if (_dstLzChainId == 0) {
revert InvalidLzChainId();
}
dstLzChainId = _dstLzChainId;
l2Receiver = _l2Receiver;
description = _description;
__ReentrancyGuard_init();
__AccessControl_init();
_setupRole(DEFAULT_ADMIN_ROLE, _admin);
_setupRole(MANAGER_ROLE, _manager);
lrtDepositPool = ILRTDepositPool(_lrtDepositPool);
rsETH = IRSETH(_rsETH);
oftAdapter = IRSETH_OFTAdapter(_oftAdapter);
}
/**
* @dev Call depositETH on LRTDepositPool to get rsETH from the ETH held within L1 vault
*/
function depositETHForL1VaultETH() external payable nonReentrant onlyRole(MANAGER_ROLE) {
uint256 balanceOfETH = address(this).balance;
uint256 rsETHAmountToMint = lrtDepositPool.getRsETHAmountToMint(ETH_IDENTIFIER, balanceOfETH);
if (rsETHAmountToMint == 0) {
revert InvalidMinRSETHAmountExpected();
}
lrtDepositPool.depositETH{ value: balanceOfETH }(rsETHAmountToMint, "");
emit ETHDepositForL1Vault(balanceOfETH, rsETHAmountToMint);
}
/**
* @dev Call depositAsset on LRTDepositPool to get rsETH from the LSTs held within L1 vault
*/
function depositAssetForL1Vault(address token) external nonReentrant onlyRole(MANAGER_ROLE) {
UtilLib.checkNonZeroAddress(token);
uint256 tokenBalance = IERC20(token).balanceOf(address(this));
uint256 rsETHAmountToMint = lrtDepositPool.getRsETHAmountToMint(token, tokenBalance);
if (rsETHAmountToMint == 0) {
revert InvalidMinRSETHAmountExpected();
}
// Approve the LRT deposit pool to transfer the token
IERC20(token).safeIncreaseAllowance(address(lrtDepositPool), tokenBalance);
lrtDepositPool.depositAsset(token, tokenBalance, rsETHAmountToMint, "");
emit AssetDepositForL1Vault(token, tokenBalance, rsETHAmountToMint);
}
/// @notice Unwrap wstETH to stETH to be able to mint rsETH
function unwrapWstETH() external nonReentrant onlyRole(MANAGER_ROLE) {
uint256 wstETHBalance = IERC20(wstETH).balanceOf(address(this));
if (wstETHBalance == 0) {
revert NoWstETHBalance();
}
// Unwrap wstETH to stETH
uint256 stETHAmount = IWstETH(wstETH).unwrap(wstETHBalance);
emit WstETHUnwrapped(stETHAmount);
}
/// @notice Unwrap WETH to ETH to be able to mint rsETH
function unwrapWETH() external nonReentrant onlyRole(MANAGER_ROLE) {
uint256 wethBalance = IERC20(WETH).balanceOf(address(this));
if (wethBalance == 0) {
revert NoWETHBalance();
}
// Unwrap WETH to ETH
IWETH(WETH).withdraw(wethBalance);
emit WETHUnwrapped(wethBalance);
}
/**
* @dev Bridge rsETH to L2
* @param amount The amount of rsETH to bridge
* @param minAmount The minimum amount of rsETH to receive on L2
* @param nativeFee The native fee to pay for the bridge
*/
function bridgeRsETHToL2(
uint256 amount,
uint256 minAmount,
uint256 nativeFee
)
external
payable
nonReentrant
onlyRole(MANAGER_ROLE)
{
if (rsETH.balanceOf(address(this)) < amount) {
revert InsufficientRsETHBalance();
}
if (minAmount > amount || minAmount == 0) {
revert InvalidMinAmount();
}
if (msg.value < nativeFee) {
revert InsufficientNativeFee();
}
IERC20(address(rsETH)).safeIncreaseAllowance(address(oftAdapter), amount);
SendParam memory sendParam = SendParam({
dstEid: dstLzChainId,
to: getReceiver(),
amountLD: amount,
minAmountLD: minAmount,
extraOptions: bytes(""),
composeMsg: bytes(""),
oftCmd: bytes("")
});
MessagingFee memory fee = MessagingFee({ nativeFee: nativeFee, lzTokenFee: 0 });
oftAdapter.send{ value: nativeFee }(sendParam, fee, msg.sender);
emit BridgedRsETHToL2(dstLzChainId, l2Receiver, amount, minAmount);
}
/**
* @dev Quote the native fee for sending rsETH to L2
* @param amount The amount of rsETH to send
* @param minAmount The minimum amount of rsETH to receive on L2
* @return The fee to be paid in native currency
*/
function getNativeFee(uint256 amount, uint256 minAmount) external view returns (uint256) {
if (minAmount > amount || minAmount == 0) {
revert InvalidMinAmount();
}
SendParam memory sendParam = SendParam({
dstEid: dstLzChainId,
to: getReceiver(),
amountLD: amount,
minAmountLD: minAmount,
extraOptions: bytes(""),
composeMsg: bytes(""),
oftCmd: bytes("")
});
MessagingFee memory fee = oftAdapter.quoteSend(sendParam, false);
return fee.nativeFee;
}
/**
* @dev Get the receiver address in the bytes32 format
* @return The receiver address in the bytes32 format
*/
function getReceiver() public view returns (bytes32) {
return bytes32(uint256(uint160(l2Receiver)));
}
/**
* @dev Set the LRT deposit pool address
* @param _lrtDepositPool The address of the LRT deposit pool
*/
function setLrtDepositPool(address _lrtDepositPool) external onlyRole(TIMELOCK_ROLE) {
UtilLib.checkNonZeroAddress(_lrtDepositPool);
lrtDepositPool = ILRTDepositPool(_lrtDepositPool);
emit LRTDepositPoolSet(_lrtDepositPool);
}
/**
* @dev Set the rsETH address
* @param _rsETH The address of the rsETH token
*/
function setRsETH(address _rsETH) external onlyRole(TIMELOCK_ROLE) {
UtilLib.checkNonZeroAddress(_rsETH);
rsETH = IRSETH(_rsETH);
emit RsETHSet(_rsETH);
}
/**
* @dev Set the OFT adapter address
* @param _oftAdapter The address of the OFT adapter
*/
function setOFTAdapter(address _oftAdapter) external onlyRole(TIMELOCK_ROLE) {
UtilLib.checkNonZeroAddress(_oftAdapter);
oftAdapter = IRSETH_OFTAdapter(_oftAdapter);
emit OFTAdapterSet(_oftAdapter);
}
/**
* @dev Sets the destination LayerZero chain ID
* @param _dstLzChainId The LayerZero chain ID of the corresponding L2 chain
*/
function setDstLzChainId(uint32 _dstLzChainId) external onlyRole(TIMELOCK_ROLE) {
if (_dstLzChainId == 0) {
revert InvalidLzChainId();
}
dstLzChainId = _dstLzChainId;
emit DstLzChainIdSet(_dstLzChainId);
}
/**
* @dev Sets the L2 receiver address
* @param _l2Receiver The address of the RsETHTokenWrapper on the corresponding L2 chain
*/
function setL2Receiver(address _l2Receiver) external onlyRole(TIMELOCK_ROLE) {
UtilLib.checkNonZeroAddress(_l2Receiver);
l2Receiver = _l2Receiver;
emit L2ReceiverSet(_l2Receiver);
}
/**
* @dev Sets the description of the L1Vault contract
* @param _description The description to identify the L1Vault for which L2 chain is used
*/
function setDescription(string calldata _description) external onlyRole(TIMELOCK_ROLE) {
if (bytes(_description).length == 0) {
revert EmptyDescription();
}
description = _description;
emit DescriptionSet(_description);
}
/**
* @dev Sets the wstETH address
* @param _wstETH The address of the wstETH token
*/
function setWstETH(address _wstETH) external onlyRole(TIMELOCK_ROLE) {
UtilLib.checkNonZeroAddress(_wstETH);
wstETH = _wstETH;
emit WstETHSet(_wstETH);
}
/// @dev Handles direct ETH transfers from the L2 bridge
receive() external payable { }
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControlUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../utils/StringsUpgradeable.sol";
import "../utils/introspection/ERC165Upgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
function __AccessControl_init() internal onlyInitializing {
}
function __AccessControl_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
StringsUpgradeable.toHexString(account),
" is missing role ",
StringsUpgradeable.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @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 Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 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 functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_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 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_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() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @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 {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/security/ReentrancyGuardUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
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;
uint256 private _status;
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
_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 {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// 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) {
return _status == _ENTERED;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
"
},
"lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 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 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.encodeWithSelector(token.transfer.selector, 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.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 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);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
* 0 before setting it to a non-zero value.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @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, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @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.isContract(address(token));
}
}
"
},
"contracts/interfaces/ILRTDepositPool.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
interface ILRTDepositPool {
//errors
error InvalidAmountToDeposit();
error NotEnoughAssetToTransfer();
error MaximumDepositLimitReached();
error MaximumNodeDelegatorLimitReached();
error InvalidMaximumNodeDelegatorLimit();
error MinimumAmountToReceiveNotMet();
error NodeDelegatorNotFound();
error NodeDelegatorHasAssetBalance(address assetAddress, uint256 assetBalance);
error NodeDelegatorHasETH();
error EthTransferFailed();
error NotEnoughETHToTransfer();
error ZeroAssetAmount();
error MinAssetAmountNotMet();
//events
event MaxNodeDelegatorLimitUpdated(uint256 maxNodeDelegatorLimit);
event NodeDelegatorAddedinQueue(address[] nodeDelegatorContracts);
event NodeDelegatorRemovedFromQueue(address nodeDelegatorContracts);
event AssetDeposit(
address indexed depositor,
address indexed asset,
uint256 depositAmount,
uint256 rsethMintAmount,
string referralId
);
event ETHDeposit(address indexed depositor, uint256 depositAmount, uint256 rsethMintAmount, string referralId);
event MinAmountToDepositUpdated(uint256 minAmountToDeposit);
event MaxNegligibleAmountUpdated(uint256 maxNegligibleAmount);
event ETHSwappedForLST(uint256 ethAmount, address indexed toAsset, uint256 returnAmount);
event AssetSwappedForETH(address indexed fromAsset, uint256 fromAssetAmount, uint256 returnAmount);
event EthTransferred(address to, uint256 amount);
event AssetStaked(address indexed asset, uint256 ethAmount, uint256 stETHShares);
// functions
function depositETH(uint256 minRSETHAmountExpected, string calldata referralId) external payable;
function depositAsset(
address asset,
uint256 depositAmount,
uint256 minRSETHAmountExpected,
string calldata referralId
)
external;
function getSwapETHToAssetReturnAmount(
address toAsset,
uint256 ethAmountToSend
)
external
view
returns (uint256 returnAmount);
function getTotalAssetDeposits(address asset) external view returns (uint256);
function getAssetCurrentLimit(address asset) external view returns (uint256);
function getRsETHAmountToMint(address asset, uint256 depositAmount) external view returns (uint256);
function addNodeDelegatorContractToQueue(address[] calldata nodeDelegatorContract) external;
function transferAssetToNodeDelegator(uint256 ndcIndex, address asset, uint256 amount) external;
function updateMaxNodeDelegatorLimit(uint256 maxNodeDelegatorLimit) external;
function getNodeDelegatorQueue() external view returns (address[] memory);
function getAssetDistributionData(address asset)
external
view
returns (
uint256 assetLyingInDepositPool,
uint256 assetLyingInNDCs,
uint256 assetStakedInEigenLayer,
uint256 assetUnstakingFromEigenLayer,
uint256 assetLyingInConverter,
uint256 assetLyingUnstakingVault
);
function getETHDistributionData()
external
view
returns (
uint256 ethLyingInDepositPool,
uint256 ethLyingInNDCs,
uint256 ethStakedInEigenLayer,
uint256 ethUnstakingFromEigenLayer,
uint256 ethLyingInConverter,
uint256 ethLyingInUnstakingVault
);
function isNodeDelegator(address nodeDelegatorContract) external view returns (uint256);
// receivers
function receiveFromRewardReceiver() external payable;
function receiveFromLRTConverter() external payable;
function receiveFromNodeDelegator() external payable;
}
"
},
"contracts/interfaces/IRSETH.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
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;
function pause() external;
function unpause() external;
}
"
},
"contracts/interfaces/IRSETH_OFTAdapter.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
/**
* @dev Struct representing token parameters for the OFT send() operation
*/
struct SendParam {
uint32 dstEid; // Destination endpoint ID.
bytes32 to; // Recipient address.
uint256 amountLD; // Amount to send in local decimals
uint256 minAmountLD; // Minimum amount to send in local decimals
bytes extraOptions; // Additional options supplied by the caller to be used in the LayerZero message
bytes composeMsg; // The composed message for the send() operation
bytes oftCmd; // The OFT command to be executed, unused in default OFT implementations
}
/**
* @dev Struct representing the messaging fee for the OFT send() operation
*/
struct MessagingFee {
uint256 nativeFee; // The fee to be paid in native currency
uint256 lzTokenFee; // The fee to be paid in ZRO tokens
}
/**
* @dev Struct representing messaging receipt information
*/
struct MessagingReceipt {
bytes32 guid; // The GUID of the message
uint64 nonce; // The nonce of the message
MessagingFee fee; // The fee paid for the message (native currency and LZ tokens)
}
/**
* @dev Struct representing OFT receipt information
*/
struct OFTReceipt {
uint256 amountSentLD; // Amount of tokens ACTUALLY debited from the sender in local decimals
uint256 amountReceivedLD; // Amount of tokens to be received on the remote side
}
/// @title RSETH OFT Adapter Interface
/// @notice Interface for the RSETH OFT (Omnichain Fungible Token) Adapter, which integrates with LayerZero protocol
interface IRSETH_OFTAdapter {
/// @notice Sends tokens to another chain
/// @dev This function handles the cross-chain token transfer
/// @param _sendParam Parameters for the send operation
/// @param _fee Messaging fee for the LayerZero protocol
/// @param _refundAddress Address to refund excess fees
/// @return msgReceipt Receipt of the messaging operation
/// @return oftReceipt Receipt of the OFT operation
function send(
SendParam calldata _sendParam,
MessagingFee calldata _fee,
address _refundAddress
)
external
payable
returns (MessagingReceipt memory msgReceipt, OFTReceipt memory oftReceipt);
/// @notice Quotes the fee for sending tokens to another chain
/// @dev This function estimates the fee without executing the transfer
/// @param _sendParam Parameters for the send operation
/// @param _payInLzToken Whether to pay the fee in LZ tokens
/// @return MessagingFee structure containing the estimated fees
function quoteSend(SendParam calldata _sendParam, bool _payInLzToken) external view returns (MessagingFee memory);
}
"
},
"contracts/utils/UtilLib.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
/// @title UtilLib - Utility library
/// @notice Utility functions
library UtilLib {
error ZeroAddressNotAllowed();
/// @dev zero address check modifier
/// @param address_ address to check
function checkNonZeroAddress(address address_) internal pure {
if (address_ == address(0)) revert ZeroAddressNotAllowed();
}
function getMin(uint256 a, uint256 b) internal pure returns (uint256) {
if (a < b) return a;
return b;
}
function getMax(uint256 a, uint256 b) internal pure returns (uint256) {
if (a > b) return a;
return b;
}
}
"
},
"contracts/external/weth/IWETH.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;
interface IWETH {
function deposit() external payable;
function transfer(address to, uint256 value) external returns (bool);
function withdraw(uint256) external;
}
"
},
"contracts/external/lido/IWstETH.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.27;
/**
* @title IWstETH
* @notice Interface for the wstETH token
*/
interface IWstETH {
/**
* @notice Exchanges wstETH to stETH
* @param _wstETHAmount amount of wstETH to uwrap in exchange for stETH
* @dev Requirements:
* - `_wstETHAmount` must be non-zero
* - msg.sender must have at least `_wstETHAmount` wstETH.
* @return Amount of stETH user receives after unwrap
*/
function unwrap(uint256 _wstETHAmount) external returns (uint256);
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/access/IAccessControlUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControlUpgradeable {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
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;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/utils/StringsUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/MathUpgradeable.sol";
import "./math/SignedMathUpgradeable.sol";
/**
* @dev String operations.
*/
library StringsUpgradeable {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = MathUpgradeable.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMathUpgradeable.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, MathUpgradeable.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/utils/introspection/ERC165Upgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165Upgradeable.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {
function __ERC165_init() internal onlyInitializing {
}
function __ERC165_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165Upgradeable).interfaceId;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/utils/AddressUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @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.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @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, it is bubbled up by this
* function (like regular Solidity function calls).
*
* 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.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @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`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes m
Submitted on: 2025-09-17 14:47:43
Comments
Log in to comment.
No comments yet.