Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions projects/cookswap/index.js
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
}
}

1 change: 1 addition & 0 deletions projects/helper/chains.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
"jbc",
"joltify",
"juno",
"juchain",
"kadena",
"karak",
"kardia",
Expand Down
10 changes: 9 additions & 1 deletion projects/helper/tokenMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@ const fixBalancesTokens = {
},
somnia: {
'0x936ab8c674bcb567cd5deb85d8a216494704e9d8': { coingeckoId: 'ethereum', decimals: 18 }
}
},
juchain: {
[nullAddress]: { coingeckoId: "ju", decimals: 18 },
'0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE': { coingeckoId: "ju", decimals: 18 },
'0x4d1B49B424afd7075d3c063adDf97D5575E1c7E2': { coingeckoId: "wju", decimals: 18 },
'0x80077F108Dd73B709C43A1a13F0EEF25e48f7D0e': { coingeckoId: "ethereum", decimals: 18 },
'0x5a68b722098F559F275baC1E64AedEA39b3E97c1': { coingeckoId: "usdc", decimals: 18 },
'0xc8e19C19479a866142B42fB390F2ea1Ff082E0D2': { coingeckoId: "tether", decimals: 18 },
},
}

ibcChains.forEach(chain => fixBalancesTokens[chain] = { ...ibcMappings, ...(fixBalancesTokens[chain] || {}) })
Expand Down
82 changes: 82 additions & 0 deletions projects/jamm/index.js
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)
Copy link
Collaborator

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

Copy link
Author

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.

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
}
}
Loading