Skip to content

Add Canonic volume and fees adapters (MegaETH)#5832

Open
0xnerdz wants to merge 1 commit intoDefiLlama:masterfrom
0xnerdz:add-canonic-adapters
Open

Add Canonic volume and fees adapters (MegaETH)#5832
0xnerdz wants to merge 1 commit intoDefiLlama:masterfrom
0xnerdz:add-canonic-adapters

Conversation

@0xnerdz
Copy link

@0xnerdz 0xnerdz commented Feb 6, 2026

Summary

  • Adds DEX volume and fees adapters for Canonic, an on-chain orderbook DEX (CLOB) on MegaETH
  • Tracks daily volume and fees from RungFilled events across 3 MAOB orderbook contracts
  • Fee structure: 0.03% taker fee (BTC.b/USDm, WETH/USDm), 0.003% (USDT0/USDm), 0% maker fee
  • 100% of fees go to protocol treasury (no supply-side fee share)
  • Uses ceiling division to match on-chain fee rounding

Markets

Market Taker Fee Contract
BTC.b/USDm 0.03% 0xaD7e5CBfB535ceC8d2E58Dca17b11d9bA76f555E
WETH/USDm 0.03% 0x23469683e25b780DFDC11410a8e83c923caDF125
USDT0/USDm 0.003% 0xDf1576c3C82C9f8B759C69f4cF256061C6Fe1f9e

Protocol Links

Test plan

  • npm test dexs canonic returns correct daily volume
  • npm test fees canonic returns correct fee breakdown
  • Verify RungFilled event parsing works on MegaETH RPC

Summary by CodeRabbit

New Features

  • Added trading volume tracking across Canonic DEX markets on MEGAETH blockchain, enabling daily aggregation of trading metrics
  • Added comprehensive fee and revenue analytics for MEGAETH DEX, tracking daily trading volumes, transaction fees, user fees, and protocol/supply-side revenue breakdown

Canonic is an on-chain orderbook DEX (CLOB) on MegaETH.

- Volume: tracks daily trading volume from RungFilled events across 3 markets
- Fees: computes taker fees (0.03% for BTC/ETH, 0.003% for stables)
  - 100% of fees go to protocol (no supply-side fee share)
  - Uses ceiling division to match on-chain rounding

Markets: BTC.b/USDm, WETH/USDm, USDT0/USDm

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

Two new adapter modules are introduced for the MEGAETH chain: one aggregates daily trading volume across market addresses via RungFilled event logs, and the other computes daily fees and volumes by parsing the same events with per-market fee rates and trade-direction-based calculations.

Changes

Cohort / File(s) Summary
DEX Volume Adapter
dexs/canonic/index.ts
Fetches and aggregates daily trading volume across multiple market addresses (MAOBS) by parsing RungFilled events; tracks quoteAmount in USDM token.
Fee Accounting Adapter
fees/canonic/index.ts
Computes daily fees and volumes by iterating markets, retrieving per-market takerFee rates, and calculating fees via ceil(amount \* takerFee / FEE_DENOM) with trade-direction logic (buy: baseAmount, sell: quoteAmount).

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Fetch as fetch(options)
    participant BalanceAPI as options.createBalances()
    participant Blockchain as MEGAETH Chain
    participant EventLogs as RungFilled Events

    Caller->>Fetch: invoke with options
    Fetch->>BalanceAPI: initialize dailyVolume
    BalanceAPI-->>Fetch: balances object
    
    loop For each MAOB market address
        Fetch->>Blockchain: getLogs(market, RungFilled ABI)
        Blockchain->>EventLogs: filter event logs
        EventLogs-->>Fetch: logs with quoteAmount
        Fetch->>Fetch: accumulate quoteAmount into dailyVolume[USDM]
    end
    
    Fetch-->>Caller: return dailyVolume
Loading
sequenceDiagram
    participant Caller
    participant Fetch as fetch(options)
    participant BalanceAPI as options.createBalances()
    participant Blockchain as MEGAETH Chain
    participant EventLogs as RungFilled Events
    participant FeeCalc as Fee Calculation

    Caller->>Fetch: invoke with options
    Fetch->>BalanceAPI: initialize dailyVolume & dailyFees
    BalanceAPI-->>Fetch: balance objects
    
    loop For each MAOB market address
        Fetch->>Blockchain: retrieve takerFee for market
        Blockchain-->>Fetch: takerFee value
        Fetch->>Blockchain: getLogs(market, RungFilled ABI)
        Blockchain->>EventLogs: filter event logs
        EventLogs-->>Fetch: logs with amounts & isBuy flag
        
        loop For each log
            Fetch->>FeeCalc: compute fee based on isBuy
            alt Buy Trade
                FeeCalc->>FeeCalc: fee = ceil(baseAmount * takerFee / FEE_DENOM)
            else Sell Trade
                FeeCalc->>FeeCalc: fee = ceil(quoteAmount * takerFee / FEE_DENOM)
            end
            FeeCalc-->>Fetch: calculated fee
            Fetch->>Fetch: accumulate quoteAmount into dailyVolume
            Fetch->>Fetch: accumulate fee into dailyFees
        end
    end
    
    Fetch-->>Caller: return {dailyVolume, dailyFees, dailyUserFees, dailyRevenue, ...}
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~28 minutes

Poem

🐰 Two adapters hop and play,
Tracking fees and volume's way,
Through MEGAETH's bustling trades,
Logs aggregate in data glades,
Markets sing, their volumes cascade! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main changes: adding volume and fees adapters for Canonic on MegaETH.
Description check ✅ Passed The PR description includes a clear summary, market details with fee structure, protocol links, and a test plan. However, it does not follow the repository's template structure for new protocol listings.
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

The canonic adapter exports:

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

🦙 Running CANONIC adapter 🦙
---------------------------------------------------
Start Date:	Thu, 05 Feb 2026 17:35:00 GMT
End Date:	Fri, 06 Feb 2026 17:35:00 GMT
---------------------------------------------------

Skipping megaeth because the configured start time is Mon, 09 Feb 2026 00:00:00 GMT 

@llamabutler
Copy link

The canonic adapter exports:

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

🦙 Running CANONIC adapter 🦙
---------------------------------------------------
Start Date:	Thu, 05 Feb 2026 17:35:02 GMT
End Date:	Fri, 06 Feb 2026 17:35:02 GMT
---------------------------------------------------

Skipping megaeth because the configured start time is Mon, 09 Feb 2026 00:00:00 GMT 

Copy link
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

🤖 Fix all issues with AI agents
In `@dexs/canonic/index.ts`:
- Around line 28-36: The start date for the adapter's CHAIN.MEGAETH entry is a
placeholder; update the start value in the adapter object (the start property
under adapter -> [CHAIN.MEGAETH]) from '2026-02-09' to the actual first trade
date for Canonic so the fetch logic uses the correct historical range; make sure
to verify the true first-trade timestamp from your source and replace the TODO
comment accordingly in the same file where adapter, CHAIN.MEGAETH, and fetch are
defined.

In `@fees/canonic/index.ts`:
- Line 60: The start date constant currently set as start: '2026-02-09' in
fees/canonic/index.ts is a placeholder; replace it with the actual first trade
date (same fix as in dexs/canonic/index.ts) before merging. Locate the
exported/declared variable named start in fees/canonic/index.ts, update the
string value to the real first trade date (ISO format), and remove the TODO
comment. Ensure the date matches the one used in dexs/canonic/index.ts to keep
both modules consistent.
🧹 Nitpick comments (1)
dexs/canonic/index.ts (1)

4-12: Consider extracting shared constants to a common module.

The USDM address, MAOBS market addresses, and EVENT_ABI are duplicated between dexs/canonic/index.ts and fees/canonic/index.ts. If any contract address changes or a new market is added, both files must be updated in lockstep.

You could create a shared helpers/canonic.ts (or similar) to hold these constants.

Comment on lines +28 to +36
const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.MEGAETH]: {
fetch,
start: '2026-02-09', // TODO: update to actual first trade date
},
},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Placeholder start date — ensure it's updated before merge.

Line 33 has a TODO to update the start date to the actual first trade date. Make sure this is resolved before merging.

🤖 Prompt for AI Agents
In `@dexs/canonic/index.ts` around lines 28 - 36, The start date for the adapter's
CHAIN.MEGAETH entry is a placeholder; update the start value in the adapter
object (the start property under adapter -> [CHAIN.MEGAETH]) from '2026-02-09'
to the actual first trade date for Canonic so the fetch logic uses the correct
historical range; make sure to verify the true first-trade timestamp from your
source and replace the TODO comment accordingly in the same file where adapter,
CHAIN.MEGAETH, and fetch are defined.

adapter: {
[CHAIN.MEGAETH]: {
fetch,
start: '2026-02-09', // TODO: update to actual first trade date
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Placeholder start date — ensure it's updated before merge.

Same as in dexs/canonic/index.ts, this TODO needs to be resolved with the actual first trade date.

🤖 Prompt for AI Agents
In `@fees/canonic/index.ts` at line 60, The start date constant currently set as
start: '2026-02-09' in fees/canonic/index.ts is a placeholder; replace it with
the actual first trade date (same fix as in dexs/canonic/index.ts) before
merging. Locate the exported/declared variable named start in
fees/canonic/index.ts, update the string value to the real first trade date (ISO
format), and remove the TODO comment. Ensure the date matches the one used in
dexs/canonic/index.ts to keep both modules consistent.

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.

2 participants