Verified contractExactMIT
ConferenceUpgradeable
Address0xa60ee9343b7e79b9ee7d97d2d9dcee93c2a14496
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.24
- Same code
Only this contract
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- paris
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,340,248
- Creation transaction
- 0xdf2c92bb02…34bfd42e4a
5 files
- contracts/upgradeable/ConferenceUpgradeable.solmain14.86 KB
- contracts/upgradeable/GroupAdminUpgradeable.sol3.78 KB
- contracts/upgradeable/OwnableUpgradeable.sol2.62 KB
- lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol144 B
- lib/openzeppelin-contracts/contracts/proxy/utils/Initializable.sol9.28 KB
contracts/upgradeable/ConferenceUpgradeable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "./GroupAdminUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
/**
* @title ConferenceUpgradeable
* @dev Upgradeable implementation of the Conference contract for use with beacon proxies.
*
* SECURITY NOTES:
* 1. This implementation uses OpenZeppelin's Initializable to prevent re-initialization attacks.
* 2. The _disableInitializers() call in the constructor prevents the implementation contract
* itself from being initialized, mitigating attacks like the Parity wallet incident.
* 3. Each proxy must call initialize() exactly once during deployment.
* 4. Uses ERC-7201 namespaced storage to prevent storage collisions during upgrades.
* 5. Destructible functionality is removed as selfdestruct is deprecated and incompatible
* with upgradeable proxies (implementation is shared across all proxies).
*/
contract ConferenceUpgradeable is Initializable, GroupAdminUpgradeable {
/// @custom:storage-location erc7201:blockparty.storage.ConferenceUpgradeable
struct ConferenceStorage {
string name;
string metadataUri; // Arweave URI for off-chain metadata (e.g., "ar://txId")
uint256 deposit;
uint256 limitOfParticipants;
uint256 registered;
uint256 attended;
bool ended;
bool cancelled;
uint256 endedAt;
uint256 coolingPeriod;
uint256 payoutAmount;
mapping(address => Participant) participants;
mapping(uint256 => address) participantsIndex;
}
// keccak256(abi.encode(uint256(keccak256("blockparty.storage.ConferenceUpgradeable"))
// - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant CONFERENCE_STORAGE_LOCATION =
0x5b8ccbb9d4f9f6e3b2a1d0c9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e000;
function _getConferenceStorage() private pure returns (ConferenceStorage storage $) {
assembly {
$.slot := CONFERENCE_STORAGE_LOCATION
}
}
struct Participant {
string participantName;
address addr;
bool attended;
bool paid;
}
event RegisterEvent(address addr, string participantName);
event AttendEvent(address addr);
event PaybackEvent(uint256 _payout);
event WithdrawEvent(address addr, uint256 _payout);
event CancelEvent();
event ClearEvent(address addr, uint256 leftOver);
event MetadataUpdated(string uri);
/* Modifiers */
modifier onlyActive() {
ConferenceStorage storage $ = _getConferenceStorage();
require(!$.ended, "Conference: event has ended");
_;
}
modifier noOneRegistered() {
ConferenceStorage storage $ = _getConferenceStorage();
require($.registered == 0, "Conference: participants already registered");
_;
}
modifier onlyEnded() {
ConferenceStorage storage $ = _getConferenceStorage();
require($.ended, "Conference: event has not ended");
_;
}
/**
* @dev CRITICAL: Disable initializers in the constructor to prevent the implementation
* contract from being initialized. This protects against attacks where an attacker
* could initialize the implementation and potentially become its owner.
* Reference: Parity wallet hack - uninitialized implementation was taken over.
*/
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
/**
* @notice Initialize event and owner.
* @dev Initializes the Conference proxy. This replaces the constructor for upgradeable contracts.
* Can only be called once per proxy due to the initializer modifier.
* @param _name Name (empty=Test)
* @param _deposit Deposit (0=0.02 ETH)
* @param _limitOfParticipants Capacity (0=20)
* @param _coolingPeriod Seconds (0=604800)
* @param _metadataUri Metadata URI
* @param _owner Event owner wallet
* @custom:clearsig-format _deposit=unit _coolingPeriod=raw
* @custom:clearsig-base _deposit="ETH"
* @custom:clearsig-decimals _deposit=18
*/
function initialize(
string memory _name,
uint256 _deposit,
uint256 _limitOfParticipants,
uint256 _coolingPeriod,
string memory _metadataUri,
address payable _owner
) public initializer {
__GroupAdmin_init();
// Transfer ownership to the specified owner (factory caller)
if (_owner != msg.sender) {
transferOwnership(_owner);
}
ConferenceStorage storage $ = _getConferenceStorage();
if (bytes(_name).length != 0) {
$.name = _name;
} else {
$.name = "Test";
}
if (_deposit != 0) {
$.deposit = _deposit;
} else {
$.deposit = 0.02 ether;
}
if (_limitOfParticipants != 0) {
$.limitOfParticipants = _limitOfParticipants;
} else {
$.limitOfParticipants = 20;
}
if (_coolingPeriod != 0) {
$.coolingPeriod = _coolingPeriod;
} else {
$.coolingPeriod = 1 weeks;
}
$.metadataUri = _metadataUri;
}
/* Public view functions */
function name() public view returns (string memory) {
ConferenceStorage storage $ = _getConferenceStorage();
return $.name;
}
function metadataUri() public view returns (string memory) {
ConferenceStorage storage $ = _getConferenceStorage();
return $.metadataUri;
}
function deposit() public view returns (uint256) {
ConferenceStorage storage $ = _getConferenceStorage();
return $.deposit;
}
function limitOfParticipants() public view returns (uint256) {
ConferenceStorage storage $ = _getConferenceStorage();
return $.limitOfParticipants;
}
function registered() public view returns (uint256) {
ConferenceStorage storage $ = _getConferenceStorage();
return $.registered;
}
function attended() public view returns (uint256) {
ConferenceStorage storage $ = _getConferenceStorage();
return $.attended;
}
function ended() public view returns (bool) {
ConferenceStorage storage $ = _getConferenceStorage();
return $.ended;
}
function cancelled() public view returns (bool) {
ConferenceStorage storage $ = _getConferenceStorage();
return $.cancelled;
}
function endedAt() public view returns (uint256) {
ConferenceStorage storage $ = _getConferenceStorage();
return $.endedAt;
}
function coolingPeriod() public view returns (uint256) {
ConferenceStorage storage $ = _getConferenceStorage();
return $.coolingPeriod;
}
function payoutAmount() public view returns (uint256) {
ConferenceStorage storage $ = _getConferenceStorage();
return $.payoutAmount;
}
function participants(address _addr) public view returns (
string memory participantName,
address addr,
bool participantAttended,
bool paid
) {
ConferenceStorage storage $ = _getConferenceStorage();
Participant storage p = $.participants[_addr];
return (p.participantName, p.addr, p.attended, p.paid);
}
function participantsIndex(uint256 index) public view returns (address) {
ConferenceStorage storage $ = _getConferenceStorage();
return $.participantsIndex[index];
}
/**
* @notice Register and deposit ETH.
* @dev Registers with twitter name.
* @param _participant Participant name
* @custom:clearsig-format @.value=unit
* @custom:clearsig-label @.value=Deposit paid
* @custom:clearsig-base @.value="ETH"
* @custom:clearsig-decimals @.value=18
*/
function register(string calldata _participant) external payable onlyActive {
ConferenceStorage storage $ = _getConferenceStorage();
require(msg.value == $.deposit, "Conference: incorrect deposit amount");
require($.registered < $.limitOfParticipants, "Conference: participant limit reached");
require(!isRegistered(msg.sender), "Conference: already registered");
$.registered++;
$.participantsIndex[$.registered] = msg.sender;
$.participants[msg.sender] = Participant(_participant, msg.sender, false, false);
emit RegisterEvent(msg.sender, _participant);
}
/**
* @notice Withdraw your event payout.
* @dev Withdraws deposit after the event is over.
*/
function withdraw() external onlyEnded {
ConferenceStorage storage $ = _getConferenceStorage();
require($.payoutAmount > 0, "Conference: no payout available");
Participant storage participant = $.participants[msg.sender];
require(participant.addr == msg.sender, "Conference: not a participant");
require($.cancelled || participant.attended, "Conference: did not attend");
require(participant.paid == false, "Conference: already paid");
participant.paid = true;
(bool sent, ) = payable(msg.sender).call{value: $.payoutAmount}("");
require(sent, "Conference: payout transfer failed");
emit WithdrawEvent(msg.sender, $.payoutAmount);
}
/* Constants */
/**
* @dev Returns total balance of the contract.
* @return The total balance of the contract.
*/
function totalBalance() public view returns (uint256) {
return address(this).balance;
}
/**
* @dev Returns true if the given user is registered.
* @param _addr The address of a participant.
* @return True if the address exists in the participant list.
*/
function isRegistered(address _addr) public view returns (bool) {
ConferenceStorage storage $ = _getConferenceStorage();
return $.participants[_addr].addr != address(0);
}
/**
* @dev Returns true if the given user is attended.
* @param _addr The address of a participant.
* @return True if the user is marked as attended by admin.
*/
function isAttended(address _addr) public view returns (bool) {
ConferenceStorage storage $ = _getConferenceStorage();
return isRegistered(_addr) && $.participants[_addr].attended;
}
/**
* @dev Returns true if the given user has withdrawn his/her deposit.
* @param _addr The address of a participant.
* @return True if the attendee has withdrawn his/her deposit.
*/
function isPaid(address _addr) public view returns (bool) {
ConferenceStorage storage $ = _getConferenceStorage();
return isRegistered(_addr) && $.participants[_addr].paid;
}
/**
* @dev Show the payout amount each participant can withdraw.
* @return The amount each participant can withdraw.
*/
function payout() public view returns (uint256) {
ConferenceStorage storage $ = _getConferenceStorage();
if ($.ended) return $.payoutAmount;
if ($.attended == 0) return 0;
return totalBalance() / $.attended;
}
/* Admin only functions */
/**
* @notice End event and enable payouts.
* @dev Ends the event by owner
*/
function payback() external onlyOwner onlyActive {
ConferenceStorage storage $ = _getConferenceStorage();
$.payoutAmount = payout();
$.ended = true;
$.endedAt = block.timestamp;
emit PaybackEvent($.payoutAmount);
}
/**
* @notice Cancel and allow refunds.
* @dev Cancels the event by owner. When the event is canceled each participant can withdraw their deposit back.
*/
function cancel() external onlyOwner onlyActive {
ConferenceStorage storage $ = _getConferenceStorage();
$.payoutAmount = $.deposit;
$.cancelled = true;
$.ended = true;
$.endedAt = block.timestamp;
emit CancelEvent();
}
/**
* @notice Send unclaimed ETH to owner.
* @dev The event owner transfer the outstanding deposits if there are any unclaimed deposits after cooling period
*/
function clear() external onlyOwner onlyEnded {
ConferenceStorage storage $ = _getConferenceStorage();
require(block.timestamp > $.endedAt + $.coolingPeriod, "Conference: cooling period not passed");
uint256 leftOver = totalBalance();
(bool sent, ) = owner().call{value: leftOver}("");
require(sent, "Conference: balance transfer failed");
emit ClearEvent(owner(), leftOver);
}
/**
* @notice Change event capacity.
* @dev Change the capacity of the event. The owner can change it until event is over.
* @param _limitOfParticipants Maximum participants
*/
function setLimitOfParticipants(uint256 _limitOfParticipants) external onlyOwner onlyActive {
ConferenceStorage storage $ = _getConferenceStorage();
require(_limitOfParticipants > 0, "Conference: capacity must be positive");
require(_limitOfParticipants >= $.registered, "Conference: capacity below registrations");
$.limitOfParticipants = _limitOfParticipants;
}
/**
* @notice Change event name.
* @dev Change the name of the event. The owner can change it as long as no one has registered yet.
* @param _name New event name
*/
function changeName(string calldata _name) external onlyOwner onlyActive noOneRegistered {
ConferenceStorage storage $ = _getConferenceStorage();
require(bytes(_name).length > 0, "Conference: name is required");
$.name = _name;
}
/**
* @notice Replace event metadata.
* @dev Set or update the metadata URI. Admins can update metadata at any time to change event details.
* @param _metadataUri Event metadata URI
*/
function setMetadataUri(string calldata _metadataUri) external onlyAdmin {
ConferenceStorage storage $ = _getConferenceStorage();
$.metadataUri = _metadataUri;
emit MetadataUpdated(_metadataUri);
}
/**
* @notice Permanently mark attendance.
* @dev Mark participants as attended. The attendance cannot be undone.
* @param _addresses Participant wallets
*/
function attend(address[] calldata _addresses) external onlyAdmin onlyActive {
ConferenceStorage storage $ = _getConferenceStorage();
for (uint i = 0; i < _addresses.length; i++) {
address _addr = _addresses[i];
require(isRegistered(_addr), "Conference: address not registered");
require(!isAttended(_addr), "Conference: already attended");
emit AttendEvent(_addr);
$.participants[_addr].attended = true;
$.attended++;
}
}
}
contracts/upgradeable/GroupAdminUpgradeable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "./OwnableUpgradeable.sol";
/**
* @title GroupAdminUpgradeable
* @dev Upgradeable version of GroupAdmin that allows multiple addresses to perform as admin.
*/
abstract contract GroupAdminUpgradeable is OwnableUpgradeable {
/// @custom:storage-location erc7201:blockparty.storage.GroupAdminUpgradeable
struct GroupAdminStorage {
address[] admins;
}
// keccak256(abi.encode(uint256(keccak256("blockparty.storage.GroupAdminUpgradeable"))
// - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant GROUP_ADMIN_STORAGE_LOCATION =
0x8a0c9d8ec1d9f8b4c7b09d5c3b0a4f0e0d1c2b3a4958697a7b8c9d0e1f203100;
function _getGroupAdminStorage() private pure returns (GroupAdminStorage storage $) {
assembly {
$.slot := GROUP_ADMIN_STORAGE_LOCATION
}
}
event AdminGranted(address indexed grantee);
event AdminRevoked(address indexed grantee);
modifier onlyAdmin() {
require(isAdmin(msg.sender), "GroupAdmin: caller is not an admin");
_;
}
/**
* @dev Initializes the GroupAdmin. Should be called during proxy initialization.
*/
function __GroupAdmin_init() internal onlyInitializing {
__Ownable_init();
__GroupAdmin_init_unchained();
}
function __GroupAdmin_init_unchained() internal onlyInitializing {
// No additional initialization needed
}
/**
* @notice Grant event admin permissions.
* @dev Grants admin right to given addresses.
* @param newAdmins New admin wallets
*/
function grant(address[] calldata newAdmins) public onlyOwner {
GroupAdminStorage storage $ = _getGroupAdminStorage();
for (uint i = 0; i < newAdmins.length; i++) {
require(newAdmins[i] != address(0), "GroupAdmin: zero address");
require(!isAdmin(newAdmins[i]), "GroupAdmin: already admin");
$.admins.push(newAdmins[i]);
emit AdminGranted(newAdmins[i]);
}
}
/**
* @notice Revoke event admin access.
* @dev Revoke admin right from given addresses.
* @param oldAdmins Admins to remove
*/
function revoke(address[] calldata oldAdmins) public onlyOwner {
GroupAdminStorage storage $ = _getGroupAdminStorage();
for (uint oldIdx = 0; oldIdx < oldAdmins.length; oldIdx++) {
for (uint idx = 0; idx < $.admins.length;) {
if ($.admins[idx] == oldAdmins[oldIdx]) {
$.admins[idx] = $.admins[$.admins.length - 1];
$.admins.pop();
emit AdminRevoked(oldAdmins[oldIdx]);
} else {
idx++;
}
}
}
}
/**
* @dev Returns admin addresses
* @return Admin addresses
*/
function getAdmins() public view returns (address[] memory) {
GroupAdminStorage storage $ = _getGroupAdminStorage();
return $.admins;
}
/**
* @dev Returns number of admins.
* @return Number of admins.
*/
function numOfAdmins() public view returns (uint) {
GroupAdminStorage storage $ = _getGroupAdminStorage();
return $.admins.length;
}
/**
* @dev Returns if the given address is admin or not.
* @param admin An address.
* @return True if the given address is admin.
*/
function isAdmin(address admin) public view returns (bool) {
if (admin == owner()) return true;
GroupAdminStorage storage $ = _getGroupAdminStorage();
for (uint i = 0; i < $.admins.length; i++) {
if ($.admins[i] == admin) {
return true;
}
}
return false;
}
}
contracts/upgradeable/OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
/**
* @title OwnableUpgradeable
* @dev Upgradeable version of Ownable contract with an owner address and basic authorization control.
* Uses OpenZeppelin's Initializable to safely initialize in proxy context.
*/
abstract contract OwnableUpgradeable is Initializable {
/// @custom:storage-location erc7201:blockparty.storage.OwnableUpgradeable
struct OwnableStorage {
address payable owner;
}
// keccak256(abi.encode(uint256(keccak256("blockparty.storage.OwnableUpgradeable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant OWNABLE_STORAGE_LOCATION =
0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;
function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
assembly {
$.slot := OWNABLE_STORAGE_LOCATION
}
}
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
* CRITICAL: This function must be called during proxy initialization to prevent
* uninitialized implementation attacks (like the Parity wallet hack).
*/
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained(payable(msg.sender));
}
function __Ownable_init_unchained(address payable initialOwner) internal onlyInitializing {
OwnableStorage storage $ = _getOwnableStorage();
$.owner = initialOwner;
emit OwnershipTransferred(address(0), initialOwner);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address payable) {
OwnableStorage storage $ = _getOwnableStorage();
return $.owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner(), "Ownable: caller is not the owner");
_;
}
/**
* @notice Transfer ownership.
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner New owner wallet
*/
function transferOwnership(address payable newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
OwnableStorage storage $ = _getOwnableStorage();
emit OwnershipTransferred($.owner, newOwner);
$.owner = newOwner;
}
}
lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
lib/openzeppelin-contracts/contracts/proxy/utils/Initializable.sol
// 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
}
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "paris",
"remappings": [
"forge-std/=lib/forge-std/src/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.