From 69486b977016885afb1200c5e88b19ce18b63cb5 Mon Sep 17 00:00:00 2001 From: 0xgnek <0xgnek@gmail.com> Date: Fri, 9 Feb 2024 14:24:37 +0000 Subject: [PATCH] fix add blacklistedChains --- dexs/sunswap/index.ts | 3 ++- helpers/getBlock.ts | 54 +++++++++++++++++++++++++++++++++++++++---- package.json | 2 +- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/dexs/sunswap/index.ts b/dexs/sunswap/index.ts index af3d391140..3c5701ac03 100644 --- a/dexs/sunswap/index.ts +++ b/dexs/sunswap/index.ts @@ -15,7 +15,8 @@ interface IVolumeall { const fetch = async (timestamp: number) => { const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)) - const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint)); + const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint)).data; + const totalVolume = historicalVolume .filter(volItem => (new Date(volItem.time).getTime() / 1000) <= dayTimestamp) .reduce((acc, { volume }) => acc + Number(volume), 0) diff --git a/helpers/getBlock.ts b/helpers/getBlock.ts index 60c646b4b0..c279871683 100644 --- a/helpers/getBlock.ts +++ b/helpers/getBlock.ts @@ -6,7 +6,53 @@ import * as sdk from "@defillama/sdk" import { httpGet } from "../utils/fetchURL"; const retry = require("async-retry") -const blacklistedChains = ['sui'] +const blacklistedChains: string[] = [ + "tron", + "juno", + "cardano", + "litecoin", + "bitcoin", + "tezos", + "solana", + "elrond", + "defichain", + "stacks", + "KARURA", + "hedera", + "eos", + "icon", + "clv", + "stellar", + "algorand", + "mixin", + "thorchain", + "flow", + "aptos", + "neo", + "phantasma", + "starknet", + "carbon", + "vechain", + "wax", + "injective", + "ton", + "obyte", + "zksync", + "sora", + "cosmos", + "hydra", + "icp", + "hydradx", + "osmosis", + "sei", + "ergo", + "radixdlt", + "near", + "persistence", + "sui", + "neutron", + "terra2" +]; async function getBlock(timestamp: number, chain: Chain, chainBlocks = {} as ChainBlocks) { if (blacklistedChains.includes(chain)) { @@ -42,9 +88,9 @@ async function getBlock(timestamp: number, chain: Chain, chainBlocks = {} as Cha else if (chain as CHAIN === CHAIN.POLYGON_ZKEVM || chain === CHAIN.VISION || chain as CHAIN === CHAIN.ERA) return sdk.api.util.lookupBlock(timestamp, { chain }).then((blockData: any) => blockData.block) // TODO after get block support chain polygon_zkevm then swith to use api https://coins.llama.fi/block else if (chain as CHAIN === CHAIN.WAVES) - block = Number((await retry(async () => (await httpGet(`https://nodes.wavesnodes.com/blocks/heightByTimestamp/${timestamp}`).catch((e) => { + block = Number((await retry(async () => (await httpGet(`https://nodes.wavesnodes.com/blocks/heightByTimestamp/${(timestamp * 1000)}`).catch((e) => { throw new Error(`Error getting block: ${chain} ${timestamp} ${e.message}`) - }))?.height))); + }))?.height, { retries: 3 }))); else if (chain === CHAIN.BASE) block = Number((await retry(async () => (await httpGet(`https://base.blockscout.com/api?module=block&action=getblocknobytime×tamp=${timestamp}&closest=before`).catch((e) => { throw new Error(`Error getting block: ${chain} ${timestamp} ${e.message}`) @@ -56,7 +102,7 @@ async function getBlock(timestamp: number, chain: Chain, chainBlocks = {} as Cha else block = Number((await retry(async () => (await httpGet(`https://coins.llama.fi/block/${chain}/${timestamp}`).catch((e) => { throw new Error(`Error getting block: ${chain} ${timestamp} ${e.message}`) - }))?.height, { retries: 3 }))); + }))?.height, { retries: 1 }))); if (block) chainBlocks[chain] = block return block // https://base.blockscout.com diff --git a/package.json b/package.json index 31c963925b..c195f00278 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "update-submodules": "git submodule update --init --recursive --remote --merge", - "test": "yarn run update-submodules && ts-node cli/testAdapter.ts", + "test": "yarn run update-submodules && ts-node --transpile-only cli/testAdapter.ts", "ts-check": "yarn run update-submodules && tsc --project tsconfig.json", "ts-check-cli": "yarn run update-submodules && tsc --project tsconfig.cli.json", "interactive": "node cli/interactive.js"