From 2141082ef5f81da656d35fb3c2359cc56acca99e Mon Sep 17 00:00:00 2001 From: bmino Date: Tue, 29 Aug 2023 12:22:40 -0400 Subject: [PATCH] sdk 5.3.5 Includes avalanche subgraph and subgraph fixes --- package.json | 2 +- src/handlers/pangolin.ts | 6 ++++-- src/handlers/png.ts | 12 ++++++++---- src/utils/queries.ts | 6 +++--- yarn.lock | 8 ++++---- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 99e48e4..26a56ce 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "license": "BSD-3-Clause", "dependencies": { - "@pangolindex/sdk": "5.3.4", + "@pangolindex/sdk": "5.3.5", "worktop": "0.8.0-next.5" }, "devDependencies": { diff --git a/src/handlers/pangolin.ts b/src/handlers/pangolin.ts index 07487de..d2aff09 100644 --- a/src/handlers/pangolin.ts +++ b/src/handlers/pangolin.ts @@ -47,11 +47,13 @@ export const addresses: Handler = async (_, context) => { export const average: Handler = async (_, context) => { const chainInfo = getChainInfo(context.params.chain); + const entityName = chainInfo.chainId === '43114' ? 'factories' : 'pangolinFactories'; + const result = await gql.request( - QUERIES._FACTORY(chainInfo.factory), + QUERIES._FACTORY(entityName), chainInfo.subgraph_exchange, ); - const {totalVolumeUSD, txCount} = result.pangolinFactories[0]; + const {totalVolumeUSD, txCount} = result[entityName][0]; const text = (Number.parseFloat(totalVolumeUSD) / Number.parseInt(txCount, 10)).toFixed(2); diff --git a/src/handlers/png.ts b/src/handlers/png.ts index e475eea..4efcff5 100644 --- a/src/handlers/png.ts +++ b/src/handlers/png.ts @@ -10,12 +10,14 @@ import * as QUERIES from '../utils/queries'; export const tvl: Handler = async (_, context) => { const chainInfo = getChainInfo(context.params.chain); + const entityName = chainInfo.chainId === '43114' ? 'factories' : 'pangolinFactories'; + const result = await gql.request( - QUERIES._FACTORY(chainInfo.factory), + QUERIES._FACTORY(entityName), chainInfo.subgraph_exchange, ); - const text = Number.parseFloat(result.pangolinFactories[0].totalLiquidityUSD).toFixed(2); + const text = Number.parseFloat(result[entityName][0].totalLiquidityUSD).toFixed(2); return send(200, text, { 'Cache-Control': 'public,s-maxage=300', @@ -25,12 +27,14 @@ export const tvl: Handler = async (_, context) => { export const volume: Handler = async (_, context) => { const chainInfo = getChainInfo(context.params.chain); + const entityName = chainInfo.chainId === '43114' ? 'factories' : 'pangolinFactories'; + const result = await gql.request( - QUERIES._FACTORY(chainInfo.factory), + QUERIES._FACTORY(entityName), chainInfo.subgraph_exchange, ); - const text = Number.parseFloat(result.pangolinFactories[0].totalVolumeUSD).toFixed(2); + const text = Number.parseFloat(result[entityName][0].totalVolumeUSD).toFixed(2); return send(200, text, { 'Cache-Control': 'public,s-maxage=300', diff --git a/src/utils/queries.ts b/src/utils/queries.ts index c64755e..c9cafef 100644 --- a/src/utils/queries.ts +++ b/src/utils/queries.ts @@ -1,6 +1,6 @@ -export const _FACTORY = (FACTORY_ADDRESS: string) => ` -query pangolinFactories { - pangolinFactories(where: { id: "${FACTORY_ADDRESS}" }) { +export const _FACTORY = (ENTITY_NAME: string) => ` +query ${ENTITY_NAME} { + ${ENTITY_NAME}(where: { id: "1" }) { id totalVolumeUSD totalLiquidityUSD diff --git a/yarn.lock b/yarn.lock index 3e681fb..401cff5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -623,10 +623,10 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" -"@pangolindex/sdk@5.3.4": - version "5.3.4" - resolved "https://registry.yarnpkg.com/@pangolindex/sdk/-/sdk-5.3.4.tgz#b48aebd063ae6f4abd9930199fb118b58246d159" - integrity sha512-Xj2pLgI0EK9DNEhuMQVchmmk6UC6G27hdzjiL71AnNYpB+abt7ZB5Ou6SdjeeHQJIxsxfVhV/BRY096XDGquog== +"@pangolindex/sdk@5.3.5": + version "5.3.5" + resolved "https://registry.yarnpkg.com/@pangolindex/sdk/-/sdk-5.3.5.tgz#6cf491976493bd24444eae3f24a05ad7c867f36b" + integrity sha512-YMhAwJhvj7U4bpLXCw/X5ePWmNcxrbDCUSFpIN84L04dM8qWTFCF3FXGtYkQRJwoK7Gfqg8XusKIFTEWGwJbrA== dependencies: big.js "^5.2.2" decimal.js-light "^2.5.0"