Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"src/MintRedeem/Router.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Order, OrderType, MintRedeemMode, RequestStatus} from "src/MintRedeem/Structs.sol";
import {IMinter} from "src/interfaces/IMinter.sol";
import {IRedeemer} from "src/interfaces/IRedeemer.sol";
import {IAssetReserve} from "src/interfaces/IAssetReserve.sol";
import {SingleAdminAccessControl} from "src/utils/SingleAdminAccessControl.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
/// @title Router
/// @notice Main entry point for minting ELUSD using various collateral assets
/// @dev Manages the routing of minting operations to appropriate minter contracts and handles asset reserve interactions
contract Router is SingleAdminAccessControl, Pausable {
using SafeERC20 for IERC20;
/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
error ZeroInput();
error AssetNotSupported();
error Unauthorized();
error InvalidRequestStatus();
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event MinterSet(address indexed asset, address minter);
event RedeemerSet(address indexed asset, address redeemer);
event AssetReserveSet(address indexed assetReserve);
event MintWhitelistEnforcementSet(bool enabled);
event RedeemWhitelistEnforcementSet(bool enabled);
event MintWhitelisted(address indexed user, bool whitelisted);
event RedeemWhitelisted(address indexed user, bool whitelisted);
event RequestMint(uint256 indexed requestId, Order order);
event ServeRequestMint(uint256 indexed requestId);
event MintRequestCancelled(uint256 indexed requestId);
event Mint(
address indexed benefactor,
address indexed beneficiary,
address collateral_asset,
uint256 collateral_amount,
uint256 elusd_amount
);
event RequestRedemption(uint256 indexed requestId, Order order);
event ServeRequestRedemption(uint256 indexed requestId);
event RedemptionRequestCancelled(uint256 indexed requestId);
event Redeem(
address indexed benefactor,
address indexed beneficiary,
address collateral_asset,
uint256 collateral_amount,
uint256 elusd_amount
);
event OrderWaitingPeriodSet(uint24 orderWaitingPeriod);
/*//////////////////////////////////////////////////////////////
STORAGE
//////////////////////////////////////////////////////////////*/
/// @notice Role for pausing the contract
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
/// @notice Role for managing the whitelist
bytes32 public constant WHITELISTER_ROLE = keccak256("WHITELISTER_ROLE");
/// @notice Role for managing the redemption keeper
bytes32 public constant KEEPER_ROLE = keccak256("KEEPER_ROLE");
/// @notice ELUSD
IERC20 public immutable ELUSD;
/// @notice Mapping of collateral asset addresses to their corresponding minter contracts
mapping(address collateralAsset => IMinter minter) public minters;
/// @notice Mapping of collateral asset addresses to their corresponding redeemer contracts
mapping(address collateralAsset => IRedeemer redeemer) public redeemers;
/// @notice Address of asset reserve
address public assetReserve;
/// @notice The order waiting period
uint24 public orderWaitingPeriod;
/// @notice Whether the mint whitelist enforcement is enabled
bool public isMintWhitelistEnforced;
/// @notice Whether the redeem whitelist enforcement is enabled
bool public isRedeemWhitelistEnforced;
/// @notice Mapping of user addresses to their mint whitelist status
mapping(address user => bool) public isMintWhitelisted;
/// @notice Mapping of user addresses to their redeem whitelist status
mapping(address user => bool) public isRedeemWhitelisted;
/// @notice The current mint request ID
uint256 public mintRequestId;
/// @notice Mapping of mint request IDs to mint requests
mapping(uint256 requestId => Order) public mintRequests;
/// @notice Mapping of mint request IDs to mint request statuses
mapping(uint256 requestId => RequestStatus) public mintRequestStatus;
/// @notice The current redemption request ID
uint256 public redemptionRequestId;
/// @notice Mapping of redemption request IDs to redemption requests
/// @dev This is filled when liquid buffer cannot serve redemption, we use this to serve the redemption request
mapping(uint256 requestId => Order) public redemptionRequests;
/// @notice Mapping of redemption request IDs to redemption request statuses
mapping(uint256 requestId => RequestStatus) public redemptionRequestStatus;
/*//////////////////////////////////////////////////////////////
INITIALIZATION
//////////////////////////////////////////////////////////////*/
/// @notice Initializes the Router contract
/// @param _elusd Address of the ELUSD token
/// @param _admin Address of the admin
/// @param _assetReserve Address of the asset reserve
constructor(address _elusd, address _admin, address _assetReserve) {
ELUSD = IERC20(_elusd);
_grantRole(DEFAULT_ADMIN_ROLE, _admin);
// Set asset reserve
_setAssetReserve(_assetReserve);
// Set whitelist
// _setMintWhitelistEnforcement(true);
// _setRedeemWhitelistEnforcement(true);
// Set order waiting period
_setOrderWaitingPeriod(7 days);
}
/*//////////////////////////////////////////////////////////////
ADMIN FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Configures an asset
/// @param _collateralAsset Address of the collateral asset
/// @param _minter Address of the minter contract
/// @param _redeemer Address of the redeemer contract
function configureAsset(address _collateralAsset, address _minter, address _redeemer)
external
onlyRole(DEFAULT_ADMIN_ROLE)
{
if (_collateralAsset == address(ELUSD)) revert AssetNotSupported();
_setMinter(_collateralAsset, _minter);
_setRedeemer(_collateralAsset, _redeemer);
}
/// @notice Sets the asset reserve
/// @param _assetReserve Address of the asset reserve
function setAssetReserve(address _assetReserve) external onlyRole(DEFAULT_ADMIN_ROLE) {
_setAssetReserve(_assetReserve);
}
/// @notice Sets the order waiting
/// @param _orderWaitingPeriod Duration of the order waiting period
function setOrderWaitingPeriod(uint24 _orderWaitingPeriod) external onlyRole(DEFAULT_ADMIN_ROLE) {
_setOrderWaitingPeriod(_orderWaitingPeriod);
}
/// @notice Pauses the contract
function pause() external onlyRole(PAUSER_ROLE) {
_pause();
}
/// @notice Unpauses the contract
function unpause() external onlyRole(PAUSER_ROLE) {
_unpause();
}
/// @notice Sets the mint whitelist enforcement
/// @param _enabled Boolean indicating whether the mint whitelist enforcement should be enabled
function setMintWhitelistEnforcement(bool _enabled) external onlyRole(WHITELISTER_ROLE) {
_setMintWhitelistEnforcement(_enabled);
}
/// @notice Sets the redeem whitelist enforcement
/// @param _enabled Boolean indicating whether the redeem whitelist enforcement should be enabled
function setRedeemWhitelistEnforcement(bool _enabled) external onlyRole(WHITELISTER_ROLE) {
_setRedeemWhitelistEnforcement(_enabled);
}
/// @notice Sets a user's mint whitelist status
/// @param _user Address of the user
/// @param _whitelisted Boolean indicating whether the user should be whitelisted
function setMintWhitelisted(address _user, bool _whitelisted) external onlyRole(WHITELISTER_ROLE) {
_setMintWhitelisted(_user, _whitelisted);
}
/// @notice Sets a user's redeem whitelist status
/// @param _user Address of the user
/// @param _whitelisted Boolean indicating whether the user should be whitelisted
function setRedeemWhitelisted(address _user, bool _whitelisted) external onlyRole(WHITELISTER_ROLE) {
_setRedeemWhitelisted(_user, _whitelisted);
}
/*//////////////////////////////////////////////////////////////
REDEMPTION KEEPER FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Serves a mint request
/// @param _requestId ID of the mint request
function serveMintRequest(uint256 _requestId) external onlyRole(KEEPER_ROLE) {
if (mintRequestStatus[_requestId] != RequestStatus.PENDING) revert InvalidRequestStatus();
Order memory order = mintRequests[_requestId];
_mint(order);
mintRequestStatus[_requestId] = RequestStatus.COMPLETED;
emit ServeRequestMint(_requestId);
}
/// @notice Cancels a mint request
/// @param _requestId ID of the mint request
function cancelMintRequest(uint256 _requestId) external onlyRole(KEEPER_ROLE) {
if (mintRequestStatus[_requestId] != RequestStatus.PENDING) revert InvalidRequestStatus();
Order memory order = mintRequests[_requestId];
mintRequestStatus[_requestId] = RequestStatus.CANCELLED;
IERC20(order.collateralAsset).safeTransfer(order.benefactor, order.collateralAmount);
emit MintRequestCancelled(_requestId);
}
/// @notice Serves a redemption request
/// @param _requestId ID of the redemption request
function serveRedemptionRequest(uint256 _requestId) external onlyRole(KEEPER_ROLE) {
if (redemptionRequestStatus[_requestId] != RequestStatus.PENDING) revert InvalidRequestStatus();
Order memory order = redemptionRequests[_requestId];
address originalBenefactor = order.benefactor;
// ELUSD have been transferred to the router, it becomes the benefactor
order.benefactor = address(this);
_redeem(order, originalBenefactor);
redemptionRequestStatus[_requestId] = RequestStatus.COMPLETED;
emit ServeRequestRedemption(_requestId);
}
/// @notice Cancels a redemption request
/// @param _requestId ID of the redemption request
function cancelRedemptionRequest(uint256 _requestId) external onlyRole(KEEPER_ROLE) {
if (redemptionRequestStatus[_requestId] != RequestStatus.PENDING) revert InvalidRequestStatus();
Order memory order = redemptionRequests[_requestId];
ELUSD.safeTransfer(order.benefactor, order.elusdAmount);
redemptionRequestStatus[_requestId] = RequestStatus.CANCELLED;
emit RedemptionRequestCancelled(_requestId);
}
/*//////////////////////////////////////////////////////////////
ENTRYPOINT FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Mints ELUSD using collateral
/// @param _beneficiary Address that will receive the minted ELUSD
/// @param _collateralAsset Address of the collateral asset
/// @param _collateralAmount Amount of collateral to deposit
/// @param _minElusdAmount Minimum amount of ELUSD to receive (slippage protection)
/// @param _additionalData Additional data for the order, in case of future use for minters / redeemers
function mint(
address _beneficiary,
address _collateralAsset,
uint256 _collateralAmount,
uint256 _minElusdAmount,
bytes calldata _additionalData
) external whenNotPaused enforceMintWhitelist(msg.sender) {
if (_collateralAsset == address(0) || _collateralAmount == 0 || _beneficiary == address(0)) revert ZeroInput();
if (minters[_collateralAsset] == IMinter(address(0))) revert AssetNotSupported();
// Transfer funds to the router
IERC20(_collateralAsset).safeTransferFrom(msg.sender, address(this), _collateralAmount);
// Create order
Order memory order = Order({
orderType: OrderType.MINT,
expiry: block.timestamp + orderWaitingPeriod,
benefactor: msg.sender,
beneficiary: _beneficiary,
collateralAsset: _collateralAsset,
collateralAmount: _collateralAmount,
elusdAmount: _minElusdAmount,
additionalData: _additionalData
});
MintRedeemMode mintMode = getMintMode(order.collateralAsset, order.collateralAmount);
mintMode == MintRedeemMode.INSTANT ? _mint(order) : _requestMint(order);
}
/// @notice Redeems ELUSD for collateral
/// @param _beneficiary Address that will receive the redeemed collateral
/// @param _collateralAsset Address of the collateral asset
/// @param _elusdAmount Amount of ELUSD to redeem
/// @param _minCollateralAmount Minimum amount of collateral to receive (slippage protection)
/// @param _additionalData Additional data for the order, in case of future use for minters / redeemers
// checked
function redeem(
address _beneficiary,
address _collateralAsset,
uint256 _elusdAmount,
uint256 _minCollateralAmount,
bytes calldata _additionalData
) external whenNotPaused enforceRedeemWhitelist(msg.sender) {
if (_collateralAsset == address(0) || _elusdAmount == 0 || _beneficiary == address(0)) revert ZeroInput();
if (redeemers[_collateralAsset] == IRedeemer(address(0))) revert AssetNotSupported();
// Create order
Order memory order = Order({
orderType: OrderType.REDEEM,
expiry: block.timestamp + orderWaitingPeriod,
benefactor: msg.sender,
beneficiary: _beneficiary,
collateralAsset: _collateralAsset,
collateralAmount: _minCollateralAmount,
elusdAmount: _elusdAmount,
additionalData: _additionalData
});
MintRedeemMode redemptionMode = getRedemptionMode(order.collateralAsset, order.elusdAmount);
redemptionMode == MintRedeemMode.INSTANT ? _redeem(order, order.benefactor) : _requestRedemption(order);
}
/*//////////////////////////////////////////////////////////////
VIEW FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Gets a quote for the amount of ELUSD that would be minted for a given amount of collateral
/// @param _collateralAsset Address of the collateral asset
/// @param _amount Amount of collateral to quote
/// @return The amount of ELUSD that would be minted
function quoteDeposit(address _collateralAsset, uint256 _amount) external view returns (uint256) {
return minters[_collateralAsset].quoteDeposit(_collateralAsset, _amount);
}
/// @notice Gets the mint mode for a given collateral asset and amount
/// @param _collateralAsset Address of the collateral asset
/// @param _amount Amount of collateral to mint
/// @return The mint mode, if INSTANT, the mint will be served immediately, if QUEUED, the mint will be queued and served later
function getMintMode(address _collateralAsset, uint256 _amount) public view returns (MintRedeemMode) {
return minters[_collateralAsset].getMintMode(_collateralAsset, _amount);
}
/// @notice Gets the redemption mode for a given collateral asset and ELUSD amount
/// @param _collateralAsset Address of the collateral asset
/// @param _elusdAmount Amount of ELUSD to redeem
/// @return The redemption mode, if INSTANT, the redemption will be served immediately, if QUEUED, the redemption will be queued and served later
function getRedemptionMode(address _collateralAsset, uint256 _elusdAmount) public view returns (MintRedeemMode) {
return redeemers[_collateralAsset].getRedemptionMode(_collateralAsset, _elusdAmount);
}
/// @notice Gets a quote for the amount of collateral that would be redeemed for a given amount of ELUSD
/// @param _collateralAsset Address of the collateral asset
/// @param _elusdAmount Amount of ELUSD to redeem
/// @return The amount of collateral that would be redeemed
function quoteRedemption(address _collateralAsset, uint256 _elusdAmount) external view returns (uint256) {
return redeemers[_collateralAsset].quoteRedeem(_collateralAsset, _elusdAmount);
}
/// @notice Gets the pending mint requests
/// @return The pending mint requests
/// @dev This is to be used offchain
function getPendingMintRequests() external view returns (Order[] memory, uint256[] memory) {
uint256 count = 0;
Order[] memory pendingRequests = new Order[](mintRequestId);
uint256[] memory pendingRequestIds = new uint256[](mintRequestId);
for (uint256 i = 0; i < mintRequestId; i++) {
if (mintRequestStatus[i] == RequestStatus.PENDING && mintRequests[i].expiry > block.timestamp) {
pendingRequests[count] = mintRequests[i];
pendingRequestIds[count] = i;
count++;
}
}
// Resize arrays to actual count using assembly
assembly {
mstore(pendingRequests, count)
mstore(pendingRequestIds, count)
}
return (pendingRequests, pendingRequestIds);
}
/// @notice Gets the pending mint requests
/// @param _startIndex The start index of the pending mint requests
/// @param _endIndex The end index of the pending mint requests
/// @return The pending mint requests
/// @dev This is to be used offchain
function getPendingMintRequests(uint256 _startIndex, uint256 _endIndex)
external
view
returns (Order[] memory, uint256[] memory)
{
uint256 count = 0;
uint256 length = _endIndex - _startIndex;
Order[] memory pendingRequests = new Order[](length);
uint256[] memory pendingRequestIds = new uint256[](length);
for (uint256 i = _startIndex; i < _endIndex; i++) {
if (mintRequestStatus[i] == RequestStatus.PENDING && mintRequests[i].expiry > block.timestamp) {
pendingRequests[count] = mintRequests[i];
pendingRequestIds[count] = i;
count++;
}
}
// Resize arrays to actual count using assembly
assembly {
mstore(pendingRequests, count)
mstore(pendingRequestIds, count)
}
return (pendingRequests, pendingRequestIds);
}
/// @notice Gets the pending redemption requests
/// @return The pending redemption requests
/// @dev This is to be used offchain
function getPendingRedemptionRequests() external view returns (Order[] memory, uint256[] memory) {
uint256 count = 0;
Order[] memory pendingRequests = new Order[](redemptionRequestId);
uint256[] memory pendingRequestIds = new uint256[](redemptionRequestId);
for (uint256 i = 0; i < redemptionRequestId; i++) {
if (redemptionRequestStatus[i] == RequestStatus.PENDING && redemptionRequests[i].expiry > block.timestamp) {
pendingRequests[count] = redemptionRequests[i];
pendingRequestIds[count] = i;
count++;
}
}
// Resize arrays to actual count using assembly
assembly {
mstore(pendingRequests, count)
mstore(pendingRequestIds, count)
}
return (pendingRequests, pendingRequestIds);
}
/// @notice Gets the pending redemption requests
/// @param _startIndex The start index of the pending redemption requests
/// @param _endIndex The end index of the pending redemption requests
/// @return The pending redemption requests
/// @dev This is to be used offchain
function getPendingRedemptionRequests(uint256 _startIndex, uint256 _endIndex)
external
view
returns (Order[] memory, uint256[] memory)
{
uint256 count = 0;
uint256 length = _endIndex - _startIndex;
Order[] memory pendingRequests = new Order[](length);
uint256[] memory pendingRequestIds = new uint256[](length);
for (uint256 i = _startIndex; i < _endIndex; i++) {
if (redemptionRequestStatus[i] == RequestStatus.PENDING && redemptionRequests[i].expiry > block.timestamp) {
pendingRequests[count] = redemptionRequests[i];
pendingRequestIds[count] = i;
count++;
}
}
// Resize arrays to actual count using assembly
assembly {
mstore(pendingRequests, count)
mstore(pendingRequestIds, count)
}
return (pendingRequests, pendingRequestIds);
}
/*//////////////////////////////////////////////////////////////
INTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
modifier enforceMintWhitelist(address _user) {
if (isMintWhitelistEnforced && !isMintWhitelisted[_user]) revert Unauthorized();
_;
}
modifier enforceRedeemWhitelist(address _user) {
if (isRedeemWhitelistEnforced && !isRedeemWhitelisted[_user]) revert Unauthorized();
_;
}
/// @notice Internal function to set a minter for an asset
/// @param _collateralAsset Address of the collateral asset
/// @param _minter Address of the minter contract
function _setMinter(address _collateralAsset, address _minter) internal {
if (_minter == address(0)) revert ZeroInput();
IMinter minter = IMinter(_minter);
if (!minter.isAssetSupported(_collateralAsset)) revert AssetNotSupported();
minters[_collateralAsset] = minter;
emit MinterSet(_collateralAsset, _minter);
}
/// @notice Internal function to set a redeemer for an asset
/// @param _collateralAsset Address of the collateral asset
/// @param _redeemer Address of the redeemer contract
function _setRedeemer(address _collateralAsset, address _redeemer) internal {
if (_redeemer == address(0)) revert ZeroInput();
IRedeemer redeemer = IRedeemer(_redeemer);
if (!redeemer.isAssetSupported(_collateralAsset)) revert AssetNotSupported();
redeemers[_collateralAsset] = redeemer;
emit RedeemerSet(_collateralAsset, _redeemer);
}
/// @notice Internal function to set the asset reserve
/// @param _assetReserve Address of the asset reserve
function _setAssetReserve(address _assetReserve) internal {
if (_assetReserve == address(0)) revert ZeroInput();
assetReserve = _assetReserve;
emit AssetReserveSet(_assetReserve);
}
/// @notice Internal function to set the mint whitelist enforcement
/// @param _enabled Boolean indicating whether the whitelist enforcement should be enabled
function _setMintWhitelistEnforcement(bool _enabled) internal {
isMintWhitelistEnforced = _enabled;
emit MintWhitelistEnforcementSet(_enabled);
}
/// @notice Internal function to set the redeem whitelist enforcement
/// @param _enabled Boolean indicating whether the redeem whitelist enforcement should be enabled
function _setRedeemWhitelistEnforcement(bool _enabled) internal {
isRedeemWhitelistEnforced = _enabled;
emit RedeemWhitelistEnforcementSet(_enabled);
}
/// @notice Internal function to set a user's mint whitelist status
/// @param _user Address of the user
/// @param _whitelisted Boolean indicating whether the user should be whitelisted
function _setMintWhitelisted(address _user, bool _whitelisted) internal {
isMintWhitelisted[_user] = _whitelisted;
emit MintWhitelisted(_user, _whitelisted);
}
/// @notice Internal function to set a user's redeem whitelist status
/// @param _user Address of the user
/// @param _whitelisted Boolean indicating whether the user should be whitelisted
function _setRedeemWhitelisted(address _user, bool _whitelisted) internal {
isRedeemWhitelisted[_user] = _whitelisted;
emit RedeemWhitelisted(_user, _whitelisted);
}
/// @notice Internal function to set the order waiting period
/// @param _orderWaitingPeriod Duration of the order waiting period
function _setOrderWaitingPeriod(uint24 _orderWaitingPeriod) internal {
orderWaitingPeriod = _orderWaitingPeriod;
emit OrderWaitingPeriodSet(_orderWaitingPeriod);
}
/// @notice Internal function to request a mint
/// @param _order Order containing the mint details
function _requestMint(Order memory _order) internal {
mintRequests[mintRequestId] = _order;
mintRequestStatus[mintRequestId] = RequestStatus.PENDING;
emit RequestMint(mintRequestId, _order);
mintRequestId++;
}
/// @notice Internal function to mint ELUSD
/// @param _order Order containing the mint details
function _mint(Order memory _order) internal {
// Transfer funds to the asset reserve
IERC20(_order.collateralAsset).safeTransfer(assetReserve, _order.collateralAmount);
// Mint ELUSD
uint256 amountMinted = minters[_order.collateralAsset].mint(_order);
emit Mint(_order.benefactor, _order.beneficiary, _order.collateralAsset, _order.collateralAmount, amountMinted);
}
/// @notice Internal function to redeem ELUSD for collateral
/// @param _order Order containing the redemption details
function _redeem(Order memory _order, address _originalBenefactor) internal {
uint256 collateralAmount = redeemers[_order.collateralAsset].redeem(_order);
// send collateral to beneficiary
IAssetReserve(assetReserve).processRedemption(_order.beneficiary, _order.collateralAsset, collateralAmount);
emit Redeem(
_originalBenefactor, _order.beneficiary, _order.collateralAsset, collateralAmount, _order.elusdAmount
);
}
/// @notice Internal function to request a redemption
/// @param _order Order containing the redemption details
function _requestRedemption(Order memory _order) internal {
ELUSD.safeTransferFrom(_order.benefactor, address(this), _order.elusdAmount);
redemptionRequests[redemptionRequestId] = _order;
redemptionRequestStatus[redemptionRequestId] = RequestStatus.PENDING;
emit RequestRedemption(redemptionRequestId, _order);
redemptionRequestId++;
}
}
"
},
"node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
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 value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` 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 value) external returns (bool);
}
"
},
"node_modules/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 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 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @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.encodeCall(token.transfer, (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.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, 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.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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 {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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 silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}
"
},
"src/MintRedeem/Structs.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
import {IPriceOracle} from "src/interfaces/IPriceOracle.sol";
enum OrderType {
MINT,
REDEEM
}
enum MintRedeemMode {
/// @dev Atomic mint against collateral
/// @dev Redeem directly from the liquid buffer
INSTANT,
/// @dev Queue the mint request and serve it later
/// @dev Queue the redemption request and serve it later
QUEUED
}
enum RequestStatus {
EMPTY,
PENDING,
COMPLETED,
CANCELLED
}
struct Order {
OrderType orderType;
uint256 expiry;
/// @dev The address that pays for the transaction
address benefactor;
/// @dev The address that will receive the assets.
address beneficiary;
address collateralAsset;
/// @dev When minting, this is the amount of collateral to deposit
/// @dev When redeeming, this is the minimum amount of collateral to receive
uint256 collateralAmount;
/// @dev When minting, this is the minimum amount of ELUSD to receive
/// @dev When redeeming, this is the amount of ELUSD to burn
uint256 elusdAmount;
/// @dev Additional data for the order, in case of future use for minters / redeemers
bytes additionalData;
}
struct Asset {
bool isSupported;
address asset;
uint8 decimals;
/// @dev Oracle rely on ERC7726 that comes with integrated checks https://github.com/euler-xyz/euler-price-oracle/
IPriceOracle oracle;
}
"
},
"src/interfaces/IMinter.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
import {Order, MintRedeemMode} from "src/MintRedeem/Structs.sol";
interface IMinter {
function mint(Order memory order) external returns (uint256);
function quoteDeposit(address _token, uint256 _amount) external view returns (uint256);
function getMintMode(address _collateralAsset, uint256 _amount) external view returns (MintRedeemMode);
function isAssetSupported(address _collateralAsset) external view returns (bool);
}
"
},
"src/interfaces/IRedeemer.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
import {Order, MintRedeemMode} from "src/MintRedeem/Structs.sol";
interface IRedeemer {
function redeem(Order memory order) external returns (uint256);
function quoteRedeem(address _token, uint256 _amount) external view returns (uint256);
function getRedemptionMode(address _collateralAsset, uint256 _elusdAmount) external view returns (MintRedeemMode);
function isAssetSupported(address _collateralAsset) external view returns (bool);
}
"
},
"src/interfaces/IAssetReserve.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
interface IAssetReserve {
function processRedemption(address _recipient, address _collateralAsset, uint256 _amount) external;
}
"
},
"src/utils/SingleAdminAccessControl.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.19 <0.9.0;
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/interfaces/IERC5313.sol";
import "src/interfaces/ISingleAdminAccessControl.sol";
/**
* @title SingleAdminAccessControl
* @notice SingleAdminAccessControl is a contract that provides a single admin role
* @notice This contract is a simplified alternative to OpenZeppelin's AccessControlDefaultAdminRules
*/
abstract contract SingleAdminAccessControl is IERC5313, ISingleAdminAccessControl, AccessControl {
address private _currentDefaultAdmin;
address private _pendingDefaultAdmin;
modifier notAdmin(bytes32 role) {
if (role == DEFAULT_ADMIN_ROLE) revert InvalidAdminChange();
_;
}
/// @notice Transfer the admin role to a new address
/// @notice This can ONLY be executed by the current admin
/// @param newAdmin address
function transferAdmin(address newAdmin) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (newAdmin == msg.sender) revert InvalidAdminChange();
_pendingDefaultAdmin = newAdmin;
emit AdminTransferRequested(_currentDefaultAdmin, newAdmin);
}
function acceptAdmin() external {
if (msg.sender != _pendingDefaultAdmin) revert NotPendingAdmin();
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
}
/// @notice grant a role
/// @notice can only be executed by the current single admin
/// @notice admin role cannot be granted externally
/// @param role bytes32
/// @param account address
function grantRole(bytes32 role, address account) public override onlyRole(DEFAULT_ADMIN_ROLE) notAdmin(role) {
_grantRole(role, account);
}
/// @notice revoke a role
/// @notice can only be executed by the current admin
/// @notice admin role cannot be revoked
/// @param role bytes32
/// @param account address
function revokeRole(bytes32 role, address account) public override onlyRole(DEFAULT_ADMIN_ROLE) notAdmin(role) {
_revokeRole(role, account);
}
/// @notice renounce the role of msg.sender
/// @notice admin role cannot be renounced
/// @param role bytes32
/// @param account address
function renounceRole(bytes32 role, address account) public virtual override notAdmin(role) {
super.renounceRole(role, account);
}
/**
* @dev See {IERC5313-owner}.
*/
function owner() public view virtual returns (address) {
return _currentDefaultAdmin;
}
/**
* @notice no way to change admin without removing old admin first
*/
function _grantRole(bytes32 role, address account) internal override returns (bool) {
if (role == DEFAULT_ADMIN_ROLE) {
emit AdminTransferred(_currentDefaultAdmin, account);
_revokeRole(DEFAULT_ADMIN_ROLE, _currentDefaultAdmin);
_currentDefaultAdmin = account;
delete _pendingDefaultAdmin;
}
return super._grantRole(role, account);
}
}
"
},
"node_modules/@openzeppelin/contracts/utils/Pausable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
bool private _paused;
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev The operation failed because the contract is paused.
*/
error EnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/
error ExpectedPause();
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
"
},
"node_modules/@openzeppelin/contracts/interfaces/IERC1363.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)
pragma solidity >=0.6.2;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
"
},
"src/interfaces/IPriceOracle.sol": {
"content": "// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;
/// @title IPriceOracle
/// @custom:security-contact security@euler.xyz
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Common PriceOracle interface.
interface IPriceOracle {
/// @notice Get the name of the oracle.
/// @return The name of the oracle.
function name() external view returns (string memory);
/// @notice One-sided price: How much quote token you would get for inAmount of base token, assuming no price spread.
/// @param inAmount The amount of `base` to convert.
/// @param base The token that is being priced.
/// @param quote The token that is the unit of account.
/// @return outAmount The amount of `quote` that is equivalent to `inAmount` of `base`.
function getQuote(uint256 inAmount, address base, address quote) external view returns (uint256 outAmount);
/// @notice Two-sided price: How much quote token you would get/spend for selling/buying inAmount of base token.
/// @param inAmount The amount of `base` to convert.
/// @param base The token that is being priced.
/// @param quote The token that is the unit of account.
/// @return bidOutAmount The amount of `quote` you would get for selling `inAmount` of `base`.
/// @return askOutAmount The amount of `quote` you would spend for buying `inAmount` of `base`.
function getQuotes(uint256 inAmount, address base, address quote)
external
view
returns (uint256 bidOutAmount, uint256 askOutAmount);
}
"
},
"node_modules/@openzeppelin/contracts/access/AccessControl.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {IERC165, ERC165} from "../utils/introspection/ERC165.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 AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
mapping(bytes32 role => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with an {AccessControlUnauthorizedAccount} error including the required role.
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
return _roles[role].hasRole[account];
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
* is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
* is missing `role`.
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
/**
* @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 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 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 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 `callerConfirmation`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
/**
* @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 Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
if (!hasRole(role, account)) {
_roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
/**
* @dev Attempts to revoke `role` from `account` and returns a boolean indicating if `role` was revoked.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}
"
},
"node_modules/@openzeppelin/contracts/interfaces/IERC5313.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC5313.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface for the Light Contract Ownership Standard.
*
* A standardized minimal interface required to identify an account that controls a contract
*/
interface IERC5313 {
/**
* @dev Gets the address of the owner.
*/
function owner() external view returns (address);
}
"
},
"src/interfaces/ISingleAdminAccessControl.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
interface ISingleAdminAccessControl {
error InvalidAdminChange();
error NotPendingAdmin();
event AdminTransferred(address indexed oldAdmin, address indexed newAdmin);
event AdminTransferRequested(address indexed oldAdmin, address indexed newAdmin);
}
"
},
"node_modules/@openzeppelin/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @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 Context {
function
Submitted on: 2025-10-20 15:01:11
Comments
Log in to comment.
No comments yet.