43 lines
1.5 KiB
Solidity
43 lines
1.5 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity ^0.8.10;
|
|
|
|
/**
|
|
* @title VersionedInitializable
|
|
*
|
|
* @dev Helper contract to support initializer functions. To use it, replace
|
|
* the constructor with a function that has the `initializer` modifier.
|
|
* WARNING: Unlike constructors, initializer functions must be manually
|
|
* invoked. This applies both to deploying an Initializable contract, as well
|
|
* as extending an Initializable contract via inheritance.
|
|
* WARNING: When used with inheritance, manual care must be taken to not invoke
|
|
* a parent initializer twice, or ensure that all initializers are idempotent,
|
|
* because this is not dealt with automatically as with constructors.
|
|
*
|
|
* @author Aave, inspired by the OpenZeppelin Initializable contract
|
|
*/
|
|
abstract contract VersionedInitializable {
|
|
/**
|
|
* @dev Indicates that the contract has been initialized.
|
|
*/
|
|
uint256 internal lastInitializedRevision = 0;
|
|
|
|
/**
|
|
* @dev Modifier to use in the initializer function of a contract.
|
|
*/
|
|
modifier initializer() {
|
|
uint256 revision = getRevision();
|
|
require(revision > lastInitializedRevision, 'Contract instance has already been initialized');
|
|
|
|
lastInitializedRevision = revision;
|
|
|
|
_;
|
|
}
|
|
|
|
/// @dev returns the revision number of the contract.
|
|
/// Needs to be defined in the inherited class as a constant.
|
|
function getRevision() internal pure virtual returns (uint256);
|
|
|
|
// Reserved storage space to allow for layout changes in the future.
|
|
uint256[50] private ______gap;
|
|
}
|