-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
base: master
Are you sure you want to change the base?
Conversation
The euler adapter exports:
|
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.
.
…the end to avoid rate changes
The euler adapter exports:
|
fees/euler/index.ts
Outdated
let totalShares = 0n; | ||
for (const log of vaultLogs) { | ||
try { | ||
const parsedLog = iface.parseLog({ |
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.
if you pass eventAbi, the data should already be parsed?
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.
i need the addresses so i used entireLog: true, i'm not sure i can get the address without entireLog
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.
yeah, but why do you need the addresses in the first place?
fees/euler/index.ts
Outdated
topics: log.topics, | ||
data: log.data | ||
}); | ||
if (!parsedLog || log.address.toLowerCase() !== vaultAddress) continue; |
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.
log.address.toLowerCase() !== vaultAddress
this should never happen
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.
when I think about it, log parsing should also never fail
fees/euler/index.ts
Outdated
dailyRevenue.add(underlyings[i], assets) | ||
}) | ||
|
||
return {dailyFees,dailyRevenue} |
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.
can also track dailySupplySideRevenue as
const dailySupplySideRevenue = dailyFees.clone()
dailySupplySideRevenue.subtract(dailyRevenue)
fees/euler/index.ts
Outdated
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})) |
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.
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
…which is not required
The euler adapter exports:
|
The euler adapter exports:
|
The euler adapter exports:
|
The euler adapter exports:
|
dailyFees.add(underlyings[i], dailyInterest[i]) | ||
dailyRevenue.add(underlyings[i], assets) | ||
}) | ||
const dailySupplySideRevenue = dailyFees.clone() |
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.
nit: shall this variable be called dailySupplySideRevenue
? to be consistent I guess it should be called something like dailySupplySideFees
?
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.
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
…aultLength everytime
The euler adapter exports:
|
fees/euler/index.ts
Outdated
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) => { |
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.
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)
The euler adapter exports:
|
track euler fees & revenue