# Integration Workflows

#### Discovering or Creating Pools

1. Call `factory.getPair(tokenA, tokenB)`.
2. If it returns `address(0)`, call `factory.createPair(tokenA, tokenB)` (tokens will be sorted).
3. Alternatively, derive the address off-chain via `pair = address(uint(keccak256(abi.encodePacked(hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), INIT_CODE_PAIR_HASH))))` and watch for `PairCreated`.

#### Adding Liquidity (token-token)

1. Use `router.getAmountsOut` or `WarpLibrary.quote` to decide `amountAMin`/`amountBMin`.
2. `IERC20(tokenA/B).approve(router, amountADesired/amountBDesired)`.
3. Call `router.addLiquidity(...)` and receive LP tokens in `to`.
4. Capture the returned `(amountA, amountB, liquidity)` for accounting.\
   \&#xNAN;*For bonding-curve launchpads graduating to Warp, `addLiquidityETH` is typically the final step that pairs the emitted token with native ETH/WMEGAETH.*

#### Removing Liquidity

* Use `removeLiquidity` or `removeLiquidityETH` to withdraw, optionally signing a permit beforehand so the router can transfer LP tokens without a separate transaction.
* Integrations that tax transfers must route through the `SupportingFeeOnTransferTokens` variants to avoid shortfalls.

#### Swapping

1. Construct a `path` array (up to any length) of token addresses.
2. Determine `amountIn`/`amountOut` via the helper methods.
3. Approve the router for the first token (unless swapping from native ETH).
4. Call the appropriate swap function and monitor for `Swap` events emitted by each touched pair.
5. Set `deadline` on every user call to avoid stuck transactions.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.warpx.exchange/for-developers/warpx-v2/integration-workflows.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
