Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add op_bnb chain #1971

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions dexs/myx-finance/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ChainEndpoints, Fetch, FetchOptions, SimpleAdapter } from "../../adapters/types";
import { ChainEndpoints, FetchOptions, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import fetchURL from "../../utils/fetchURL";

const endpoints: ChainEndpoints = {
Expand All @@ -16,22 +15,9 @@ const methodology = {
const getFetch = async (optios: FetchOptions) => {
const result = await fetchURL(endpoints[optios.chain])

const dayTimestamp = getUniqStartOfTodayTimestamp(new Date((optios.endTimestamp * 1000)))
const dailyVolume = result.data.reduce((acc, item) => acc + (item?.target_volume || 0), 0)


const volume = result.data.reduce((acc, item) => {
return acc + (item?.target_volume || 0)
}, 0)

console.log({
timestamp: dayTimestamp,
dailyVolume: volume || "0",
})

return {
timestamp: dayTimestamp,
dailyVolume: volume || "0",
}
return { dailyVolume }
}


Expand All @@ -46,6 +32,7 @@ const adapter: SimpleAdapter = {
return {
...acc,
[chain]: {
runAtCurrTime: true,
fetch: getFetch,
start: startTimestamps[chain],
meta: {
Expand Down
26 changes: 16 additions & 10 deletions fees/myx-finance/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SimpleAdapter, FetchResultFees, FetchOptions } from "../../adapters/types";
import { SimpleAdapter, FetchOptions } from "../../adapters/types";
import fetchURL from "../../utils/fetchURL";
import { CHAIN } from "../../helpers/chains";

Expand Down Expand Up @@ -30,29 +30,28 @@ const fetchApi = async (type: FetchType, startTime: number, endTime: number) =>
return data
}

const fetchFees = async (_t: any, _b: any, optios: FetchOptions) => {
const start = optios.startOfDay;
const end = start + 86400;
const dailyAlls: Data[] = await fetchApi(FetchType.DAILY, start, end)
const dailyFees = dailyAlls.find((daily: Data)=> daily.chainId === optios.toApi.chainId)
const fetchFees = async ({ fromTimestamp, toTimestamp, api }: FetchOptions) => {
const chainId = api.chainId
const dailyAlls: Data[] = await fetchApi(FetchType.DAILY, fromTimestamp, toTimestamp )
const dailyFees = dailyAlls.find((daily: Data)=> daily.chainId === chainId)

const totalAlls: Data[] = await fetchApi(FetchType.TOTAL, start, end)
const totalFees = totalAlls.find((daily: Data)=> daily.chainId === optios.toApi.chainId)
const totalAlls: Data[] = await fetchApi(FetchType.TOTAL, fromTimestamp, toTimestamp )
const totalFees = totalAlls.find((daily: Data)=> daily.chainId === chainId)

return {
totalFees: totalFees?.tradingFee,
dailyFees: dailyFees?.tradingFee,
timestamp: optios.startTimestamp
}
}

const startTimestamps: { [chain: string]: number } = {
[CHAIN.ARBITRUM]: 1706659200,
[CHAIN.LINEA]: 1708473600,
[CHAIN.OP_BNB]: 1727443900
}

const adapter: SimpleAdapter = {
version: 1,
version: 2,
adapter: {
[CHAIN.ARBITRUM]: {
fetch: fetchFees,
Expand All @@ -68,6 +67,13 @@ const adapter: SimpleAdapter = {
methodology
}
},
[CHAIN.OP_BNB]: {
fetch: fetchFees,
start: startTimestamps[CHAIN.OP_BNB],
meta: {
methodology
}
},
}
}

Expand Down
Loading