Skip to main contentTechnical architecture of TED Protocol smart contracts and systems.
Overview
TED Protocol is built on a modular, upgradeable architecture using the Diamond Pattern (EIP-2535). User transactions flow through a single DiamondProxy entry point, which routes calls to specialized facets: Swap Facets (FXSwapFacet, CurveAdapter, UniswapV3), Bridge Facets (CCTPFacet, LayerZeroFacet, WormholeFacet), and Admin Facets (AdminFacet, DiamondCut, DiamondLoupe).
Diamond Pattern (EIP-2535)
Why Diamond? The pattern offers modularity (each feature is a separate facet), upgradeability (update single facets without redeploying entire contracts), no size limits (bypasses the 24KB contract limit), a single address (one entry point for all functions), and gas efficiency (delegatecall-based routing).
Structure. The DiamondProxy contract maps function selectors to facet addresses. When a function is called, the proxy looks up which facet handles that selector and delegates the call. This allows the protocol to add, replace, or remove functionality without changing the main contract address.
Storage pattern. All facets share diamond storage using a unique storage position (keccak256 hash), preventing storage collisions that can occur with traditional proxy patterns. The storage struct contains facet mappings, owner address, and protocol state like pause status.
Core Facets
FXSwapFacet handles stablecoin FX swaps with multi-DEX routing. The main functions are swap() which executes token exchanges, and getQuote() which returns expected output, price impact, route details, and gas estimates.
DEX Adapters provide specialized integrations for each exchange: CurveAdapter for Curve Finance (optimized for stablecoin pools and meta pools), UniswapAdapter for Uniswap V3 (concentrated liquidity), and PancakeAdapter for PancakeSwap V3 pools on BSC.
Bridge Facets enable cross-chain functionality: CCTPFacet for Circle CCTP (USDC only), LayerZeroFacet for LayerZero V2 (USDT and TEDP via OFT), and WormholeFacet for Wormhole (general token transfers).
Data Flow
Same-chain swap. User calls swap() with their token pair and amount. DiamondProxy routes to FXSwapFacet. The facet queries all DEX adapters in parallel, selects the best route, executes the swap via the optimal DEX, and sends output tokens to the user.
Cross-chain swap. User calls crossChainSwap(). On the source chain: swap to bridge-compatible token if needed, then initiate cross-chain transfer via the appropriate bridge facet. The bridge protocol delivers the message. On the destination chain: receive tokens, swap to target token if needed, and deliver final tokens to the user.
Security Architecture
Access control flows through a multi-sig (3/5 requirement) to a timelock (48 hours) before reaching the DiamondProxy. This ensures no single party can make changes, and users have time to react to proposed modifications.
Emergency controls use tiered multi-sig requirements: Pause requires 2-of-5 signatures (stop all operations), Unpause requires 3-of-5 (resume operations), Upgrade requires 3-of-5 plus timelock (deploy new facets), and Emergency requires 4-of-5 (bypass timelock for critical fixes).
TEDP Token Architecture
OFT Standard. TEDP implements LayerZero OFT (Omnichain Fungible Token) combined with ERC-20 and ERC-20Permit. The contract mints the fixed supply of 1 billion tokens at deployment and enables seamless cross-chain transfers.
Cross-chain flow. On the source chain, TEDP tokens are burned. LayerZero’s Decentralized Verifier Networks (DVNs) verify the burn transaction. Once verified, the destination chain mints equivalent TEDP to the recipient. Total supply remains constant across all chains.
External Integrations
DEX contracts. Curve uses pool-specific routers with a registry for discovery. Uniswap V3 uses SwapRouter02 with UniswapV3Factory. PancakeSwap uses SmartRouter with V3Factory.
Bridge contracts. Circle CCTP uses TokenMessenger and MessageTransmitter. LayerZero uses Endpoint, DVN, and Executor contracts. Wormhole uses Core Bridge and Token Bridge contracts.
Gas Optimization
TED Protocol employs several optimization techniques: batch operations (30-50% savings), storage packing (20-40% savings), assembly optimization (10-20% savings), and minimal proxy patterns (50%+ deployment savings).
Typical gas costs. Simple swaps use approximately 150k gas on both Ethereum and L2s. Multi-hop swaps use around 300k gas. Cross-chain initiation uses approximately 200k gas on the source chain.