Skip to content
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

track euler fees & revenue #2708

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

ReynardoEW
Copy link
Contributor

track euler fees & revenue

@llamabutler
Copy link

The euler adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees euler

🦙 Running EULER adapter 🦙
---------------------------------------------------
Start Date:	Tue, 25 Mar 2025 11:41:39 GMT
End Date:	Wed, 26 Mar 2025 11:41:39 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 14/8/2024
Daily fees: 45.80 k
Daily revenue: 1.99 k
End timestamp: 1742989298 (2025-03-26T11:41:38.000Z)


SONIC 👇
Backfill start time: 25/1/2025
Daily fees: 6.66 k
Daily revenue: 875
End timestamp: 1742989298 (2025-03-26T11:41:38.000Z)


BASE 👇
Backfill start time: 11/11/2024
Daily fees: -1100886
Daily revenue: 282
End timestamp: 1742989298 (2025-03-26T11:41:38.000Z)


---- AGGREGATE 👇
Backfill start time not defined
End timestamp: 1742989298 (2025-03-26T11:41:38.000Z)
Daily fees: -1048423
Daily revenue: 3.15 k

@g1nt0ki g1nt0ki self-assigned this Mar 26, 2025
Copy link
Member

@g1nt0ki g1nt0ki left a comment

Choose a reason for hiding this comment

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

.

@llamabutler
Copy link

The euler adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees euler

🦙 Running EULER adapter 🦙
---------------------------------------------------
Start Date:	Wed, 26 Mar 2025 03:30:28 GMT
End Date:	Thu, 27 Mar 2025 03:30:28 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 18/8/2024
Daily fees: 47.93 k
Daily revenue: 2.06 k
End timestamp: 1743046227 (2025-03-27T03:30:27.000Z)


SONIC 👇
Backfill start time: 31/1/2025
Daily fees: 6.46 k
Daily revenue: 924
End timestamp: 1743046227 (2025-03-27T03:30:27.000Z)


BASE 👇
Backfill start time: 27/11/2024
Daily fees: 4.45 k
Daily revenue: 232
End timestamp: 1743046227 (2025-03-27T03:30:27.000Z)


---- AGGREGATE 👇
Backfill start time not defined
End timestamp: 1743046227 (2025-03-27T03:30:27.000Z)
Daily fees: 58.84 k
Daily revenue: 3.21 k

@ReynardoEW ReynardoEW requested a review from g1nt0ki March 27, 2025 06:02
let totalShares = 0n;
for (const log of vaultLogs) {
try {
const parsedLog = iface.parseLog({
Copy link
Member

Choose a reason for hiding this comment

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

if you pass eventAbi, the data should already be parsed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i need the addresses so i used entireLog: true, i'm not sure i can get the address without entireLog

Copy link
Member

Choose a reason for hiding this comment

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

yeah, but why do you need the addresses in the first place?

topics: log.topics,
data: log.data
});
if (!parsedLog || log.address.toLowerCase() !== vaultAddress) continue;
Copy link
Member

Choose a reason for hiding this comment

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

log.address.toLowerCase() !== vaultAddress this should never happen

Copy link
Member

Choose a reason for hiding this comment

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

when I think about it, log parsing should also never fail

dailyRevenue.add(underlyings[i], assets)
})

return {dailyFees,dailyRevenue}
Copy link
Member

Choose a reason for hiding this comment

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

can also track dailySupplySideRevenue as

const dailySupplySideRevenue = dailyFees.clone()
dailySupplySideRevenue.subtract(dailyRevenue)

const totalBorrows = await toApi.multiCall({calls: vaults, abi: eulerVaultABI.totalBorrows})
const dailyInterest = totalBorrows.map((borrow, i) => borrow * (interestAccumulatorEnd[i] - interestAccumulatorStart[i]) / interestAccumulatorStart[i])

const logs = (await getLogs({targets: vaults, eventAbi: eulerVaultABI.convertFees, flatten:false, entireLog: true}))
Copy link
Member

Choose a reason for hiding this comment

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

this is a bit of an edge case, if target/targets param is not passed, it will look for all events matching a given topic, so, good to add a check if vaults.length > 0 here or at the start and return empty object if there are no vaults

@llamabutler
Copy link

The euler adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees euler

🦙 Running EULER adapter 🦙
---------------------------------------------------
Start Date:	Wed, 26 Mar 2025 08:10:42 GMT
End Date:	Thu, 27 Mar 2025 08:10:42 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 18/8/2024
Daily fees: 48.06 k
Daily revenue: 2.06 k
Daily supply side revenue: 46.00 k
End timestamp: 1743063041 (2025-03-27T08:10:41.000Z)


SONIC 👇
Backfill start time: 31/1/2025
Daily fees: 6.45 k
Daily revenue: 926
Daily supply side revenue: 5.53 k
End timestamp: 1743063041 (2025-03-27T08:10:41.000Z)


---- AGGREGATE 👇
Backfill start time not defined
End timestamp: 1743063041 (2025-03-27T08:10:41.000Z)
Daily fees: 54.52 k
Daily revenue: 2.99 k
Daily supply side revenue: 51.53 k

@llamabutler
Copy link

The euler adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees euler

🦙 Running EULER adapter 🦙
---------------------------------------------------
Start Date:	Wed, 26 Mar 2025 08:12:49 GMT
End Date:	Thu, 27 Mar 2025 08:12:49 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 18/8/2024
Daily fees: 48.06 k
Daily revenue: 2.06 k
Daily supply side revenue: 46.00 k
End timestamp: 1743063168 (2025-03-27T08:12:48.000Z)


SONIC 👇
Backfill start time: 31/1/2025
Daily fees: 6.45 k
Daily revenue: 926
Daily supply side revenue: 5.53 k
End timestamp: 1743063168 (2025-03-27T08:12:48.000Z)


---- AGGREGATE 👇
Backfill start time not defined
End timestamp: 1743063168 (2025-03-27T08:12:48.000Z)
Daily fees: 54.51 k
Daily revenue: 2.99 k
Daily supply side revenue: 51.52 k

@llamabutler
Copy link

The euler adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees euler

🦙 Running EULER adapter 🦙
---------------------------------------------------
Start Date:	Wed, 26 Mar 2025 08:40:32 GMT
End Date:	Thu, 27 Mar 2025 08:40:32 GMT
---------------------------------------------------

[Error: Promise pool failed! 
 PromisePoolError: value out-of-bounds (argument="shares", value="-43354717510616", code=INVALID_ARGUMENT, version=6.13.2)] {
  _isCustomError: true,
  chain: 'base'
}

@llamabutler
Copy link

The euler adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees euler

🦙 Running EULER adapter 🦙
---------------------------------------------------
Start Date:	Wed, 26 Mar 2025 09:08:01 GMT
End Date:	Thu, 27 Mar 2025 09:08:01 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 18/8/2024
Daily fees: 48.08 k
Daily revenue: 2.06 k
Daily supply side revenue: 46.02 k
End timestamp: 1743066480 (2025-03-27T09:08:00.000Z)


SONIC 👇
Backfill start time: 31/1/2025
Daily fees: 6.44 k
Daily revenue: 923
Daily supply side revenue: 5.52 k
End timestamp: 1743066480 (2025-03-27T09:08:00.000Z)


BASE 👇
Backfill start time: 27/11/2024
Daily fees: 4.22 k
Daily revenue: 218
Daily supply side revenue: 4.00 k
End timestamp: 1743066480 (2025-03-27T09:08:00.000Z)


---- AGGREGATE 👇
Backfill start time not defined
End timestamp: 1743066480 (2025-03-27T09:08:00.000Z)
Daily fees: 58.74 k
Daily revenue: 3.20 k
Daily supply side revenue: 55.54 k

dailyFees.add(underlyings[i], dailyInterest[i])
dailyRevenue.add(underlyings[i], assets)
})
const dailySupplySideRevenue = dailyFees.clone()

Choose a reason for hiding this comment

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

nit: shall this variable be called dailySupplySideRevenue? to be consistent I guess it should be called something like dailySupplySideFees?

Copy link
Member

Choose a reason for hiding this comment

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

you are right, but it is a bit late to fix now, though we could change this display label for this field in the website for all protocols

@llamabutler
Copy link

The euler adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees euler

🦙 Running EULER adapter 🦙
---------------------------------------------------
Start Date:	Wed, 26 Mar 2025 13:29:13 GMT
End Date:	Thu, 27 Mar 2025 13:29:13 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 18/8/2024
Daily fees: 30.98 k
Daily revenue: 2.04 k
Daily supply side revenue: 28.93 k
End timestamp: 1743082152 (2025-03-27T13:29:12.000Z)


SONIC 👇
Backfill start time: 31/1/2025
Daily fees: 2.90 k
Daily revenue: 945
Daily supply side revenue: 1.95 k
End timestamp: 1743082152 (2025-03-27T13:29:12.000Z)


BASE 👇
Backfill start time: 27/11/2024
Daily fees: 3.71 k
Daily revenue: 205
Daily supply side revenue: 3.51 k
End timestamp: 1743082152 (2025-03-27T13:29:12.000Z)


---- AGGREGATE 👇
Backfill start time not defined
End timestamp: 1743082152 (2025-03-27T13:29:12.000Z)
Daily fees: 37.58 k
Daily revenue: 3.19 k
Daily supply side revenue: 34.39 k

const accumulatedFeesStart = await fromApi.multiCall({calls: vaults, abi: eulerVaultABI.accumulatedFees})
const accumulatedFeesEnd = await toApi.multiCall({calls: vaults, abi: eulerVaultABI.accumulatedFees})

const interestAccrued = (await getLogs({targets: vaults, eventAbi: eulerVaultABI.interestAccumulated, flatten: false})).map((logs) => {

Choose a reason for hiding this comment

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

I thought about it a little bit more and I realized that this solution is sub-optimal. The reason for that is that this event is only emitted when the account is touched. It means that someone can create a borrow position and then simply don't interact with their account for a long time until repay. Only then the InterestAccrued will get emitted which would be obviously wrong as we want to track the interest accrued daily.

Different way we can approach it is by using VaultStatus logs:
https://github.com/euler-xyz/euler-vault-kit/blob/master/src/EVault/shared/Events.sol#L59-L67

The difficulty here is that the interest accrued would need to be calculated by looking at the current VaultStatus log and the previous one. It would look like this:
interest = prevTotalBorrows * (currentInterestAccumulator/prevInterestAccumulator - 1)

I guess that you can easily handle that by writing a reduce function. The only hard thing is to get the last log from the day preceding the one you're processing at the moment (or carry it over somehow)

@llamabutler
Copy link

The euler adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees euler

🦙 Running EULER adapter 🦙
---------------------------------------------------
Start Date:	Mon, 31 Mar 2025 06:54:10 GMT
End Date:	Tue, 01 Apr 2025 06:54:10 GMT
---------------------------------------------------

ETHEREUM 👇
Backfill start time: 18/8/2024
Daily fees: 47.58 k
Daily revenue: 1.78 k
Daily supply side revenue: 45.80 k
End timestamp: 1743490449 (2025-04-01T06:54:09.000Z)


SONIC 👇
Backfill start time: 31/1/2025
Daily fees: 5.64 k
Daily revenue: 722
Daily supply side revenue: 4.92 k
End timestamp: 1743490449 (2025-04-01T06:54:09.000Z)


BASE 👇
Backfill start time: 27/11/2024
Daily fees: 0
Daily revenue: 0
Daily supply side revenue: 0
End timestamp: 1743490449 (2025-04-01T06:54:09.000Z)


---- AGGREGATE 👇
Backfill start time not defined
End timestamp: 1743490449 (2025-04-01T06:54:09.000Z)
Daily fees: 53.22 k
Daily revenue: 2.50 k
Daily supply side revenue: 50.71 k

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants