Skip to content

Commit

Permalink
feat: add mango-v4 to dexs + fees
Browse files Browse the repository at this point in the history
  • Loading branch information
Lou-Kamades committed Sep 18, 2023
1 parent 9f70032 commit f83c0cf
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 0 deletions.
77 changes: 77 additions & 0 deletions dexs/mango-v4/index.ts
Original file line number Diff line number Diff line change
@@ -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<FetchResultVolume> => {
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<FetchResultVolume> => {
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;
83 changes: 83 additions & 0 deletions fees/mango-v4.ts
Original file line number Diff line number Diff line change
@@ -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<FetchResultFees> => {
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<FetchResultFees> => {
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;

0 comments on commit f83c0cf

Please sign in to comment.