Skip to main content
Solver context (also called relayer context) is a critical component that allows solvers to pass settlement-specific data to adapters. This guide explains how context works and how to use it with different adapters.

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:
This efficient assembly code:
  1. Reads the context length from the last 32 bytes of calldata
  2. Calculates the offset where context begins
  3. Returns a calldata slice without copying data

Adapter-Specific Context Formats

SameChainAdapter

The SameChainAdapter expects the simplest context format - just a recipient address. Format:
Implementation from SameChainAdapter.sol:115-120:
Usage Example:
In Settlement Flow (from SameChainAdapter.sol:233-244):

MultiCallAdapter

The MultiCallAdapter also uses a simple address-only context. Format:
Implementation from MultiCallAdapter.sol:42-47:
Usage Example:
Helper Function:

IntentExecutorAdapter

The IntentExecutorAdapter doesn’t consume any solver context. From IntentExecutorAdapter.sol:227-229:
Adapters that skip relayer context have special tags that tell the Router not to consume a context entry for them. This is important for batch operations. Usage Example:

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: From RouterLogic.sol:288-292:
If you provide the wrong number of contexts, you’ll get a LengthMismatch error.

Building Custom Context Formats

When building custom adapters, design your context format carefully:
1

Define your data structure

Determine what configuration your adapter needs:
2

Implement extraction function

Create a helper to extract and validate context:
3

Use in adapter functions

Extract context in your fill/claim operations:
4

Provide encoding helper

Make it easy for solvers to construct context:

Best Practices

Efficiency

  • Keep it compact: Use abi.encodePacked instead of abi.encode to 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