Skip to content

Echo Fees #2865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 120 commits into from
Apr 24, 2025
Merged
Changes from 4 commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
7521ed7
quick fix
treeoflife2 Apr 10, 2025
67ea459
Feat: Echo Fees
treeoflife2 Apr 10, 2025
ddf6458
Feat: improved event and duplicate filtering for older contracts.
treeoflife2 Apr 11, 2025
9023ef5
Merge branch 'DefiLlama:master' into echo
treeoflife2 Apr 11, 2025
503ef0b
Used Topics
treeoflife2 Apr 11, 2025
6f92e39
fix fromblock, and toblock
treeoflife2 Apr 11, 2025
d1590a4
Change Dune query Id to sql (#2874)
treeoflife2 Apr 11, 2025
fd08a67
Implement caching for start timestamp retrieval
g1nt0ki Apr 11, 2025
40463bd
Fix cache key generation in getStartTimestamp function
g1nt0ki Apr 11, 2025
b4ed4cd
disable random delay in runAdapter function
g1nt0ki Apr 11, 2025
d46d2ed
change query from allium to dune to fix the solanareceived bug (#2875)
treeoflife2 Apr 11, 2025
be2b148
track kongswap fees
g1nt0ki Apr 11, 2025
6af60f9
Gmx v1 helper (#2858)
dtmkeng Apr 13, 2025
f163106
solana SIMD-0096 priority fees change
treeoflife2 Apr 13, 2025
e05dc83
Fix: only burned fee will be counted for chain revenue
treeoflife2 Apr 13, 2025
09847d3
update maverick v2 to use the subgraph (#2877)
gte620v Apr 14, 2025
d05de3f
feat: add axiom fees to defillama (#2839)
henryzhang03 Apr 14, 2025
6e4fc31
feat: add fee methodology to axiom
g1nt0ki Apr 14, 2025
48a9062
fix rooster
g1nt0ki Apr 14, 2025
29952f2
update sdk version
g1nt0ki Apr 14, 2025
fb25798
Add mellow LRTs fees adapter (#2883)
noateden Apr 14, 2025
849d95c
add liquid ron fee adapter (#2872)
seuchenhund Apr 14, 2025
ebe0b2b
feat: Set sentio to not read the cache to avoid delayed data (#2884)
Hedy-chu Apr 14, 2025
bccdaef
fees adapters: extracted sql queries from dune (#2885)
treeoflife2 Apr 14, 2025
505d129
update name to mellow-lrt
realdealshaman Apr 14, 2025
19e45fa
bitget swap, hide eth and sol chain as wrong data from API (#2888)
treeoflife2 Apr 14, 2025
7a3004b
fix: bug (#2889)
treeoflife2 Apr 14, 2025
a7b6260
Fix Axiom (#2892)
henryzhang03 Apr 15, 2025
b10f5dc
fix: add vault assets to fees (#2891)
noateden Apr 15, 2025
f2c4efc
feat: change backfill policy (#2890)
Khrafts Apr 15, 2025
2f88109
Update D8X perps volume adapter (#2887)
m66260 Apr 15, 2025
a8d2b21
minor refactor
g1nt0ki Apr 15, 2025
cf1e668
Add ELFi volume adapter (#2893)
0xELFi02 Apr 15, 2025
1fd6b2d
Fix: raydium stat api change in poolsortfield from default to volume…
treeoflife2 Apr 15, 2025
8308a78
elfi: turn v2
g1nt0ki Apr 15, 2025
6e23f54
track elys dex
g1nt0ki Apr 15, 2025
661cfc0
minor fix
g1nt0ki Apr 15, 2025
8dfafba
hfun: remove referral fee from the revenue (#2895)
treeoflife2 Apr 15, 2025
4031841
added more Coinbase Commerce contract addresses including the latest …
pmiklos Apr 15, 2025
8368a17
fix vfat
g1nt0ki Apr 16, 2025
7403970
Add new wallets to makenow-meme fees adapter (#2886)
alaskan-malamute2 Apr 16, 2025
d8bd315
add noTarget option to getLogs and getAllTransfers functions
g1nt0ki Apr 16, 2025
d0986ad
Fix: carbondefi analytics API and incorrect calculation (#2907)
treeoflife2 Apr 16, 2025
0dc996b
add typus-perp (#2905)
WayneAl Apr 16, 2025
b969d9c
remaining adapter with dune queryId to query sql (#2896)
treeoflife2 Apr 16, 2025
3b4b073
Fix: update XDAI chain configuration with correct CGToken and additio…
g1nt0ki Apr 16, 2025
e5a01ff
Swellchain dapp revenue (#2899)
darvinrio Apr 16, 2025
7f156b9
feat: Add Yei finance fees dashboard (#2901)
santa-yei Apr 16, 2025
e3cca20
add Tea-REX volume (#2882)
VensonLiou Apr 16, 2025
1e759fc
Update Morpho adapter to get fees from blue contracts (#2903)
noateden Apr 16, 2025
5640ed5
add wal token (#2947)
0xaslan Apr 16, 2025
eda5218
TON Pump volume (#2205)
pvolnov Apr 16, 2025
ba73a3d
Pancakeswap use logs where subgraph is not available, easier config m…
treeoflife2 Apr 17, 2025
fd1bc44
magpie remove runAtCurrTime flag, as api support historical data (#2952)
treeoflife2 Apr 17, 2025
9c8b7af
Feat: update FlowX V3 volume (#2950)
devflowx Apr 17, 2025
bd89df8
Added Kame volume aggregator (#2953)
kameag Apr 17, 2025
962dded
prevent Nan value
dtmkeng Apr 17, 2025
78af03c
Fix: noTarget error, and other volume/fee broken adapters (#2956)
treeoflife2 Apr 17, 2025
fc917c1
Add OpenEden T-Bill fees for balances on ripple, solana (#2906)
noateden Apr 17, 2025
e1df80c
Add Chedda Finance dimension adapter (#2951)
g1nt0ki Apr 18, 2025
0f675c7
add loxodrome-perp (#2962)
dtmkeng Apr 18, 2025
f84f9ae
Feat: add arbitrum timeboost revenue (#2958)
treeoflife2 Apr 18, 2025
d8b2c09
Feat: kairos fee/revenue adapter (#2959)
treeoflife2 Apr 18, 2025
86eeee3
Fix: near from api to allium, fix paradex volume adapter (#2963)
treeoflife2 Apr 18, 2025
9dc25e0
Ostium Fee/Revenue (#2968)
treeoflife2 Apr 19, 2025
0dea5d3
update type of adapter (#2970)
dtmkeng Apr 19, 2025
606cda6
fix: spacewhale subgraph endpoint
noateden Apr 21, 2025
67e504b
feat: new adapter for lista lending (#2948)
tyler-tsai Apr 21, 2025
2b3ccf8
update dackieswap fees and dexs adapters
noateden Apr 21, 2025
ed6c226
Feat: zora onchain social network fees/revenue and contract volume (#…
treeoflife2 Apr 21, 2025
25357e9
fix: rubic adapters apis (#2976)
noateden Apr 21, 2025
9e185ab
update teleswap dead date (#2978)
noateden Apr 21, 2025
2f22f49
Fix some adapters errors (#2979)
noateden Apr 21, 2025
9d832f7
fix broken api (#2983)
dtmkeng Apr 21, 2025
b49a80b
fix error api
dtmkeng Apr 21, 2025
79a9df2
feat: add WOOFi Berachain (#2982)
0xmer1in Apr 21, 2025
67a6242
refresh to new data api (#2981)
liuxieric123 Apr 21, 2025
80371bf
add fees from yearn finance and yETH (#2974)
noateden Apr 21, 2025
94e1203
Raydium Launchlab Volume (#2971)
treeoflife2 Apr 21, 2025
b47429b
add compound v3 fees (#2969)
noateden Apr 21, 2025
4566f71
Amnis (#2984)
g1nt0ki Apr 21, 2025
1e320bb
feat: adjust node income for lista dao (#2961)
tyler-tsai Apr 21, 2025
6a0b9da
feat: add beezie's trading volume adapter (#2898)
btspoony Apr 21, 2025
ab00429
throw error for negative metrics for sushiswap and balancer (#2985)
treeoflife2 Apr 21, 2025
2992535
update filter paradexs volume (#2991)
dtmkeng Apr 22, 2025
573b7fe
limit call apex api (#2992)
dtmkeng Apr 22, 2025
1720823
Add RFQ stats (#2954)
sanatik Apr 22, 2025
8b57287
ostium volume adapter (#2986)
treeoflife2 Apr 22, 2025
b30ad3c
LIFI bridge aggregator adapter (#2994)
treeoflife2 Apr 22, 2025
bee20c2
add liquidate volume (#2989)
WayneAl Apr 22, 2025
b67960c
feat: add KittyPunch v3 adapter on FLOW chain (#2988)
btspoony Apr 22, 2025
81a691f
lifi: correct starttime for each chain (#2995)
treeoflife2 Apr 22, 2025
7439644
disable DUNE_RESTRICTED_MODE
g1nt0ki Apr 22, 2025
8304e46
fix error euler
dtmkeng Apr 22, 2025
e60291c
Convert dune adapters to v1 (#2997)
treeoflife2 Apr 22, 2025
e7e4ccf
Fix some dexs adapters (#2999)
noateden Apr 22, 2025
2bf52e6
exclude wrong token
dtmkeng Apr 23, 2025
5d2607a
fix query timestamp
dtmkeng Apr 23, 2025
f5b795c
Query premia data using factories and blocks (#3000)
noateden Apr 23, 2025
e2daf98
fix error mix type
dtmkeng Apr 23, 2025
99d518d
fix premia fees
dtmkeng Apr 23, 2025
66e3b6a
remove wrong total value
dtmkeng Apr 23, 2025
357dd85
Agdex (#3007)
liuxieric123 Apr 23, 2025
b2686ab
track sonicxswap #3005
g1nt0ki Apr 23, 2025
745dee4
Add revenue from permastaked RSUP (#3006)
benber86 Apr 23, 2025
2f1ee07
feat(markets): looping accross right markets on the api query (#3003)
tomrpl Apr 23, 2025
bc8cf89
vanilla finance perps (#2996)
VanillaDevTeam Apr 23, 2025
4217173
Fix: solana chain base fee and priority fee calc (#3009)
treeoflife2 Apr 23, 2025
f91cb06
add hemi chain to iziswap adapter (#3010)
LpcAries Apr 24, 2025
e00850e
feat(berachain): add dimensions berachain (#3012)
dev-holdstation Apr 24, 2025
4a43780
Add m0.org fees adapter (#3001)
noateden Apr 24, 2025
7f277a3
Track bucket fees (#3014)
g1nt0ki Apr 24, 2025
54a3c17
track ooga booga revenue #3013
g1nt0ki Apr 24, 2025
6c13e32
Add Typus Finance fees (#3002)
WayneAl Apr 24, 2025
5f0960c
New DexToro App Fix (#2960)
0xVitalii Apr 24, 2025
ca39cbb
fix superchain
g1nt0ki Apr 24, 2025
8e27d82
add Swaps.io to DEXs (#3015)
KirillGordievich Apr 24, 2025
6ec58c7
Add Lifi Fees, update sushi v3 optimism subgraph (#3017)
treeoflife2 Apr 24, 2025
ca03796
superchain: add link to source of wallets
g1nt0ki Apr 24, 2025
5540f37
minor fix
g1nt0ki Apr 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions fees/echo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Echo Protocol Fee Adapter
*
* Note on duplicate transactions:
* In v1/v2 factory contracts, deals often sent both deal funds and platform fees
* to the fee receiver address in the same transaction. This created duplicate logs
* that would artificially inflate fee calculations. To handle this, we track unique
* transactions by combining address, transaction hash, and token as a key, and for
* any duplicates we only count the transaction with the smallest amount (which
* represents the actual platform fee, not the deal funds).
*
*/

import { FetchOptions, SimpleAdapter } from "../../adapters/types"
import { CHAIN } from "../../helpers/chains"

// Echo protocol contract addresses
const ECHO_v1_DEAL_FACTORY = '0x32885c0174FBd53A3BDf418408415c7bEF679810'
const ECHO_v2_DEAL_FACTORY = '0x31a85750a7fd18b598e1bc6dc5561ad1ef694fc4'
const ECHO_v3_DEAL_FACTORY = '0xB6D2c5dc2d181E0E1D031F2b3B76Ea8b678EAA46'

const ECHO_FEE_RECEIVER = '0x395426cE9081aE5ceA3f9fBA3078B00f16E7aE21'
const ECHO_FEE_RECEIVER_TOPIC = "0x000000000000000000000000395426ce9081ae5cea3f9fba3078b00f16e7ae21"
const DEAL_FUNDS_WITHDRAWN_TOPIC = "0x7e63be7447cb592fc5a80b0ca7ceb813b777d8aa50ec5c00b89578b892b4b8e9"

const fetchFees = async (options: FetchOptions) => {
const fromBlock = await options.getBlock(options.fromTimestamp, options.chain, {})
const toBlock = await options.getBlock(options.toTimestamp, options.chain, {})
// const fromBlock = 15111743
// const toBlock = 28654931

const logs = await options.getLogs({
eventAbi: "event DealFundsWithdrawn (address indexed token, address indexed to, uint256 amount)",
topic: DEAL_FUNDS_WITHDRAWN_TOPIC,
fromBlock,
toBlock,
entireLog: true,
skipIndexer: true
})

const uniqueFees = new Map<string, { token: string, amount: bigint }>();

// Process each log, keeping only the platform fee portion
for (const log of logs) {
if (log.topics[2] !== ECHO_FEE_RECEIVER_TOPIC) continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it

const token = '0x' + log.topics[1].slice(26);
const amount = BigInt(log.data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why convert to BigInt and later convert to string? can leave it as is?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I see the check in line 49, I think dailyFees.add accepts bigInt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it

const key = `${log.address.toLowerCase()}_${log.transactionHash.toLowerCase()}_${token}`;
if (!uniqueFees.has(key) || amount < uniqueFees.get(key)!.amount) {
uniqueFees.set(key, { token, amount });
}
}

const dailyFees = options.createBalances();
for (const { token, amount } of uniqueFees.values()) {
dailyFees.add(token, amount.toString());
}

return {
dailyFees,
dailyRevenue: dailyFees,
}
}

const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.BASE]: {
fetch: fetchFees,
start: '2024-03-27',
meta: {
methodology: {
Fees: "Platform fees collected by Echo protocol from each deal"
}
}
}
}
}

export default adapter
Loading