Skip to content

Commit

Permalink
Merge pull request #2344 from FilamentFinance/master
Browse files Browse the repository at this point in the history
Volume and fees scripts updated for Filament Finance
  • Loading branch information
dtmkeng authored Jan 22, 2025
2 parents 702542a + 7d5ac5b commit cc20ded
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
35 changes: 33 additions & 2 deletions dexs/filament/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,51 @@ import type { SimpleAdapter } from "../../adapters/types";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import { httpGet } from "../../utils/fetchURL";

const api = "https://orderbook.filament.finance/sei/api/v1/orderbook/tradeVolumeStats/BTC";
const assets = ["BTC", "ETH", "SOL", "TRUMP"];

const fetch = async () => {
const fetchForAsset = async (asset: string) => {
const api = `https://orderbookv5.filament.finance/k8s/api/v1/orderbook/tradeVolumeStats/${asset}`;
const timestamp = getUniqStartOfTodayTimestamp();
const res = await httpGet(api);

if (!res || typeof res !== "object" || !("allTimeVolume" in res) || !("volumeIn24Hours" in res)) {
throw new Error(`Invalid response for asset ${asset}: ${JSON.stringify(res)}`);
}

const { allTimeVolume, volumeIn24Hours } = res;

if (typeof allTimeVolume !== "number" || typeof volumeIn24Hours !== "number") {
throw new Error(`Invalid volume data for ${asset}: ${JSON.stringify(res)}`);
}

return {
timestamp,
dailyVolume: volumeIn24Hours,
totalVolume: allTimeVolume,
};
};

const fetch = async () => {
const results = await Promise.all(
assets.map(async (asset) => {
try {
return { asset, ...(await fetchForAsset(asset)) };
} catch (error) {
console.error(`Error fetching ${asset}:`, error);
return null;
}
})
);

return results.reduce((acc, item) => {
if (item) {
const { asset, ...data } = item;
acc[asset] = data;
}
return acc;
}, {} as Record<string, { timestamp: number; dailyVolume: number; totalVolume: number }>);
};

const adapter: SimpleAdapter = {
adapter: {
sei: {
Expand Down
4 changes: 2 additions & 2 deletions fees/filament/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FetchOptions, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";

const endpoint =
"https://api.goldsky.com/api/public/project_cm0qvthsz96sp01utcnk55ib0/subgraphs/filament-sei/v1/gn";
"https://api.goldsky.com/api/public/project_cm0qvthsz96sp01utcnk55ib0/subgraphs/filament-sei/v2/gn";

// Get timestamps for yesterday and today
const now = Math.floor(Date.now() / 1000); // Current timestamp in seconds
Expand Down Expand Up @@ -96,7 +96,7 @@ const adapter: SimpleAdapter = {
adapter: {
[CHAIN.SEI]: {
fetch: fetchProtocolFees,
start: '2024-09-07',
start: '2025-01-21',
meta: {
methodology,
},
Expand Down

0 comments on commit cc20ded

Please sign in to comment.