Skip to content

Commit b89cb93

Browse files
feat: now tracking fees and revenue of drift staked sol (DefiLlama#3814)
* feat: now tracking fees and revenue of drift staked sol * Drift correct Revenue and Fees, and merged dune query --------- Co-authored-by: treeoflife2 <sol.analyzoor@gmail.com>
1 parent d883570 commit b89cb93

File tree

3 files changed

+116
-26
lines changed

3 files changed

+116
-26
lines changed

fees/drift-staked-sol/index.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Source: https://solanacompass.com/stake-pools/9mhGNSPArRMHpLDMSmxAvuoizBqtBGqYdT8WGuqgxNdn
2+
3+
import { FetchOptions } from "../../adapters/types";
4+
import { CHAIN } from "../../helpers/chains";
5+
import { getSqlFromFile, queryDuneSql } from "../../helpers/dune";
6+
import ADDRESSES from "../../helpers/coreAssets.json";
7+
8+
const DRIFT_STAKE_POOL_AUTHORITY = "6727ZvQ2YEz8jky1Z9fqDFG5mYuAvC9G34o2MxwzmrUK";
9+
const STAKE_POOL_RESERVE_ACCOUNT = "4RjzgujRmdadbLjyh2L1Qn5ECsQ1qfjaapTfeWKYtsC3";
10+
const LST_FEE_TOKEN_ACCOUNT = "5NJUMVJPVxN5huLKQ7tNxBv7LHxHDLwREUym5ekfdSgD";
11+
const LST_MINT = ADDRESSES.solana.DRIFTSOL;
12+
13+
const fetch = async (_a: any, _b: any, options: FetchOptions) => {
14+
const query = getSqlFromFile("helpers/queries/solana-liquid-staking-fees.sql", {
15+
start: options.startTimestamp,
16+
end: options.endTimestamp,
17+
stake_account: STAKE_POOL_RESERVE_ACCOUNT,
18+
authority: DRIFT_STAKE_POOL_AUTHORITY,
19+
LST_FEE_TOKEN_ACCOUNT: LST_FEE_TOKEN_ACCOUNT,
20+
LST_MINT: LST_MINT
21+
});
22+
23+
const results = await queryDuneSql(options, query);
24+
25+
const dailyFees = options.createBalances();
26+
const dailyRevenue = options.createBalances();
27+
28+
results.forEach((row: any) => {
29+
if (row.metric_type === 'dailyFees') {
30+
dailyFees.addCGToken("drift-staked-sol", row.amount || 0);
31+
} else if (row.metric_type === 'dailyRevenue') {
32+
dailyRevenue.addCGToken("drift-staked-sol", row.amount || 0);
33+
}
34+
});
35+
36+
return {
37+
dailyFees,
38+
dailyRevenue,
39+
dailyProtocolRevenue: dailyRevenue
40+
};
41+
};
42+
43+
const meta = {
44+
methodology: {
45+
Fees: 'Staking rewards from staked SOL on drift staked solana',
46+
Revenue: 'Includes withdrawal fees and management fees collected by fee collector',
47+
ProtocolRevenue: 'Revenue going to treasury/team',
48+
}
49+
}
50+
51+
export default {
52+
version: 1,
53+
adapter: {
54+
[CHAIN.SOLANA]: {
55+
fetch,
56+
start: "2024-08-26",
57+
meta
58+
}
59+
},
60+
isExpensiveAdapter: true
61+
};

helpers/coreAssets.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,9 @@
600600
"BUSDbs": "5RpUwQ8wtdPCZHhu6MERp2RGrpobsbZ6MH5dDHkUjs2",
601601
"VSOL": "vSoLxydx6akxyMD9XEcPvGYNGq6Nn66oqVb3UkGkei7",
602602
"PUMP": "pumpCmXqMfrsAkQ5r49WcJnRayYRqmXz6ae8H7H9Dfn",
603-
"JUP": "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN"
603+
"JUP": "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN",
604+
"BSOL": "bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1",
605+
"DRIFTSOL": "Dso1bDeDjCQxTrWHqUUi63oBvV7Mdm6WaobLbQ7gnPQ"
604606
},
605607
"astar": {
606608
"WASTR_1": "0xaeaaf0e2c81af264101b9129c00f4440ccf0f720",
Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,53 @@
1-
WITH stake_accounts AS (
2-
SELECT
3-
d.stake_account_raw,
4-
d.vote_account_raw,
5-
a.authority
6-
FROM dune.dune.result_solana_stake_accounts_vote_delegates AS d
7-
LEFT JOIN dune.dune.result_solana_stake_accounts_authorities AS a
8-
ON d.stake_account_raw = a.stake_account_raw
9-
WHERE
10-
d.latest = 1
11-
AND a.latest = 1
12-
AND a.authority = '{{authority}}'
13-
UNION ALL
14-
SELECT
15-
'{{stake_account}}' AS stake_account_raw,
16-
NULL AS vote_account_raw,
17-
NULL AS authority
1+
WITH
2+
stake_accounts AS (
3+
SELECT
4+
d.stake_account_raw,
5+
d.vote_account_raw,
6+
a.authority
7+
FROM
8+
dune.dune.result_solana_stake_accounts_vote_delegates AS d
9+
LEFT JOIN dune.dune.result_solana_stake_accounts_authorities AS a ON d.stake_account_raw=a.stake_account_raw
10+
WHERE
11+
d.latest=1
12+
AND a.latest=1
13+
AND a.authority='{{authority}}'
14+
UNION ALL
15+
SELECT
16+
'{{stake_account}}' AS stake_account_raw,
17+
NULL AS vote_account_raw,
18+
NULL AS authority
19+
),
20+
staking_fees AS (
21+
SELECT
22+
'dailyFees' as metric_type,
23+
sum(lamports/1e9) as amount
24+
FROM
25+
stake_accounts sa
26+
LEFT JOIN solana.rewards r on r.recipient=sa.stake_account_raw
27+
AND r.reward_type='Staking'
28+
AND r.block_time>=from_unixtime({{start}})
29+
AND r.block_time<=from_unixtime({{end}})
30+
),
31+
revenue_fees AS (
32+
SELECT
33+
'dailyRevenue' as metric_type,
34+
SUM(amount)/POW(10, 9) as amount
35+
FROM
36+
tokens_solana.transfers
37+
WHERE
38+
to_token_account='{{LST_FEE_TOKEN_ACCOUNT}}'
39+
AND token_mint_address='{{LST_MINT}}'
40+
AND block_time>=from_unixtime({{start}})
41+
AND block_time<=from_unixtime({{end}})
1842
)
19-
SELECT
20-
sum(lamports/1e9) as daily_yield
21-
FROM stake_accounts sa
22-
LEFT JOIN solana.rewards r
23-
on r.recipient = sa.stake_account_raw
24-
AND r.reward_type = 'Staking'
25-
AND r.block_time >= from_unixtime({{start}})
26-
AND r.block_time < from_unixtime({{end}})
43+
SELECT
44+
metric_type,
45+
COALESCE(amount, 0) as amount
46+
FROM
47+
staking_fees
48+
UNION ALL
49+
SELECT
50+
metric_type,
51+
COALESCE(amount, 0) as amount
52+
FROM
53+
revenue_fees

0 commit comments

Comments
 (0)