diff --git a/benchmarks/token-trade-coverage.yml b/benchmarks/token-trade-coverage.yml new file mode 100644 index 00000000..24dd9d96 --- /dev/null +++ b/benchmarks/token-trade-coverage.yml @@ -0,0 +1,149 @@ +# OpenChainBench. Bench № 090 + +slug: token-trade-coverage +number: "090" +title: Most complete onchain trade data API, live coverage across Solana, EVM and Stellar +seo_title: "Best token trade data API 2026 (Mobula vs Bitquery vs Codex vs Moralis)" +seo_description: "Which onchain data API returns the most complete trade history for a newly launched token? Live coverage % across Mobula, Bitquery, Codex and Moralis on Solana, Ethereum, BSC, Base and Stellar." +subtitle: For each reference token per chain, we fetch every trade in a fixed measurement window from each provider and compare against the union baseline. Higher percent means the provider returned more of the true trade set, with fewer missed DEXs and fewer dropped fills. +category: Aggregators +status: draft +metric: Trade capture rate +unit: pct +higher_is_better: true + +seo_intro: | + This benchmark measures how much of a token's real trade history each + onchain data API actually returns. For a fixed set of reference tokens + per chain (Solana, Ethereum, BSC, Base, Stellar), the harness fetches + every trade in the same measurement window from Mobula, Bitquery, + Codex and Moralis, then computes each provider's capture rate against + the union baseline (max count across the four). A rate of 100 means + the provider returned as many trades as the best-covering provider on + that token. A rate of 20 means the provider missed 80 percent of the + swaps that did happen. The comparison is chain-scoped because + coverage is not uniform: a provider strong on Solana DEX indexing can + be weak on niche BSC pools, and no provider covers every chain + equally (Stellar coverage in particular is uneven since only two of + the four measured providers index it at all today). + +abstract: | + Coverage is measured on a fixed set of reference tokens per chain, + querying each provider's public trade endpoint for the same time + window. We take the union of all trades returned across all providers + as the baseline (denominator) and each provider's returned count as + the numerator. Reference tokens are chosen for meaningful trade + volume in the measurement window so a coverage gap actually shows. + Providers use their official public endpoints. Mobula through + /api/2/trades/filters, Bitquery through streaming.bitquery.io + GraphQL, Codex through graph.codex.io GraphQL, Moralis through the + Solana gateway for Solana and the EVM API for Ethereum, BSC, Base. + Stellar is measured only for providers that officially list a + Stellar trades endpoint; providers that do not index Stellar at all + are omitted from that chain's row rather than counted as zero. + +methodology: + - "Reference tokens: a fixed set per chain, chosen for enough trade volume in the measurement window that a coverage gap is visible above sampling noise." + - "Measurement window: 60 minutes rolling. The window is the same for every provider in a given cycle so counts are directly comparable." + - "Mobula: `GET https://api.mobula.io/api/2/trades/filters?from={ts_ms}&to={ts_ms}` with `Authorization: `. Cursor pagination, limit=5000." + - "Bitquery: `POST https://streaming.bitquery.io/graphql` with `X-API-KEY`. GraphQL query on `DEXTradeByTokens` with `Block.Time.since` / `till` on the realtime dataset. Hard limit 10000 per call." + - "Codex: `POST https://graph.codex.io/graphql` with `Authorization: `. GraphQL query on `getTokenEvents` with `timestamp` bounds. Cursor pagination." + - "Moralis: `GET https://solana-gateway.moralis.io/token/mainnet/{addr}/swaps` for Solana; `GET https://deep-index.moralis.io/api/v2.2/erc20/{addr}/swaps` for EVM. `X-API-Key` header. Manual cursor pagination, limit=100." + - "Stellar coverage measured only for providers that ship an official Stellar trades endpoint. Providers with no Stellar support are excluded from the Stellar row rather than counted as zero (that would penalise all four providers unfairly against a chain none of them promised)." + - "Capture rate: `provider_count / max(provider_count across all providers on that (chain, token)) * 100`. Union baseline is the largest observed count, not a synthetic ground truth." + - "Cadence: every 30 minutes per (provider, chain, token). One measurement is short (a handful of API calls per token) so the full cycle finishes well inside the 30-minute window." + - "Failure handling: HTTP timeouts and 5xx count as zero trades for that cycle. Persistent 5xx (three cycles in a row) surfaces as `unresponsive` on the leaderboard, not silent zeros." + +findings: + - "{{best_name}} currently leads at {{best_p50}} average trade capture across {{count}} measured providers. The union baseline updates every cycle: as one provider extends coverage the ceiling moves and the others' relative capture rates shift." + - "{{name:mobula}} averages {{p50:mobula}}. Mobula's advantage on this bench is DEX breadth. Coverage of pump.fun, meme AMMs and small aggregator DEXs is what drives the number up on new-launch Solana tokens where competitors often index only Raydium or Meteora." + - "{{name:bitquery}} averages {{p50:bitquery}}. Bitquery ships strong Solana and EVM coverage through its `DEXTradeByTokens` GraphQL, but the 10000-row hard cap on a single query truncates high-volume tokens in the first hour after launch; the harness paginates when possible, but not every trade type is paginable." + - "{{name:codex}} averages {{p50:codex}}. Codex (formerly Defined) prioritises depth on EVM and Solana DEX event indexing, which shows here as strong per-chain coverage on the chains they index and no coverage at all on Stellar." + - "{{name:moralis}} averages {{p50:moralis}}. Moralis's Solana coverage is limited to two DEXs (PumpSwap and Meteora Dynamic AMM v2), so on any Solana token that trades across more than those two venues the capture rate drops fast; on EVM chains coverage is broader." + - "Stellar coverage is uneven: only providers that officially list a Stellar trades endpoint appear on that chain's row. This is the honest way to represent the current state of the market. Mobula added Stellar recently, others have not shipped it yet." + +source: https://github.com/ChainBench/OpenChainBench/tree/main/harnesses/token-trade-coverage + +prometheus: + window: 24h + expected_freshness_seconds: 3600 + +faq: + - q: "Which crypto data API returns the most complete trade history for a token?" + a: "{{best_name}} currently leads at {{best_p50}} average trade capture across {{count}} measured providers. This is measured per (chain, token) and averaged, so the leaderboard reflects real coverage across a mixed sample rather than a single lucky token." + - q: "What does 'capture rate' actually mean here?" + a: "For each reference token on each chain, the harness fetches trades from every provider over the same time window. The largest count across providers is the baseline (union of what's discoverable through public APIs). Each provider's rate is its own count divided by that baseline, expressed as a percent. A rate of 100 on a token means the provider returned as many trades as the best-covering provider. A rate of 40 means it missed 60 percent of the swaps the best-covering provider found." + - q: "Why not use a canonical onchain ground truth from RPC nodes?" + a: "In principle you could walk the block explorer and reconstruct every swap. In practice the ground truth depends on which DEX programs, protocols and vault contracts you include, and that decision is itself opinionated. The union-of-providers baseline is a defensible proxy that mirrors what a trader integrating a public API can actually see. It undercounts the truth uniformly across providers, so relative ranking is preserved even if absolute completeness is not 100." + - q: "Which chains are covered?" + a: "Solana, Ethereum, BSC, Base and Stellar. Every provider is measured on each chain it officially supports. Stellar is included because Mobula added Stellar trades to its API recently; other providers that do not ship a Stellar endpoint are excluded from the Stellar row rather than counted as zero." + - q: "Is Moralis really that far behind on Solana?" + a: "On the Solana row Moralis's rate averages {{p50:moralis:chain:solana}} in this bench. The reason is DEX coverage. Moralis's Solana swaps endpoint at time of writing indexes PumpSwap and Meteora Dynamic AMM v2. Any trade routed through Raydium, Jupiter, Meteora DAMM v1, Orca or the long tail of aggregator DEXs is missed. Providers that index the full DEX set (Mobula, Bitquery, Codex) show much higher capture rates on the same tokens." + +dimensions: + chain: + - value: all + label: All chains + - value: solana + label: Solana + - value: ethereum + label: Ethereum + - value: bsc + label: BNB Chain + - value: base + label: Base + - value: stellar + label: Stellar + +providers: + - slug: mobula + name: Mobula + tag: /api/2/trades/filters + formula: "Trades returned by Mobula /api/2/trades/filters divided by union-across-providers count on the same (chain, token) in a rolling 60 min window." + queries: + p50: avg_over_time(ocb_token_trade_capture_pct{provider="mobula"}[24h]) + p90: quantile_over_time(0.90, ocb_token_trade_capture_pct{provider="mobula"}[24h]) + p99: quantile_over_time(0.99, ocb_token_trade_capture_pct{provider="mobula"}[24h]) + mean: avg_over_time(ocb_token_trade_capture_pct{provider="mobula"}[24h]) + success: clamp_max(avg_over_time(ocb_token_trade_probe_ok{provider="mobula"}[24h]), 1) + sample_size: count_over_time(ocb_token_trade_capture_pct{provider="mobula"}[24h]) + series: ocb_token_trade_capture_pct{provider="mobula"} + + - slug: bitquery + name: Bitquery + tag: streaming.bitquery.io GraphQL + formula: "Trades returned by Bitquery DEXTradeByTokens (realtime dataset) divided by union-across-providers count on the same (chain, token) in a rolling 60 min window." + queries: + p50: avg_over_time(ocb_token_trade_capture_pct{provider="bitquery"}[24h]) + p90: quantile_over_time(0.90, ocb_token_trade_capture_pct{provider="bitquery"}[24h]) + p99: quantile_over_time(0.99, ocb_token_trade_capture_pct{provider="bitquery"}[24h]) + mean: avg_over_time(ocb_token_trade_capture_pct{provider="bitquery"}[24h]) + success: clamp_max(avg_over_time(ocb_token_trade_probe_ok{provider="bitquery"}[24h]), 1) + sample_size: count_over_time(ocb_token_trade_capture_pct{provider="bitquery"}[24h]) + series: ocb_token_trade_capture_pct{provider="bitquery"} + + - slug: codex + name: Codex + tag: graph.codex.io GraphQL + formula: "Trades returned by Codex getTokenEvents divided by union-across-providers on the same (chain, token) in a rolling 60 min window. Excluded from Stellar row." + queries: + p50: avg_over_time(ocb_token_trade_capture_pct{provider="codex"}[24h]) + p90: quantile_over_time(0.90, ocb_token_trade_capture_pct{provider="codex"}[24h]) + p99: quantile_over_time(0.99, ocb_token_trade_capture_pct{provider="codex"}[24h]) + mean: avg_over_time(ocb_token_trade_capture_pct{provider="codex"}[24h]) + success: clamp_max(avg_over_time(ocb_token_trade_probe_ok{provider="codex"}[24h]), 1) + sample_size: count_over_time(ocb_token_trade_capture_pct{provider="codex"}[24h]) + series: ocb_token_trade_capture_pct{provider="codex"} + + - slug: moralis + name: Moralis + tag: solana-gateway.moralis.io + deep-index.moralis.io + formula: "Trades returned by Moralis per-token swaps endpoint (Solana gateway or EVM API) divided by union-across-providers on (chain, token) rolling 60 min. Excluded from Stellar row." + queries: + p50: avg_over_time(ocb_token_trade_capture_pct{provider="moralis"}[24h]) + p90: quantile_over_time(0.90, ocb_token_trade_capture_pct{provider="moralis"}[24h]) + p99: quantile_over_time(0.99, ocb_token_trade_capture_pct{provider="moralis"}[24h]) + mean: avg_over_time(ocb_token_trade_capture_pct{provider="moralis"}[24h]) + success: clamp_max(avg_over_time(ocb_token_trade_probe_ok{provider="moralis"}[24h]), 1) + sample_size: count_over_time(ocb_token_trade_capture_pct{provider="moralis"}[24h]) + series: ocb_token_trade_capture_pct{provider="moralis"} diff --git a/harnesses/token-trade-coverage/.env.example b/harnesses/token-trade-coverage/.env.example new file mode 100644 index 00000000..bd51d009 --- /dev/null +++ b/harnesses/token-trade-coverage/.env.example @@ -0,0 +1,15 @@ +# token-trade-coverage harness. Fill in and rename to `.env`. + +# Providers (all required for a full bench cycle; the harness +# tolerates missing keys per-provider and reports probe_ok=0 for that +# provider but keeps the others going, so partial config is fine for +# local debugging). +MOBULA_API_KEY= +BITQUERY_API_KEY= +CODEX_API_KEY= +MORALIS_API_KEY= + +# Cadence + runtime knobs. +SWEEP_SEC=1800 +METRICS_PORT=2112 +HTTP_TIMEOUT_SEC=30 diff --git a/harnesses/token-trade-coverage/Dockerfile b/harnesses/token-trade-coverage/Dockerfile new file mode 100644 index 00000000..0b6e7282 --- /dev/null +++ b/harnesses/token-trade-coverage/Dockerfile @@ -0,0 +1,12 @@ +FROM golang:1.23-alpine AS build +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /out/scanner ./cmd/scanner + +FROM alpine:3.20 +RUN apk add --no-cache ca-certificates && update-ca-certificates +COPY --from=build /out/scanner /usr/local/bin/scanner +EXPOSE 2112 +ENTRYPOINT ["/usr/local/bin/scanner"] diff --git a/harnesses/token-trade-coverage/README.md b/harnesses/token-trade-coverage/README.md new file mode 100644 index 00000000..d32dc009 --- /dev/null +++ b/harnesses/token-trade-coverage/README.md @@ -0,0 +1,98 @@ +# Harness · token-trade-coverage + +> Source for bench № 090 · Most complete onchain trade data API. Measures, for each reference token per chain, how many trades each provider (Mobula, Bitquery, Codex, Moralis) returns in a fixed 60-minute window, then publishes the capture rate vs the union baseline. + +## What ships in this directory + +- `cmd/scanner/main.go` — measurement loop. Every `SWEEP_SEC` (default 1800 = 30 min) it iterates every (provider, chain, token) tuple, fetches trades in the same 60-minute window, computes the union baseline as `max(counts across providers)` and emits per-provider capture rate to Prometheus. +- `cmd/scanner/mobula.go`, `bitquery.go`, `codex.go`, `moralis.go` — one file per provider. Each exposes a single `fetchTrades(ctx, chain, tokenAddress, windowStart, windowEnd) (int, error)` function that returns the number of distinct trades. Not the full trade objects — we only need the count for capture-rate computation, so the harness never materializes hundreds of MB of trade JSON in memory. +- `cmd/scanner/config.go` — reference token list per chain, env parsing, provider capability matrix (which provider supports which chain). +- `cmd/scanner/metrics.go` — Prom metric definitions (`ocb_token_trade_capture_pct`, `ocb_token_trade_probe_ok`, `ocb_token_trade_query_latency_ms`, `ocb_token_trade_dex_count`). + +## Providers + +| Provider | Endpoint | Auth | Chains | +| --- | --- | --- | --- | +| Mobula | `GET /api/2/trades/filters` | `Authorization: ` | Solana, Ethereum, BSC, Base, Stellar | +| Bitquery | `POST /graphql` (streaming.bitquery.io) | `X-API-KEY` header | Solana, Ethereum, BSC, Base | +| Codex | `POST /graphql` (graph.codex.io) | `Authorization: ` | Solana, Ethereum, BSC, Base | +| Moralis | `GET /token/mainnet/{addr}/swaps` (Solana) or `GET /erc20/{addr}/swaps` (EVM) | `X-API-Key` | Solana, Ethereum, BSC, Base | + +Stellar is measured for Mobula only (the other three do not ship a public Stellar trades endpoint at time of writing). The bench renders Stellar coverage as a per-chain view where non-supporting providers are absent from the row, not counted as zero. + +## Reference tokens + +Chosen for meaningful trade activity in the measurement window so a coverage gap is visible above sampling noise. See `config.go` for the current list. Rotated periodically to avoid a single token going illiquid and dragging every provider's absolute count to zero. + +## Cadence + +`SWEEP_SEC=1800` (30 min). One full sweep does 4 providers × 5 chains × 2 tokens = up to 40 API calls (fewer when a provider does not support a chain). Each call is bounded by `HTTP_TIMEOUT_SEC=30`. A full sweep completes well inside 30 minutes so `SWEEP_SEC` cadence and `avg_over_time(...[24h])` on the spec queries stay honest. + +## Env vars + +Required: + +- `MOBULA_API_KEY` — Mobula API key. Contact mobula.io if you don't have one. +- `BITQUERY_API_KEY` — Bitquery streaming.bitquery.io key. +- `CODEX_API_KEY` — Codex (Defined) API key. NOTE: this bench does NOT use the cookie-based JWT flow from `aggregator-head-lag` because the query volume is high (batch historical, not live subscribe). Fresh dedicated key recommended. +- `MORALIS_API_KEY` — Moralis Web3 Data API key. + +Optional: + +- `SWEEP_SEC` (default 1800) +- `METRICS_PORT` (default 2112) +- `HTTP_TIMEOUT_SEC` (default 30) +- `LOG_LEVEL` (default info; set debug to log every provider call) + +## Metrics produced + +| Metric | Description | +| --- | --- | +| `ocb_token_trade_capture_pct{provider, chain, token}` | Capture rate percent (0-100). `provider_count / max_provider_count * 100`. Union baseline is per (chain, token) per cycle. | +| `ocb_token_trade_absolute_count{provider, chain, token}` | Raw trade count returned by that provider in the measurement window. | +| `ocb_token_trade_query_latency_ms{provider, chain, token}` | Wall-clock latency of the provider call, including pagination. | +| `ocb_token_trade_dex_count{provider, chain, token}` | Distinct DEX venues represented in the returned trade set. Companion metric — coverage breadth vs pure count. | +| `ocb_token_trade_probe_ok{provider, chain, token}` | 1 on successful fetch, 0 on error/timeout. Consumed by the spec's `success` query. | + +The spec at `benchmarks/token-trade-coverage.yml` aggregates these across (chain, token) into a per-provider p50 for the headline leaderboard. + +## Run locally + +```bash +cp .env.example .env +# Fill in the four API keys +go run ./cmd/scanner/ +``` + +`/metrics` at `http://localhost:2112/metrics`. + +## Run in the OCB VPS stack + +Add a service block in `/opt/ocb/docker-compose.yml`: + +```yaml + token-trade-coverage: + build: + context: /opt/ocb/harnesses/token-trade-coverage + dockerfile: Dockerfile + container_name: ocb-token-trade-coverage + restart: unless-stopped + env_file: /run/ocb/.env.token-trade-coverage + expose: ["2112"] + networks: [web] + mem_limit: 512m + cpus: "0.3" +``` + +Prometheus scrape config additions in `/opt/ocb/prometheus.yml`: + +```yaml + - job_name: token-trade-coverage + scrape_interval: 60s + static_configs: + - targets: ["token-trade-coverage:2112"] +``` + +## Reference implementation + +The initial TypeScript reference lives at https://github.com/Flotapponnier/token-trade-benchmark-. This harness is a Go port with Prometheus emission and OCB conventions. Any semantic drift between the two (which trades count, how the window is bounded) is corrected here first; the reference repo is a design document, not a source of truth. diff --git a/harnesses/token-trade-coverage/cmd/scanner/bitquery.go b/harnesses/token-trade-coverage/cmd/scanner/bitquery.go new file mode 100644 index 00000000..c20ad8e2 --- /dev/null +++ b/harnesses/token-trade-coverage/cmd/scanner/bitquery.go @@ -0,0 +1,182 @@ +package main + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "time" +) + +const bitqueryURL = "https://streaming.bitquery.io/graphql" + +// bitqueryEVMResp / bitquerySolanaResp keep the response tight: only +// what we need to count trades and derive DEX venues. +type bitqueryEVMResp struct { + Data struct { + EVM struct { + DEXTrades []struct { + Transaction struct { + Hash string `json:"Hash"` + } `json:"Transaction"` + Trade struct { + Dex struct { + ProtocolName string `json:"ProtocolName"` + } `json:"Dex"` + } `json:"Trade"` + } `json:"DEXTrades"` + } `json:"EVM"` + } `json:"data"` +} + +type bitquerySolanaResp struct { + Data struct { + Solana struct { + DEXTradeByTokens []struct { + Transaction struct { + Signature string `json:"Signature"` + } `json:"Transaction"` + Trade struct { + Dex struct { + ProtocolName string `json:"ProtocolName"` + } `json:"Dex"` + } `json:"Trade"` + } `json:"DEXTradeByTokens"` + } `json:"Solana"` + } `json:"data"` +} + +// fetchBitquery returns (trade count, distinct DEXs, error). Bitquery +// caps a single query at 10000 rows and has no cursor pagination on +// DEXTradeByTokens; on tokens whose true trade count exceeds 10k the +// bench under-reports Bitquery vs a paginated provider. The findings +// section of the spec calls this out honestly rather than pretending +// Bitquery is worse than it is. +func fetchBitquery( + ctx context.Context, + client *http.Client, + apiKey string, + tok Token, + windowStart, windowEnd int64, +) (int, int, error) { + if apiKey == "" { + return 0, 0, fmt.Errorf("BITQUERY_API_KEY not set") + } + + sinceISO := time.Unix(windowStart/1000, 0).UTC().Format(time.RFC3339) + tillISO := time.Unix(windowEnd/1000, 0).UTC().Format(time.RFC3339) + + var query string + if tok.Chain == "solana" { + query = solanaTradesGQL(tok.Address, sinceISO, tillISO) + } else { + network := bitqueryEVMNetwork(tok.Chain) + if network == "" { + return 0, 0, fmt.Errorf("bitquery: unsupported chain %s", tok.Chain) + } + query = evmTradesGQL(network, tok.Address, sinceISO, tillISO) + } + + body, _ := json.Marshal(map[string]string{"query": query}) + req, err := http.NewRequestWithContext(ctx, "POST", bitqueryURL, bytes.NewReader(body)) + if err != nil { + return 0, 0, err + } + req.Header.Set("X-API-KEY", apiKey) + req.Header.Set("Content-Type", "application/json") + + resp, err := client.Do(req) + if err != nil { + return 0, 0, err + } + respBody, err := io.ReadAll(resp.Body) + resp.Body.Close() + if err != nil { + return 0, 0, err + } + if resp.StatusCode >= 300 { + return 0, 0, fmt.Errorf("bitquery http %d: %s", resp.StatusCode, truncate(string(respBody), 200)) + } + + dexSet := map[string]struct{}{} + hashSet := map[string]struct{}{} + + if tok.Chain == "solana" { + var r bitquerySolanaResp + if err := json.Unmarshal(respBody, &r); err != nil { + return 0, 0, fmt.Errorf("bitquery parse: %w", err) + } + for _, t := range r.Data.Solana.DEXTradeByTokens { + if _, seen := hashSet[t.Transaction.Signature]; seen { + continue + } + hashSet[t.Transaction.Signature] = struct{}{} + if t.Trade.Dex.ProtocolName != "" { + dexSet[t.Trade.Dex.ProtocolName] = struct{}{} + } + } + } else { + var r bitqueryEVMResp + if err := json.Unmarshal(respBody, &r); err != nil { + return 0, 0, fmt.Errorf("bitquery parse: %w", err) + } + for _, t := range r.Data.EVM.DEXTrades { + if _, seen := hashSet[t.Transaction.Hash]; seen { + continue + } + hashSet[t.Transaction.Hash] = struct{}{} + if t.Trade.Dex.ProtocolName != "" { + dexSet[t.Trade.Dex.ProtocolName] = struct{}{} + } + } + } + return len(hashSet), len(dexSet), nil +} + +func bitqueryEVMNetwork(chain string) string { + switch chain { + case "ethereum": + return "eth" + case "bsc": + return "bsc" + case "base": + return "base" + } + return "" +} + +func solanaTradesGQL(mintAddress, since, till string) string { + return fmt.Sprintf(`{ + Solana(dataset: realtime) { + DEXTradeByTokens( + limit: {count: 10000} + where: { + Block: {Time: {since: "%s", till: "%s"}} + Trade: {Currency: {MintAddress: {is: "%s"}}} + } + ) { + Transaction { Signature } + Trade { Dex { ProtocolName } } + } + } +}`, since, till, mintAddress) +} + +func evmTradesGQL(network, tokenAddress, since, till string) string { + return fmt.Sprintf(`{ + EVM(dataset: realtime, network: %s) { + DEXTrades( + limit: {count: 10000} + where: { + Block: {Time: {since: "%s", till: "%s"}} + Trade: {Buy: {Currency: {SmartContract: {is: "%s"}}}} + } + ) { + Transaction { Hash } + Trade { Dex { ProtocolName } } + } + } +}`, network, since, till, tokenAddress) +} diff --git a/harnesses/token-trade-coverage/cmd/scanner/codex.go b/harnesses/token-trade-coverage/cmd/scanner/codex.go new file mode 100644 index 00000000..b5065d51 --- /dev/null +++ b/harnesses/token-trade-coverage/cmd/scanner/codex.go @@ -0,0 +1,143 @@ +package main + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" +) + +const codexURL = "https://graph.codex.io/graphql" + +// codexResp: minimal envelope. Codex's `getTokenEvents` is cursor-paginated +// via the `cursor` string returned in each response. +type codexResp struct { + Data struct { + GetTokenEvents struct { + Items []struct { + TransactionHash string `json:"transactionHash"` + EventType string `json:"eventType"` + ExchangeAddress string `json:"exchangeAddress"` + } `json:"items"` + Cursor string `json:"cursor"` + } `json:"getTokenEvents"` + } `json:"data"` + Errors []struct { + Message string `json:"message"` + } `json:"errors"` +} + +// codexNetworkID maps OCB chain slug to Codex's numeric networkId. +// Same table as in the reference TS impl. +func codexNetworkID(chain string) int { + switch chain { + case "solana": + return 1399811149 + case "ethereum": + return 1 + case "bsc": + return 56 + case "base": + return 8453 + } + return 0 +} + +// fetchCodex returns (trade count, distinct exchanges, error). Uses +// standard API-key auth via `Authorization` header — the cookie-based +// JWT flow that lives in aggregator-head-lag is not used here because +// query volume is batch-historical, not live-subscribe. +func fetchCodex( + ctx context.Context, + client *http.Client, + apiKey string, + tok Token, + windowStart, windowEnd int64, +) (int, int, error) { + if apiKey == "" { + return 0, 0, fmt.Errorf("CODEX_API_KEY not set") + } + networkID := codexNetworkID(tok.Chain) + if networkID == 0 { + return 0, 0, fmt.Errorf("codex: unsupported chain %s", tok.Chain) + } + + fromSec := windowStart / 1000 + toSec := windowEnd / 1000 + + var ( + total int + cursor string + exchSet = map[string]struct{}{} + hashSet = map[string]struct{}{} + maxPages = 50 + ) + + for page := 0; page < maxPages; page++ { + query := fmt.Sprintf(` +query GetEvents { + getTokenEvents( + query: { + address: "%s" + networkId: %d + timestamp: {from: %d, to: %d} + eventType: Swap + } + limit: 200 + cursor: %q + ) { + items { + transactionHash + eventType + exchangeAddress + } + cursor + } +}`, tok.Address, networkID, fromSec, toSec, cursor) + + body, _ := json.Marshal(map[string]string{"query": query}) + req, err := http.NewRequestWithContext(ctx, "POST", codexURL, bytes.NewReader(body)) + if err != nil { + return total, len(exchSet), err + } + req.Header.Set("Authorization", apiKey) + req.Header.Set("Content-Type", "application/json") + + resp, err := client.Do(req) + if err != nil { + return total, len(exchSet), err + } + respBody, err := io.ReadAll(resp.Body) + resp.Body.Close() + if err != nil { + return total, len(exchSet), err + } + if resp.StatusCode >= 300 { + return total, len(exchSet), fmt.Errorf("codex http %d: %s", resp.StatusCode, truncate(string(respBody), 200)) + } + var r codexResp + if err := json.Unmarshal(respBody, &r); err != nil { + return total, len(exchSet), fmt.Errorf("codex parse: %w", err) + } + if len(r.Errors) > 0 { + return total, len(exchSet), fmt.Errorf("codex graphql: %s", r.Errors[0].Message) + } + for _, it := range r.Data.GetTokenEvents.Items { + if _, seen := hashSet[it.TransactionHash]; seen { + continue + } + hashSet[it.TransactionHash] = struct{}{} + total++ + if it.ExchangeAddress != "" { + exchSet[it.ExchangeAddress] = struct{}{} + } + } + if r.Data.GetTokenEvents.Cursor == "" || len(r.Data.GetTokenEvents.Items) == 0 { + break + } + cursor = r.Data.GetTokenEvents.Cursor + } + return total, len(exchSet), nil +} diff --git a/harnesses/token-trade-coverage/cmd/scanner/config.go b/harnesses/token-trade-coverage/cmd/scanner/config.go new file mode 100644 index 00000000..63278ca4 --- /dev/null +++ b/harnesses/token-trade-coverage/cmd/scanner/config.go @@ -0,0 +1,119 @@ +package main + +import ( + "os" + "strconv" + "time" +) + +// Token is a reference token watched for coverage measurement. +type Token struct { + Chain string // "solana", "ethereum", "bsc", "base", "stellar" + Address string // native address on that chain + Symbol string // short label for logs +} + +// ProviderCapability declares which chains a provider is measured on. +// A provider is EXCLUDED from a chain's row if the chain is not listed +// here; that keeps the leaderboard honest instead of counting a +// non-integration as a zero-score defeat. +type ProviderCapability map[string]bool + +// Config is populated once at startup and read-only afterwards. +type Config struct { + SweepSec int + MetricsPort string + HTTPTimeoutSec int + MobulaKey string + BitqueryKey string + CodexKey string + MoralisKey string + Tokens []Token + Capabilities map[string]ProviderCapability // provider -> {chain -> supported} + MeasurementWinMs int64 // rolling window per measurement +} + +// LoadConfig reads env, defaults + hardcoded reference token list. +// Reference tokens are chosen for meaningful trade activity so a +// coverage gap becomes visible; rotate them here when a listed token +// goes illiquid. +func LoadConfig() *Config { + return &Config{ + SweepSec: envInt("SWEEP_SEC", 1800), + MetricsPort: envStr("METRICS_PORT", "2112"), + HTTPTimeoutSec: envInt("HTTP_TIMEOUT_SEC", 30), + MeasurementWinMs: int64(60*60) * 1000, // 60 min rolling window + MobulaKey: os.Getenv("MOBULA_API_KEY"), + BitqueryKey: os.Getenv("BITQUERY_API_KEY"), + CodexKey: os.Getenv("CODEX_API_KEY"), + MoralisKey: os.Getenv("MORALIS_API_KEY"), + Tokens: []Token{ + // Solana. Pump.fun-era memes with high trade frequency across + // multiple DEXs so any provider indexing only one venue drops + // visibly in capture rate. Rotated when activity dies out. + {Chain: "solana", Address: "BWJ7zJauzatao4FsBnGdVsqdBi3k5NbgSY62noZApump", Symbol: "NANA"}, + {Chain: "solana", Address: "GJqCjtgEwqdFWVRsDs8JXKFoTeRVZeHs1RL4ccvrpump", Symbol: "OILINU"}, + // Ethereum. Active meme + real-utility pairs so the Ethereum + // row isn't dominated by a single AMM. + {Chain: "ethereum", Address: "0x279B46A5BCB1D1de37F5588e46c756B15b26A896", Symbol: "OIL"}, + {Chain: "ethereum", Address: "0x2b566950BA2298AcEf3c730CC0129b2f4fBd30a3", Symbol: "KIMCHI"}, + // BSC. High-volume PancakeSwap tokens. + {Chain: "bsc", Address: "0xc20E45E49e0E79f0fC81E71F05fD2772d6587777", Symbol: "MILADY"}, + {Chain: "bsc", Address: "0xCae117ca6Bc8A341D2E7207F30E180f0e5618B9D", Symbol: "ARK"}, + // Base. Aerodrome + Uniswap v3 v4 anchors. + {Chain: "base", Address: "0x64384EBd580f8c48ED4972bbbE895aDE55671Aca", Symbol: "BROKE"}, + {Chain: "base", Address: "0x9aA448c1Da3B8975e0619A5a96db4Fccc491e4d5", Symbol: "LANCER"}, + // Stellar. Populate with active issuer:asset codes once Mobula + // confirms the addresses. Placeholder rows are skipped by the + // harness (empty address = skip). + {Chain: "stellar", Address: "", Symbol: "STELLAR-1"}, + {Chain: "stellar", Address: "", Symbol: "STELLAR-2"}, + }, + Capabilities: map[string]ProviderCapability{ + "mobula": { + "solana": true, "ethereum": true, "bsc": true, "base": true, "stellar": true, + }, + "bitquery": { + "solana": true, "ethereum": true, "bsc": true, "base": true, + }, + "codex": { + "solana": true, "ethereum": true, "bsc": true, "base": true, + }, + "moralis": { + "solana": true, "ethereum": true, "bsc": true, "base": true, + }, + }, + } +} + +func (c *Config) HTTPTimeout() time.Duration { + return time.Duration(c.HTTPTimeoutSec) * time.Second +} + +// Supports reports whether the (provider, chain) pair is measured. +func (c *Config) Supports(provider, chain string) bool { + caps, ok := c.Capabilities[provider] + if !ok { + return false + } + return caps[chain] +} + +func envInt(k string, def int) int { + v := os.Getenv(k) + if v == "" { + return def + } + n, err := strconv.Atoi(v) + if err != nil { + return def + } + return n +} + +func envStr(k, def string) string { + if v := os.Getenv(k); v != "" { + return v + } + return def +} diff --git a/harnesses/token-trade-coverage/cmd/scanner/main.go b/harnesses/token-trade-coverage/cmd/scanner/main.go new file mode 100644 index 00000000..30e44ced --- /dev/null +++ b/harnesses/token-trade-coverage/cmd/scanner/main.go @@ -0,0 +1,150 @@ +// Materialize the token-trade-coverage bench (№ 090). +// +// Loop: every SWEEP_SEC, iterate every (provider, chain, token) tuple, +// fetch trades in the same rolling 60-minute window, compute the union +// baseline per (chain, token) as max(counts) across providers and +// publish capture rate + companion metrics to Prometheus. +// +// The design keeps memory bounded: providers return counts, not trade +// arrays, so a token with 50k trades in the window costs O(1) here. + +package main + +import ( + "context" + "fmt" + "log" + "net/http" + "os" + "os/signal" + "sync" + "syscall" + "time" + + "github.com/prometheus/client_golang/prometheus/promhttp" +) + +var providers = []string{"mobula", "bitquery", "codex", "moralis"} + +func main() { + cfg := LoadConfig() + log.Printf("[boot] sweep=%ds providers=%v tokens=%d", cfg.SweepSec, providers, len(cfg.Tokens)) + + // Expose /metrics before the first sweep so Prom starts scraping + // immediately; capture_pct just stays 0 until the loop populates it. + http.Handle("/metrics", promhttp.Handler()) + go func() { + addr := ":" + cfg.MetricsPort + log.Printf("[boot] metrics on %s/metrics", addr) + if err := http.ListenAndServe(addr, nil); err != nil { + log.Fatalf("http: %v", err) + } + }() + + client := &http.Client{Timeout: cfg.HTTPTimeout()} + + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) + defer cancel() + + ticker := time.NewTicker(time.Duration(cfg.SweepSec) * time.Second) + defer ticker.Stop() + + // First sweep runs immediately at boot so Prom sees data within + // SWEEP_SEC + measurement time rather than waiting a full cycle. + sweep(ctx, cfg, client) + for { + select { + case <-ctx.Done(): + log.Printf("[shutdown] signal received") + return + case <-ticker.C: + sweep(ctx, cfg, client) + } + } +} + +// sweep runs one full measurement cycle. For each token, we fan out +// across every supported provider in parallel, wait for all to finish +// (or fail), compute the union baseline as max(counts) and emit. +func sweep(ctx context.Context, cfg *Config, client *http.Client) { + sweepStart := time.Now() + windowEnd := sweepStart.UnixMilli() + windowStart := windowEnd - cfg.MeasurementWinMs + + for _, tok := range cfg.Tokens { + if tok.Address == "" { + // Placeholder row (Stellar addresses TBD). Skip silently + // so the container doesn't spam warnings until they land. + continue + } + results := make([]Result, 0, len(providers)) + var mu sync.Mutex + var wg sync.WaitGroup + + for _, p := range providers { + if !cfg.Supports(p, tok.Chain) { + continue + } + wg.Add(1) + go func(p string) { + defer wg.Done() + start := time.Now() + count, dex, err := fetchOne(ctx, client, cfg, p, tok, windowStart, windowEnd) + latMs := float64(time.Since(start).Milliseconds()) + r := Result{ + Provider: p, + Chain: tok.Chain, + Token: tok.Symbol, + Count: count, + DexCount: dex, + LatencyMs: latMs, + OK: err == nil, + } + if err != nil { + log.Printf("[%s][%s/%s] err: %v", p, tok.Chain, tok.Symbol, err) + } else { + log.Printf("[%s][%s/%s] count=%d dex=%d %.0fms", p, tok.Chain, tok.Symbol, count, dex, latMs) + } + mu.Lock() + results = append(results, r) + mu.Unlock() + }(p) + } + wg.Wait() + + // Union baseline: the largest count observed across providers + // that succeeded. If every provider failed the baseline is 0 + // and capture rate stays 0 across the board (spec `success` + // query then flags the (chain, token) as unresponsive). + unionMax := 0 + for _, r := range results { + if r.OK && r.Count > unionMax { + unionMax = r.Count + } + } + emitCycle(results, unionMax) + } + log.Printf("[sweep] done in %.1fs", time.Since(sweepStart).Seconds()) +} + +// fetchOne dispatches to the provider-specific fetcher. +func fetchOne( + ctx context.Context, + client *http.Client, + cfg *Config, + provider string, + tok Token, + windowStart, windowEnd int64, +) (int, int, error) { + switch provider { + case "mobula": + return fetchMobula(ctx, client, cfg.MobulaKey, tok, windowStart, windowEnd) + case "bitquery": + return fetchBitquery(ctx, client, cfg.BitqueryKey, tok, windowStart, windowEnd) + case "codex": + return fetchCodex(ctx, client, cfg.CodexKey, tok, windowStart, windowEnd) + case "moralis": + return fetchMoralis(ctx, client, cfg.MoralisKey, tok, windowStart, windowEnd) + } + return 0, 0, fmt.Errorf("unknown provider %s", provider) +} diff --git a/harnesses/token-trade-coverage/cmd/scanner/metrics.go b/harnesses/token-trade-coverage/cmd/scanner/metrics.go new file mode 100644 index 00000000..b0cf151a --- /dev/null +++ b/harnesses/token-trade-coverage/cmd/scanner/metrics.go @@ -0,0 +1,73 @@ +package main + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +// Metric surface. Labels are (provider, chain, token). Kept exactly +// three labels so PromQL aggregation stays simple and the spec's +// `series` query at the bench level can group by any one of them. +var ( + capturePct = promauto.NewGaugeVec(prometheus.GaugeOpts{ + Name: "ocb_token_trade_capture_pct", + Help: "Percent of the union-baseline trade count returned by this provider for (chain, token) in the last measurement window.", + }, []string{"provider", "chain", "token"}) + + absoluteCount = promauto.NewGaugeVec(prometheus.GaugeOpts{ + Name: "ocb_token_trade_absolute_count", + Help: "Raw trade count returned by this provider for (chain, token) in the last measurement window.", + }, []string{"provider", "chain", "token"}) + + queryLatency = promauto.NewGaugeVec(prometheus.GaugeOpts{ + Name: "ocb_token_trade_query_latency_ms", + Help: "Wall-clock latency of the provider's trade fetch call including pagination, in milliseconds.", + }, []string{"provider", "chain", "token"}) + + dexCount = promauto.NewGaugeVec(prometheus.GaugeOpts{ + Name: "ocb_token_trade_dex_count", + Help: "Distinct DEX venues represented in the trade set returned by this provider for (chain, token).", + }, []string{"provider", "chain", "token"}) + + probeOK = promauto.NewGaugeVec(prometheus.GaugeOpts{ + Name: "ocb_token_trade_probe_ok", + Help: "1 on successful fetch, 0 on error or timeout. Consumed by the bench spec's `success` query.", + }, []string{"provider", "chain", "token"}) +) + +// Result is the per-call outcome of one provider fetch. +type Result struct { + Provider string + Chain string + Token string + Count int + DexCount int + LatencyMs float64 + OK bool +} + +// emitCycle publishes one full cycle's worth of results. Called once +// per (chain, token) after every provider has been queried and the +// union baseline is known. +func emitCycle(results []Result, unionMax int) { + for _, r := range results { + lbl := prometheus.Labels{ + "provider": r.Provider, + "chain": r.Chain, + "token": r.Token, + } + absoluteCount.With(lbl).Set(float64(r.Count)) + queryLatency.With(lbl).Set(r.LatencyMs) + dexCount.With(lbl).Set(float64(r.DexCount)) + if r.OK { + probeOK.With(lbl).Set(1) + } else { + probeOK.With(lbl).Set(0) + } + if unionMax > 0 && r.OK { + capturePct.With(lbl).Set(float64(r.Count) / float64(unionMax) * 100) + } else { + capturePct.With(lbl).Set(0) + } + } +} diff --git a/harnesses/token-trade-coverage/cmd/scanner/mobula.go b/harnesses/token-trade-coverage/cmd/scanner/mobula.go new file mode 100644 index 00000000..a9b7e9b7 --- /dev/null +++ b/harnesses/token-trade-coverage/cmd/scanner/mobula.go @@ -0,0 +1,133 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strconv" + "time" +) + +const mobulaBase = "https://api.mobula.io/api/2/trades/filters" + +// mobulaResp is the minimal envelope we care about: we only need the +// count (via len(data)) and the DEX per row for coverage-breadth. Full +// trade objects are 30+ fields we intentionally ignore. +type mobulaResp struct { + Data []struct { + DEX string `json:"dex"` + Hash string `json:"hash"` + } `json:"data"` + Pagination struct { + Cursor string `json:"cursor"` + } `json:"pagination"` +} + +// fetchMobula returns (trade count, distinct DEXs, error). Paginates +// via cursor until either exhausted or the safety cap is hit. +func fetchMobula( + ctx context.Context, + client *http.Client, + apiKey string, + tok Token, + windowStart, windowEnd int64, +) (int, int, error) { + if apiKey == "" { + return 0, 0, fmt.Errorf("MOBULA_API_KEY not set") + } + var ( + total int + cursor string + dexSet = map[string]struct{}{} + hashSet = map[string]struct{}{} + maxPages = 50 + ) + for page := 0; page < maxPages; page++ { + u, _ := url.Parse(mobulaBase) + q := u.Query() + q.Set("chain", mobulaChainName(tok.Chain)) + q.Set("token", tok.Address) + q.Set("from", strconv.FormatInt(windowStart, 10)) + q.Set("to", strconv.FormatInt(windowEnd, 10)) + q.Set("limit", "5000") + if cursor != "" { + q.Set("cursor", cursor) + } + u.RawQuery = q.Encode() + + req, err := http.NewRequestWithContext(ctx, "GET", u.String(), nil) + if err != nil { + return total, len(dexSet), err + } + req.Header.Set("Authorization", apiKey) + req.Header.Set("Accept", "application/json") + + resp, err := client.Do(req) + if err != nil { + return total, len(dexSet), err + } + body, err := io.ReadAll(resp.Body) + resp.Body.Close() + if err != nil { + return total, len(dexSet), err + } + if resp.StatusCode >= 300 { + return total, len(dexSet), fmt.Errorf("mobula http %d: %s", resp.StatusCode, truncate(string(body), 200)) + } + var r mobulaResp + if err := json.Unmarshal(body, &r); err != nil { + return total, len(dexSet), fmt.Errorf("mobula parse: %w", err) + } + for _, t := range r.Data { + // Dedupe by tx hash across pages. Providers occasionally + // return the same hash on consecutive pages when a cursor + // resets under the hood. + if _, seen := hashSet[t.Hash]; seen { + continue + } + hashSet[t.Hash] = struct{}{} + total++ + if t.DEX != "" { + dexSet[t.DEX] = struct{}{} + } + } + if r.Pagination.Cursor == "" || len(r.Data) == 0 { + break + } + cursor = r.Pagination.Cursor + // Cursor pages back-to-back can trip provider rate limits; a + // short breather keeps the fetch inside its budget without + // starving the cadence. + time.Sleep(50 * time.Millisecond) + } + return total, len(dexSet), nil +} + +// mobulaChainName maps OCB canonical chain slug → Mobula chain param +// value. Kept centralised so the mapping is auditable in one place. +func mobulaChainName(chain string) string { + switch chain { + case "solana": + return "Solana" + case "ethereum": + return "Ethereum" + case "bsc": + return "BNB Smart Chain (BEP20)" + case "base": + return "Base" + case "stellar": + return "Stellar" + default: + return chain + } +} + +func truncate(s string, n int) string { + if len(s) <= n { + return s + } + return s[:n] + "…" +} diff --git a/harnesses/token-trade-coverage/cmd/scanner/moralis.go b/harnesses/token-trade-coverage/cmd/scanner/moralis.go new file mode 100644 index 00000000..6851211b --- /dev/null +++ b/harnesses/token-trade-coverage/cmd/scanner/moralis.go @@ -0,0 +1,141 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "time" +) + +// Moralis has two hosts: a Solana gateway with its own routes and the +// EVM deep-index API with shared /erc20 routes. +const ( + moralisSolanaBase = "https://solana-gateway.moralis.io" + moralisEVMBase = "https://deep-index.moralis.io/api/v2.2" +) + +type moralisResp struct { + Cursor string `json:"cursor"` + Result []struct { + TransactionHash string `json:"transactionHash"` + ExchangeName string `json:"exchangeName"` + PairAddress string `json:"pairAddress"` + } `json:"result"` +} + +// fetchMoralis returns (trade count, distinct DEX venues, error). +// Moralis paginates via `cursor` on both hosts; page size caps at 100. +func fetchMoralis( + ctx context.Context, + client *http.Client, + apiKey string, + tok Token, + windowStart, windowEnd int64, +) (int, int, error) { + if apiKey == "" { + return 0, 0, fmt.Errorf("MORALIS_API_KEY not set") + } + + fromISO := time.Unix(windowStart/1000, 0).UTC().Format(time.RFC3339) + toISO := time.Unix(windowEnd/1000, 0).UTC().Format(time.RFC3339) + + var ( + total int + cursor string + dexSet = map[string]struct{}{} + hashSet = map[string]struct{}{} + maxPages = 100 + ) + + for page := 0; page < maxPages; page++ { + var reqURL string + if tok.Chain == "solana" { + base := fmt.Sprintf("%s/token/mainnet/%s/swaps", moralisSolanaBase, tok.Address) + u, _ := url.Parse(base) + q := u.Query() + q.Set("fromDate", fromISO) + q.Set("toDate", toISO) + q.Set("order", "ASC") + q.Set("limit", "100") + q.Set("transactionTypes", "buy,sell") + if cursor != "" { + q.Set("cursor", cursor) + } + u.RawQuery = q.Encode() + reqURL = u.String() + } else { + chain := moralisEVMChain(tok.Chain) + if chain == "" { + return 0, 0, fmt.Errorf("moralis: unsupported chain %s", tok.Chain) + } + base := fmt.Sprintf("%s/erc20/%s/swaps", moralisEVMBase, tok.Address) + u, _ := url.Parse(base) + q := u.Query() + q.Set("chain", chain) + q.Set("fromDate", fromISO) + q.Set("toDate", toISO) + q.Set("order", "ASC") + q.Set("limit", "100") + if cursor != "" { + q.Set("cursor", cursor) + } + u.RawQuery = q.Encode() + reqURL = u.String() + } + + req, err := http.NewRequestWithContext(ctx, "GET", reqURL, nil) + if err != nil { + return total, len(dexSet), err + } + req.Header.Set("X-API-Key", apiKey) + req.Header.Set("Accept", "application/json") + + resp, err := client.Do(req) + if err != nil { + return total, len(dexSet), err + } + body, err := io.ReadAll(resp.Body) + resp.Body.Close() + if err != nil { + return total, len(dexSet), err + } + if resp.StatusCode >= 300 { + return total, len(dexSet), fmt.Errorf("moralis http %d: %s", resp.StatusCode, truncate(string(body), 200)) + } + var r moralisResp + if err := json.Unmarshal(body, &r); err != nil { + return total, len(dexSet), fmt.Errorf("moralis parse: %w", err) + } + for _, t := range r.Result { + if _, seen := hashSet[t.TransactionHash]; seen { + continue + } + hashSet[t.TransactionHash] = struct{}{} + total++ + if t.ExchangeName != "" { + dexSet[t.ExchangeName] = struct{}{} + } + } + if r.Cursor == "" || len(r.Result) == 0 { + break + } + cursor = r.Cursor + time.Sleep(50 * time.Millisecond) + } + return total, len(dexSet), nil +} + +func moralisEVMChain(chain string) string { + switch chain { + case "ethereum": + return "0x1" + case "bsc": + return "0x38" + case "base": + return "0x2105" + } + return "" +} diff --git a/harnesses/token-trade-coverage/go.mod b/harnesses/token-trade-coverage/go.mod new file mode 100644 index 00000000..000366ca --- /dev/null +++ b/harnesses/token-trade-coverage/go.mod @@ -0,0 +1,17 @@ +module github.com/ChainBench/OpenChainBench/harnesses/token-trade-coverage + +go 1.23 + +require github.com/prometheus/client_golang v1.20.5 + +require ( + github.com/beorn7/perks v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/klauspost/compress v1.17.11 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/common v0.62.0 // indirect + github.com/prometheus/procfs v0.15.1 // indirect + golang.org/x/sys v0.28.0 // indirect + google.golang.org/protobuf v1.36.1 // indirect +) diff --git a/harnesses/token-trade-coverage/go.sum b/harnesses/token-trade-coverage/go.sum new file mode 100644 index 00000000..c231b510 --- /dev/null +++ b/harnesses/token-trade-coverage/go.sum @@ -0,0 +1,32 @@ +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= +github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= +github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io= +github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk= +google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/harnesses/token-trade-coverage/scanner b/harnesses/token-trade-coverage/scanner new file mode 100755 index 00000000..1a16c449 Binary files /dev/null and b/harnesses/token-trade-coverage/scanner differ