> For the complete documentation index, see [llms.txt](https://docs.warpx.exchange/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.warpx.exchange/for-developers/warpx-v2/core.md).

# Core

#### WarpFactory

Source: `packages/core/contracts/WarpFactory.sol`

Responsibilities:

* Deploys every `WarpPair` (using `CREATE2`) and records them in the `getPair` mapping.
* Exposes `INIT_CODE_PAIR_HASH = 0x0904716a2e7c34f649f3837f2424539ef9f2c8cc5ba0d9d55ed439d013b94ce0` deterministic pair address derivation.

Key functions:

<table><thead><tr><th width="374.99609375">Signature</th><th>Usage</th></tr></thead><tbody><tr><td><code>function allPairsLength() external view returns (uint)</code></td><td>Count pairs for pagination.</td></tr><tr><td><code>function getPair(address tokenA, address tokenB) external view returns (address)</code></td><td>Query existing pair (tokens sorted internally).</td></tr><tr><td><code>function createPair(address tokenA, address tokenB) external returns (address pair)</code></td><td>Deploys a new pair. Reverts on identical/zero addresses or if the pair already exists.</td></tr></tbody></table>

Event: `PairCreated(token0, token1, pair, pairIndex)` fires whenever a new pool is deployed. Listen to this to surface freshly created pools without polling.

#### WarpPair

Source: `packages/core/contracts/WarpPair.sol`

Warp LP tokens implement `IWarpPair` + ERC-20 + EIP-2612 permit. Highlights:

* Immutable token ordering: `token0`, `token1` stored on initialization.
* `getReserves()` returns reserves and the timestamp of the last sync for TWAP calculations.
* `MINIMUM_LIQUIDITY = 1_000` LP tokens are permanently locked to prevent divide-by-zero on the initial liquidity event.
* Fees: 0.30% swap fee (997/1000 factor) with optional protocol fee (mints 1/6 of √k growth to `feeTo` if set).
* Flash swaps: `swap()` accepts arbitrary `data`; if `data.length > 0`, it callbacks `IWarpCallee.warpCall(sender, amount0Out, amount1Out, data)`. Return the owed tokens before the function completes.
* Housekeeping helpers: `skim(address)` sends any excess tokens (beyond reserves) to `to`, `sync()` forcibly updates reserves to match balances.

Key entrypoints and why integrators use them:

| Signature                                                                          | Purpose                                                                                                                  |
| ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `function mint(address to) external returns (uint liquidity)`                      | Called by the router after tokens have been transferred in. Returns LP tokens minted to `to`.                            |
| `function burn(address to) external returns (uint amount0, uint amount1)`          | Burns LP tokens held by the pair and sends out the underlying assets.                                                    |
| `function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data)` | Core swap primitive. Either `amount0Out` or `amount1Out` must be > 0. Caller must have already sent the input tokens in. |
| `function permit(...) external`                                                    | Enables gasless approvals so `removeLiquidityWithPermit` can operate without a prior `approve`.                          |
| `function getReserves()` + `price0CumulativeLast/price1CumulativeLast`             | Fetch raw reserves and cumulative price data for off-chain quoting/TWAPs.                                                |

Events worth indexing: `Mint`, `Burn`, `Swap`, `Sync`, and standard ERC-20 `Transfer`/`Approval`.
