Talos Launch App

04 · Developers

Hook data and the router

How a swap names the wallet, the lock, and the referrer, and why the stock router cannot.

Per-wallet rules trust one router. That router writes the real msg.sender into the swap. Anyone else is treated as one trader: themselves.

The bytes

TraderRouter packs hookData as abi.encodePacked(bytes32 trader, extra).

If the caller is not the trusted router, word 0 is ignored and the trader is msg.sender. The payload word, if any, is then the first 32 bytes instead of the second. A launchpad that swaps from its own contract, and names that contract as the trusted router, must pack the bytes the same way. If it does not, every user of that contract shares one cap.

swapExactInput

router.swapExactInput(
    key,
    zeroForOne,
    amountIn,
    amountOutMin,
    extra,      // empty, abi.encode(lockBlocks), abi.encode(referrer),
                // or abi.encode(lockBlocks, referrer) when both hooks are on the pool
    deadline
);

zeroForOne is true when the trader spends currency0. If the launch token is currency1, a buy is zeroForOne = true. If the launch token is currency0, a buy is zeroForOne = false. The router pulls the input from the caller and sends the output to the caller. The caller must approve the router for the input token. Native ETH is rejected.

Buyback is a different door

BuybackHook.buyback does not go through TraderRouter. The caller approves the buyback hook, not the router. The swap's sender is the buyback hook, so wallet rules attribute the buy to the hook's address. A cohort cap on that address can block a later buyback. A closed wave can block it too. The sink receives the launch tokens. The caller receives nothing except the event.

Do not use the stock v4 router as the trusted router

The Universal Router and the v4 swap router forward whatever hookData the user signed. A user can put someone else's address in word 0 and spend that wallet's cap, or skip a sell delay. Set trustedRouter to TraderRouter, or to your own contract that pins msg.sender the same way and does not accept hook data from the caller.

Slippage

amountOutMin is checked on the specified output after the hook deltas settle. A hook that takes part of the output, such as split stream or conviction lock, reduces what the trader receives. Set the minimum against that net amount, not against a quote that ignored the fee.