Skip to content
Lattice

InitializableLib

Git Source

Title: InitializableLib

Authors: Modified from diamond-lib v0.3.0 (https://github.com/dadadave80/diamond-lib/blob/v0.3.0/test/utils/InitializableLib.sol), Solady (https://github.com/vectorized/solady/blob/main/src/utils/Initializable.sol), Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/contracts/proxy/utils/Initializable.sol)

Initialization guard logic for Lattice diamonds, facet inits, and standalones.

Moved out of upstream src/ in v0.3.0 ("initializables move to lattice"); the returns-slot preInitializer fixes nested-constructor-initializer double-finalize — postInitializer MUST receive the RETURNED slot. Diverges from upstream: preInitializer() is parameterless and pinned to the default slot (upstream takes the slot as a parameter).

Functions

initializableSlot

Returns the default initializable storage slot.

function initializableSlot() internal pure returns (bytes32);

Returns

NameTypeDescription
<none>bytes32

preInitializer

Marks the start of an initializer-guarded function.

Returns the slot to pass to postInitializer. In the nested constructor-initializer case the returned slot is zero, which tells postInitializer to skip finalization — the outermost initializer clears the flag and emits the event exactly once. Always pass the RETURNED value to postInitializer, not the original slot.

function preInitializer() internal returns (bytes32 slot_);

Returns

NameTypeDescription
slot_bytes32

postInitializer

Marks the end of an initializer-guarded function. Takes the slot RETURNED by preInitializer.

function postInitializer(bytes32 _initializableSlot) internal;

Parameters

NameTypeDescription
_initializableSlotbytes32

preReinitializer

Marks the start of a reinitializer-guarded function.

function preReinitializer(bytes32 _initializableSlot, uint64 _version) internal;

Parameters

NameTypeDescription
_initializableSlotbytes32
_versionuint64

postReinitializer

Marks the end of a reinitializer-guarded function.

function postReinitializer(bytes32 _initializableSlot, uint64 _version) internal;

Parameters

NameTypeDescription
_initializableSlotbytes32
_versionuint64

checkInitializing

Reverts if the contract is not initializing.

function checkInitializing(bytes32 _initializableSlot) internal view;

Parameters

NameTypeDescription
_initializableSlotbytes32

disableInitializers

Locks any future initializations by setting the initialized version to 2**64 - 1.

Calling this in the constructor will prevent the contract from being initialized or reinitialized. 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 called.

function disableInitializers(bytes32 _initializableSlot) internal;

Parameters

NameTypeDescription
_initializableSlotbytes32

getInitializedVersion

Returns the highest version that has been initialized.

function getInitializedVersion(bytes32 _initializableSlot) internal view returns (uint64 version_);

Parameters

NameTypeDescription
_initializableSlotbytes32

Returns

NameTypeDescription
version_uint64

isInitializing

Returns whether the contract is currently initializing.

function isInitializing(bytes32 _initializableSlot) internal view returns (bool result_);

Parameters

NameTypeDescription
_initializableSlotbytes32

Returns

NameTypeDescription
result_bool