/** * HedgeFUN client: a typed wrapper around the public read API. * Drop this file into any TypeScript project (browser or Node 18+). No dependencies. * * import { HedgeFun } from "./hedgefun"; * const hf = new HedgeFun(); * const portfolios = await hf.portfolios(); */ export type Venue = "pump" | "stock" | "sol"; export interface Asset { mint: string; ticker: string; name: string; venue: Venue; issuer?: string; icon: string | null; decimals: number; priceUsd: number | null; change24h: number | null; liquidity?: number | null; } export interface Portfolio { mint: string; signature: string; indexName: string; name: string; symbol: string; description: string; image: string | null; creator: string; devBuySol: number; basket: { mint: string; ticker: string; weight: number; icon: string | null; venue: string }[]; wallets: { role: "dev" | "mini"; address: string; plannedBuySol: number }[]; fees: { basketPct: number; buybackPct: number; treasuryPct: number }; socials: { x?: string; telegram?: string; site?: string }; at: number; } export interface ActivityEntry { mint: string; kind: "launch" | "mini-buy" | "collect" | "basket-buy" | "buyback"; signature: string; signer: string; amountSol: number; asset?: string; recipient?: string; at: number; } export interface Quote { price: number; mcap: number; change24h: number; volume24h: number; liquidity: number; pair: string; dex: string; } export interface Candle { t: number; o: number; h: number; l: number; c: number; v: number; } export class HedgeFun { constructor(private base = "https://www.hedgefun.online") {} private async get(path: string): Promise { const res = await fetch(`${this.base}${path}`); if (!res.ok) throw new Error(`HedgeFUN ${path} → ${res.status}`); return res.json() as Promise; } /** Every asset a portfolio can hold, with live prices */ async assets(): Promise { return (await this.get<{ assets: Asset[] }>("/api/universe")).assets; } /** Every portfolio deployed through HedgeFUN, newest first */ async portfolios(): Promise { return (await this.get<{ launches: Portfolio[] }>("/api/launches")).launches; } /** One portfolio by its token mint */ async portfolio(mint: string): Promise { return (await this.portfolios()).find((p) => p.mint === mint) ?? null; } /** On-chain-verified activity: deployment, allocations, fee collections, reinvestment, buybacks */ async activity(mint?: string): Promise { return (await this.get<{ entries: ActivityEntry[] }>(`/api/ledger${mint ? `?mint=${mint}` : ""}`)).entries; } /** Live quotes for up to 60 token mints */ async quotes(mints: string[]): Promise> { return (await this.get<{ quotes: Record }>(`/api/market?mints=${mints.join(",")}`)).quotes; } /** Quote plus 15-minute candles for one token */ async chart(mint: string): Promise<{ quote: Quote | null; candles: Candle[] }> { const r = await this.get<{ quotes: Record; candles: Candle[] }>(`/api/market?mint=${mint}&chart=1`); return { quote: r.quotes[mint] ?? null, candles: r.candles }; } }