Skip to content

track prestocks fees#6409

Merged
bheluga merged 2 commits intomasterfrom
prestocks
Apr 16, 2026
Merged

track prestocks fees#6409
bheluga merged 2 commits intomasterfrom
prestocks

Conversation

@bheluga
Copy link
Copy Markdown
Member

@bheluga bheluga commented Apr 16, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 16, 2026

Walkthrough

A new Solana adapter module for Meteora DLMM PreStocks computes daily fee and revenue metrics by querying program accounts via RPC, decoding account data to extract positions, fetching per-pool volume history from Meteora's API, and aggregating USD values across three balance buckets.

Changes

Cohort / File(s) Summary
Meteora DLMM PreStocks Adapter
fees/prestocks/index.ts
New adapter module that queries Solana RPC for METEORA_DLMM_PROGRAM_ID accounts, decodes base64 account data to extract position public keys, retrieves daily pool volume history from Meteora's API, and aggregates fee metrics (LP fees, protocol fees, net revenue) with 500ms throttling between requests. Includes methodology metadata and configured for Solana chain with start date 2025-09-16.

Sequence Diagram

sequenceDiagram
    participant Adapter as PreStocks Adapter
    participant RPC as Solana RPC
    participant API as Meteora API
    
    Adapter->>RPC: getProgramAccounts(METEORA_DLMM_PROGRAM_ID)<br/>with memcmp filter for PRESTOCKS_LP_WALLET
    RPC-->>Adapter: Program account data (base64)
    
    loop For each position (with 500ms throttle)
        Adapter->>Adapter: Decode base64, extract<br/>public keys via byte offset
        Adapter->>API: requestPerPoolVolumeHistory<br/>(startOfDay, endTimestamp)
        API-->>Adapter: Pool volume history
        Adapter->>Adapter: Select entry matching<br/>startOfDay, aggregate USD
    end
    
    Adapter->>Adapter: Aggregate into 3 buckets:<br/>LP fees, protocol fees,<br/>net LP revenue
    Adapter-->>Adapter: Return balances object
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels

fees, new-adapter, methodology

🚥 Pre-merge checks | ✅ 1 | ❌ 5

❌ Failed checks (4 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'track prestocks fees' is vague and does not follow the required format [type] protocol-name - description. Revise the title to follow the specified format, for example: '[feat] meteora prestocks - add fee tracking adapter' or similar.
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.
Income Statement Compliance ⚠️ Warning The prestocks adapter incorrectly maps dailySupplySideRevenue to protocol fees instead of actual supplier revenue, violating income statement compliance standards. Restructure dailySupplySideRevenue to represent net LP fees retained (fees - protocol_fees) rather than Meteora's infrastructure costs.
Description check ⚠️ Warning The PR description contains only a URL and lacks any substantive information about the adapter being added. Required template fields such as name, website link, chain, description, category, and methodology are completely missing or not filled out. Complete the PR description by filling out the template fields: add protocol name, Twitter link, website, short description, chain (Solana), category, methodology explaining how fees are calculated, and any other relevant information about the Prestocks adapter.
Version 2 Required ❓ Inconclusive Unable to execute shell commands. Please provide the adapter file contents or specify the file path to review for version: 2 format export. Share the adapter file contents or path so the version format can be verified against the required v2 specification.
✅ Passed checks (1 passed)
Check name Status Explanation
Breakdown Methodology Check ✅ Passed All breakdown labels used in .addUSDValue() calls (METRIC.LP_FEES and METRIC.PROTOCOL_FEES) have corresponding entries in breakdownMethodology and are properly exported.

✏️ 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 prestocks

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 prestocks adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees prestocks

🦙 Running PRESTOCKS adapter 🦙
---------------------------------------------------
Start Date:	Wed, 15 Apr 2026 00:00:00 GMT
End Date:	Thu, 16 Apr 2026 00:00:00 GMT
---------------------------------------------------

SOLANA 👇
Backfill start time: 16/9/2025
Daily fees: 3.78 k
Daily supply side revenue: 310.00
Daily revenue: 3.47 k
Daily protocol revenue: 3.47 k

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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@fees/prestocks/index.ts`:
- Line 50: The fetch function is using the deprecated v1 signature with unused
parameters (_a, _b) — update async function fetch(_a: any, _b: any, options:
FetchOptions) to the v2 signature async function fetch(options: FetchOptions),
remove the unused parameters and any code that expects the old args, and ensure
any internal references use the single options object; keep the FetchOptions
type and adapter export as-is so the adapter uses the modern signature and can
opt out of isExpensiveAdapter.
- Around line 59-63: The code assumes todaysData exists after
poolData.data.find(...) and will crash if undefined; update the block that calls
todaysData.fees and todaysData.protocol_fees to first check if todaysData is
truthy (from poolData.data.find using options.startOfDay) and handle the missing
case (e.g., skip adding metrics or pass 0 values) before calling
dailyFees.addUSDValue, dailySupplySideRevenue.addUSDValue and
dailyRevenue.addUSDValue so you never dereference an undefined todaysData.
🪄 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: bf3f0562-b673-40b4-913e-df536e6e4b3e

📥 Commits

Reviewing files that changed from the base of the PR and between 5634cca and d8f9800.

📒 Files selected for processing (1)
  • fees/prestocks/index.ts

Comment thread fees/prestocks/index.ts
});
}

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

@coderabbitai coderabbitai Bot Apr 16, 2026

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Use the modern adapter signature.

This adapter doesn't have isExpensiveAdapter: true, so it should use the Version 2 signature async function fetch(options: FetchOptions) instead of the deprecated v1 pattern with unused parameters.

♻️ 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 `@fees/prestocks/index.ts` at line 50, The fetch function is using the
deprecated v1 signature with unused parameters (_a, _b) — update async function
fetch(_a: any, _b: any, options: FetchOptions) to the v2 signature async
function fetch(options: FetchOptions), remove the unused parameters and any code
that expects the old args, and ensure any internal references use the single
options object; keep the FetchOptions type and adapter export as-is so the
adapter uses the modern signature and can opt out of isExpensiveAdapter.

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.

version would be 1 for either its dependent on dune, or some api which provides data once in 24hrs
version can be 2 and still expensive for allium

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! You're right — the Version 1 signature is the correct choice here because the Meteora API only returns daily aggregates (not per-timestamp data), making it impossible to use Version 2 even if the adapter isn't flagged as isExpensiveAdapter. I'll retract the suggestion.


✏️ Learnings added
Learnt from: bheluga
Repo: DefiLlama/dimension-adapters PR: 6409
File: fees/prestocks/index.ts:50-50
Timestamp: 2026-04-16T08:57:44.422Z
Learning: Applies to fees/**/*.ts: When an adapter fetches from an external API that only returns daily aggregated data (not filterable by arbitrary timestamps), the Version 1 adapter signature `async function fetch(_a: any, _b: any, options: FetchOptions)` is correct and intentional. Do NOT flag this as deprecated or suggest switching to the Version 2 `(options: FetchOptions)` signature. Version selection is determined by the data source's granularity, not by whether the adapter is marked `isExpensiveAdapter`. For example, the Meteora per-pool volume history API used in `fees/prestocks/index.ts` only provides daily aggregates, justifying Version 1.

Learnt from: bheluga
Repo: DefiLlama/dimension-adapters PR: 6409
File: fees/prestocks/index.ts:50-50
Timestamp: 2026-04-16T08:57:44.422Z
Learning: Applies to dexs/**/*.ts, fees/**/*.ts, open-interest/**/*.ts: The Version 2 adapter signature `(options: FetchOptions)` can still be "expensive" (e.g., Allium queries). Adapter version is NOT determined by whether it is expensive, but by whether the underlying data source supports timestamp-filtered queries. Use Version 1 when the data source (external API, etc.) only returns daily aggregates; use Version 2 when the source supports granular time filtering (on-chain logs, contract calls, subgraphs, Dune/Allium with timestamp filters).

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: bheluga
Repo: DefiLlama/dimension-adapters PR: 6390
File: dexs/txflow-perps/index.ts:5-5
Timestamp: 2026-04-14T11:10:50.312Z
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.

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-04-15T09:34:16.435Z
Learning: Applies to **/adapter.{js,ts} : 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: GUIDELINES.md:0-0
Timestamp: 2026-04-15T09:32:36.613Z
Learning: Use Adapter Version 2 when possible with on-chain logs, contract calls, subgraphs, Dune queries with timestamp filters; use Version 1 only when v2 is not possible with external APIs that only return daily aggregates

Learnt from: CopsLikeDonuts
Repo: DefiLlama/dimension-adapters PR: 6353
File: fees/thorwallet/index.ts:5-7
Timestamp: 2026-04-08T12:11:46.613Z
Learning: In DefiLlama/dimension-adapters, THORWallet (`fees/thorwallet/index.ts`) intentionally omits defensive `|| 0` fallbacks on `parseFloat()` calls. The API endpoint (`https://api-v2-prod.thorwallet.org/defillama/fees`) is purpose-built for this adapter, and the preference is to fail loudly (throw/NaN) rather than silently return zeros when the response shape changes. This is consistent with how other adapters in the repo handle their data sources.

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: options/GUIDELINES.md:0-0
Timestamp: 2026-04-15T09:34:12.054Z
Learning: Applies to options/**/*.ts : Avoid double-counting expired options when calculating volume metrics in options adapters

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: GUIDELINES.md:0-0
Timestamp: 2026-04-15T09:32:36.613Z
Learning: Applies to **/*adapters/**/*.{ts,js} : Use `pullHourly: true` wherever EVM logs and Allium queries are used to avoid recomputing data for the same time period and provide more granular data

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: options/GUIDELINES.md:0-0
Timestamp: 2026-04-15T09:34:12.054Z
Learning: Applies to options/**/*.ts : If tracking fees/revenue dimensions in options adapters, follow the guidelines defined in `fees/GUIDELINES.md`

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: aggregator-options/GUIDELINES.md:0-0
Timestamp: 2026-04-15T09:32:56.336Z
Learning: Applies to aggregator-options/**/*.{js,ts,py,go,java,rs} : Follow fee/revenue tracking guidelines in `fees/GUIDELINES.md` if the aggregator charges fees and this adapter returns fee/revenue dimensions

Learnt from: CopsLikeDonuts
Repo: DefiLlama/dimension-adapters PR: 6353
File: fees/thorwallet/index.ts:35-39
Timestamp: 2026-04-08T11:57:56.597Z
Learning: In DefiLlama/dimension-adapters, THORWallet (`fees/thorwallet/index.ts`) is a **separate protocol** from THORChain and should use `CHAIN.THORWALLET` (not `CHAIN.THORCHAIN`). The DEX adapter at `dexs/thorwallet/index.ts` using `CHAIN.THORCHAIN` is a known legacy inconsistency to be fixed separately. Do not flag `CHAIN.THORWALLET` usage in the fees adapter as incorrect.

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: fees/GUIDELINES.md:0-0
Timestamp: 2026-04-15T09:33:41.050Z
Learning: Applies to fees/**/*.ts : Always provide labels in `.add()` calls even when there is only one source of fees to prevent needing to update and backfill data later when adapter is listed under a parent protocol

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-04-15T09:34:16.435Z
Learning: Applies to **/fees/**/adapter.{js,ts} : 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-04-15T09:33:41.050Z
Learning: Applies to fees/**/*.ts : Include a required `breakdownMethodology` object in TypeScript adapter files documenting all labels used in `.add()` calls, organized by dimension (Fees, Revenue, SupplySideRevenue, HoldersRevenue)

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: dexs/GUIDELINES.md:0-0
Timestamp: 2026-04-15T09:33:22.030Z
Learning: Applies to dexs/**/*.ts : Include fees/revenue tracking dimensions (`dailyFees`, `dailyRevenue`, `dailySupplySideRevenue`) when the adapter also tracks fees/revenue, following guidelines in `fees/GUIDELINES.md` with appropriate breakdown labels and `breakdownMethodology`

Learnt from: CopsLikeDonuts
Repo: DefiLlama/dimension-adapters PR: 6353
File: fees/thorwallet/index.ts:18-23
Timestamp: 2026-04-08T11:58:26.321Z
Learning: In DefiLlama/dimension-adapters, THORWallet (`fees/thorwallet/index.ts`) collects only affiliate fees from swaps and perpetual close fees. There are no supply-side parties (no LPs, lenders, stakers, or external integrators), so 100% of collected fees are protocol revenue. `dailyRevenue = dailyFees` is correct and intentional. The `dailyProtocolRevenue` (~45%) and `dailyHoldersRevenue` (~50%) entries represent internal allocations, not cost-of-funds, so `dailySupplySideRevenue` should not be added to this adapter.

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: GUIDELINES.md:0-0
Timestamp: 2026-04-15T09:32:36.613Z
Learning: Applies to **/*adapters/**/*.{ts,js} : Do not use deprecated `dailyBribesRevenue` and `dailyTokenTaxes` fields; put these as sub-sections within `dailyHoldersRevenue` instead

Learnt from: DomCrogan
Repo: DefiLlama/dimension-adapters PR: 6406
File: fees/metronome-synth/index.ts:38-44
Timestamp: 2026-04-15T14:38:48.975Z
Learning: In `fees/metronome-synth/index.ts` (Metronome Synth adapter, DefiLlama/dimension-adapters), VELO rewards received by the protocol's Optimism multisigs from Protocol-Owned Liquidity (POL) positions are correctly classified as `dailyFees`/`dailyRevenue` (protocol revenue), NOT `dailyHoldersRevenue` or supply-side costs. The protocol is the LP itself, so VELO rewards represent yield on the protocol's own capital. The `fromAddressFilter` on EXTRA_INFLOWS entries correctly scopes these inflows to a specific sender (the VELO reward distributor).

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-04-15T09:34:16.435Z
Learning: Applies to **/fees/**/adapter.{js,ts} : For fees adapters: verify that all breakdown labels used in .add() calls have corresponding entries in breakdownMethodology object, and that breakdownMethodology is exported in the adapter

Learnt from: 0xCatalyst
Repo: DefiLlama/dimension-adapters PR: 6355
File: fees/neverland.ts:541-541
Timestamp: 2026-04-14T07:31:51.018Z
Learning: In DefiLlama/dimension-adapters, when adapters build the `FLASHLOAN_FEES` breakdown using the shared Aave V3 helper (`helpers/aave.ts` -> `getPoolFees`), ensure the `FLASHLOAN_FEES` breakdown text/description reflects only the `flashloanPremiumForProtocol` (i.e., the protocol/treasury portion derived from `FLASHLOAN_PREMIUM_TO_PROTOCOL`). Do NOT describe `FLASHLOAN_FEES` as gross flashloan fees or include the LP/lender share, since the LP portion accrues via the Aave liquidity index and is already accounted for in `BORROW_INTEREST`.

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: fees/GUIDELINES.md:0-0
Timestamp: 2026-04-15T09:33:41.050Z
Learning: Applies to fees/**/*.ts : Avoid vague labels in new TypeScript adapters - do not use 'Protocol Fees', 'Fees', 'Revenue', 'Other', or 'Misc' and instead use specific source labels

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: GUIDELINES.md:0-0
Timestamp: 2026-04-15T09:32:36.613Z
Learning: For listing requirements, must provide all required dimensions for the adapter category, and for fees adapters must provide accurate `dailyFees` and `dailyRevenue`

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: open-interest/GUIDELINES.md:0-0
Timestamp: 2026-04-15T09:34:04.085Z
Learning: When implementing fee/revenue tracking in open-interest adapters, follow the guidelines in `fees/GUIDELINES.md`

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: fees/GUIDELINES.md:0-0
Timestamp: 2026-04-15T09:33:41.050Z
Learning: Applies to fees/**/*.ts : If the adapter also tracks volume (dexs/ style metrics), follow the volume-specific rules in `dexs/GUIDELINES.md` in addition to fees guidelines

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: fees/GUIDELINES.md:0-0
Timestamp: 2026-04-15T09:33:41.050Z
Learning: Applies to fees/**/*.ts : Use clear, descriptive label names in TypeScript adapters - examples: 'Borrow Interest', 'GHO Borrow Interest', 'Liquidation Fees', 'Staking Rewards', 'Borrow Interest To Treasury', 'Borrow Interest To Lenders'

Learnt from: CR
Repo: DefiLlama/dimension-adapters PR: 0
File: bridge-aggregators/GUIDELINES.md:0-0
Timestamp: 2026-04-15T09:33:12.226Z
Learning: Applies to bridge-aggregators/**/bridge-aggregators/**/*.ts : If the bridge aggregator charges fees and the adapter returns fee/revenue dimensions, follow the guidelines in `fees/GUIDELINES.md` and include `dailyFees`, `dailyRevenue`, and `dailySupplySideRevenue` dimensions

Comment thread fees/prestocks/index.ts
@github-actions
Copy link
Copy Markdown

The prestocks adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees prestocks

🦙 Running PRESTOCKS adapter 🦙
---------------------------------------------------
Start Date:	Wed, 15 Apr 2026 00:00:00 GMT
End Date:	Thu, 16 Apr 2026 00:00:00 GMT
---------------------------------------------------

SOLANA 👇
Backfill start time: 16/9/2025
Daily fees: 3.78 k
Daily supply side revenue: 310.00
Daily revenue: 3.47 k
Daily protocol revenue: 3.47 k

@bheluga bheluga merged commit 520f94a into master Apr 16, 2026
3 checks passed
@bheluga bheluga deleted the prestocks branch April 16, 2026 09:07
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