Skip to content

Commit

Permalink
Fix API response data format
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Feb 5, 2024
1 parent a3f11f1 commit 554a296
Show file tree
Hide file tree
Showing 191 changed files with 373 additions and 618 deletions.
2 changes: 1 addition & 1 deletion aggregator-derivatives/logx-aggregator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface IAPIResponse {
const fetch = async (timestamp: number): Promise<FetchResult> => {
const { dailyVolume, totalVolume }: IAPIResponse = (
await fetchURL(`${URL}${endpoint}${timestamp}`)
).data;
);
return {
dailyVolume,
totalVolume,
Expand Down
22 changes: 5 additions & 17 deletions aggregators/1inch-agg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,18 @@ const chainsMap: Record<string, string> = {

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

try {
const data = (
await fetchURLWithRetry(
`https://api.dune.com/api/v1/query/1736855/results`
)
).data;
const chainData = data?.result?.rows?.find(
async (_: number): Promise<FetchResult> => {
const unixTimestamp = getUniqStartOfTodayTimestamp();
const data = await fetchURLWithRetry(`https://api.dune.com/api/v1/query/1736855/results`)
const chainData = data.result.rows.find(
(row: any) => chainsMap[row.blockchain] === chain
);

return {
dailyVolume: chainData.volume_24h,
timestamp: unixTimestamp,
};
} catch (e) {
return {
dailyVolume: "0",
timestamp: unixTimestamp,
};
}
};
};

const adapter: any = {
adapter: {
Expand Down
2 changes: 1 addition & 1 deletion aggregators/aftermath-aggregator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const URL = "https://aftermath.finance/api/router/volume-24hrs";
const fetch = async (timestamp: number): Promise<FetchResult> => {
const dailyVolume = (
await fetchURL(`${URL}`)
).data;
);

return {
dailyVolume,
Expand Down
2 changes: 1 addition & 1 deletion aggregators/avnu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface IAPIResponse {
}
const fetch = async (timestamp: number): Promise<FetchResult> => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
const {dailyVolume, totalVolume}: IAPIResponse = (await fetchURL(`${URL}${endpoint}${timestamp * 1000}`)).data;
const {dailyVolume, totalVolume}: IAPIResponse = (await fetchURL(`${URL}${endpoint}${timestamp * 1000}`));
return {
dailyVolume,
totalVolume,
Expand Down
19 changes: 4 additions & 15 deletions aggregators/conveyor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@ const chainsMap: Record<string, string> = {

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

try {
const data = (
await fetchURLWithRetry(
`https://api.dune.com/api/v1/query/3325921/results`
)
).data;
const data = await fetchURLWithRetry(`https://api.dune.com/api/v1/query/3325921/results`)
const chainData = data?.result?.rows?.find(
(row: any) => chainsMap[row.blockchain] === chain
);
Expand All @@ -30,13 +25,7 @@ const fetch =
dailyVolume: chainData.volume_24h,
timestamp: unixTimestamp,
};
} catch (e) {
return {
dailyVolume: "0",
timestamp: unixTimestamp,
};
}
};
};

const adapter: any = {
adapter: {
Expand Down
21 changes: 4 additions & 17 deletions aggregators/cowswap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,10 @@ const chainsMap: Record<string, string> = {

const fetch =
() =>
async (timestamp: number): Promise<FetchResult> => {
const unixTimestamp = getUniqStartOfTodayTimestamp(
new Date(timestamp * 1000)
);
async (timestamp: number): Promise<FetchResult> => {
const unixTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));

try {
const data = (
await fetchURLWithRetry(
"https://api.dune.com/api/v1/query/3321375/results"
)
).data;
const data = await fetchURLWithRetry("https://api.dune.com/api/v1/query/3321375/results")
const chainData = data?.result?.rows.find(
({ aggregate_by }: { aggregate_by: string }) =>
getUniqStartOfTodayTimestamp(new Date(aggregate_by)) === unixTimestamp
Expand All @@ -29,13 +22,7 @@ const fetch =
dailyVolume: chainData?.volume ?? "0",
timestamp: unixTimestamp,
};
} catch (e) {
return {
dailyVolume: "0",
timestamp: unixTimestamp,
};
}
};
};

const adapter: any = {
adapter: {
Expand Down
2 changes: 1 addition & 1 deletion aggregators/deflex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface IAPIResponse {

const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const response: IAPIResponse[] = (await fetchURL(URL)).data.last_24h;
const response: IAPIResponse[] = (await fetchURL(URL)).last_24h;
return {
dailyVolume: `${response.reduce((prev: number, current: any) => current.volume + prev, 0)}`,
timestamp: dayTimestamp,
Expand Down
2 changes: 1 addition & 1 deletion aggregators/dexhunter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface IAPIResponse {

const fetchData = async (period: '24h' | 'all'): Promise<string> => {
const response = await postURL(`${URL}${endpoint}`, { period });
const data: IAPIResponse[] = response.data;
const data: IAPIResponse[] = response;

const dexhunterData = data.find(d => d.is_dexhunter);
if (!dexhunterData) {
Expand Down
2 changes: 1 addition & 1 deletion aggregators/dforce/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface IAPIResponse {
};

const fetch = (chain: string) => async (timestamp: number) => {
const response: IAPIResponse = (await fetchURL(endpoints[chain])).data;
const response: IAPIResponse = (await fetchURL(endpoints[chain]));
const totalDailyVolume = response.data.preChain.reduce((acc,cur) => {return acc + parseInt(cur.volume)/10**18}, 0)
const t = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
return {
Expand Down
4 changes: 2 additions & 2 deletions aggregators/jupiter-aggregator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface IVolumeall {

const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint))?.data.volumeInUSD;
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint))?.volumeInUSD;
const totalVolume = historicalVolume
.filter(volItem => (new Date(volItem.groupTimestamp).getTime() / 1000) <= dayTimestamp)
.reduce((acc, { amount }) => acc + Number(amount), 0)
Expand All @@ -31,7 +31,7 @@ const fetch = async (timestamp: number) => {
};

const getStartTimestamp = async () => {
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint))?.data.volumeInUSD;
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint))?.volumeInUSD;
return (new Date(historicalVolume[historicalVolume.length - 1].groupTimestamp).getTime() / 1000);
}
const adapter: SimpleAdapter = {
Expand Down
2 changes: 1 addition & 1 deletion aggregators/kanalabs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CHAIN } from "../../helpers/chains";
const URL = "https://stats.kanalabs.io/volume";

const fetch = async (timestamp: number): Promise<FetchResultVolume> => {
const dailyVolume = (await fetchURL(`${URL}?chainId=1`)).data.data;
const dailyVolume = (await fetchURL(`${URL}?chainId=1`)).data;
return {
timestamp,
dailyVolume: dailyVolume.today.volume,
Expand Down
2 changes: 1 addition & 1 deletion aggregators/kyberswap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const fetch = (chain: string) => async (timestamp: number) => {
await fetchURL(
`https://common-service.kyberswap.com/api/v1/aggregator/volume/daily?chainId=${chainToId[chain]}&timestamps=${unixTimestamp}`
)
).data.data?.volumes?.[0];
).data?.volumes?.[0];

return {
dailyVolume: data?.value ?? "0",
Expand Down
4 changes: 2 additions & 2 deletions aggregators/llamaswap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ const fetch =
);

return {
dailyVolume: dailyVolume.data.volume || "0",
totalVolume: totalVolume.data.volume || "0",
dailyVolume: dailyVolume.volume || "0",
totalVolume: totalVolume.volume || "0",
timestamp: dayTimestamp,
};
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion aggregators/logx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface IAPIResponse {
const fetch = async (timestamp: number): Promise<FetchResult> => {
const { dailyVolume, totalVolume }: IAPIResponse = (
await fetchURL(`${URL}${endpoint}${timestamp}`)
).data;
);
return {
dailyVolume,
totalVolume,
Expand Down
2 changes: 1 addition & 1 deletion aggregators/openocean/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const fetch =
);

return {
dailyVolume: data.data.data[chainsMap[chain] || chain]?.volume,
dailyVolume: data.data[chainsMap[chain] || chain]?.volume,
timestamp: unixTimestamp,
};
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion aggregators/plexus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const fetch = (chainId: number) => {
await fetchURL(
`https://api.plexus.app/v1/dashboard/volume?date=${dateString}`
)
).data.data;
).data;
const dailyVolume: number = data[chainId] || 0;
return {
dailyVolume: dailyVolume.toString(),
Expand Down
2 changes: 1 addition & 1 deletion aggregators/swapgpt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const endpoint = "stats/getDefiLamaStats"

const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const historicalVolume: IVolumeall[] = (await fetchURL(`${baseUrl}/${endpoint}`))?.data.volumeInUsd
const historicalVolume: IVolumeall[] = (await fetchURL(`${baseUrl}/${endpoint}`))?.volumeInUsd
const totalVolume = historicalVolume
.filter(volItem => (new Date(volItem.grouptimestamp).getTime() / 1000) <= dayTimestamp)
.reduce((acc, { amount }) => acc + Number(amount), 0)
Expand Down
19 changes: 4 additions & 15 deletions aggregators/unidex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,10 @@ const chainsMap: Record<string, string> = {

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

try {
const response = (
await fetchURLWithRetry(
`https://unidexswaps.metabaseapp.com/api/public/dashboard/f0dd81ef-7bc7-47b5-9ac4-281c7cd71bdc/dashcard/11/card/12?parameters=%5B%5D`
)
).data;
const response = await fetchURLWithRetry(`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(
Expand All @@ -37,13 +32,7 @@ const fetch =
dailyVolume: chainData ? chainData[2].toString() : "0",
timestamp: unixTimestamp,
};
} catch (e) {
return {
dailyVolume: "0",
timestamp: unixTimestamp,
};
}
};
};

const adapter: any = {
adapter: {
Expand Down
41 changes: 11 additions & 30 deletions aggregators/yield-yak/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,18 @@ const fetch = (chain: string) => async (timestamp: number) => {
new Date(timestamp * 1000)
);

try {
const data = await (
await fetchURLWithRetry(
"https://api.dune.com/api/v1/query/3321376/results"
)
).data?.result?.rows;
const dayData = data.find(
({
block_date,
blockchain,
project,
}: {
block_date: number;
blockchain: string;
project: string;
}) =>
getUniqStartOfTodayTimestamp(new Date(block_date)) === unixTimestamp &&
blockchain === (chainMap[chain] || chain) &&
project === NAME
);
const data = (await fetchURLWithRetry("https://api.dune.com/api/v1/query/3321376/results")).result?.rows;
const dayData = data.find(
({ block_date, blockchain, project, }: { block_date: number; blockchain: string; project: string; }) =>
getUniqStartOfTodayTimestamp(new Date(block_date)) === unixTimestamp &&
blockchain === (chainMap[chain] || chain) &&
project === NAME
);

return {
dailyVolume: dayData?.trade_amount ?? "0",
timestamp: unixTimestamp,
};
} catch (e) {
return {
dailyVolume: "0",
timestamp: unixTimestamp,
};
}
return {
dailyVolume: dayData?.trade_amount ?? "0",
timestamp: unixTimestamp,
};
};

const adapter: any = {
Expand Down
2 changes: 1 addition & 1 deletion dexs/10kswap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface IVolumeall {

const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint))?.data.data.volumes;
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint))?.data.volumes;
const totalVolume = historicalVolume
.filter(volItem => (new Date(volItem.date).getTime() / 1000) <= dayTimestamp)
.reduce((acc, { volume }) => acc + Number(volume), 0)
Expand Down
2 changes: 1 addition & 1 deletion dexs/4swap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface IAPIResponse {

const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const response: IAPIResponse[] = (await fetchURL(URL))?.data?.data.pairs;
const response: IAPIResponse[] = (await fetchURL(URL))?.data.pairs;
const dailyVolume = response
.reduce((acc, { volume_24h }) => acc + Number(volume_24h), 0);

Expand Down
2 changes: 1 addition & 1 deletion dexs/ICDex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fetchURL from "../../utils/fetchURL";


const fetch = async (timestamp: number): Promise<FetchResultVolume> => {
let historicalVolume = (await fetchURL('https://gwhbq-7aaaa-aaaar-qabya-cai.raw.icp0.io/v1/latest')).data;
let historicalVolume = (await fetchURL('https://gwhbq-7aaaa-aaaar-qabya-cai.raw.icp0.io/v1/latest'));
let dailyVolume = 0;
let totalVolume = 0;
for (let key in historicalVolume) {
Expand Down
2 changes: 1 addition & 1 deletion dexs/MantisSwap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const fetch = (chain: string) => async (timestamp: number) => {
await fetchURL(
`https://api.mantissa.finance/api/pool/stats/volume/${chain}/?from_timestamp=${from}&to_timestamp=${to}`
)
).data;
);
return {
totalVolume: `${stats.total_volume}`,
dailyVolume: `${stats.daily_volume}`,
Expand Down
2 changes: 1 addition & 1 deletion dexs/aark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const endpoint = "https://api.aark.digital/stats/volume/futures";
const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));

const res = (await fetchURL(`${endpoint}/${timestamp}`))?.data
const res = (await fetchURL(`${endpoint}/${timestamp}`))

return {
totalVolume: res.data.totalVolume,
Expand Down
2 changes: 1 addition & 1 deletion dexs/aevo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function fetchAevoVolumeData(
}

async function getAevoVolumeData(endpoint: string): Promise<IAevoVolumeResponse> {
return (await fetchURL(endpoint))?.data;
return (await fetchURL(endpoint));
}

export default adapter;
2 changes: 1 addition & 1 deletion dexs/aftermath-fi-amm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const URL = "https://aftermath.finance/api/pools/volume-24hrs";
const fetch = async (timestamp: number): Promise<FetchResult> => {
const dailyVolume = (
await fetchURL(`${URL}`)
).data;
);

return {
dailyVolume,
Expand Down
Loading

0 comments on commit 554a296

Please sign in to comment.