What is Solver Context?
Solver context is arbitrary bytes data that solvers append to adapter calls to configure settlement behavior. Each adapter defines its own context format based on its specific requirements. Key Characteristics:- Solver-specific configuration data passed to adapters
- Format varies by adapter implementation
- Extracted efficiently using assembly in
AdapterBase.sol:137-144 - Does not increase gas costs significantly due to calldata efficiency
How Context Works
When the Router calls an adapter, it appends the solver context using a specific encoding pattern:Calldata Structure
Extracting Context
Adapters extract context using the_loadRelayerContext() helper:
- Reads the context length from the last 32 bytes of calldata
- Calculates the offset where context begins
- Returns a calldata slice without copying data
Adapter-Specific Context Formats
SameChainAdapter
The SameChainAdapter expects the simplest context format - just a recipient address. Format:SameChainAdapter.sol:115-120:
SameChainAdapter.sol:233-244):
MultiCallAdapter
The MultiCallAdapter also uses a simple address-only context. Format:MultiCallAdapter.sol:42-47:
IntentExecutorAdapter
The IntentExecutorAdapter doesn’t consume any solver context. FromIntentExecutorAdapter.sol:227-229:
Context in Batch Operations
When executing batch operations, context consumption follows specific rules:Regular Adapters
Each regular adapter call consumes one solver context from the array in order.Mixed Adapters
Special selectors and adapters that skip context don’t consume entries:Context Validation
The Router validates context consumption at the end of batch execution: FromRouterLogic.sol:288-292:
LengthMismatch error.
Building Custom Context Formats
When building custom adapters, design your context format carefully:Best Practices
Efficiency
- Keep it compact: Use
abi.encodePackedinstead ofabi.encodeto minimize calldata size - Fixed-size when possible: Fixed-size types (address, uint256) are easier to extract than dynamic types
- Validate length: Always check context length to prevent out-of-bounds access
Safety
- Validate addresses: Check that extracted addresses are not zero when required
- Bounds checking: Ensure context is long enough before extracting data
- Clear errors: Use descriptive error messages for context validation failures
Documentation
- Document format: Clearly document the expected context format for your adapter
- Provide helpers: Include encoding helper functions for solvers
- Show examples: Include usage examples in comments and documentation
Debugging Context Issues
Common Problems
InvalidRelayerContext Error
- Context length doesn’t match expected size
- Check that you’re encoding the right data types
LengthMismatch Error in Batches
- Number of contexts doesn’t match number of regular adapter calls
- Remember that special selectors and skip-context adapters don’t consume entries
Testing Context Extraction
Next Steps
Building Adapters
Learn how to build custom adapters with context
Solver Guide
Complete guide for solver integration