Skip to content

Commit dae3ac3

Browse files
treeoflife2g1nt0kidtmkenggte620vhenryzhang03
authored
Echo Fees (#2865)
* quick fix * Feat: Echo Fees * Feat: improved event and duplicate filtering for older contracts. * Used Topics * fix fromblock, and toblock * Change Dune query Id to sql (#2874) * Implement caching for start timestamp retrieval * Fix cache key generation in getStartTimestamp function * disable random delay in runAdapter function * change query from allium to dune to fix the solanareceived bug (#2875) * track kongswap fees * Gmx v1 helper (#2858) * add gmx v1 fees helper functions * add dailyVolume * track dailyRevenue for gmx v1 forks --------- Co-authored-by: g1nt0ki <[email protected]> * solana SIMD-0096 priority fees change * Fix: only burned fee will be counted for chain revenue * update maverick v2 to use the subgraph (#2877) * feat: add axiom fees to defillama (#2839) * feat: add fee methodology to axiom * fix rooster * update sdk version * Add mellow LRTs fees adapter (#2883) * add mellow LRTs fees adapter * add supply side revenue * update to reduce rpc calls * add backfill start time * minor fix * add liquid ron fee adapter (#2872) * add liquid ron fee adapter * code refactor --------- Co-authored-by: g1nt0ki <[email protected]> * feat: Set sentio to not read the cache to avoid delayed data (#2884) * fees adapters: extracted sql queries from dune (#2885) * update name to mellow-lrt * bitget swap, hide eth and sol chain as wrong data from API (#2888) * fix: bug (#2889) * Fix Axiom (#2892) * feat: add axiom fees to defillama * Update axiom.ts * fix: add vault assets to fees (#2891) * feat: change backfill policy (#2890) * Update D8X perps volume adapter (#2887) * d8x daily volume * fetch from events * minor refactor * Add ELFi volume adapter (#2893) * Add ELFi volume adapter * minor fix --------- Co-authored-by: g1nt0ki <[email protected]> * Fix: raydium stat api change in poolsortfield from default to volume24h (#2894) * elfi: turn v2 * track elys dex * minor fix * hfun: remove referral fee from the revenue (#2895) * added more Coinbase Commerce contract addresses including the latest version (#2881) * fix vfat * Add new wallets to makenow-meme fees adapter (#2886) * Update makenow-meme.ts with new fee wallets * Update makenow-meme.ts: fix blacklists * add noTarget option to getLogs and getAllTransfers functions * Fix: carbondefi analytics API and incorrect calculation (#2907) * add typus-perp (#2905) * add typus-perp * minor fix --------- Co-authored-by: g1nt0ki <[email protected]> * remaining adapter with dune queryId to query sql (#2896) * remaining dunequery to dunequerysql * remove querydune export * Fix: update XDAI chain configuration with correct CGToken and additional stats API * Swellchain dapp revenue (#2899) * add velodrome v2 revenue * velo volume * add ambient * feat: Add Yei finance fees dashboard (#2901) * feat: Add Yei finance fees dashboard * fix: Remote unnecessary configs * code refactor --------- Co-authored-by: santai <[email protected]> Co-authored-by: g1nt0ki <[email protected]> * add Tea-REX volume (#2882) * add Tea-REX volume * minor fix --------- Co-authored-by: g1nt0ki <[email protected]> * Update Morpho adapter to get fees from blue contracts (#2903) * update: get fees from blue contracts * morpho: cache graph result --------- Co-authored-by: g1nt0ki <[email protected]> * add wal token (#2947) * TON Pump volume (#2205) * TON Pump volume * fix file type * minor fix --------- Co-authored-by: 0xgnek <[email protected]> Co-authored-by: g1nt0ki <[email protected]> * Pancakeswap use logs where subgraph is not available, easier config management (#2949) * magpie remove runAtCurrTime flag, as api support historical data (#2952) * Feat: update FlowX V3 volume (#2950) * Feat: update flowx v3 volume * code refactor --------- Co-authored-by: g1nt0ki <[email protected]> * Added Kame volume aggregator (#2953) * Feat: update kame aggregator * code refactor --------- Co-authored-by: g1nt0ki <[email protected]> * prevent Nan value * Fix: noTarget error, and other volume/fee broken adapters (#2956) * Add OpenEden T-Bill fees for balances on ripple, solana (#2906) * add tbill balance on ripple, sol * Update index.ts * update fees on solana and ripple --------- Co-authored-by: g1nt0ki <[email protected]> * Add Chedda Finance dimension adapter (#2951) * feat: add chedda finance dimension adapter * fix: use address registry * code refactor --------- Co-authored-by: sadeeqdev <[email protected]> Co-authored-by: WarTech <[email protected]> * add loxodrome-perp (#2962) * Feat: add arbitrum timeboost revenue (#2958) * Feat: arbitrum timeboost revenue to DAO * rollback arbitrum, created arbitrum-timeboost * Feat: kairos fee/revenue adapter (#2959) * Feat: kairos fee/revenue adapter * correct dailyRevenue by substracting the cost from dailyFee * Fix: near from api to allium, fix paradex volume adapter (#2963) * Ostium Fee/Revenue (#2968) * update type of adapter (#2970) * fix: spacewhale subgraph endpoint * feat: new adapter for lista lending (#2948) * feat: new adapter for lista lending * minor fix --------- Co-authored-by: Tyler Tsai <[email protected]> Co-authored-by: g1nt0ki <[email protected]> * update dackieswap fees and dexs adapters * Feat: zora onchain social network fees/revenue and contract volume (#2966) * Feat: zora onchain social network fees/revenue * add zora chain fees * Dune query for fees and volumes --------- Co-authored-by: Eden <[email protected]> * fix: rubic adapters apis (#2976) * update teleswap dead date (#2978) * Fix some adapters errors (#2979) * return null on api call failed * add starbase dead date because web is down * add plexus dead date because web is down * add hop-agg dead date * fix broken api (#2983) * fix error api * feat: add WOOFi Berachain (#2982) * refresh to new data api (#2981) * add fees from yearn finance and yETH (#2974) * Raydium Launchlab Volume (#2971) * add compound v3 fees (#2969) * Amnis (#2984) * Amnis Finance add fee and revenue * Rename index.js to index.ts * minor fix --------- Co-authored-by: John Amnis <[email protected]> * feat: adjust node income for lista dao (#2961) Co-authored-by: Tyler Tsai <[email protected]> * feat: add beezie's trading volume adapter (#2898) * feat: add beezie's trading volume adapter * minor refactor * fix: add missing start timestamp for FLOW adapter --------- Co-authored-by: g1nt0ki <[email protected]> * throw error for negative metrics for sushiswap and balancer (#2985) * update filter paradexs volume (#2991) * limit call apex api (#2992) * Add RFQ stats (#2954) * Add RFQ stats * Fix casting * Fix total revenue * ostium volume adapter (#2986) * LIFI bridge aggregator adapter (#2994) * LIFI bridge aggregator adapter * minor fix --------- Co-authored-by: g1nt0ki <[email protected]> * add liquidate volume (#2989) * feat: add KittyPunch v3 adapter on FLOW chain (#2988) * feat: add KittyPunch v3 adapter for Uniswap V3 on FLOW chain * feat: create new file for KittyPunch v3 adapter in fees directory --------- Co-authored-by: g1nt0ki <[email protected]> * lifi: correct starttime for each chain (#2995) * disable DUNE_RESTRICTED_MODE * fix error euler * Convert dune adapters to v1 (#2997) * Fix some dexs adapters (#2999) * fix fjord-foundry dexs v2 api * set kyberswap dead date for classic and elastic products * exclude wrong token * fix query timestamp * Query premia data using factories and blocks (#3000) * query premia data using factories and blocks * remove console log * fix error mix type * fix premia fees * remove wrong total value * Agdex (#3007) * refresh to new data api * refresh api * track sonicxswap #3005 * Add revenue from permastaked RSUP (#3006) * feat(markets): looping accross right markets on the api query (#3003) * vanilla finance perps (#2996) * vanilla finance perps * use log instead * use log instead * code refactor --------- Co-authored-by: osel <[email protected]> Co-authored-by: g1nt0ki <[email protected]> * Fix: solana chain base fee and priority fee calc (#3009) * add hemi chain to iziswap adapter (#3010) * feat(berachain): add dimensions berachain (#3012) Co-authored-by: CuongNT <[email protected]> * Add m0.org fees adapter (#3001) * add m0.org fees adapter * update start date * update correct start date * Track bucket fees (#3014) * feat: bucket fee & revenue statistic * code refactor --------- Co-authored-by: Jarek Lin <[email protected]> * track ooga booga revenue #3013 * Add Typus Finance fees (#3002) * add typus fees * fix calculation * minor fix --------- Co-authored-by: g1nt0ki <[email protected]> * New DexToro App Fix (#2960) DexToro's perpetual DEX on Optimism has been discontinued, and the company has transitioned to an iOS trading app based on Solana. This commit replaces the code that was tracking the old Optimism app with updated code to track revenue (fees collected) on the project's Solana Treasury wallet. * fix superchain * add Swaps.io to DEXs (#3015) * Add Lifi Fees, update sushi v3 optimism subgraph (#3017) * superchain: add link to source of wallets * minor fix --------- Co-authored-by: g1nt0ki <[email protected]> Co-authored-by: dtmkeng <[email protected]> Co-authored-by: Bob Baxley <[email protected]> Co-authored-by: Henry Zhang <[email protected]> Co-authored-by: Eden <[email protected]> Co-authored-by: seuchenhund <[email protected]> Co-authored-by: Hedy-chu <[email protected]> Co-authored-by: realshaman <[email protected]> Co-authored-by: Uyoyou Saint Uwuseba <[email protected]> Co-authored-by: m66260 <[email protected]> Co-authored-by: 0xELFi02 <[email protected]> Co-authored-by: Peter Miklos <[email protected]> Co-authored-by: alaskan-malamute2 <[email protected]> Co-authored-by: Wayne Kuo <[email protected]> Co-authored-by: maybeyonas <[email protected]> Co-authored-by: santa-yei <[email protected]> Co-authored-by: santai <[email protected]> Co-authored-by: VensonLiou <[email protected]> Co-authored-by: 0xaslan <[email protected]> Co-authored-by: Peter Volnov <[email protected]> Co-authored-by: HoU | FlowX <[email protected]> Co-authored-by: kameag <[email protected]> Co-authored-by: sadeeqdev <[email protected]> Co-authored-by: WarTech <[email protected]> Co-authored-by: tyler-tsai <[email protected]> Co-authored-by: Tyler Tsai <[email protected]> Co-authored-by: Merlin <[email protected]> Co-authored-by: liuxieric123 <[email protected]> Co-authored-by: John Amnis <[email protected]> Co-authored-by: BT.Wood(Tang Bo Hao) <[email protected]> Co-authored-by: boson42 <[email protected]> Co-authored-by: benny <[email protected]> Co-authored-by: Reppelin Tom <[email protected]> Co-authored-by: VanillaDevTeam <[email protected]> Co-authored-by: osel <[email protected]> Co-authored-by: LpcAries <[email protected]> Co-authored-by: HoldStation <[email protected]> Co-authored-by: CuongNT <[email protected]> Co-authored-by: Jarek Lin <[email protected]> Co-authored-by: Vitaliy Tsigulev <[email protected]> Co-authored-by: Kirill <[email protected]>
1 parent 96f46da commit dae3ac3

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

fees/echo/index.ts

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Echo Protocol Fee Adapter
3+
*
4+
* Note on duplicate transactions:
5+
* In v1/v2 factory contracts, deals often sent both deal funds and platform fees
6+
* to the fee receiver address in the same transaction. This created duplicate logs
7+
* that would artificially inflate fee calculations. To handle this, we track unique
8+
* transactions by combining address, transaction hash, and token as a key, and for
9+
* any duplicates we only count the transaction with the smallest amount (which
10+
* represents the actual platform fee, not the deal funds).
11+
*
12+
*/
13+
14+
import { ethers } from "ethers"
15+
import { FetchOptions, SimpleAdapter } from "../../adapters/types"
16+
import { CHAIN } from "../../helpers/chains"
17+
18+
// Echo protocol contract addresses
19+
const ECHO_v1_DEAL_FACTORY = '0x32885c0174FBd53A3BDf418408415c7bEF679810'
20+
const ECHO_v2_DEAL_FACTORY = '0x31a85750a7fd18b598e1bc6dc5561ad1ef694fc4'
21+
const ECHO_v3_DEAL_FACTORY = '0xB6D2c5dc2d181E0E1D031F2b3B76Ea8b678EAA46'
22+
23+
const ECHO_FEE_RECEIVER = '0x395426cE9081aE5ceA3f9fBA3078B00f16E7aE21'
24+
const DEAL_FUNDS_WITHDRAWN_TOPIC = "0x7e63be7447cb592fc5a80b0ca7ceb813b777d8aa50ec5c00b89578b892b4b8e9"
25+
26+
const fetchFees = async (options: FetchOptions) => {
27+
const fromBlock = await options.getBlock(options.fromTimestamp, options.chain, {})
28+
const toBlock = await options.getBlock(options.toTimestamp, options.chain, {})
29+
// const fromBlock = 15111743
30+
// const toBlock = 28654931
31+
32+
const logs = await options.getLogs({
33+
eventAbi: "event DealFundsWithdrawn (address indexed token, address indexed to, uint256 amount)",
34+
topics: [DEAL_FUNDS_WITHDRAWN_TOPIC, null as any, ethers.zeroPadValue(ECHO_FEE_RECEIVER, 32)],
35+
fromBlock,
36+
toBlock,
37+
entireLog: true,
38+
skipIndexer: true,
39+
noTarget: true,
40+
})
41+
42+
const uniqueFees = new Map<string, { token: string, amount: bigint }>();
43+
44+
// Process each log, keeping only the platform fee portion
45+
for (const log of logs) {
46+
const token = '0x' + log.topics[1].slice(26);
47+
const amount = BigInt(log.data);
48+
const key = `${log.address.toLowerCase()}_${log.transactionHash.toLowerCase()}_${token}`;
49+
if (!uniqueFees.has(key) || amount < uniqueFees.get(key)!.amount) {
50+
uniqueFees.set(key, { token, amount });
51+
}
52+
}
53+
54+
const dailyFees = options.createBalances();
55+
for (const { token, amount } of uniqueFees.values()) {
56+
dailyFees.add(token, amount);
57+
}
58+
59+
return {
60+
dailyFees,
61+
dailyRevenue: dailyFees,
62+
}
63+
}
64+
65+
const adapter: SimpleAdapter = {
66+
version: 2,
67+
adapter: {
68+
[CHAIN.BASE]: {
69+
fetch: fetchFees,
70+
start: '2024-03-27',
71+
meta: {
72+
methodology: {
73+
Fees: "Platform fees collected by Echo protocol from each deal"
74+
}
75+
}
76+
}
77+
}
78+
}
79+
80+
export default adapter

0 commit comments

Comments
 (0)