Talos Launch App

04 · Developers

Write a module

The smallest contract that can join a stack, and the mistakes that unbalance the pool.

Extend LaunchHook. You get registration, the trader, exact-input checks, and the hub-aware take and fee relay. Implement IMarketModule only if you cannot extend the base. The function signatures have to match either way.

Checklist

  1. Decide which callbacks you need. Return that set from getHookPermissions by adding a function on HookFlags. Do not turn on a callback you do not implement. The hub will call it.
  2. Deploy at an address whose low bits equal HookFlags.toUint(permissions). BaseHook's constructor checks this and reverts otherwise. The pool's hook is still the hub. The module's own flags exist because the module is also a valid standalone hook.
  3. In createLaunch, call _register and _setLaunchToken. Store your parameters in a struct packed so the hot path reads one slot when it can. Do not add a setter.
  4. In beforeSwap, call _onlyExactInput and _load. Return a zero BeforeSwapDelta. The hub reverts anything else. If you set a fee, return fee | OVERRIDE_FEE_FLAG. A fee of zero with the flag is a real override. The hub keeps it.
  5. In afterSwap, if you need tokens from the pool, call _take and return that amount as a positive unspecified delta when you are the pool's hook. Under the hub, _take calls pull and the hub ignores your returned delta and uses the sum of pulls instead. Still return the amount. Standalone mode needs it.
  6. Do not call poolManager.take or updateDynamicLPFee yourself. Those calls must come from the address stored on the pool. The base contract already branches on whether the hub called you.
  7. Call attachHub before createLaunch if this module will sit under a hub. _attachedTo allows key.hooks == hub only after the hub is set.

Accounting

A positive after-swap delta means the hook took that much of the unspecified currency from the pool. Unspecified currency on an exact-input swap is the output. If you take 1 token and return a delta of 0, the PoolManager's books do not balance and the swap reverts. If you return 1 and take 0, the same thing happens. Take and return the same number.

Tokens you keep, such as a fee pot or a lock, should be transferred to address(this) inside _take. Under the hub, pull sends them to the module, not to the hub. Claims then transfer from the module to the user. Check _attachedTo(key) in the claim, not address(key.hooks) == address(this), or the tokens are stuck whenever the pool points at the hub.

Tests

test/utils/LaunchFixture.sol etches a hook at a flagged address, funds two mock ERC-20s, and swaps through TraderRouter. Copy a case from test/ThirdWaveHooks.t.sol for a standalone hook, and from test/TalosHook.t.sol for a module under the hub. Run forge test --offline. via_ir is on, so a cold compile takes about a minute.

Permissions and the warning

Some callbacks override a non-view base function and the compiler says the state mutability can be restricted to view. Leave that. The override has to match BaseHook. The unreachable return in LaunchHook.moduleBeforeSwap's sibling path is the same kind of leftover. It is not a logic branch you should "clean up" by changing the signature.