Winner Takes It All
public class RewardCalculator {
/**
* Calculate the reward for a correct prediction in a 'Winner Takes It All' prediction system.
*
* @param totalPool The total amount of tokens in the pool.
* @param platformFee The fee percentage or fixed amount taken by the platform.
* @param yourVoteAmount The amount of tokens the user voted with.
* @param correctAnswerPool The total amount of tokens staked on the correct answer.
* @return The reward amount the user will receive.
*/
public static double calculateReward(double totalPool, double platformFee, double yourVoteAmount, double correctAnswerPool) {
// Calculate the adjusted pool after deducting the platform fee
double adjustedPool = totalPool - platformFee;
// Calculate the user's share in the correct answer pool
double userSharePercentage = yourVoteAmount / correctAnswerPool;
// Calculate the user's reward
double reward = adjustedPool * userSharePercentage;
return reward;
}
public static void main(String[] args) {
double totalPool = 1000; // Total pool amount in USDC
double platformFee = 50; // Platform fee amount in USDC
double yourVoteAmount = 10; // Your vote amount in USDC
double correctAnswerPool = 100; // Total amount staked on the correct answer in USDC
double reward = calculateReward(totalPool, platformFee, yourVoteAmount, correctAnswerPool);
System.out.printf("Your reward is: %.2f USDC%n", reward);
}
}Last updated