Skip to content

track txflow perps oi, fees and volume#6390

Draft
bheluga wants to merge 2 commits intomasterfrom
txflow-perps
Draft

track txflow perps oi, fees and volume#6390
bheluga wants to merge 2 commits intomasterfrom
txflow-perps

Conversation

@bheluga
Copy link
Copy Markdown
Member

@bheluga bheluga commented Apr 14, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 14, 2026

Walkthrough

This PR adds support for the TxFlow chain by introducing a new chain identifier and two corresponding adapters: one for daily trading metrics (volume and fees) and another for hourly open-interest data, both sourcing from Dune SQL.

Changes

Cohort / File(s) Summary
Chain Definition
helpers/chains.ts
Added TXFLOW = "txflow" enum member to extend supported chain identifiers.
TxFlow Adapters
dexs/txflow-perps/index.ts, open-interest/txflow-perps-oi.ts
Implemented two new adapters for TxFlow: one fetches daily volume and fees from dune.txflow_mainnet.platform_daily_trades, splitting fees into maker/taker proportions; the other fetches hourly open interest from dune.txflow_mainnet.platform_hourly_oi. Both mark the adapter as expensive and require Dune dependency.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

dexs, new-adapter, helper

🚥 Pre-merge checks | ❌ 6

❌ Failed checks (6 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is incomplete, providing only a website URL without filling in the required template sections for new protocol listings. Complete the template by filling in relevant sections such as Name, Chain, Website Link, Short Description, and other applicable protocol metadata fields.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 50.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Breakdown Methodology Check ⚠️ Warning The adapter uses breakdown labels 'Maker Fees' and 'Taker Fees' in .add() calls, but breakdownMethodology is not exported in the adapter object. Add breakdownMethodology object with entries for 'Maker Fees' and 'Taker Fees' to the exported adapter configuration.
Income Statement Compliance ⚠️ Warning The adapter returns dailyFees but is missing required fields dailyRevenue and dailySupplySideRevenue as specified in fees/GUIDELINES.md. Add dailyRevenue: dailyFees and dailySupplySideRevenue: options.createBalances() to the return statement to comply with income statement structure requirements.
Version 2 Required ⚠️ Warning Both new adapters (dexs/txflow-perps/index.ts and open-interest/txflow-perps-oi.ts) are missing the required version: 2 property in their adapter configuration objects. Add version: 2, to the adapter configuration objects in both files to align with codebase pattern and version 2 specification requirements.
Title check ⚠️ Warning The title 'track txflow perps oi, fees and volume' is descriptive and accurately summarizes the main changes (adding adapters for open interest, fees, and volume tracking for TxFlow perps), but does not follow the required format of [type] protocol-name - description. Reformat the title to follow the pattern '[type] protocol-name - description', such as '[feature] txflow-perps - track open interest, fees, and volume'.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch txflow-perps

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 and usage tips.

@github-actions
Copy link
Copy Markdown

The txflow-perps adapter exports:

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

🦙 Running TXFLOW-PERPS adapter 🦙
---------------------------------------------------
Start Date:	Mon, 13 Apr 2026 00:00:00 GMT
End Date:	Tue, 14 Apr 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:75:33)
DUNE_API_KEYS environment variable is not set

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In `@dexs/txflow-perps/index.ts`:
- Line 5: The fetch function currently uses the deprecated signature async
function fetch(_a: any, _b: any, options: FetchOptions) — update it to the
Version 2 adapter signature async function fetch(options: FetchOptions) by
removing the unused _a and _b parameters, update any internal references to use
options directly, and ensure the function conforms to Dune v2 adapter
expectations (keep the function name fetch and type FetchOptions).
- Around line 29-33: dailyUserFees is set to the same Balances object as
dailyFees (dailyUserFees: dailyFees), which can cause shared-mutation bugs;
update the return to create an explicit copy by using dailyUserFees:
dailyFees.clone() (or the Balances clone method used elsewhere) so dailyFees and
dailyUserFees are independent objects and consistent with helpers like
uniswap.ts.

In `@open-interest/txflow-perps-oi.ts`:
- Around line 1-4: The imports are split for types from the same module;
consolidate by importing Dependencies together with FetchOptions and
SimpleAdapter from "../adapters/types" (update the import containing
FetchOptions and SimpleAdapter to also include Dependencies) and remove the
separate import of Dependencies so only a single import statement for those
three types remains.
- Line 6: The fetch function currently uses unnamed placeholders (_a, _b) and
must adopt the V2 adapter signature: change the declaration async function
fetch(_a: any, _b: any, options: FetchOptions) to a clear V2 signature such as
async function fetch(timestamp: number, chainBlocks: any, options: FetchOptions)
(keeping the existing FetchOptions type), then update any internal references
accordingly to use timestamp and chainBlocks instead of _a/_b; the function name
fetch and the FetchOptions type are the key symbols to adjust.
- Around line 7-14: The Dune SQL comparison uses a raw integer timestamp so
update the duneQuery string (the duneQuery constant that references
options.startOfDay) to convert the epoch to a Dune timestamp using
from_unixtime(${options.startOfDay}) in the WHERE clause (instead of hour_ts =
${options.startOfDay}); also enable hourly pulls by adding pullHourly: true to
the adapter configuration object exported in this module so the source supports
hourly granularity.
🪄 Autofix (Beta)

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

Run ID: caa6978f-3c3e-408a-bfb0-83fdd45924a9

📥 Commits

Reviewing files that changed from the base of the PR and between 3c27c78 and 24c53ce.

📒 Files selected for processing (3)
  • dexs/txflow-perps/index.ts
  • helpers/chains.ts
  • open-interest/txflow-perps-oi.ts

import { CHAIN } from "../../helpers/chains";
import { queryDuneSql } from "../../helpers/dune";

async function fetch(_a: any, _b: any, options: FetchOptions) {
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot Apr 14, 2026

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Use Version 2 adapter signature.

The function uses the deprecated (_a: any, _b: any, options: FetchOptions) signature. Per guidelines, prefer the Version 2 signature (options: FetchOptions) for Dune queries.

♻️ Proposed fix
-async function fetch(_a: any, _b: any, options: FetchOptions) {
+async function fetch(options: FetchOptions) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async function fetch(_a: any, _b: any, options: FetchOptions) {
async function fetch(options: FetchOptions) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dexs/txflow-perps/index.ts` at line 5, The fetch function currently uses the
deprecated signature async function fetch(_a: any, _b: any, options:
FetchOptions) — update it to the Version 2 adapter signature async function
fetch(options: FetchOptions) by removing the unused _a and _b parameters, update
any internal references to use options directly, and ensure the function
conforms to Dune v2 adapter expectations (keep the function name fetch and type
FetchOptions).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

dune queries would have version 1 , they would be run once a day as they are expensive, remember for future

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.

@bheluga, thanks for the clarification! I've noted this for future reviews — expensive Dune query adapters intentionally use the Version 1 signature (_a: any, _b: any, options: FetchOptions) since they run once a day, and the Version 2 signature recommendation does not apply to them.


✏️ Learnings added
Learnt from: bheluga
Repo: DefiLlama/dimension-adapters PR: 6390
File: dexs/txflow-perps/index.ts:5-5
Timestamp: 2026-04-14T11:10:46.769Z
Learning: Applies to dexs/**/*.ts and open-interest/**/*.ts: Expensive Dune query adapters (marked with `isExpensiveAdapter: true` and `dependencies: [Dependencies.DUNE]`) intentionally use the Version 1 adapter signature `async function fetch(_a: any, _b: any, options: FetchOptions)` because they run once a day. Do NOT flag this as deprecated or suggest switching to the Version 2 `(options: FetchOptions)` signature for such adapters.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: GUIDELINES.md:0-0
Timestamp: 2026-04-03T10:25:08.836Z
Learning: Applies to adapters/**/*.ts : Use Adapter Version 2 with `(options: FetchOptions)` signature for on-chain logs, contract calls, subgraphs, and Dune queries with timestamp filters. Support arbitrary start/end timestamps and `pullHourly` option. Prefer Version 2 over Version 1

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: dexs/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:25.918Z
Learning: Applies to dexs/**/*.ts : Prioritize on-chain event logs, then subgraphs, then query engines (Dune, Flipside, Allium), and use protocol APIs as a last resort for data sources in DEX adapters

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: aggregators/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:05.173Z
Learning: Applies to aggregators/**/*.ts : Track all chains the aggregator operates on in the adapter implementation

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: dexs/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:25.918Z
Learning: Applies to dexs/**/*.ts : Use options.getLogs() for on-chain event logs as the most reliable data source for DEX adapters

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: options/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:07:11.033Z
Learning: Applies to options/**/*.{ts,js} : Use query engines for complex options analysis as a data source

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: aggregator-options/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:05:54.952Z
Learning: Applies to aggregator-options/**/*.{ts,tsx,js,jsx} : Avoid double-counting with underlying options protocol adapters when aggregating options data

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: options/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:07:11.033Z
Learning: Applies to options/**/*.{ts,js} : Use protocol subgraphs as a data source for historical options data

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: aggregators/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:05.173Z
Learning: Applies to aggregators/**/*.ts : Use aggregator APIs as an alternative data source when on-chain tracking is complex

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: aggregators/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:05.173Z
Learning: Applies to aggregators/**/*.ts : Use query engines for cross-DEX aggregation analysis when needed

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: aggregator-derivatives/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:05:47.814Z
Learning: Applies to aggregator-derivatives/**/*.{js,ts,tsx} : Use Protocol APIs as a data source when on-chain tracking of aggregator volume is complex

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: coderabbit-custom-pre-merge-checks-unique-id-file-non-traceable-F7F2B60C-1728-4C9A-8889-4F2235E186CA.txt:0-0
Timestamp: 2026-03-30T12:07:15.631Z
Learning: Applies to **/*adapter*.{ts,js} : New adapters must use version: 2 format. Check that the adapter exports version: 2 unless it's updating an existing v1 adapter.

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: fees/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:41.566Z
Learning: Applies to fees/**/*.ts : Include `dailyFees` dimension in fees adapters - maps to Gross Protocol Revenue and should include all fees from all sources (total value flow into protocol ecosystem)

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: dexs/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:25.918Z
Learning: Applies to dexs/**/*.ts : Track dailyFees, dailyRevenue, and dailySupplySideRevenue dimensions with appropriate breakdown labels and breakdownMethodology when tracking fees/revenue in DEX adapters

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: coderabbit-custom-pre-merge-checks-unique-id-file-non-traceable-F7F2B60C-1728-4C9A-8889-4F2235E186CA.txt:0-0
Timestamp: 2026-03-30T12:07:15.631Z
Learning: Applies to **/*adapter*.{ts,js} : For fees adapters: verify dailyFees represents Gross Protocol Revenue (all potential fees), dailyRevenue represents Gross Profit (protocol's portion), and dailySupplySideRevenue represents Cost of Funds (supplier payments). Ensure dailyRevenue = dailyFees - dailySupplySideRevenue conceptually.

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: fees/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:41.566Z
Learning: Applies to fees/**/*.ts : Use source and destination labels for `dailySupplySideRevenue` dimension in fees adapters (e.g., 'Borrow Interest To Lenders', 'Swap Fees To LPs')

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: fees/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:41.566Z
Learning: Applies to fees/**/*.ts : Use source and destination labels for `dailyRevenue` dimension in fees adapters (e.g., 'Borrow Interest To Treasury', 'Swap Fees To Protocol')

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: GUIDELINES.md:0-0
Timestamp: 2026-04-03T10:25:08.836Z
Learning: Applies to adapters/**/*.ts : Always provide breakdown labels even when there is only one source/destination of fees. Use source-of-fees labels for `dailyFees` (e.g., 'Swap Fees', 'Borrow Interest'). Use detailed destination labels for `dailyRevenue`/`dailySupplySideRevenue`/`dailyHoldersRevenue` (e.g., 'Swap Fees To LPs', 'Borrow Interest To Treasury')

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: fees/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:41.566Z
Learning: Applies to fees/**/*.ts : Include integrator and referrer fees in `dailySupplySideRevenue` as supply-side costs in fees adapters

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: fees/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:41.566Z
Learning: Applies to fees/**/*.ts : Include `dailyRevenue` dimension in fees adapters - maps to Gross Profit and should equal `dailyFees - dailySupplySideRevenue` (what protocol keeps)

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: fees/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:41.566Z
Learning: Applies to fees/**/*.ts : Use simple source-based labels for `dailyFees` dimension in fees adapters (e.g., 'Borrow Interest', 'Swap Fees', 'Liquidation Fees')

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: GUIDELINES.md:0-0
Timestamp: 2026-04-03T10:25:08.836Z
Learning: Applies to adapters/**/*.ts : Do not use deprecated fields `dailyBribesRevenue` and `dailyTokenTaxes`; put these as sub-sections within `dailyHoldersRevenue` instead

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: GUIDELINES.md:0-0
Timestamp: 2026-04-03T10:25:08.836Z
Learning: For perpetual DEX adapters: track TAKER volume only, do NOT double-count maker+taker volume

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: dexs/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:25.918Z
Learning: Applies to dexs/**/*.ts : Include dailyVolume dimension as a required field in all DEX volume adapters

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: aggregator-derivatives/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:05:47.814Z
Learning: Applies to aggregator-derivatives/**/*.{js,ts,tsx} : Track `dailyVolume` as a required dimension for derivatives aggregators, representing perpetual/derivatives trading volume (TAKER volume only)

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: dexs/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:25.918Z
Learning: Applies to dexs/**/*.ts : Track actual trading volume from swap events in spot DEX implementations

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: bridge-aggregators/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:13.996Z
Learning: Applies to bridge-aggregators/**/[!.]*.ts : Track volume ROUTED through the bridge aggregator, including all cross-chain transfers facilitated, reflecting the value being bridged rather than fees

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: bridge-aggregators/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:13.996Z
Learning: Applies to bridge-aggregators/**/[!.]*.ts : Implement multi-chain indexing to track both source and destination chains for bridge aggregator volume tracking

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: dexs/GUIDELINES.md:0-0
Timestamp: 2026-03-30T12:06:25.918Z
Learning: Applies to dexs/**/*.ts : Track TAKER volume ONLY for perpetual/derivatives - do NOT double count by adding both taker and maker volumes

@github-actions
Copy link
Copy Markdown

The txflow-perps adapter exports:

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

🦙 Running TXFLOW-PERPS adapter 🦙
---------------------------------------------------
Start Date:	Mon, 13 Apr 2026 00:00:00 GMT
End Date:	Tue, 14 Apr 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:75:33)
DUNE_API_KEYS environment variable is not set

@bheluga bheluga marked this pull request as draft April 14, 2026 11:11
@bheluga bheluga changed the title track txflow perps oi and volume track txflow perps oi, fees and volume Apr 14, 2026
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.

1 participant