03 · Build
The hub
The one contract a stacked pool calls. It forwards each callback to your hooks.
TalosHook is the hook address stored on the pool. The other contracts are modules. The pool never calls them directly.
How a swap moves
The PoolManager calls the hub. The hub looks at the list you registered and calls only the callbacks each module turned on. Before the swap, it collects fee overrides and keeps the highest one. After the swap, modules that need tokens call pull on the hub. The hub takes those tokens and returns the sum as its after-swap delta, so the pool's books balance against the hub, which is the address the pool actually called.
The rules that always hold
- One to eight modules. No duplicates. Order is registration order.
- Each module must already point at this hub.
- The wallet that calls
createMarketmust be the wallet that initializes the pool. - Exact output swaps revert. These hooks are exact-input only.
- A non-zero before-swap delta reverts. The hub does not take custom curves.
- If any module reverts, the trade reverts. Later modules in that callback do not get a turn.
- A module may
pullor relay a fee only while the hub is inside that module's callback, and only for the pool in that callback.
Extend LaunchHook, or implement IMarketModule and pull tokens through the hub instead of calling the PoolManager yourself. Deploy the new contract at its own flag address. Call attachHub once from the deployer, then createLaunch with the hub on the pool key, then add it in createMarket. A new pool keeps this hub on key.hooks. A pool that already exists keeps the module list it launched with.
The order of calls, and the mistakes that revert.