"""crosscheck.py (Vonk, CC0): put Bazaar's own numbers next to the chain for every wallet onchain.py checked. Reads raw/bazaar_.json + raw/onchain_*.json (v2), writes crosscheck.json. No network. v2 (cycle 68): two chain counts, never mixed up. chain_inflows_* = every inbound USDC Transfer (funding and other sales included); chain_eip3009_* = only Transfers settled by EIP-3009 transferWithAuthorization, the shape of an x402 'exact' settlement. Only same-length windows are compared (Bazaar's counters are 30-day).""" import json, glob, pathlib HERE = pathlib.Path(__file__).parent baz = json.loads(sorted(HERE.glob("raw/bazaar_*.json"))[-1].read_text(encoding="utf-8")) out = [] for f in sorted(glob.glob(str(HERE / "raw" / "onchain_*.json"))): oc = json.loads(pathlib.Path(f).read_text(encoding="utf-8")) if oc.get("version", 1) < 2 or oc["days"] != 30: print("skip (v1 or not a 30-day window):", pathlib.Path(f).name) continue w = oc["wallet"].lower() seen, calls, best_payers, service = set(), 0, 0, None for it in baz["items"]: if it["resource"] in seen: continue if any((a.get("payTo") or "").lower() == w and a.get("network") == "eip155:8453" for a in it.get("accepts") or []): seen.add(it["resource"]) q = it.get("quality") or {} calls += q.get("l30DaysTotalCalls") or 0 best_payers = max(best_payers, q.get("l30DaysUniquePayers") or 0) service = service or it.get("service") i, e = oc["wallet_inflows"], oc["eip3009"] out.append({"wallet": w, "service": service, "bazaar_listings": len(seen), "bazaar_calls_30d": calls, "bazaar_best_listing_payers": best_payers, "bazaar_fetched_utc": baz.get("fetched_utc"), "chain_days": oc["days"], "chain_checked_utc": oc["checked_utc"], "chain_inflows_n": i["transfers_in"], "chain_inflows_usdc": i["usdc_in"], "chain_inflows_payers": i["distinct_payers"], "chain_eip3009_n": e["transfers_in"], "chain_eip3009_usdc": e["usdc_in"], "chain_eip3009_payers": e["distinct_payers"], "eip3009_share_of_inflows": oc["eip3009_share_of_inflows"], "eip3009_vs_bazaar": round(e["transfers_in"] / calls, 3) if calls else None, "chain_eip3009_over10_usd": e["amount_hist"].get(">10", 0), "submitter_sample": oc["submitter_sample"]["by_sender"]}) (HERE / "crosscheck.json").write_text(json.dumps(out, indent=1) + "\n", encoding="utf-8") for o in out: print({k: v for k, v in o.items() if k != "submitter_sample"})