Skip to content

feat: Add Bags dammv2 fee#5761

Open
dirty-w0rk wants to merge 3 commits intoDefiLlama:masterfrom
dirty-w0rk:bags-dammv2-fee
Open

feat: Add Bags dammv2 fee#5761
dirty-w0rk wants to merge 3 commits intoDefiLlama:masterfrom
dirty-w0rk:bags-dammv2-fee

Conversation

@dirty-w0rk
Copy link
Copy Markdown
Contributor

@dirty-w0rk dirty-w0rk commented Jan 29, 2026

NOTE

Please enable "Allow edits by maintainers" while putting up the PR.


  • If you would like to add a tvl adapter please submit the PR here.
  1. Once your adapter has been merged, it takes time to show on the UI. If more than 24 hours have passed, please let us know in Discord.
  2. Please fill the form below only if the PR is for listing a new protocol else it can be ignored/replaced with reason/details about the PR
  3. For updating listing info It is a different repo, you can find your listing in this file: https://github.com/DefiLlama/defillama-server/blob/master/defi/src/protocols/data4.ts, you can edit it there and put up a PR
  4. Do not edit/push package.json/package-lock.json file as part of your changes
  5. No need to go to our discord/other channel and announce that you've created a PR, we monitor all PRs and will review it asap

Name (to be shown on DefiLlama):
Twitter Link:
List of audit links if any:
Website Link:
Logo (High resolution, will be shown with rounded borders):
Current TVL:
Treasury Addresses (if the protocol has treasury)
Chain:
Coingecko ID (so your TVL can appear on Coingecko, leave empty if not listed): (https://api.coingecko.com/api/v3/coins/list)
Coinmarketcap ID (so your TVL can appear on Coinmarketcap, leave empty if not listed): (https://api.coinmarketcap.com/data-api/v3/map/all?listing_status=active,inactive,untracked&start=1&limit=10000)
Short Description (to be shown on DefiLlama):
Token address and ticker if any:
Category (full list at https://defillama.com/categories) *Please choose only one:
Oracle Provider(s): Specify the oracle(s) used (e.g., Chainlink, Band, API3, TWAP, etc.):
Implementation Details: Briefly describe how the oracle is integrated into your project:
Documentation/Proof: Provide links to documentation or any other resources that verify the oracle's usage:
forkedFrom (Does your project originate from another project):
methodology (what is being counted as tvl, how is tvl being calculated):
Github org/user (Optional, if your code is open source, we can track activity):
Does this project have a referral program?

Summary by CodeRabbit

  • New Features
    • Integrated post-migration fee data from an external API and mapped results into daily USD fee metrics.
    • Ingested USD values so protocol and creator fees are reported in currency terms.
  • Refactor
    • Unified pre- and post-migration processing and updated aggregation to separately accumulate pre-migration protocol fees and post-migration USD-valued protocol/creator revenues.
  • Other
    • Extended output to include USD-valued accumulations.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

Integrates DAMMv2 post-migration fee data (via external HTTP API) with pre-migration DBC data (via Dune) in the launch-on-bags fee adapter, adding types/constants and extending aggregation to separately accumulate USD-valued protocol and creator fees across both periods.

Changes

Cohort / File(s) Summary
Launch-on-Bags core
fees/launch-on-bags/index.ts
Added DAMMV2_API_URL, IDbcData, IDammv2FeeResult, IDammv2FeeResponse. Switched to v1 Dune query output (dbcData), fetches DBC (pre-migration) and DAMMv2 (post-migration) results; computes and accumulates protocolFees, creatorFees, and USD-valued metrics across both periods.
DBC query
helpers/queries/bags-v1.sql
New SQL for FeeShare v1: computes daily fees and protocol revenue from DBC swap events, excludes v2 fee authorities, and provides start/end time placeholders for the pre-migration window.

Sequence Diagram

sequenceDiagram
    participant Caller as Adapter Caller
    participant Dune as Dune API
    participant DAMMv2 as DAMMv2 API
    participant Processor as Fee Processor
    participant Aggregator as Aggregator

    Caller->>Dune: Request pre-migration DBC rows
    Dune-->>Caller: Return DBC rows

    Caller->>Processor: Provide DBC rows
    Processor->>Processor: Compute protocolFees, creatorFees, USD values (DBC)

    Caller->>DAMMv2: Request DAMMv2 fee results (start_time +1s)
    DAMMv2-->>Caller: Return DAMMv2 fee results

    Caller->>Processor: Provide DAMMv2 results
    Processor->>Processor: Map to daily metrics, compute protocolRevenue & creatorFees, convert to USD

    Processor->>Aggregator: Merge DBC and DAMMv2 aggregates
    Aggregator-->>Caller: Return unified fee metrics
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • treeoflife2
  • noateden

Poem

🐇
I hopped from DBC to DAMMv2 shore,
Counting fees, then counting more.
USD carrots lined the trail—so neat,
Two eras joined where totals meet.
Hop, tally, merge — a rabbit's feat.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description contains only the generic template with no protocol-specific details, implementation context, or explanation of the DAMMv2 integration changes, making it entirely unhelpful for reviewers. Replace template boilerplate with actual details about the DAMMv2 integration, changes to fee calculations, and any relevant migration context or testing information.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: Add Bags dammv2 fee' accurately describes the main change—adding DAMMv2 fee integration to the Bags adapter, which aligns with the substantial code modifications for post-migration fee handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@llamabutler
Copy link
Copy Markdown

The launch-on-bags adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees launch-on-bags

🦙 Running LAUNCH-ON-BAGS adapter 🦙
---------------------------------------------------
Start Date:	Wed, 28 Jan 2026 00:00:00 GMT
End Date:	Thu, 29 Jan 2026 00:00:00 GMT
---------------------------------------------------

------ ERROR ------
Error: Request failed with status code 401
    at _queryDune (/home/runner/work/dimension-adapters/dimension-adapters/helpers/dune.ts:219:22)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
Request failed with status code 401

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

Caution

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

⚠️ Outside diff range comments (1)
fees/launch-on-bags/index.ts (1)

84-86: Fix grammatical issue in Revenue methodology.

The sentence structure appears incomplete or incorrectly punctuated: "...from DBC (pre-migration), For DAMMv2 (post-migration)."

📝 Suggested fix
   methodology: {
     Fees: "Total trading fees paid by users when swapping against Bags DBC pools (pre-migration) and DAMMv2 pools (post-migration). These fees exclude the underlying Meteora protocol fee and DAMMv2 LP Fees and any referral fees.",
-    Revenue: "Trading-fee revenue earned by Bags from DBC (pre-migration), For DAMMv2 (post-migration).",
+    Revenue: "Trading-fee revenue earned by Bags from DBC pools (pre-migration) and DAMMv2 pools (post-migration).",
     ProtocolRevenue: "Net Revenue earned by the Bags protocol from trading activity"
   },
🤖 Fix all issues with AI agents
In `@fees/launch-on-bags/index.ts`:
- Around line 53-64: The code assumes dammv2Response.results is always an array;
add a defensive check before iterating: after obtaining dammv2Response from
httpGet (and matching IDammv2FeeResponse), verify dammv2Response is truthy and
Array.isArray(dammv2Response.results) (or fall back to an empty array) and only
then call forEach; if results is missing/null, log a warning or skip processing
to avoid runtime errors while still ensuring dailyFees, dailyProtocolRevenue and
METRIC usages remain unchanged inside the safe iteration.

@treeoflife2 treeoflife2 self-assigned this Jan 29, 2026
@llamabutler
Copy link
Copy Markdown

The launch-on-bags adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees launch-on-bags

🦙 Running LAUNCH-ON-BAGS adapter 🦙
---------------------------------------------------
Start Date:	Thu, 29 Jan 2026 00:00:00 GMT
End Date:	Fri, 30 Jan 2026 00:00:00 GMT
---------------------------------------------------

------ ERROR ------
Error: Request failed with status code 401
    at _queryDune (/home/runner/work/dimension-adapters/dimension-adapters/helpers/dune.ts:219:22)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
Request failed with status code 401

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

Caution

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

⚠️ Outside diff range comments (1)
fees/launch-on-bags/index.ts (1)

85-85: ⚠️ Potential issue | 🟡 Minor

Complete the Revenue methodology description.

The sentence appears truncated: "Trading-fee revenue earned by Bags from DBC (pre-migration), For DAMMv2 (post-migration)." The comma before "For" and the incomplete phrasing suggest missing text describing what revenue is earned from DAMMv2.

📝 Suggested fix
-    Revenue: "Trading-fee revenue earned by Bags from DBC (pre-migration), For DAMMv2 (post-migration).",
+    Revenue: "Trading-fee revenue earned by Bags from DBC (pre-migration) and DAMMv2 pools (post-migration).",
🧹 Nitpick comments (2)
fees/launch-on-bags/index.ts (2)

40-47: Add defensive check for dbcData for consistency with DAMMv2 handling.

The DAMMv2 response on line 55 uses (dammv2Response?.results ?? []).forEach(...) to guard against null/undefined, but dbcData lacks the same protection. If queryDuneSql returns an unexpected value, this will throw.

🛡️ Proposed fix for consistency
-  dbcData.forEach(row => {
+  (dbcData ?? []).forEach(row => {
     const protocolFees = Number(row.daily_protocol_revenue);
     const creatorFees = Number(row.daily_fees) - protocolFees;

49-52: Clarify the +1 second adjustment.

The comment states adding 1 second is needed "to match the start of the day," but this is counterintuitive—start-of-day timestamps are typically at 00:00:00. If this is compensating for an API boundary condition (e.g., exclusive vs. inclusive start), please update the comment to explain the actual reason to prevent future confusion.

@llamabutler
Copy link
Copy Markdown

The launch-on-bags adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees launch-on-bags

🦙 Running LAUNCH-ON-BAGS adapter 🦙
---------------------------------------------------
Start Date:	Wed, 04 Feb 2026 00:00:00 GMT
End Date:	Thu, 05 Feb 2026 00:00:00 GMT
---------------------------------------------------

------ ERROR ------
Error: Request failed with status code 401
    at _queryDune (/home/runner/work/dimension-adapters/dimension-adapters/helpers/dune.ts:219:22)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
Request failed with status code 401

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.

3 participants