-
Notifications
You must be signed in to change notification settings - Fork 1.4k
track euler fees & revenue #2708
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
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
274b7ea
track euler fees & revenue
ReynardoEW c9dbad5
change to use multicall instead, and also convert shares at asset at …
ReynardoEW 44f1fd3
added dailySupplySideRevenue, use index instead of using the address …
ReynardoEW 78d031d
handle if vault length = 0
ReynardoEW 9e0321d
re enabling base and the totalShares are correctly calculated again
ReynardoEW a40a81e
test butler
ReynardoEW 6b6af62
use interestAccrued events, and use uint256 max instead of checking v…
ReynardoEW 4112e73
use vault status
ReynardoEW File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { Adapter, FetchOptions, SimpleAdapter } from "../../adapters/types" | ||
import { CHAIN } from "../../helpers/chains" | ||
import * as sdk from "@defillama/sdk"; | ||
|
||
const eVaultFactories = { | ||
[CHAIN.ETHEREUM]: "0x29a56a1b8214D9Cf7c5561811750D5cBDb45CC8e", | ||
[CHAIN.SONIC]: "0xF075cC8660B51D0b8a4474e3f47eDAC5fA034cFB", | ||
[CHAIN.BASE]: "0x7F321498A801A191a93C840750ed637149dDf8D0" | ||
} | ||
|
||
const eulerFactoryABI = { | ||
vaultLength: "function getProxyListLength() view returns (uint256)", | ||
getProxyListSlice: "function getProxyListSlice(uint256 start, uint256 end) view returns (address[] list)", | ||
} | ||
|
||
const eulerVaultABI = { | ||
asset: "function asset() view returns (address)", | ||
interestAccumulator: "function interestAccumulator() view returns (uint256)", | ||
accumulatedFeesAssets: "function accumulatedFeesAssets() view returns (uint256)", | ||
totalBorrows: "function totalBorrows() view returns (uint256)", | ||
convertToAssets: "function convertToAssets(uint256 shares) view returns (uint256)", | ||
convertFees: "event ConvertFees(address indexed account, address indexed protocolReceiver, address indexed governorReceiver, uint256 protocolShares, uint256 governorShares)", | ||
vaultStatus: "event VaultStatus(uint256 totalShares, uint256 totalBorrows, uint256 accumulatedFees, uint256 cash, uint256 interestAccumulator, uint256 interestRate, uint256 timestamp)" | ||
} | ||
|
||
const getVaults = async ({createBalances, api, fromApi, toApi, getLogs, chain}: FetchOptions, { | ||
dailyFees, | ||
dailyRevenue, | ||
}: { | ||
dailyFees?: sdk.Balances, | ||
dailyRevenue?: sdk.Balances, | ||
}) => { | ||
|
||
if (!dailyFees) dailyFees = createBalances() | ||
if (!dailyRevenue) dailyRevenue = createBalances() | ||
const vaultLength = await api.call({target: eVaultFactories[chain], abi: eulerFactoryABI.vaultLength}) | ||
const vaults = await api.call({target: eVaultFactories[chain], abi: eulerFactoryABI.getProxyListSlice, params: [0, vaultLength]}) | ||
const underlyings = await api.multiCall({calls: vaults.map(vault=>({target: vault})), abi: eulerVaultABI.asset}) | ||
underlyings.forEach((underlying, index) => { | ||
if (!underlying) underlyings[index] = '0x0000000000000000000000000000000000000000' | ||
}) | ||
|
||
const vaultWithUnderlyings = vaults.map((vault, index) => ({vault, underlying: underlyings[index]})) | ||
await Promise.all(vaultWithUnderlyings.map(async ({ vault, underlying }) => { | ||
ReynardoEW marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const accumulatedFeesStart = await fromApi.call({target: vault, abi: eulerVaultABI.accumulatedFeesAssets, permitFailure: true}) | ||
const accumulatedFeesEnd = await toApi.call({target: vault, abi: eulerVaultABI.accumulatedFeesAssets, permitFailure: true}) | ||
|
||
const interestAccumulatorStart = await fromApi.call({target: vault, abi: eulerVaultABI.interestAccumulator, permitFailure: true}) | ||
const interestAccumulatorEnd = await toApi.call({target: vault, abi: eulerVaultABI.interestAccumulator, permitFailure: true}) | ||
const totalBorrow = await fromApi.call({target: vault, abi: eulerVaultABI.totalBorrows, permitFailure: true}) | ||
|
||
const dailyInterest = totalBorrow * (interestAccumulatorEnd - interestAccumulatorStart) / interestAccumulatorStart | ||
|
||
const logsVaultStatus = await getLogs({ | ||
target: vault, | ||
eventAbi: eulerVaultABI.vaultStatus, | ||
}); | ||
|
||
logsVaultStatus.sort((a, b) => Number(a.timestamp) - Number(b.timestamp)); | ||
|
||
// we listen for the convert fees event otherwise if convert fees happened accumulatedfees will be 0 and mess every thing up Daily Revenue = accumulatedFees + sum(converted_fees) | ||
const logs = await getLogs({target: vault, eventAbi: eulerVaultABI.convertFees}) | ||
const convertShares = await Promise.all(logs.map(async (log: any) => { | ||
ReynardoEW marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const shares = log.protocolShares + log.governorShares; | ||
const assets = await api.call({ | ||
target: vault, | ||
abi: eulerVaultABI.convertToAssets, | ||
params: [shares], | ||
permitFailure: false, | ||
}); | ||
return Number(assets); | ||
})); | ||
const totalConvertedAmount = convertShares.reduce((sum, amount) => sum + amount, 0); | ||
|
||
const accumulatedFees = (accumulatedFeesEnd - accumulatedFeesStart) + totalConvertedAmount | ||
|
||
dailyFees.add(underlying, dailyInterest) | ||
dailyRevenue.add(underlying, accumulatedFees) | ||
})) | ||
|
||
return { | ||
dailyFees, | ||
dailyRevenue | ||
} | ||
} | ||
|
||
const fetch = async (options: FetchOptions) => { | ||
return await getVaults(options, {}) | ||
} | ||
|
||
const adapters: Adapter = { | ||
adapter: { | ||
[CHAIN.ETHEREUM]: { | ||
fetch: fetch, | ||
start: '2024-08-14' | ||
}, | ||
[CHAIN.SONIC]: { | ||
fetch: fetch, | ||
start: '2025-01-25' | ||
}, | ||
[CHAIN.BASE]: { | ||
fetch: fetch, | ||
start: '2024-11-11' | ||
} | ||
}, | ||
version: 2 | ||
} | ||
|
||
export default adapters; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.