UNPKG

wisdom-sdk

Version:

Core business logic and data access layer for prediction markets

89 lines (87 loc) 2.77 kB
/** * Utility functions for OP Predict */ declare const ADMIN_USER_IDS: string[]; declare function isAdmin(userId: string): boolean; /** * Generates a UUID using the Web Crypto API which is available in both * Node.js and edge runtime environments. This replaces the Node.js-specific * crypto.randomUUID() function. * * @returns A UUID v4 string */ declare function generateUUID(): string; /** * Calculate outcome percentages based on staked amounts with fallback to votes * @param outcomes Market outcomes * @returns Outcomes with percentages and a flag indicating if vote-based fallback was used */ declare function calculateOutcomePercentages(outcomes: { id: number; name: string; amount?: number; votes?: number; }[]): { outcomesWithPercentages: { percentage: number; id: number; name: string; amount?: number; votes?: number; }[]; useFallbackVotes: boolean; }; /** * Safely get the base URL of the application without causing SSR issues * with window access */ declare function getBaseUrl(): string; type MarketStatus = 'active' | 'resolved' | 'cancelled' | 'closed' | 'all'; type MarketType = 'binary' | 'multiple' | 'all'; type SortField = 'createdAt' | 'endDate' | 'poolAmount' | 'participants'; type SortDirection = 'asc' | 'desc'; interface MarketQueryOptions { status?: MarketStatus; category?: string; type?: MarketType; search?: string; creatorId?: string; limit?: number; offset?: number; cursor?: string; sortBy?: SortField; sortDirection?: SortDirection; resolvedOutcomeId?: number; resolvedAt?: string; resolvedBy?: string; adminFee?: number; remainingPot?: number; totalWinningAmount?: number; } interface PaginatedResult<T> { items: T[]; total: number; hasMore: boolean; nextCursor?: string; } /** * Simple text search for markets * Searches for terms in name and description */ declare function searchMarketText(market: any, searchText: string): boolean; /** * Filter markets by multiple criteria */ declare function filterMarkets(markets: any[], options?: MarketQueryOptions): any[]; /** * Sort markets by specified field and direction */ declare function sortMarkets(markets: any[], sortBy?: SortField, sortDirection?: SortDirection): any[]; /** * Apply pagination to results */ declare function paginateResults<T>(items: T[], options: { limit?: number; offset?: number; }): PaginatedResult<T>; export { ADMIN_USER_IDS, type MarketQueryOptions, type MarketStatus, type MarketType, type PaginatedResult, type SortDirection, type SortField, calculateOutcomePercentages, filterMarkets, generateUUID, getBaseUrl, isAdmin, paginateResults, searchMarketText, sortMarkets };