Add Canonic volume and fees adapters (MegaETH)#5832
Add Canonic volume and fees adapters (MegaETH)#58320xnerdz wants to merge 1 commit intoDefiLlama:masterfrom
Conversation
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>
📝 WalkthroughWalkthroughTwo 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
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
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, ...}
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~28 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
|
The canonic adapter exports: |
|
The canonic adapter exports: |
There was a problem hiding this comment.
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
USDMaddress,MAOBSmarket addresses, andEVENT_ABIare duplicated betweendexs/canonic/index.tsandfees/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.
| const adapter: SimpleAdapter = { | ||
| version: 2, | ||
| adapter: { | ||
| [CHAIN.MEGAETH]: { | ||
| fetch, | ||
| start: '2026-02-09', // TODO: update to actual first trade date | ||
| }, | ||
| }, | ||
| } |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
Summary
RungFilledevents across 3 MAOB orderbook contractsMarkets
0xaD7e5CBfB535ceC8d2E58Dca17b11d9bA76f555E0x23469683e25b780DFDC11410a8e83c923caDF1250xDf1576c3C82C9f8B759C69f4cF256061C6Fe1f9eProtocol Links
Test plan
npm test dexs canonicreturns correct daily volumenpm test fees canonicreturns correct fee breakdownRungFilledevent parsing works on MegaETH RPCSummary by CodeRabbit
New Features