-
Notifications
You must be signed in to change notification settings - Fork 6.5k
RPC uses subgraph instead #16690
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
jksusu
wants to merge
3
commits into
DefiLlama:main
Choose a base branch
from
jksusu:add-juchain-cookswap
base: main
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
RPC uses subgraph instead #16690
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,87 @@ | ||
| // 使用 Subgraph 接口直接获取 USD 价格 | ||
| async function tvl(api) { | ||
| // 使用完整的 GraphQL 查询 | ||
| const query = ` | ||
| query PoolList( | ||
| $first: Int = 100 | ||
| $skip: Int = 0 | ||
| $where: Pool_filter = {} | ||
| $q: String = "" | ||
| $orderBy: Pool_orderBy = totalValueLockedUSD | ||
| $orderDirection: OrderDirection = desc | ||
| ) { | ||
| pools( | ||
| first: $first | ||
| skip: $skip | ||
| orderBy: $orderBy | ||
| orderDirection: $orderDirection | ||
| where: { | ||
| and: [ | ||
| $where | ||
| { | ||
| or: [ | ||
| { token0_: { name_contains_nocase: $q } } | ||
| { token0_: { symbol_contains_nocase: $q } } | ||
| { token1_: { name_contains_nocase: $q } } | ||
| { token1_: { symbol_contains_nocase: $q } } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ) { | ||
| id | ||
| token0 { id symbol name } | ||
| token1 { id symbol name } | ||
| feeTier | ||
| totalValueLockedUSD | ||
| hourData24h: poolHourData(first: 24, orderBy: periodStartUnix, orderDirection: desc) { | ||
| periodStartUnix | ||
| volumeUSD | ||
| tvlUSD | ||
| } | ||
| } | ||
| } | ||
| ` | ||
|
|
||
| try { | ||
| const response = await fetch('https://www.cookpump.ai/subgraphs/name/v3-juchain-subgraph', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: JSON.stringify({ | ||
| query, | ||
| variables: { | ||
| first: 100, | ||
| skip: 0, | ||
| orderBy: "totalValueLockedUSD", | ||
| orderDirection: "desc", | ||
| where: {}, | ||
| q: "" | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| const data = await response.json() | ||
| const pools = data.data.pools | ||
| let totalUSD = 0 | ||
| pools.forEach(pool => { | ||
| const usdValue = parseFloat(pool.totalValueLockedUSD) | ||
| totalUSD += usdValue | ||
| }) | ||
| return { | ||
| 'tether': totalUSD | ||
| } | ||
|
|
||
| } catch (error) { | ||
| return {} | ||
| } | ||
| } | ||
|
|
||
|
|
||
| module.exports = { | ||
| juchain: { | ||
| tvl | ||
| } | ||
| } | ||
|
|
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 |
|---|---|---|
|
|
@@ -205,6 +205,7 @@ | |
| "jbc", | ||
| "joltify", | ||
| "juno", | ||
| "juchain", | ||
| "kadena", | ||
| "karak", | ||
| "kardia", | ||
|
|
||
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
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,82 @@ | ||
| const { sumTokens2 } = require('../helper/unwrapLPs') | ||
|
|
||
| // 使用 Subgraph 接口直接获取 USD 价格 | ||
| async function tvl(api) { | ||
| console.log('Using Subgraph USD values for Jamm TVL calculation') | ||
|
|
||
| // 使用 jamm 的 GraphQL 查询 | ||
| const query = ` | ||
| query AllPairs($first: Int!, $skip: Int!, $search: String) { | ||
| pairs( | ||
| first: $first | ||
| skip: $skip | ||
| where: {or: [{token0_: {symbol_contains_nocase: $search}}, {token1_: {symbol_contains_nocase: $search}}]} | ||
| orderBy: reserveUSD | ||
| orderBySecondary: id | ||
| orderDirection: desc | ||
| ) { | ||
| id | ||
| fee | ||
| reserveUSD | ||
| reserveETH | ||
| yearApr0 | ||
| reserve0 | ||
| reserve1 | ||
| token0 { | ||
| id | ||
| name | ||
| symbol | ||
| } | ||
| token1 { | ||
| id | ||
| name | ||
| symbol | ||
| } | ||
| volumeUSD | ||
| txCount | ||
| } | ||
| } | ||
| ` | ||
|
|
||
| try { | ||
| const response = await fetch('https://jamm.fun/api/graph', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: JSON.stringify({ | ||
| operationName: "AllPairs", | ||
| query, | ||
| variables: { | ||
| first: 100, | ||
| skip: 0, | ||
| search: "" | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| const data = await response.json() | ||
| const pairs = data.data.pairs | ||
|
|
||
| let totalUSD = 0 | ||
| pairs.forEach(pair => { | ||
| const usdValue = parseFloat(pair.reserveUSD) | ||
| totalUSD += usdValue | ||
| }) | ||
|
|
||
| console.log(`Total TVL from Jamm Subgraph: ${totalUSD}`) | ||
| return { | ||
| 'tether': totalUSD | ||
| } | ||
|
|
||
| } catch (error) { | ||
| console.error('Error fetching from Jamm Subgraph:', error) | ||
| return {} | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| juchain: { | ||
| tvl | ||
| } | ||
| } | ||
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.
can we use erc20:balanceOf instead of reading USD values from the subgraph
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.
#16628 (comment) Our chain RPC service provider does not support performance. Can we use subgraphs entirely? Please take a look at this closed PR.