Working tree is now the canonical repo. Off-chain play-money + trustless on-chain (FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution, mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
16 KiB
LibTransient
Library for transient storage operations.
Note:
The functions postfixed with Compat will only use transient storage on L1.
L2s are super cheap anyway.
For best safety, always clear the storage after use.
Structs
TUint256
struct TUint256 {
uint256 _spacer;
}
Pointer struct to a uint256 in transient storage.
TInt256
struct TInt256 {
uint256 _spacer;
}
Pointer struct to a int256 in transient storage.
TBytes32
struct TBytes32 {
uint256 _spacer;
}
Pointer struct to a bytes32 in transient storage.
TAddress
struct TAddress {
uint256 _spacer;
}
Pointer struct to a address in transient storage.
TBool
struct TBool {
uint256 _spacer;
}
Pointer struct to a bool in transient storage.
TBytes
struct TBytes {
uint256 _spacer;
}
Pointer struct to a bytes in transient storage.
TStack
struct TStack {
uint256 _spacer;
}
Pointer struct to a stack pointer generator in transient storage.
This stack does not directly take in values. Instead, it generates pointers
that can be casted to any of the other transient storage pointer struct.
Custom Errors
StackIsEmpty()
error StackIsEmpty()
The transient stack is empty.
Constants
REGISTRY
address internal constant REGISTRY =
0x000000000000297f64C7F8d9595e43257908F170
The canonical address of the transient registry.
See: https://gist.github.com/Vectorized/4ab665d7a234ef5aaaff2e5091ec261f
Uint256 Operations
tUint256(bytes32)
function tUint256(bytes32 tSlot)
internal
pure
returns (TUint256 storage ptr)
Returns a pointer to a uint256 in transient storage.
tUint256(uint256)
function tUint256(uint256 tSlot)
internal
pure
returns (TUint256 storage ptr)
Returns a pointer to a uint256 in transient storage.
get(TUint256)
function get(TUint256 storage ptr) internal view returns (uint256 result)
Returns the value at transient ptr.
getCompat(TUint256)
function getCompat(TUint256 storage ptr)
internal
view
returns (uint256 result)
Returns the value at transient ptr.
set(TUint256,uint256)
function set(TUint256 storage ptr, uint256 value) internal
Sets the value at transient ptr.
setCompat(TUint256,uint256)
function setCompat(TUint256 storage ptr, uint256 value) internal
Sets the value at transient ptr.
clear(TUint256)
function clear(TUint256 storage ptr) internal
Clears the value at transient ptr.
clearCompat(TUint256)
function clearCompat(TUint256 storage ptr) internal
Clears the value at transient ptr.
inc(TUint256)
function inc(TUint256 storage ptr) internal returns (uint256 newValue)
Increments the value at transient ptr by 1.
incCompat(TUint256)
function incCompat(TUint256 storage ptr)
internal
returns (uint256 newValue)
Increments the value at transient ptr by 1.
inc(TUint256,uint256)
function inc(TUint256 storage ptr, uint256 delta)
internal
returns (uint256 newValue)
Increments the value at transient ptr by delta.
incCompat(TUint256,uint256)
function incCompat(TUint256 storage ptr, uint256 delta)
internal
returns (uint256 newValue)
Increments the value at transient ptr by delta.
dec(TUint256)
function dec(TUint256 storage ptr) internal returns (uint256 newValue)
Decrements the value at transient ptr by 1.
decCompat(TUint256)
function decCompat(TUint256 storage ptr)
internal
returns (uint256 newValue)
Decrements the value at transient ptr by delta.
dec(TUint256,uint256)
function dec(TUint256 storage ptr, uint256 delta)
internal
returns (uint256 newValue)
Decrements the value at transient ptr by delta.
decCompat(TUint256,uint256)
function decCompat(TUint256 storage ptr, uint256 delta)
internal
returns (uint256 newValue)
Decrements the value at transient ptr by delta.
incSigned(TUint256,int256)
function incSigned(TUint256 storage ptr, int256 delta)
internal
returns (uint256 newValue)
Increments the value at transient ptr by delta.
incSignedCompat(TUint256,int256)
function incSignedCompat(TUint256 storage ptr, int256 delta)
internal
returns (uint256 newValue)
Increments the value at transient ptr by delta.
decSigned(TUint256,int256)
function decSigned(TUint256 storage ptr, int256 delta)
internal
returns (uint256 newValue)
Decrements the value at transient ptr by delta.
decSignedCompat(TUint256,int256)
function decSignedCompat(TUint256 storage ptr, int256 delta)
internal
returns (uint256 newValue)
Decrements the value at transient ptr by delta.
Int256 Operations
tInt256(bytes32)
function tInt256(bytes32 tSlot)
internal
pure
returns (TInt256 storage ptr)
Returns a pointer to a int256 in transient storage.
tInt256(uint256)
function tInt256(uint256 tSlot)
internal
pure
returns (TInt256 storage ptr)
Returns a pointer to a int256 in transient storage.
get(TInt256)
function get(TInt256 storage ptr) internal view returns (int256 result)
Returns the value at transient ptr.
getCompat(TInt256)
function getCompat(TInt256 storage ptr)
internal
view
returns (int256 result)
Returns the value at transient ptr.
set(TInt256,int256)
function set(TInt256 storage ptr, int256 value) internal
Sets the value at transient ptr.
setCompat(TInt256,int256)
function setCompat(TInt256 storage ptr, int256 value) internal
Sets the value at transient ptr.
clear(TInt256)
function clear(TInt256 storage ptr) internal
Clears the value at transient ptr.
clearCompat(TInt256)
function clearCompat(TInt256 storage ptr) internal
Clears the value at transient ptr.
inc(TInt256)
function inc(TInt256 storage ptr) internal returns (int256 newValue)
Increments the value at transient ptr by 1.
incCompat(TInt256)
function incCompat(TInt256 storage ptr)
internal
returns (int256 newValue)
Increments the value at transient ptr by 1.
inc(TInt256,int256)
function inc(TInt256 storage ptr, int256 delta)
internal
returns (int256 newValue)
Increments the value at transient ptr by delta.
incCompat(TInt256,int256)
function incCompat(TInt256 storage ptr, int256 delta)
internal
returns (int256 newValue)
Increments the value at transient ptr by delta.
dec(TInt256)
function dec(TInt256 storage ptr) internal returns (int256 newValue)
Decrements the value at transient ptr by 1.
decCompat(TInt256)
function decCompat(TInt256 storage ptr)
internal
returns (int256 newValue)
Decrements the value at transient ptr by 1.
dec(TInt256,int256)
function dec(TInt256 storage ptr, int256 delta)
internal
returns (int256 newValue)
Decrements the value at transient ptr by delta.
decCompat(TInt256,int256)
function decCompat(TInt256 storage ptr, int256 delta)
internal
returns (int256 newValue)
Decrements the value at transient ptr by delta.
Bytes32 Operations
tBytes32(bytes32)
function tBytes32(bytes32 tSlot)
internal
pure
returns (TBytes32 storage ptr)
Returns a pointer to a bytes32 in transient storage.
tBytes32(uint256)
function tBytes32(uint256 tSlot)
internal
pure
returns (TBytes32 storage ptr)
Returns a pointer to a bytes32 in transient storage.
get(TBytes32)
function get(TBytes32 storage ptr) internal view returns (bytes32 result)
Returns the value at transient ptr.
getCompat(TBytes32)
function getCompat(TBytes32 storage ptr)
internal
view
returns (bytes32 result)
Returns the value at transient ptr.
set(TBytes32,bytes32)
function set(TBytes32 storage ptr, bytes32 value) internal
Sets the value at transient ptr.
setCompat(TBytes32,bytes32)
function setCompat(TBytes32 storage ptr, bytes32 value) internal
Sets the value at transient ptr.
clear(TBytes32)
function clear(TBytes32 storage ptr) internal
Clears the value at transient ptr.
clearCompat(TBytes32)
function clearCompat(TBytes32 storage ptr) internal
Clears the value at transient ptr.
Address Operations
tAddress(bytes32)
function tAddress(bytes32 tSlot)
internal
pure
returns (TAddress storage ptr)
Returns a pointer to a address in transient storage.
tAddress(uint256)
function tAddress(uint256 tSlot)
internal
pure
returns (TAddress storage ptr)
Returns a pointer to a address in transient storage.
get(TAddress)
function get(TAddress storage ptr) internal view returns (address result)
Returns the value at transient ptr.
getCompat(TAddress)
function getCompat(TAddress storage ptr)
internal
view
returns (address result)
Returns the value at transient ptr.
set(TAddress,address)
function set(TAddress storage ptr, address value) internal
Sets the value at transient ptr.
setCompat(TAddress,address)
function setCompat(TAddress storage ptr, address value) internal
Sets the value at transient ptr.
clear(TAddress)
function clear(TAddress storage ptr) internal
Clears the value at transient ptr.
clearCompat(TAddress)
function clearCompat(TAddress storage ptr) internal
Clears the value at transient ptr.
Bool Operations
tBool(bytes32)
function tBool(bytes32 tSlot) internal pure returns (TBool storage ptr)
Returns a pointer to a bool in transient storage.
tBool(uint256)
function tBool(uint256 tSlot) internal pure returns (TBool storage ptr)
Returns a pointer to a bool in transient storage.
get(TBool)
function get(TBool storage ptr) internal view returns (bool result)
Returns the value at transient ptr.
getCompat(TBool)
function getCompat(TBool storage ptr) internal view returns (bool result)
Returns the value at transient ptr.
set(TBool,bool)
function set(TBool storage ptr, bool value) internal
Sets the value at transient ptr.
setCompat(TBool,bool)
function setCompat(TBool storage ptr, bool value) internal
Sets the value at transient ptr.
clear(TBool)
function clear(TBool storage ptr) internal
Clears the value at transient ptr.
clearCompat(TBool)
function clearCompat(TBool storage ptr) internal
Clears the value at transient ptr.
Bytes Operations
tBytes(bytes32)
function tBytes(bytes32 tSlot) internal pure returns (TBytes storage ptr)
Returns a pointer to a bytes in transient storage.
tBytes(uint256)
function tBytes(uint256 tSlot) internal pure returns (TBytes storage ptr)
Returns a pointer to a bytes in transient storage.
length(TBytes)
function length(TBytes storage ptr)
internal
view
returns (uint256 result)
Returns the length of the bytes stored at transient ptr.
lengthCompat(TBytes)
function lengthCompat(TBytes storage ptr)
internal
view
returns (uint256 result)
Returns the length of the bytes stored at transient ptr.
get(TBytes)
function get(TBytes storage ptr)
internal
view
returns (bytes memory result)
Returns the bytes stored at transient ptr.
getCompat(TBytes)
function getCompat(TBytes storage ptr)
internal
view
returns (bytes memory result)
Returns the bytes stored at transient ptr.
set(TBytes,bytes)
function set(TBytes storage ptr, bytes memory value) internal
Sets the value at transient ptr.
setCompat(TBytes,bytes)
function setCompat(TBytes storage ptr, bytes memory value) internal
Sets the value at transient ptr.
setCalldata(TBytes,bytes)
function setCalldata(TBytes storage ptr, bytes calldata value) internal
Sets the value at transient ptr.
setCalldataCompat(TBytes,bytes)
function setCalldataCompat(TBytes storage ptr, bytes calldata value)
internal
Sets the value at transient ptr.
clear(TBytes)
function clear(TBytes storage ptr) internal
Clears the value at transient ptr.
clearCompat(TBytes)
function clearCompat(TBytes storage ptr) internal
Clears the value at transient ptr.
Stack Operations
tStack(bytes32)
function tStack(bytes32 tSlot) internal pure returns (TStack storage ptr)
Returns a pointer to a stack in transient storage.
tStack(uint256)
function tStack(uint256 tSlot) internal pure returns (TStack storage ptr)
Returns a pointer to a stack in transient storage.
length(TStack)
function length(TStack storage ptr)
internal
view
returns (uint256 result)
Returns the number of elements in the stack.
clear(TStack)
function clear(TStack storage ptr) internal
Clears the stack at ptr.
Note: Future usage of the stack will point to a fresh transient storage region.
place(TStack)
function place(TStack storage ptr) internal returns (bytes32 topPtr)
Increments the stack length by 1, and returns a pointer to the top element.
We don't want to call this push as it does not take in an element value.
Note: The value pointed to might not be cleared from previous usage.
peek(TStack)
function peek(TStack storage ptr) internal view returns (bytes32 topPtr)
Returns a pointer to the top element. Returns the zero pointer if the stack is empty.
This method can help avoid an additional TLOAD, but you MUST check if the
returned pointer is zero. And if it is, please DO NOT read / write to it.
top(TStack)
function top(TStack storage ptr) internal view returns (bytes32 topPtr)
Returns a pointer to the top element. Reverts if the stack is empty.
pop(TStack)
function pop(TStack storage ptr) internal returns (bytes32 lastTopPtr)
Decrements the stack length by 1, returns a pointer to the top element
before the popping. Reverts if the stack is empty.
Note: Popping from the stack does NOT auto-clear the top value.
Transient Registry Operations
registrySet(bytes32,bytes)
function registrySet(bytes32 key, bytes memory value) internal
Sets the value for the key.
If the key does not exist, its admin will be set to the caller.
If the key already exist, its value will be overwritten,
and the caller must be the current admin for the key.
Reverts with empty data if the registry has not been deployed.
registryGet(bytes32)
function registryGet(bytes32 key)
internal
view
returns (bytes memory result)
Returns the value for the key.
Reverts if the key does not exist.
Reverts with empty data if the registry has not been deployed.
registryClear(bytes32)
function registryClear(bytes32 key) internal
Clears the admin and the value for the key.
The caller must be the current admin of the key.
Reverts with empty data if the registry has not been deployed.
registryAdminOf(bytes32)
function registryAdminOf(bytes32 key)
internal
view
returns (address result)
Returns the admin of the key.
Returns address(0) if the key does not exist.
Reverts with empty data if the registry has not been deployed.
registryChangeAdmin(bytes32,address)
function registryChangeAdmin(bytes32 key, address newAdmin) internal
Changes the admin of the key.
The caller must be the current admin of the key.
The new admin must not be address(0).
Reverts with empty data if the registry has not been deployed.