Skip to content

Commit

Permalink
add v1 data
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrievous3 committed Apr 29, 2024
1 parent c51f333 commit 97935c8
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
34 changes: 34 additions & 0 deletions dexs/fjord-foundry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fetchURL from "../../utils/fetchURL";
import { CHAIN } from "../../helpers/chains";

const feeEndpoint = "https://fjord-api.vercel.app/api/daily-stats?version=2";
const feeEndpointV1 = "https://fjord-api.vercel.app/api/daily-stats?version=1";

const v2ChainIDs = {
[CHAIN.ETHEREUM]: 1,
Expand All @@ -15,6 +16,11 @@ const v2ChainIDs = {
[CHAIN.BSC]: 56,
};

const v1ChainIDs = {
[CHAIN.ETHEREUM]: 1,
[CHAIN.POLYGON]: 137,
[CHAIN.ARBITRUM]: 42161,
};

const getV2Data = async (endTimestamp: number, chainId: number) => {
const dayTimestamp = getTimestampAtStartOfDayUTC(endTimestamp)
Expand All @@ -35,6 +41,25 @@ const getV2Data = async (endTimestamp: number, chainId: number) => {
};
};

const getV1Data = async (endTimestamp: number, chainId: number) => {
const dayTimestamp = getTimestampAtStartOfDayUTC(endTimestamp)
const historicalVolume = (await fetchURL(feeEndpointV1))

const chainData = historicalVolume.stats.find(cd => cd.chainId === chainId);

const totalVolume = chainData.stats
.filter(item => item.timestamp <= dayTimestamp)
.reduce((acc, { volume }) => acc + volume, 0)

const dailyVolume = chainData.stats
.find(dayItem => dayItem.timestamp === dayTimestamp)?.volume

return {
totalVolume: `${totalVolume}`,
dailyVolume: dailyVolume ? `${dailyVolume}` : '0',
};
};

const adapter: BreakdownAdapter = {
breakdown: {
v2: Object.keys(v2ChainIDs).reduce((acc, chain) => {
Expand All @@ -46,6 +71,15 @@ const adapter: BreakdownAdapter = {
},
}
}, {}),
v1: Object.keys(v1ChainIDs).reduce((acc, chain) => {
return {
...acc,
[chain]: {
fetch: async (_ts: number, _chain: any, { startOfDay }: FetchOptions) => await getV1Data(startOfDay, v1ChainIDs[chain]),
start: 1631836800,
},
}
}, {}),
}
}

Expand Down
40 changes: 40 additions & 0 deletions fees/fjord-foundry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fetchURL from "../../utils/fetchURL";
import { CHAIN } from "../../helpers/chains";

const feeEndpoint = "https://fjord-api.vercel.app/api/daily-stats?version=2";
const feeEndpointV1 = "https://fjord-api.vercel.app/api/daily-stats?version=1";

const v2ChainIDs = {
[CHAIN.ETHEREUM]: 1,
Expand All @@ -15,6 +16,12 @@ const v2ChainIDs = {
[CHAIN.BSC]: 56,
};

const v1ChainIDs = {
[CHAIN.ETHEREUM]: 1,
[CHAIN.POLYGON]: 137,
[CHAIN.ARBITRUM]: 42161,
};

const getV2Data = async (endTimestamp: number, chainId: number) => {
const dayTimestamp = getTimestampAtStartOfDayUTC(endTimestamp)
const historicalFees = (await fetchURL(feeEndpoint))
Expand All @@ -36,6 +43,27 @@ const getV2Data = async (endTimestamp: number, chainId: number) => {
};
};

const getV1Data = async (endTimestamp: number, chainId: number) => {
const dayTimestamp = getTimestampAtStartOfDayUTC(endTimestamp)
const historicalFees = (await fetchURL(feeEndpointV1))

const chainData = historicalFees.stats.find(cd => cd.chainId === chainId);

const totalFee = chainData.stats
.filter(item => item.timestamp <= dayTimestamp)
.reduce((acc, { fees }) => acc + fees, 0)

const dailyFee = chainData.stats
.find(dayItem => dayItem.timestamp === dayTimestamp)?.fees

return {
totalFees: `${totalFee}`,
dailyFees: dailyFee ? `${dailyFee}` : '0',
totalRevenue: `${totalFee}`,
dailyRevenue: dailyFee ? `${dailyFee}` : '0',
};
};

const methodology = {
Fees: "Fees collected from user trading fees",
Revenue: "Revenue is 100% fee of each swap which goes to treasury",
Expand All @@ -55,6 +83,18 @@ const adapter: BreakdownAdapter = {
},
}
}, {}),
v1: Object.keys(v1ChainIDs).reduce((acc, chain) => {
return {
...acc,
[chain]: {
fetch: async (_ts: number, _chain: any, { startOfDay }: FetchOptions) => await getV1Data(startOfDay, v1ChainIDs[chain]),
start: 1631836800,
meta: {
methodology,
},
},
}
}, {}),
}
}

Expand Down

0 comments on commit 97935c8

Please sign in to comment.