Skip to content

Commit cdf8eac

Browse files
authored
feat: add Kensei adapter for tracking total trading volume (#4585)
1 parent e4cb48f commit cdf8eac

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

dexs/kensei/index.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { Dependencies, FetchOptions, SimpleAdapter } from '../../adapters/types';
2+
import { CHAIN } from '../../helpers/chains';
3+
import { queryDuneSql } from '../../helpers/dune';
4+
5+
const fetch = async (_a:any, _b:any, options: FetchOptions) => {
6+
const query = `
7+
WITH buy_volume AS (
8+
SELECT SUM(usd_in) AS total_buy_usd
9+
FROM query_5971327
10+
WHERE block_time >= from_unixtime(${options.startTimestamp})
11+
AND block_time < from_unixtime(${options.endTimestamp})
12+
),
13+
sell_volume AS (
14+
SELECT SUM(usd_out) AS total_sell_usd
15+
FROM query_5971367
16+
WHERE block_time >= from_unixtime(${options.startTimestamp})
17+
AND block_time < from_unixtime(${options.endTimestamp})
18+
)
19+
SELECT
20+
COALESCE(b.total_buy_usd, 0) + COALESCE(s.total_sell_usd, 0) AS total_volume_usd
21+
FROM buy_volume b
22+
CROSS JOIN sell_volume s;
23+
`
24+
25+
let dailyVolume = options.createBalances()
26+
const result = await queryDuneSql(options, query)
27+
28+
if (result && result.length > 0) {
29+
dailyVolume.addUSDValue(result[0].total_volume_usd)
30+
}
31+
32+
return { dailyVolume }
33+
}
34+
35+
const adapter: SimpleAdapter = {
36+
version: 1,
37+
fetch,
38+
chains: [CHAIN.KATANA],
39+
start: '2025-10-16',
40+
dependencies: [Dependencies.DUNE],
41+
isExpensiveAdapter: true,
42+
}
43+
44+
export default adapter

0 commit comments

Comments
 (0)