-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add Calculus DEX volume adapter on BSC #5797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
calculusfinanceofficial
wants to merge
2
commits into
DefiLlama:master
Choose a base branch
from
calculusfinanceofficial:patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+67
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import type { Adapter, FetchV2 } from "../../adapters/types"; | ||
| import { CHAIN } from "../../helpers/chains"; | ||
|
|
||
| const CALCULUS_CONTRACT = "0xb5e6AdA1466840096FcEDCC409528a9cB763f650"; | ||
| const TOKENPAIR_REGISTRY = "0x497f6e7eF1C0ad1E44A2DF48ee15Fa3B748EE2c6"; | ||
|
|
||
| const START_TS = 1761980058; | ||
|
|
||
| const VAULT_CREATED_EVENT = | ||
| "event VaultCreated(uint64 indexed operationNonce, uint16 tokenPairId, uint32 vaultId, uint256 reserve0, uint256 reserve1, address operator, tuple(uint16 strategyId, bytes metadata) strategy)"; | ||
|
|
||
| const getTokenPairAddressesAbi = | ||
| "function getTokenPairAddresses(uint16 _id) external view returns (address, address)"; | ||
|
|
||
| const fetch: FetchV2 = async ({ getLogs, createBalances, api }) => { | ||
| const dailyVolume = createBalances(); | ||
|
|
||
| const pairIds = Array.from({ length: 18 }, (_, i) => i + 1); | ||
|
|
||
| const pairs = await api.multiCall({ | ||
| abi: getTokenPairAddressesAbi, | ||
| target: TOKENPAIR_REGISTRY, | ||
| calls: pairIds.map((id) => ({ params: [id] })), | ||
| }); | ||
|
|
||
| const pairIdToTokens = new Map<number, { token0: string; token1: string }>(); | ||
| pairIds.forEach((id, i) => { | ||
| const [token0, token1] = pairs[i] as any; | ||
| if (token0 && token1) { | ||
| pairIdToTokens.set(id, { token0, token1 }); | ||
| } | ||
| }); | ||
|
|
||
| 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); | ||
| } | ||
|
|
||
| return { dailyVolume }; | ||
| }; | ||
|
|
||
| export default { | ||
| version: 2, | ||
| adapter: { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| [CHAIN.BSC]: { | ||
| fetch, | ||
| start: START_TS, | ||
| doublecounted: true, | ||
| meta: { | ||
| methodology: { | ||
| Volume: | ||
| "Daily opening volume is calculated from the VaultCreated event by summing reserve0 and reserve1, mapped to their corresponding token addresses via tokenPairId. This represents user capital inflow when opening managed LP vaults.", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } as Adapter; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?