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/isSupportedgetMarketMetadata— pool, LP token, creator, creation source, verified flaggetMarketBond/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.
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 & liquidatability —
getPositionHealth,getPositionView/getPositionRiskView(worth, health ratio,poolDirectLiquidatable). - LP rewards & balances —
pendingLPRewards,getUserPoolAccountView,getUserLiquidityLotViews. - Previews —
previewOpenPosition,previewAddLiquidity/previewRemoveLiquidity,previewClosePayout,previewReducePositionLeverage,previewTradingFee/getEffectiveFeeRate. - Pool state —
getPoolComposition,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.
