Skip to content

Commit

Permalink
fix add blacklistedChains
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng committed Feb 9, 2024
1 parent 9edd60e commit 69486b9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
3 changes: 2 additions & 1 deletion dexs/sunswap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
54 changes: 50 additions & 4 deletions helpers/getBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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&timestamp=${timestamp}&closest=before`).catch((e) => {
throw new Error(`Error getting block: ${chain} ${timestamp} ${e.message}`)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 69486b9

Please sign in to comment.