Skip to content

Commit d43ade3

Browse files
vitusha-ratg1nt0ki
andauthored
Add lab-terminal adapter (#4135)
* added daily fees & daily volume adapter for lab terminal * marked as expensive adapter * merge queries * minor fix --------- Co-authored-by: g1nt0ki <[email protected]>
1 parent ede30d6 commit d43ade3

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

fees/lab-terminal.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import ADDRESSES from "../helpers/coreAssets.json";
2+
import { FetchOptions, SimpleAdapter } from "../adapters/types";
3+
import { CHAIN } from "../helpers/chains";
4+
import { queryDuneSql } from "../helpers/dune";
5+
6+
const fetch: any = async (_: any, _1: any, options: FetchOptions) => {
7+
const dailyFees = options.createBalances();
8+
const dailyVolume = options.createBalances();
9+
const FEE_WALLET = "Eno27Pu6ok2nNwLTgNCLnFmY2YxQsAXecmrnnLvJeFYh";
10+
11+
const combinedQuery = `
12+
WITH
13+
allFeePayments AS (
14+
SELECT
15+
tx_id,
16+
balance_change
17+
FROM
18+
solana.account_activity
19+
WHERE
20+
block_time >= from_unixtime(${options.startTimestamp})
21+
AND block_time <= from_unixtime(${options.endTimestamp})
22+
AND tx_success
23+
AND address = '${FEE_WALLET}'
24+
AND balance_change > 0
25+
),
26+
botTrades AS (
27+
SELECT
28+
trades.tx_id,
29+
IF(
30+
token_sold_mint_address = 'So11111111111111111111111111111111111111112',
31+
token_sold_amount,
32+
token_bought_amount
33+
) AS amount_usd
34+
FROM
35+
dex_solana.trades AS trades
36+
JOIN allFeePayments AS feePayments ON trades.tx_id = feePayments.tx_id
37+
WHERE
38+
trades.block_time >= from_unixtime(${options.startTimestamp})
39+
AND trades.block_time <= from_unixtime(${options.endTimestamp})
40+
AND trades.trader_id != '${FEE_WALLET}'
41+
)
42+
SELECT
43+
COALESCE(SUM(allFeePayments.balance_change), 0) AS daily_fees,
44+
COALESCE(SUM(botTrades.amount_usd), 0) AS volume
45+
FROM
46+
allFeePayments
47+
LEFT JOIN botTrades ON allFeePayments.tx_id = botTrades.tx_id
48+
`;
49+
50+
const res = await queryDuneSql(options, combinedQuery);
51+
dailyFees.add(ADDRESSES.solana.SOL, res[0].daily_fees);
52+
dailyVolume.add(ADDRESSES.solana.SOL, res[0].volume * 1e9);
53+
54+
return {
55+
dailyFees,
56+
// dailyRevenue: dailyFees, // skipping these for now as we are not excluding amount for referrals
57+
// dailyProtocolRevenue: dailyFees,
58+
dailyVolume,
59+
};
60+
};
61+
62+
const adapter: SimpleAdapter = {
63+
chains: [CHAIN.SOLANA],
64+
fetch,
65+
start: "2025-06-29",
66+
isExpensiveAdapter: true,
67+
methodology: {
68+
Fees: "Trading tokens fees paid by users",
69+
// ProtocolRevenue: "Trading fees are collected by Lab Terminal",
70+
// Revenue: "Trading fees are collected by Lab Terminal",
71+
},
72+
};
73+
74+
export default adapter;

0 commit comments

Comments
 (0)