-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add velkonix yield adapter (Aave V3 fork on MegaETH) #2768
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
Open
CryptoBetmen
wants to merge
1
commit into
DefiLlama:master
Choose a base branch
from
K613-Official:feat/velkonix-yield-adapter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+141
−0
Open
Changes from all commits
Commits
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,141 @@ | ||
| const sdk = require('@defillama/sdk'); | ||
|
|
||
| const utils = require('../utils'); | ||
| const poolAbi = require('../aave-v3/poolAbi'); | ||
|
|
||
| const PROTOCOL_DATA_PROVIDER = '0x6da56B769B42952CACA18D37Feda3015FDB2fE67'; | ||
| const CHAIN = 'megaeth'; | ||
| const PROJECT = 'velkonix'; | ||
| const APP_URL = 'https://velkonix.com'; | ||
|
|
||
| const apy = async () => { | ||
| const reserveTokens = ( | ||
| await sdk.api.abi.call({ | ||
| target: PROTOCOL_DATA_PROVIDER, | ||
| abi: poolAbi.find((m) => m.name === 'getAllReservesTokens'), | ||
| chain: CHAIN, | ||
| }) | ||
| ).output; | ||
|
|
||
| const aTokens = ( | ||
| await sdk.api.abi.call({ | ||
| target: PROTOCOL_DATA_PROVIDER, | ||
| abi: poolAbi.find((m) => m.name === 'getAllATokens'), | ||
| chain: CHAIN, | ||
| }) | ||
| ).output; | ||
|
|
||
| const poolsReserveData = ( | ||
| await sdk.api.abi.multiCall({ | ||
| calls: reserveTokens.map((p) => ({ | ||
| target: PROTOCOL_DATA_PROVIDER, | ||
| params: p.tokenAddress, | ||
| })), | ||
| abi: poolAbi.find((m) => m.name === 'getReserveData'), | ||
| chain: CHAIN, | ||
| }) | ||
| ).output.map((o) => o.output); | ||
|
|
||
| const poolsReservesConfigurationData = ( | ||
| await sdk.api.abi.multiCall({ | ||
| calls: reserveTokens.map((p) => ({ | ||
| target: PROTOCOL_DATA_PROVIDER, | ||
| params: p.tokenAddress, | ||
| })), | ||
| abi: poolAbi.find((m) => m.name === 'getReserveConfigurationData'), | ||
| chain: CHAIN, | ||
| }) | ||
| ).output.map((o) => o.output); | ||
|
|
||
| const poolsReserveCaps = ( | ||
| await sdk.api.abi.multiCall({ | ||
| calls: reserveTokens.map((p) => ({ | ||
| target: PROTOCOL_DATA_PROVIDER, | ||
| params: p.tokenAddress, | ||
| })), | ||
| abi: poolAbi.find((m) => m.name === 'getReserveCaps'), | ||
| chain: CHAIN, | ||
| }) | ||
| ).output.map((o) => o.output); | ||
|
|
||
| const underlyingBalances = ( | ||
| await sdk.api.abi.multiCall({ | ||
| chain: CHAIN, | ||
| abi: 'erc20:balanceOf', | ||
| calls: aTokens.map((t, i) => ({ | ||
| target: reserveTokens[i].tokenAddress, | ||
| params: [t.tokenAddress], | ||
| })), | ||
| }) | ||
| ).output.map((o) => o.output); | ||
|
|
||
| const underlyingDecimals = ( | ||
| await sdk.api.abi.multiCall({ | ||
| chain: CHAIN, | ||
| abi: 'erc20:decimals', | ||
| calls: aTokens.map((t) => ({ | ||
| target: t.tokenAddress, | ||
| })), | ||
| }) | ||
| ).output.map((o) => o.output); | ||
|
|
||
| const priceKeys = reserveTokens | ||
| .map((t) => `${CHAIN}:${t.tokenAddress}`) | ||
| .join(','); | ||
| const prices = ( | ||
| await utils.getPriceApiData(`/prices/current/${priceKeys}`) | ||
| ).coins; | ||
|
|
||
| const pools = reserveTokens | ||
| .map((pool, i) => { | ||
| const cfg = poolsReservesConfigurationData[i]; | ||
| if (cfg.isFrozen) return null; | ||
|
|
||
| const price = prices[`${CHAIN}:${pool.tokenAddress}`]?.price; | ||
| if (!price) return null; | ||
|
|
||
| const p = poolsReserveData[i]; | ||
| const decimals = Number(underlyingDecimals[i]); | ||
| const toTokenAmount = (amount) => Number(amount) / 10 ** decimals; | ||
|
|
||
| const tvlUsd = toTokenAmount(underlyingBalances[i]) * price; | ||
| const totalBorrow = | ||
| BigInt(p.totalStableDebt) + BigInt(p.totalVariableDebt); | ||
| const totalBorrowUsd = toTokenAmount(totalBorrow) * price; | ||
| const totalSupplyUsd = tvlUsd + totalBorrowUsd; | ||
|
|
||
| const borrowCap = Number(poolsReserveCaps[i].borrowCap); | ||
| const borrowCapUsd = borrowCap * price; | ||
| const availableBorrowUsd = borrowCap | ||
| ? Math.max(Math.min(tvlUsd, borrowCapUsd - totalBorrowUsd), 0) | ||
| : tvlUsd; | ||
|
|
||
| return { | ||
| pool: `${aTokens[i].tokenAddress}-${CHAIN}`.toLowerCase(), | ||
| chain: utils.formatChain(CHAIN), | ||
| project: PROJECT, | ||
| symbol: pool.symbol, | ||
| tvlUsd, | ||
| apyBase: (Number(p.liquidityRate) / 10 ** 27) * 100, | ||
| underlyingTokens: [pool.tokenAddress], | ||
| totalSupplyUsd, | ||
| totalBorrowUsd, | ||
| availableBorrowUsd, | ||
| apyBaseBorrow: Number(p.variableBorrowRate) / 1e25, | ||
| borrowToken: pool.tokenAddress, | ||
| ltv: Number(cfg.ltv) / 10000, | ||
| borrowable: cfg.borrowingEnabled, | ||
| token: aTokens[i].tokenAddress, | ||
| }; | ||
| }) | ||
| .filter(Boolean); | ||
|
|
||
| return pools.filter(utils.keepFinite); | ||
| }; | ||
|
|
||
| module.exports = { | ||
| timetravel: false, | ||
| apy, | ||
| url: APP_URL, | ||
| protocolId: '8056', | ||
| }; | ||
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.
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.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Report supplied liquidity as
tvlUsd, not only idle liquidity.Line 101 currently makes
tvlUsdequal the underlying cash sitting in the aToken contract. Once users borrow, that underreports pool TVL by the borrowed amount. Keep available liquidity separate foravailableBorrowUsd, and settvlUsdfrom total supplied liquidity.Proposed change
Also applies to: 118-123
🤖 Prompt for AI Agents