What it does
Three things in one module:- Enforce policies - check every rule before the transaction executes
- Collect fees - transfer a flat fee directly to the Functor treasury
- Emit audit events - create an onchain record of every transaction and every blocked attempt
preCheck - before execution
Called by the smart account before every transaction. The hook:- Identifies which keyId signed the transaction (from the validator context)
- Loads the policy set for that keyId
- Evaluates every policy - all must pass (AND semantics)
- Transfers the flat fee from the smart account to the treasury
- Caches pre-execution state (e.g., token balances before a swap)
postCheck - after execution
Called by the smart account after the transaction executes. The hook:- Verifies execution outcome against cached pre-execution state (e.g., did the token balance change as expected?)
- Updates rolling spending counters per token per time window
- Increments rate limit counters
- Emits the
FunctorTxExecutedevent with full transaction details and policy results
Onchain state
The hook maintains per-account, per-keyId state:Time-windowed counters
Spending and rate limit counters reset lazily. On each transaction, the hook checks whether the current time has crossed a window boundary. If it has, the counter resets before evaluation. No background scheduler, no off-chain process.Post-execution verification
Because the hook runs after execution (postCheck), it can verify outcomes that pre-execution checks cannot:- Did a swap return at least the expected amount of tokens?
- Did an unexpected token leave the account?
- Did the account balance change by more than the transaction value?