Skip to content

Add Calculus DEX volume adapter on BSC#5797

Open
calculusfinanceofficial wants to merge 2 commits intoDefiLlama:masterfrom
calculusfinanceofficial:patch-1
Open

Add Calculus DEX volume adapter on BSC#5797
calculusfinanceofficial wants to merge 2 commits intoDefiLlama:masterfrom
calculusfinanceofficial:patch-1

Conversation

@calculusfinanceofficial
Copy link
Contributor

@calculusfinanceofficial calculusfinanceofficial commented Feb 2, 2026

Overview

This PR adds a DEX volume adapter for Calculus on BSC.

Calculus is a PancakeSwap v3 liquidity management protocol. Users open managed vaults which deploy PancakeSwap v3 positions. Opening volume can be measured directly from on-chain vault creation events.


Volume Methodology

Daily volume is calculated using the VaultCreated event:

  • reserve0 and reserve1 emitted during vault creation are treated as opening trade volume.
  • Volume is counted only for events occurring within the active 24-hour window provided by DefiLlama.
  • Closing actions and fees are excluded.
  • No off-chain data sources are used.

Chains

  • BSC

Notes

  • Volume reflects opening volume only.
  • This adapter does not attempt to estimate liquidity movement inside PancakeSwap v3 pools after vault creation.

Checklist

  • Tested locally using pnpm test dexs calculus
  • No additional dependencies added
  • No lockfile changes
  • Allow edits by maintainers enabled

Summary by CodeRabbit

  • New Features
    • Added daily opening volume data for Calculus decentralized exchange on Binance Smart Chain.
  • Documentation
    • Included methodology/metadata describing how daily opening volume is derived from on-chain VaultCreated events.

Add Calculus DEX volume adapter on BSC
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 2, 2026

📝 Walkthrough

Walkthrough

A new TypeScript adapter for the Calculus DEX on BSC was added, computing daily opening volume by processing VaultCreated events, resolving token pair addresses via TOKENPAIR_REGISTRY multiCall (IDs 1–18), and aggregating reserves per token.

Changes

Cohort / File(s) Summary
Calculus DEX Adapter
dexs/calculus/index.ts
Added a v2 Adapter implementing a FetchV2 function for BSC: queries TOKENPAIR_REGISTRY (IDs 1–18) via multiCall to map pairId→token addresses, fetches VaultCreated logs from CALCULUS_CONTRACT, and aggregates reserve0/reserve1 into a dailyVolume balances object. Exports adapter with metadata and start timestamp.

Sequence Diagram

sequenceDiagram
    participant Adapter as Fetch Function
    participant Registry as TOKENPAIR_REGISTRY
    participant Contract as CALCULUS_CONTRACT
    participant Balances as DailyVolume Accumulator

    Adapter->>Balances: Initialize daily balances
    Adapter->>Registry: multiCall token pairs (IDs 1-18)
    Registry-->>Adapter: Return token0, token1 per pairId
    Adapter->>Adapter: Build pairId → {token0, token1} map
    Adapter->>Contract: Fetch VaultCreated event logs (filtered)
    Contract-->>Adapter: Return VaultCreated logs
    loop For each VaultCreated log
        Adapter->>Adapter: Resolve token addresses via pairId
        Adapter->>Balances: Add reserve0 to token0
        Adapter->>Balances: Add reserve1 to token1
    end
    Adapter-->>Adapter: Return dailyVolume object
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • treeoflife2

Poem

🐰 Hopped through logs at break of day,
Pair IDs mapped in tidy array,
Reserves collected, tokens cheer,
BSC volumes hop into the mirror,
A little rabbit counts them clear.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add Calculus DEX volume adapter on BSC' accurately summarizes the main change—introducing a DEX volume adapter for the Calculus protocol on the BSC chain.
Description check ✅ Passed The PR description includes a clear overview, detailed volume methodology, supported chains, and important notes. While it does not follow the optional template fields for TVL/protocol listing (which are not applicable for a volume adapter), it provides all necessary context and documentation for the code changes.
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

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Reviews will stop working after February 8, 2026 if the new IP is not added to your allowlist.


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

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

🦙 Running CALCULUS adapter 🦙
---------------------------------------------------
Start Date:	Sun, 01 Feb 2026 08:48:55 GMT
End Date:	Mon, 02 Feb 2026 08:48:55 GMT
---------------------------------------------------

BSC 👇
Backfill start time: 1/11/2025
Daily volume: 4.23 k
End timestamp: 1770022134 (2026-02-02T08:48:54.000Z)

@treeoflife2 treeoflife2 self-assigned this Feb 3, 2026
Copy link
Member

@treeoflife2 treeoflife2 left a comment

Choose a reason for hiding this comment

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

.


export default {
version: 2,
adapter: {
Copy link
Member

Choose a reason for hiding this comment

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

please add doublecounted: true as behind the scenes it's using the panckeswap lp for trades

if (!pair) continue;

dailyVolume.add(pair.token0, l.reserve0);
dailyVolume.add(pair.token1, l.reserve1);
Copy link
Member

Choose a reason for hiding this comment

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

why do you add both tokens in volume calc?

@llamabutler
Copy link

The calculus adapter exports:

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

🦙 Running CALCULUS adapter 🦙
---------------------------------------------------
Start Date:	Tue, 03 Feb 2026 05:10:36 GMT
End Date:	Wed, 04 Feb 2026 05:10:36 GMT
---------------------------------------------------

BSC 👇
Backfill start time: 1/11/2025
Daily volume: 12.87 k
End timestamp: 1770181835 (2026-02-04T05:10:35.000Z)

@calculusfinanceofficial
Copy link
Contributor Author

calculusfinanceofficial commented Feb 4, 2026 via email

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