The solver directory contains the implementation of the Intent Solver, a TypeScript application designed to listen to blockchain events and process intents accordingly. This application plays a crucial role in handling events from different sources and executing the necessary actions based on those events.
solver/
├── index.ts
├── logger.ts
├── NonceKeeperWallet.ts
├── patch-bigint-buffer-warn.js
├── test/
├── config/
│ ├── index.ts
│ ├── allowBlockLists.ts
│ ├── chainMetadata.ts # Picks a profile from config/chains/
│ ├── chains/
│ ├── types.ts
│ └── tradingPairs/
│ ├── handler.ts
│ ├── pairs.ts # Pair type + reversible expansion
│ ├── pairs.json # Working config (gitignored)
│ ├── pairs.testnet.json # Template per environment (committed)
│ └── pairs.mainnet.json
└── solvers/
├── index.ts
├── BaseFiller.ts
├── BaseListener.ts
├── types.ts
├── utils.ts
├── contracts/
└── <eco|hyperlane7683|router>/
├── index.ts
├── listener.ts
├── prepare.ts # Optional: pre-fill strategy (e.g., auction logic)
├── auction.ts # Auction manager (commit-reveal logic)
├── filler.ts
├── types.ts
├── utils.ts
├── contracts/
├── rules/
│ └── index.ts
└── config/
├── index.ts
├── metadata.ts
└── allowBlockLists.ts
- solver/index.ts: The main entry point of the solver application. It initializes and starts the listeners and fillers for different solvers.
- logger.ts: Contains the Logger class used for logging messages with various formats and levels.
- NonceKeeperWallet.ts: A class that extends ethers Wallet and prevents nonces race conditions when the solver needs to fill different intents (from different solutions) in the same network.
- patch-bigint-buffer-warn.js: A script to suppress specific warnings related to BigInt and Buffer, ensuring cleaner console output.
- config/: Global configuration for the solver.
- tradingPairs/: Trading pairs configuration.
- handler.ts: Loads pairs from JSON, resolves oracle/URL exchange rates.
- pairs.ts: Trading pair type, expands
reversiblepairs into both directions. - pairs.json: Working pairs config (gitignored, created via
yarn pairs:init). - pairs.testnet.json / pairs.mainnet.json: Templates, one per deployment.
- tradingPairs/: Trading pairs configuration.
- scripts/solver-escrow/: CLI for solver collateral —
balance.ts,deposit.ts,withdraw.ts, pluscommon.ts(provider/wallet, escrow lookup viarouter.SOLVER_ESCROW(), token decimals & symbol). - solvers/: Contains implementations of different solvers and common utilities.
- BaseListener.ts: An abstract base class that provides common functionality for event listeners. It handles setting up contract connections and defines the interface for parsing event arguments.
- BaseFiller.ts: An abstract base class that provides common functionality for fillers. It handles the solver's lifecycle
prepareIntent,fill, andsettle.prepareIntent: evaluate allow/block lists, balances, and run the defined rules to decide whether to fill or not an intent.fill: The actual filling.settle: The settlement step, can be avoided.
- <eco|hyperlane7683|router>/: Implements the solvers for different protocols.
- listener.ts: Extends
BaseListenerto handle domain-specific events. - prepare.ts: (Optional) Implements pre-fill strategy. For Router, handles commit-reveal auction and order claiming.
- auction.ts: Auction manager — commit/reveal phases, winner detection, auction restart handling.
- filler.ts: Extends
BaseFillerto handle domain-specific intents. - rules/: Custom validation rules for deciding whether to fill an intent.
- contracts/: Contains contract ABI and type definitions for interacting with domain-specific contracts.
- listener.ts: Extends
- index.ts: Exports the solvers to be used in the main application.
Create a .env file before running (see Configuration).
Prerequisites: Node.js 20+, Yarn
yarn install
yarn buildPrerequisites: Docker, Docker Compose
# Build and start
docker compose up -d --build
# Live PM2 logs (JSON)
docker compose exec solver pm2 logs
# Live PM2 logs (formatted)
tail -f ./logs/solver-out.log | npx pino-pretty
# PM2 process status
docker compose exec solver pm2 list
# Enter container
docker compose exec solver sh
# Graceful restart PM2 processes
docker compose exec solver pm2 reload all
# Stop
docker compose downCreate a .env file in the solver directory with the following required and optional variables:
# Required: Private key for solver wallet (used to sign transactions)
PRIVATE_KEY=0x...
# Required: Router contract address (same for all chains)
ROUTER_CONTRACT=0x3448f63B27161cEE72781319e6b579132d905d08
# Optional: Log level (debug, info, warn, error)
LOG_LEVEL=info
# Select testnet (Outbe/BSC Testnet/Sepolia) or mainnet (Outbe/Ethereum)
NETWORK=testnetImportant:
PRIVATE_KEYis required - the solver wallet must have sufficient funds on all chains where it will operateROUTER_CONTRACTaddress is used for all chains in the selected profileLOG_LEVELdefaults toinfoif not specified
NETWORK (testnet by default) picks one of two profiles, each a plain literal you can read end to end:
config/chains/testnet.ts— Outbe Testnet, BSC Testnet, Sepoliaconfig/chains/mainnet.ts— Outbe Mainnet, Ethereum
config/chainMetadata.ts chooses between them. Testnet RPCs can be overridden at runtime with
BSC_RPC_URLS, OUTBE_RPC_URLS, and SEPOLIA_RPC_URLS; each value may contain one URL or a
comma-separated fallback list. Without an override, the profile's public RPC URLs are used.
Trading pairs live in config/tradingPairs/pairs.json (gitignored), created by yarn pairs:init from
the template of the active network — pairs.testnet.json or pairs.mainnet.json. Manage them via
CLI commands:
yarn pairs:init # Create pairs.json from the environment's template
yarn pairs:list # Show configured pairs
yarn pairs:add # Add a pair interactively
yarn pairs:remove # Remove a pair interactively
yarn pairs:oracle # List available oracle pairs and current ratesExample pairs.json:
[
{
"originChain": "outbetestnet",
"destinationChain": "sepolia",
"inputToken": "0x0000000000000000000000000000000000000000",
"outputToken": "0xe6AE7EBD5b5c34ed3E696e6Ced7f2A1660F20454",
"rate": "0x0000000000000000000000000000000000000000/0x00000000000000000000000000000000000CC840",
"quoteTolerance": 0.01,
"reversible": true
},
{
"originChain": "outbetestnet",
"destinationChain": "sepolia",
"inputToken": "0xe6AE7EBD5b5c34ed3E696e6Ced7f2A1660F20454",
"outputToken": "0xe6AE7EBD5b5c34ed3E696e6Ced7f2A1660F20454",
"rate": 1,
"quoteTolerance": 0,
"reversible": true
}
]Parameters:
rate: One of three formats:- Fixed: number, e.g.
1 - Oracle:
"<baseAddr>/<quoteAddr>", or"1/<baseAddr>/<quoteAddr>"for the inverse - URL: e.g.
"https://my-api.com/rate"— must return JSON{"exchangeRate": "0.023271"}
- Fixed: number, e.g.
quoteTolerance: Extra % added to output to increase winning chances (e.g.,0.01= 1% more)inputToken/outputToken: Token addresses. Use0x0000000000000000000000000000000000000000for native tokens (COEN, BNB).reversible: Optional.truealso trades the pair the other way round — chains and tokens swapped, rate inverted (4→0.25,"A/B"→"1/A/B"). One entry, two traded directions, nothing to keep in sync. Omitted orfalse= one-way only.
yarn pairs:list marks reversible pairs with ↔ and prints how many directions are actually traded.
Oracle rates are fetched on-chain at each order. Use yarn pairs:oracle to see available oracle pairs.
Configure which intents to fill or ignore using allow/block lists at config/allowBlockLists.ts:
const allowBlockLists: AllowBlockLists = {
allowList: [],
blockList: [],
};The solver has to post collateral before it can fill anything — the escrow address is read from
router.SOLVER_ESCROW() on the chain you pass, so the router must be deployed there.
yarn escrow:balance [chain] [token|native[,token2,...]] # total / locked / available
yarn escrow:deposit [chain] [token|native] [amount] # approve + deposit
yarn escrow:withdraw [chain] [token|native] [amount|all]Chain names come from chainMetadata.ts, amounts are human-readable (0.1, 100), everything acts on the
PRIVATE_KEY address. Deposit sets the escrow as an ERC6909 operator on The Compact on first run and
approves the ERC20 when needed; withdraw takes all.
Arguments are optional: run any command bare and it asks for chain, token and amount interactively
(like pairs:add), offering the tokens from pairs.json for that chain.
yarn escrow:deposit bsctestnet 0xe6AE7EBD5b5c34ed3E696e6Ced7f2A1660F20454 100The router in
solvers/router/config/metadata.tscurrently uses one address (ROUTER_CONTRACT) for every chain, and it is deployed on bsctestnet only — escrow commands on outbetestnet and sepolia fail onSOLVER_ESCROW()until the router is deployed there or given a per-chain address.
Start the solver application:
yarn solverThis will run the compiled JavaScript code from the dist directory, initializing and starting all enabled solvers as defined in config/solvers.json. Each solver's status (enabled/disabled) can be configured in this JSON file.
Run in watch mode for development:
yarn devThe Router solver targets the shared Router settler contract, which abstracts the underlying cross-chain transport (Hyperlane / LayerZero) behind a single bridge(). It implements a commit-reveal Vickrey auction where multiple solvers compete by first committing a hash of their quote, then revealing the actual amount. The highest bidder wins but pays the second-highest price.
The solver uses a four-module architecture:
- Listener (
listener.ts): DetectsOpenevents from Router contracts - Prepare (
prepare.ts): Orchestrates auction flow and claims winning orders on the router - Auction (
auction.ts): Manages commit-reveal phases, winner detection, and auction restart handling - Filler (
filler.ts): Executes fills when solver wins the auction
When an order is detected, the solver:
- Calculates competitive output amount using trading pair config (exchange rate + quote tolerance)
- Runs pre-commit checks (escrow collateral, token balance)
- Generates a random salt and commits a hash:
keccak256(abi.encode(orderId, outputAmount, salt)) - Waits for the commit deadline (a block number of the auction chain — phases count blocks, not seconds)
After commit phase ends:
- Solver reveals the actual
outputAmount,salt, andoriginData(encoded order data fromfillInstructions) - Contract verifies the reveal matches the committed hash
- Waits for auction to end (reveal deadline, also a block number)
After auction ends:
- Contract determines winner (Vickrey: highest bidder, second-highest price)
- Solver checks if it won via
auction.winner() - If winner, claims the order on the router contract via
router.claimOrder() - If claim triggers
AuctionRestarted(winner disqualified for insufficient collateral), solver does not retry
If the solver loses the auction, it waits up to 30 seconds for an AuctionRestarted event (emitted when the winner is disqualified). If restarted, the solver enters a new auction round automatically.
- Commit-reveal scheme: Prevents front-running — quotes are hidden until reveal phase
- Vickrey pricing: Winner pays second-highest price, incentivizing truthful bidding
- Escrow collateral check: Verifies solver has sufficient collateral before committing
- Oracle exchange rates: Supports on-chain oracle rates (e.g.,
COEN/USDC) alongside fixed rates - Auction restart handling: Automatically re-enters auction if winner is disqualified
- Precise phase timing: Uses on-chain deadlines for phase transitions to avoid missed reveals
User creates order: 100 COEN → wants minimum 1 USDC
TradingPair: exchangeRate = "COEN/USDC" (oracle), quoteTolerance = 0.01
Oracle returns: COEN/USDC = 0.023
1. Calculate output:
- Base: 100 * 0.023 = 2.3 USDC
- Boost: 2.3 * (1 + 0.01) = 2.323 USDC
- Check: 2.323 >= 1 ✅
2. Commit phase:
- Generate salt
- Commit hash of (orderId, 2.323 USDC, salt)
- Wait for commit deadline
3. Reveal phase:
- Reveal 2.323 USDC + salt
- Wait for auction end
4. Winner check:
- If won → claim order on router → fill
- If lost → wait 30s for possible restart
The application uses a custom Logger class. Default: stdout with INFO level.
Customize using pino transports. See pino transports docs. There's an example for logging to a Syslog server running on localhost commented in logger.ts.