Split StorageSlot into TransientSlot (#5239)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
|
||||
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
|
||||
|
||||
pragma solidity ^0.8.24;
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
/**
|
||||
* @dev Library for reading and writing primitive types to specific storage slots.
|
||||
@ -29,24 +29,6 @@ pragma solidity ^0.8.24;
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* Since version 5.1, this library also support writing and reading value types to and from transient storage.
|
||||
*
|
||||
* * Example using transient storage:
|
||||
* ```solidity
|
||||
* contract Lock {
|
||||
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
|
||||
* bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;
|
||||
*
|
||||
* modifier locked() {
|
||||
* require(!_LOCK_SLOT.asBoolean().tload());
|
||||
*
|
||||
* _LOCK_SLOT.asBoolean().tstore(true);
|
||||
* _;
|
||||
* _LOCK_SLOT.asBoolean().tstore(false);
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* TIP: Consider using this library along with {SlotDerivation}.
|
||||
*/
|
||||
library StorageSlot {
|
||||
@ -158,154 +140,4 @@ library StorageSlot {
|
||||
r.slot := store.slot
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev UDVT that represent a slot holding a address.
|
||||
*/
|
||||
type AddressSlotType is bytes32;
|
||||
|
||||
/**
|
||||
* @dev Cast an arbitrary slot to a AddressSlotType.
|
||||
*/
|
||||
function asAddress(bytes32 slot) internal pure returns (AddressSlotType) {
|
||||
return AddressSlotType.wrap(slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev UDVT that represent a slot holding a bool.
|
||||
*/
|
||||
type BooleanSlotType is bytes32;
|
||||
|
||||
/**
|
||||
* @dev Cast an arbitrary slot to a BooleanSlotType.
|
||||
*/
|
||||
function asBoolean(bytes32 slot) internal pure returns (BooleanSlotType) {
|
||||
return BooleanSlotType.wrap(slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev UDVT that represent a slot holding a bytes32.
|
||||
*/
|
||||
type Bytes32SlotType is bytes32;
|
||||
|
||||
/**
|
||||
* @dev Cast an arbitrary slot to a Bytes32SlotType.
|
||||
*/
|
||||
function asBytes32(bytes32 slot) internal pure returns (Bytes32SlotType) {
|
||||
return Bytes32SlotType.wrap(slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev UDVT that represent a slot holding a uint256.
|
||||
*/
|
||||
type Uint256SlotType is bytes32;
|
||||
|
||||
/**
|
||||
* @dev Cast an arbitrary slot to a Uint256SlotType.
|
||||
*/
|
||||
function asUint256(bytes32 slot) internal pure returns (Uint256SlotType) {
|
||||
return Uint256SlotType.wrap(slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev UDVT that represent a slot holding a int256.
|
||||
*/
|
||||
type Int256SlotType is bytes32;
|
||||
|
||||
/**
|
||||
* @dev Cast an arbitrary slot to a Int256SlotType.
|
||||
*/
|
||||
function asInt256(bytes32 slot) internal pure returns (Int256SlotType) {
|
||||
return Int256SlotType.wrap(slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Load the value held at location `slot` in transient storage.
|
||||
*/
|
||||
function tload(AddressSlotType slot) internal view returns (address value) {
|
||||
assembly ("memory-safe") {
|
||||
value := tload(slot)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Store `value` at location `slot` in transient storage.
|
||||
*/
|
||||
function tstore(AddressSlotType slot, address value) internal {
|
||||
assembly ("memory-safe") {
|
||||
tstore(slot, value)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Load the value held at location `slot` in transient storage.
|
||||
*/
|
||||
function tload(BooleanSlotType slot) internal view returns (bool value) {
|
||||
assembly ("memory-safe") {
|
||||
value := tload(slot)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Store `value` at location `slot` in transient storage.
|
||||
*/
|
||||
function tstore(BooleanSlotType slot, bool value) internal {
|
||||
assembly ("memory-safe") {
|
||||
tstore(slot, value)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Load the value held at location `slot` in transient storage.
|
||||
*/
|
||||
function tload(Bytes32SlotType slot) internal view returns (bytes32 value) {
|
||||
assembly ("memory-safe") {
|
||||
value := tload(slot)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Store `value` at location `slot` in transient storage.
|
||||
*/
|
||||
function tstore(Bytes32SlotType slot, bytes32 value) internal {
|
||||
assembly ("memory-safe") {
|
||||
tstore(slot, value)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Load the value held at location `slot` in transient storage.
|
||||
*/
|
||||
function tload(Uint256SlotType slot) internal view returns (uint256 value) {
|
||||
assembly ("memory-safe") {
|
||||
value := tload(slot)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Store `value` at location `slot` in transient storage.
|
||||
*/
|
||||
function tstore(Uint256SlotType slot, uint256 value) internal {
|
||||
assembly ("memory-safe") {
|
||||
tstore(slot, value)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Load the value held at location `slot` in transient storage.
|
||||
*/
|
||||
function tload(Int256SlotType slot) internal view returns (int256 value) {
|
||||
assembly ("memory-safe") {
|
||||
value := tload(slot)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Store `value` at location `slot` in transient storage.
|
||||
*/
|
||||
function tstore(Int256SlotType slot, int256 value) internal {
|
||||
assembly ("memory-safe") {
|
||||
tstore(slot, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user