-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Echo Fees #2865
Changes from 4 commits
7521ed7
67ea459
ddf6458
9023ef5
503ef0b
6f92e39
d1590a4
fd08a67
40463bd
b4ed4cd
d46d2ed
be2b148
6af60f9
f163106
e05dc83
09847d3
d05de3f
6e4fc31
48a9062
29952f2
fb25798
849d95c
ebe0b2b
bccdaef
505d129
19e45fa
7a3004b
a7b6260
b10f5dc
f2c4efc
2f88109
a8d2b21
cf1e668
1fd6b2d
8308a78
6e23f54
661cfc0
8dfafba
4031841
8368a17
7403970
d8bd315
d0986ad
0dc996b
b969d9c
3b4b073
e5a01ff
7f156b9
e3cca20
1e759fc
5640ed5
eda5218
ba73a3d
fd1bc44
9c8b7af
bd89df8
962dded
78af03c
fc917c1
e1df80c
0f675c7
f84f9ae
d8b2c09
86eeee3
9dc25e0
0dea5d3
606cda6
67e504b
2b3ccf8
ed6c226
25357e9
9e185ab
2f22f49
9d832f7
b49a80b
79a9df2
67a6242
80371bf
94e1203
b47429b
4566f71
1e320bb
6a0b9da
ab00429
2992535
573b7fe
1720823
8b57287
b30ad3c
bee20c2
b67960c
81a691f
7439644
8304e46
e60291c
e7e4ccf
2bf52e6
5d2607a
f5b795c
e2daf98
99d518d
66e3b6a
357dd85
b2686ab
745dee4
2f1ee07
bc8cf89
4217173
f91cb06
e00850e
4a43780
7f277a3
54a3c17
6c13e32
5f0960c
ca39cbb
8e27d82
6ec58c7
ca03796
5540f37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
const token = '0x' + log.topics[1].slice(26); | ||
const amount = BigInt(log.data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, I see the check in line 49, I think There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not pass this as part of topics? like here: https://github.com/DefiLlama/dimension-adapters/blob/master/fees/ether-fi/index.ts#L106
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed it