diff --git a/dexs/mute.io/index.ts b/dexs/mute.io/index.ts index 2ef992c945..e9832a49c1 100644 --- a/dexs/mute.io/index.ts +++ b/dexs/mute.io/index.ts @@ -2,7 +2,7 @@ import { univ2Adapter } from "../../helpers/getUniSubgraphVolume"; import { CHAIN } from "../../helpers/chains"; const endpoints = { - [CHAIN.ERA]: "https://api.studio.thegraph.com/query/12332/muteswitch---zksync-era/v0.0.5", + [CHAIN.ERA]: "https://api.goldsky.com/api/public/project_clmtie4nnezuh2nw6hhjg6mo7/subgraphs/mute_switch/v0.0.7/gn", }; const adapter = univ2Adapter(endpoints, { @@ -15,4 +15,4 @@ const adapter = univ2Adapter(endpoints, { adapter.adapter.era.start = 1679529600 -export default adapter +export default adapter \ No newline at end of file diff --git a/fees/koi-finance/index.ts b/fees/koi-finance/index.ts new file mode 100644 index 0000000000..1431899b4d --- /dev/null +++ b/fees/koi-finance/index.ts @@ -0,0 +1,27 @@ +import { Adapter, FetchResultFees } from '../../adapters/types'; +import { ZKSYNC } from '../../helpers/chains'; +import { fetchV1 } from './koi-finance'; + + +const getFees = async (timestamp: number): Promise => { + const [feeV1] = await Promise.all([fetchV1()(timestamp)]); + const dailyFees = Number(feeV1.dailyFees); + const dailyRevenue = Number(feeV1.dailyRevenue); + + return { + dailyFees: `${dailyFees}`, + dailyRevenue: `${dailyRevenue}`, + timestamp + } +} + +const adapter: Adapter = { + adapter: { + [ZKSYNC]: { + fetch: getFees, + start: 1677110400, // TODO: Add accurate timestamp + }, + }, +}; + +export default adapter; \ No newline at end of file diff --git a/fees/koi-finance/koi-finance.ts b/fees/koi-finance/koi-finance.ts new file mode 100644 index 0000000000..1a524282c8 --- /dev/null +++ b/fees/koi-finance/koi-finance.ts @@ -0,0 +1,62 @@ +import request, { gql } from "graphql-request"; +import { getBlock } from "../../helpers/getBlock"; +import { + getTimestampAtStartOfDayUTC, + getTimestampAtStartOfPreviousDayUTC +} from "../../utils/date"; +import BigNumber from "bignumber.js"; + +const endpoint = "https://api.goldsky.com/api/public/project_clmtie4nnezuh2nw6hhjg6mo7/subgraphs/mute_switch/v0.0.7/gn" + +export const fetchV1 = () => { + return async (timestamp: number) => { + const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp); + const yesterdaysTimestamp = getTimestampAtStartOfPreviousDayUTC(timestamp); + const todaysBlock = await getBlock( + todaysTimestamp, + "era", + {} + ); + + const yesterdaysBlock = await getBlock(yesterdaysTimestamp, "era", {}); + + const query = gql` + query fees { + yesterday: pairs(block: {number: ${yesterdaysBlock}}, where: {volumeUSD_gt: "0"}, first: 1000, orderBy:volumeUSD, orderDirection:desc) { + id + stable + pairFee + volumeUSD + } + today: pairs(block: {number: ${todaysBlock}}, where: {volumeUSD_gt: "0"}, first: 1000, orderBy:volumeUSD, orderDirection:desc) { + id + stable + pairFee + volumeUSD + } + } + `; + const todayVolume: { [id: string]: BigNumber } = {}; + const graphRes = await request(endpoint, query); + let dailyFee = new BigNumber(0); + for (const pool of graphRes["today"]) { + todayVolume[pool.id] = new BigNumber(pool.volumeUSD); + } + + for (const pool of graphRes["yesterday"]) { + if (!todayVolume[pool.id]) continue; + + const dailyVolume = BigNumber(todayVolume[pool.id]).minus( + pool.volumeUSD + ); + + dailyFee = dailyFee.plus(dailyVolume.times(pool.pairFee).div(10000)) + } + + return { + timestamp, + dailyFees: dailyFee.toString(), + dailyRevenue: dailyFee.times(0.2).toString(), + }; + }; +}; \ No newline at end of file