UniswapV4PoolManagerHelpers
Inherits: Assertion
Title: UniswapV4PoolManagerHelpers
Author: Phylax Systems
Fork-aware Uniswap v4 PoolManager state helpers used by the example assertions.
V4 stores every pool’s state inside the singleton PoolManager at slot 6
(mapping(PoolId => Pool.State) _pools). For each watched pool we compute the per-pool
base storage slot once at construction and then read the packed Slot0, liquidity, and
fee growth via the manager’s extsload(bytes32) precompile. Protocol-fee accruals are
tracked globally per currency on the manager, not per pool.
Constants
MIN_SQRT_PRICE
uint160 internal constant MIN_SQRT_PRICE = 4_295_128_739
MAX_SQRT_PRICE
uint160 internal constant MAX_SQRT_PRICE = 1_461_446_703_485_210_103_287_273_052_203_988_822_378_723_970_342
POOLS_SLOT
Storage slot of mapping(PoolId => Pool.State) _pools on the PoolManager. Mirrors
StateLibrary.POOLS_SLOT from v4-core.
uint256 internal constant POOLS_SLOT = 6
FEE_GROWTH_GLOBAL0_OFFSET
Per-pool offsets inside Pool.State. Mirror StateLibrary constants in v4-core.
uint256 internal constant FEE_GROWTH_GLOBAL0_OFFSET = 1
FEE_GROWTH_GLOBAL1_OFFSET
uint256 internal constant FEE_GROWTH_GLOBAL1_OFFSET = 2
LIQUIDITY_OFFSET
uint256 internal constant LIQUIDITY_OFFSET = 3
MANAGER
address internal immutable MANAGER
CURRENCY0
address internal immutable CURRENCY0
CURRENCY1
address internal immutable CURRENCY1
POOL_ID
bytes32 internal immutable POOL_ID
POOL_STATE_BASE_SLOT
bytes32 internal immutable POOL_STATE_BASE_SLOT
Functions
constructor
Accepts the manager and the full PoolKey explicitly so the constructor never reads
from the adopter. The Credible Layer assertion-deploy runtime is isolated from the
calling state, so a manager.extsload(...) call in the constructor would revert with
EXTCODESIZE = 0.
constructor(address manager_, IUniswapV4PoolManagerLike.PoolKey memory poolKey_) ;
_snapshotAt
function _snapshotAt(PhEvm.ForkId memory fork) internal view returns (PoolSnapshot memory snapshot);
_slot0At
function _slot0At(PhEvm.ForkId memory fork) internal view returns (Slot0Snapshot memory slot0);
_liquidityAt
function _liquidityAt(PhEvm.ForkId memory fork) internal view returns (uint128 liquidity);
_feeGrowthGlobalsAt
function _feeGrowthGlobalsAt(PhEvm.ForkId memory fork) internal view returns (uint256 g0, uint256 g1);
_protocolFeesAccruedAt
function _protocolFeesAccruedAt(address currency, PhEvm.ForkId memory fork) internal view returns (uint256);
_currencyBalanceAt
function _currencyBalanceAt(address currency, address account, PhEvm.ForkId memory fork)
internal
view
returns (uint256);
_isNativeCurrency
function _isNativeCurrency(address currency) internal pure returns (bool);
_extsloadAt
function _extsloadAt(bytes32 slot, PhEvm.ForkId memory fork) internal view returns (bytes32);
_offsetSlot
function _offsetSlot(uint256 offset) internal view returns (bytes32);
_swapArgs
function _swapArgs(bytes memory input)
internal
pure
returns (
IUniswapV4PoolManagerLike.PoolKey memory key,
IUniswapV4PoolManagerLike.SwapParams memory params,
bytes memory hookData
);
_modifyLiquidityArgs
function _modifyLiquidityArgs(bytes memory input)
internal
pure
returns (
IUniswapV4PoolManagerLike.PoolKey memory key,
IUniswapV4PoolManagerLike.ModifyLiquidityParams memory params,
bytes memory hookData
);
_collectProtocolFeesArgs
function _collectProtocolFeesArgs(bytes memory input)
internal
pure
returns (address recipient, address currency, uint256 amount);
_inRange
function _inRange(int24 currentTick, int24 tickLower, int24 tickUpper) internal pure returns (bool);
_matchesConfiguredPool
function _matchesConfiguredPool(IUniswapV4PoolManagerLike.PoolKey memory key) internal view returns (bool);
_requireConfiguredManagerIsAdopter
function _requireConfiguredManagerIsAdopter() internal view;
_args
function _args(bytes memory input) internal pure returns (bytes memory args);
Structs
Slot0Snapshot
struct Slot0Snapshot {
uint160 sqrtPriceX96;
int24 tick;
uint24 protocolFee;
uint24 lpFee;
}
PoolSnapshot
struct PoolSnapshot {
Slot0Snapshot slot0;
uint128 liquidity;
uint256 feeGrowthGlobal0X128;
uint256 feeGrowthGlobal1X128;
uint256 protocolFeesAccrued0;
uint256 protocolFeesAccrued1;
uint256 managerBalance0;
uint256 managerBalance1;
}