Documentation

System Architecture

How Yield Forge is built — the Diamond pattern, facets, and adapters.

Yield Forge is built on the EIP-2535 Diamond Pattern — a single proxy contract that delegates calls to multiple logic modules called "facets."

Why Diamond?

A regular smart contract hits the 24KB size limit fast. The Diamond pattern solves this by splitting logic across multiple contracts while keeping a single entry point and shared storage.

BenefitDetail
One addressUsers interact with a single Diamond contract
Unlimited sizeLogic is split across as many facets as needed
Modular upgradesFix or upgrade one facet without redeploying everything
Shared storageAll facets read/write the same state

The 10 Facets

FacetWhat It Does
DiamondCutFacetAdds, replaces, or removes facets (upgrade mechanism)
DiamondLoupeFacetIntrospection — query which facets exist and what functions they expose
OwnershipFacetOwnership management (ERC-173)
PoolRegistryFacetRegister pools, manage adapters and quote token whitelists
LiquidityFacetAdd/remove liquidity, mint PT + YT, create new cycles
RedemptionFacetRedeem PT after maturity
YieldAccumulatorFacetHarvest yield from protocols, distribute to YT holders
YieldForgeMarketFacetPT trading AMM — swaps, LP add/remove
PauseFacetEmergency pause/unpause
YTOrderbookFacetYT peer-to-peer order placement, filling, cancellation

Adapters

Adapters are the bridge between Yield Forge and external DeFi protocols. Each adapter implements the same interface but translates calls into protocol-specific logic.

AdapterProtocolHow It Works
UniswapV4AdapterUniswap V4Uses unlock() callback, full-range positions, no NFTs
UniswapV3AdapterUniswap V3Manages NFT positions (ERC-721), collects fees via collect()

Data Flow

User → Diamond Proxy → Facet Logic → Storage Update
                                   → Adapter Call (deposit/withdraw/collect)
                                   → PT/YT Mint/Burn
                                   → Emit Events → Indexer → UI

Yield Distribution

The YieldAccumulatorFacet uses a yield-per-share model to ensure fair distribution among YT holders. When yield is harvested from the underlying protocol, a 5% fee goes to the protocol and the rest is distributed proportionally to all YT holders based on their share of the total supply. This ensures latecomers don't claim yield that accrued before they entered.

Security Layers

  • Cross-facet reentrancy protection shared across all facets
  • 48-hour timelock on all administrative upgrades
  • Pause guardian can instantly halt operations in emergencies
  • Adapter whitelist — only approved protocols can be used

For more details, see the Security section.