Skip to content

[codex] Add Binance index-kline price feed E2E#758

Draft
ByteYue wants to merge 14 commits into
mainfrom
codex/sports-score-oracle-poc
Draft

[codex] Add Binance index-kline price feed E2E#758
ByteYue wants to merge 14 commits into
mainfrom
codex/sports-score-oracle-poc

Conversation

@ByteYue

@ByteYue ByteYue commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds an SDK E2E suite for the Gravity oracle price-feed rail using Binance USD-M indexPriceKlines semantics:

  • Bumps the gravity-reth dependency to the relayer-backed Binance continuous bucket PoC commit.
  • Replaces the old hype_price_feed suite with binance_price_feed.
  • Registers two continuous sourceType=3 tasks through governance:
    • feedId=1001: provider=binance_index_kline_v1&pair=NVDAUSDT&interval=1m&continuous=true.
    • feedId=1002: provider=binance_index_kline_v1&pair=TSLAUSDT&interval=1m&continuous=true.
  • Keeps the deterministic local mock as the default E2E path for byte-identical validator payloads.
  • Adds BINANCE_PRICE_FEED_MODE=live for manual demos that fetch Binance public indexPriceKlines closed 1-minute buckets directly.
  • Deploys MultiSourceOracleResolver, wires it as the NativeOracle default callback, waits for the short epoch to rebuild relayer-backed JWK observers, and verifies resolver writes.
  • Adds demo runner support with --keep-running and --demo-config-out, so the local chain can stay alive for a frontend demo after assertions pass.

How to run the deterministic E2E

Build the quick-release binaries, then run the suite:

make BINARY=gravity_node MODE=quick-release
make BINARY=gravity_cli MODE=quick-release
PATH="$HOME/.foundry/bin:$PWD/target/quick-release:$PATH" \
  ./gravity_e2e/run_test.sh binance_price_feed --force-init --log-cli-level=INFO

This mode starts a local deterministic /fapi/v1/indexPriceKlines mock and still makes the relayer use the Binance adapter request shape: pair, interval, startTime, endTime, and limit=1.

How to run the mock frontend demo backend

Use keep-running mode and write a frontend-readable runtime config:

PATH="$HOME/.foundry/bin:$PWD/target/quick-release:$PATH" \
  ./gravity_e2e/run_test.sh binance_price_feed \
    --force-init \
    --keep-running \
    --demo-config-out ../gravity_price_feed_demo_web/public/demo-config.json \
    --log-cli-level=INFO

Expected output includes:

Binance price feed resolved: feedId=1001 deliveryNonce=3 roundId=29720877 price=19612645000
Binance price feed resolved: feedId=1002 deliveryNonce=3 roundId=29720877 price=40117545000
Wrote price feed demo config to ../gravity_price_feed_demo_web/public/demo-config.json
PASSED
Suite binance_price_feed PASSED
All suites passed!
Demo keep-running mode enabled; cluster left running.

After that, the local Gravity RPC and deterministic Binance mock keep running. The web demo reads the generated config, proxies JSON-RPC through /rpc, and renders continuously updating resolver state.

Stop commands:

bash cluster/stop.sh --config gravity_e2e/cluster_test_cases/binance_price_feed/cluster.toml
kill "$(cat gravity_e2e/cluster_test_cases/binance_price_feed/artifacts/mock_binance.pid)"

How to run the live Binance demo backend

For a pure manual demo, set live mode:

BINANCE_PRICE_FEED_MODE=live \
BINANCE_PRICE_FEED_LAG_MINUTES=2 \
PATH="$HOME/.foundry/bin:$PWD/target/quick-release:$PATH" \
  ./gravity_e2e/run_test.sh binance_price_feed \
    --force-init \
    --keep-running \
    --demo-config-out ../gravity_price_feed_demo_web/public/demo-config.json \
    --log-cli-level=INFO

Live mode sends outbound requests to Binance public market-data APIs. It does not require BINANCE_API_KEY or BINANCE_SECRET_KEY.

At startup it computes a recent closed 1-minute bucket, generates a run-local relayer config, and registers matching task URIs such as:

GET https://fapi.binance.com/fapi/v1/indexPriceKlines
  ?pair=<NVDAUSDT|TSLAUSDT>
  &interval=1m
  &startTime=<closed bucket start>
  &endTime=<closed bucket end>
  &limit=1

In live mode, stop only the local cluster:

bash cluster/stop.sh --config gravity_e2e/cluster_test_cases/binance_price_feed/cluster.toml

Expected effect

Both mock and live modes exercise the same Gravity path:

relayer fetch -> canonical bytes -> unsupported-JWK consensus -> NativeOracle -> MultiSourceOracleResolver.priceRounds / latestPrice.

Mock mode asserts exact fixture prices. Live mode asserts the resolver shape and positive observed price because the source data is external market data.

How this helps build a Polymarket-like Gravity product

This suite covers the long-running epoch-config oracle path:

  • sourceType=3 can feed price/index markets or a demo PerpDex-style price board.
  • The existing Polymarket mock path covers sourceType=6-style settlement data.
  • Product contracts can consume resolver state to settle YES/NO, multi-outcome, or index-price markets.

It does not implement intra-epoch dynamic request discovery. A future dynamic watcher should scan finalized request events with watermarks/backfill, request expiry, typed Pending / Unknown / Expired states, retryable add_uri, and request/config/payload hashes in the signed object.

Verification

Ran successfully without live Binance traffic:

python3 -m py_compile gravity_e2e/runner.py gravity_e2e/cluster_test_cases/binance_price_feed/test_binance_price_feed.py gravity_e2e/cluster_test_cases/binance_price_feed/mock_binance.py gravity_e2e/cluster_test_cases/binance_price_feed/hooks.py
PYTHONPATH=gravity_e2e:. pytest --collect-only -q gravity_e2e/cluster_test_cases/binance_price_feed
python3 - <<'PY'
import importlib.util, json
from pathlib import Path
p = Path('gravity_e2e/cluster_test_cases/binance_price_feed/hooks.py')
spec = importlib.util.spec_from_file_location('hooks', p)
hooks = importlib.util.module_from_spec(spec)
spec.loader.exec_module(hooks)
env = {'BINANCE_PRICE_FEED_MODE': 'live', 'BINANCE_PRICE_FEED_LAG_MINUTES': '2'}
hooks.pre_deploy(p.parent, env, [])
config_path = Path(env['RELAYER_CONFIG_TPL'])
print(json.loads(config_path.read_text())['uri_mappings'].keys())
config_path.unlink()
PY
git diff --check

Previously verified the keep-running mock backend end-to-end:

PATH="$HOME/.foundry/bin:$PWD/target/quick-release:$PATH" \
  ./gravity_e2e/run_test.sh binance_price_feed \
    --force-init \
    --keep-running \
    --demo-config-out ../gravity_price_feed_demo_web/public/demo-config.json \
    --log-cli-level=INFO

Notes for reviewers:

  • The default E2E uses a local deterministic Binance mock, so validator consensus bytes remain deterministic and no live Binance traffic is required.
  • Live mode is intentionally manual/demo-only and uses public market-data endpoints.
  • Validator-local API keys and RPC URLs stay outside committed fixtures.

ByteYue added 7 commits June 23, 2026 22:41
Document and test a local-only Polymarket-style settlement flow for Gravity.

The polymarket_mock suite starts a local Polygon JSON-RPC mock, maps the configured oracle URI through relayer_config.json, drives the existing relayer plus unsupported-JWK/oracle consensus path into NativeOracle, and settles a match-market contract from the resolver result.

How to run:

  PATH="$CONDA_PREFIX/bin:$HOME/.foundry/bin:$PWD/target/quick-release:$PATH" ./gravity_e2e/run_test.sh polymarket_mock --force-init

Expected successful output includes Suite polymarket_mock PASSED and All suites passed. A verified local run passed with 1 test in about 128 seconds.

This proves the settlement rail first; dynamic Polymarket-like request discovery can be layered later with finalized request events, watermarks, deadlines, and typed pending/unknown/expired states.
@ByteYue ByteYue force-pushed the codex/sports-score-oracle-poc branch from 65d73c4 to 459ebc7 Compare June 28, 2026 14:47
Update the SDK lockfile to the gravity-reth oracle branch commit that includes sourceType=3 price feed support and the Hype/HIP-3 adapter.

Add a local hype_price_feed suite that registers deterministic NVDA/USD and GOOGL/USD price tasks, waits for the next short epoch so JWK observers rebuild relayer-backed providers, and verifies NativeOracle -> MultiSourceOracleResolver.latestPrice for feed IDs 1001 and 1002.

Document how to run the suite, the expected resolved prices, and how this epoch-config feed path can support Gravity price-index or Polymarket-like products without claiming intra-epoch dynamic request discovery.
@ByteYue ByteYue changed the title [codex] Add runnable Polymarket oracle mock E2E [codex] Add Hype price feed E2E Jun 30, 2026
ByteYue added 2 commits June 30, 2026 16:44
Switch the hype_price_feed suite from static observations to provider=hype URIs backed by a local deterministic /info mock. The relayer now runs the Hype/HIP-3 HTTP adapter for xyz:NVDA and xyz:GOOGL, publishes the canonical price bytes through the unsupported-JWK path, and the test verifies NativeOracle -> MultiSourceOracleResolver.latestPrice for feedIds 1001 and 1002.

Run with: PATH="$HOME/.foundry/bin:$PWD/target/quick-release:$PWD/target/release:$PATH" ./gravity_e2e/run_test.sh hype_price_feed --force-init. Expected effect: both feed IDs resolve round 1 prices and the suite ends with All suites passed.
Replace the previous Hype price feed suite with a continuous Binance index-kline PoC. The suite registers NVDAUSDT and TSLAUSDT sourceType=3 tasks, serves deterministic closed 1-minute klines from a local mock Binance endpoint, waits for delivery nonce 3, and verifies MultiSourceOracleResolver.priceRounds for roundId 29720877.

Verification: built gravity_cli and gravity_node with the local gravity-reth PoC branch; ran ./gravity_e2e/run_test.sh binance_price_feed --force-init --log-cli-level=INFO, which passed with both feeds resolved on-chain.
@ByteYue ByteYue changed the title [codex] Add Hype price feed E2E [codex] Add Binance index-kline price feed E2E Jul 7, 2026
ByteYue added 4 commits July 7, 2026 17:50
Add runner support for --keep-running and --demo-config-out so a successful suite can leave the local Gravity cluster alive for a frontend demo.

Extract the Binance index-kline mock into a reusable server, add binance_price_feed hooks that keep the mock alive in demo mode, and write frontend-readable runtime config after the resolver is deployed.

Verification: python3 -m py_compile for runner and Binance suite helpers; pytest --collect-only for binance_price_feed; ran binance_price_feed with --keep-running and confirmed the node, mock server, JSON-RPC, and resolver latestPrice remain available after runner exit.
Add a pre-deploy hook so the binance_price_feed suite can generate run-local relayer config for live Binance indexPriceKlines demos while keeping the deterministic mock path as the default E2E mode.

Live mode computes a recent closed one-minute bucket, registers matching sourceType=3 task URIs, validates resolver writes without fixed price assertions, and writes provider metadata for the demo frontend.

Verification: py_compile runner/hooks/test/mock; pytest --collect-only for binance_price_feed; generated live relayer config dry-run; git diff --check.
Add a Gravity oracle demo skill with the live Binance index-kline startup flow, including the testnet base URL fallback used when production Binance returns HTTP 451.

Document frontend demo wiring and clarify that the Polymarket mock E2E can back both direct binary mirrors and single-condition 3-way mirrors.
Add oracle_demo, a single local Gravity E2E suite that runs Binance index-kline price feeds and a Fed-style Polymarket binary mirror in the same cluster. The suite starts deterministic local Binance and Polygon mocks, registers sourceType=3 and sourceType=6 oracle paths, settles the binary market, and can emit one frontend demo-config.json.

Update the oracle demo skill with the combined startup command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant