TACO ships two factory/lens pairs: one for AMM pools (PvpAMMFactory + PvpAMMLens) and one for cross-margin accounts (MarginAccountFactory + MarginAccountLens). Factories give you a canonical way to create and discover contracts; lenses give you a canonical, stateless way to inspect them.

PvpAMMFactory

PvpAMMFactory deploys upgradeable pools and registers them by (marketId, collateral). The registry is deterministic: pools are created with CREATE2 (salt = keccak256(marketId, collateral)) through a dedicated PvpAMMPoolDeployer, so apps can compute a pool address ahead of time with predictPoolAddress. Each deployment also wires up an LP token and fee-pool manager. Lookups (all keyed by market and collateral):
  • getPool / getLPToken / isSupported
  • getMarketMetadata — pool, LP token, creator, creation source, verified flag
  • getMarketBond / isMarketBondSlashed

Two ways to create a market

  • Governance (createPool, owner-only): full control over implementation, oracle, risk params, and pool admin.
  • Permissionless (createPoolWithBond): anyone can create a market after locking the configured bond token (TACO). Bonded pools reuse the governance-configured implementation, risk params, and pool admin — the creator receives no roles.
Bonded markets are created unverified. Governance can promote one with setMarketVerified (read via isMarketVerified), so frontends can surface a “verified” badge and filter unvetted markets. A creator reclaims their bond with withdrawMarketBond after the lock elapses; governance can slashMarketBond on an abusive unverified market.

PvpAMMLens

PvpAMMLens is a stateless read surface reused across all compatible pools. Prefer it for consistent reads instead of calling pools directly:
  • Health & liquidatabilitygetPositionHealth, getPositionView / getPositionRiskView (worth, health ratio, poolDirectLiquidatable).
  • LP rewards & balancespendingLPRewards, getUserPoolAccountView, getUserLiquidityLotViews.
  • PreviewspreviewOpenPosition, previewAddLiquidity / previewRemoveLiquidity, previewClosePayout, previewReducePositionLeverage, previewTradingFee / getEffectiveFeeRate.
  • Pool stategetPoolComposition, getFundingRateView, getPsi, getPrice.

MarginAccountFactory and MarginAccountLens

For cross-margin, MarginAccountFactory deploys a deterministic clone per (owner, collateral). createAccount returns the existing account on repeat calls; predictAccount / getAccount / isAccountFor resolve addresses without deploying. The factory also owns per-collateral cross-margin risk config (setCollateralConfig) and the trusted-router lifecycle. MarginAccountLens.getAccountPreflight is the read-only companion for keepers and frontends: it returns account-level health plus per-position readability and health, and identifies any Pyth oracles that need a price refresh before a margin-sensitive call.

Why factories and lenses

  • Factories give a canonical, deterministic way to create and discover pools and margin accounts.
  • Lenses give a canonical, stateless way to inspect them.
  • Together they cut per-app duplication and keep integrations aligned with the protocol.