Repository: DefiLlama/dimension-adapters
Pull request #3196: fix joe v1 api
Author: login: dtmkeng
Created: 2025-05-17T08:04:26Z | Merged: 2025-05-17T08:06:47Z



Diff:
diff --git a/dexs/traderjoe/index.ts b/dexs/traderjoe/index.ts
index 68acad9068..2154667e24 100644
--- a/dexs/traderjoe/index.ts
+++ b/dexs/traderjoe/index.ts
@@ -1,13 +1,15 @@
 import * as sdk from "@defillama/sdk";
 import { Chain } from "@defillama/sdk/build/general";
-import { BreakdownAdapter,  } from "../../adapters/types";
+import { BreakdownAdapter, FetchOptions,  } from "../../adapters/types";
 import { CHAIN } from "../../helpers/chains";
 import { getChainVolume, } from "../../helpers/getUniSubgraphVolume";
+import { getTimestampAtStartOfDayUTC } from "../../utils/date";
+import { httpGet } from "../../utils/fetchURL";
 
-const endpoints = {
-  [CHAIN.AVAX]: sdk.graph.modifyEndpoint('9ZjERoA7jGANYNz1YNuFMBt11fK44krveEhzssJTWokM'),
-  [CHAIN.BSC]: sdk.graph.modifyEndpoint('3VgCBQh13PseR81hPNAbKua3gD8b8r33LauKjVnMbSAs'),
-  [CHAIN.ARBITRUM]: sdk.graph.modifyEndpoint('3jFnXqk6UXZyciPu5jfUuPR7kzGXPSndsLNrWXQ6xAxk'),
+const endpoints: { [s: string | Chain]: string } = {
+  [CHAIN.AVAX]: "https://barn.lfj.gg/v1/joev1/dex/analytics/avalanche?startTime=1731974400&aggregateBy=daily",
+  [CHAIN.BSC]: "https://barn.lfj.gg/v1/joev1/dex/analytics/binance?startTime=1731974400&aggregateBy=daily",
+  [CHAIN.ARBITRUM]: "https://barn.lfj.gg/v1/joev1/dex/analytics/arbitrum?startTime=1731974400&aggregateBy=daily",
 };
 type TEndpoint = {
   [s: string | Chain]: string;
@@ -19,13 +21,36 @@ const endpointsV2: TEndpoint = {
   [CHAIN.ETHEREUM]: "https://barn.traderjoexyz.com/v1/dex/analytics/ethereum?startTime=1695513600&aggregateBy=daily"
 }
 
-const graphsV1 = getChainVolume({
-  graphUrls: endpoints,
-  totalVolume: {
-    factory: "factories",
-    field: "volumeUSD",
-  },
-});
+const TOTAL_FEES = 0.003;
+const LP_FEE = 0.0025;
+const PROTOCOL_FEES = 0.0005;
+const HOLDER_REV = 0.0005;
+interface IResponse {
+  date: string;
+  volumeUsd: number 
+}
+
+const fetchV1 = async (_t: any, _b: any, options: FetchOptions) => {
+    const { createBalances, chain, startOfDay } = options
+    const date = getTimestampAtStartOfDayUTC(startOfDay)
+    const dateStr = new Date(date * 1000).toISOString().split('T')[0]
+    const response: IResponse[] = await httpGet(endpoints[chain])
+    const dailyVolume = createBalances()
+    const volume = response.find((item) => item.date.split('T')[0] === dateStr)?.volumeUsd || 0
+    dailyVolume.addUSDValue(volume)
+    const dailyFees = dailyVolume.clone(TOTAL_FEES)
+    const dailyRevenue = dailyVolume.clone(PROTOCOL_FEES)
+    const dailyHoldersRevenue = dailyVolume.clone(HOLDER_REV)
+    const dailySupplySideRevenue = dailyVolume.clone(LP_FEE)
+    return {
+      dailyVolume,
+      timestamp: date,
+      dailyFees,
+      dailyRevenue,
+      dailyHoldersRevenue,
+      dailySupplySideRevenue,
+    }
+}
 
 
 const graphsV2 = getChainVolume({
@@ -41,15 +66,15 @@ const adapter: BreakdownAdapter = {
   breakdown: {
     v1: {
       [CHAIN.AVAX]: {
-        fetch: graphsV1(CHAIN.AVAX),
+        fetch:  fetchV1,
         start: '2021-08-09',
       },
       [CHAIN.BSC]: {
-        fetch: graphsV1(CHAIN.BSC),
+        fetch: fetchV1,
         start: '2022-10-04',
       },
       [CHAIN.ARBITRUM]: {
-        fetch: graphsV1(CHAIN.ARBITRUM),
+        fetch: fetchV1,
         start: '2022-10-04',
       },
     },
diff --git a/fees/traderjoe-v1.ts b/fees/traderjoe-v1.ts
index 3cbc86df89..13fad6ce12 100644
--- a/fees/traderjoe-v1.ts
+++ b/fees/traderjoe-v1.ts
@@ -1,5 +1,5 @@
 
-import adapter from './traderjoe'
+import adapter from '../dexs/traderjoe'
 const { breakdown,  ...rest } = adapter as any
 
 export default {
diff --git a/fees/traderjoe.ts b/fees/traderjoe.ts
index aec3beba1d..e86acbbd0d 100644
--- a/fees/traderjoe.ts
+++ b/fees/traderjoe.ts
@@ -2,13 +2,6 @@ import { Adapter, FetchOptions } from "../adapters/types";
 import { Chain } from "@defillama/sdk/build/general";
 import { CHAIN } from "../helpers/chains";
 import { httpGet } from "../utils/fetchURL";
-import * as sdk from "@defillama/sdk";
-import { getChainVolume } from "../helpers/getUniSubgraphVolume";
-
-const TOTAL_FEES = 0.003;
-const LP_FEE = 0.0025;
-const PROTOCOL_FEES = 0.0005;
-const HOLDER_REV = 0.0005;
 
 interface IData {
   feesUsd: number;
@@ -16,33 +9,6 @@ interface IData {
   timestamp: number;
 }
 
-type TEndpoint = {
-  [s: string | Chain]: string;
-};
-const endpointsV2: TEndpoint = {
-  [CHAIN.AVAX]:
-    "https://barn.traderjoexyz.com/v1/dex/analytics/avalanche?startTime=1669420800&aggregateBy=daily",
-  [CHAIN.ARBITRUM]:
-    "https://barn.traderjoexyz.com/v1/dex/analytics/arbitrum?startTime=1672012800&aggregateBy=daily",
-  [CHAIN.BSC]:
-    "https://barn.traderjoexyz.com/v1/dex/analytics/binance?startTime=1677801600&aggregateBy=daily",
-  [CHAIN.ETHEREUM]:
-    "https://barn.traderjoexyz.com/v1/dex/analytics/ethereum?startTime=1695513600&aggregateBy=daily",
-};
-
-const endpoints = {
-  [CHAIN.AVAX]: sdk.graph.modifyEndpoint('9ZjERoA7jGANYNz1YNuFMBt11fK44krveEhzssJTWokM'),
-  [CHAIN.BSC]: sdk.graph.modifyEndpoint('3VgCBQh13PseR81hPNAbKua3gD8b8r33LauKjVnMbSAs'),
-  [CHAIN.ARBITRUM]: sdk.graph.modifyEndpoint('3jFnXqk6UXZyciPu5jfUuPR7kzGXPSndsLNrWXQ6xAxk'),
-};
-
-const graphsV1 = getChainVolume({
-  graphUrls: endpoints,
-  totalVolume: {
-    factory: "factories",
-    field: "volumeUSD",
-  },
-});
 const graph = async (_t: any, _tt: any, options: FetchOptions) => {
     const dayTimestamp = options.startOfDay;
     const start = options.startOfDay;
@@ -79,50 +45,6 @@ const mapChain = (chain: Chain): string => {
 const adapter: Adapter = {
   version: 1,
   breakdown: {
-    v1: {
-      [CHAIN.ARBITRUM]: {
-        fetch: async (_t: any, _tt: any, options: FetchOptions) => {
-          const data = await graphsV1(CHAIN.ARBITRUM)(_t, _tt, options);
-          return {
-            dailyFees: data.dailyVolume ? `${Number(data.dailyVolume) * TOTAL_FEES}` : "0",
-            dailyUserFees: data.dailyVolume ? `${Number(data.dailyVolume) * TOTAL_FEES}` : "0",
-            dailyRevenue: data.dailyVolume ? `${Number(data.dailyVolume) * PROTOCOL_FEES}` : "0",
-            dailyHoldersRevenue: data.dailyVolume ? `${Number(data.dailyVolume) * HOLDER_REV}` : "0",
-            dailySupplySideRevenue: data.dailyVolume ? `${Number(data.dailyVolume) * LP_FEE}` : "0",
-            timestamp: options.startOfDay,
-          };
-        },
-        start: '2022-12-26',
-      },
-      [CHAIN.BSC]: {
-        fetch: async (_t: any, _tt: any, options: FetchOptions) => {
-          const data = await graphsV1(CHAIN.BSC)(_t, _tt, options);
-          return {
-            dailyFees: data.dailyVolume ? `${Number(data.dailyVolume) * TOTAL_FEES}` : "0",
-            dailyUserFees: data.dailyVolume ? `${Number(data.dailyVolume) * TOTAL_FEES}` : "0",
-            dailyRevenue: data.dailyVolume ? `${Number(data.dailyVolume) * PROTOCOL_FEES}` : "0",
-            dailyHoldersRevenue: data.dailyVolume ? `${Number(data.dailyVolume) * HOLDER_REV}` : "0",
-            dailySupplySideRevenue: data.dailyVolume ? `${Number(data.dailyVolume) * LP_FEE}` : "0",
-            timestamp: options.startOfDay,
-          };
-        },
-        start: '2022-10-04',
-      },
-      [CHAIN.AVAX]: {
-        fetch: async (_t: any, _tt: any, options: FetchOptions) => {
-          const data = await graphsV1(CHAIN.AVAX)(_t, _tt, options);
-          return {
-            dailyFees: data.dailyVolume ? `${Number(data.dailyVolume) * TOTAL_FEES}` : "0",
-            dailyUserFees: data.dailyVolume ? `${Number(data.dailyVolume) * TOTAL_FEES}` : "0",
-            dailyRevenue: data.dailyVolume ? `${Number(data.dailyVolume) * PROTOCOL_FEES}` : "0",
-            dailyHoldersRevenue: data.dailyVolume ? `${Number(data.dailyVolume) * HOLDER_REV}` : "0",
-            dailySupplySideRevenue: data.dailyVolume ? `${Number(data.dailyVolume) * LP_FEE}` : "0",
-            timestamp: options.startOfDay,
-          };
-        },
-        start: '2022-11-26',
-      },
-    },
     v2: {
       [CHAIN.AVAX]: {
         fetch: graph,


Reviews:
user: login: g1nt0ki
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-05-22T14:51:59Z
user: login: g1nt0ki
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-05-22T14:52:12Z
user: login: g1nt0ki
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-05-22T14:55:09Z

Review comments:
diff_hunk: @@ -19,13 +21,36 @@ const endpointsV2: TEndpoint = {
   [CHAIN.ETHEREUM]: "https://barn.traderjoexyz.com/v1/dex/analytics/ethereum?startTime=1695513600&aggregateBy=daily"
 }
 
-const graphsV1 = getChainVolume({
-  graphUrls: endpoints,
-  totalVolume: {
-    factory: "factories",
-    field: "volumeUSD",
-  },
-});
+const TOTAL_FEES = 0.003;
+const LP_FEE = 0.0025;
+const PROTOCOL_FEES = 0.0005;
+const HOLDER_REV = 0.0005;
+interface IResponse {
+  date: string;
+  volumeUsd: number 
+}
+
+const fetchV1 = async (_t: any, _b: any, options: FetchOptions) => {
+    const { createBalances, chain, startOfDay } = options
+    const date = getTimestampAtStartOfDayUTC(startOfDay)
+    const dateStr = new Date(date * 1000).toISOString().split('T')[0]
path: dexs/traderjoe/index.ts
user: login: g1nt0ki
body: you can get get dateStr by `options.dateString`
created_at: 2025-05-22T14:51:59Z
author_association: MEMBER
diff_hunk: @@ -19,13 +21,36 @@ const endpointsV2: TEndpoint = {
   [CHAIN.ETHEREUM]: "https://barn.traderjoexyz.com/v1/dex/analytics/ethereum?startTime=1695513600&aggregateBy=daily"
 }
 
-const graphsV1 = getChainVolume({
-  graphUrls: endpoints,
-  totalVolume: {
-    factory: "factories",
-    field: "volumeUSD",
-  },
-});
+const TOTAL_FEES = 0.003;
+const LP_FEE = 0.0025;
+const PROTOCOL_FEES = 0.0005;
+const HOLDER_REV = 0.0005;
+interface IResponse {
+  date: string;
+  volumeUsd: number 
+}
+
+const fetchV1 = async (_t: any, _b: any, options: FetchOptions) => {
+    const { createBalances, chain, startOfDay } = options
+    const date = getTimestampAtStartOfDayUTC(startOfDay)
+    const dateStr = new Date(date * 1000).toISOString().split('T')[0]
+    const response: IResponse[] = await httpGet(endpoints[chain])
+    const dailyVolume = createBalances()
+    const volume = response.find((item) => item.date.split('T')[0] === dateStr)?.volumeUsd || 0
+    dailyVolume.addUSDValue(volume)
+    const dailyFees = dailyVolume.clone(TOTAL_FEES)
+    const dailyRevenue = dailyVolume.clone(PROTOCOL_FEES)
+    const dailyHoldersRevenue = dailyVolume.clone(HOLDER_REV)
+    const dailySupplySideRevenue = dailyVolume.clone(LP_FEE)
+    return {
+      dailyVolume,
+      timestamp: date,
path: dexs/traderjoe/index.ts
user: login: g1nt0ki
body: avoid this field
created_at: 2025-05-22T14:52:12Z
author_association: MEMBER
diff_hunk: @@ -19,13 +21,36 @@ const endpointsV2: TEndpoint = {
   [CHAIN.ETHEREUM]: "https://barn.traderjoexyz.com/v1/dex/analytics/ethereum?startTime=1695513600&aggregateBy=daily"
 }
 
-const graphsV1 = getChainVolume({
-  graphUrls: endpoints,
-  totalVolume: {
-    factory: "factories",
-    field: "volumeUSD",
-  },
-});
+const TOTAL_FEES = 0.003;
+const LP_FEE = 0.0025;
+const PROTOCOL_FEES = 0.0005;
+const HOLDER_REV = 0.0005;
+interface IResponse {
+  date: string;
+  volumeUsd: number 
+}
+
+const fetchV1 = async (_t: any, _b: any, options: FetchOptions) => {
+    const { createBalances, chain, startOfDay } = options
+    const date = getTimestampAtStartOfDayUTC(startOfDay)
+    const dateStr = new Date(date * 1000).toISOString().split('T')[0]
+    const response: IResponse[] = await httpGet(endpoints[chain])
+    const dailyVolume = createBalances()
+    const volume = response.find((item) => item.date.split('T')[0] === dateStr)?.volumeUsd || 0
path: dexs/traderjoe/index.ts
user: login: g1nt0ki
body: if data is missing, you should throw an error
created_at: 2025-05-22T14:55:09Z
author_association: MEMBER

PR comments:
user: login: llamabutler
created_at: 2025-05-17T08:04:56Z
body: The traderjoe adapter exports:
        
 
 
    > adapters@1.0.0 test
    > ts-node --transpile-only cli/testAdapter.ts dexs traderjoe
    
    🦙 Running TRADERJOE adapter 🦙
    ---------------------------------------------------
    GRAPH_API_KEY env variable is not set, using the default api key
    Start Date:	Fri, 16 May 2025 00:00:00 GMT
    End Date:	Sat, 17 May 2025 00:00:00 GMT
    ---------------------------------------------------
    
    Error: Breakdown adapters are deprecated, migrate it to use simple adapter
        at runAdapter (/home/runner/work/dimension-adapters/dimension-adapters/adapters/utils/runAdapter.ts:23:32)
        at /home/runner/work/dimension-adapters/dimension-adapters/cli/testAdapter.ts:93:17
        at Array.map (<anonymous>)
        at /home/runner/work/dimension-adapters/dimension-adapters/cli/testAdapter.ts:92:75
        at processTicksAndRejections (node:internal/process/task_queues:95:5)
    
author_association: NONE
user: login: llamabutler
created_at: 2025-05-17T08:05:04Z
body: The traderjoe-v1.ts adapter exports:
        
 
 
    > adapters@1.0.0 test
    > ts-node --transpile-only cli/testAdapter.ts fees traderjoe-v1.ts
    
    🦙 Running TRADERJOE-V1.TS adapter 🦙
    ---------------------------------------------------
    GRAPH_API_KEY env variable is not set, using the default api key
    Start Date:	Fri, 16 May 2025 00:00:00 GMT
    End Date:	Sat, 17 May 2025 00:00:00 GMT
    ---------------------------------------------------
    
    AVAX 👇
    Backfill start time: 9/8/2021
    Daily volume: 3.26 M
    End timestamp: 1747353600 (2025-05-16T00:00:00.000Z)
    Daily fees: 9.77 k
    Daily revenue: 1.63 k
    Daily holders revenue: 1.63 k
    Daily supply side revenue: 8.14 k
    
    
    BSC 👇
    Backfill start time: 4/10/2022
    Daily volume: 0
    End timestamp: 1747353600 (2025-05-16T00:00:00.000Z)
    Daily fees: 0
    Daily revenue: 0
    Daily holders revenue: 0
    Daily supply side revenue: 0
    
    
    ARBITRUM 👇
    Backfill start time: 4/10/2022
    Daily volume: 2.52 k
    End timestamp: 1747353600 (2025-05-16T00:00:00.000Z)
    Daily fees: 8
    Daily revenue: 1
    Daily holders revenue: 1
    Daily supply side revenue: 6
    
    
    ---- AGGREGATE 👇
    Backfill start time not defined
    End timestamp: 1747353600 (2025-05-16T00:00:00.000Z)
    Daily volume: 3.26 M
    Daily fees: 9.78 k
    Daily revenue: 1.63 k
    Daily holders revenue: 1.63 k
    Daily supply side revenue: 8.15 k
    
    
    
    
    
author_association: NONE
user: login: llamabutler
created_at: 2025-05-17T08:05:06Z
body: The traderjoe.ts adapter exports:
        
 
 
    > adapters@1.0.0 test
    > ts-node --transpile-only cli/testAdapter.ts fees traderjoe.ts
    
    🦙 Running TRADERJOE.TS adapter 🦙
    ---------------------------------------------------
    Start Date:	Fri, 16 May 2025 00:00:00 GMT
    End Date:	Sat, 17 May 2025 00:00:00 GMT
    ---------------------------------------------------
    
    Error: Breakdown adapters are deprecated, migrate it to use simple adapter
        at runAdapter (/home/runner/work/dimension-adapters/dimension-adapters/adapters/utils/runAdapter.ts:23:32)
        at /home/runner/work/dimension-adapters/dimension-adapters/cli/testAdapter.ts:93:17
        at Array.map (<anonymous>)
        at /home/runner/work/dimension-adapters/dimension-adapters/cli/testAdapter.ts:92:75
        at processTicksAndRejections (node:internal/process/task_queues:95:5)
    
author_association: NONE