Skip to content

fix(docs): correct Dune analytics SQL to the real Stellar event schema#97

Merged
0xdevcollins merged 1 commit into
testnetfrom
fix/dune-analytics-sql-decoding
Jul 23, 2026
Merged

fix(docs): correct Dune analytics SQL to the real Stellar event schema#97
0xdevcollins merged 1 commit into
testnetfrom
fix/dune-analytics-sql-decoding

Conversation

@0xdevcollins

Copy link
Copy Markdown
Collaborator

Follow-up to #80. The merged queries are syntactically valid but functionally broken — they return zero rows against Dune, so every dashboard panel renders empty. I verified this and the fix against live Dune data.

Root cause (verified on stellar.history_contract_events)

Two wrong assumptions, both silently returning null (no SQL error):

  1. Event name — queries used JSON_EXTRACT_SCALAR(topics_decoded, '$[0]'). The real value is an array of ScVal objects: [{"symbol":"EventCreated"}], so $[0] is an object → null → the = 'EventCreated' filter never matches.
  2. Fields — queries used flat data_decoded '$.id', '$.amount', etc. The real value is a type-wrapped ScVal map: {"map":[{"key":{"symbol":"id"},"val":{"u64":"7"}}, ...]}. There is no top-level $.id.

Fix (all 10 dune-queries/*.sql rewritten)

  • Event name via topics_decoded '$[0].symbol'.
  • Decode fields by rebuilding the map into MAP(field → ScVal JSON) with map_from_entries(transform(...)), then reading each by ScVal type ($.u64, $.i128, $.address, $.string, $.vec[0].symbol).
  • Added the closed_at_date partition filter (the queries previously full-scanned every Stellar contract event).
  • to_hex(transaction_hash) (it's varbinary).

Validation

Every primitive was executed against live Soroban events on Dune (map extraction, i128DECIMAL/DOUBLE, $.string, $.vec[0] path, to_hex) — all run clean and return correctly decoded values. The one field I can't verify without a real Boundless event — pillar's unit-enum encoding — is surfaced as pillar_raw in 10_event_created_decode_test.sql so it can be confirmed on the first live event and the path adjusted if needed.

Doc corrections (dune-analytics.md)

  • Rewrote the §1 decoding reference to the real schema + the map_from_entries recipe.
  • Corrected the fee accounting: escrow holds the full budget (fee charged on top, not deducted); fee revenue is not derivable from these events.
  • Added the 3 manager events from fix(events): require acceptance for manager delegation (#70) #88 (ManagerProposed, ManagerChanged, PendingManagerCancelled).
  • §4 now points at the canonical .sql files rather than duplicating (previously broken) SQL inline.

Docs-only. build now runs on docs PRs (from #80's workflow change), so CI gates this.

🤖 Generated with Claude Code

The queries merged in #80 return zero rows against Dune: they filtered on
JSON_EXTRACT_SCALAR(topics_decoded,'$[0]') (an ScVal object, never the
event name) and read data_decoded as flat $.field (it's a type-wrapped
ScVal map). Both silently yield null, so every dashboard panel is empty.

Verified the real stellar.history_contract_events shapes on live Dune data
and rewrote all 10 dune-queries/*.sql to:
- filter the event name via topics_decoded '$[0].symbol'
- decode fields by rebuilding data_decoded '$.map' into
  MAP(field -> ScVal JSON) with map_from_entries(), then reading each by
  ScVal type ($.u64, $.i128, $.address, $.string, $.vec[0].symbol)
- add the closed_at_date partition filter (avoids full-table scans)
- to_hex(transaction_hash) (it is varbinary)

Every primitive was executed against live Soroban events on Dune. The one
field that can't be checked without a real Boundless event — pillar's unit-
enum encoding — is emitted as pillar_raw in the decode test for confirmation.

Doc fixes: rewrote the §1 decoding reference; corrected the fee accounting
(escrow holds the full budget, fee charged on top; fee revenue is not in the
events); added the ManagerProposed/ManagerChanged/PendingManagerCancelled
events (#88); pointed §4 at the canonical .sql files instead of duplicating
now-corrected SQL inline.
@almanax-ai

almanax-ai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Quota reached

Your plan allows 300 CI/CD file units per month. You've used 297 and this scan would add 11 more (total: 308).

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@0xdevcollins, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2c8de6a9-d8f4-49ef-9e82-65f9d871c6a5

📥 Commits

Reviewing files that changed from the base of the PR and between 02153d4 and 52fbbaa.

📒 Files selected for processing (11)
  • docs/dune-analytics.md
  • docs/dune-queries/01_tvl_current.sql
  • docs/dune-queries/02_tvl_over_time.sql
  • docs/dune-queries/03_bounties_funded.sql
  • docs/dune-queries/04_total_payouts.sql
  • docs/dune-queries/05_unique_participants.sql
  • docs/dune-queries/06_event_outcomes.sql
  • docs/dune-queries/07_avg_size_and_ttp.sql
  • docs/dune-queries/08_payout_by_token.sql
  • docs/dune-queries/09_crowdfunding_contributions.sql
  • docs/dune-queries/10_event_created_decode_test.sql
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/dune-analytics-sql-decoding

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@0xdevcollins
0xdevcollins merged commit ba4e704 into testnet Jul 23, 2026
4 checks passed
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