Skip to content

Commit

Permalink
use parametized dune query for gTrade stats
Browse files Browse the repository at this point in the history
  • Loading branch information
0xCrumb committed Oct 23, 2024
1 parent 4acfb7c commit 92e7fe8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
18 changes: 9 additions & 9 deletions dexs/gains-network/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { FetchResultVolume, SimpleAdapter } from "../../adapters/types";
import { ChainBlocks, FetchOptions, FetchResultVolume, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { queryDune } from "../../helpers/dune";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";

interface IStats {
unix_ts: number;
day: string;
blockchain: string;
daily_volume: number;
}

const fetch: any = async (timestamp: number, _, { chain }): Promise<FetchResultVolume> => {
const stats: IStats[] = await queryDune("4192058"); // dune.gains.result_g_trade_stats_defillama

const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
const dateString = new Date(dayTimestamp * 1000).toISOString().split("T")[0];

const chainStat = stats.find((stat) => stat.day.split(" ")[0] === dateString && stat.blockchain === chain);
const fetch: any = async (
timestamp: number,
_: ChainBlocks,
{ chain, startOfDay, toTimestamp }: FetchOptions
): Promise<FetchResultVolume> => {
const stats: IStats[] = await queryDune("4192496", { start: startOfDay, end: toTimestamp });
const chainStat = stats.find((stat) => stat.unix_ts === startOfDay && stat.blockchain === chain);

return { timestamp, dailyVolume: chainStat?.daily_volume || 0 };
};
Expand Down
12 changes: 4 additions & 8 deletions fees/gains-network.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Adapter, ChainBlocks, FetchOptions, FetchResultFees } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import { queryDune } from "../helpers/dune";
import { getUniqStartOfTodayTimestamp } from "../helpers/getUniSubgraphVolume";

interface IStats {
unix_ts: number;
day: string;
blockchain: string;
daily_volume: number;
Expand All @@ -26,13 +26,9 @@ interface IStats {
gns_stakers: number;
}

const fetch = async (timestamp: number, _: ChainBlocks, { chain }: FetchOptions): Promise<FetchResultFees> => {
const stats: IStats[] = await queryDune("4192058"); // dune.gains.result_g_trade_stats_defillama

const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
const dateString = new Date(dayTimestamp * 1000).toISOString().split("T")[0];

const chainStat = stats.find((stat) => stat.day.split(" ")[0] === dateString && stat.blockchain === chain);
const fetch = async (timestamp: number, _: ChainBlocks, { chain, startOfDay, toTimestamp }: FetchOptions): Promise<FetchResultFees> => {
const stats: IStats[] = await queryDune("4192496", { start: startOfDay, end: toTimestamp });
const chainStat = stats.find((stat) => stat.unix_ts === startOfDay && stat.blockchain === chain);
const [dailyFees, dailyRevenue, dailyHoldersRevenue, dailySupplySideRevenue, totalFees] = chainStat
? [
chainStat.all_fees,
Expand Down

0 comments on commit 92e7fe8

Please sign in to comment.