Skip to content

Fira v1#6330

Open
zgorizzo69 wants to merge 7 commits intoDefiLlama:masterfrom
usual-dao:fira-v1
Open

Fira v1#6330
zgorizzo69 wants to merge 7 commits intoDefiLlama:masterfrom
usual-dao:fira-v1

Conversation

@zgorizzo69
Copy link
Copy Markdown
Contributor

add fees and revenue for fira v1

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Extended Fira fee tracking to include liquidation and trading fees
    • Added comprehensive support for fixed-rate lending market monitoring
    • Introduced USUAL protocol revenue tracking adapter
  • Improvements

    • Enhanced fee discovery across multiple market types and sources
    • Refined revenue calculation methodology for improved accuracy

Walkthrough

This pull request refactors the Fira fees adapter to implement a multi-stage market discovery and interest accounting pipeline across multiple contract components, while introducing a new Usual adapter integrating treasury balances and Dune query-based fee and revenue data.

Changes

Cohort / File(s) Summary
Fira Adapter Refactoring
fees/fira.ts
Restructured configuration schema and reworked fetch function into a multi-stage pipeline: discovers lending markets and legacy fallbacks, loads market parameters (loan token, oracle, fees), discovers fixed-rate coupon tokens via factory logs, aggregates interest events (variable via AccrueInterest, fixed-rate via RedeemInterest/CollectInterestFee/TreasuryFwInterestAccrued), adds AMM Swap fee accounting with netFwFee calculations, and estimates liquidation fees using oracle prices. Expanded contract ABIs to support market creation, interest flows, liquidation, and trading events.
Usual Adapter Creation
fees/usual/index.ts
New SimpleAdapter for ETHEREUM that fetches treasury balances via ERC-20 balanceOf queries and integrates Dune-based fee and revenue data. Constructs dailyFees and totalRevenue objects using dual Dune query mappings (total_revenue and optional extra_revenue_usd).

Sequence Diagram(s)

sequenceDiagram
    participant Discovery as Market Discovery
    participant Params as Market Parameters
    participant Tokens as Token Discovery
    participant Interest as Interest Events
    participant AMM as AMM Accounting
    participant Liquidation as Liquidation Fees
    participant Aggregation as Fee Aggregation

    Discovery->>Discovery: Scan CreateMarket logs from fromBlock<br/>for each lendingMarket
    Discovery->>Discovery: Deduplicate & append legacyMarkets
    Discovery->>Params: Query idToMarketParams & market<br/>for loanToken, oracle, fee

    Discovery->>Tokens: Query marketFactory CreateNewMarket<br/>logs for BTs
    Tokens->>Tokens: Map BTs to CTs via CT()

    Params->>Interest: For discovered markets,<br/>pull interest logs
    Interest->>Interest: Variable: AccrueInterest logs<br/>Fixed-rate: RedeemInterest,<br/>CollectInterestFee,<br/>TreasuryFwInterestAccrued

    Tokens->>AMM: Map fixed-rate lending BTs<br/>to AMM addresses
    AMM->>AMM: Read AMM tokens via readTokens()
    AMM->>AMM: Aggregate Swap event fees<br/>using netFwFee & netFwToReserve

    Params->>Liquidation: Use oracle price()<br/>to convert seizedAssets to<br/>loan token value
    Liquidation->>Liquidation: Calculate fee as<br/>seizedValueInLoanToken - repaidAssets

    Interest->>Aggregation: Add interest revenues
    AMM->>Aggregation: Add swap fees
    Liquidation->>Aggregation: Add liquidation fees
    Aggregation->>Aggregation: Populate dailyFees,<br/>dailyRevenue,<br/>dailySupplySideRevenue
Loading
sequenceDiagram
    participant Treasury as Treasury Module
    participant Dune as Dune Service
    participant Balances as ERC-20 Query
    participant Aggregation as Fee Aggregation

    Treasury->>Balances: Query balanceOf() for<br/>fixed treasury addresses
    Balances->>Aggregation: Return aggregated balances<br/>as totalRevenue

    Treasury->>Dune: Query Dune (total_revenue ID)
    Dune->>Aggregation: Return fee and revenue data

    Treasury->>Dune: Query Dune (extra_revenue_usd ID)<br/>if present
    Dune->>Aggregation: Return additional revenue data

    Aggregation->>Aggregation: Construct dailyFees object
    Aggregation->>Aggregation: Apply Dune mappings via<br/>addUSDValue(...)
    Aggregation->>Aggregation: Return dailyFees &<br/>totalRevenue
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Suggested labels

fees, new-adapter, methodology

🚥 Pre-merge checks | ✅ 2 | ❌ 4

❌ Failed checks (1 warning, 3 inconclusive)

Check name Status Explanation Resolution
Income Statement Compliance ⚠️ Warning The fees/fira.ts and fees/usual/index.ts adapters violate Income Statement Compliance by adding fees without proper allocation to dailyRevenue and dailySupplySideRevenue. Add liquidation and Dune fees to appropriate income statement buckets (dailyRevenue or dailySupplySideRevenue) and ensure dailyFees = dailyRevenue + dailySupplySideRevenue identity holds.
Title check ❓ Inconclusive Title is vague and generic, using only 'Fira v1' without descriptive details about the changes, not following the required format '[type] protocol-name - description'. Revise title to follow format '[type] protocol-name - description', e.g. '[feat] fira - add fees and revenue adapters' to clearly describe the main changes.
Description check ❓ Inconclusive Description is minimal and only states 'add fees and revenue for fira v1', lacks specificity about the changes and reasoning for the PR. Expand description to include details about the fee/revenue implementation, market discovery mechanism, and integration with fixed/variable lending markets and AMM components.
Breakdown Methodology Check ❓ Inconclusive Target files fees/fira.ts and fees/usual/index.ts referenced in the PR are not present in the repository. Verify that the correct branch is checked out and files are staged or committed before running verification.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Version 2 Required ✅ Passed Both new adapters (fees/fira.ts and fees/usual/index.ts) explicitly declare version: 2 in their SimpleAdapter exports.

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

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

@llamabutler
Copy link
Copy Markdown

The fira.ts adapter exports:

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

🦙 Running FIRA.TS adapter 🦙
---------------------------------------------------
Start Date:	Thu, 02 Apr 2026 11:00:00 GMT
End Date:	Fri, 03 Apr 2026 11:00:00 GMT
---------------------------------------------------

Slice 0:
Start Date:	Thu, 02 Apr 2026 11:00:00 GMT
End Date:	Thu, 02 Apr 2026 12:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 59.00
Daily supply side revenue: 59.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775131199 (2026-04-02T11:59:59.000Z)


Slice 1:
Start Date:	Thu, 02 Apr 2026 12:00:00 GMT
End Date:	Thu, 02 Apr 2026 13:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 34.00
Daily supply side revenue: 34.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775134799 (2026-04-02T12:59:59.000Z)


Slice 2:
Start Date:	Thu, 02 Apr 2026 13:00:00 GMT
End Date:	Thu, 02 Apr 2026 14:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775138399 (2026-04-02T13:59:59.000Z)


Slice 3:
Start Date:	Thu, 02 Apr 2026 14:00:00 GMT
End Date:	Thu, 02 Apr 2026 15:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 72.00
Daily supply side revenue: 72.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775141999 (2026-04-02T14:59:59.000Z)


Slice 4:
Start Date:	Thu, 02 Apr 2026 15:00:00 GMT
End Date:	Thu, 02 Apr 2026 16:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775145599 (2026-04-02T15:59:59.000Z)


Slice 5:
Start Date:	Thu, 02 Apr 2026 16:00:00 GMT
End Date:	Thu, 02 Apr 2026 17:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 133.00
Daily supply side revenue: 133.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775149199 (2026-04-02T16:59:59.000Z)


Slice 6:
Start Date:	Thu, 02 Apr 2026 17:00:00 GMT
End Date:	Thu, 02 Apr 2026 18:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775152799 (2026-04-02T17:59:59.000Z)


Slice 7:
Start Date:	Thu, 02 Apr 2026 18:00:00 GMT
End Date:	Thu, 02 Apr 2026 19:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775156399 (2026-04-02T18:59:59.000Z)


Slice 8:
Start Date:	Thu, 02 Apr 2026 19:00:00 GMT
End Date:	Thu, 02 Apr 2026 20:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775159999 (2026-04-02T19:59:59.000Z)


Slice 9:
Start Date:	Thu, 02 Apr 2026 20:00:00 GMT
End Date:	Thu, 02 Apr 2026 21:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775163599 (2026-04-02T20:59:59.000Z)


Slice 10:
Start Date:	Thu, 02 Apr 2026 21:00:00 GMT
End Date:	Thu, 02 Apr 2026 22:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775167199 (2026-04-02T21:59:59.000Z)


Slice 11:
Start Date:	Thu, 02 Apr 2026 22:00:00 GMT
End Date:	Thu, 02 Apr 2026 23:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775170799 (2026-04-02T22:59:59.000Z)


Slice 12:
Start Date:	Thu, 02 Apr 2026 23:00:00 GMT
End Date:	Fri, 03 Apr 2026 00:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775174399 (2026-04-02T23:59:59.000Z)


Slice 13:
Start Date:	Fri, 03 Apr 2026 00:00:00 GMT
End Date:	Fri, 03 Apr 2026 01:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 361.00
Daily supply side revenue: 361.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775177999 (2026-04-03T00:59:59.000Z)


Slice 14:
Start Date:	Fri, 03 Apr 2026 01:00:00 GMT
End Date:	Fri, 03 Apr 2026 02:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775181599 (2026-04-03T01:59:59.000Z)


Slice 15:
Start Date:	Fri, 03 Apr 2026 02:00:00 GMT
End Date:	Fri, 03 Apr 2026 03:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775185199 (2026-04-03T02:59:59.000Z)


Slice 16:
Start Date:	Fri, 03 Apr 2026 03:00:00 GMT
End Date:	Fri, 03 Apr 2026 04:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775188799 (2026-04-03T03:59:59.000Z)


Slice 17:
Start Date:	Fri, 03 Apr 2026 04:00:00 GMT
End Date:	Fri, 03 Apr 2026 05:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775192399 (2026-04-03T04:59:59.000Z)


Slice 18:
Start Date:	Fri, 03 Apr 2026 05:00:00 GMT
End Date:	Fri, 03 Apr 2026 06:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775195999 (2026-04-03T05:59:59.000Z)


Slice 19:
Start Date:	Fri, 03 Apr 2026 06:00:00 GMT
End Date:	Fri, 03 Apr 2026 07:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775199599 (2026-04-03T06:59:59.000Z)


Slice 20:
Start Date:	Fri, 03 Apr 2026 07:00:00 GMT
End Date:	Fri, 03 Apr 2026 08:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775203199 (2026-04-03T07:59:59.000Z)


Slice 21:
Start Date:	Fri, 03 Apr 2026 08:00:00 GMT
End Date:	Fri, 03 Apr 2026 09:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775206799 (2026-04-03T08:59:59.000Z)


Slice 22:
Start Date:	Fri, 03 Apr 2026 09:00:00 GMT
End Date:	Fri, 03 Apr 2026 10:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775210399 (2026-04-03T09:59:59.000Z)


Slice 23:
Start Date:	Fri, 03 Apr 2026 10:00:00 GMT
End Date:	Fri, 03 Apr 2026 11:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 28/11/2025
Daily fees: 0.00
Daily supply side revenue: 0.00
Daily revenue: 0.00
Daily protocol revenue: 0.00
End timestamp: 1775213999 (2026-04-03T10:59:59.000Z)



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

ETHEREUM 👇
End timestamp: 1775213999 (2026-04-03T10:59:59.000Z)
Daily fees: 659.00
Daily supply side revenue: 659.00
Daily revenue: 0.00
Daily protocol revenue: 0.00

@llamabutler
Copy link
Copy Markdown

The usual adapter exports:

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

🦙 Running USUAL adapter 🦙
---------------------------------------------------
Start Date:	Thu, 02 Apr 2026 11:00:00 GMT
End Date:	Fri, 03 Apr 2026 11:00:00 GMT
---------------------------------------------------

Slice 0:
Start Date:	Thu, 02 Apr 2026 11:00:00 GMT
End Date:	Thu, 02 Apr 2026 12:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 295.00
Daily revenue: 259.00
Daily protocol revenue: 258.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775131199 (2026-04-02T11:59:59.000Z)


Slice 1:
Start Date:	Thu, 02 Apr 2026 12:00:00 GMT
End Date:	Thu, 02 Apr 2026 13:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 3.81 k
Daily revenue: 3.78 k
Daily protocol revenue: 3.78 k
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775134799 (2026-04-02T12:59:59.000Z)


Slice 2:
Start Date:	Thu, 02 Apr 2026 13:00:00 GMT
End Date:	Thu, 02 Apr 2026 14:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 319.00
Daily revenue: 280.00
Daily protocol revenue: 278.00
Daily holders revenue: 0.00
Daily supply side revenue: 39.00
End timestamp: 1775138399 (2026-04-02T13:59:59.000Z)


Slice 3:
Start Date:	Thu, 02 Apr 2026 14:00:00 GMT
End Date:	Thu, 02 Apr 2026 15:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 262.00
Daily revenue: 230.00
Daily protocol revenue: 229.00
Daily holders revenue: 97.00
Daily supply side revenue: 32.00
End timestamp: 1775141999 (2026-04-02T14:59:59.000Z)


Slice 4:
Start Date:	Thu, 02 Apr 2026 15:00:00 GMT
End Date:	Thu, 02 Apr 2026 16:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 1.92 M
Daily revenue: 1.92 M
Daily protocol revenue: 1.92 M
Daily holders revenue: 0.00
Daily supply side revenue: 37.00
End timestamp: 1775145599 (2026-04-02T15:59:59.000Z)


Slice 5:
Start Date:	Thu, 02 Apr 2026 16:00:00 GMT
End Date:	Thu, 02 Apr 2026 17:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 1.56 k
Daily revenue: 1.52 k
Daily protocol revenue: 1.52 k
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775149199 (2026-04-02T16:59:59.000Z)


Slice 6:
Start Date:	Thu, 02 Apr 2026 17:00:00 GMT
End Date:	Thu, 02 Apr 2026 18:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 802.00
Daily revenue: 766.00
Daily protocol revenue: 765.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775152799 (2026-04-02T17:59:59.000Z)


Slice 7:
Start Date:	Thu, 02 Apr 2026 18:00:00 GMT
End Date:	Thu, 02 Apr 2026 19:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 296.00
Daily revenue: 260.00
Daily protocol revenue: 258.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775156399 (2026-04-02T18:59:59.000Z)


Slice 8:
Start Date:	Thu, 02 Apr 2026 19:00:00 GMT
End Date:	Thu, 02 Apr 2026 20:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 295.00
Daily revenue: 259.00
Daily protocol revenue: 258.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775159999 (2026-04-02T19:59:59.000Z)


Slice 9:
Start Date:	Thu, 02 Apr 2026 20:00:00 GMT
End Date:	Thu, 02 Apr 2026 21:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 295.00
Daily revenue: 259.00
Daily protocol revenue: 258.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775163599 (2026-04-02T20:59:59.000Z)


Slice 10:
Start Date:	Thu, 02 Apr 2026 21:00:00 GMT
End Date:	Thu, 02 Apr 2026 22:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 294.00
Daily revenue: 258.00
Daily protocol revenue: 257.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775167199 (2026-04-02T21:59:59.000Z)


Slice 11:
Start Date:	Thu, 02 Apr 2026 22:00:00 GMT
End Date:	Thu, 02 Apr 2026 23:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 294.00
Daily revenue: 258.00
Daily protocol revenue: 257.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775170799 (2026-04-02T22:59:59.000Z)


Slice 12:
Start Date:	Thu, 02 Apr 2026 23:00:00 GMT
End Date:	Fri, 03 Apr 2026 00:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 296.00
Daily revenue: 260.00
Daily protocol revenue: 258.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775174399 (2026-04-02T23:59:59.000Z)


Slice 13:
Start Date:	Fri, 03 Apr 2026 00:00:00 GMT
End Date:	Fri, 03 Apr 2026 01:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 296.00
Daily revenue: 260.00
Daily protocol revenue: 258.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775177999 (2026-04-03T00:59:59.000Z)


Slice 14:
Start Date:	Fri, 03 Apr 2026 01:00:00 GMT
End Date:	Fri, 03 Apr 2026 02:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 295.00
Daily revenue: 259.00
Daily protocol revenue: 258.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775181599 (2026-04-03T01:59:59.000Z)


Slice 15:
Start Date:	Fri, 03 Apr 2026 02:00:00 GMT
End Date:	Fri, 03 Apr 2026 03:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 294.00
Daily revenue: 258.00
Daily protocol revenue: 257.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775185199 (2026-04-03T02:59:59.000Z)


Slice 16:
Start Date:	Fri, 03 Apr 2026 03:00:00 GMT
End Date:	Fri, 03 Apr 2026 04:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 295.00
Daily revenue: 259.00
Daily protocol revenue: 258.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775188799 (2026-04-03T03:59:59.000Z)


Slice 17:
Start Date:	Fri, 03 Apr 2026 04:00:00 GMT
End Date:	Fri, 03 Apr 2026 05:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 294.00
Daily revenue: 258.00
Daily protocol revenue: 257.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775192399 (2026-04-03T04:59:59.000Z)


Slice 18:
Start Date:	Fri, 03 Apr 2026 05:00:00 GMT
End Date:	Fri, 03 Apr 2026 06:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 296.00
Daily revenue: 260.00
Daily protocol revenue: 258.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775195999 (2026-04-03T05:59:59.000Z)


Slice 19:
Start Date:	Fri, 03 Apr 2026 06:00:00 GMT
End Date:	Fri, 03 Apr 2026 07:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 296.00
Daily revenue: 260.00
Daily protocol revenue: 258.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775199599 (2026-04-03T06:59:59.000Z)


Slice 20:
Start Date:	Fri, 03 Apr 2026 07:00:00 GMT
End Date:	Fri, 03 Apr 2026 08:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 295.00
Daily revenue: 259.00
Daily protocol revenue: 258.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775203199 (2026-04-03T07:59:59.000Z)


Slice 21:
Start Date:	Fri, 03 Apr 2026 08:00:00 GMT
End Date:	Fri, 03 Apr 2026 09:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 294.00
Daily revenue: 258.00
Daily protocol revenue: 257.00
Daily holders revenue: 0.00
Daily supply side revenue: 36.00
End timestamp: 1775206799 (2026-04-03T08:59:59.000Z)


Slice 22:
Start Date:	Fri, 03 Apr 2026 09:00:00 GMT
End Date:	Fri, 03 Apr 2026 10:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 306.00
Daily revenue: 268.00
Daily protocol revenue: 267.00
Daily holders revenue: 0.00
Daily supply side revenue: 37.00
End timestamp: 1775210399 (2026-04-03T09:59:59.000Z)


Slice 23:
Start Date:	Fri, 03 Apr 2026 10:00:00 GMT
End Date:	Fri, 03 Apr 2026 11:00:00 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 24/5/2024
Daily fees: 306.00
Daily revenue: 268.00
Daily protocol revenue: 267.00
Daily holders revenue: 0.00
Daily supply side revenue: 37.00
End timestamp: 1775213999 (2026-04-03T10:59:59.000Z)



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

ETHEREUM 👇
End timestamp: 1775213999 (2026-04-03T10:59:59.000Z)
Daily fees: 1.93 M
Daily revenue: 1.93 M
Daily protocol revenue: 1.93 M
Daily holders revenue: 97.00
Daily supply side revenue: 866.00

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

🤖 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/fira.ts`:
- Around line 263-265: The current calls to dailyFees.add, dailyRevenue.add, and
dailySupplySideRevenue.add are using source-only metric labels (e.g.,
METRIC.SWAP_FEES, METRIC.BORROW_INTEREST) which makes retained vs supplier flows
indistinguishable; update these calls so the metric label encodes both source
and destination (for example use distinct constants like
METRIC.SWAP_FEES_RETAINED and METRIC.SWAP_FEES_SUPPLIER or
METRIC.BORROW_INTEREST_RETAINED/SUPPLIER) and pass the appropriate
destination-specific label when adding values (affecting the lines using
dailyFees.add(feeToken, netFwFee,...), dailyRevenue.add(feeToken,
ammRevenue,...) and dailySupplySideRevenue.add(feeToken,
ammSupplySideRevenue,...) and the analogous calls at 283-285, 299-312, 356-369);
ensure naming follows existing METRIC enum/style and update any downstream
consumers if needed.
- Around line 316-334: The liquidation penalty is only being recorded into
dailyFees (METRIC.LIQUIDATION_FEES) but not routed to the actual recipient
buckets; update the logic around where liquidationFee is recorded so the same
computed liquidationFee is also allocated to dailySupplySideRevenue when lenders
receive it, split between dailySupplySideRevenue and dailyRevenue when the
protocol keeps a cut (use the marketData or fee-related fields on marketData to
determine the split), or omit it from revenue metrics if paid entirely to
external liquidators; ensure after changes the adapter preserves the invariant
dailyRevenue = dailyFees - dailySupplySideRevenue by adding corresponding
dailySupplySideRevenue.add(...) and/or dailyRevenue.add(...) calls alongside
dailyFees.add(...) wherever liquidationFee is processed (referencing variables
marketData, liquidationFee, dailyFees, dailySupplySideRevenue, dailyRevenue, and
METRIC.LIQUIDATION_FEES).

In `@fees/usual/index.ts`:
- Around line 39-55: The current code collapses Dune results into anonymous
dailyFees additions (using resRev/resFee -> dailyFees.addUSDValue) and thus
omits retained-side labels and breakdownMethodology; update the handlers for
queryDune("4957281") and queryDune("4957293") so that each mapped item calls
dailyFees.addUSDValue with an explicit label (e.g., "dailyRevenue" for resRev
and "dailyProtocolRevenue" or "dailyRevenue:extra" for resFee depending on
treasury allocation) and add corresponding entries to the exported
breakdownMethodology/meta for those labels; locate the mapping code around
resRev/resFee and the dailyFees object usage to add labeled adds and ensure
every emitted label has a descriptive breakdownMethodology entry.
- Around line 22-33: fetchTreasuryRevenue currently treats end-of-period token
balances as revenue—remove/replace that behavior: stop aggregating
YIELD_TREASURY balances into fee totals in fetchTreasuryRevenue (and the similar
block at lines 56-60) and either (a) implement proper revenue calculation by
summing actual fee-related events/transfers (e.g., use fee event logs or a
calculateFeesFromEvents function) or (b) convert this function into a treasury
snapshot/TVL helper (rename to fetchTreasurySnapshot or similar) that returns
plain balances without calling it "revenue"; update callers to use the correct
function (fee adapter should call the real revenue calculator, reporting adapter
should call the snapshot) and adjust function name/exports accordingly to avoid
mislabeling stock positions as revenue.
- Around line 39-42: The Dune queries are passing undefined timestamps because
they use options.startTimestamp and options.endTimestamp; change both queryDune
calls (e.g., the call assigned to resRev and any other queryDune usage in
fees/usual/index.ts) to use the correct FetchOptions fields
options.fromTimestamp and options.toTimestamp so the time window is forwarded
properly.
- Around line 63-81: Two modules resolve to the same slug "usual" (the
implementations in usual.ts and usual/index.ts) causing a discovery collision
and one adapter to overwrite the other; remove or rename one of these modules so
only a single "usual" adapter is exported. Keep the more comprehensive
implementation (the one that tracks broader revenue) and delete the narrower one
(or rename its module slug), ensuring only one export named adapter
(SimpleAdapter) remains and that fetchFeesAndRevenue / adapter.version /
adapter.adapter[CHAIN.ETHEREUM] are defined on the retained module. Also verify
buildModules' output no longer contains duplicate keys for "usual".
🪄 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: e120441a-5097-4ef2-b669-a6955691e2a1

📥 Commits

Reviewing files that changed from the base of the PR and between 262246f and d05854e.

📒 Files selected for processing (2)
  • fees/fira.ts
  • fees/usual/index.ts

Comment on lines +263 to +265
dailyFees.add(feeToken, netFwFee, METRIC.SWAP_FEES);
dailyRevenue.add(feeToken, ammRevenue, METRIC.SWAP_FEES);
dailySupplySideRevenue.add(feeToken, ammSupplySideRevenue, METRIC.SWAP_FEES);
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.

⚠️ Potential issue | 🟠 Major

Use destination-specific labels for retained vs supplier flows.

METRIC.SWAP_FEES and METRIC.BORROW_INTEREST are written into dailyFees, dailyRevenue, and dailySupplySideRevenue. That makes the retained side indistinguishable from the supplier-paid side in downstream breakdowns. The section-level descriptions in breakdownMethodology do not fix that, because the emitted label itself still stays source-only.

As per coding guidelines, dailyRevenue and dailySupplySideRevenue labels must include both the fee source and its destination.

Also applies to: 283-285, 299-312, 356-369

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@fees/fira.ts` around lines 263 - 265, The current calls to dailyFees.add,
dailyRevenue.add, and dailySupplySideRevenue.add are using source-only metric
labels (e.g., METRIC.SWAP_FEES, METRIC.BORROW_INTEREST) which makes retained vs
supplier flows indistinguishable; update these calls so the metric label encodes
both source and destination (for example use distinct constants like
METRIC.SWAP_FEES_RETAINED and METRIC.SWAP_FEES_SUPPLIER or
METRIC.BORROW_INTEREST_RETAINED/SUPPLIER) and pass the appropriate
destination-specific label when adding values (affecting the lines using
dailyFees.add(feeToken, netFwFee,...), dailyRevenue.add(feeToken,
ammRevenue,...) and dailySupplySideRevenue.add(feeToken,
ammSupplySideRevenue,...) and the analogous calls at 283-285, 299-312, 356-369);
ensure naming follows existing METRIC enum/style and update any downstream
consumers if needed.

Comment on lines +316 to 334
// Liquidation penalty (when seized collateral value exceeds repaid debt).
for (let i = 0; i < lendingMarkets.length; i++) {
const marketAddress = lendingMarkets[i];
for (const log of liquidationLogs[i] ?? []) {
const marketId = (log.id ?? '').toLowerCase();
const marketData = marketDataByKey.get(`${marketAddress}:${marketId}`);
if (!marketData) continue;

const oraclePrice = oraclePriceByAddress.get(marketData.oracle.toLowerCase());
if (!oraclePrice || oraclePrice <= 0n) continue;

const repaidAssets = BigInt(log.repaidAssets ?? 0);
const seizedAssets = BigInt(log.seizedAssets ?? 0);
const seizedValueInLoanToken = (seizedAssets * oraclePrice) / ORACLE_PRICE_SCALE;
if (seizedValueInLoanToken <= repaidAssets) continue;

const liquidationFee = seizedValueInLoanToken - repaidAssets;
dailyFees.add(marketData.loanToken, liquidationFee, METRIC.LIQUIDATION_FEES);
}
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.

⚠️ Potential issue | 🟠 Major

Route liquidation penalties into the correct destination bucket too.

Line 333 adds METRIC.LIQUIDATION_FEES only to dailyFees. On liquidation days, dailyRevenue + dailySupplySideRevenue will undercount gross fees because this source never gets assigned to whoever actually receives it. Book it into dailySupplySideRevenue if it goes to lenders, split it with dailyRevenue if the protocol keeps a cut, or drop it from fee metrics entirely if it is paid straight to external liquidators.

Based on learnings, fees adapters should keep dailyRevenue = dailyFees - dailySupplySideRevenue conceptually.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@fees/fira.ts` around lines 316 - 334, The liquidation penalty is only being
recorded into dailyFees (METRIC.LIQUIDATION_FEES) but not routed to the actual
recipient buckets; update the logic around where liquidationFee is recorded so
the same computed liquidationFee is also allocated to dailySupplySideRevenue
when lenders receive it, split between dailySupplySideRevenue and dailyRevenue
when the protocol keeps a cut (use the marketData or fee-related fields on
marketData to determine the split), or omit it from revenue metrics if paid
entirely to external liquidators; ensure after changes the adapter preserves the
invariant dailyRevenue = dailyFees - dailySupplySideRevenue by adding
corresponding dailySupplySideRevenue.add(...) and/or dailyRevenue.add(...) calls
alongside dailyFees.add(...) wherever liquidationFee is processed (referencing
variables marketData, liquidationFee, dailyFees, dailySupplySideRevenue,
dailyRevenue, and METRIC.LIQUIDATION_FEES).

Comment on lines +22 to +33
const fetchTreasuryRevenue = async (options: FetchOptions) => {
const totalRevenue = options.createBalances();
const usualXHolding = await getBalanceOf(options, USUALX, YIELD_TREASURY);
totalRevenue.add(USUALX, usualXHolding);

const usualHolding = await getBalanceOf(options, USUAL, YIELD_TREASURY);
totalRevenue.add(USUAL, usualHolding);

const usd0Holding = await getBalanceOf(options, USD0, YIELD_TREASURY);
totalRevenue.add(USD0, usd0Holding);
return totalRevenue;
};
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.

⚠️ Potential issue | 🟠 Major

Don't publish treasury balances as revenue.

fetchTreasuryRevenue() is reading end-of-period token balances, which are stock positions. Transfers, redemptions, emissions, and spending can change those balances without any fee event, so returning them as totalRevenue will misstate actual earnings. If you need this snapshot, keep it in a treasury/TVL-style adapter instead of a fee adapter.

Also applies to: 56-60

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@fees/usual/index.ts` around lines 22 - 33, fetchTreasuryRevenue currently
treats end-of-period token balances as revenue—remove/replace that behavior:
stop aggregating YIELD_TREASURY balances into fee totals in fetchTreasuryRevenue
(and the similar block at lines 56-60) and either (a) implement proper revenue
calculation by summing actual fee-related events/transfers (e.g., use fee event
logs or a calculateFeesFromEvents function) or (b) convert this function into a
treasury snapshot/TVL helper (rename to fetchTreasurySnapshot or similar) that
returns plain balances without calling it "revenue"; update callers to use the
correct function (fee adapter should call the real revenue calculator, reporting
adapter should call the snapshot) and adjust function name/exports accordingly
to avoid mislabeling stock positions as revenue.

Comment on lines +39 to +55
const resRev = await queryDune("4957281", {
start: options.startTimestamp,
end: options.endTimestamp,
});
resRev.map((item: any) => {
dailyFees.addUSDValue(item?.total_revenue);
});
// USUAL Extra Collateral Revenue
const resFee = await queryDune("4957293", {
start: options.startTimestamp,
end: options.endTimestamp,
});
resFee.map((item: any) => {
if (item?.extra_revenue_usd) {
dailyFees.addUSDValue(item?.extra_revenue_usd);
}
});
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.

⚠️ Potential issue | 🟠 Major

Return labeled retained-side dimensions for these Dune sources.

These two Dune sources are collapsed into anonymous dailyFees additions. That drops the retained-side dimension (dailyRevenue, and dailyProtocolRevenue if treasury-allocated) and leaves no emitted labels for a breakdownMethodology to document. The generic meta.methodology text is not a substitute.

As per coding guidelines, fees/**/*.ts must include dailyRevenue, always provide descriptive labels even for a single source, and include a breakdownMethodology entry for every emitted label.

Also applies to: 57-60, 70-74

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@fees/usual/index.ts` around lines 39 - 55, The current code collapses Dune
results into anonymous dailyFees additions (using resRev/resFee ->
dailyFees.addUSDValue) and thus omits retained-side labels and
breakdownMethodology; update the handlers for queryDune("4957281") and
queryDune("4957293") so that each mapped item calls dailyFees.addUSDValue with
an explicit label (e.g., "dailyRevenue" for resRev and "dailyProtocolRevenue" or
"dailyRevenue:extra" for resFee depending on treasury allocation) and add
corresponding entries to the exported breakdownMethodology/meta for those
labels; locate the mapping code around resRev/resFee and the dailyFees object
usage to add labeled adds and ensure every emitted label has a descriptive
breakdownMethodology entry.

Comment on lines +39 to +42
const resRev = await queryDune("4957281", {
start: options.startTimestamp,
end: options.endTimestamp,
});
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.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== FetchOptions timestamp fields =="
rg -n -C2 --type=ts 'type FetchOptions|fromTimestamp|toTimestamp|startTimestamp|endTimestamp' adapters/types.ts fees/usual/index.ts

echo
echo "== Timestamp fields used by other v2 adapters =="
( rg -n -C1 --type=ts '\b(fromTimestamp|toTimestamp)\b' fees adapters | head -n 80 ) || true

Repository: DefiLlama/dimension-adapters

Length of output: 6986


Fix timestamp field names in Dune queries.

The code uses options.startTimestamp and options.endTimestamp, but FetchOptions defines fromTimestamp and toTimestamp. Both Dune queries will receive undefined values for the time window.

Required changes
  const resRev = await queryDune("4957281", {
-   start: options.startTimestamp,
-   end: options.endTimestamp,
+   start: options.fromTimestamp,
+   end: options.toTimestamp,
  });
  const resFee = await queryDune("4957293", {
-   start: options.startTimestamp,
-   end: options.endTimestamp,
+   start: options.fromTimestamp,
+   end: options.toTimestamp,
  });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@fees/usual/index.ts` around lines 39 - 42, The Dune queries are passing
undefined timestamps because they use options.startTimestamp and
options.endTimestamp; change both queryDune calls (e.g., the call assigned to
resRev and any other queryDune usage in fees/usual/index.ts) to use the correct
FetchOptions fields options.fromTimestamp and options.toTimestamp so the time
window is forwarded properly.

Comment on lines +63 to +81
const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.ETHEREUM]: {
fetch: fetchFeesAndRevenue,
start: 1716163200,
runAtCurrTime: false,
meta: {
methodology: {
Fees: "RWA on the treasury generates revenue. User pays fees when redeeming USD0, unlocking USD0++ or exiting vaults",
Revenue: "DAO holds Usual treasury and earns yield on it.",
},
},
},
},
isExpensiveAdapter: true,
};

export default adapter;
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.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Usual adapter entrypoints =="
for f in fees/usual.ts fees/usual/index.ts; do
  if [ -f "$f" ]; then
    echo "--- $f ---"
    sed -n '1,120p' "$f"
  fi
done

echo
echo "== Module discovery implementation =="
build_modules="$(fd -a 'buildModules\.ts$' . | head -n 1 || true)"
if [ -n "$build_modules" ]; then
  echo "--- $build_modules ---"
  sed -n '1,260p' "$build_modules"
else
  echo "buildModules.ts not found; searching for adapter file enumeration:"
  rg -n -C3 --type=ts 'readdirSync|glob|globby|walk|fees/' .
fi

Repository: DefiLlama/dimension-adapters

Length of output: 15314


Both adapters resolve to the same module slug due to module discovery collision—delete or rename one before merging.

fees/usual.ts and fees/usual/index.ts both map to the slug usual in module discovery. The buildModules.ts code processes each directory entry and stores the result at dimensionsImports[adapterType][fileKey]. Since removeDotTs("usual.ts") and importing fees/usual (which resolves to fees/usual/index.ts) both result in fileKey="usual", whichever is processed second overwrites the first. The processing order from readdir() is not guaranteed, so either adapter could silently stop contributing data.

fees/usual.ts provides broader revenue tracking; fees/usual/index.ts focuses narrowly on Yield Treasury holdings. Keep the more comprehensive implementation and remove the other.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@fees/usual/index.ts` around lines 63 - 81, Two modules resolve to the same
slug "usual" (the implementations in usual.ts and usual/index.ts) causing a
discovery collision and one adapter to overwrite the other; remove or rename one
of these modules so only a single "usual" adapter is exported. Keep the more
comprehensive implementation (the one that tracks broader revenue) and delete
the narrower one (or rename its module slug), ensuring only one export named
adapter (SimpleAdapter) remains and that fetchFeesAndRevenue / adapter.version /
adapter.adapter[CHAIN.ETHEREUM] are defined on the retained module. Also verify
buildModules' output no longer contains duplicate keys for "usual".

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