VeilSolver
SDK DOCUMENTATION

@veilsolver/sdk

TypeScript SDK for MEV-resistant DeFi on 0G. Two functions. Zero mempool exposure.

v0.1.0
InstallationQuick StartbuildIntentuploadStrategyArchitecture

Installation

bash
npm install @veilsolver/sdk ethers

Quick Start

Use VeilSolverClient for the full pipeline in a single call. It handles encryption, TEE inference, plan signing, and on-chain settlement.

typescript
import { VeilSolverClient } from "@veilsolver/sdk"
import { ethers } from "ethers"

const solver = new VeilSolverClient({
  apiUrl:          "https://solver.veilsolver.xyz",
  contractAddress: "0x02553ef7529118EB33E199b7329732d4F2884cEb",
  solverPublicKey: "0x039a5b81f4b2bc0c181b1292f3aeb55721de43dc7e3d07c6c44ba3aa08e7caae04"
})

// Full pipeline: encrypt → TEE → sign → settle
const { solveResponse, receipt } = await solver.solve({
  tokenIn:        "0x0683F96B376cd819C12Bdb0c723b7D508ceF42Cf",  // USDC
  tokenOut:       "0x2550713236C759e185068ba531E2f63dc0de41D2",  // WETH
  amountIn:       "100",      // human-readable — 100 USDC
  decimalsIn:     6,
  maxSlippageBps: 50,         // 0.5%
  signer                      // ethers.Signer from MetaMask
})

console.log("tx:", receipt?.hash)
console.log("min received:", solveResponse.plan.minAmountOut)

Individual Functions

For step-by-step control, use the individual functions directly. All functions are pure TypeScript — no React dependency.

buildIntentTradingIntent
buildIntent({ tokenIn, tokenOut, amountIn, decimalsIn, maxSlippageBps, userAddress, chainId, strategyId? })

Constructs a TradingIntent from human-readable parameters. Converts amountIn to wei string using decimalsIn. Generates a cryptographically random 32-byte nonce for replay protection. chainId prevents cross-chain replay attacks.

typescript
import { buildIntent } from "@veilsolver/sdk"

const intent = buildIntent({
  tokenIn:        "0xUSDC...",
  tokenOut:       "0xWETH...",
  amountIn:       "100",   // 100 USDC — human-readable
  decimalsIn:     6,
  maxSlippageBps: 50,      // 0.5%
  userAddress:    "0xYourWallet...",
  chainId:        16602,   // 0G testnet
  strategyId:     "0abc…"  // optional: 0G Storage root hash
})
encryptIntentPromise<string>
encryptIntent(intent: TradingIntent, solverPublicKey: string)

Encrypts the intent using ECIES with the solver's enclave public key. Returns a hex-encoded ciphertext. The solver API receives this alongside the plaintext intent (used for routing) but cannot read the plaintext without the enclave private key.

typescript
import { encryptIntent } from "@veilsolver/sdk"

const SOLVER_PUBKEY = "0x039a5b81f4b2bc0c181b1292f3aeb55721de43dc7e3d07c6c44ba3aa08e7caae04"
const encryptedIntent = await encryptIntent(intent, SOLVER_PUBKEY)
// encryptedIntent: "0x04a3b9..." — ECIES ciphertext
callSolverAPIPromise<SolveResponse>
callSolverAPI(intent: TradingIntent, encryptedIntent: string, apiUrl: string)

POSTs to /solve with the intent and encrypted blob. The solver API forwards to 0G Compute (GLM-5-FP8 in Intel TDX), verifies the TEE attestation, signs the plan, stores the audit record to 0G Storage, and returns the full SolveResponse.

typescript
import { callSolverAPI } from "@veilsolver/sdk"

const response = await callSolverAPI(
  intent,
  encryptedIntent,
  "https://solver.veilsolver.xyz"
)

// response.plan         — execution plan (tokenIn, tokenOut, minAmountOut, route, deadline)
// response.signature    — ECDSA hex, verified by VeilSolver.sol
// response.attestation  — { chatID, isVerified, provider, model, timestamp }
// response.auditRootHash — 0G Storage root hash (empty string if storage failed)
submitSettlementPromise<TransactionReceipt | null>
submitSettlement({ solveResult, contractAddress, signer })

Approves ERC20 spend, then calls executePlan() on VeilSolver.sol. The contract verifies the ECDSA signature, checks the deadline and replay mapping, deducts the fee, and routes the swap through the DEX. Returns the ethers TransactionReceipt on success.

typescript
import { submitSettlement } from "@veilsolver/sdk"

const receipt = await submitSettlement({
  solveResult:     response,
  contractAddress: "0x02553ef7529118EB33E199b7329732d4F2884cEb",
  signer           // ethers.Signer — must have tokenIn balance + approval
})

console.log("tx hash:", receipt?.hash)
console.log("block:",   receipt?.blockNumber)

Strategy Registry

Upload private system prompts to 0G Storage. Each prompt is ECIES-encrypted before upload — only the TEE can decrypt it. The returned strategyId is the 0G Storage merkle root hash — safe to share publicly.

typescript
import { VeilSolverClient } from "@veilsolver/sdk"

const solver = new VeilSolverClient({ apiUrl, contractAddress, solverPublicKey })

// 1. Upload your private strategy prompt
const strategyId = await solver.uploadStrategy({
  prompt: "You are a conservative DeFi executor. Never route through more than 2 pools...",
  signer
})
// strategyId = 0G Storage root hash — share with your users

// 2. Use it in a trade — TEE fetches + decrypts it internally
const { receipt } = await solver.solve({
  tokenIn, tokenOut, amountIn, decimalsIn,
  maxSlippageBps: 50,
  strategyId,    // ← activates your custom strategy
  signer
})
Privacy guarantee

The encrypted blob is stored on 0G Storage. The strategyId is a content-addressed root hash — publicly retrievable, but the blob is ECIES encrypted. The operator cannot read strategy contents. Only the TEE enclave can decrypt using its private key — which never leaves the Intel TDX hardware boundary.

Architecture

VeilSolver is a three-layer system. The client layer handles encryption and settlement. The solver layer orchestrates TEE inference and storage. The chain layer enforces all guarantees via smart contract.

plaintext
User → buildIntent() → encryptIntent() → POST /solve
         ↓ (ECIES encrypted, unreadable to solver)
Solver API → 0G Compute (GLM-5-FP8 in Intel TDX enclave)
         ↓ (execution plan computed inside enclave)
Solver API → signPlan() → storeAuditRecord() → 0G Storage
         ↓
SolveResponse { plan, signature, attestation, auditRootHash }
         ↓
submitSettlement() → VeilSolver.sol → DEX swap → receipt
Client
buildIntent() — TradingIntent from form values
encryptIntent() — ECIES, local computation
submitSettlement() — ERC20 approve + executePlan()
Solver API
inference.ts — 0G Compute, broker singleton
signer.ts — ECDSA plan hash (matches Solidity)
storage.ts — 0G Storage audit trail
VeilSolver.sol
ecrecover(planHash, sig) == solverKey
executedIntents[hash] — replay protection
minAmountOut enforced — MEV shield
SECURITY MODEL
GuaranteeEnforcement
Intent contents privateECIES encryption — only enclave key decrypts
Strategy logic privateTeeML — host cannot read enclave memory
Execution plan authenticECDSA — contract verifies via ecrecover
Audit record immutable0G Storage merkle root — content-addressed
No replayOn-chain mapping — EVM state is final
MEV boundedminAmountOut enforced by VeilSolver.sol
VeilSolver · 0G APAC Hackathon 2026Privacy is an architecture property, not a policy promise.
GET STARTED

Ready to build?

Private intent solver. Two-line SDK. No mempool exposure.

Launch DemoRead the Docs
VeilSolver · 0G APAC Hackathon 2026