Skip to content

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.

ClassPurposeV2V3BalancerStableswap
JoinInitialize pool with both tokens
SwapSwap exact token_in for token_out
AddLiquidityDouble-sided deposit
RemoveLiquidityDouble-sided withdrawal
SwapDepositSingle-sided deposit (zap-in)
WithdrawSwapSingle-sided withdrawal (zap-out)
LPQuoteRead-only quoting (price, LP↔token)🔜🔜

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 lp state: reserves, LP-token supply, fee accumulators, etc.
  • Returns operation-specific values. Some return scalars (a swap output amount), some return structured outputs, some return None and rely on pool-state inspection.