Skip to content

Commit

Permalink
Merge pull request #2032 from ryanfanjc/master
Browse files Browse the repository at this point in the history
feat: update MYX-FINANCE Volume request
  • Loading branch information
dtmkeng authored Oct 22, 2024
2 parents a7b091c + b5fe961 commit e157f25
Showing 1 changed file with 42 additions and 24 deletions.
66 changes: 42 additions & 24 deletions dexs/myx-finance/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
import { ChainEndpoints, Fetch, FetchOptions, SimpleAdapter } from "../../adapters/types";
import { FetchOptions, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import fetchURL from "../../utils/fetchURL";

const endpoints: ChainEndpoints = {
[CHAIN.ARBITRUM]: "https://api.myx.finance/v2/quote/market/contracts/arbitrum",
[CHAIN.LINEA]: "https://api.myx.finance/v2/quote/market/contracts/linea",
[CHAIN.OP_BNB]: "https://api.myx.finance/v2/quote/market/contracts/opbnb",
const FETCH_URL = 'https://api.myx.finance/v2/scan/defilama/trade-volume/stat_by_chain'

type VolumeType = {
chainId: number,
volume: string
}

const methodology = {
TotalVolume: "Total Volume from the sum of the open/close/liquidation of positions.",
DailyVolume: "Daily Volume from the sum of the open/close/liquidation of positions.",
}

const getFetch = async (_t: any, _tts: any, options: FetchOptions) => {
const result = await fetchURL(endpoints[options.chain])
const fetchApi = async (startTime: number, endTime: number) => {
const rs = await fetchURL(`${FETCH_URL}?startTime=${startTime}&endTime=${endTime}`)
const data: VolumeType[] = rs?.data ?? []

return data
}

const getFetch = async ({ fromTimestamp, toTimestamp, api }: FetchOptions) => {
const result = await fetchApi(fromTimestamp, toTimestamp)

const dayTimestamp = getUniqStartOfTodayTimestamp(new Date((options.endTimestamp * 1000)))
const volume = result.data.reduce((acc, item) => {
return acc + (item?.target_volume || 0)
}, 0)
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date((fromTimestamp * 1000)))

const volumeData: VolumeType = result.find((dataItem) => dataItem.chainId === api.chainId) ?? {} as VolumeType

return {
timestamp: dayTimestamp,
dailyVolume: volume || "0",
dailyVolume: volumeData?.volume ?? '0',
}
}

Expand All @@ -36,19 +43,30 @@ const startTimestamps: { [chain: string]: number } = {
}

const adapter: SimpleAdapter = {
version: 1,
adapter: Object.keys(endpoints).reduce((acc, chain) => {
return {
...acc,
[chain]: {
fetch: getFetch,
start: startTimestamps[chain],
meta: {
methodology: methodology,
},
version: 2,
adapter: {
[CHAIN.ARBITRUM]: {
fetch: getFetch,
start: startTimestamps[CHAIN.ARBITRUM],
meta: {
methodology
}
},
[CHAIN.LINEA]: {
fetch: getFetch,
start: startTimestamps[CHAIN.LINEA],
meta: {
methodology
}
}
}, {})
},
[CHAIN.OP_BNB]: {
fetch: getFetch,
start: startTimestamps[CHAIN.OP_BNB],
meta: {
methodology
}
},
}
}

export default adapter;

0 comments on commit e157f25

Please sign in to comment.