Skip to content

feat: add Stratabook volume/fees adapter (Solana CLOB) - #8722

Merged
bheluga merged 11 commits into
DefiLlama:masterfrom
limeneris-beep:add-stratabook
Aug 13, 2026
Merged

feat: add Stratabook volume/fees adapter (Solana CLOB)#8722
bheluga merged 11 commits into
DefiLlama:masterfrom
limeneris-beep:add-stratabook

Conversation

@limeneris-beep

Copy link
Copy Markdown
Contributor

Adds the Stratabook volume, fees, and revenue adapter for Solana.

Protocol: Stratabook (Strata DEX) — fully on-chain CLOB on Solana with three execution layers, all settled by the same CLOB program strataZWURmW6bzMWpkLCAFxNFrQXCNSE9cSmBmdPgP:

  • L1 native orderbook fills (source 0)
  • L2 RFQ / MM-signed quotes (source 1)
  • L3 Sonar aggregator / AVL routed swaps (source 2, 4)

Volume: parsed from on-chain OrderFilled events (sol_log_data, 100-byte payload) — tag 3, fill_size at bytes 81-89, settle_price 89-97, source 97. Sum of base-side fill sizes, USD-priced by DefiLlama. No warehouse dependency.

Fees/Revenue: taker fee (Market.taker_fee_bps, read live from market accounts) on all fills; maker rebate ships 0 and is not paid; supply-side revenue 0 (no LP incentives).

Chain: Solana · Category: Dexs · Start: 2026-08-09 (first on-chain activity)

Methodology and full event layout documented in the adapter header comment.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Summary by CodeRabbit

  • New Features
    • Added support for tracking Solana Stratabook markets and successful trades.
    • Added hourly reporting for filled orders and base-token trading volume.
    • Added accurate token attribution while excluding ambiguous transactions.
    • Added taker fees, protocol revenue, and total revenue metrics.
    • Added market-specific fee rates with a fallback rate where needed.
    • Added methodology and fee/revenue breakdown details for Stratabook metrics.

Walkthrough

Adds a Dune-based Solana Stratabook adapter. It identifies successful CLOB fills, matches them to token transfers, aggregates base-token volume and taker fees by mint, and exports hourly fee and revenue metrics.

Changes

Stratabook Solana Dune integration

Layer / File(s) Summary
Dune query and fee model
dexs/stratabook/index.ts
Defines successful OrderFilled filtering, event decoding, market taker fees, transfer matching, ambiguous-match exclusion, and volume aggregation.
Balance aggregation
dexs/stratabook/index.ts
Processes Dune decimal values without JavaScript number conversion. Records volume, fees, revenue, and protocol revenue. Supply-side revenue remains zero.
Adapter configuration
dexs/stratabook/index.ts
Exports the hourly Solana SimpleAdapter with its start date, Dune dependency, classification, methodology, and fee/revenue breakdowns.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant StratabookAdapter
  participant Dune
  participant SolanaCLOB
  StratabookAdapter->>Dune: Submit the requested time-range query
  Dune->>SolanaCLOB: Read successful OrderFilled events and token transfers
  SolanaCLOB-->>Dune: Return fill, transfer, market, and mint data
  Dune-->>StratabookAdapter: Return grouped volume and fee rows
  StratabookAdapter->>StratabookAdapter: Create volume and revenue balances
Loading

Suggested labels: dexs, new-adapter, methodology

🚥 Pre-merge checks | ✅ 12 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title describes the adapter but does not follow the required '[type] protocol-name - description' format. Use a title such as '[feat] Stratabook - add Solana volume and fees adapter'.
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 50.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Dune Adapters Are Version 1 ⚠️ Warning The PR adds queryDuneSql while retaining version: 2 and pullHourly: true; its SQL also combines TIME_RANGE with a redundant tr.block_time date filter. Set the adapter to version: 1 and remove the explicit transfer date predicates, leaving TIME_RANGE as the query date filter.
✅ Passed checks (12 passed)
Check name Status Explanation
Description check ✅ Passed The description provides protocol scope, implementation details, methodology, chain, category, and start date, which is sufficient for this adapter PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Breakdown Methodology Check ✅ Passed All labeled .add() calls use "Swap Fees" or "Swap Fees To Protocol", and both labels appear under the matching breakdownMethodology sections on the exported adapter.
Income Statement Compliance ✅ Passed The adapter records each taker fee in dailyFees and dailyRevenue, records no supplier payments in dailySupplySideRevenue, and documents maker rebates as zero; thus dailyRevenue = dailyFees - 0.
Version 2 Required ✅ Passed The new Stratabook adapter exports version: 2 and uses pullHourly: true; its Dune query is not limited to daily aggregates.
Pullhourly Required For Version 2 ✅ Passed The new Stratabook adapter sets version: 2 and explicitly sets pullHourly: true at lines 204–206.
Income Statement Balance ✅ Passed Each positive fee is added to dailyFees, dailyRevenue, and dailyProtocolRevenue; dailySupplySideRevenue stays empty, matching the stated zero LP incentives, so fees balance.
Fetchoptions Usage ✅ Passed The adapter uses one FetchOptions parameter, uses options.startTimestamp/endTimestamp for hourly windows, uses options.createBalances(), and returns no timestamp field.
Adapter Shape ✅ Passed The adapter has one chain, CHAIN.SOLANA, with one shared start date and no per-chain configuration, matching the required simplest shape.
Efficiency And Error Handling ✅ Passed The adapter uses Dune SQL, not getLogs or API calls, and has no try/catch or allowNegativeValue; its CLOB address, fee map, and event offsets have source comments.
Methodology Keys ✅ Passed The Stratabook methodology object uses only permitted dimension keys: Volume, Fees, Revenue, ProtocolRevenue, and SupplySideRevenue; it has no daily* code-field keys.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
✨ Simplify code
  • Create PR with simplified code

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.

@github-actions

Copy link
Copy Markdown

The stratabook adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts dexs stratabook

🦙 Running STRATABOOK adapter 🦙
---------------------------------------------------
Start Date:	Mon, 10 Aug 2026 20:14:37 GMT
End Date:	Tue, 11 Aug 2026 20:14:37 GMT
---------------------------------------------------

SOLANA 👇
Backfill start time: 9/8/2026
Daily volume: 0.00
Daily fees: 0.00
Daily revenue: 0.00
Daily supply side revenue: 0.00
End timestamp: 1786479276 (2026-08-11T20:14:36.000Z)




FEES BREAKDOWN 👇

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dexs/stratabook/index.ts`:
- Around line 30-33: Correct the verification-date claim in the module
documentation near the market PDA account-layout description: replace the future
date with the actual completed verification date, or explicitly state that
verification is planned if it has not yet occurred.
- Around line 241-244: Update the log-processing loop around EVENT_ORDER_FILLED
to track Solana program invocation context, activating decoding only after a log
entry invokes CLOB_PROGRAM and suspending it when that invocation ends. Require
the context to be active before decoding any “Program data:” payload, while
preserving the existing length and event-tag checks.
- Around line 202-203: Prevent incomplete collection from producing balances in
the Stratabook adapter: at dexs/stratabook/index.ts lines 202-203, do not return
balances when the scan reaches MAX_SIGS_PER_RUN before exhausting the historical
window; at lines 176-178, rethrow persistent transaction-retrieval failures
instead of appending null or omitting transactions; at lines 192-193, treat an
empty market result as unavailable or invalid unless the adapter can prove no
markets existed.
- Around line 268-275: Update the SimpleAdapter configuration in the adapter
declaration to use the version 2 root shape: set pullHourly: true explicitly and
move chains, start, and fetch to the root level, using a shared chains array
containing CHAIN.SOLANA. Preserve the existing start date and fetch
implementation.
- Around line 220-223: Update the transaction filter in the loop over txs to
skip any transaction whose tx.meta.err is set, before accessing accounts or
parsing logs. Preserve the existing metadata, blockTime, and time-range checks
for transactions without errors.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 89b0f106-1404-445e-8f5f-43ce2fc6bdb9

📥 Commits

Reviewing files that changed from the base of the PR and between c5df4ff and 02988bd.

📒 Files selected for processing (1)
  • dexs/stratabook/index.ts

Comment thread dexs/stratabook/index.ts Outdated
Comment thread dexs/stratabook/index.ts Outdated
Comment thread dexs/stratabook/index.ts Outdated
Comment thread dexs/stratabook/index.ts Outdated
Comment thread dexs/stratabook/index.ts Outdated
…CLOB invocation context, completeness guards
@limeneris-beep

Copy link
Copy Markdown
Contributor Author

Addressed all 5 CodeRabbit comments:

  1. Header date — removed the future verification date; now says 'verified against live mainnet accounts'.
  2. Incomplete collection — (a) sequential-fallback now rethrows persistent RPC errors instead of appending null; (b) throws if MAX_SIGS_PER_RUN caps the scan before the historical window is exhausted (no partial data); (c) empty market result now throws instead of returning zeros.
  3. Failed txs — skip txs with tx.meta.err before parsing logs.
  4. Invocation context — 'Program data:' payloads are only decoded while the CLOB program invocation is active (invoke/success/failed tracking), so non-Stratabook events can't be counted.
  5. v2 shape — pullHourly: true, chains/start/fetch moved to root.

Validated: adapter test passes, ts-check passes, and a direct fetch over Aug 9-10 decodes the real 8 fills (fees = 10bps taker on volume).

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
dexs/stratabook/index.ts (1)

186-190: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Report retained fees as dailyProtocolRevenue.

The adapter adds every taker fee to dailyRevenue. It reports zero dailySupplySideRevenue. Therefore, the same amount is protocol revenue.

Create, populate, and return dailyProtocolRevenue. Add the matching ProtocolRevenue methodology entry.

Proposed fix
   const dailyFees = createBalances();
   const dailyRevenue = createBalances();
+  const dailyProtocolRevenue = createBalances();
   const dailySupplySideRevenue = createBalances();

   dailyFees.add(market.baseMint, takerFee.toString());
   dailyRevenue.add(market.baseMint, takerFee.toString());
+  dailyProtocolRevenue.add(market.baseMint, takerFee.toString());

-  return { dailyVolume, dailyFees, dailyRevenue, dailySupplySideRevenue };
+  return { dailyVolume, dailyFees, dailyRevenue, dailyProtocolRevenue, dailySupplySideRevenue };

As per coding guidelines, “Flag missing supply-side deductions, missing protocol/holder splits.”

Also applies to: 261-262, 279-279

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dexs/stratabook/index.ts` around lines 186 - 190, Update the adapter’s daily
fee accounting to introduce and populate dailyProtocolRevenue alongside
dailyRevenue, assigning retained taker fees to protocol revenue while leaving
dailySupplySideRevenue at zero. Return dailyProtocolRevenue from the adapter and
add the corresponding ProtocolRevenue methodology entry, including the related
logic at the other indicated fee-processing locations.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dexs/stratabook/index.ts`:
- Around line 241-248: Replace the boolean inClobInvoke tracking around the
transaction log loop with an invocation stack that pushes every Program <id>
invoke record and pops the matching completion record. Decode Program data
payloads only when CLOB_PROGRAM is the current stack top, preventing nested
program events from being counted while preserving CLOB event handling.

---

Outside diff comments:
In `@dexs/stratabook/index.ts`:
- Around line 186-190: Update the adapter’s daily fee accounting to introduce
and populate dailyProtocolRevenue alongside dailyRevenue, assigning retained
taker fees to protocol revenue while leaving dailySupplySideRevenue at zero.
Return dailyProtocolRevenue from the adapter and add the corresponding
ProtocolRevenue methodology entry, including the related logic at the other
indicated fee-processing locations.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 617dad38-de07-4dea-b3b8-7328c083c23d

📥 Commits

Reviewing files that changed from the base of the PR and between 02988bd and 2face8e.

📒 Files selected for processing (1)
  • dexs/stratabook/index.ts

Comment thread dexs/stratabook/index.ts Outdated
@github-actions

Copy link
Copy Markdown

The stratabook adapter exports:

====== TOTAL DAILY AGGREGATED (sum of slots per chain) ======

SOLANA 👇
End timestamp: 1786481999 (2026-08-11T20:59:59.000Z)
Daily volume: 0.00
Daily fees: 0.00
Daily revenue: 0.00
Daily supply side revenue: 0.00




FEES BREAKDOWN 👇

@limeneris-beep

Copy link
Copy Markdown
Contributor Author

Addressed both new comments:

  1. Invocation stack — replaced the boolean with a proper invocation stack (push on 'Program X invoke [N]', pop on success/failed, decode 'Program data:' only when CLOB_PROGRAM is stack top). Verified against real fill txs: CLOB CPI-invokes LBUZKh/TokenzQd mid-invocation and its own OrderFilled event fires after those nested invocations complete, so stack-top decoding is correct and nested program events can't be counted.

  2. dailyProtocolRevenue — taker fees are 100% protocol-retained (supply-side = 0), so dailyProtocolRevenue now mirrors dailyFees/dailyRevenue, with matching ProtocolRevenue methodology + breakdown entries.

Validated: ts-check passes, adapter test passes, direct fetch over Aug 9-10 decodes the real fills with fees = 10bps taker and protocolRevenue = revenue.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dexs/stratabook/index.ts`:
- Around line 273-275: Update the fee writes in the daily fee processing flow so
dailyFees uses the “Swap Fees” label, while dailyRevenue and
dailyProtocolRevenue use “Swap Fees To Protocol”; declare both labels under
their corresponding breakdownMethodology keys and preserve the existing
market.baseMint and takerFee values.
- Around line 269-275: Update the three Balances.add calls for takerFee in the
fee-accounting block to pass "swap fees" as their third argument: dailyFees,
dailyRevenue, and dailyProtocolRevenue. Preserve the existing mint and fee
amount arguments.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 57db4ada-5f5b-43b5-ab7d-c219c7cceb45

📥 Commits

Reviewing files that changed from the base of the PR and between 2face8e and 11fabd2.

📒 Files selected for processing (1)
  • dexs/stratabook/index.ts

Comment thread dexs/stratabook/index.ts Outdated
Comment thread dexs/stratabook/index.ts Outdated
@github-actions

Copy link
Copy Markdown

The stratabook adapter exports:

====== TOTAL DAILY AGGREGATED (sum of slots per chain) ======

SOLANA 👇
End timestamp: 1786485599 (2026-08-11T21:59:59.000Z)
Daily volume: 0.00
Daily fees: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
Daily supply side revenue: 0.00




FEES BREAKDOWN 👇

@limeneris-beep

Copy link
Copy Markdown
Contributor Author

Addressed both comments — the fee calls now pass breakdown labels:

and declares the matching labels (Swap Fees / Swap Fees To Protocol) under Fees, Revenue, and ProtocolRevenue. ts-check passes locally; direct fetch over the live window still decodes fills correctly.

@limeneris-beep

Copy link
Copy Markdown
Contributor Author

Addressed both comments — the fee .add() calls now pass breakdown labels:

  • dailyFees.add(mint, amount, "Swap Fees")
  • dailyRevenue.add(mint, amount, "Swap Fees To Protocol")
  • dailyProtocolRevenue.add(mint, amount, "Swap Fees To Protocol")

and breakdownMethodology declares the matching labels (Swap Fees / Swap Fees To Protocol) under Fees, Revenue, and ProtocolRevenue. ts-check passes locally; direct fetch over the live window still decodes fills correctly.

@github-actions

Copy link
Copy Markdown

The stratabook adapter exports:

====== TOTAL DAILY AGGREGATED (sum of slots per chain) ======

SOLANA 👇
End timestamp: 1786485599 (2026-08-11T21:59:59.000Z)
Daily volume: 0.00
Daily fees: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
Daily supply side revenue: 0.00




FEES BREAKDOWN 👇

@limeneris-beep

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot removed the dexs label Aug 12, 2026
@limeneris-beep

Copy link
Copy Markdown
Contributor Author

@coderabbitai approve

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Comments resolved and changes approved.

@limeneris-beep

Copy link
Copy Markdown
Contributor Author

All checks green, CodeRabbit approved. Ready for review/merge — Stratabook volume + fees adapter for the new Solana CLOB. Thanks @g1nt0ki @0xngmi!

@bheluga bheluga self-assigned this Aug 12, 2026
@bheluga

bheluga commented Aug 12, 2026

Copy link
Copy Markdown
Member

@limeneris-beep thanks for the PR
Can you try to use dune/allium queries instead, preferable over solana rpc

@limeneris-beep

Copy link
Copy Markdown
Contributor Author

Done — adapter now sources volume + fees entirely from Dune Analytics, zero Solana RPC calls. Thanks for the review @bheluga!

What changed

Data source: solana.instruction_calls (raw per-instruction log messages, same table whales-market / futarchy-amm / solfi-v2 use) instead of getSignaturesForAddress + getTransaction RPC scanning.

Volume: each Program data: OrderFilled event (tag 3 → base64 prefix Aw==, 100-byte payload) is decoded in SQL — fill_size u64 LE at byte 81 — and the base-side token transfer is matched via tokens_solana.transfers (verified 1:1: transfer amount == fill_size on live mainnet fills), so each fill is attributed to its base mint. Batch settles count each fill once.

Fees: taker fee = fill_size × Market.taker_fee_bps, computed in SQL.

One honest caveat on fees

I verified the fee rate is not uniform: the 9 live markets carry taker_fee_bps of 5 or 10 bps (read from market account data on 2026-08-12). Dune does not index market account config for this program (it's 3 days old, no Allium decoder either), so the adapter embeds the per-market fee map with a documented maintenance note. Volume itself is fully event-derived and needs no such map.

  • If you'd prefer, I can switch the volume side to Allium solana.dex.trades — but Stratabook isn't in Allium's decoded project set yet, so that would return 0 until Allium adds a decoder. Dune's raw instruction_calls is the only query-engine path that has live data today.
  • Happy to adjust the fee approach if the repo has a preferred pattern for market-config-dependent fees on non-decoded programs.

ts-check + adapter test pass; CI re-running now.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions

Copy link
Copy Markdown

The stratabook adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts dexs stratabook

🦙 Running STRATABOOK adapter 🦙
---------------------------------------------------
Start Date:	Tue, 11 Aug 2026 16:00:00 GMT
End Date:	Wed, 12 Aug 2026 16:00:00 GMT
---------------------------------------------------

------ ERROR ------
Error: DUNE_API_KEYS environment variable is not set
    at getAxiosDune (/home/runner/work/dimension-adapters/dimension-adapters/helpers/dune.ts:17:11)
    at submitQuery (/home/runner/work/dimension-adapters/dimension-adapters/helpers/dune.ts:81:33)
DUNE_API_KEYS environment variable is not set

@coderabbitai coderabbitai Bot removed the dexs label Aug 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
dexs/stratabook/index.ts (1)

103-116: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Restrict event decoding to the active CLOB invocation.

fills accepts every matching payload in s.log_messages. A CLOB instruction can execute nested programs. A nested program can emit a tag-3 payload that this query parses as an OrderFilled event. The query then attributes that payload to CLOB accounts and transfers. This can inflate volume, fees, and revenue.

Parse the ordered invocation logs and decode payloads only when CLOB_PROGRAM is the invocation-stack top. Use an emitter-specific Dune field if one exists. This reintroduces the previously resolved invocation-context issue after the Dune migration. Dune documents that log_messages contains logs emitted during an instruction’s execution. (dune.mintlify.app)

As per path instructions, review DEX adapters for “Volume calculation accuracy.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dexs/stratabook/index.ts` around lines 103 - 116, Update the fills CTE in the
Stratabook query to decode tag-3 payloads only when the ordered invocation logs
identify CLOB_PROGRAM as the active invocation-stack top, using Dune’s
emitter-specific field if available. Do not treat every matching entry in
s.log_messages as a CLOB event; preserve attribution only for payloads emitted
by the active CLOB invocation.

Sources: Path instructions, MCP tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@dexs/stratabook/index.ts`:
- Around line 103-116: Update the fills CTE in the Stratabook query to decode
tag-3 payloads only when the ordered invocation logs identify CLOB_PROGRAM as
the active invocation-stack top, using Dune’s emitter-specific field if
available. Do not treat every matching entry in s.log_messages as a CLOB event;
preserve attribution only for payloads emitted by the active CLOB invocation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 396582a6-32db-44cd-b5dd-2d9d52f17a39

📥 Commits

Reviewing files that changed from the base of the PR and between 900be83 and fc9b89c.

📒 Files selected for processing (1)
  • dexs/stratabook/index.ts

…ads)

A CLOB instruction's log_messages includes nested program logs. The CLOB's
own OrderFilled fires after all nested invocations complete, so it is the
last 'Program data:' line in the instruction's log slice. Count remaining
Program-data lines per log line (ROWS BETWEEN CURRENT ROW AND UNBOUNDED
FOLLOWING) and decode only lines with exactly one remaining — nested
programs' tag-3 payloads are rejected instead of miscounted as fills.
@limeneris-beep

Copy link
Copy Markdown
Contributor Author

Addressed the emitter-binding finding (commit 89325d6): the fills CTE now decodes only the CLOB program's own event. Since the CLOB's OrderFilled fires AFTER all nested CPI invocations complete (verified on live mainnet fills), it is always the LAST Program data: line in the instruction's log slice. The query counts remaining Program-data lines per log line (window ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING, partitioned per instruction) and only decodes lines with exactly one remaining — nested programs' tag-3 100-byte payloads are rejected instead of being miscounted as fills.

Validated locally: sqlglot Trino-dialect parse + column resolution against the Dune schema for both tables, plus a functional simulation of the window logic (nested tag-3 payload REJECTED, CLOB OrderFilled ACCEPTED). ts-check passes.

Current state of the query: outer_instruction_index everywhere (the schema column that exists), per-fill fee CTE with contains(), exact DECIMAL(38,0) math, instruction-correlated mint mapping, emitter binding. If your run still errors, paste the Dune execution error text here and I'll fix whatever's left.

@limeneris-beep

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions

Copy link
Copy Markdown

The stratabook adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts dexs stratabook

🦙 Running STRATABOOK adapter 🦙
---------------------------------------------------
Start Date:	Tue, 11 Aug 2026 16:00:00 GMT
End Date:	Wed, 12 Aug 2026 16:00:00 GMT
---------------------------------------------------

------ ERROR ------
Error: DUNE_API_KEYS environment variable is not set
    at getAxiosDune (/home/runner/work/dimension-adapters/dimension-adapters/helpers/dune.ts:17:11)
    at submitQuery (/home/runner/work/dimension-adapters/dimension-adapters/helpers/dune.ts:81:33)
DUNE_API_KEYS environment variable is not set

@bheluga

bheluga commented Aug 12, 2026

Copy link
Copy Markdown
Member

@limeneris-beep it still seems to fail
image

@coderabbitai coderabbitai Bot added the dexs label Aug 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dexs/stratabook/index.ts`:
- Line 123: Update the fill_size expression in the query to use
varbinary_to_uint256 on the reversed eight-byte payload instead of
from_big_endian_64, preserving the existing base64 decoding, substring
extraction, and decimal cast so the little-endian u64 is interpreted as
unsigned.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: eafbe3de-2784-4f1d-aa18-6c0f5cd57518

📥 Commits

Reviewing files that changed from the base of the PR and between fc9b89c and 89325d6.

📒 Files selected for processing (1)
  • dexs/stratabook/index.ts

Comment thread dexs/stratabook/index.ts Outdated
from_big_endian_64 returns a signed BIGINT; a u64 fill_size above 2^63-1
would wrap negative. varbinary_to_uint256 (DuneSQL) interprets the 8-byte
little-endian payload as unsigned big-endian, then the DECIMAL(38,0) cast
preserves exact magnitude.
@limeneris-beep

Copy link
Copy Markdown
Contributor Author

Addressed the fill_size sign finding (commit 66bd86e): the decode now uses varbinary_to_uint256 (DuneSQL) on the reversed 8-byte payload instead of from_big_endian_64 — the u64 fill_size is interpreted as unsigned, so fills above 2^63-1 can't wrap negative. Same DECIMAL(38,0) cast afterwards, so exact magnitude is preserved.

Validated: sqlglot Trino-dialect parse + column resolution passes, ts-check passes.

@limeneris-beep

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions

Copy link
Copy Markdown

The stratabook adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts dexs stratabook

🦙 Running STRATABOOK adapter 🦙
---------------------------------------------------
Start Date:	Tue, 11 Aug 2026 17:00:00 GMT
End Date:	Wed, 12 Aug 2026 17:00:00 GMT
---------------------------------------------------

------ ERROR ------
Error: DUNE_API_KEYS environment variable is not set
    at getAxiosDune (/home/runner/work/dimension-adapters/dimension-adapters/helpers/dune.ts:17:11)
    at submitQuery (/home/runner/work/dimension-adapters/dimension-adapters/helpers/dune.ts:81:33)
DUNE_API_KEYS environment variable is not set

…base64 character'

Dune's log_messages can contain 'Program data:' lines that are NOT valid
base64 (programs can log arbitrary text with that prefix; control chars
survive into the stored array). Trino's from_base64 is strict and throws,
killing the whole query — Node's Buffer tolerated it silently, which is why
local RPC-log testing missed it. Decode once via try(from_base64(...))
(NULL on invalid input), filter on payload IS NOT NULL, and count only
decodable lines for the emitter-binding window.
@limeneris-beep

Copy link
Copy Markdown
Contributor Author

Fixed — the screenshot gave it away. The query was dying on Illegal base64 character 20 — not a column name (that was a separate earlier bug, already fixed).

Root cause: Dune's log_messages contains Program data: lines that are not valid base64 — a program can log arbitrary text with that prefix, and control characters survive into the stored array. Trino's from_base64 is strict and throws on the first invalid character, killing the whole query. (My earlier local validation used RPC logs + Node's Buffer.from, which silently tolerates invalid chars — that's why I didn't catch it; your run is the first one through Trino's strict decoder.)

Fix (commit 6260d2f): decode defensively — try(from_base64(SUBSTR(msg,15))) returns NULL on invalid input instead of throwing; rows whose payload doesn't decode are filtered out (payload IS NOT NULL) before the tag/length checks. The emitter-binding window now counts only decodable Program-data lines. The real OrderFilled events (valid base64, tag 3, 100 bytes) are unaffected.

Validated:

  • sqlglot Trino-dialect parse + column resolution ✅
  • Functional simulation of the exact failure: a Program data: text line with a control char makes strict from_base64 throw Illegal base64 character, try() returns NULL, and the CLOB's own OrderFilled is still the only accepted line ✅
  • ts-check ✅

Please re-run when you get a chance — if anything else surfaces, the Dune execution ID from the error (01KZVQ0A1JE9VTF3AMTRYW75DG) or the error text will pinpoint it.

@limeneris-beep

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions

Copy link
Copy Markdown

The stratabook adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts dexs stratabook

🦙 Running STRATABOOK adapter 🦙
---------------------------------------------------
Start Date:	Tue, 11 Aug 2026 17:00:00 GMT
End Date:	Wed, 12 Aug 2026 17:00:00 GMT
---------------------------------------------------

------ ERROR ------
Error: DUNE_API_KEYS environment variable is not set
    at getAxiosDune (/home/runner/work/dimension-adapters/dimension-adapters/helpers/dune.ts:17:11)
    at submitQuery (/home/runner/work/dimension-adapters/dimension-adapters/helpers/dune.ts:81:33)
DUNE_API_KEYS environment variable is not set

@limeneris-beep

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions

Copy link
Copy Markdown

The stratabook adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts dexs stratabook

🦙 Running STRATABOOK adapter 🦙
---------------------------------------------------
Start Date:	Wed, 12 Aug 2026 00:00:00 GMT
End Date:	Thu, 13 Aug 2026 00:00:00 GMT
---------------------------------------------------

------ ERROR ------
Error: DUNE_API_KEYS environment variable is not set
    at getAxiosDune (/home/runner/work/dimension-adapters/dimension-adapters/helpers/dune.ts:17:11)
    at submitQuery (/home/runner/work/dimension-adapters/dimension-adapters/helpers/dune.ts:81:33)
DUNE_API_KEYS environment variable is not set

@bheluga
bheluga merged commit ca513fa into DefiLlama:master Aug 13, 2026
2 of 3 checks passed
@bheluga

bheluga commented Aug 13, 2026

Copy link
Copy Markdown
Member

@limeneris-beep thanks for the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants