Open the app

HookrNativeMechanicsCoordinatorLibV2

Read about the admission library the market coordinator delegates to, and exactly how it routes the founding-position fee.

Deployed at 0xafC0a7656DF8B1aA5A173d04612a9661C4b9c7E2, compiled from src/libraries/HookrNativeMechanicsCoordinatorLibV2.sol at source commit 8db7fc940938f811f508ba9cb0c8f2d3f24c9a25. Its source is verified on the explorer; see Verification.

Coordinator-side admission and fee routing for the native mechanics module

A linked library, executed by DELEGATECALL, so its storage writes and its transfers happen in the coordinator's context.

Constants

NameTypeValue
MODULE_KEYbytes32keccak256("HOOKR_NATIVE_MECHANICS")
CONFIG_SCHEMA_HASHbytes32the canonical config schema hash the module must report
REQUIRED_PHASE_MASKuint8all phases
MIN_MODULE_VERSIONuint322
MAX_MODULE_VERSIONuint322
QUERY_GASuint32150,000
MAX_GUARD_BLOCKSuint256100,000
GUARD_ACCOUNTING_STORAGE_SLOTbytes32the fixed slot in the coordinator's storage that holds every pool's guard-accounting record

Both version bounds are 2, so only HookrNativeMechanicsBlockV2 admits through this library. A module at any other version fails closed.

Functions

validateOrigin

Resolves the one canonical native module in the selections and proves every admission fact. Returns zero for both values when no native module is selected, which is how the coordinator detects a stack that would have no rules.

function validateOrigin(
    IHookrNativeMechanicsCatalogReadV1 registry,
    uint8 origin,
    uint24 baseLpFeePips,
    HookrModuleTypesV1.ModuleSelection[] calldata selections,
    address treasuryReader,
    address creator
) public view returns (address module, bytes32 codeHash);

Parameters

NameTypeDescription
registryIHookrNativeMechanicsCatalogReadV1Registry exposing the module snapshot
originuint81 for the new-token lane, anything else for the existing-asset lane
baseLpFeePipsuint24The base fee the stack limits declare
selectionsModuleSelection[]The module selections being frozen
treasuryReaderaddressContract exposing treasuryBeneficiary() and protocolShareBps(address creator); the coordinator passes itself
creatoraddressAccount opening the market

Returns

NameTypeDescription
moduleaddressThe bound native-mechanics implementation, or zero
codeHashbytes32Its runtime code hash at admission time

Every external read here, except the coordinator's own treasuryBeneficiary(), is a gas-bounded staticcall that requires a full 32-byte return word. A target that reverts, runs long, or returns a short word fails admission rather than being treated as absent.

validateAndRecordMarket

Runs validateOrigin and records the module binding for the pool atomically.

function validateAndRecordMarket(
    IHookrNativeMechanicsCatalogReadV1 registry,
    uint8 origin,
    uint24 baseLpFeePips,
    HookrModuleTypesV1.ModuleSelection[] calldata selections,
    bytes32 poolId,
    address treasuryReader,
    address creator
) public returns (address module);

Returns

NameTypeDescription
moduleaddressThe bound implementation; the coordinator reverts NativeMechanicsModuleRequired on zero

recordMarket

Writes the module and its code hash into the pool's guard-accounting record. Reverts InvalidGuardAccounting if a record already exists for that pool, and InvalidNativeMechanicsModule when exactly one of the module address and its code hash is zero.

function recordMarket(bytes32 poolId, address module, bytes32 moduleCodeHash) public;

guardLpEarned

Reads the module's cumulative guard-window quote earnings, but only from the exact implementation recorded at market creation and only while its runtime code hash is unchanged. Reverts InvalidNativeMechanicsModule on drift.

function guardLpEarned(address module, bytes32 expectedCodeHash, bytes32 poolId)
    public
    view
    returns (uint256 earned);

guardAccounting

Per-pool guard-window view for interfaces: the module recorded for the pool and its cumulative guard-window earnings. Nothing is withheld and nothing is pending, so there is nothing else to report.

function guardAccounting(bytes32 poolId) public view returns (address module, uint256 cumulativeEarned);

Returns

NameTypeDescription
moduleaddressThe native module recorded for this pool
cumulativeEarneduint256Cumulative guard-window quote LP earnings, read from that module at its recorded code hash

routeFoundingPositionFees

Sends both collected currencies to lpFeeRecipient and emits LpFeesCollected. Executed by DELEGATECALL, so the transfers originate from the coordinator.

function routeFoundingPositionFees(FeeRouteInput memory input) public {
    if (input.amount0 != 0) _refund(input.currency0, input.lpFeeRecipient, input.amount0);
    if (input.amount1 != 0) _refund(input.currency1, input.lpFeeRecipient, input.amount1);
    emit LpFeesCollected(input.poolId, input.lpFeeRecipient, input.amount0, input.amount1);
}

That is the whole body. There is no withholding branch and no treasury read.

ERC-20 transfers inside _refund are balance-checked on both sides and revert TaxedTransfer if either party's balance moves by anything other than the exact amount.

Structs

FeeRouteInput

struct FeeRouteInput {
    bytes32 poolId;
    address currency0;
    address currency1;
    address lpFeeRecipient;
    uint256 amount0;
    uint256 amount1;
}

GuardAccounting

struct GuardAccounting {
    address module;
    bytes32 moduleCodeHash;
}

Events

LpFeesCollected(bytes32 indexed poolId, address indexed recipient, uint256 amount0, uint256 amount1); the library declares poolId as bytes32, the coordinator as PoolId, and the topic is the same.

Errors

InvalidNativeMechanicsModule, ProtocolShareTierMismatch(expected, actual), GuardRequiresLockedFoundingPosition, InvalidGuardAccounting, TransferFailed, TaxedTransfer, NativeTransferFailed.