Created
February 7, 2023 16:37
-
-
Save krogla/3e9358fdea558f0123b6644da2e13980 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
// solhint-disable-next-line lido/fixed-compiler-version | |
pragma solidity >=0.4.24 <0.9.0; | |
library UnstructuredStorageMap { | |
function getStorageMappingUint256(bytes32 position, uint256 key) internal view returns (uint256 data) { | |
return getStorageMappingUint256Offset(position, key, 0); | |
} | |
function getStorageMappingUint256Offset(bytes32 position, uint256 key, uint256 offset) | |
internal | |
view | |
returns (uint256 data) | |
{ | |
assembly { | |
mstore(0, key) | |
mstore(32, position) | |
let hash := add(keccak256(0, 64), offset) | |
data := sload(hash) | |
} | |
} | |
function setStorageMappingUint256(bytes32 position, uint256 key, uint256 data) internal { | |
setStorageMappingUint256Offset(position, key, 0, data); | |
} | |
function setStorageMappingUint256Offset(bytes32 position, uint256 key, uint256 offset, uint256 data) internal { | |
assembly { | |
mstore(0, key) | |
mstore(32, position) | |
let hash := add(keccak256(0, 64), offset) | |
sstore(hash, data) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
used for
mapping(uint256 => uint256)
ormapping(uint256 => struct)