LayerZero: Best Omnichain Implementation
Partner Prize | Extended OFT with Novel Cross-Chain Use Cases
β οΈ Mandatory Requirements (Must Have All)
β¨ HedgePod: We override _debit() and _credit() with custom APR-checking logic. This is TRUE extension.
β Strong Bonus Points (Competitive Advantages)
π Implementation Based on Official LayerZero Documentation
Our implementation follows these official LayerZero V2 patterns:
β What We Built: Extended LayerZero V2 OFT
We didn't just inherit LayerZero contractsβwe EXTENDED them with custom yield-aware logic per OFT best practices.
APR-Aware Routing (Custom _debit)
Overrides OFT _debit() to block transfers to lower-yield chains. Only moves funds if APR improvement exceeds threshold. Novel use of OFT extension pattern.
Batch Transfers (Official Pattern)
Implements LayerZero Batch Send pattern: gas-optimized batchSend() for multi-chain transfers in single tx. See docs.layerzero.network/v2/developers/evm/oapp/overview#batch-send
Circuit Breakers (Safety)
Per-chain emergency circuit breakers and global emergency mode. Foundation for rate limiting and advanced safety patterns.
Yield Statistics (Analytics)
Tracks totalCrossChainTransfers and totalGasSaved. On-chain analytics for demonstrating real-world value.
8 Chain Deployment (Production)
Deployed across World Chain, Base, Celo, Zircuit, Polygon, Arbitrum, Optimism, Avalanche. Real mainnet & testnet addresses.
Automated Peer Config (Tooling)
Custom setPeers.ts script automatically configures trusted peers across all chains using LayerZero V2 Endpoint IDs (lzEid).
π₯ CRITICAL: How We EXTEND Base Contract Logic (Mandatory Requirement)
LayerZero explicitly requires: "Must extend the Base Contract Logic (not sufficient to just inherit OApp/OFT/Endpoint interface contracts)"
We do this by overriding core OFT functions with custom business logic:
1. Override _debit() - Add APR-Checking Logic
We don't just call super._debit(). We add yield-aware routing that blocks transfers to lower-yield chains:
// contracts/AutoYieldToken.sol (Lines 112-140)
function _debit(
uint256 _amountLD,
uint256 _minAmountLD,
uint32 _dstEid
) internal virtual override returns (uint256 amountSentLD, uint256 amountReceivedLD) {
// β‘ CUSTOM LOGIC: Check if target chain has better APR
uint256 currentAPR = chainAPRs[block.chainid];
uint256 targetAPR = chainAPRs[_dstEid];
// π₯ EXTENSION: Only allow transfer if APR improves
if (targetAPR <= currentAPR + aprThreshold) {
revert InsufficientAPRImprovement(currentAPR, targetAPR, aprThreshold);
}
// Then call parent implementation
return super._debit(_amountLD, _minAmountLD, _dstEid);
}β This is TRUE extension: we add new functionality (APR checking) before calling parent.
2. Override _credit() - Add Event Emission & Analytics
We extend _credit() to track cross-chain transfers and emit custom events:
// contracts/AutoYieldToken.sol (Lines 142-160)
function _credit(
address _to,
uint256 _amountLD,
uint32 _srcEid
) internal virtual override returns (uint256 amountReceivedLD) {
// Call parent implementation
amountReceivedLD = super._credit(_to, _amountLD, _srcEid);
// β‘ CUSTOM LOGIC: Track analytics
totalCrossChainTransfers++;
// π₯ EXTENSION: Emit custom event
emit CrossChainTransferReceived(
_to,
_srcEid,
_amountLD,
block.timestamp
);
return amountReceivedLD;
}β This is TRUE extension: we add analytics tracking and custom events.
3. Novel Cross-Chain Use Case: Autonomous Yield Optimization
Our extensions create a NEW use case that didn't exist before:
- APR-Aware Routing: Tokens only move if yield improves (gas-efficient)
- Autonomous Agents: Coinbase CDP agents use our OFT for 24/7 rebalancing
- Circuit Breakers: Per-chain pause control for safety
- Batch Transfers: Multi-destination sends in one transaction
- On-Chain Analytics: Track totalCrossChainTransfers and totalGasSaved
β This isn't a simple token bridgeβit's an intelligent yield optimization protocol.
β‘ Advanced LayerZero Patterns We Use
1. OFT Standard Extension (Not Just Inheritance)
Per OFT Quickstart, we override core OFT functions:
_debit() β APR-checking logic before transfer
_credit() β Event emission on receive
Extends OFT, not just inherits2. Batch Send Pattern (Official Pattern)
Implements Batch Send for gas-optimized multi-chain ops:
function batchSend(uint32[] calldata dstEids, ...)
β Single tx, multiple destinations
β Cumulative fee validation3. Circuit Breakers & Emergency Mode
Foundation for Rate Limiting pattern:
mapping(uint32 => bool) circuitBreakers
bool emergencyMode
β Per-chain pause control4. LayerZero V2 Endpoint Integration
Uses Endpoint V2 immutable protocol contracts:
OFT(_lzEndpoint, _delegate) constructor
β Immutable transport layer
β Configurable security (DVNs/Executors)π Code Evidence
Extended LayerZero V2 OFT with custom logic:
function _debit(uint256 _amountLD, uint256 _minAmountLD, uint32 _dstEid)
// Custom APR checking logic
if (targetAPR <= currentAPR + aprThreshold) revert InsufficientAPRImprovement();function _credit(...) override
// Emit custom event for yield tracking
emit CrossChainReceived(from, amountLD);function batchSend(SendParam[] calldata _params)
// Gas-optimized multi-chain transfers
emit BatchTransferCompleted(totalTransfers, totalGasSaved);Cross-chain vault orchestration with LayerZero integration
AutoYieldToken integration + cross-chain deposit/withdrawal logicAutomated script to configure LayerZero V2 peers across all deployed chains
Iterates through networks, calls setPeer() for each remote chainLayerZero V2 Endpoint IDs (lzEid) configured for all 8 chains
Base: 30184, World Chain: 30163, Polygon: 30109, Arbitrum: 30110, etc.Autonomous agent that triggers LayerZero cross-chain transfers when APR delta exceeds threshold
Monitors yields, calculates APR delta, calls AutoYieldToken.send()π Custom Features (Not Standard OFT)
Standard OFT allows any transfer. Our extension checks if destination chain APR justifies the move. Reverts with InsufficientAPRImprovement if delta too small.
New batchSend() function processes multiple cross-chain transfers in a single transaction, tracking gas savings across all batches.
Per-chain circuit breakers + global emergency mode. Can pause specific chains or entire system if anomaly detected. Custom errors: CircuitBreakerActive, EmergencyModeActive
New events: APRCheckPassed, APRCheckFailed,BatchTransferCompleted, CrossChainReceived
π΄ Live Demo
π Omnichain Deployment Scale
8 chains | 150+ potential via LayerZero network