> ## Documentation Index
> Fetch the complete documentation index at: https://docs.basestonk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Trading bots

> One router function, one PoolKey shape, two things every bot must handle.

BaseStonk pools live in the canonical Uniswap v4 PoolManager on Base, with
a custom fee hook per launcher. Wallets cannot call the PoolManager
directly (v4 swaps happen inside an unlock callback), so trade through
BaseStonk's router.

## The router

```solidity theme={null}
// SwapRouter - see the contract reference for the address
function swap(
    PoolKey key,      // (currency0, currency1, fee, tickSpacing, hooks)
    bool zeroForOne,  // false = buy the token, true = sell it
    uint256 amountIn,
    uint256 minOut,
    address to
) returns (uint256 amountOut)
```

Exact-in only. Approve the input currency to the router first.

## Constructing the PoolKey

For any BaseStonk token:

| Field         | Value                                               |
| ------------- | --------------------------------------------------- |
| `currency0`   | the launched token (always sorts below its pair)    |
| `currency1`   | the pair token - from the token's API record        |
| `fee`         | `3000`                                              |
| `tickSpacing` | `60`                                                |
| `hooks`       | the token's own hook - the `curve` field in the API |

<Warning>
  Different launchers install different hooks, and a pool's identity
  includes its hook. An indexer that assumes one hook for every pool
  computes pool ids that the other launcher's swaps never match - those
  tokens will chart flat while trading normally.
</Warning>

## Two things every bot must handle

1. **The tax is taken inside the swap** by the hook. Quote `minOut` with
   at least the token's tax rate of headroom or the swap reverts. The
   token's rate is in its API record.
2. **Max wallet reverts oversized buys.** A buy that would push the
   recipient past a token's holding cap reverts - surface it as *reduce
   size*, not a generic failure. Oversized sells near the launch price can
   also revert with `CurrencyNotSettled`; see
   [the sell floor](/sell-mechanics).
