Skip to content

Commit 2ed8956

Browse files
ernestognwarr00
andauthored
Add _initializableStorageSlot (#5337)
Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com>
1 parent 3bdc3a3 commit 2ed8956

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

.changeset/fast-coats-try.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openzeppelin-solidity': minor
3+
---
4+
5+
`Initializable`: Add `_initializableStorageSlot` function that returns a pointer to the storage struct. The function allows customizing with a custom storage slot with an `override`.

contracts/proxy/utils/Initializable.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,23 @@ abstract contract Initializable {
216216
return _getInitializableStorage()._initializing;
217217
}
218218

219+
/**
220+
* @dev Pointer to storage slot. Allows integrators to override it with a custom storage location.
221+
*
222+
* NOTE: Consider following the ERC-7201 formula to derive storage locations.
223+
*/
224+
function _initializableStorageSlot() internal pure virtual returns (bytes32) {
225+
return INITIALIZABLE_STORAGE;
226+
}
227+
219228
/**
220229
* @dev Returns a pointer to the storage namespace.
221230
*/
222231
// solhint-disable-next-line var-name-mixedcase
223232
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
233+
bytes32 slot = _initializableStorageSlot();
224234
assembly {
225-
$.slot := INITIALIZABLE_STORAGE
235+
$.slot := slot
226236
}
227237
}
228238
}

0 commit comments

Comments
 (0)