wisdom-sdk
Version:
Core business logic and data access layer for prediction markets
111 lines (109 loc) • 3.82 kB
text/typescript
declare const predictionStore: {
createPrediction(data: {
marketId: string;
marketName: string;
outcomeId: number;
outcomeName: string;
userId: string;
amount: number;
}): Promise<{
id: string;
marketId: string;
outcomeId: number;
outcomeName: string;
userId: string;
amount: number;
createdAt: string;
nftReceipt: {
id: string;
tokenId: string;
image: string;
predictionId: string;
marketName: string;
outcomeName: string;
amount: number;
createdAt: string;
};
status: string;
}>;
getUserPredictions(userId: string): Promise<({} | undefined)[]>;
getMarketPredictions(marketId: string): Promise<({} | undefined)[]>;
getPrediction(id: string): Promise<{} | undefined>;
getNFTReceipt(id: string): Promise<{} | undefined>;
updatePredictionStatus(id: string, status: "active" | "won" | "lost" | "redeemed" | "cancelled"): Promise<{
status: "active" | "cancelled" | "won" | "lost" | "redeemed";
} | undefined>;
generateNftImage(marketName: string, outcomeName: string, amount: number): string;
/**
* Create a prediction with balance update
* This function handles the complete process of:
* 1. Checking user balance and deducting funds
* 2. Creating the prediction and NFT receipt
* 3. Updating market stats
* 4. Updating user stats for leaderboard
*
* @param data Prediction data
* @returns Object with created prediction or error message
*/
createPredictionWithBalanceUpdate(data: {
marketId: string;
outcomeId: number;
userId: string;
amount: number;
}): Promise<{
success: boolean;
prediction?: any;
error?: string;
market?: Record<string, unknown>;
outcomeName?: string;
}>;
deletePrediction(predictionId: string): Promise<boolean>;
/**
* Update a prediction with new data
*/
updatePrediction(predictionId: string, data: any): Promise<any>;
/**
* Validate if a prediction is eligible for redemption
*
* @param predictionId ID of the prediction
* @param userId User attempting to redeem
* @returns Validation result with prediction if successful
*/
validateRedemptionEligibility(predictionId: string, userId: string): Promise<{
success: boolean;
prediction?: any;
error?: string;
isAdmin?: boolean;
}>;
/**
* Redeem a prediction with balance update
* This function handles the complete process of:
* 1. Validating the prediction is eligible for redemption
* 2. Updating the prediction status
* 3. Updating the user's balance
*
* @param predictionId The ID of the prediction to redeem
* @param userId The ID of the user trying to redeem
* @returns Object with redemption result
*/
redeemPredictionWithBalanceUpdate(predictionId: string, userId: string): Promise<{
success: boolean;
prediction?: any;
payout?: number;
error?: string;
}>;
/**
* Redeem a prediction after market resolution
* This is kept for backward compatibility but we recommend using
* redeemPredictionWithBalanceUpdate for new code
*/
redeemPrediction(predictionId: string): Promise<{
prediction: any;
payout: number;
}>;
/**
* Get all predictions for a specific market with a specific status
*/
getMarketPredictionsByStatus(marketId: string, status: string): Promise<({} | undefined)[]>;
};
export { predictionStore };