From 3a750cc417309536aed8b333ecef1dde04af1a66 Mon Sep 17 00:00:00 2001 From: anchor Date: Fri, 10 Oct 2025 18:47:09 +0800 Subject: [PATCH 1/3] Add Juchain Cookswap --- projects/cookswap/index.js | 14 ++++++++++++++ projects/helper/chain/juchain.js | 23 +++++++++++++++++++++++ projects/helper/chains.json | 1 + projects/helper/tokenMapping.js | 10 +++++++++- 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 projects/cookswap/index.js create mode 100644 projects/helper/chain/juchain.js diff --git a/projects/cookswap/index.js b/projects/cookswap/index.js new file mode 100644 index 00000000000..d0aaa4ecfd8 --- /dev/null +++ b/projects/cookswap/index.js @@ -0,0 +1,14 @@ +const { uniV3Export } = require('../helper/uniswapV3') + +const config = { + juchain: { + factory: '0xEB63eBEE36Ec44a81408E101C4899020145e2daB', + fromBlock: 15519262, + blacklistedTokens: [ + ], + permitFailure: true, + sumChunkSize: 200, + } +} + +module.exports = uniV3Export(config) diff --git a/projects/helper/chain/juchain.js b/projects/helper/chain/juchain.js new file mode 100644 index 00000000000..7037a01db05 --- /dev/null +++ b/projects/helper/chain/juchain.js @@ -0,0 +1,23 @@ +const { ChainApi } = require('@defillama/sdk'); + +const CHAIN_CONFIG = { + rpc: 'https://rpc.juchain.org', + chainId: 'juchain', + name: 'Juchain', + decimals: 18, + blockExplorerUrl: 'https://explorer.juscan.io', + blockExplorerApiUrl: 'https://explorer.juscan.io', + blockTime: 4, + gasToken: 'JU', + nativeCurrency: { + name: 'Juchain', + symbol: 'JU', + decimals: 18 + } +}; + +ChainApi.addChain(CHAIN_CONFIG); + +module.exports = { + CHAIN_CONFIG +}; diff --git a/projects/helper/chains.json b/projects/helper/chains.json index 931194b33d1..f41e36f041e 100644 --- a/projects/helper/chains.json +++ b/projects/helper/chains.json @@ -205,6 +205,7 @@ "jbc", "joltify", "juno", + "juchain", "kadena", "karak", "kardia", diff --git a/projects/helper/tokenMapping.js b/projects/helper/tokenMapping.js index 43f477f1842..0e32a8fe8bf 100644 --- a/projects/helper/tokenMapping.js +++ b/projects/helper/tokenMapping.js @@ -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] || {}) }) From dc725f2fe5b77a0b9d9be45851ffad844fa99d11 Mon Sep 17 00:00:00 2001 From: anchor Date: Wed, 15 Oct 2025 15:29:17 +0800 Subject: [PATCH 2/3] fix Llama RPC error! Bug Graph substitute --- projects/cookswap/index.js | 93 ++++++++++++++++++++++++++++---- projects/helper/chain/juchain.js | 23 -------- 2 files changed, 84 insertions(+), 32 deletions(-) delete mode 100644 projects/helper/chain/juchain.js diff --git a/projects/cookswap/index.js b/projects/cookswap/index.js index d0aaa4ecfd8..42b9fd417c4 100644 --- a/projects/cookswap/index.js +++ b/projects/cookswap/index.js @@ -1,14 +1,89 @@ -const { uniV3Export } = require('../helper/uniswapV3') +// 使用 Subgraph 接口直接获取 USD 价格 +async function tvl(api) { + console.log('Using Subgraph USD values for TVL calculation') + + // 使用完整的 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 {} + } +} + -const config = { +module.exports = { juchain: { - factory: '0xEB63eBEE36Ec44a81408E101C4899020145e2daB', - fromBlock: 15519262, - blacklistedTokens: [ - ], - permitFailure: true, - sumChunkSize: 200, + tvl } } -module.exports = uniV3Export(config) diff --git a/projects/helper/chain/juchain.js b/projects/helper/chain/juchain.js deleted file mode 100644 index 7037a01db05..00000000000 --- a/projects/helper/chain/juchain.js +++ /dev/null @@ -1,23 +0,0 @@ -const { ChainApi } = require('@defillama/sdk'); - -const CHAIN_CONFIG = { - rpc: 'https://rpc.juchain.org', - chainId: 'juchain', - name: 'Juchain', - decimals: 18, - blockExplorerUrl: 'https://explorer.juscan.io', - blockExplorerApiUrl: 'https://explorer.juscan.io', - blockTime: 4, - gasToken: 'JU', - nativeCurrency: { - name: 'Juchain', - symbol: 'JU', - decimals: 18 - } -}; - -ChainApi.addChain(CHAIN_CONFIG); - -module.exports = { - CHAIN_CONFIG -}; From 1a98a0e940e136ba91576c70f6bb7d749e650af9 Mon Sep 17 00:00:00 2001 From: anchor Date: Wed, 15 Oct 2025 15:31:28 +0800 Subject: [PATCH 3/3] del console.log --- projects/cookswap/index.js | 2 - projects/jamm/index.js | 82 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 projects/jamm/index.js diff --git a/projects/cookswap/index.js b/projects/cookswap/index.js index 42b9fd417c4..4d6e46b546d 100644 --- a/projects/cookswap/index.js +++ b/projects/cookswap/index.js @@ -1,7 +1,5 @@ // 使用 Subgraph 接口直接获取 USD 价格 async function tvl(api) { - console.log('Using Subgraph USD values for TVL calculation') - // 使用完整的 GraphQL 查询 const query = ` query PoolList( diff --git a/projects/jamm/index.js b/projects/jamm/index.js new file mode 100644 index 00000000000..996b739ba0e --- /dev/null +++ b/projects/jamm/index.js @@ -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 + } +}