Skip to content

Commit

Permalink
move unidex
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng committed Apr 26, 2024
1 parent 763a326 commit 0129ad0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 53 deletions.
53 changes: 0 additions & 53 deletions aggregators/unidex/index.ts

This file was deleted.

2 changes: 2 additions & 0 deletions dexs/unidex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getTimestampAtStartOfDayUTC } from "../../utils/date";
import { Chain } from "@defillama/sdk/build/general";
import request, { gql } from "graphql-request";
import { adapteraggderivative } from './unidex-agg-perp/index'
import { adapter_dexs_agg } from './unidex-dexs-agg/index'

type TChainIDs = {
[key in Chain]?: number;
Expand Down Expand Up @@ -121,6 +122,7 @@ const adapterbreakdown: BreakdownAdapter = {
breakdown: {
"unidex": adapter["adapter"],
"unidex-agg-derivative": adapteraggderivative["adapter"],
"unidex-dexs-agg": adapter_dexs_agg["adapter"],
}
}
export default adapterbreakdown;
62 changes: 62 additions & 0 deletions dexs/unidex/unidex-dexs-agg/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { FetchResult } from "../../../adapters/types";
import { getUniqStartOfTodayTimestamp } from "../../../helpers/getUniSubgraphVolume";
import { CHAIN } from "../../../helpers/chains";
import { httpGet } from "../../../utils/fetchURL";

const chainsMap: Record<string, string> = {
ETHEREUM: "ethereum",
ARBITRUM: "arbitrum",
POLYGON: "polygon",
BNB: "bsc",
OPTIMISM: "optimism",
BASE: "base",
FANTOM: "fantom",
METIS: "metis",
GNOSIS: "gnosis",
[CHAIN.ERA]: "zksync",
AVALANCHE: "avax",
};

const fetch =
(chain: string) =>
async (timestamp: number): Promise<FetchResult> => {
try {
const unixTimestamp = getUniqStartOfTodayTimestamp();

const response = await httpGet(`https://unidexswaps.metabaseapp.com/api/public/dashboard/f0dd81ef-7bc7-47b5-9ac4-281c7cd71bdc/dashcard/11/card/12?parameters=%5B%5D`)

const rows = response.data.rows;
const chainData = rows.find(
(row: any) => row[1].toLowerCase() === chain
);

return {
dailyVolume: chainData ? chainData[2]?.toString() : "0",
timestamp: unixTimestamp,
};
} catch (e: any) {
return {
dailyVolume: "0",
timestamp: timestamp,
}
}
};

const adapter_dexs_agg: any = {
adapter: {
...Object.values(chainsMap).reduce((acc, chain) => {
return {
...acc,
[(chainsMap as any)[chain] || chain]: {
fetch: fetch(chain),
runAtCurrTime: true,
start: 1704348000,
},
};
}, {}),
},
};

export {
adapter_dexs_agg
}

0 comments on commit 0129ad0

Please sign in to comment.