Add Calculus DEX volume adapter on BSC#5797
Add Calculus DEX volume adapter on BSC#5797calculusfinanceofficial wants to merge 2 commits intoDefiLlama:masterfrom
Conversation
Add Calculus DEX volume adapter on BSC
📝 WalkthroughWalkthroughA 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
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
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)
Important Action Needed: IP Allowlist UpdateIf your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:
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. Comment |
|
The calculus adapter exports: |
|
|
||
| export default { | ||
| version: 2, | ||
| adapter: { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
why do you add both tokens in volume calc?
|
The calculus adapter exports: |
|
Hi,
Thanks for the review and the comments.
We have just pushed a new commit adding:
`doublecounted: true`
to the Calculus volume adapter as requested.
Regarding the question about why both tokens are added in the volume
calculation:
Calculus is an LP management protocol built on top of PancakeSwap V3. When
a vault is created, the `reserve0` and `reserve1` values represent the
two-sided liquidity added to the underlying PancakeSwap pool. From our
perspective, this reflects the full notional trading activity involved in
opening the LP position.
Since this volume is derived from PancakeSwap LP activity and counts both
sides of the pair, we marked the adapter as `doublecounted: true` to make
this explicit and avoid any ambiguity.
Please let us know if you would prefer a single-sided volume representation
instead, and we can adjust the logic accordingly.
Best regards,
Calculus Team
…On Tue, Feb 3, 2026 at 9:59 PM tree ***@***.***> wrote:
***@***.**** requested changes on this pull request.
.
------------------------------
In dexs/calculus/index.ts
<#5797 (comment)>
:
> + // 3) Sum reserve0 / reserve1 as opening volume
+ for (const l of logs as any[]) {
+ const tokenPairId = Number(l.tokenPairId ?? l.args?.tokenPairId);
+ const pair = pairIdToTokens.get(tokenPairId);
+ if (!pair) continue;
+
+ dailyVolume.add(pair.token0, l.reserve0);
+ dailyVolume.add(pair.token1, l.reserve1);
+ }
+
+ return { dailyVolume };
+};
+
+export default {
+ version: 2,
+ adapter: {
please add doublecounted: true as behind the scenes it's using the
panckeswap lp for trades
------------------------------
In dexs/calculus/index.ts
<#5797 (comment)>
:
> + }
+ });
+
+ const logs = await getLogs({
+ target: CALCULUS_CONTRACT,
+ eventAbi: VAULT_CREATED_EVENT,
+ });
+
+ // 3) Sum reserve0 / reserve1 as opening volume
+ for (const l of logs as any[]) {
+ const tokenPairId = Number(l.tokenPairId ?? l.args?.tokenPairId);
+ const pair = pairIdToTokens.get(tokenPairId);
+ if (!pair) continue;
+
+ dailyVolume.add(pair.token0, l.reserve0);
+ dailyVolume.add(pair.token1, l.reserve1);
why do you add both tokens in volume calc?
—
Reply to this email directly, view it on GitHub
<#5797 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/B474IYTCQZG3HZF7IU2EJA34KCSTHAVCNFSM6AAAAACTVM2JV2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTONBVGQZTENBTGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
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
VaultCreatedevent:reserve0andreserve1emitted during vault creation are treated as opening trade volume.Chains
Notes
Checklist
pnpm test dexs calculusSummary by CodeRabbit