From a2aeeb0b67dfcd8ed7c84c779233546fb2dda293 Mon Sep 17 00:00:00 2001 From: 0xdcota <32775237+0xdcota@users.noreply.github.com> Date: Mon, 17 Feb 2025 22:31:20 -0800 Subject: [PATCH 1/7] feat(defiapp): add defiapp volume data --- aggregators/defiapp/index.ts | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 aggregators/defiapp/index.ts diff --git a/aggregators/defiapp/index.ts b/aggregators/defiapp/index.ts new file mode 100644 index 0000000000..698f1b770c --- /dev/null +++ b/aggregators/defiapp/index.ts @@ -0,0 +1,54 @@ +import { SimpleAdapter, FetchResultVolume } from "../../adapters/types"; +import { CHAIN } from "../../helpers/chains"; +import fetchURL from "../../utils/fetchURL"; + +const DEFIAPP_24H_VOLUME_URL = "http://localhost:3000/api/stats/volume/24h"; // TBD +const START_TIMESTAMP = 1739433600; // 02.13.2025 + +type TChainId = { + [l: string]: string; +}; +const defiAppChainIdMap: TChainId = { + [CHAIN.ETHEREUM]: "1", + [CHAIN.BSC]: "56", + [CHAIN.ARBITRUM]: "42161", + [CHAIN.BASE]: "8453", + [CHAIN.SOLANA]: "1151111081099710", +}; + +interface IDefiAppResponse { + isLast24Hours: boolean; + startDate: string; + endDate: string; + totalUsdVolume: string; + perChainUsdVolume: Record; +} + +const fetch = (chain: string) => { + return async (timestamp: number): Promise => { + const dayResponse = ( + await fetchURL(DEFIAPP_24H_VOLUME_URL) + ); + + const dailyVolume = dayResponse.perChainUsdVolume[defiAppChainIdMap[chain]]; + return { + dailyVolume: dailyVolume || "0", + timestamp, + }; + }; +}; + +const adapter: SimpleAdapter = { + adapter: {}, +}; + +const chainKeys = Object.keys(defiAppChainIdMap); + +chainKeys.forEach((chain: string) => { + adapter.adapter[chain] = { + fetch: fetch(chain), + start: START_TIMESTAMP, + }; +}); + +export default adapter; From e23aa7b5fa1c505b48b33a9dee26fdd9228d952c Mon Sep 17 00:00:00 2001 From: 0xdcota <32775237+0xdcota@users.noreply.github.com> Date: Wed, 19 Feb 2025 10:41:29 -0800 Subject: [PATCH 2/7] chore: add options to send to when fetch retrying util function --- utils/fetchURL.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/fetchURL.ts b/utils/fetchURL.ts index bc6dcb302a..3a1923694a 100644 --- a/utils/fetchURL.ts +++ b/utils/fetchURL.ts @@ -1,11 +1,11 @@ import axios, { AxiosRequestConfig } from "axios" -export default async function fetchURL(url: string, retries = 3) { +export default async function fetchURL(url: string, options?: AxiosRequestConfig, retries = 3) { try { - const res = await httpGet(url) + const res = await httpGet(url, options) return res } catch (error) { - if (retries > 0) return fetchURL(url, retries - 1) + if (retries > 0) return fetchURL(url, options, retries - 1) throw error } } From fbd826c694e18ea4628d478102e96875f0a3fa84 Mon Sep 17 00:00:00 2001 From: 0xdcota <32775237+0xdcota@users.noreply.github.com> Date: Wed, 19 Feb 2025 10:42:24 -0800 Subject: [PATCH 3/7] chore(defiapp): complete defiapp adapter for reporting volume --- aggregators/defiapp/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/aggregators/defiapp/index.ts b/aggregators/defiapp/index.ts index 698f1b770c..4d886456e5 100644 --- a/aggregators/defiapp/index.ts +++ b/aggregators/defiapp/index.ts @@ -2,7 +2,7 @@ import { SimpleAdapter, FetchResultVolume } from "../../adapters/types"; import { CHAIN } from "../../helpers/chains"; import fetchURL from "../../utils/fetchURL"; -const DEFIAPP_24H_VOLUME_URL = "http://localhost:3000/api/stats/volume/24h"; // TBD +const DEFIAPP_24H_VOLUME_URL = "http://api.defi.app/api/stats/volume/24h"; // requires authentication const START_TIMESTAMP = 1739433600; // 02.13.2025 type TChainId = { @@ -27,7 +27,14 @@ interface IDefiAppResponse { const fetch = (chain: string) => { return async (timestamp: number): Promise => { const dayResponse = ( - await fetchURL(DEFIAPP_24H_VOLUME_URL) + await fetchURL(DEFIAPP_24H_VOLUME_URL, { + headers: { + "Content-Type": "application/json", + // DefiLlama team to advice on how this is setup + "X-API-KEY": process.env.DEFIAPP_API_KEY, + User: "defillama", + }, + }) ); const dailyVolume = dayResponse.perChainUsdVolume[defiAppChainIdMap[chain]]; @@ -40,6 +47,7 @@ const fetch = (chain: string) => { const adapter: SimpleAdapter = { adapter: {}, + isExpensiveAdapter: true, }; const chainKeys = Object.keys(defiAppChainIdMap); From e1ca61b8f3adc9e137d62530e7b361eb887c20e6 Mon Sep 17 00:00:00 2001 From: 0xdcota <32775237+0xdcota@users.noreply.github.com> Date: Wed, 19 Feb 2025 10:43:05 -0800 Subject: [PATCH 4/7] chore(defiapp): comment update --- aggregators/defiapp/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aggregators/defiapp/index.ts b/aggregators/defiapp/index.ts index 4d886456e5..31c8053bb1 100644 --- a/aggregators/defiapp/index.ts +++ b/aggregators/defiapp/index.ts @@ -30,7 +30,7 @@ const fetch = (chain: string) => { await fetchURL(DEFIAPP_24H_VOLUME_URL, { headers: { "Content-Type": "application/json", - // DefiLlama team to advice on how this is setup + // DefiLlama team to configure "X-API-KEY": process.env.DEFIAPP_API_KEY, User: "defillama", }, From 092243b84d253e4e8f7d9d10b11516e877c0de22 Mon Sep 17 00:00:00 2001 From: 0xdcota <32775237+0xdcota@users.noreply.github.com> Date: Wed, 19 Feb 2025 15:20:08 -0800 Subject: [PATCH 5/7] chore(defiapp): add methodology --- aggregators/defiapp/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/aggregators/defiapp/index.ts b/aggregators/defiapp/index.ts index 31c8053bb1..78ce6d468f 100644 --- a/aggregators/defiapp/index.ts +++ b/aggregators/defiapp/index.ts @@ -56,6 +56,12 @@ chainKeys.forEach((chain: string) => { adapter.adapter[chain] = { fetch: fetch(chain), start: START_TIMESTAMP, + meta: { + methodology: { + dailyVolume: + "Volume is calculated by summing the usd value of all token trades routed via DefiApp protocol in the last 24h.", + }, + }, }; }); From fb101a6332e7fe598eb9dd42369024d5423add98 Mon Sep 17 00:00:00 2001 From: 0xdcota <32775237+0xdcota@users.noreply.github.com> Date: Thu, 20 Feb 2025 07:57:58 -0800 Subject: [PATCH 6/7] chore: revert utils/fetchURL.ts to commit f94315c199fc827c375de557839d150e9e1cf572 --- utils/fetchURL.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/fetchURL.ts b/utils/fetchURL.ts index 3a1923694a..bc6dcb302a 100644 --- a/utils/fetchURL.ts +++ b/utils/fetchURL.ts @@ -1,11 +1,11 @@ import axios, { AxiosRequestConfig } from "axios" -export default async function fetchURL(url: string, options?: AxiosRequestConfig, retries = 3) { +export default async function fetchURL(url: string, retries = 3) { try { - const res = await httpGet(url, options) + const res = await httpGet(url) return res } catch (error) { - if (retries > 0) return fetchURL(url, options, retries - 1) + if (retries > 0) return fetchURL(url, retries - 1) throw error } } From aa18d3d4935a663b3d18df19f2f4cbedb0357c4b Mon Sep 17 00:00:00 2001 From: 0xdcota <32775237+0xdcota@users.noreply.github.com> Date: Thu, 20 Feb 2025 07:58:55 -0800 Subject: [PATCH 7/7] chore(defiapp): update fetch method to httpGet per feedback request --- aggregators/defiapp/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aggregators/defiapp/index.ts b/aggregators/defiapp/index.ts index 78ce6d468f..bad71b3a56 100644 --- a/aggregators/defiapp/index.ts +++ b/aggregators/defiapp/index.ts @@ -1,6 +1,6 @@ import { SimpleAdapter, FetchResultVolume } from "../../adapters/types"; import { CHAIN } from "../../helpers/chains"; -import fetchURL from "../../utils/fetchURL"; +import { httpGet } from "../../utils/fetchURL"; const DEFIAPP_24H_VOLUME_URL = "http://api.defi.app/api/stats/volume/24h"; // requires authentication const START_TIMESTAMP = 1739433600; // 02.13.2025 @@ -27,7 +27,7 @@ interface IDefiAppResponse { const fetch = (chain: string) => { return async (timestamp: number): Promise => { const dayResponse = ( - await fetchURL(DEFIAPP_24H_VOLUME_URL, { + await httpGet(DEFIAPP_24H_VOLUME_URL, { headers: { "Content-Type": "application/json", // DefiLlama team to configure