UNPKG

@pump-fun/shared-contracts

Version:

Shared contracts for Pump.fun microservices.

113 lines (104 loc) 3.25 kB
/** * NATS Message Type Definitions for Pump.fun Notification System * * These types define the payload structure for each NATS subject */ import { z } from "zod"; /** * Unified trade event schema (matches the actual UnifiedTradeEvent interface) */ export const UnifiedTradeSchema = z.object({ /** Amount of SOL in the trade */ amountSol: z.string(), /** Amount in USD */ amountUsd: z.string(), /** Amount of base tokens (SPL token) */ baseAmount: z.string(), /** Whether the trade occurred on a bonding curve */ isBondingCurve: z.boolean(), /** Total liquidity in USD */ liquidityUSD: z.string(), /** LP fee taken */ lpFee: z.string(), /** LP fee in USD */ lpFeeUsd: z.string(), /** Total market cap in USD */ marketCap: z.string(), /** Token mint address */ mintAddress: z.string(), /** Liquidity pool address */ poolAddress: z.string(), /** Price ratio: base per quote */ priceBasePerQuote: z.string(), /** Price ratio: quote per base */ priceQuotePerBase: z.string(), /** Price in SOL */ priceSol: z.string(), /** Token price in USD */ priceUsd: z.string(), /** Protocol fee in SOL (may be absent in some events) */ protocolFeeSol: z.string().optional(), /** Protocol fee in USD (may be absent in some events) */ protocolFeeUsd: z.string(), /** Amount of quote tokens (SOL) */ quoteAmount: z.string(), /** Unique identifier for the slot */ slotIndexId: z.string(), /** ISO timestamp of the trade */ timestamp: z.string(), /** Transaction hash/signature */ tx: z.string(), /** Trade direction - buy or sell */ type: z.union([z.literal("buy"), z.literal("sell")]), /** Address of the user who made the trade */ userAddress: z.string(), }); export type UnifiedTrade = z.infer<typeof UnifiedTradeSchema>; // ============================================ // Watcher Service Messages // ============================================ /** * Portfolio alert schema */ export const PortfolioAlertSchema = z.object({ /** Alert type */ alertType: z.literal("pnl_threshold"), /** Current P&L */ currentPnl: z.number(), mintId: z.string(), /** P&L percentage */ pnlPercent: z.number(), /** P&L threshold that was triggered */ pnlThresholdPercent: z.number(), /** Alert timestamp */ timestamp: z.number(), /** User ID */ walletAddress: z.string(), }); export type PortfolioAlert = z.infer<typeof PortfolioAlertSchema>; /** * Processed notification schema */ export const ProcessedNotificationSchema = z.object({ /** Notification body */ body: z.string(), /** Delivery channels */ channels: z.array(z.union([z.literal("push"), z.literal("email"), z.literal("in_app")])), /** Created timestamp */ createdAt: z.number(), /** Additional data */ data: z.record(z.unknown()), /** Notification ID */ notificationId: z.string(), /** Priority level */ priority: z.union([z.literal("high"), z.literal("normal"), z.literal("low")]), /** Notification title */ title: z.string(), /** Time to live in seconds */ ttl: z.number().optional(), /** Notification type */ type: z.string(), /** User ID */ userId: z.string(), }); export type ProcessedNotification = z.infer<typeof ProcessedNotificationSchema>;