Skip to content

Commit 262246f

Browse files
henrystatsbheluga
andauthored
add omnipair borrow interest (#6329)
* add omnipair borrow interest * reuse existing metric --------- Co-authored-by: bheluga <bheluga@defillama.com>
1 parent 728c055 commit 262246f

File tree

1 file changed

+58
-14
lines changed

1 file changed

+58
-14
lines changed

dexs/omnipair/index.ts

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,101 @@ import { METRIC } from "../../helpers/metrics";
66
async function fetch(_a: any, _b: any, options: FetchOptions) {
77
const query = `
88
select
9-
token_in_mint,
9+
token_mint,
1010
cast(daily_volume as varchar) as daily_volume,
1111
cast(daily_fees as varchar) as daily_fees,
12+
cast(daily_user_fees as varchar) as daily_user_fees,
1213
cast(daily_revenue as varchar) as daily_revenue,
1314
cast(daily_protocol_revenue as varchar) as daily_protocol_revenue,
14-
cast(daily_supply_side_revenue as varchar) as daily_supply_side_revenue
15-
from query_6897800
15+
cast(daily_supply_side_revenue as varchar) as daily_supply_side_revenue,
16+
cast(swap_fees_total as varchar) as swap_fees_total,
17+
cast(swap_fees_protocol as varchar) as swap_fees_protocol,
18+
cast(swap_fees_lp as varchar) as swap_fees_lp,
19+
cast(borrow_interest_total as varchar) as borrow_interest_total,
20+
cast(borrow_interest_protocol as varchar) as borrow_interest_protocol,
21+
cast(borrow_interest_lp as varchar) as borrow_interest_lp
22+
from query_6940593
1623
where block_date = cast(from_unixtime(${options.startOfDay}) as date)
1724
`
1825
const data = await queryDuneSql(options, query)
1926

2027
const dailyVolume = options.createBalances()
2128
const dailyFees = options.createBalances()
29+
const dailyUserFees = options.createBalances()
2230
const dailyRevenue = options.createBalances()
31+
const dailyProtocolRevenue = options.createBalances()
2332
const dailySupplySideRevenue = options.createBalances()
2433

2534
data.forEach(row => {
26-
dailyVolume.add(row.token_in_mint, row.daily_volume)
27-
dailyFees.add(row.token_in_mint, row.daily_fees, METRIC.SWAP_FEES)
28-
dailyRevenue.add(row.token_in_mint, row.daily_revenue, METRIC.SWAP_FEES)
29-
dailySupplySideRevenue.add(row.token_in_mint, row.daily_supply_side_revenue, METRIC.SWAP_FEES)
35+
dailyVolume.add(row.token_mint, row.daily_volume)
36+
37+
if (row.swap_fees_total !== '0') {
38+
dailyFees.add(row.token_mint, row.swap_fees_total, METRIC.SWAP_FEES)
39+
dailyUserFees.add(row.token_mint, row.swap_fees_total, METRIC.SWAP_FEES)
40+
}
41+
42+
if (row.swap_fees_protocol !== '0') {
43+
dailyRevenue.add(row.token_mint, row.swap_fees_protocol, METRIC.SWAP_FEES)
44+
dailyProtocolRevenue.add(row.token_mint, row.swap_fees_protocol, METRIC.SWAP_FEES)
45+
}
46+
47+
if (row.swap_fees_lp !== '0') {
48+
dailySupplySideRevenue.add(row.token_mint, row.swap_fees_lp, METRIC.SWAP_FEES)
49+
}
50+
51+
if (row.borrow_interest_total !== '0') {
52+
dailyFees.add(row.token_mint, row.borrow_interest_total, METRIC.BORROW_INTEREST)
53+
dailyUserFees.add(row.token_mint, row.borrow_interest_total, METRIC.BORROW_INTEREST)
54+
}
55+
56+
if (row.borrow_interest_protocol !== '0') {
57+
dailyRevenue.add(row.token_mint, row.borrow_interest_protocol, METRIC.BORROW_INTEREST)
58+
dailyProtocolRevenue.add(row.token_mint, row.borrow_interest_protocol, METRIC.BORROW_INTEREST)
59+
}
60+
61+
if (row.borrow_interest_lp !== '0') {
62+
dailySupplySideRevenue.add(row.token_mint, row.borrow_interest_lp, METRIC.BORROW_INTEREST)
63+
}
3064
})
3165

3266
return {
3367
dailyVolume,
3468
dailyFees,
69+
dailyUserFees,
3570
dailyRevenue,
36-
dailyProtocolRevenue: dailyRevenue,
71+
dailyProtocolRevenue,
3772
dailySupplySideRevenue,
3873
}
3974
}
4075

4176
const methodology = {
42-
Fees: "All swap fees paid by users on Omnipair. Computed from Dune as lp_fee + protocol_fee, grouped by input token mint.",
43-
Revenue: "Protocol revenue equals the protocol_fee portion of swap fees.",
44-
ProtocolRevenue: "Protocol revenue equals the protocol_fee portion of swap fees.",
45-
SupplySideRevenue: "Supply-side revenue equals the lp_fee portion distributed to liquidity providers.",
77+
Fees: "All swap fees and borrow interest paid by users on Omnipair. Swap fees are computed as lp_fee + protocol_fee. Borrow interest is computed from UpdatePairEvent accrued_interest fields.",
78+
UserFees: "All swap fees and borrow interest paid directly by users on Omnipair.",
79+
Revenue: "Protocol revenue equals the protocol share of swap fees plus the protocol share of borrow interest.",
80+
ProtocolRevenue: "Protocol revenue equals the protocol share of swap fees plus the protocol share of borrow interest.",
81+
SupplySideRevenue: "Supply-side revenue equals the LP share of swap fees plus the LP share of borrow interest.",
4682
};
4783

4884
const breakdownMethodology = {
4985
Fees: {
50-
[METRIC.SWAP_FEES]: "All swap fees paid by users on Omnipair",
86+
[METRIC.SWAP_FEES]: "All swap fees paid by users on Omnipair.",
87+
[METRIC.BORROW_INTEREST]: "All interest paid by borrowers on Omnipair.",
88+
},
89+
UserFees: {
90+
[METRIC.SWAP_FEES]: "All swap fees paid by users on Omnipair.",
91+
[METRIC.BORROW_INTEREST]: "All interest paid by borrowers on Omnipair.",
5192
},
5293
Revenue: {
5394
[METRIC.SWAP_FEES]: "The protocol_fee portion of swap fees.",
95+
[METRIC.BORROW_INTEREST]: "The protocol share of borrow interest.",
5496
},
5597
ProtocolRevenue: {
5698
[METRIC.SWAP_FEES]: "The protocol_fee portion of swap fees.",
99+
[METRIC.BORROW_INTEREST]: "The protocol share of borrow interest.",
57100
},
58101
SupplySideRevenue: {
59102
[METRIC.SWAP_FEES]: "The lp_fee portion of swap fees distributed to liquidity providers.",
103+
[METRIC.BORROW_INTEREST]: "The LP share of borrow interest distributed to liquidity providers.",
60104
},
61105
}
62106

@@ -71,4 +115,4 @@ const adapter: SimpleAdapter = {
71115
breakdownMethodology,
72116
}
73117

74-
export default adapter
118+
export default adapter

0 commit comments

Comments
 (0)