Description:
Proxy contract enabling upgradeable smart contract patterns. Delegates calls to an implementation contract.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"src/vendor/braid/USDZ.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {
PausableUpgradeable
} from "../../../lib/common/lib/openzeppelin-contracts-upgradeable/contracts/utils/PausableUpgradeable.sol";
import { MYieldToOne } from "../../projects/yieldToOne/MYieldToOne.sol";
import { IUSDZ } from "./IUSDZ.sol";
/**
██╗ ██╗███████╗██████╗ ███████╗
██║ ██║██╔════╝██╔══██╗╚══███╔╝
██║ ██║███████╗██║ ██║ ███╔╝
██║ ██║╚════██║██║ ██║ ███╔╝
╚██████╔╝███████║██████╔╝███████╗
╚═════╝ ╚══════╝╚═════╝ ╚══════╝
*/
/**
* @title USDZ
* @notice M extension for the USDZ token.
* @author M0 Labs
*/
contract USDZ is IUSDZ, MYieldToOne, PausableUpgradeable {
/* ============ Variables ============ */
/// @inheritdoc IUSDZ
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
/// @inheritdoc IUSDZ
bytes32 public constant FORCED_TRANSFER_MANAGER_ROLE = keccak256("FORCED_TRANSFER_MANAGER_ROLE");
/* ============ Constructor ============ */
/**
* @custom:oz-upgrades-unsafe-allow constructor
* @notice Constructs USDZ Implementation contract
* @dev `_disableInitializers()` is called in the inherited MExtension's constructor.
* @param mToken The address of the MToken
* @param swapFacility The address of the SwapFacility
*/
constructor(address mToken, address swapFacility) MYieldToOne(mToken, swapFacility) {}
/* ============ Initializer ============ */
/**
* @dev Initializes the USDZ token.
* @param yieldRecipient The address of a yield destination.
* @param admin The address of an admin.
* @param freezeManager The address of a freeze manager.
* @param yieldRecipientManager The address of a yield recipient setter.
* @param pauser The address of a pauser.
*/
function initialize(
address yieldRecipient,
address admin,
address freezeManager,
address yieldRecipientManager,
address pauser,
address forcedTransferManager
) external initializer {
if (pauser == address(0)) revert ZeroPauser();
if (forcedTransferManager == address(0)) revert ZeroForcedTransferManager();
__MYieldToOne_init("USDZ", "USDZ", yieldRecipient, admin, freezeManager, yieldRecipientManager);
__Pausable_init();
_grantRole(PAUSER_ROLE, pauser);
_grantRole(FORCED_TRANSFER_MANAGER_ROLE, forcedTransferManager);
}
/* ============ Interactive Functions ============ */
/// @inheritdoc IUSDZ
function pause() external onlyRole(PAUSER_ROLE) {
_pause();
}
/// @inheritdoc IUSDZ
function unpause() external onlyRole(PAUSER_ROLE) {
_unpause();
}
/// @inheritdoc IUSDZ
function forceTransfer(
address frozenAccount,
address recipient,
uint256 amount
) external onlyRole(FORCED_TRANSFER_MANAGER_ROLE) {
_forceTransfer(frozenAccount, recipient, amount);
}
/// @inheritdoc IUSDZ
function forceTransfers(
address[] calldata frozenAccounts,
address[] calldata recipients,
uint256[] calldata amounts
) external onlyRole(FORCED_TRANSFER_MANAGER_ROLE) {
if (frozenAccounts.length != recipients.length || frozenAccounts.length != amounts.length) {
revert ArrayLengthMismatch();
}
for (uint256 i; i < frozenAccounts.length; ++i) {
_forceTransfer(frozenAccounts[i], recipients[i], amounts[i]);
}
}
/* ============ Hooks For Internal Interactive Functions ============ */
/**
* @dev Hook called before wrapping M into USDZ.
* @param account The account from which M is deposited.
* @param recipient The account receiving the minted USDZ.
* @param amount The amount of tokens to wrap.
*/
function _beforeWrap(address account, address recipient, uint256 amount) internal view override {
_requireNotPaused();
super._beforeWrap(account, recipient, amount);
}
/**
* @dev Hook called before unwrapping USDZ.
* @param account The account from which USDZ is burned.
* @param amount The amount of tokens to unwrap.
*/
function _beforeUnwrap(address account, uint256 amount) internal view override {
_requireNotPaused();
super._beforeUnwrap(account, amount);
}
/**
* @dev Hook called before transferring USDZ.
* @param sender The address from which the tokens are being transferred.
* @param recipient The address to which the tokens are being transferred.
* @param amount The amount of tokens to transfer.
*/
function _beforeTransfer(address sender, address recipient, uint256 amount) internal view override {
_requireNotPaused();
super._beforeTransfer(sender, recipient, amount);
}
/**
* @dev Hook called before claiming yield.
* @dev MUST only be callable by the `YIELD_RECIPIENT_MANAGER_ROLE`.
* @dev Addresses with the `YIELD_RECIPIENT_MANAGER_ROLE`
* are still able to claim yield when the contract is paused.
*/
function _beforeClaimYield() internal view override onlyRole(YIELD_RECIPIENT_MANAGER_ROLE) {}
/* ============ Internal Interactive Functions ============ */
/**
* @dev Internal ERC20 force transfer function to seize funds from a frozen account.
* @param frozenAccount The frozen account from which tokens are seized.
* @param recipient The recipient's address.
* @param amount The amount to be transferred.
* @dev Force transfer is only allowed for frozen accounts.
* @dev No `_beforeTransfer` checks apply to forced transfers; ignore checks for paused and frozen states.
* @dev Since this function can only be called by the `FORCED_TRANSFER_MANAGER_ROLE`,
* we do not check if the recipient is frozen.
*/
function _forceTransfer(address frozenAccount, address recipient, uint256 amount) internal {
_revertIfInvalidRecipient(recipient);
_revertIfNotFrozen(frozenAccount);
emit Transfer(frozenAccount, recipient, amount);
emit ForcedTransfer(frozenAccount, recipient, msg.sender, amount);
if (amount == 0) return;
_revertIfInsufficientBalance(frozenAccount, amount);
_update(frozenAccount, recipient, amount);
}
}
"
},
"lib/common/lib/openzeppelin-contracts-upgradeable/contracts/utils/PausableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.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 PausableUpgradeable is Initializable, ContextUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Pausable
struct PausableStorage {
bool _paused;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Pausable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant PausableStorageLocation = 0xcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300;
function _getPausableStorage() private pure returns (PausableStorage storage $) {
assembly {
$.slot := PausableStorageLocation
}
}
/**
* @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();
_;
}
function __Pausable_init() internal onlyInitializing {
}
function __Pausable_init_unchained() internal onlyInitializing {
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
PausableStorage storage $ = _getPausableStorage();
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 {
PausableStorage storage $ = _getPausableStorage();
$._paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
PausableStorage storage $ = _getPausableStorage();
$._paused = false;
emit Unpaused(_msgSender());
}
}
"
},
"src/projects/yieldToOne/MYieldToOne.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import { IERC20 } from "../../../lib/common/src/interfaces/IERC20.sol";
import { IMYieldToOne } from "./IMYieldToOne.sol";
import { Freezable } from "../../components/Freezable.sol";
import { MExtension } from "../../MExtension.sol";
abstract contract MYieldToOneStorageLayout {
/// @custom:storage-location erc7201:M0.storage.MYieldToOne
struct MYieldToOneStorageStruct {
uint256 totalSupply;
address yieldRecipient;
mapping(address account => uint256 balance) balanceOf;
}
// keccak256(abi.encode(uint256(keccak256("M0.storage.MYieldToOne")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant _M_YIELD_TO_ONE_STORAGE_LOCATION =
0xee2f6fc7e2e5879b17985791e0d12536cba689bda43c77b8911497248f4af100;
function _getMYieldToOneStorageLocation() internal pure returns (MYieldToOneStorageStruct storage $) {
assembly {
$.slot := _M_YIELD_TO_ONE_STORAGE_LOCATION
}
}
}
/**
* @title MYieldToOne
* @notice Upgradeable ERC20 Token contract for wrapping M into a non-rebasing token
* with yield claimable by a single recipient.
* @author M0 Labs
*/
contract MYieldToOne is IMYieldToOne, MYieldToOneStorageLayout, MExtension, Freezable {
/* ============ Variables ============ */
/// @inheritdoc IMYieldToOne
bytes32 public constant YIELD_RECIPIENT_MANAGER_ROLE = keccak256("YIELD_RECIPIENT_MANAGER_ROLE");
/* ============ Constructor ============ */
/**
* @custom:oz-upgrades-unsafe-allow constructor
* @notice Constructs MYieldToOne Implementation contract
* @dev Sets immutable storage.
* @param mToken The address of $M token.
* @param swapFacility The address of Swap Facility.
*/
constructor(address mToken, address swapFacility) MExtension(mToken, swapFacility) {}
/* ============ Initializer ============ */
/**
* @dev Initializes the M extension token with yield claimable by a single recipient.
* @param name The name of the token (e.g. "M Yield to One").
* @param symbol The symbol of the token (e.g. "MYO").
* @param yieldRecipient_ The address of a yield destination.
* @param admin The address of an admin.
* @param freezeManager The address of a freeze manager.
* @param yieldRecipientManager The address of a yield recipient setter.
*/
function initialize(
string memory name,
string memory symbol,
address yieldRecipient_,
address admin,
address freezeManager,
address yieldRecipientManager
) public virtual initializer {
__MYieldToOne_init(name, symbol, yieldRecipient_, admin, freezeManager, yieldRecipientManager);
}
/**
* @notice Initializes the MYieldToOne token.
* @param name The name of the token (e.g. "M Yield to One").
* @param symbol The symbol of the token (e.g. "MYO").
* @param yieldRecipient_ The address of a yield destination.
* @param admin The address of an admin.
* @param freezeManager The address of a freeze manager.
* @param yieldRecipientManager The address of a yield recipient setter.
*/
function __MYieldToOne_init(
string memory name,
string memory symbol,
address yieldRecipient_,
address admin,
address freezeManager,
address yieldRecipientManager
) internal onlyInitializing {
if (yieldRecipientManager == address(0)) revert ZeroYieldRecipientManager();
if (admin == address(0)) revert ZeroAdmin();
__MExtension_init(name, symbol);
__Freezable_init(freezeManager);
_setYieldRecipient(yieldRecipient_);
_grantRole(DEFAULT_ADMIN_ROLE, admin);
_grantRole(YIELD_RECIPIENT_MANAGER_ROLE, yieldRecipientManager);
}
/* ============ Interactive Functions ============ */
/// @inheritdoc IMYieldToOne
function claimYield() public returns (uint256) {
_beforeClaimYield();
uint256 yield_ = yield();
if (yield_ == 0) return 0;
emit YieldClaimed(yield_);
_mint(yieldRecipient(), yield_);
return yield_;
}
/// @inheritdoc IMYieldToOne
function setYieldRecipient(address account) external onlyRole(YIELD_RECIPIENT_MANAGER_ROLE) {
// Claim yield for the previous yield recipient.
claimYield();
_setYieldRecipient(account);
}
/* ============ View/Pure Functions ============ */
/// @inheritdoc IERC20
function balanceOf(address account) public view override returns (uint256) {
return _getMYieldToOneStorageLocation().balanceOf[account];
}
/// @inheritdoc IERC20
function totalSupply() public view returns (uint256) {
return _getMYieldToOneStorageLocation().totalSupply;
}
/// @inheritdoc IMYieldToOne
function yield() public view returns (uint256) {
unchecked {
uint256 balance_ = _mBalanceOf(address(this));
uint256 totalSupply_ = totalSupply();
return balance_ > totalSupply_ ? balance_ - totalSupply_ : 0;
}
}
/// @inheritdoc IMYieldToOne
function yieldRecipient() public view returns (address) {
return _getMYieldToOneStorageLocation().yieldRecipient;
}
/* ============ Hooks For Internal Interactive Functions ============ */
/**
* @dev Hooks called before approval of M extension spend.
* @param account The account from which M is deposited.
* @param spender The account spending M Extension token.
*/
function _beforeApprove(address account, address spender, uint256 /* amount */) internal view virtual override {
FreezableStorageStruct storage $ = _getFreezableStorageLocation();
_revertIfFrozen($, account);
_revertIfFrozen($, spender);
}
/**
* @dev Hooks called before wrapping M into M Extension token.
* @param account The account from which M is deposited.
* @param recipient The account receiving the minted M Extension token.
*/
function _beforeWrap(address account, address recipient, uint256 /* amount */) internal view virtual override {
FreezableStorageStruct storage $ = _getFreezableStorageLocation();
_revertIfFrozen($, account);
_revertIfFrozen($, recipient);
}
/**
* @dev Hook called before unwrapping M Extension token.
* @param account The account from which M Extension token is burned.
*/
function _beforeUnwrap(address account, uint256 /* amount */) internal view virtual override {
_revertIfFrozen(_getFreezableStorageLocation(), account);
}
/**
* @dev Hook called before transferring M Extension token.
* @param sender The address from which the tokens are being transferred.
* @param recipient The address to which the tokens are being transferred.
*/
function _beforeTransfer(address sender, address recipient, uint256 /* amount */) internal view virtual override {
FreezableStorageStruct storage $ = _getFreezableStorageLocation();
_revertIfFrozen($, msg.sender);
_revertIfFrozen($, sender);
_revertIfFrozen($, recipient);
}
/**
* @dev Hook called before claiming yield from the M Extension token. To be overridden in derived extensions.
*/
function _beforeClaimYield() internal view virtual {}
/* ============ Internal Interactive Functions ============ */
/**
* @dev Mints `amount` tokens to `recipient`.
* @param recipient The address whose account balance will be incremented.
* @param amount The present amount of tokens to mint.`
*/
function _mint(address recipient, uint256 amount) internal override {
MYieldToOneStorageStruct storage $ = _getMYieldToOneStorageLocation();
// NOTE: Can be `unchecked` because the max amount of $M is never greater than `type(uint240).max`.
unchecked {
$.balanceOf[recipient] += amount;
$.totalSupply += amount;
}
emit Transfer(address(0), recipient, amount);
}
/**
* @dev Burns `amount` tokens from `account`.
* @param account The address whose account balance will be decremented.
* @param amount The present amount of tokens to burn.
*/
function _burn(address account, uint256 amount) internal override {
MYieldToOneStorageStruct storage $ = _getMYieldToOneStorageLocation();
// NOTE: Can be `unchecked` because `_revertIfInsufficientBalance` is used in MExtension.
unchecked {
$.balanceOf[account] -= amount;
$.totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
}
/**
* @dev Internal balance update function called on transfer.
* @param sender The sender's address.
* @param recipient The recipient's address.
* @param amount The amount to be transferred.
*/
function _update(address sender, address recipient, uint256 amount) internal override {
MYieldToOneStorageStruct storage $ = _getMYieldToOneStorageLocation();
// NOTE: Can be `unchecked` because `_revertIfInsufficientBalance` for `sender` is used in MExtension.
unchecked {
$.balanceOf[sender] -= amount;
$.balanceOf[recipient] += amount;
}
}
/**
* @dev Sets the yield recipient.
* @param yieldRecipient_ The address of the new yield recipient.
*/
function _setYieldRecipient(address yieldRecipient_) internal {
if (yieldRecipient_ == address(0)) revert ZeroYieldRecipient();
MYieldToOneStorageStruct storage $ = _getMYieldToOneStorageLocation();
if (yieldRecipient_ == $.yieldRecipient) return;
$.yieldRecipient = yieldRecipient_;
emit YieldRecipientSet(yieldRecipient_);
}
}
"
},
"src/vendor/braid/IUSDZ.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
/**
* @title USDZ Interface
* @author M0 Labs
*
*/
interface IUSDZ {
/* ============ Events ============ */
/**
* @notice Emitted when tokens are forcefully transferred from a frozen account.
* @param frozenAccount The address of the frozen account.
* @param recipient The address of the recipient.
* @param forcedTransferManager The address of the force transfer manager that triggered the event.
* @param amount The amount of tokens transferred.
*/
event ForcedTransfer(
address indexed frozenAccount,
address indexed recipient,
address indexed forcedTransferManager,
uint256 amount
);
/* ============ Custom Errors ============ */
/// @notice Emitted in constructor if Pauser is 0x0.
error ZeroPauser();
/// @notice Emitted in constructor if Force Transfer Manager is 0x0.
error ZeroForcedTransferManager();
/// @notice Emitted when the length of the input arrays do not match in `forceTransfer` method.
error ArrayLengthMismatch();
/* ============ Interactive Functions ============ */
/**
* @notice Pauses the contract.
* @dev Can only be called by an account with the PAUSER_ROLE.
* @dev When paused, wrap/unwrap and transfer of tokens are disabled.
* Approval is still enabled to allow users to change their allowances.
* Addresses with the FORCED_TRANSFER_MANAGER_ROLE can still transfer tokens from frozen accounts.
* Addresses with the FREEZE_MANAGER_ROLE can still freeze and unfreeze accounts.
* Addresses with the YIELD_RECIPIENT_MANAGER_ROLE can still claim yield.
*/
function pause() external;
/**
* @notice Unpauses the contract.
* @dev Can only be called by an account with the PAUSER_ROLE.
*/
function unpause() external;
/**
* @notice Forcefully transfers tokens from a frozen account to a recipient.
* @dev Can only be called by an account with the FORCED_TRANSFER_MANAGER_ROLE.
* @param frozenAccount The address of the frozen account.
* @param recipient The address of the recipient.
* @param amount The amount of tokens to transfer.
*/
function forceTransfer(address frozenAccount, address recipient, uint256 amount) external;
/**
* @notice Forcefully transfers tokens from frozen accounts to recipients.
* @dev Can only be called by an account with the FORCED_TRANSFER_MANAGER_ROLE.
* @param frozenAccounts The addresses of the frozen accounts.
* @param recipients The addresses of the recipients.
* @param amounts The amounts of tokens to transfer.
*/
function forceTransfers(
address[] calldata frozenAccounts,
address[] calldata recipients,
uint256[] calldata amounts
) external;
/* ============ View/Pure Functions ============ */
/// @notice The role that can pause and unpause the contract.
function PAUSER_ROLE() external view returns (bytes32);
/// @notice The role that can force transfer tokens from frozen accounts.
function FORCED_TRANSFER_MANAGER_ROLE() external view returns (bytes32);
}
"
},
"lib/common/lib/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
"
},
"lib/common/lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @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 Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 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 in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reinitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._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 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._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() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @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 {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Pointer to storage slot. Allows integrators to override it with a custom storage location.
*
* NOTE: Consider following the ERC-7201 formula to derive storage locations.
*/
function _initializableStorageSlot() internal pure virtual returns (bytes32) {
return INITIALIZABLE_STORAGE;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
bytes32 slot = _initializableStorageSlot();
assembly {
$.slot := slot
}
}
}
"
},
"lib/common/src/interfaces/IERC20.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.20 <0.9.0;
/**
* @title ERC20 Token Standard.
* @author M^0 Labs
* @dev The interface as defined by EIP-20: https://eips.ethereum.org/EIPS/eip-20
*/
interface IERC20 {
/* ============ Events ============ */
/**
* @notice Emitted when `spender` has been approved for `amount` of the token balance of `account`.
* @param account The address of the account.
* @param spender The address of the spender being approved for the allowance.
* @param amount The amount of the allowance being approved.
*/
event Approval(address indexed account, address indexed spender, uint256 amount);
/**
* @notice Emitted when `amount` tokens is transferred from `sender` to `recipient`.
* @param sender The address of the sender who's token balance is decremented.
* @param recipient The address of the recipient who's token balance is incremented.
* @param amount The amount of tokens being transferred.
*/
event Transfer(address indexed sender, address indexed recipient, uint256 amount);
/* ============ Interactive Functions ============ */
/**
* @notice Allows a calling account to approve `spender` to spend up to `amount` of its token balance.
* @dev MUST emit an `Approval` event.
* @param spender The address of the account being allowed to spend up to the allowed amount.
* @param amount The amount of the allowance being approved.
* @return Whether or not the approval was successful.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @notice Allows a calling account to transfer `amount` tokens to `recipient`.
* @param recipient The address of the recipient who's token balance will be incremented.
* @param amount The amount of tokens being transferred.
* @return Whether or not the transfer was successful.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @notice Allows a calling account to transfer `amount` tokens from `sender`, with allowance, to a `recipient`.
* @param sender The address of the sender who's token balance will be decremented.
* @param recipient The address of the recipient who's token balance will be incremented.
* @param amount The amount of tokens being transferred.
* @return Whether or not the transfer was successful.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/* ============ View/Pure Functions ============ */
/**
* @notice Returns the allowance `spender` is allowed to spend on behalf of `account`.
* @param account The address of the account who's token balance `spender` is allowed to spend.
* @param spender The address of an account allowed to spend on behalf of `account`.
* @return The amount `spender` can spend on behalf of `account`.
*/
function allowance(address account, address spender) external view returns (uint256);
/**
* @notice Returns the token balance of `account`.
* @param account The address of some account.
* @return The token balance of `account`.
*/
function balanceOf(address account) external view returns (uint256);
/// @notice Returns the number of decimals UIs should assume all amounts have.
function decimals() external view returns (uint8);
/// @notice Returns the name of the contract/token.
function name() external view returns (string memory);
/// @notice Returns the symbol of the token.
function symbol() external view returns (string memory);
/// @notice Returns the current total supply of the token.
function totalSupply() external view returns (uint256);
}
"
},
"src/projects/yieldToOne/IMYieldToOne.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
/**
* @title M Extension where all yield is claimable by a single recipient.
* @author M0 Labs
*/
interface IMYieldToOne {
/* ============ Events ============ */
/**
* @notice Emitted when this contract's excess M is claimed.
* @param yield The amount of M yield claimed.
*/
event YieldClaimed(uint256 yield);
/**
* @notice Emitted when the yield recipient is set.
* @param yieldRecipient The address of the new yield recipient.
*/
event YieldRecipientSet(address indexed yieldRecipient);
/* ============ Custom Errors ============ */
/// @notice Emitted in constructor if Yield Recipient is 0x0.
error ZeroYieldRecipient();
/// @notice Emitted in constructor if Yield Recipient Manager is 0x0.
error ZeroYieldRecipientManager();
/// @notice Emitted in constructor if Admin is 0x0.
error ZeroAdmin();
/* ============ Interactive Functions ============ */
/// @notice Claims accrued yield to yield recipient.
function claimYield() external returns (uint256);
/**
* @notice Sets the yield recipient.
* @dev MUST only be callable by the YIELD_RECIPIENT_MANAGER_ROLE.
* @dev SHOULD revert if `yieldRecipient` is 0x0.
* @dev SHOULD return early if the `yieldRecipient` is already the actual yield recipient.
* @param yieldRecipient The address of the new yield recipient.
*/
function setYieldRecipient(address yieldRecipient) external;
/* ============ View/Pure Functions ============ */
/// @notice The role that can manage the yield recipient.
function YIELD_RECIPIENT_MANAGER_ROLE() external view returns (bytes32);
/// @notice The amount of accrued yield.
function yield() external view returns (uint256);
/// @notice The address of the yield recipient.
function yieldRecipient() external view returns (address);
}
"
},
"src/components/Freezable.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {
AccessControlUpgradeable
} from "../../lib/common/lib/openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol";
import { IFreezable } from "./IFreezable.sol";
abstract contract FreezableStorageLayout {
/// @custom:storage-location erc7201:M0.storage.Freezable
struct FreezableStorageStruct {
mapping(address account => bool isFrozen) isFrozen;
}
// keccak256(abi.encode(uint256(keccak256("M0.storage.Freezable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant _FREEZABLE_STORAGE_LOCATION =
0x2fd5767309dce890c526ace85d7fe164825199d7dcd99c33588befc51b32ce00;
function _getFreezableStorageLocation() internal pure returns (FreezableStorageStruct storage $) {
assembly {
$.slot := _FREEZABLE_STORAGE_LOCATION
}
}
}
/**
* @title Freezable
* @notice Upgradeable contract that allows for the freezing of accounts.
* @dev This contract is used to prevent certain accounts from interacting with the contract.
* @author M0 Labs
*/
abstract contract Freezable is IFreezable, FreezableStorageLayout, AccessControlUpgradeable {
/* ============ Variables ============ */
/// @inheritdoc IFreezable
bytes32 public constant FREEZE_MANAGER_ROLE = keccak256("FREEZE_MANAGER_ROLE");
/* ============ Initializer ============ */
/**
* @notice Initializes the contract with the given freeze manager.
* @param freezeManager The address of a freeze manager.
*/
function __Freezable_init(address freezeManager) internal onlyInitializing {
if (freezeManager == address(0)) revert ZeroFreezeManager();
_grantRole(FREEZE_MANAGER_ROLE, freezeManager);
}
/* ============ Interactive Functions ============ */
/// @inheritdoc IFreezable
function freeze(address account) external onlyRole(FREEZE_MANAGER_ROLE) {
_freeze(_getFreezableStorageLocation(), account);
}
/// @inheritdoc IFreezable
function freezeAccounts(address[] calldata accounts) external onlyRole(FREEZE_MANAGER_ROLE) {
FreezableStorageStruct storage $ = _getFreezableStorageLocation();
for (uint256 i; i < accounts.length; ++i) {
_freeze($, accounts[i]);
}
}
/// @inheritdoc IFreezable
function unfreeze(address account) external onlyRole(FREEZE_MANAGER_ROLE) {
_unfreeze(_getFreezableStorageLocation(), account);
}
/// @inheritdoc IFreezable
function unfreezeAccounts(address[] calldata accounts) external onlyRole(FREEZE_MANAGER_ROLE) {
FreezableStorageStruct storage $ = _getFreezableStorageLocation();
for (uint256 i; i < accounts.length; ++i) {
_unfreeze($, accounts[i]);
}
}
/* ============ View/Pure Functions ============ */
/// @inheritdoc IFreezable
function isFrozen(address account) public view returns (bool) {
return _getFreezableStorageLocation().isFrozen[account];
}
/* ============ Internal Interactive Functions ============ */
/**
* @notice Internal function that freezes an account.
* @param $ The storage location of the freezable contract.
* @param account The account to freeze.
*/
function _freeze(FreezableStorageStruct storage $, address account) internal {
// Return early if the account is already frozen
if ($.isFrozen[account]) return;
$.isFrozen[account] = true;
emit Frozen(account, block.timestamp);
}
/**
* @notice Internal function that unfreezes an account.
* @param $ The storage location of the freezable contract.
* @param account The account to unfreeze.
*/
function _unfreeze(FreezableStorageStruct storage $, address account) internal {
// Return early if the account is not frozen
if (!$.isFrozen[account]) return;
$.isFrozen[account] = false;
emit Unfrozen(account, block.timestamp);
}
/* ============ Internal View/Pure Functions ============ */
/**
* @notice Internal function that reverts if an account is frozen.
* @dev Called by inheriting contracts to check if an account is frozen.
* @param $ The storage location of the freezable contract.
* @param account The account to check.
*/
function _revertIfFrozen(FreezableStorageStruct storage $, address account) internal view {
if ($.isFrozen[account]) revert AccountFrozen(account);
}
/**
* @notice Internal function that reverts if an account is frozen.
* @dev Called by inheriting contracts to check if an account is frozen.
* @param account The account to check.
*/
function _revertIfFrozen(address account) internal view {
if (_getFreezableStorageLocation().isFrozen[account]) revert AccountFrozen(account);
}
/**
* @notice Internal function that reverts if an account is not frozen.
* @dev Called by inheriting contracts to check if an account is not frozen.
* @param $ The storage location of the freezable contract.
* @param account The account to check.
*/
function _revertIfNotFrozen(FreezableStorageStruct storage $, address account) internal view {
if (!$.isFrozen[account]) revert AccountNotFrozen(account);
}
/**
* @notice Internal function that reverts if an account is not frozen.
* @dev Called by inheriting contracts to check if an account is not frozen.
* @param account The account to check.
*/
function _revertIfNotFrozen(address account) internal view {
if (!_getFreezableStorageLocation().isFrozen[account]) revert AccountNotFrozen(account);
}
}
"
},
"src/MExtension.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import { ERC20ExtendedUpgradeable } from "../lib/common/src/ERC20ExtendedUpgradeable.sol";
import { IERC20 } from "../lib/common/src/interfaces/IERC20.sol";
import { IMTokenLike } from "./interfaces/IMTokenLike.sol";
import { IMExtension } from "./interfaces/IMExtension.sol";
import { ISwapFacility } from "./swap/interfaces/ISwapFacility.sol";
/**
* @title MExtension
* @notice Upgradeable ERC20 Token contract for wrapping M into a non-rebasing token.
* @author M0 Labs
*/
abstract contract MExtension is IMExtension, ERC20ExtendedUpgradeable {
/* ============ Variables ============ */
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
/// @inheritdoc IMExtension
address public immutable mToken;
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
/// @inheritdoc IMExtension
address public immutable swapFacility;
/* ============ Modifiers ============ */
/// @dev Modifier to check if caller is SwapFacility.
modifier onlySwapFacility() {
if (msg.sender != swapFacility) revert NotSwapFacility();
_;
}
/* ============ Constructor ============ */
/**
* @custom:oz-upgrades-unsafe-allow constructor
* @notice Constructs MExtension Implementation contract
* @dev Sets immutable storage.
* @param mToken_ The address of $M token.
* @param swapFacility_ The address of Swap Facility.
*/
constructor(address mToken_, address swapFacility_) {
_disableInitializers();
if ((mToken = mToken_) == address(0)) revert ZeroMToken();
if ((swapFacility = swapFacility_) == address(0)) revert ZeroSwapFacility();
}
/* ============ Initializer ============ */
/**
* @notice Initializes the generic M extension token.
* @param name The name of the token (e.g. "HALO USD").
* @param symbol The symbol of the token (e.g. "HUSD").
*/
function __MExtension_init(string memory name, string memory symbol) internal onlyInitializing {
__ERC20ExtendedUpgradeable_init(name, symbol, 6);
}
/* ============ Interactive Functions ============ */
/// @inheritdoc IMExtension
function wrap(address recipient, uint256 amount) external onlySwapFacility {
// NOTE: `msg.sender` is always SwapFacility contract.
// `ISwapFacility.msgSender()` is used to ensure that the original caller is passed to `_beforeWrap`.
_wrap(ISwapFacility(msg.sender).msgSender(), recipient, amount);
}
/// @inheritdoc IMExtension
function unwrap(address /* recipient */, uint256 amount) external onlySwapFacility {
// NOTE: `msg.sender` is always SwapFacility contract.
// `ISwapFacility.msgSender()` is used to ensure that the original caller is passed to `_beforeUnwrap`.
// NOTE: `recipient` is not used in this function as the $M is always sent to SwapFacility contract.
_unwrap(ISwapFacility(msg.sender).msgSender(), amount);
}
/// @inheritdoc IMExtension
function enableEarning() external virtual {
if (isEarningEnabled()) revert EarningIsEnabled();
emit EarningEnabled(currentIndex());
IMTokenLike(mToken).startEarning();
}
/// @inheritdoc IMExtension
function disableEarning() external virtual {
if (!isEarningEnabled()) revert EarningIsDisabled();
emit EarningDisabled(currentIndex());
IMTokenLike(mToken).stopEarning(address(this));
}
/* ============ View/Pure Functions ============ */
/// @inheritdoc IMExtension
function currentIndex() public view virtual returns (uint128) {
return IMTokenLike(mToken).currentIndex();
}
/// @inheritdoc IMExtension
function isEarningEnabled() public view virtual returns (bool) {
return IMTokenLike(mToken).isEarning(address(this));
}
/// @inheritdoc IERC20
function balanceOf(address account) public view virtual returns (uint256);
/* ============ Hooks For Internal Interactive Functions ============ */
/**
* @dev Hook called before approval of M Extension token.
* @param account The sender's address.
* @param spender The spender address.
* @param amount The amount to be approved.
*/
function _beforeApprove(address account, address spender, uint256 amount) internal virtual {}
/**
* @dev Hook called before wrapping M into M Extension token.
* @param account The account from which M is deposited.
* @param recipient The account receiving the minted M Extension token.
* @param amount The amount of M deposited.
*/
function _beforeWrap(address account, address recipient, uint256 amount) internal virtual {}
/**
* @dev Hook called before unwrapping M Extension token.
* @param account The account from which M Extension token is burned.
* @param amount The amount of M Extension token burned.
*/
function _beforeUnwrap(address account, uint256 amount) internal virtual {}
/**
* @dev Hook called before transferring M Extension token.
* @param sender The sender's address.
* @param recipient The recipient's address.
* @param amount The amount to be transferred.
*/
function _beforeTransfer(address sender, address recipient, uint256 amount) internal virtual {}
/* ============ Internal Interactive Functions ============ */
/**
* @dev Approve `spender` to spend `amount` of tokens from `account`.
* @param account The address approving the allowance.
* @param spender The address approved to spend the tokens.
* @param amount The amount of tokens being approved for spending.
*/
function _approve(address account, address spender, uint256 amount) internal override {
// NOTE: Add extension-specific checks before approval.
_beforeApprove(account, spender, amount);
super._approve(account, spender, amount);
}
/**
* @dev Wraps `amount` M from `account` into M Extension for `recipient`.
* @param account The original caller of SwapFacility functions.
* @param recipient The account receiving the minted M Extension token.
* @param amount The amount of M deposited.
*/
function _wrap(address account, address recipient, uint256 amount) internal {
_revertIfInvalidRecipient(recipient);
_revertIfInsufficientAmount(amount);
// NOTE: Add extension-specific checks before wrapping.
_beforeWrap(account, recipient, amount);
// NOTE: `msg.sender` is always SwapFacility contract.
// NOTE: The behavior of `IMTokenLike.transferFrom` is known, so its return can be ignored.
IMTokenLike(mToken).transferFrom(msg.sender, address(this), amount);
// NOTE: This method is overridden by the inheriting M Extension contract.
// NOTE: Mints precise amount of $M Extension token to `recipient`.
// Option 1: $M transfer from an $M earner to another $M earner ($M Extension in earning state): rounds up → rounds up,
// 0, 1, or XX extra wei may be locked in M Extension compared to the minted amount of $M Extension token.
// Option 2: $M transfer from an $M non-earner to an $M earner ($M Extension in earning state): precise $M transfer → rounds down,
// 0, -1, or -XX wei may be locked in $M Extension compared to the minted amount of $M Extension token.
//
_mint(recipient, amount);
}
/**
* @dev Unwraps `amount` M Extension token from `account` into $M and transfers to SwapFacility.
* @param account The original caller of SwapFacility functions.
* @param amount The amount of M Extension token burned.
*/
function _unwrap(address account, uint256 amount) internal {
_revertIfInsufficientAmount(amount);
// NOTE: Add extension-specific checks before unwrapping.
_beforeUnwrap(account, amount);
_revertIfInsufficientBalance(msg.sender, amount);
// NOTE: This method will be overridden by the inheriting M Extension contract.
// NOTE: Computes the actual decrease in the $M balance of the $M Extension contract.
// Option 1: $M transfer from an $M earner ($M Extension in earning state) to another $M earner: round up → rounds up.
// Option 2: $M transfer from an $M earner ($M Extension in earning state) to an $M non-earner: round up → precise $M transfer.
// In both cases, 0, 1, or XX extra wei may be deducted from the $M Extension contract's $M balance compared to the burned amount of $M Extension token.
// NOTE: Always burn from SwapFacility as it is the only contract that can call this function.
_burn(msg.sender, amount);
// NOTE: The behavior of `IMTokenLike.transfer` is known, so its return can be ignored.
// NOTE: `msg.sender` is always SwapFacility contract.
IMTokenLike(mToken).transfer(msg.sender, amount);
}
/**
* @dev Mints `amount` tokens to `recipient`.
* @param recipient The address to which the tokens will be minted.
* @param amount The amount of tokens to mint.
*/
function _mint(address recipient, uint256 amount) internal virtual;
/**
* @dev Burns `amount` tokens from `account`.
* @param account The address from which the tokens will be burned.
* @param amount The amount of tokens to burn.
*/
function _burn(address account, uint256 amount) internal virtual;
/**
* @dev Internal balance update function that needs to be implemented by the inheriting contract.
* @param sender The sender's address.
* @param recipient The recipient's address.
* @param amount The amount to be transferred.
*/
function _update(address sender, address recipient, uint256 amount) internal virtual;
/**
* @dev Internal ERC20 transfer function.
* @param sender The sender's address.
* @param recipient The recipient's address.
* @param amount The amount to be transferred.
*/
function _transfer(address sender, address recipient, uint256 amount) internal override {
_revertIfInvalidRecipient(recipient);
// NOTE: Add extension-specific checks before transfers.
_beforeTransfer(sender, recipient, amount);
emit Transfer(sender, recipient, amount);
if (amount == 0) return;
_revertIfInsufficientBalance(sender, amount);
// NOTE: This method will be overridden by the inheriting M Extension contract.
_update(sender, recipient, amount);
}
/* ============ Internal View/Pure Functions ============ */
/**
* @dev Returns the M Token balance of `account`.
* @param account The account being queried.
* @return balance The M Token balance of the account.
*/
function _mBalanceOf(address account) internal view returns (uint256) {
return IMTokenLike(mToken).balanceOf(account);
}
/**
* @dev Reverts if `recipient` is address(0).
* @param recipient Address of a recipient.
*/
function _revertIfInvalidRecipient(address recipient) internal pure {
if (recipient == address(0)) revert InvalidRecipient(recipient);
}
/**
* @dev Reverts if `amount` is equal to 0.
* @param amount Amount of token.
*/
function _revertIfInsufficientAmount(uint256 amount) internal pure {
if (amount == 0) revert InsufficientAmount(amount);
}
/**
* @dev Reverts if `account` balance is below `amount`.
* @param account Address of an account.
* @param amount Amount to transfer or burn.
*/
function _revertIfInsufficientBalance(address account, uint256 amount) internal view {
uint256 balance = balanceOf(account);
if (balance < amount) revert InsufficientBalance(account, balance, amount);
}
}
"
},
"lib/common/lib/openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {ERC165Upgradeable} from "../utils/introspection/ERC165Upgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControl, ERC165Upgradeable {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/// @custom:storage-location erc7201:openzeppelin.storage.AccessControl
struct AccessControlStorage {
mapping(bytes32 role => RoleData) _roles;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AccessControl")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant AccessControlStorageLocation = 0x02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800;
function _getAccessControlStorage() private pure returns (AccessControlStorage storage $) {
assembly {
$.slot := AccessControlStorageLocation
}
}
/**
* @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);
_;
}
function __AccessControl_init() internal onlyInitializing {
}
function __AccessControl_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(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) {
AccessControlStorage storage $ = _getAccessControlStorage();
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 {_set
Submitted on: 2025-10-12 10:04:14
Comments
Log in to comment.
No comments yet.