|
| 1 | +import { FetchOptions, SimpleAdapter } from "../../adapters/types"; |
| 2 | +import { CHAIN } from "../../helpers/chains"; |
| 3 | +import fetchURL from "../../utils/fetchURL"; |
| 4 | + |
| 5 | +interface TokenInfo { |
| 6 | + ticker: string; |
| 7 | + token_name: string; |
| 8 | + decimals: number; |
| 9 | +} |
| 10 | + |
| 11 | +interface PeriodData { |
| 12 | + bets: Record<string, unknown>; |
| 13 | + fees: { |
| 14 | + total: number; |
| 15 | + [key: string]: unknown; |
| 16 | + }; |
| 17 | + vol: Record<string, unknown>; |
| 18 | +} |
| 19 | + |
| 20 | +interface TokenData { |
| 21 | + info: TokenInfo; |
| 22 | + past_1h: PeriodData; |
| 23 | + past_6h: PeriodData; |
| 24 | + past_24h: PeriodData; |
| 25 | + past_7d: PeriodData; |
| 26 | + past_30d: PeriodData; |
| 27 | + all_time: PeriodData; |
| 28 | +} |
| 29 | + |
| 30 | +interface StatsResponse { |
| 31 | + data: Record<string, TokenData>; |
| 32 | +} |
| 33 | + |
| 34 | +const fetch = async (options: FetchOptions) => { |
| 35 | + const dailyFees = options.createBalances(); |
| 36 | + const dailyRevenue = options.createBalances(); |
| 37 | + |
| 38 | + const stats: StatsResponse = await fetchURL(`https://mf-flip.fly.dev/stats`); |
| 39 | + |
| 40 | + const tokenEntries = Object.entries(stats.data); |
| 41 | + tokenEntries.forEach(([tokenAddress, tokenData]) => { |
| 42 | + const { info, past_24h } = tokenData; |
| 43 | + |
| 44 | + const dailyHouseBetFees = parseFloat(String(past_24h?.fees?.house_bet_fees || "0")); |
| 45 | + const dailyPvpBetFees = parseFloat(String(past_24h?.fees?.pvp_bet_fees || "0")); |
| 46 | + const dailyHousePnl = parseFloat(String(past_24h?.fees?.house_pnl || "0")); |
| 47 | + |
| 48 | + const dailyFeesAmount = dailyPvpBetFees + dailyHouseBetFees; // Daily PvP + PvH fees |
| 49 | + const dailyRevenueAmount = dailyFeesAmount + dailyHousePnl; |
| 50 | + |
| 51 | + dailyFees.add(tokenAddress, dailyFeesAmount * (10 ** info.decimals)); |
| 52 | + dailyRevenue.add(tokenAddress, dailyRevenueAmount * (10 ** info.decimals)); |
| 53 | + }); |
| 54 | + |
| 55 | + return { dailyFees, dailyRevenue, dailyProtocolRevenue: dailyRevenue, dailyHoldersRevenue: 0 }; |
| 56 | +}; |
| 57 | + |
| 58 | +const adapter: SimpleAdapter = { |
| 59 | + version: 2, |
| 60 | + fetch, |
| 61 | + chains: [CHAIN.SOLANA], |
| 62 | + start: "2024-08-18", |
| 63 | + runAtCurrTime: true, |
| 64 | + allowNegativeValue: true, // As house PnL can be negative |
| 65 | + methodology: { |
| 66 | + Fees: "Fees collected (3%) from PvH (Player vs House) and PvP (Player vs Player) games across all supported tokens", |
| 67 | + Revenue: "Fees collected from players + House PnL(it can be negative)", |
| 68 | + }, |
| 69 | +}; |
| 70 | + |
| 71 | +export default adapter; |
0 commit comments