Skip to content

Commit

Permalink
fix zrx
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng committed Apr 13, 2024
1 parent e3c906d commit 928ea40
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
2 changes: 2 additions & 0 deletions dexs/0x/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BreakdownAdapter, FetchV2, } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { adapter_aggs } from './zrx/index'

// https://0x.org/docs/introduction/0x-cheat-sheet
const config = {
Expand Down Expand Up @@ -91,6 +92,7 @@ const adapter: BreakdownAdapter = {
// "0x ERC1155": adaptersERC1155,
// "0x ERC721": adaptersERC721,
"0x Limit": adaptersERCLimit,
"zrx": adapter_aggs["adapter"]
},
version: 2
}
Expand Down
49 changes: 29 additions & 20 deletions aggregators/zrx/index.ts → dexs/0x/zrx/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GraphQLClient, gql } from "graphql-request";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import { getEnv } from "../../helpers/env";
import { getUniqStartOfTodayTimestamp } from "../../../helpers/getUniSubgraphVolume";
import { getEnv } from "../../../helpers/env";
import { FetchOptions } from "../../../adapters/types";

const CHAINS = [
"Arbitrum",
Expand Down Expand Up @@ -41,35 +42,43 @@ const getVolumeByChain = async (chain: string) => {
return data;
};

const fetch = (chain: string) => async (timestamp: number) => {
const fetch = async (options: FetchOptions) => {
const unixTimestamp = getUniqStartOfTodayTimestamp(
new Date(timestamp * 1000)
new Date(options.endTimestamp * 1000)
);

const data = await getVolumeByChain(chain);
const dayData = data.find(
({ timestamp }: { timestamp: number }) =>
getUniqStartOfTodayTimestamp(new Date(timestamp)) === unixTimestamp
);

return {
dailyVolume: dayData.volumeUSD,
timestamp: unixTimestamp,
};
try {
const data = await getVolumeByChain(options.chain);
const dayData = data.find(
({ timestamp }: { timestamp: number }) =>
getUniqStartOfTodayTimestamp(new Date(timestamp)) === unixTimestamp
);
return {
dailyVolume: dayData.volumeUSD,
timestamp: unixTimestamp,
};
} catch (e) {
console.error(e);
return {
dailyVolume: "0",
timestamp: unixTimestamp,
};
}
};

const adapter: any = {
const adapter_aggs: any = {
version: 2,
adapter: {
...Object.values(CHAINS).reduce((acc, chain) => {
return {
...acc,
[chain]: {
fetch: fetch(chain),
start: 1671062400,
fetch: fetch,
start: 0,
},
};
}, {}),
},
};

export default adapter;
export {
adapter_aggs
}

0 comments on commit 928ea40

Please sign in to comment.