Verified contractExactBUSL-1.1
LRTConverter
Address0x70daf8b0bfc846cc98b71d2f8ffdc91f4d2bbd51
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.27
- Same code
Only this contract
Details
- Compiler
- solc 0.8.27+commit.40a35a09
- Language
- solidity
- Optimization
- Yes, 2,000 runs
- EVM version
- cancun
- License
- BUSL-1.1
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 24,075,612
- Creation transaction
- 0xc88863e270…5138e21bd8
20 files
- contracts/LRTConverter.solmain10.77 KB
- @openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol6.64 KB
- @openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol3.68 KB
- @openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol9.38 KB
- @openzeppelin/contracts/access/IAccessControl.sol2.92 KB
- @openzeppelin/contracts/token/ERC20/IERC20.sol2.74 KB
- @openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol2.26 KB
- @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol6.91 KB
- @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol987 B
- @openzeppelin/contracts/utils/Address.sol9.36 KB
- contracts/interfaces/ILRTConfig.sol2.23 KB
- contracts/interfaces/ILRTConverter.sol1.38 KB
- contracts/interfaces/ILRTDepositPool.sol3.77 KB
- contracts/interfaces/ILRTOracle.sol1.34 KB
- contracts/interfaces/ILRTWithdrawalManager.sol5.66 KB
- contracts/unstaking-adapters/UnstakeStETH.sol2.43 KB
- contracts/unstaking-adapters/UnstakeSwETH.sol1.56 KB
- contracts/utils/LRTConfigRoleChecker.sol2.56 KB
- contracts/utils/LRTConstants.sol4.23 KB
- contracts/utils/UtilLib.sol668 B
contracts/LRTConverter.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
import { LRTConstants } from "./utils/LRTConstants.sol";
import { UtilLib } from "./utils/UtilLib.sol";
import { LRTConfigRoleChecker, ILRTConfig } from "./utils/LRTConfigRoleChecker.sol";
import { ILRTDepositPool } from "./interfaces/ILRTDepositPool.sol";
import { ILRTOracle } from "./interfaces/ILRTOracle.sol";
import { ILRTConverter } from "./interfaces/ILRTConverter.sol";
import { ILRTWithdrawalManager } from "./interfaces/ILRTWithdrawalManager.sol";
import { IERC721Receiver } from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {
ReentrancyGuardUpgradeable
} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { UnstakeStETH } from "./unstaking-adapters/UnstakeStETH.sol";
/// @dev Legacy unstaking adapters for swETH are kept for upgrade compatibility
import { UnstakeSwETH } from "./unstaking-adapters/UnstakeSwETH.sol";
/// @title LRTConverter - Unstakes LSTs to ETH and swaps ETH to LSTs
/// @notice This contract is responsible for unstaking LSTs to ETH and swapping ETH to LSTs
contract LRTConverter is
ILRTConverter,
LRTConfigRoleChecker,
ReentrancyGuardUpgradeable,
UnstakeSwETH,
UnstakeStETH,
IERC721Receiver
{
using SafeERC20 for IERC20;
mapping(bytes32 => bool) public _legacyProcessedWithdrawalRoots;
mapping(address => bool) public _legacyConvertibleAssets;
mapping(address => uint256) public _legacyConversionLimit;
// needs to be added to total assets in protocol
uint256 public ethValueInWithdrawal;
mapping(address => bool) private whitelistedUsers;
uint256 public whitelistedUnstakeAllowance;
modifier onlyWhitelistedUser() {
if (!isUserWhitelisted(msg.sender)) {
revert UserNotWhitelisted();
}
_;
}
/// @dev Modifier to enforce unstaking limits and update counters
/// @param amountToUnstake Amount of stETH to unstake
modifier withinUnstakeLimits(uint256 amountToUnstake) {
if (amountToUnstake == 0) {
revert InvalidAmount();
}
uint256 availableActiveETHWithdrawals = _getActiveETHUserWithdrawals();
if (amountToUnstake > whitelistedUnstakeAllowance + availableActiveETHWithdrawals) {
revert UnstakeLimitExceeded();
}
// Consume intended withdrawal limit
if (whitelistedUnstakeAllowance > 0) {
uint256 whitelistedAmountConsumed =
amountToUnstake > whitelistedUnstakeAllowance ? whitelistedUnstakeAllowance : amountToUnstake;
whitelistedUnstakeAllowance -= whitelistedAmountConsumed;
}
_;
}
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
/// @dev Initializes the contract
/// @param lrtConfigAddr LRT config address
function initialize(address lrtConfigAddr) external initializer {
UtilLib.checkNonZeroAddress(lrtConfigAddr);
__ReentrancyGuard_init();
lrtConfig = ILRTConfig(lrtConfigAddr);
emit UpdatedLRTConfig(lrtConfigAddr);
}
/// @dev Initializes the contract
/// @param _withdrawalQueueAddress Address of withdrawal queue (stETH)
/// @param _stETHAddress Address of stETH
/// @param _swEXITAddress Address of swEXIT (swETH)
/// @param _swETHAddress Address of swETH
function initialize2(
address _withdrawalQueueAddress,
address _stETHAddress,
address _swEXITAddress,
address _swETHAddress
)
external
reinitializer(2)
onlyLRTAdmin
{
__ReentrancyGuard_init();
__initializeSwETH(_swEXITAddress, _swETHAddress);
__initializeStETH(_withdrawalQueueAddress, _stETHAddress);
}
function onERC721Received(address, address, uint256, bytes calldata) external pure returns (bytes4) {
return this.onERC721Received.selector;
}
/// @dev fallback to receive funds
receive() external payable { }
/*////////////////////////////////////////////////////////////
write interactions
//////////////////////////////////////////////////////////////*/
/// @notice send asset from deposit pool to LRTConverter
/// @dev Only callable by Asset Transfer Role and asset needs to be approved
/// @param _asset Asset address to send
/// @param _amount Asset amount to send
function transferAssetFromDepositPool(
address _asset,
uint256 _amount
)
external
onlySupportedERC20Token(_asset)
onlyAssetTransferRole
{
address lrtDepositPoolAddress = lrtConfig.getContract(LRTConstants.LRT_DEPOSIT_POOL);
address lrtOracleAddress = lrtConfig.getContract(LRTConstants.LRT_ORACLE);
ILRTOracle lrtOracle = ILRTOracle(lrtOracleAddress);
ethValueInWithdrawal += (_amount * lrtOracle.getAssetPrice(_asset)) / 1e18;
IERC20(_asset).safeTransferFrom(lrtDepositPoolAddress, address(this), _amount);
}
/// @notice send asset from LRTConverter to deposit pool
/// @dev Only callable by Asset Transfer Role and asset needs to be approved
/// @param _asset Asset address to send
/// @param _amount Asset amount to send
function transferAssetToDepositPool(
address _asset,
uint256 _amount
)
external
onlySupportedERC20Token(_asset)
onlyAssetTransferRole
{
address lrtDepositPoolAddress = lrtConfig.getContract(LRTConstants.LRT_DEPOSIT_POOL);
address lrtOracleAddress = lrtConfig.getContract(LRTConstants.LRT_ORACLE);
ILRTOracle lrtOracle = ILRTOracle(lrtOracleAddress);
uint256 assetValue = (_amount * lrtOracle.getAssetPrice(_asset)) / 1e18;
// Set to 0 if assetValue exceeds ethValueInWithdrawal, otherwise subtract assetValue
ethValueInWithdrawal = ethValueInWithdrawal > assetValue ? ethValueInWithdrawal - assetValue : 0;
IERC20(_asset).safeTransfer(lrtDepositPoolAddress, _amount);
}
/// @notice raises a unstake request for steth on lido
/// @param amountToUnstake Amount of stETH to unstake
function unstakeStEth(uint256 amountToUnstake)
external
nonReentrant
onlyLRTOperator
withinUnstakeLimits(amountToUnstake)
{
_unstakeStEth(amountToUnstake);
}
/// @notice claim eth from lido for steth and sends to deposit pool
function claimStEth(uint256 _requestId, uint256 _hint) external nonReentrant onlyLRTOperator {
_claimStEth(_requestId, _hint);
_sendEthToDepositPool(address(this).balance);
}
/// @notice raises a unstake request for sweth on swell
function unstakeSwEth(uint256 amountToUnstake) external nonReentrant onlyLRTOperator {
_unstakeSwEth(amountToUnstake);
}
/// @notice claim eth from sweth from swell for sweth and sends to deposit pool
function claimSwEth(uint256 _tokenId) external nonReentrant onlyLRTOperator {
_claimSwEth(_tokenId);
_sendEthToDepositPool(address(this).balance);
}
/// @notice Add or remove a user from the whitelist
/// @param user User address
/// @param whitelisted Whether to whitelist or remove from whitelist
function setUserWhitelisted(address user, bool whitelisted) external onlyLRTManager {
whitelistedUsers[user] = whitelisted;
emit UserWhitelisted(user, whitelisted);
}
/// @notice Batch add or remove users from the whitelist
/// @param users Array of user addresses
/// @param whitelisted Whether to whitelist or remove from whitelist
function batchSetUserWhitelisted(address[] calldata users, bool whitelisted) external onlyLRTManager {
for (uint256 i = 0; i < users.length; i++) {
whitelistedUsers[users[i]] = whitelisted;
emit UserWhitelisted(users[i], whitelisted);
}
}
/// @notice Declare withdrawal intent (only whitelisted users)
/// @param amount Amount of stETH to declare for withdrawal
function declareWithdrawalIntent(uint256 amount) external nonReentrant onlyWhitelistedUser {
if (amount == 0) {
revert InvalidAmount();
}
uint256 maxWhitelistedAllowance = 1_000_000_000 ether;
if (whitelistedUnstakeAllowance + amount > maxWhitelistedAllowance) {
revert WhitelistedAllowanceExceeded();
}
whitelistedUnstakeAllowance = whitelistedUnstakeAllowance + amount;
emit WithdrawalIntentDeclared(msg.sender, amount);
}
/*////////////////////////////////////////////////////////////
view functions
//////////////////////////////////////////////////////////////*/
/// @notice Get the current unstaking limits and usage
/// @return whitelistedAllowance Current whitelisted unstake allowance
/// @return activeETHWithdrawals Current active ETH withdrawals
function getUnstakeLimits() external view returns (uint256 whitelistedAllowance, uint256 activeETHWithdrawals) {
whitelistedAllowance = whitelistedUnstakeAllowance;
activeETHWithdrawals = _getActiveETHUserWithdrawals();
}
/// @notice Check if a user is whitelisted
/// @param user User address to check
/// @return True if user is whitelisted
function isUserWhitelisted(address user) public view returns (bool) {
return whitelistedUsers[user];
}
/*////////////////////////////////////////////////////////////
internal functions
//////////////////////////////////////////////////////////////*/
function _sendEthToDepositPool(uint256 _amount) internal {
address lrtDepositPoolAddress = lrtConfig.getContract(LRTConstants.LRT_DEPOSIT_POOL);
if (ethValueInWithdrawal > _amount) {
ethValueInWithdrawal -= _amount;
} else {
ethValueInWithdrawal = 0;
}
// Send eth to deposit pool
ILRTDepositPool(lrtDepositPoolAddress).receiveFromLRTConverter{ value: _amount }();
emit EthTransferred(lrtDepositPoolAddress, _amount);
}
/// @dev Get active user ETH withdrawals from LRTWithdrawalManager
function _getActiveETHUserWithdrawals() internal view returns (uint256 activeETHWithdrawals) {
ILRTWithdrawalManager lrtWithdrawalManager =
ILRTWithdrawalManager(lrtConfig.getContract(LRTConstants.LRT_WITHDRAW_MANAGER));
activeETHWithdrawals = lrtWithdrawalManager.assetsCommitted(LRTConstants.ETH_TOKEN);
}
}
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// 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;
}
}
@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol
// 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;
}
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol
// 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 memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
@openzeppelin/contracts/access/IAccessControl.sol
// 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 IAccessControl {
/**
* @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;
}
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
// 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));
}
}
@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
@openzeppelin/contracts/utils/Address.sol
// 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 Address {
/**
* @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 memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
contracts/interfaces/ILRTConfig.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
interface ILRTConfig {
// Errors
error ValueAlreadyInUse();
error AssetAlreadySupported();
error AssetNotSupported();
error ETHNotSupported();
error CallerNotLRTConfigAdmin();
error CallerNotLRTConfigManager();
error CallerNotLRTConfigOperator();
error CallerNotLRTConfigAssetTransferRole();
error CallerNotLRTConfigOperatorOrAssetTransferRole();
error CallerNotLRTConfigAllowedRole(string role);
error CannotUpdateStrategyAsItHasFundsNDCFunds(address ndc, uint256 amount);
error InvalidMaxRewardAmount();
error ProtocolFeeExceedsLimit();
error CannotRemoveAssetWithDeposits(address asset);
error TokenNotFoundError();
error InvalidDepositLimit();
// Events
event SetToken(bytes32 key, address indexed tokenAddr);
event SetContract(bytes32 key, address indexed contractAddr);
event AddedNewSupportedAsset(address indexed asset, uint256 depositLimit);
event RemovedSupportedAsset(address indexed asset);
event AssetDepositLimitUpdate(address indexed asset, uint256 depositLimit);
event AssetStrategyUpdate(address indexed asset, address indexed strategy);
event SetRSETH(address indexed rsETH);
event UpdateMaxRewardAmount(uint256 maxRewardAmount);
event MaxNegligibleAmountUpdated(uint256 maxNegligibleAmount);
event UpdateFee(uint256 newFee);
event SetEigenLayerRewardReceiver(address indexed eigenLayerRewardReceiver);
event PausedAll(address indexed sender);
// methods
function rsETH() external view returns (address);
function assetStrategy(address asset) external view returns (address);
function isSupportedAsset(address asset) external view returns (bool);
function getLSTToken(bytes32 tokenId) external view returns (address);
function getContract(bytes32 contractId) external view returns (address);
function getSupportedAssetList() external view returns (address[] memory);
function depositLimitByAsset(address asset) external view returns (uint256);
function protocolFeeInBPS() external view returns (uint256);
function eigenLayerRewardReceiver() external view returns (address);
}
contracts/interfaces/ILRTConverter.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
interface ILRTConverter {
error UserNotWhitelisted();
error InvalidAmount();
error UnstakeLimitExceeded();
error WhitelistedAllowanceExceeded();
error NotEnoughAssetToTransfer();
event ConvertedEigenlayerAssetToRsEth(address indexed receiver, uint256 rsethAmount, bytes32 withdrawalRoot);
event ETHSwappedForLST(uint256 ethAmount, address indexed toAsset, uint256 returnAmount);
event EthTransferred(address to, uint256 amount);
// stETH unstaking limit events
event UserWhitelisted(address indexed user, bool whitelisted);
event WithdrawalIntentDeclared(address indexed user, uint256 amount);
function ethValueInWithdrawal() external view returns (uint256);
function transferAssetFromDepositPool(address _asset, uint256 _amount) external;
function setUserWhitelisted(address user, bool whitelisted) external;
function batchSetUserWhitelisted(address[] calldata users, bool whitelisted) external;
function declareWithdrawalIntent(uint256 amount) external;
// View functions
function getUnstakeLimits() external view returns (uint256 whitelistedAllowance, uint256 activeETHWithdrawals);
function isUserWhitelisted(address user) external view returns (bool);
function whitelistedUnstakeAllowance() external view returns (uint256);
}
contracts/interfaces/ILRTDepositPool.sol
// 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/ILRTOracle.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
interface ILRTOracle {
// errors
error AssetOracleNotSupported();
error InvalidPriceOracle();
error PriceAboveDailyThreshold();
error ProtocolFeeExceededTVLIncrease();
error DailyFeeMintLimitExceeded(uint256 currentAmount, uint256 maxAmount);
error ContractPaused();
error ContractNotPaused();
error PeriodStartTimeShouldBeWithin24Hours();
// events
event AssetPriceOracleUpdate(address indexed asset, address indexed priceOracle);
event RsETHPriceUpdate(uint256 newPrice, uint256 oldPrice);
event PricePercentageLimitUpdate(uint256 newLimit);
event FeeMinted(address treasury, uint256 rsethAmount);
event RsETHPriceBelowPeak(uint256 highestRsethPrice, uint256 newPrice);
event RsETHPriceDecrease(uint256 newPrice, uint256 oldPrice);
event PeriodInTimestampUpdate(uint256 newPeriod);
event MaxFeeMintAmountPerDayUpdated(uint256 newLimit);
event Paused(address account);
event Unpaused(address account);
event FeePeriodStartTimeSet(uint256 feePeriodStartTime);
// methods
function getAssetPrice(address asset) external view returns (uint256);
function assetPriceOracle(address asset) external view returns (address);
function rsETHPrice() external view returns (uint256);
}
contracts/interfaces/ILRTWithdrawalManager.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
interface ILRTWithdrawalManager {
//errors
error EthTransferFailed();
error InvalidAmountToWithdraw();
error ExceedAmountToWithdraw();
error WithdrawalLocked();
error WithdrawalDelayNotPassed();
error ExceedWithdrawalDelay();
error NoPendingWithdrawals();
error AmountMustBeGreaterThanZero();
error StrategyNotSupported();
error RsETHPriceOutOfPriceRange(uint256 rsEthPrice);
error AssetPriceOutOfPriceRange(uint256 assetPrice);
error CantInstantWithdrawMoreThanAvailable();
error NotEnoughRsETH();
error InstantWithdrawalNotEnabled();
error FeeTooHigh();
error PendingWithdrawalsExist();
error TreasuryTransferFailed();
error NoWithdrawalRequests(address user, address asset);
error AaveIntegrationNotEnabled();
error InsufficientAaveBalance();
error InvalidAaveConfiguration();
error AaveHealthCheckFailed();
error InsufficientLiquidityForWithdrawal();
error UnauthorizedCaller();
error AaveIntegrationAlreadyInDesiredState(bool enabled);
struct UnlockParams {
uint256 rsETHPrice;
uint256 assetPrice;
uint256 totalAvailableAssets;
}
struct WithdrawalRequest {
uint256 rsETHUnstaked;
uint256 expectedAssetAmount;
uint256 withdrawalStartBlock;
}
//events
event AssetWithdrawalQueued(
address indexed withdrawer, address indexed asset, uint256 rsETHUnstaked, uint256 indexed userNonce
);
event AssetWithdrawalFinalized(
address indexed withdrawer, address indexed asset, uint256 amountBurned, uint256 amountReceived
);
event EtherReceived(address indexed depositor, uint256 ethAmount, uint256 sharesAmount);
event AssetUnlocked(
address indexed asset, uint256 rsEthAmount, uint256 assetAmount, uint256 rsEThPrice, uint256 assetPrice
);
event MinAmountToWithdrawUpdated(address asset, uint256 minRsEthAmountToWithdraw);
event WithdrawalDelayBlocksUpdated(uint256 withdrawalDelayBlocks);
event ReferralIdEmitted(string referralId);
event InstantWithdrawalEnabledUpdated(address indexed asset, bool enabled);
event InstantWithdrawalFeeUpdated(uint256 feeBasisPoints);
event InstantWithdrawalFeeRecipientUpdated(address indexed feeRecipient);
event InstantWithdrawalFeeCollected(address indexed user, address indexed asset, uint256 fee);
event TreasuryWithdrawalSettled(address indexed asset, uint256 amount);
event RemainingAssetsSwept(address indexed asset, uint256 amount, address indexed treasury);
event AssetWithdrawalCompletedBy(address indexed user);
event AaveIntegrationConfigured(
address indexed aavePool, address indexed aaveWETHGateway, address indexed aaveAWETH, address aaveDataProvider
);
event AaveIntegrationEnabled(bool enabled);
event ETHDepositedToAave(uint256 amount, uint256 totalDeposited);
event ETHWithdrawnFromAave(uint256 amount, uint256 totalDeposited);
event InterestCollectedToTreasury(uint256 interestAmount, address indexed treasury);
event EmergencyWithdrawFromAave(uint256 amount, address indexed recipient);
event AaveDepositFailed(uint256 amount, bytes reason);
// methods
function getExpectedAssetAmount(address asset, uint256 amount) external view returns (uint256);
function getAvailableAssetAmount(address asset) external view returns (uint256 assetAmount);
function getUserWithdrawalRequest(
address asset,
address user,
uint256 index
)
external
view
returns (uint256 rsETHAmount, uint256 expectedAssetAmount, uint256 withdrawalStartBlock, uint256 userNonce);
function initiateWithdrawal(address asset, uint256 withdrawAmount, string calldata referralId) external;
function completeWithdrawal(address asset, string calldata referralId) external;
function completeWithdrawalForUser(address asset, address user, string calldata referralId) external;
function unlockQueue(
address asset,
uint256 index,
uint256 minimumAssetPrice,
uint256 minimumRsEthPrice,
uint256 maximumAssetPrice,
uint256 maximumRsEthPrice
)
external
returns (uint256 rsETHBurned, uint256 assetAmountUnlocked);
// receive functions
function receiveFromLRTUnstakingVault() external payable;
function setInstantWithdrawalEnabled(address asset, bool enabled) external;
function setInstantWithdrawalFee(uint256 feeBasisPoints) external;
function setInstantWithdrawalFeeRecipient(address feeRecipient) external;
function assetsCommitted(address asset) external view returns (uint256);
// Treasury withdrawal flow functions
function hasUnlockedWithdrawals(address asset) external view returns (bool);
function sweepRemainingAssets(address asset) external returns (uint256 transferredAmount);
// Aave integration functions
function configureAaveIntegration(
address aavePool_,
address aaveWETHGateway_,
address aaveAWETH_,
address aaveDataProvider_
)
external;
function setAaveIntegrationEnabled(bool enabled) external;
function depositIdleETHToAave(uint256 amount) external;
function collectInterestToTreasury() external returns (uint256 interestAmount);
function emergencyWithdrawFromAave(uint256 amount) external;
function getAaveBalance() external view returns (uint256);
function getAccruedInterest() external view returns (uint256);
function aaveHealthCheck() external view returns (bool);
}
contracts/unstaking-adapters/UnstakeStETH.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
interface ILidoWithdrawalQueue {
function requestWithdrawals(
uint256[] calldata _amounts,
address _owner
)
external
returns (uint256[] memory requestIds);
/// Usage: findCheckpointHints(_requestIds, 1, getLastCheckpointIndex())
function findCheckpointHints(
uint256[] calldata _requestIds,
uint256 _firstIndex,
uint256 _lastIndex
)
external
view
returns (uint256[] memory hintIds);
function getLastCheckpointIndex() external view returns (uint256);
function claimWithdrawalsTo(uint256[] calldata _requestIds, uint256[] calldata _hints, address _recipient) external;
function finalize(uint256 _lastRequestIdToBeFinalized, uint256 _maxShareRate) external payable;
function getLastRequestId() external view returns (uint256);
}
/// @dev Upgradeable base contract without storage gaps; adding variables in upgrades can collide with inheritors.
abstract contract UnstakeStETH is Initializable {
using SafeERC20 for IERC20;
ILidoWithdrawalQueue public withdrawalQueue;
IERC20 public stETH;
event UnstakeStETHStarted(uint256 tokenId);
function __initializeStETH(address _withdrawalQueue, address _stETHAddress) internal onlyInitializing {
withdrawalQueue = ILidoWithdrawalQueue(_withdrawalQueue);
stETH = IERC20(_stETHAddress);
}
function _unstakeStEth(uint256 amountToUnstake) internal {
stETH.safeIncreaseAllowance(address(withdrawalQueue), amountToUnstake);
uint256[] memory amounts = new uint256[](1);
amounts[0] = amountToUnstake;
uint256[] memory requestIds = withdrawalQueue.requestWithdrawals(amounts, address(this));
emit UnstakeStETHStarted(requestIds[0]);
}
function _claimStEth(uint256 _requestId, uint256 _hint) internal {
uint256[] memory requestIds = new uint256[](1);
uint256[] memory hints = new uint256[](1);
requestIds[0] = _requestId;
hints[0] = _hint;
withdrawalQueue.claimWithdrawalsTo(requestIds, hints, address(this));
}
}
contracts/unstaking-adapters/UnstakeSwETH.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
interface IswEXIT {
function getLastTokenIdCreated() external view returns (uint256);
function createWithdrawRequest(uint256 amount) external;
function finalizeWithdrawal(uint256 tokenId) external;
function processWithdrawals(uint256 lastTokenIdToProcess) external;
}
/// @dev Upgradeable base contract without storage gaps; adding variables in upgrades can collide with inheritors.
abstract contract UnstakeSwETH is Initializable {
using SafeERC20 for IERC20;
IswEXIT public swEXIT;
IERC20 public swETH;
event UnstakeSwETHStarted(uint256 tokenId);
function __initializeSwETH(address _swEXITAddress, address _swETHAddress) internal onlyInitializing {
swEXIT = IswEXIT(_swEXITAddress);
swETH = IERC20(_swETHAddress);
}
function _unstakeSwEth(uint256 amountToUnstake) internal returns (uint256 tokenId) {
swETH.safeIncreaseAllowance(address(swEXIT), amountToUnstake);
// Create withdrawal request
swEXIT.createWithdrawRequest(amountToUnstake);
tokenId = swEXIT.getLastTokenIdCreated();
emit UnstakeSwETHStarted(tokenId);
}
function _claimSwEth(uint256 _tokenId) internal {
swEXIT.finalizeWithdrawal(_tokenId);
}
}
contracts/utils/LRTConfigRoleChecker.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
import { LRTConstants } from "./LRTConstants.sol";
import { ILRTConfig } from "../interfaces/ILRTConfig.sol";
import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";
/// @title LRTConfigRoleChecker - LRT Config Role Checker Contract
/// @notice Handles LRT config role checks
abstract contract LRTConfigRoleChecker {
ILRTConfig public lrtConfig;
// events
event UpdatedLRTConfig(address indexed lrtConfig);
// modifiers
modifier onlyRole(bytes32 role) {
if (!IAccessControl(address(lrtConfig)).hasRole(role, msg.sender)) {
string memory roleStr = string(abi.encodePacked(role));
revert ILRTConfig.CallerNotLRTConfigAllowedRole(roleStr);
}
_;
}
modifier onlyLRTManager() {
if (!IAccessControl(address(lrtConfig)).hasRole(LRTConstants.MANAGER, msg.sender)) {
revert ILRTConfig.CallerNotLRTConfigManager();
}
_;
}
modifier onlyLRTOperator() {
if (!IAccessControl(address(lrtConfig)).hasRole(LRTConstants.OPERATOR_ROLE, msg.sender)) {
revert ILRTConfig.CallerNotLRTConfigOperator();
}
_;
}
modifier onlyAssetTransferRole() {
if (!IAccessControl(address(lrtConfig)).hasRole(LRTConstants.ASSET_TRANSFER_ROLE, msg.sender)) {
revert ILRTConfig.CallerNotLRTConfigAssetTransferRole();
}
_;
}
modifier onlyAssetTransferOrOperatorRole() {
if (
!IAccessControl(address(lrtConfig)).hasRole(LRTConstants.ASSET_TRANSFER_ROLE, msg.sender)
&& !IAccessControl(address(lrtConfig)).hasRole(LRTConstants.OPERATOR_ROLE, msg.sender)
) {
revert ILRTConfig.CallerNotLRTConfigOperatorOrAssetTransferRole();
}
_;
}
modifier onlyLRTAdmin() {
if (!IAccessControl(address(lrtConfig)).hasRole(LRTConstants.DEFAULT_ADMIN_ROLE, msg.sender)) {
revert ILRTConfig.CallerNotLRTConfigAdmin();
}
_;
}
modifier onlySupportedAsset(address asset) {
if (!lrtConfig.isSupportedAsset(asset)) {
revert ILRTConfig.AssetNotSupported();
}
_;
}
modifier onlySupportedERC20Token(address asset) {
if (!lrtConfig.isSupportedAsset(asset)) {
revert ILRTConfig.AssetNotSupported();
}
if (asset == LRTConstants.ETH_TOKEN) {
revert ILRTConfig.ETHNotSupported();
}
_;
}
}
contracts/utils/LRTConstants.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
import { ILRTConfig } from "../interfaces/ILRTConfig.sol";
library LRTConstants {
//tokens
bytes32 public constant ST_ETH_TOKEN = keccak256("ST_ETH_TOKEN");
bytes32 public constant ETHX_TOKEN = keccak256("ETHX_TOKEN");
bytes32 public constant SFRX_ETH_TOKEN = keccak256("SFRX_ETH_TOKEN");
// native ETH as ERC20 for ease of implementation
address public constant ETH_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
//contracts
bytes32 public constant LRT_ORACLE = keccak256("LRT_ORACLE");
bytes32 public constant LRT_DEPOSIT_POOL = keccak256("LRT_DEPOSIT_POOL");
bytes32 public constant LRT_WITHDRAW_MANAGER = keccak256("LRT_WITHDRAW_MANAGER");
bytes32 public constant LRT_UNSTAKING_VAULT = keccak256("LRT_UNSTAKING_VAULT");
bytes32 public constant LRT_CONVERTER = keccak256("LRT_CONVERTER");
bytes32 public constant REWARD_RECEIVER = keccak256("REWARD_RECEIVER");
bytes32 public constant PROTOCOL_TREASURY = keccak256("PROTOCOL_TREASURY");
bytes32 public constant PUBKEY_REGISTRY = keccak256("PUBKEY_REGISTRY");
bytes32 public constant UNLOCKED_WITHDRAWAL_INITIALIZER = keccak256("UNLOCKED_WITHDRAWAL_INITIALIZER");
bytes32 public constant BEACON_CHAIN_ETH_STRATEGY = keccak256("BEACON_CHAIN_ETH_STRATEGY");
bytes32 public constant EIGEN_STRATEGY_MANAGER = keccak256("EIGEN_STRATEGY_MANAGER");
bytes32 public constant EIGEN_POD_MANAGER = keccak256("EIGEN_POD_MANAGER");
bytes32 public constant EIGEN_DELEGATION_MANAGER = keccak256("EIGEN_DELEGATION_MANAGER");
bytes32 public constant EIGEN_REWARDS_COORDINATOR = keccak256("EIGEN_REWARDS_COORDINATOR");
//Roles
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
bytes32 public constant MANAGER = keccak256("MANAGER");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
bytes32 public constant ASSET_TRANSFER_ROLE = keccak256("ASSET_TRANSFER_ROLE");
bytes32 public constant TIME_LOCK_ROLE = keccak256("TIME_LOCK_ROLE");
// constants
uint256 public constant ONE_E_9 = 1e9;
// Contract getters
function unstakingVault(ILRTConfig config) internal view returns (address) {
return config.getContract(LRT_UNSTAKING_VAULT);
}
function delegationManager(ILRTConfig config) internal view returns (address) {
return config.getContract(EIGEN_DELEGATION_MANAGER);
}
function rewardsCoordinator(ILRTConfig config) internal view returns (address) {
return config.getContract(EIGEN_REWARDS_COORDINATOR);
}
function strategyManager(ILRTConfig config) internal view returns (address) {
return config.getContract(EIGEN_STRATEGY_MANAGER);
}
function lrtConverter(ILRTConfig config) internal view returns (address) {
return config.getContract(LRT_CONVERTER);
}
function depositPool(ILRTConfig config) internal view returns (address) {
return config.getContract(LRT_DEPOSIT_POOL);
}
function lrtOracle(ILRTConfig config) internal view returns (address) {
return config.getContract(LRT_ORACLE);
}
function rewardReceiver(ILRTConfig config) internal view returns (address) {
return config.getContract(REWARD_RECEIVER);
}
function protocolTreasury(ILRTConfig config) internal view returns (address) {
return config.getContract(PROTOCOL_TREASURY);
}
function pubkeyRegistry(ILRTConfig config) internal view returns (address) {
return config.getContract(PUBKEY_REGISTRY);
}
function beaconChainETHStrategy(ILRTConfig config) internal view returns (address) {
return config.getContract(BEACON_CHAIN_ETH_STRATEGY);
}
function eigenPodManager(ILRTConfig config) internal view returns (address) {
return config.getContract(EIGEN_POD_MANAGER);
}
function withdrawManager(ILRTConfig config) internal view returns (address) {
return config.getContract(LRT_WITHDRAW_MANAGER);
}
}
contracts/utils/UtilLib.sol
// 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;
}
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 2000,
"enabled": true
},
"evmVersion": "cancun",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.