Core API
Core Primitives are the cross-protocol execution dispatchers. They mutate pool state — initializing pools, swapping, adding and removing liquidity, and quoting — across Uniswap V2, V3, Balancer, and Stableswap through a single abstract interface.
For the conceptual overview and the dispatcher-design rationale, see Core Primitives under Concepts. This page is the API reference: every public class with its signature, parameters, and a runnable example.
Class index
Section titled “Class index”| Class | Purpose | V2 | V3 | Balancer | Stableswap |
|---|---|---|---|---|---|
Join | Initialize pool with both tokens | ✅ | ✅ | ✅ | ✅ |
Swap | Swap exact token_in for token_out | ✅ | ✅ | ✅ | ✅ |
AddLiquidity | Double-sided deposit | ✅ | ✅ | ✅ | ✅ |
RemoveLiquidity | Double-sided withdrawal | ✅ | ✅ | ✅ | ✅ |
SwapDeposit | Single-sided deposit (zap-in) | ✅ | ✅ | ❌ | ❌ |
WithdrawSwap | Single-sided withdrawal (zap-out) | ✅ | ✅ | ❌ | ❌ |
LPQuote | Read-only quoting (price, LP↔token) | ✅ | ✅ | 🔜 | 🔜 |
Common contract
Section titled “Common contract”Every Core primitive follows the DeFiPy contract:
result = ClassName().apply(lp, ...args)- Stateless construction.
ClassName()takes no parameters. .apply()does the work. All operation arguments — pool, user, amounts, tokens — are passed to.apply(), not to the constructor.- Mutates the pool. Unlike Agentic primitives (read-only), Core primitives change
lpstate: reserves, LP-token supply, fee accumulators, etc. - Returns operation-specific values. Some return scalars (a swap output amount), some return structured outputs, some return
Noneand rely on pool-state inspection.
See also
Section titled “See also”- Core Primitives — narrative / conceptual overview
- Abstract Uniswap — the legacy abstract-interface page
- Tutorials → Uniswap V2 — end-to-end runnable walkthrough of every Core primitive
- Protocol API — protocol-specific factories and exchange classes that Core primitives dispatch to