Skip to content

Commit

Permalink
Merge pull request DefiLlama#2393 from EnsoBuild/master
Browse files Browse the repository at this point in the history
Update Enso adapter to v2
  • Loading branch information
dtmkeng authored Feb 10, 2025
2 parents caf060f + bc42e68 commit 0174a55
Showing 1 changed file with 42 additions and 58 deletions.
100 changes: 42 additions & 58 deletions aggregators/enso/index.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,47 @@
import { CHAIN } from "../../helpers/chains";
import { httpGet } from "../../utils/fetchURL";
import { Adapter, Fetch, FetchResultVolume } from "../../adapters/types";
import { getEnv } from "../../helpers/env";

function fetch(chainId: number): Fetch {
return async (endTimestamp: number, _, options): Promise<FetchResultVolume> => {
const totalVolume = options.createBalances();
const dailyVolume = options.createBalances();
const res = await httpGet(
`https://api.enso.finance/api/v1/volume/${chainId}?timestamp=${endTimestamp}`,
{
headers: {
Authorization: `Bearer ${getEnv("ENSO_API_KEY")}`,
},
},
);

totalVolume.addUSDValue(res.totalVolume);
dailyVolume.addUSDValue(res.dailyVolume);

return {
totalVolume,
dailyVolume,
timestamp: endTimestamp,
};
import { FetchV2 } from "../../adapters/types";
import { queryDune } from "../../helpers/dune";

const chains: Record<string, { duneChain: string; start: string }> = {
[CHAIN.ETHEREUM]: { duneChain: "ethereum", start: "2023-06-22" },
[CHAIN.OPTIMISM]: { duneChain: "optimism", start: "2023-09-19" },
[CHAIN.BSC]: { duneChain: "binance", start: "2023-09-20" },
[CHAIN.POLYGON]: { duneChain: "polygon", start: "2023-09-05" },
[CHAIN.BASE]: { duneChain: "base", start: "2023-12-24" },
[CHAIN.ARBITRUM]: { duneChain: "arbitrum", start: "2023-09-11" },
};

const queryId = "4687193";

const fetchVolume = (chain: string): FetchV2 => async ({ startTimestamp, endTimestamp }) => {
const chainConfig = chains[chain];
if (!chainConfig) throw new Error(`Chain configuration not found for: ${chain}`);

const data = await queryDune(queryId, {
timestamp_from: startTimestamp,
timestamp_to: endTimestamp,
chain: chainConfig.duneChain,
});

const chainData = data[0];
if (!chainData) throw new Error(`Dune query failed: ${JSON.stringify(data)}`);

return {
dailyVolume: chainData.volume_timerange,
totalVolume: chainData.total_volume,
timestamp: endTimestamp,
};
}

const adapter: Adapter = {
adapter: {
[CHAIN.ETHEREUM]: {
fetch: fetch(1),
start: "2023-06-22",
},
[CHAIN.OPTIMISM]: {
fetch: fetch(10),
start: "2023-09-19",
},
[CHAIN.BSC]: {
fetch: fetch(56),
start: "2023-09-20",
},
[CHAIN.POLYGON]: {
fetch: fetch(137),
start: "2023-09-05",
},
[CHAIN.BASE]: {
fetch: fetch(8453),
start: "2023-12-24",
},
[CHAIN.ARBITRUM]: {
fetch: fetch(42161),
start: "2023-09-11",
},
[CHAIN.LINEA]: {
fetch: fetch(59144),
start: "2023-12-15",
},
},
};

const adapter: any = {
version: 2,
isExpensiveAdapter: true,
adapter: Object.fromEntries(
Object.entries(chains).map(([chain, { start }]) => [
chain,
{ fetch: fetchVolume(chain), start },
])
),
};

export default adapter;

0 comments on commit 0174a55

Please sign in to comment.