Documentation Index
Fetch the complete documentation index at: https://mintlify.com/rhinestonewtf/warp-router/llms.txt
Use this file to discover all available pages before exploring further.
Architecture Overview
Warp Router implements a modular, delegatecall-based architecture that separates routing logic from protocol-specific settlement implementations. This design enables seamless integration of new protocols while maintaining consistent security guarantees and gas optimizations across all settlement types.System Architecture
The architecture consists of three primary layers:
Router Layer
Handles operation routing, batching of settlement layers, and enforcement of atomicity
Adapter Layer
Protocol-specific settlement logic executed via delegatecall
Arbiter Layer
Validates and unlocks user resources for settlement
Layer 1: Router
The Router system serves as the central coordination hub for all settlement operations. It combines execution logic (RouterLogic) with adapter lifecycle management (RouterManager) to provide a complete routing solution.Core Components
RouterLogic - Execution Engine
RouterLogic - Execution Engine
The RouterLogic contract orchestrates all settlement operations:Key Responsibilities:
src/router/core/RouterLogic.sol
- Atomic intent processing across multiple operations
- Gas optimization through adapter caching
- Signature validation for all fill operations
- Reentrancy protection via transient storage
RouterManager - Lifecycle Management
RouterManager - Lifecycle Management
The RouterManager handles adapter registration, versioning, and lifecycle:Features:
- Semantic Versioning: Enforces version compatibility for safe upgrades
- Hotfix Support: Allows patch-only upgrades for critical fixes
- Role-Based Access: Separate roles for adding (ADD_ROLE) and removing (RM_ROLE) adapters
- Emergency Pause: Can pause all fill operations by setting signer to address(0)
DirectRoutes - Special Operations
DirectRoutes - Special Operations
Built-in operations that bypass adapter lookup for common tasks:
singleCall: Direct contract interactionmultiCall: Batched contract interactions- Fee collection operations
Operation Types
- Fill Operations
- Claim Operations
Fill operations are settlement operations that fulfill user orders by transferring assets and executing target operations.Standard Fill Route:Optimized Batch Fill:
src/router/core/RouterLogic.sol
Fill operations require atomic signatures from the designated atomic signer.
Gas Optimization Features
The Router implements advanced optimization techniques:Adapter Caching
Consecutive operations with the same selector reuse cached adapter addresses:Savings: Approximately 2,100 gas per cache hit (avoids cold SLOAD)
Special Selector Bypass
Built-in operations skip adapter lookup entirely:Savings: 2,600+ gas (avoids SLOAD + DELEGATECALL overhead)
Optimized Encoding
The optimized route accepts pre-encoded calldata arrays:Savings: 200-500 gas per element in the array
Security Model
Atomic Signatures
All fill operations require cryptographic signatures from the atomic signer, preventing unauthorized execution.
Reentrancy Protection
ReentrancyGuardTransient protects all external functions using efficient transient storage (EIP-1153).
Role-Based Access
Separate roles for adapter management prevent unauthorized protocol modifications.
Batch Integrity
All operations in a batch must succeed or the entire batch reverts, ensuring atomicity.
Layer 2: Adapters
Adapters are protocol-specific contracts that handle the actual settlement logic for different protocols and chains. They are always executed via delegatecall from the Router, inheriting its storage context and permissions.Adapter Architecture
src/base/adapter/AdapterBase.sol
Implementation Requirements
Return Function Selector
All external functions must return their own function selector:This enables the Router to validate successful execution.
Solver Context Handling
Adapters extract solver-specific data using the_loadRelayerContext() helper:
src/base/adapter/AdapterBase.sol
src/arbiters/samechain/SameChainAdapter.sol
Example Adapter: IntentExecutorAdapter
The IntentExecutorAdapter demonstrates a simple forwarding pattern:src/adapters/IntentExecutorAdapter.sol
Layer 3: Arbiters
Arbiters are responsible for validating settlements and unlocking funds from user accounts or resource locks. They provide dual protocol support for both TheCompact and Permit2 standards.Arbiter Architecture
src/base/arbiter/ArbiterBase.sol
Key Responsibilities
Execute Pre-Claim Operations
Execute Pre-Claim Operations
Arbiters execute optional operations before settlement:
src/base/arbiter/ArbiterBase.sol
Compute Mandate Hashes
Compute Mandate Hashes
Arbiters compute mandate hashes for TheCompact and Permit2 validation:The mandate hash uniquely identifies the order and its operations for protocol-level validation.
Router-Only Access Control
Router-Only Access Control
Arbiters enforce strict access control:This prevents unauthorized entities from executing settlement operations or accessing user funds.
Orchestrate Settlement Flow
Orchestrate Settlement Flow
Arbiters coordinate the complete settlement flow for both protocols:
- Validate user signatures
- Execute pre-claim operations with proper gas stipends
- Unlock funds from TheCompact or Permit2
- Transfer assets to designated recipients
- Execute target operations on behalf of users
Settlement Flows
Let’s examine the complete settlement flows for different operation types.Fill Flow
Settlement Layer Interaction
Adapter interacts with the settlement layer (TheCompact, Permit2, etc.)
Claim Flow
Security Architecture
Delegatecall Context
Adapters execute in Router’s context, inheriting its storage and permissions. This requires strict security controls on adapter code.
Signature Validation
Multiple signature validation layers:
- Atomic signatures for fill operations
- User signatures for intent execution
- Protocol signatures for resource unlocking
Access Control
Layered access control:
- Router validates atomic signatures
- Adapters enforce onlyViaRouter
- Arbiters enforce onlyRouter
Atomicity Guarantees
All operations in a batch succeed or revert together, preventing partial execution vulnerabilities.
Security Considerations
For Adapter Developers
For Adapter Developers
- Delegatecall Context: Adapters execute in Router’s storage context - never write to storage slots
- External Calls: Only interact with trusted, well-audited protocols
- Return Values: Always return function selector for validation
- Interface Support: Implement ERC165 for all settlement functions
- No Untrusted Calls: Never make calls to user-provided addresses
For Arbiter Developers
For Arbiter Developers
- Router-Only Access: Enforce onlyRouter modifier on all settlement functions
- Signature Validation: Validate all user signatures before unlocking funds
- Gas Stipends: Properly account for EIP-150’s 63/64 gas forwarding rule
- Mandate Hashes: Compute hashes correctly to prevent signature replay
- Pre-Claim Safety: Execute pre-claim operations with proper error handling
For Solvers/Relayers
For Solvers/Relayers
- Atomic Signatures: Fill operations require valid signatures from atomic signer
- Context Validation: Ensure solver context matches adapter expectations
- Batch Integrity: Design batches carefully to avoid partial execution
- Gas Estimation: Account for pre-claim operation gas stipends
- Protocol Authorization: Ensure proper protocol-level authorizations for claims
Performance Characteristics
Gas Cost Breakdown
| Operation Type | Base Cost | With Caching | Special Selector |
|---|---|---|---|
| Single Fill | ~150k gas | N/A | N/A |
| Batch Fill (5 ops, same adapter) | ~600k gas | ~540k gas (10% savings) | N/A |
| Batch Fill (5 ops, mixed adapters) | ~650k gas | ~590k gas (9% savings) | N/A |
| Special Call | ~50k gas | N/A | ~47k gas (6% savings) |
Actual gas costs vary based on the specific protocol adapter and settlement layer used.
Optimization Impact
Adapter Caching Benefits:
- First operation: Full SLOAD cost (~2,100 gas)
- Cached operations: Memory read (~3 gas)
- Break-even point: 2 operations with same adapter
- Maximum benefit: Long batches with few adapters
Special Selector Benefits:
- Avoids SLOAD: ~2,100 gas saved
- Avoids DELEGATECALL: ~700 gas saved
- Avoids context append: ~200 gas saved
- Total savings: ~2,600+ gas per operation
Next Steps
Integration Guide
Learn how to integrate Warp Router into your solver or relayer
Build an Adapter
Step-by-step guide to building custom protocol adapters
API Reference
Complete API documentation for all contracts
Security Best Practices
Learn security best practices for each layer