Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Francisco Giordano <fg@frang.io> Co-authored-by: Joseph Delong <joseph@delong.me> Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com> Co-authored-by: Renan Souza <renan.rodrigues.souza1@gmail.com> Co-authored-by: Ernesto García <ernestognw@gmail.com> Co-authored-by: Voronor <129545215+voronor@users.noreply.github.com> Co-authored-by: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Co-authored-by: Michalis Kargakis <kargakis@protonmail.com> Co-authored-by: Bilog WEB3 <155262265+Bilogweb3@users.noreply.github.com> Co-authored-by: Fallengirl <155266340+Fallengirl@users.noreply.github.com> Co-authored-by: XxAlex74xX <30472093+XxAlex74xX@users.noreply.github.com> Co-authored-by: PixelPilot <161360836+PixelPil0t1@users.noreply.github.com> Co-authored-by: kilavvy <140459108+kilavvy@users.noreply.github.com> Co-authored-by: Devkuni <155117116+detrina@users.noreply.github.com> Co-authored-by: Danbo <140512416+dannbbb1@users.noreply.github.com> Co-authored-by: Ann Wagner <chant_77_swirly@icloud.com> Co-authored-by: comfsrt <155266597+comfsrt@users.noreply.github.com> Co-authored-by: Bob <158583129+bouchmann@users.noreply.github.com> Co-authored-by: JohnBonny <158583902+JohnBonny@users.noreply.github.com> Co-authored-by: moonman <155266991+moooonman@users.noreply.github.com> Co-authored-by: kazak <alright-epsilon8h@icloud.com> Co-authored-by: Wei <ybxerlvqtx@rambler.ru> Co-authored-by: Maxim Evtush <154841002+maximevtush@users.noreply.github.com> Co-authored-by: Vitalyr <158586577+Vitaliyr888@users.noreply.github.com> Co-authored-by: pendrue <158588659+pendrue@users.noreply.github.com> Co-authored-by: Tronica <wudmytrotest404@gmail.com> Co-authored-by: emmmm <155267286+eeemmmmmm@users.noreply.github.com> Co-authored-by: bigbear <155267841+aso20455@users.noreply.github.com> Co-authored-by: Tomás Andróil <tomasandroil@gmail.com> Co-authored-by: GooseMatrix <155266802+GooseMatrix@users.noreply.github.com> Co-authored-by: jasmy <3776356370@qq.com> Co-authored-by: SITADRITA1 <mrlime2018@gmail.com> Co-authored-by: Ocenka <testoviydiman1@gmail.com>
184 lines
5.0 KiB
Solidity
184 lines
5.0 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
// OpenZeppelin Contracts (last updated v5.3.0) (utils/TransientSlot.sol)
|
|
// This file was procedurally generated from scripts/generate/templates/TransientSlot.js.
|
|
|
|
pragma solidity ^0.8.24;
|
|
|
|
/**
|
|
* @dev Library for reading and writing value-types to specific transient storage slots.
|
|
*
|
|
* Transient slots are often used to store temporary values that are removed after the current transaction.
|
|
* This library helps with reading and writing to such slots without the need for inline assembly.
|
|
*
|
|
* * Example reading and writing values using transient storage:
|
|
* ```solidity
|
|
* contract Lock {
|
|
* using TransientSlot for *;
|
|
*
|
|
* // 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 TransientSlot {
|
|
/**
|
|
* @dev UDVT that represents a slot holding an address.
|
|
*/
|
|
type AddressSlot is bytes32;
|
|
|
|
/**
|
|
* @dev Cast an arbitrary slot to a AddressSlot.
|
|
*/
|
|
function asAddress(bytes32 slot) internal pure returns (AddressSlot) {
|
|
return AddressSlot.wrap(slot);
|
|
}
|
|
|
|
/**
|
|
* @dev UDVT that represents a slot holding a bool.
|
|
*/
|
|
type BooleanSlot is bytes32;
|
|
|
|
/**
|
|
* @dev Cast an arbitrary slot to a BooleanSlot.
|
|
*/
|
|
function asBoolean(bytes32 slot) internal pure returns (BooleanSlot) {
|
|
return BooleanSlot.wrap(slot);
|
|
}
|
|
|
|
/**
|
|
* @dev UDVT that represents a slot holding a bytes32.
|
|
*/
|
|
type Bytes32Slot is bytes32;
|
|
|
|
/**
|
|
* @dev Cast an arbitrary slot to a Bytes32Slot.
|
|
*/
|
|
function asBytes32(bytes32 slot) internal pure returns (Bytes32Slot) {
|
|
return Bytes32Slot.wrap(slot);
|
|
}
|
|
|
|
/**
|
|
* @dev UDVT that represents a slot holding a uint256.
|
|
*/
|
|
type Uint256Slot is bytes32;
|
|
|
|
/**
|
|
* @dev Cast an arbitrary slot to a Uint256Slot.
|
|
*/
|
|
function asUint256(bytes32 slot) internal pure returns (Uint256Slot) {
|
|
return Uint256Slot.wrap(slot);
|
|
}
|
|
|
|
/**
|
|
* @dev UDVT that represents a slot holding a int256.
|
|
*/
|
|
type Int256Slot is bytes32;
|
|
|
|
/**
|
|
* @dev Cast an arbitrary slot to a Int256Slot.
|
|
*/
|
|
function asInt256(bytes32 slot) internal pure returns (Int256Slot) {
|
|
return Int256Slot.wrap(slot);
|
|
}
|
|
|
|
/**
|
|
* @dev Load the value held at location `slot` in transient storage.
|
|
*/
|
|
function tload(AddressSlot slot) internal view returns (address value) {
|
|
assembly ("memory-safe") {
|
|
value := tload(slot)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Store `value` at location `slot` in transient storage.
|
|
*/
|
|
function tstore(AddressSlot slot, address value) internal {
|
|
assembly ("memory-safe") {
|
|
tstore(slot, value)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Load the value held at location `slot` in transient storage.
|
|
*/
|
|
function tload(BooleanSlot slot) internal view returns (bool value) {
|
|
assembly ("memory-safe") {
|
|
value := tload(slot)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Store `value` at location `slot` in transient storage.
|
|
*/
|
|
function tstore(BooleanSlot slot, bool value) internal {
|
|
assembly ("memory-safe") {
|
|
tstore(slot, value)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Load the value held at location `slot` in transient storage.
|
|
*/
|
|
function tload(Bytes32Slot slot) internal view returns (bytes32 value) {
|
|
assembly ("memory-safe") {
|
|
value := tload(slot)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Store `value` at location `slot` in transient storage.
|
|
*/
|
|
function tstore(Bytes32Slot slot, bytes32 value) internal {
|
|
assembly ("memory-safe") {
|
|
tstore(slot, value)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Load the value held at location `slot` in transient storage.
|
|
*/
|
|
function tload(Uint256Slot slot) internal view returns (uint256 value) {
|
|
assembly ("memory-safe") {
|
|
value := tload(slot)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Store `value` at location `slot` in transient storage.
|
|
*/
|
|
function tstore(Uint256Slot slot, uint256 value) internal {
|
|
assembly ("memory-safe") {
|
|
tstore(slot, value)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Load the value held at location `slot` in transient storage.
|
|
*/
|
|
function tload(Int256Slot slot) internal view returns (int256 value) {
|
|
assembly ("memory-safe") {
|
|
value := tload(slot)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Store `value` at location `slot` in transient storage.
|
|
*/
|
|
function tstore(Int256Slot slot, int256 value) internal {
|
|
assembly ("memory-safe") {
|
|
tstore(slot, value)
|
|
}
|
|
}
|
|
}
|