AlsoSwap
Create Pool
How It WorksUpgradeable AMMLocal-first, Sepolia-ready

AlsoSwap Protocol

Learn the mechanics behind pools, LP shares, swaps, and TWAP. Everything on this page maps to real on-chain rules enforced by the core contracts.

Pool-first markets
No pool, no trade. Pools define executable price on-chain.
Real protections
Slippage + deadline are enforced inside the pool logic.
RouterV2 paths
Auto-select direct or 2-hop routing for better execution.

AlsoSwap Protocol Map

A practical walkthrough of how AlsoSwap moves value: pools, liquidity shares, swaps, fees, TWAP, and timelocked governance.

Big Picture

AlsoSwap is a constant-product AMM. The core idea is simple: markets exist only as pools. No pool means no executable price and no swap for that pair.

Users interact with Router or RouterV2. Routers resolve pools through PoolFactory. Pools store reserves, mint LP shares, execute swaps, and track cumulative prices for TWAP.

USERROUTER / ROUTERV2POOLFACTORYLIQUIDITYPOOLRESERVES + SHARESprotocol fee shareFeeCollector (Treasury)TWAP snapshotsPriceOracle (TWAP)
Key takeaways
  • Pools are the market. If a pool does not exist for a pair, the pair is not tradable.
  • Routers are UX. They route you into pools, handle ETH paths, and apply slippage/deadline controls.
  • Factory is global config. Fees, pause state, and optional limiters live there and pools read it at execution time.

System Flow (One Swap)

This is the exact mental model you want when debugging a revert. Reads can fail because of RPC/network mismatch, but writes fail only when a contract rule is violated.

1) User submits swap through Router / RouterV2
2) Router resolves pool via PoolFactory.getPool(token0, token1)
3) Router transfers tokenIn into LiquidityPool
4) LiquidityPool computes amountOut using current reserves + fee config
5) LiquidityPool transfers tokenOut to recipient
6) Pool syncs reserves and updates cumulative prices
7) Protocol fee portion (if enabled) is sent to FeeCollector

Core Modules

The protocol is intentionally modular. State lives in pools and factory. Routers are stateless UX helpers.

PoolFactory
Creates pools, stores swapFeeBps, protocolFeeBps, fee receiver, and global pause state.
LiquidityPool
Holds reserves, mints/burns LP shares, executes swaps, and tracks TWAP cumulatives (plus sync/skim utilities).
Router
Add/remove liquidity and swap helpers with deadline + slippage controls, including ETH paths for WETH pools.
RouterV2
Finds best direct or 2-hop route (path length 2 or 3), improving execution when a direct pool is thin.
FeeCollector
Treasury receiver of the protocol fee share (if protocolFeeBps > 0).
PriceOracle
Pull-based TWAP updates and consult() quotes based on pool cumulative prices.
DEXGovernance
Timelocked executor for critical PoolFactory actions (queue → wait → execute).

Hard Guarantees (On-Chain)

These constraints are enforced by contracts and cannot be bypassed by UI.

  • ProtocolPaused: PoolFactory is paused, so swaps and liquidity actions revert.
  • DeadlineExpired: your transaction arrived too late.
  • SlippageExceeded: execution would be worse than your min amounts.
  • InsufficientLiquidity: reserves are empty or too small to quote.
  • InvalidFeeConfig: swap/protocol fee config is inconsistent.

Upgradeable vs Immutable

Factory, routers, oracle, limiter, and governance are deployed behind transparent proxies. LiquidityPool instances are immutable per-pair contracts (new pair → new pool instance).

Practically: upgrades change global behavior and UX helpers, but do not retroactively “edit” individual pools. Pool state remains transparent and auditable.