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.
| Benefit | Detail |
|---|---|
| One address | Users interact with a single Diamond contract |
| Unlimited size | Logic is split across as many facets as needed |
| Modular upgrades | Fix or upgrade one facet without redeploying everything |
| Shared storage | All facets read/write the same state |
The 10 Facets
| Facet | What It Does |
|---|---|
| DiamondCutFacet | Adds, replaces, or removes facets (upgrade mechanism) |
| DiamondLoupeFacet | Introspection — query which facets exist and what functions they expose |
| OwnershipFacet | Ownership management (ERC-173) |
| PoolRegistryFacet | Register pools, manage adapters and quote token whitelists |
| LiquidityFacet | Add/remove liquidity, mint PT + YT, create new cycles |
| RedemptionFacet | Redeem PT after maturity |
| YieldAccumulatorFacet | Harvest yield from protocols, distribute to YT holders |
| YieldForgeMarketFacet | PT trading AMM — swaps, LP add/remove |
| PauseFacet | Emergency pause/unpause |
| YTOrderbookFacet | YT 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.
| Adapter | Protocol | How It Works |
|---|---|---|
| UniswapV4Adapter | Uniswap V4 | Uses unlock() callback, full-range positions, no NFTs |
| UniswapV3Adapter | Uniswap V3 | Manages 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.