Skip to content

Solver

The Solver is a test market maker that provides quotes for the RFQ (Request for Quote) system. It generates signed quotes for users and submits RFQ theses to Kaizen Core.

Running

# Dry run (quotes only, no transactions)
pnpm run --filter mock-solver start -- --dry-run
 
# Custom port and multiplier
pnpm run --filter mock-solver start -- --port 3000 --multiplier 1.5
 
# Full options
pnpm run --filter mock-solver start -- \
  --rpc-url http://localhost:8545 \
  --ws-url ws://localhost:8546 \
  --port 3000 \
  --multiplier 1.5

CLI Options

OptionDescriptionDefault
-d, --dry-runRun without submitting transactionsfalse
-r, --rpc-url <url>Kaizen Core RPC URLhttp://localhost:8545
-w, --ws-url <url>Kaizen Core WebSocket URLws://localhost:8546
-k, --private-key <key>Solver private key (0x-prefixed, 64 hex chars)From env
-p, --port <port>API server port3000
-m, --multiplier <ratio>Base payout multiplier (1.0 - 10.0)1.5
--max-risk <amount>Max risk per thesis (USDC, 6 decimals)10000000000

Environment Variables

VariableDescription
KAIZEN_RPC_URLKaizen Core RPC URL
KAIZEN_WS_URLKaizen Core WebSocket URL
SOLVER_PRIVATE_KEYSolver wallet private key (0x-prefixed)

Supported Pairs

The mock solver supports the following trading pairs:

Base TokenQuote TokenBase Address
BTCUSDT0x0000000000000000000000000000000000000001
ETHUSDT0x0000000000000000000000000000000000000002
SOLUSDT0x0000000000000000000000000000000000000003

Quote token address (USDT): 0x0000000000000000000000000000000000000100

API Reference

The solver exposes an HTTP API for quoting and thesis execution.

GET /health

Health check endpoint.

Response
{
  "status": "ok",
  "solver": "0x...",
  "dryRun": false
}

GET /info

Get solver information and configuration.

Response
{
  "address": "0x...",
  "balance": "1000000000",
  "dryRun": false,
  "config": {
    "basePayoutMultiplier": 1.5,
    "maxPayoutRatio": 10,
    "minBetAmount": "1",
    "maxBetAmount": "1000000000000",
    "minDuration": 1000,
    "maxDuration": 86400000
  }
}
FieldDescription
addressSolver's address
balanceSolver's balance in USDC (6 decimals)
dryRunWhether solver is in dry-run mode
config.basePayoutMultiplierBase multiplier for payout calculation
config.maxPayoutRatioMaximum allowed payout ratio
config.minBetAmountMinimum bet amount (USDC, 6 decimals)
config.maxBetAmountMaximum bet amount (USDC, 6 decimals)
config.minDurationMinimum thesis duration (ms)
config.maxDurationMaximum thesis duration (ms)

GET /pairs

List supported trading pairs.

Response
{
  "pairs": [
    {
      "base": "0x0000000000000000000000000000000000000001",
      "quote": "0x0000000000000000000000000000000000000100"
    },
    {
      "base": "0x0000000000000000000000000000000000000002",
      "quote": "0x0000000000000000000000000000000000000100"
    }
  ]
}

POST /quote

Request a signed quote for a trade.

Request Body
{
  "user": "0x...",
  "thesisType": "box",
  "base": "0x0000000000000000000000000000000000000001",
  "quote": "0x0000000000000000000000000000000000000100",
  "lowerPrice": "95000000000",
  "upperPrice": "105000000000",
  "betAmount": "1000000000",
  "startTime": 1700000000000,
  "endTime": 1700003600000,
  "deadline": 1700000060000
}
FieldTypeDescription
userAddressUser's address
thesisTypestringThesis type (only "box" supported)
baseAddressBase token address
quoteAddressQuote token address
lowerPricestringLower price bound (bigint as string)
upperPricestringUpper price bound (bigint as string)
betAmountstringBet amount in USDC (bigint as string)
startTimenumberThesis start time (Unix timestamp in ms)
endTimenumberThesis end time (Unix timestamp in ms)
deadlinenumberQuote deadline (Unix timestamp in ms)
Response (Success)
{
  "success": true,
  "quote": {
    "user": "0x...",
    "thesisType": "box",
    "oraclePair": { "base": "0x...", "quote": "0x..." },
    "priceRange": { "lower": "95000000000", "upper": "105000000000" },
    "betAmount": "1000000000",
    "payout": "1050000000",
    "startTime": 1700000000000,
    "endTime": 1700003600000,
    "deadline": 1700000060000,
    "signature": "0x..."
  }
}
Response (Error)
{
  "success": false,
  "error": "UNSUPPORTED_PAIR: Pair 0x.../0x... is not supported"
}
Error Codes
CodeDescription
UNSUPPORTED_PAIRTrading pair is not supported
BET_TOO_SMALLBet amount below minimum
BET_TOO_LARGEBet amount above maximum
DURATION_TOO_SHORTThesis duration below minimum
DURATION_TOO_LONGThesis duration above maximum
INVALID_PRICE_RANGELower price >= upper price

POST /execute

Execute an RFQ thesis. The user submits the quote and their signature, and the solver submits the transaction to Kaizen Core.

Note: This endpoint is not available in dry-run mode.

Request Body
{
  "quote": {
    "user": "0x...",
    "thesisType": "box",
    "oraclePair": { "base": "0x...", "quote": "0x..." },
    "priceRange": { "lower": "95000000000", "upper": "105000000000" },
    "betAmount": "1000000000",
    "payout": "1050000000",
    "startTime": 1700000000000,
    "endTime": 1700003600000,
    "deadline": 1700000060000,
    "signature": "0x..."
  },
  "userSignature": "0x..."
}
FieldTypeDescription
quoteobjectThe solver quote (returned from /quote)
userSignatureHexUser's signature over the quote hash (65 bytes)
Response (Success)
{
  "success": true,
  "result": {
    "txHash": "0x...",
    "status": "committed",
    "thesisId": 42
  }
}
FieldTypeDescription
result.txHashHexTransaction hash
result.statusstringTransaction status ("committed" or "failed")
result.thesisIdnumberThesis ID assigned by Core (optional)
Response (Error)
{
  "success": false,
  "error": "Quote deadline has passed"
}

Flow:

  1. User gets a quote via POST /quote
  2. User signs the quote hash (using SDK's signQuote method)
  3. User sends quote + signature to POST /execute
  4. Solver performs risk checks and hedging (simulated delay in mock)
  5. Solver signs and submits RfqSubmit transaction to Core
  6. Core validates signatures and creates the thesis

POST /estimate

Estimate payout without generating a signature. Useful for UI previews.

Request Body
{
  "thesisType": "box",
  "base": "0x0000000000000000000000000000000000000001",
  "quote": "0x0000000000000000000000000000000000000100",
  "lowerPrice": "95000000000",
  "upperPrice": "105000000000",
  "betAmount": "1000000000",
  "startTime": 1700000000000,
  "endTime": 1700003600000
}
FieldTypeRequiredDescription
thesisTypestringNoThesis type (default: "box")
baseAddressNoBase token address (default: BTC)
quoteAddressNoQuote token address (default: USDT)
lowerPricestringYesLower price bound (bigint as string)
upperPricestringYesUpper price bound (bigint as string)
betAmountstringYesBet amount (bigint as string)
startTimenumberYesThesis start time (Unix timestamp in ms)
endTimenumberYesThesis end time (Unix timestamp in ms)
deadlinenumberNoQuote deadline (default: now + 60s)
Response
{
  "success": true,
  "estimate": {
    "betAmount": "1000000000",
    "payout": "1070000000",
    "multiplier": "1.0700",
    "solverCollateral": "70000000"
  }
}
FieldDescription
estimate.betAmountUser's bet amount
estimate.payoutTotal payout if user wins
estimate.multiplierPayout multiplier (formatted to 4 decimals)
estimate.solverCollateralSolver's collateral (payout - betAmount)

Thesis Execution Flow

Solver Execution Flow

Key Points:

  • The solver submits the transaction to Core (not the user)
  • Core validates that tx.sender == solver (recovered from quote signature)
  • Core validates the user signature over the quote hash
  • The solver can perform risk checks and hedging before submitting
  • Settlements are handled automatically by Core (no challenge monitoring needed)

Payout Calculation

The mock solver calculates payouts with a random multiplier between 1.05x and 1.10x of the bet amount:

payout = betAmount * (1.05 + random * 0.05)

This is intentionally simplified for testing. Production solvers would implement sophisticated pricing based on:

  • Oracle price volatility
  • Thesis duration
  • Price range width
  • Market conditions