-
Notifications
You must be signed in to change notification settings - Fork 1.1k
add shapeswap v3 yields #2628
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
DenSmolonski
wants to merge
4
commits into
DefiLlama:master
Choose a base branch
from
protofire:shapeswap-yields
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.
Open
add shapeswap v3 yields #2628
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,86 @@ | ||
| const { request, gql } = require('graphql-request'); | ||
|
|
||
| const utils = require('../utils'); | ||
|
|
||
| const SUBGRAPH = 'https://graph.swap.w3us.site/subgraphs/name/shape/uniswap-v3'; | ||
| const CHAIN = 'shape'; | ||
| const PROJECT = 'shapeswap-v3'; | ||
|
|
||
| const poolsQuery = gql` | ||
| query ($block: Int!) { | ||
| pools( | ||
| first: 1000 | ||
| orderBy: totalValueLockedUSD | ||
| orderDirection: desc | ||
| block: { number: $block } | ||
| where: { totalValueLockedUSD_gt: "100" } | ||
| ) { | ||
| id | ||
| feeTier | ||
| totalValueLockedToken0 | ||
| totalValueLockedToken1 | ||
| totalValueLockedUSD | ||
| volumeUSD | ||
| token0 { id symbol decimals } | ||
| token1 { id symbol decimals } | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| const priorVolumeQuery = gql` | ||
| query ($block: Int!) { | ||
| pools( | ||
| first: 1000 | ||
| orderBy: totalValueLockedUSD | ||
| orderDirection: desc | ||
| block: { number: $block } | ||
| ) { | ||
| id | ||
| volumeUSD | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| const apy = async (timestamp = null) => { | ||
| const [block, blockPrior] = await utils.getBlocks(CHAIN, timestamp, [SUBGRAPH]); | ||
|
|
||
| const { pools } = await request(SUBGRAPH, poolsQuery, { block }); | ||
|
|
||
| let priorPools = []; | ||
| try { | ||
| priorPools = (await request(SUBGRAPH, priorVolumeQuery, { block: blockPrior })).pools; | ||
| } catch (e) { | ||
| console.log('shapeswap-v3 prior block query failed, falling back to zero prior volume', e.message); | ||
| } | ||
| const priorVolumeById = Object.fromEntries(priorPools.map((p) => [p.id, Number(p.volumeUSD)])); | ||
|
|
||
| return pools | ||
| .map((p) => { | ||
| const tvlUsd = Number(p.totalValueLockedUSD); | ||
| const volumeUsdAll = Number(p.volumeUSD); | ||
| const volumeUsd1d = Math.max(volumeUsdAll - (priorVolumeById[p.id] ?? volumeUsdAll), 0); | ||
| const feeRate = Number(p.feeTier) / 1e6; | ||
| const fees1d = volumeUsd1d * feeRate; | ||
| const apyBase = tvlUsd > 0 ? (fees1d * 365 * 100) / tvlUsd : 0; | ||
|
|
||
| return { | ||
| pool: `${p.id}-${CHAIN}`.toLowerCase(), | ||
| chain: utils.formatChain(CHAIN), | ||
| project: PROJECT, | ||
| symbol: utils.formatSymbol(`${p.token0.symbol}-${p.token1.symbol}`), | ||
| tvlUsd, | ||
| apyBase, | ||
| underlyingTokens: [p.token0.id, p.token1.id], | ||
| poolMeta: `${Number(p.feeTier) / 1e4}%`, | ||
| url: `https://info.shapeswap.xyz/home#/pools/${p.id}`, | ||
| volumeUsd1d, | ||
| }; | ||
| }) | ||
| .filter(utils.keepFinite); | ||
| }; | ||
|
|
||
| module.exports = { | ||
| timetravel: false, | ||
| apy, | ||
| url: 'https://shapeswap.xyz/', | ||
| }; | ||
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
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.
Incorrect fallback for missing prior volume data.
When
priorVolumeById[p.id]is undefined (pool missing from prior data or prior query failed), the fallbackvolumeUsdAllcauses the calculation to becomevolumeUsdAll - volumeUsdAll = 0, resulting in zero 1-day volume and zero APY for affected pools.The error message on line 53 states "falling back to zero prior volume", which suggests the intent is to treat prior volume as 0 (not 1-day volume as 0). This would make 1-day volume equal to current cumulative volume for new pools or when prior data is unavailable.
🐛 Proposed fix to use zero prior volume as fallback
📝 Committable suggestion
🤖 Prompt for AI Agents