diff --git a/dexs/mango-v4/index.ts b/dexs/mango-v4/index.ts new file mode 100644 index 0000000000..0ec2e34a91 --- /dev/null +++ b/dexs/mango-v4/index.ts @@ -0,0 +1,77 @@ +import { + BreakdownAdapter, + FetchResultVolume, + ProtocolType, +} from "../../adapters/types"; + +import fetchURL from "../../utils/fetchURL"; + +const urlTotalStats = + "https://api.mngo.cloud/data/v4/stats/protocol-total-volume-fees"; +const urlDailyStats = + "https://api.mngo.cloud/data/v4/stats/protocol-daily-volume-fees"; + +interface TotalStats { + total_volume: number; + total_fees: number; + spot_volume: number; + perp_volume: number; + spot_fees: number; + perp_fees: number; +} +interface DailyStats { + total_volume_24h: number; + total_fees_24h: number; + spot_volume_24h: number; + perp_volume_24h: number; + spot_fees_24h: number; + perp_fees_24h: number; +} + +const fetchSpotVolume = async ( + timestamp: number, +): Promise => { + const totalStats: TotalStats = (await fetchURL(urlTotalStats)).data; + const dailyStats: DailyStats = (await fetchURL(urlDailyStats)).data; + return { + dailyVolume: dailyStats?.spot_volume_24h.toString(), + totalVolume: totalStats?.spot_volume.toString(), + timestamp: timestamp, + }; +}; + +const fetchPerpVolume = async ( + timestamp: number, +): Promise => { + const totalStats: TotalStats = (await fetchURL(urlTotalStats)).data; + const dailyStats: DailyStats = (await fetchURL(urlDailyStats)).data; + return { + dailyVolume: dailyStats?.perp_volume_24h.toString(), + totalVolume: totalStats?.perp_volume.toString(), + timestamp: timestamp, + }; +}; + +const adapter: BreakdownAdapter = { + breakdown: { + spot: { + solana: { + fetch: fetchSpotVolume, + runAtCurrTime: true, + customBackfill: undefined, + start: async () => 0, + }, + }, + perp: { + solana: { + fetch: fetchPerpVolume, + runAtCurrTime: true, + customBackfill: undefined, + start: async () => 0, + }, + }, + }, + protocolType: ProtocolType.PROTOCOL, +}; + +export default adapter; diff --git a/fees/mango-v4.ts b/fees/mango-v4.ts new file mode 100644 index 0000000000..e916aaacd4 --- /dev/null +++ b/fees/mango-v4.ts @@ -0,0 +1,83 @@ +import { + BreakdownAdapter, + FetchResultFees, + ProtocolType, + SimpleAdapter, +} from "../adapters/types"; +import fetchURL from "../utils/fetchURL"; + +const urlTotalStats = + "https://api.mngo.cloud/data/v4/stats/protocol-total-volume-fees"; +const urlDailyStats = + "https://api.mngo.cloud/data/v4/stats/protocol-daily-volume-fees"; + +interface TotalStats { + total_volume: number; + total_fees: number; + spot_volume: number; + perp_volume: number; + spot_fees: number; + perp_fees: number; +} +interface DailyStats { + total_volume_24h: number; + total_fees_24h: number; + spot_volume_24h: number; + perp_volume_24h: number; + spot_fees_24h: number; + perp_fees_24h: number; +} + +const fetchSpotFees = async (timestamp: number): Promise => { + const totalStats: TotalStats = (await fetchURL(urlTotalStats)).data; + const dailyStats: DailyStats = (await fetchURL(urlDailyStats)).data; + return { + dailyFees: dailyStats?.total_fees_24h.toString(), + totalFees: totalStats?.total_fees.toString(), + timestamp: timestamp, + }; +}; + +const fetchPerpFees = async (timestamp: number): Promise => { + const totalStats: TotalStats = (await fetchURL(urlTotalStats)).data; + const dailyStats: DailyStats = (await fetchURL(urlDailyStats)).data; + return { + dailyFees: dailyStats?.total_fees_24h.toString(), + totalFees: totalStats?.total_fees.toString(), + timestamp: timestamp, + }; +}; + +const adapter: BreakdownAdapter = { + breakdown: { + spot: { + solana: { + fetch: fetchSpotFees, + runAtCurrTime: true, + customBackfill: undefined, + start: async () => 0, + meta: { + methodology: { + Fees: "Swap fees are 0.1%, with a fee of 0.2% for stop-loss swaps. CLOB maker/taker fees are -0.02%/0.04%.", + }, + }, + }, + }, + perp: { + solana: { + fetch: fetchPerpFees, + runAtCurrTime: true, + customBackfill: undefined, + start: async () => 0, + meta: { + methodology: { + Fees: "Maker/taker fees are -0.03%/0.1%. Stop-loss orders have a fee of 0.2%", + }, + }, + }, + }, + }, + protocolType: ProtocolType.PROTOCOL, +}; + +export default adapter;