From fb83c70d238b7d247a5f25217383f476b356cea3 Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 16 Mar 2026 15:50:19 +0000 Subject: [PATCH] fix: chore: fetch and cache Uniswap V3 replay datasets for evolution backtesting (#883) - Add fetch-datasets.sh wrapper that fetches HIGHER/WETH, DEGEN/WETH, and TOSHI/WETH 30-day event caches via fetch-events.ts; reads INFURA_API_KEY from env and fails with a helpful error if unset - Update .gitignore from cache/ (whole dir) to cache/*.jsonl so the pattern is precise to the generated data files; cache/ is already covered by the repo-root .gitignore via its own cache/ rule JSONL cache files are gitignored and must be generated locally by running ./fetch-datasets.sh with INFURA_API_KEY set. Co-Authored-By: Claude Sonnet 4.6 --- onchain/script/backtesting/.gitignore | 2 +- onchain/script/backtesting/fetch-datasets.sh | 53 ++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100755 onchain/script/backtesting/fetch-datasets.sh diff --git a/onchain/script/backtesting/.gitignore b/onchain/script/backtesting/.gitignore index 7663573..e6e14ec 100644 --- a/onchain/script/backtesting/.gitignore +++ b/onchain/script/backtesting/.gitignore @@ -1,2 +1,2 @@ # Cache files generated by fetch-events.ts at runtime — do not commit -cache/ +cache/*.jsonl diff --git a/onchain/script/backtesting/fetch-datasets.sh b/onchain/script/backtesting/fetch-datasets.sh new file mode 100755 index 0000000..c4a4ddc --- /dev/null +++ b/onchain/script/backtesting/fetch-datasets.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +# fetch-datasets.sh — Download and cache Uniswap V3 replay datasets for the +# evolution backtester. Re-running is safe: fetch-events.ts has resume support. +# +# Usage: +# INFURA_API_KEY= ./fetch-datasets.sh +# # or export the variable beforehand: +# export INFURA_API_KEY= +# ./fetch-datasets.sh +# +# Alternatively derive the key from BASE_RPC_URL: +# export INFURA_API_KEY=$(echo "$BASE_RPC_URL" | grep -oP '/v3/\K.*') + +set -euo pipefail + +: "${INFURA_API_KEY:?INFURA_API_KEY is required. Set it directly or derive from BASE_RPC_URL: export INFURA_API_KEY=\$(echo \"\$BASE_RPC_URL\" | grep -oP '/v3/\\K.*')}" + +export INFURA_API_KEY + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +cd "$SCRIPT_DIR" + +mkdir -p cache + +echo "=== Fetching HIGHER/WETH (last 30 days) ===" +npx tsx fetch-events.ts \ + --pool 0xCC28456d4Ff980CeE3457Ca809a257E52Cd9CDb0 \ + --days 30 \ + --output cache/higher-weth-30d.jsonl + +echo "=== Fetching DEGEN/WETH (last 30 days) ===" +npx tsx fetch-events.ts \ + --pool 0x0cA6485b7e9cF814A3Fd09d81672B07323535b64 \ + --days 30 \ + --output cache/degen-weth-30d.jsonl + +echo "=== Fetching TOSHI/WETH (last 30 days) ===" +npx tsx fetch-events.ts \ + --pool 0x4b0Aaf3EBb163dd45F663b38b6d93f6093EBC2d3 \ + --days 30 \ + --output cache/toshi-weth-30d.jsonl + +echo "" +echo "=== Done. Event counts: ===" +for f in cache/higher-weth-30d.jsonl cache/degen-weth-30d.jsonl cache/toshi-weth-30d.jsonl; do + if [ -f "$f" ]; then + count=$(wc -l < "$f") + echo " $f: $count events" + else + echo " $f: MISSING" + fi +done