04 · Developers
Developer guide
How the contracts fit together, and the order of calls that produces a live pool.
A pool stores one hook address. That address is either one launch hook, or TalosHook. The hub forwards each callback to an ordered list of modules. Modules are the launch hooks, or a later contract with the same interface.
The pieces
LaunchHookis the base. It registers a pool, reads the trader, takes tokens, and relays a dynamic fee. Child hooks override the callbacks they care about.TalosHookis the pool's hook when more than one rule should run. It does not store balances for the modules. It forwards calls and sums pulls.TraderRouteris the swap entrypoint. Word 0 ofhookDatais the wallet. Hooks trust that word only when the caller is the router named increateLaunch.PoolSettlepays and takes ERC-20 deltas inside an unlock. It rejects native ETH and a fee-on-transfer token.HookFlagsis the permission bitmap each contract must deploy with. The low 14 bits of the address are those flags.script/00_DeployHooks.s.solmines them with CREATE2.
Lifecycle of a stacked pool
- Deploy the hub, the modules, and TraderRouter against the same PoolManager. Mine each hook address so its flags match
getHookPermissions(). The constructor argument is the PoolManager. - attachHub, once, from the wallet that deployed that module. After this,
module.hub()equals the hub.createMarketreverts if it does not. - createLaunch on every module, from the launch controller. The pool key's
hooksfield is the hub, not the module. This stores the router, the launch token, and that hook's parameters. There is no setter later. - createMarket on the hub, from that same controller, with one to eight module addresses in run order. No duplicates.
- initialize the pool from that same controller.
beforeInitializereverts if the sender is not the controller, or if the market was never registered. - Add liquidity through the position manager, or call
seedon the floor hook if that module is in the stack. The floor hook is the only address allowed to change liquidity until graduation.
Do steps 3 through 5 in one transaction. Registration is first-come for a pool id. Anyone who sees your key can register it if you leave a gap.
A single hook, no hub
Put the module address in key.hooks. Do not call attachHub. Call createLaunch, then initialize, from the same wallet. The module's own callbacks run, because it is the pool's hook. _take calls poolManager.take directly. _relayFee calls updateDynamicLPFee directly.
What runs on a swap
- The PoolManager calls the pool's hook
beforeSwap. Exact output reverts here. The amount specified must be negative. - On the hub, each module whose flags include beforeSwap is called. A non-zero
BeforeSwapDeltareverts. Fee overrides are compared and the highest clean fee is returned with the override flag. - The pool executes the swap.
- The PoolManager calls
afterSwap. The hub sets a transient pull lock, calls each afterSwap module, and returns the sum of pulls as its unspecified delta. Modules must not callpoolManager.takethemselves while the hub is the caller.LaunchHook._takeroutes that throughhub.pull.
Parameters do not move
Nothing in these contracts has an owner, a proxy, or a function that changes a live pool's numbers. attachHub can be called once, by the deployer, before the pool exists. After createLaunch, the cap, the fee, the sink, and the router are fixed. If you need different numbers, that is a new pool.
The tests cover the rules these contracts claim. They are not a formal audit, and nothing here is a mainnet deployment. Read Limits and the parameters you actually pass before you point a launch at them.
How a swap names the wallet, the lock, and the referrer, and why the stock router cannot.