-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(kinetiq-markets) - dedupe builder-routed HIP-3 volume #9064
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,31 @@ | ||
| import { FetchOptions, SimpleAdapter } from "../adapters/types"; | ||
| import { CHAIN } from "../helpers/chains"; | ||
| import { fetchBuilderCodeRevenue, fetchHIP3DeployerData } from "../helpers/hyperliquid"; | ||
| import { FetchOptions, SimpleAdapter } from "../adapters/types"; | ||
|
|
||
| const KINETIQ_MARKETS_LEGACY_END_DATE = "2026-06-20"; | ||
| const KINETIQ_MARKETS_BUILDER_ADDRESS = '0x42f3226007290b02c5a0b15bccbb1ba6df04f992'; | ||
|
|
||
| const fetch = async (options: FetchOptions) => { | ||
| const deployerId = options.dateString > KINETIQ_MARKETS_LEGACY_END_DATE ? 'mkts' : 'km'; | ||
| const { dailyVolume: builderVolume, dailyFees: builderFees } = await fetchBuilderCodeRevenue({ | ||
| options, | ||
| builder_address: '0x42f3226007290b02c5a0b15bccbb1ba6df04f992', | ||
| builder_address: KINETIQ_MARKETS_BUILDER_ADDRESS, | ||
| }); | ||
|
|
||
| const builderHip3OverlapVolume = options.createBalances(); | ||
|
|
||
| // No builder activity means the builder/HIP-3 intersection is necessarily zero. | ||
| if (await builderVolume.getUSDValue()) { | ||
| const { dailyVolume: builderHip3Volume } = await fetchBuilderCodeRevenue({ | ||
| options, | ||
| builder_address: KINETIQ_MARKETS_BUILDER_ADDRESS, | ||
| market: 'hip3', | ||
| hip3DeployerId: deployerId, | ||
| }); | ||
|
Comment on lines
+19
to
+24
Contributor
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. 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- relevant knowledge scopes ---'
find /tmp/coderabbit-repo-knowledge/defillama-dimension-adapters-a02d4e4d \
-maxdepth 2 -type f \( -path '*/learnings/*' -o -path '*/architecture/*' -o -path '*/conventions/*' \) \
-print | sort | while IFS= read -r f; do
printf '\n### %s\n' "$f"
head -80 "$f"
done
printf '\n--- adapter ---\n'
cat -n dexs/kinetiq-markets.ts
printf '\n--- helper definitions and references ---\n'
rg -n -g '*.ts' 'fetchBuilderCodeRevenue|LLAMA_HL_INDEXER|builder_fills|hip3DeployerId' .Repository: DefiLlama/dimension-adapters Length of output: 50384 🏁 Script executed: #!/bin/bash
set -eu
log=/tmp/coderabbit-shell-logs/shell-output-v5tOo4
printf '%s\n' '--- prior output: adapter/helper matches ---'
rg -n -C 12 'kinetiq-markets|fetchBuilderCodeRevenue|LLAMA_HL_INDEXER|builder_fills|hip3DeployerId' "$log" | head -240
printf '\n%s\n' '--- tracked files containing the helper ---'
rg -l -g '*.ts' 'export .*fetchBuilderCodeRevenue|function fetchBuilderCodeRevenue|const fetchBuilderCodeRevenue' . | sort
printf '\n%s\n' '--- adapter source ---'
cat -n dexs/kinetiq-markets.tsRepository: DefiLlama/dimension-adapters Length of output: 15008 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- hyperliquid helper ---'
cat -n helpers/hyperliquid.ts | sed -n '1,190p'
printf '\n%s\n' '--- fetchURL/fetchJson helper declarations used by hyperliquid.ts ---'
rg -n -C 8 'fetchURL|fetchJson|response\.ok|statusText|HTTP|throw new Error' helpers/hyperliquid.ts helpers adapters | head -260Repository: DefiLlama/dimension-adapters Length of output: 24631 Add an indexer-backed HIP-3 breakdown or fallback. When 🤖 Prompt for AI Agents |
||
|
|
||
| builderHip3OverlapVolume.add(builderHip3Volume); | ||
| } | ||
|
|
||
| const { dailyPerpVolume: hip3Volume, dailyPerpFee: hip3Fees, dailyDeployerFee: hip3DeployerFee } = await fetchHIP3DeployerData({ | ||
| options, | ||
| hip3DeployerId: deployerId, | ||
|
|
@@ -21,6 +37,7 @@ const fetch = async (options: FetchOptions) => { | |
| const dailySupplySideRevenue = options.createBalances(); | ||
|
|
||
| dailyVolume.add(builderVolume); | ||
| dailyVolume.subtract(builderHip3OverlapVolume); | ||
| dailyVolume.add(hip3Volume); | ||
|
|
||
| // Builder-code fees are retained entirely by Kinetiq. | ||
|
|
@@ -49,6 +66,7 @@ const adapter: SimpleAdapter = { | |
| start: '2025-12-16', | ||
| doublecounted: true, | ||
| methodology: { | ||
| Volume: "Unique trading volume routed through Kinetiq Markets' builder code or executed on Kinetiq's HIP-3 markets. Builder-routed trades on Kinetiq's own HIP-3 markets are counted once.", | ||
| Fees: "Trading fees paid by users on Hyperliquid via Kinetiq's builder code and its HIP-3 markets.", | ||
| Revenue: "Builder-code fees (retained by Kinetiq) plus Kinetiq's deployer-fee cut of its HIP-3 market fees.", | ||
| ProtocolRevenue: "Same as Revenue — retained by Kinetiq.", | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,14 +1,14 @@ | ||||||||||||||||||||||||||||||||||||||||||
| import { FetchOptions, SimpleAdapter } from "../adapters/types"; | ||||||||||||||||||||||||||||||||||||||||||
| import * as fs from "fs"; | ||||||||||||||||||||||||||||||||||||||||||
| import * as path from "path"; | ||||||||||||||||||||||||||||||||||||||||||
| import { Balances } from "@defillama/sdk"; | ||||||||||||||||||||||||||||||||||||||||||
| import axios from "axios"; | ||||||||||||||||||||||||||||||||||||||||||
| import * as fs from "fs"; | ||||||||||||||||||||||||||||||||||||||||||
| import { decompressFrame } from "lz4-napi"; | ||||||||||||||||||||||||||||||||||||||||||
| import { getEnv } from "./env"; | ||||||||||||||||||||||||||||||||||||||||||
| import * as path from "path"; | ||||||||||||||||||||||||||||||||||||||||||
| import { FetchOptions, SimpleAdapter } from "../adapters/types"; | ||||||||||||||||||||||||||||||||||||||||||
| import { httpGet, httpPost } from "../utils/fetchURL"; | ||||||||||||||||||||||||||||||||||||||||||
| import { formatAddress, sleep } from "../utils/utils"; | ||||||||||||||||||||||||||||||||||||||||||
| import { Balances } from "@defillama/sdk"; | ||||||||||||||||||||||||||||||||||||||||||
| import { findClosest } from "./utils/findClosest"; | ||||||||||||||||||||||||||||||||||||||||||
| import { CHAIN } from "./chains"; | ||||||||||||||||||||||||||||||||||||||||||
| import { getEnv } from "./env"; | ||||||||||||||||||||||||||||||||||||||||||
| import { findClosest } from "./utils/findClosest"; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export type HyperliquidMarket = "all" | "hip3" | "hip4"; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -33,17 +33,23 @@ export const fetchBuilderCodeRevenue = async ({ | |||||||||||||||||||||||||||||||||||||||||
| options, | ||||||||||||||||||||||||||||||||||||||||||
| builder_address, | ||||||||||||||||||||||||||||||||||||||||||
| market = "all", | ||||||||||||||||||||||||||||||||||||||||||
| hip3DeployerId, | ||||||||||||||||||||||||||||||||||||||||||
| }: { | ||||||||||||||||||||||||||||||||||||||||||
| options: FetchOptions; | ||||||||||||||||||||||||||||||||||||||||||
| builder_address: string; | ||||||||||||||||||||||||||||||||||||||||||
| market?: HyperliquidMarket; | ||||||||||||||||||||||||||||||||||||||||||
| hip3DeployerId?: string; | ||||||||||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+36
to
42
Contributor
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. 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win Document the new public parameter.
As per coding guidelines, “Include JSDoc comments for public helper functions.” Suggested documentation+/**
+ * Fetch builder-code fees and volume.
+ * `@param` hip3DeployerId Restricts results to `{hip3DeployerId}:...` HIP-3 coins.
+ * Requires `market: "hip3"`.
+ */
export const fetchBuilderCodeRevenue = async ({📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Coding guidelines |
||||||||||||||||||||||||||||||||||||||||||
| const startTimestamp = options.startOfDay; | ||||||||||||||||||||||||||||||||||||||||||
| const dailyFees = options.createBalances(); | ||||||||||||||||||||||||||||||||||||||||||
| const dailyVolume = options.createBalances(); | ||||||||||||||||||||||||||||||||||||||||||
| const isHIP3Market = market === "hip3"; | ||||||||||||||||||||||||||||||||||||||||||
| const isHIP4Market = market === "hip4"; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if (hip3DeployerId && !isHIP3Market) { | ||||||||||||||||||||||||||||||||||||||||||
| throw new Error("hip3DeployerId requires market='hip3'"); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // try with llama hl indexer | ||||||||||||||||||||||||||||||||||||||||||
| const endpoint = getEnv("LLAMA_HL_INDEXER"); | ||||||||||||||||||||||||||||||||||||||||||
| if (market === "all" && startTimestamp >= LLAMA_HL_INDEXER_FROM_TIME && endpoint) { | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -143,6 +149,9 @@ export const fetchBuilderCodeRevenue = async ({ | |||||||||||||||||||||||||||||||||||||||||
| if (isHIP3Market && !coin?.includes(":")) { | ||||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if (hip3DeployerId && !coin?.startsWith(`${hip3DeployerId}:`)) { | ||||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if (isHIP4Market && !/^#\d+$/.test(coin)) { | ||||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
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.
📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
Document the migration boundary and protocol address.
The new migration date,
km/mktsnamespace values, and builder address are hardcoded without explaining their provenance. Add comments that state the migration rule and address source.As per coding guidelines, “Document every hardcoded rate, address, or magic number with a comment and, where possible, a source link.”
Suggested documentation
Also applies to: 9-9
🤖 Prompt for AI Agents
Source: Coding guidelines