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/DeploiNotes3475.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "./interfaces/IERC3475.sol";
/* -------- Upgradeable base (OZ v5) -------- */
import {Initializable} from "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import {UUPSUpgradeable} from "openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol";
import {AccessControlUpgradeable} from "openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol";
import {PausableUpgradeable} from "openzeppelin-contracts-upgradeable/contracts/utils/PausableUpgradeable.sol";
contract DeploiNotes3475 is
Initializable,
UUPSUpgradeable,
AccessControlUpgradeable,
PausableUpgradeable,
IERC3475
{
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE"); // issue/redeem/burn
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");
uint256 private constant MAX_BATCH = 64;
struct Nonce {
mapping(uint256 => string) valuesId;
mapping(string => Values) values;
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) allowances;
uint256 activeSupply;
uint256 burnedSupply;
uint256 redeemedSupply;
uint256 issuance;
uint256 maturity;
}
struct Class {
mapping(uint256 => string) valuesId;
mapping(string => Values) values;
mapping(uint256 => Nonce) nonces;
}
mapping(uint256 => Class) private _classes;
// approvals
mapping(address => mapping(address => bool)) private operatorApproved;
// whitelist + caps
mapping(address => bool) private _wl;
mapping(uint256 => mapping(uint256 => uint256)) private _seriesCap; // per (class, nonce); 0=off
mapping(uint256 => mapping(uint256 => mapping(address => uint256))) private _investorCap; // 0=off
event WhitelistSet(address indexed account, bool ok);
event SeriesCapSet(uint256 indexed classId, uint256 indexed nonceId, uint256 cap);
event InvestorCapSet(uint256 indexed classId, uint256 indexed nonceId, address indexed investor, uint256 cap);
// metadata (optional)
Metadata[] private classMeta;
mapping(uint256 => Metadata[]) private nonceMeta;
struct NonceParams { uint256 issuance; uint256 maturity; }
mapping(uint256 => mapping(uint256 => NonceParams)) private nonceParams;
event Approval(address indexed owner, address indexed spender, uint256 indexed classId, uint256 nonceId, uint256 amount);
event NonceScheduleSet(uint256 indexed classId, uint256 indexed nonceId, uint256 issuance, uint256 maturity);
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() { _disableInitializers(); }
function initialize(address admin) external initializer {
require(admin != address(0), "ZERO_ADDR");
__UUPSUpgradeable_init();
__AccessControl_init();
__Pausable_init();
_grantRole(DEFAULT_ADMIN_ROLE, admin);
_grantRole(UPGRADER_ROLE, admin);
_grantRole(OPERATOR_ROLE, admin);
_wl[admin] = true;
}
/* ---------- Admin / compliance ---------- */
function _authorizeUpgrade(address) internal override onlyRole(UPGRADER_ROLE) {}
function pause() external onlyRole(DEFAULT_ADMIN_ROLE) { _pause(); }
function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) { _unpause(); }
function setWhitelist(address a, bool ok) external onlyRole(DEFAULT_ADMIN_ROLE) {
_wl[a] = ok;
emit WhitelistSet(a, ok);
}
function setSeriesCap(uint256 c, uint256 n, uint256 cap) external onlyRole(DEFAULT_ADMIN_ROLE) {
uint256 active = _classes[c].nonces[n].activeSupply;
require(cap == 0 || cap >= active, "CAP<ACTIVE");
_seriesCap[c][n] = cap;
emit SeriesCapSet(c, n, cap);
}
function setInvestorCap(uint256 c, uint256 n, address who, uint256 cap) external onlyRole(DEFAULT_ADMIN_ROLE) {
require(cap == 0 || cap >= _classes[c].nonces[n].balances[who], "CAP<BAL");
_investorCap[c][n][who] = cap;
emit InvestorCapSet(c, n, who, cap);
}
// metadata (optional)
function pushClassMetadata(Metadata calldata m) external onlyRole(DEFAULT_ADMIN_ROLE) {
classMeta.push(m);
}
function pushNonceMetadata(uint256 c, Metadata calldata m) external onlyRole(DEFAULT_ADMIN_ROLE) {
nonceMeta[c].push(m);
}
function setNonceSchedule(uint256 c, uint256 n, uint256 issuance, uint256 maturity) external onlyRole(DEFAULT_ADMIN_ROLE) {
_classes[c].nonces[n].issuance = issuance;
_classes[c].nonces[n].maturity = maturity;
emit NonceScheduleSet(c, n, issuance, maturity);
}
/* ---------- Approvals ---------- */
function setApprovalFor(address op, bool ok) external override whenNotPaused {
operatorApproved[msg.sender][op] = ok;
emit ApprovalFor(msg.sender, op, ok);
}
function approve(address spender, Transaction[] calldata txs) external override whenNotPaused {
uint256 len = txs.length;
require(len > 0 && len <= MAX_BATCH, "BATCH");
for (uint256 i; i < len; ) {
Transaction calldata t = txs[i];
uint256 cur = _classes[t.classId].nonces[t.nonceId].allowances[msg.sender][spender];
require(t._amount == 0 || cur == 0, "ALLOW_NONZERO");
_classes[t.classId].nonces[t.nonceId].allowances[msg.sender][spender] = t._amount;
emit Approval(msg.sender, spender, t.classId, t.nonceId, t._amount);
unchecked { ++i; }
}
}
/* ---------- Transfers ---------- */
function transferFrom(address from, address to, Transaction[] calldata txs) external override whenNotPaused {
require(from != address(0) && to != address(0), "ADDR");
require(msg.sender == from || operatorApproved[from][msg.sender], "AUTH");
require(_wl[from] && _wl[to], "WL");
uint256 len = txs.length;
require(len > 0 && len <= MAX_BATCH, "BATCH");
for (uint256 i; i < len; ) {
Transaction calldata t = txs[i];
require(t._amount > 0, "AMT");
_debit(from, t.classId, t.nonceId, t._amount);
_enforceInvestorCap(to, t.classId, t.nonceId, t._amount);
_credit(to, t.classId, t.nonceId, t._amount);
unchecked { ++i; }
}
emit Transfer(msg.sender, from, to, txs);
}
function transferAllowanceFrom(address from, address to, Transaction[] calldata txs) external override whenNotPaused {
require(from != address(0) && to != address(0), "ADDR");
require(_wl[from] && _wl[to], "WL");
uint256 len = txs.length;
require(len > 0 && len <= MAX_BATCH, "BATCH");
for (uint256 i; i < len; ) {
Transaction calldata t = txs[i];
require(t._amount > 0, "AMT");
Nonce storage n = _classes[t.classId].nonces[t.nonceId];
uint256 currentAllowance = n.allowances[from][msg.sender];
require(currentAllowance >= t._amount, "ALLOW");
unchecked { n.allowances[from][msg.sender] = currentAllowance - t._amount; }
_debit(from, t.classId, t.nonceId, t._amount);
_enforceInvestorCap(to, t.classId, t.nonceId, t._amount);
_credit(to, t.classId, t.nonceId, t._amount);
unchecked { ++i; }
}
emit Transfer(msg.sender, from, to, txs);
}
/* ---------- Lifecycle ---------- */
function issue(address to, Transaction[] calldata txs) external override whenNotPaused onlyRole(OPERATOR_ROLE) {
require(to != address(0) && _wl[to], "WL");
uint256 len = txs.length;
require(len > 0 && len <= MAX_BATCH, "BATCH");
for (uint256 i; i < len; ) {
Transaction calldata t = txs[i];
require(t._amount > 0, "AMT");
_enforceSeriesCap(t.classId, t.nonceId, t._amount);
_enforceInvestorCap(to, t.classId, t.nonceId, t._amount);
_credit(to, t.classId, t.nonceId, t._amount);
_classes[t.classId].nonces[t.nonceId].activeSupply += t._amount;
unchecked { ++i; }
}
emit Issue(msg.sender, to, txs);
}
function redeem(address from, Transaction[] calldata txs) external override whenNotPaused onlyRole(OPERATOR_ROLE) {
require(from != address(0), "ADDR");
uint256 len = txs.length;
require(len > 0 && len <= MAX_BATCH, "BATCH");
for (uint256 i; i < len; ) {
Transaction calldata t = txs[i];
require(t._amount > 0, "AMT");
_debit(from, t.classId, t.nonceId, t._amount);
Nonce storage n = _classes[t.classId].nonces[t.nonceId];
n.activeSupply -= t._amount;
n.redeemedSupply += t._amount;
unchecked { ++i; }
}
emit Redeem(msg.sender, from, txs);
}
function burn(address from, Transaction[] calldata txs) external override whenNotPaused onlyRole(OPERATOR_ROLE) {
require(from != address(0), "ADDR");
uint256 len = txs.length;
require(len > 0 && len <= MAX_BATCH, "BATCH");
for (uint256 i; i < len; ) {
Transaction calldata t = txs[i];
require(t._amount > 0, "AMT");
_debit(from, t.classId, t.nonceId, t._amount);
Nonce storage n = _classes[t.classId].nonces[t.nonceId];
n.activeSupply -= t._amount;
n.burnedSupply += t._amount;
unchecked { ++i; }
}
emit Burn(msg.sender, from, txs);
}
/* ---------- Views ---------- */
function totalSupply(uint256 c, uint256 n) external view override returns (uint256) {
Nonce storage nonce = _classes[c].nonces[n];
return nonce.activeSupply + nonce.redeemedSupply + nonce.burnedSupply;
}
function redeemedSupply(uint256 c, uint256 n) external view override returns (uint256) {
return _classes[c].nonces[n].redeemedSupply;
}
function burnedSupply(uint256 c, uint256 n) external view override returns (uint256) {
return _classes[c].nonces[n].burnedSupply;
}
function activeSupply(uint256 c, uint256 n) external view override returns (uint256) {
return _classes[c].nonces[n].activeSupply;
}
function balanceOf(address a, uint256 c, uint256 n) external view override returns (uint256) {
return _classes[c].nonces[n].balances[a];
}
function allowance(address owner, address spender, uint256 c, uint256 n) external view override returns (uint256) {
return _classes[c].nonces[n].allowances[owner][spender];
}
function isApprovedFor(address owner, address op) external view override returns (bool) {
return operatorApproved[owner][op];
}
function classMetadata(uint256 id) external view override returns (Metadata memory) {
require(id < classMeta.length, "META");
return classMeta[id];
}
function nonceMetadata(uint256 c, uint256 id) external view override returns (Metadata memory) {
require(id < nonceMeta[c].length, "META");
return nonceMeta[c][id];
}
function classValues(uint256 c, uint256 id) external view override returns (Values memory) {
string memory key = _classes[c].valuesId[id];
require(bytes(key).length != 0, "VAL");
return _classes[c].values[key];
}
function nonceValues(uint256 c, uint256 n, uint256 id) external view override returns (Values memory) {
string memory key = _classes[c].nonces[n].valuesId[id];
require(bytes(key).length != 0, "VAL");
return _classes[c].nonces[n].values[key];
}
function getProgress(uint256 c, uint256 n) external view override returns (uint256 done, uint256 remain) {
Nonce storage x = _classes[c].nonces[n];
if (x.issuance == 0 || x.maturity <= x.issuance) return (0, 0);
if (block.timestamp >= x.maturity) return (x.maturity - x.issuance, 0);
if (block.timestamp < x.issuance) return (0, x.maturity - x.issuance);
uint256 elapsed = block.timestamp - x.issuance;
uint256 total = x.maturity - x.issuance;
return (elapsed, total - elapsed);
}
function seriesCap(uint256 c, uint256 n) external view returns (uint256) {
return _seriesCap[c][n];
}
function investorCap(uint256 c, uint256 n, address who) external view returns (uint256) {
return _investorCap[c][n][who];
}
/* ---------- Internals ---------- */
function _debit(address from, uint256 c, uint256 n, uint256 amt) internal {
Nonce storage nonce = _classes[c].nonces[n];
uint256 fromBalance = nonce.balances[from];
require(fromBalance >= amt, "BAL");
unchecked { nonce.balances[from] = fromBalance - amt; }
}
function _credit(address to, uint256 c, uint256 n, uint256 amt) internal {
_classes[c].nonces[n].balances[to] += amt;
}
function _enforceSeriesCap(uint256 c, uint256 n, uint256 add) internal view {
uint256 cap = _seriesCap[c][n];
if (cap > 0) {
uint256 active = _classes[c].nonces[n].activeSupply;
require(active + add <= cap, "SCAP");
}
}
function _enforceInvestorCap(address to, uint256 c, uint256 n, uint256 add) internal view {
uint256 cap = _investorCap[c][n][to];
if (cap > 0) require(_classes[c].nonces[n].balances[to] + add <= cap, "ICAP");
}
// ERC165 via AccessControl
function supportsInterface(bytes4 iid) public view override(AccessControlUpgradeable) returns (bool) {
return iid == type(IERC3475).interfaceId || super.supportsInterface(iid);
}
// Reserve 50 slots for future upgrades
uint256[50] private __gap;
}
"
},
"src/interfaces/IERC3475.sol": {
"content": "// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;
interface IERC3475 {
// STRUCTURE
/**
* @dev Values structure of the Metadata
*/
struct Values {
string stringValue;
uint uintValue;
address addressValue;
bool boolValue;
}
/**
* @dev structure allows to define particular bond metadata (ie the values in the class as well as nonce inputs).
* @notice 'title' defining the title information,
* @notice '_type' explaining the data type of the title information added (eg int, bool, address),
* @notice 'description' explains little description about the information stored in the bond",
*/
struct Metadata {
string title;
string _type;
string description;
}
/**
* @dev structure that defines the parameters for specific issuance of bonds and amount which are to be transferred/issued/given allowance, etc.
* @notice this structure is used to streamline the input parameters for functions of this standard with that of other Token standards like ERC20.
* @classId is the class id of the bond.
* @nonceId is the nonce id of the given bond class. This param is for distinctions of the issuing conditions of the bond.
* @amount is the amount of the bond that will be transferred.
*/
struct Transaction {
uint256 classId;
uint256 nonceId;
uint256 _amount;
}
// WRITABLES
/**
* @dev allows the transfer of a bond from one address to another (either single or in batches).
* @param _from is the address of the holder whose balance is about to decrease.
* @param _to is the address of the recipient whose balance is about to increase.
* @param _transactions is the object defining {class,nonce and amount of the bonds to be transferred}.
*/
function transferFrom(address _from, address _to, Transaction[] calldata _transactions) external;
/**
* @dev allows the transfer of allowance from one address to another (either single or in batches).
* @param _from is the address of the holder whose balance about to decrease.
* @param _to is the address of the recipient whose balance is about to increased.
* @param _transactions is the object defining {class,nonce and amount of the bonds to be allowed to transferred}.
*/
function transferAllowanceFrom(address _from, address _to, Transaction[] calldata _transactions) external;
/**
* @dev allows issuing of any number of bond types to an address(either single/batched issuance).
* The calling of this function needs to be restricted to bond issuer contract.
* @param _to is the address to which the bond will be issued.
* @param _transactions is the object defining {class,nonce and amount of the bonds to be issued for given whitelisted bond}.
*/
function issue(address _to, Transaction[] calldata _transactions) external;
/**
* @dev allows redemption of any number of bond types from an address.
* The calling of this function needs to be restricted to bond issuer contract.
* @param _from is the address _from which the bond will be redeemed.
* @param _transactions is the object defining {class,nonce and amount of the bonds to be redeemed for given whitelisted bond}.
*/
function redeem(address _from, Transaction[] calldata _transactions) external;
/**
* @dev allows the transfer of any number of bond types from an address to another.
* The calling of this function needs to be restricted to bond issuer contract.
* @param _from is the address of the holder whose balance about to decrease.
* @param _transactions is the object defining {class,nonce and amount of the bonds to be redeemed for given whitelisted bond}.
*/
function burn(address _from, Transaction[] calldata _transactions) external;
/**
* @dev Allows _spender to withdraw from your account multiple times, up to the amount.
* @notice If this function is called again, it overwrites the current allowance with amount.
* @param _spender is the address the caller approve for his bonds.
* @param _transactions is the object defining {class,nonce and amount of the bonds to be approved for given whitelisted bond}.
*/
function approve(address _spender, Transaction[] calldata _transactions) external;
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of the caller's tokens.
* @dev MUST emit the ApprovalForAll event on success.
* @param _operator Address to add to the set of authorized operators
* @param _approved "True" if the operator is approved, "False" to revoke approval.
*/
function setApprovalFor(address _operator, bool _approved) external;
// READABLES
/**
* @dev Returns the total supply of the bond in question.
*/
function totalSupply(uint256 classId, uint256 nonceId) external view returns (uint256);
/**
* @dev Returns the redeemed supply of the bond in question.
*/
function redeemedSupply(uint256 classId, uint256 nonceId) external view returns (uint256);
/**
* @dev Returns the active supply of the bond in question.
*/
function activeSupply(uint256 classId, uint256 nonceId) external view returns (uint256);
/**
* @dev Returns the burned supply of the bond in question.
*/
function burnedSupply(uint256 classId, uint256 nonceId) external view returns (uint256);
/**
* @dev Returns the balance of the giving bond classId and bond nonce.
*/
function balanceOf(address _account, uint256 classId, uint256 nonceId) external view returns (uint256);
/**
* @dev Returns the JSON metadata of the classes.
* The metadata SHOULD follow a set of structure explained later in eip-3475.md
* @param metadataId is the index corresponding to the class parameter that you want to return from mapping.
*/
function classMetadata(uint256 metadataId) external view returns ( Metadata memory);
/**
* @dev Returns the JSON metadata of the Values of the nonces in the corresponding class.
* @param classId is the specific classId of which you want to find the metadata of the corresponding nonce.
* @param metadataId is the index corresponding to the class parameter that you want to return from mapping.
* @notice The metadata SHOULD follow a set of structure explained later in metadata section.
*/
function nonceMetadata(uint256 classId, uint256 metadataId) external view returns ( Metadata memory);
/**
* @dev Returns the values of the given classId.
* @param classId is the specific classId of which we want to return the parameter.
* @param metadataId is the index corresponding to the class parameter that you want to return from mapping.
* the metadata SHOULD follow a set of structures explained in eip-3475.md
*/
function classValues(uint256 classId, uint256 metadataId) external view returns ( Values memory);
/**
* @dev Returns the values of given nonceId.
* @param metadataId index number of structure as explained in the metadata section in EIP-3475.
* @param classId is the class of bonds for which you determine the nonce.
* @param nonceId is the nonce for which you return the value struct info.
* Returns the values object corresponding to the given value.
*/
function nonceValues(uint256 classId, uint256 nonceId, uint256 metadataId) external view returns ( Values memory);
/**
* @dev Returns the information about the progress needed to redeem the bond identified by classId and nonceId.
* @notice Every bond contract can have its own logic concerning the progress definition.
* @param classId The class of bonds.
* @param nonceId is the nonce of bonds for finding the progress.
* Returns progressAchieved is the current progress achieved.
* Returns progressRemaining is the remaining progress.
*/
function getProgress(uint256 classId, uint256 nonceId) external view returns (uint256 progressAchieved, uint256 progressRemaining);
/**
* @notice Returns the amount that spender is still allowed to withdraw from _owner (for given classId and nonceId issuance)
* @param _owner is the address whose owner allocates some amount to the _spender address.
* @param classId is the classId of the bond.
* @param nonceId is the nonce corresponding to the class for which you are approving the spending of total amount of bonds.
*/
function allowance(address _owner, address _spender, uint256 classId, uint256 nonceId) external view returns (uint256);
/**
* @notice Queries the approval status of an operator for bonds (for all classes and nonce issuances of owner).
* @param _owner is the current holder of the bonds for all classes/nonces.
* @param _operator is the address with access to the bonds of _owner for transferring.
* Returns "true" if the operator is approved, "false" if not.
*/
function isApprovedFor(address _owner, address _operator) external view returns (bool);
// EVENTS
/**
* @notice MUST trigger when tokens are transferred, including zero value transfers.
* e.g:
emit Transfer(0x2d03B6C79B75eE7aB35298878D05fe36DC1fE8Ef, 0x492Af743654549b12b1B807a9E0e8F397E44236E,0x3d03B6C79B75eE7aB35298878D05fe36DC1fEf, [IERC3475.Transaction(1,14,500)])
means that operator 0x2d03B6C79B75eE7aB35298878D05fe36DC1fE8Ef wants to transfer 500 bonds of class 1 , Nonce 14 of owner 0x492Af743654549b12b1B807a9E0e8F397E44236E to address 0x3d03B6C79B75eE7aB35298878D05fe36DC1fEf.
*/
event Transfer(address indexed _operator, address indexed _from, address indexed _to, Transaction[] _transactions);
/**
* @notice MUST trigger when tokens are issued
* @notice Issue MUST trigger when Bonds are issued. This SHOULD not include zero value Issuing.
* @dev This SHOULD not include zero value issuing.
* @dev Issue MUST be triggered when the operator (i.e Bank address) contract issues bonds to the given entity.
eg: emit Issue(_operator, 0x2d03B6C79B75eE7aB35298878D05fe36DC1fE8Ef,[IERC3475.Transaction(1,14,500)]);
issue by address(operator) 500 Bonds(nonce14,class 0) to address 0x2d03B6C79B75eE7aB35298878D05fe36DC1fE8Ef.
*/
event Issue(address indexed _operator, address indexed _to, Transaction[] _transactions);
/**
* @notice MUST trigger when tokens are redeemed.
* @notice Redeem MUST trigger when Bonds are redeemed. This SHOULD not include zero value redemption.
* eg: emit Redeem(0x2d03B6C79B75eE7aB35298878D05fe36DC1fE8Ef,0x492Af743654549b12b1B807a9E0e8F397E44236E,[IERC3475.Transaction(1,14,500)]);
* this emit event when 5000 bonds of class 1, nonce 14 owned by address 0x492Af743654549b12b1B807a9E0e8F397E44236E are being redeemed by 0x2d03B6C79B75eE7aB35298878D05fe36DC1fE8Ef.
*/
event Redeem(address indexed _operator, address indexed _from, Transaction[] _transactions);
/**
* @notice MUST trigger when tokens are burned
* @dev `Burn` MUST trigger when the bonds are being redeemed via staking (or being invalidated) by the bank contract.
* @dev `Burn` MUST trigger when Bonds are burned. This SHOULD not include zero value burning
* @notice emit Burn(0x2d03B6C79B75eE7aB35298878D05fe36DC1fE8Ef,0x492Af743654549b12b1B807a9E0e8F397E44236E,[IERC3475.Transaction(1,14,500)]);
* emits event when 5000 bonds of owner 0x492Af743654549b12b1B807a9E0e8F397E44236E of type (class 1, nonce 14) are burned by operator 0x2d03B6C79B75eE7aB35298878D05fe36DC1fE8Ef.
*/
event Burn(address indexed _operator, address indexed _from, Transaction[] _transactions);
/**
* @dev MUST emit when approval for a second party/operator address to manage all bonds from a classId given for an owner address is enabled or disabled (absence of an event assumes disabled).
* @dev its emitted when address(_owner) approves the address(_operator) to transfer his bonds.
* @notice Approval MUST trigger when bond holders are approving an _operator. This SHOULD not include zero value approval.
*/
event ApprovalFor(address indexed _owner, address indexed _operator, bool _approved);
}
"
},
"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/openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.22;
import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address private immutable __self = address(this);
/**
* @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
* and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
* while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
* If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
* be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
* during an upgrade.
*/
string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";
/**
* @dev The call is from an unauthorized context.
*/
error UUPSUnauthorizedCallContext();
/**
* @dev The storage `slot` is unsupported as a UUID.
*/
error UUPSUnsupportedProxiableUUID(bytes32 slot);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC-1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC-1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
_checkProxy();
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
_checkNotDelegated();
_;
}
function __UUPSUpgradeable_init() internal onlyInitializing {
}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
}
/**
* @dev Implementation of the ERC-1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual notDelegated returns (bytes32) {
return ERC1967Utils.IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data);
}
/**
* @dev Reverts if the execution is not performed via delegatecall or the execution
* context is not of a proxy with an ERC-1967 compliant implementation pointing to self.
*/
function _checkProxy() internal view virtual {
if (
address(this) == __self || // Must be called through delegatecall
ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
) {
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Reverts if the execution is performed via delegatecall.
* See {notDelegated}.
*/
function _checkNotDelegated() internal view virtual {
if (address(this) != __self) {
// Must not be called through delegatecall
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
*
* As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
* is expected to be the implementation slot in ERC-1967.
*
* Emits an {IERC1967-Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
revert UUPSUnsupportedProxiableUUID(slot);
}
ERC1967Utils.upgradeToAndCall(newImplementation, data);
} catch {
// The implementation is not UUPS
revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
}
}
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.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 {
}
/// @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) {
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 {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
AccessControlStorage storage $ = _getAccessControlStorage();
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 {
AccessControlStorage storage $ = _getAccessControlStorage();
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) {
AccessControlStorage storage $ = _getAccessControlStorage();
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) {
AccessControlStorage storage $ = _getAccessControlStorage();
if (hasRole(role, account)) {
$._roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}
"
},
"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());
}
}
"
},
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/interfaces/draft-IERC1822.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/draft-IERC1822.sol)
pragma solidity >=0.4.16;
/**
* @dev ERC-1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}
"
},
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Utils.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (proxy/ERC1967/ERC1967Utils.sol)
pragma solidity ^0.8.21;
import {IBeacon} from "../beacon/IBeacon.sol";
import {IERC1967} from "../../interfaces/IERC1967.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";
/**
* @dev This library provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots.
*/
library ERC1967Utils {
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev The `implementation` of the proxy is invalid.
*/
error ERC1967InvalidImplementation(address implementation);
/**
* @dev The `admin` of the proxy is invalid.
*/
error ERC1967InvalidAdmin(address admin);
/**
* @dev The `beacon` of the proxy is invalid.
*/
error ERC1967InvalidBeacon(address beacon);
/**
* @dev An upgrade function sees `msg.value > 0` that may be lost.
*/
error ERC1967NonPayable();
/**
* @dev Returns the current implementation address.
*/
function getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the ERC-1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
if (newImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(newImplementation);
}
StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Performs implementation upgrade with additional setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-Upgraded} event.
*/
function upgradeToAndCall(address newImplementation, bytes memory data) internal {
_setImplementation(newImplementation);
emit IERC1967.Upgraded(newImplementation);
if (data.length > 0) {
Address.functionDelegateCall(newImplementation, data);
} else {
_checkNonPayable();
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
* the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
*/
function getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the ERC-1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
if (newAdmin == address(0)) {
revert ERC1967InvalidAdmin(address(0));
}
StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {IERC1967-AdminChanged} event.
*/
function changeAdmin(address newAdmin) internal {
emit IERC1967.AdminChanged(getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the ERC-1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
if (newBeacon.code.length == 0) {
revert ERC1967InvalidBeacon(newBeacon);
}
StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;
address beaconImplementation = IBeacon(newBeacon).implementation();
if (beaconImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(beaconImplementation);
}
}
/**
* @dev Change the beacon and trigger a setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-BeaconUpgraded} event.
*
* CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
* it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
* efficiency.
*/
function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
_setBeacon(newBeacon);
emit IERC1967.BeaconUpgraded(newBeacon);
if (data.length > 0) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
} else {
_checkNonPayable();
}
}
/**
* @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
* if an upgrade doesn't perform an initialization call.
*/
function _checkNonPayable() private {
if (msg.value > 0) {
revert ERC1967NonPayable();
}
}
}
"
},
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/access/IAccessControl.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/IAccessControl.sol)
pragma solidity >=0.8.4;
/**
* @dev External interface of AccessControl declared to support ERC-165 detection.
*/
interface IAccessControl {
/**
* @dev The `account` is missing a role.
*/
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
/**
* @dev The caller of a function is not the expected one.
*
* NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
*/
error AccessControlBadConfirmation();
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted to signal this.
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call. This account bears the admin role (for the granted role).
* Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `
Submitted on: 2025-10-09 09:14:14
Comments
Log in to comment.
No comments yet.