Skip to content

Commit

Permalink
added events
Browse files Browse the repository at this point in the history
  • Loading branch information
SolidityDrone committed Oct 31, 2024
1 parent b94bd24 commit b5e4c62
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/MultiOutcomePredictionMarket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ contract MultiOutcomePredictionMarket is IMultiOutcomePredictionMarket {
for (uint256 i = 0; i < initialPrices.length; i++) {
newMarket.options.push(Option(0, initialPrices[i], initialPrices[i], optionNames[i]));
}

marketCre
}

/**
Expand All @@ -98,6 +100,8 @@ contract MultiOutcomePredictionMarket is IMultiOutcomePredictionMarket {
require(winningOptionIndex < market.options.length , "Option out of array bounds");
market.winningOptionIndex = winningOptionIndex;
market.resolved = true;

emit MarketResolved(marketId, winningOptionIndex, getMarketWinner(marketId));
}

/**
Expand Down Expand Up @@ -148,6 +152,8 @@ contract MultiOutcomePredictionMarket is IMultiOutcomePredictionMarket {
IERC20(USDC_BASE_SEPOLIA).transferFrom(msg.sender, address(this), cost);

_updateMarketPrices(marketId);

emit(BoughtShares(msg.sender, marketId, optionId, quantity, cost));
}

/**
Expand Down Expand Up @@ -177,6 +183,8 @@ contract MultiOutcomePredictionMarket is IMultiOutcomePredictionMarket {
IERC20(USDC_BASE_SEPOLIA).transfer(msg.sender, sellReturn);

_updateMarketPrices(marketId);

emit SoldShares(user, marketId, optionId, quantity, sellReturn);
}

/**
Expand Down Expand Up @@ -249,7 +257,7 @@ contract MultiOutcomePredictionMarket is IMultiOutcomePredictionMarket {
// First share + arithmetic mean of remaining shares prices * number of remaining shares
return firstShareCost + (remainingShares * (secondSharePrice + lastSharePrice) / 2);
}

/**
* @notice Calculates the return from selling shares with exact price matching
* @param marketId ID of the target market
Expand Down Expand Up @@ -436,10 +444,13 @@ contract MultiOutcomePredictionMarket is IMultiOutcomePredictionMarket {
Market memory market = markets[marketId];
UserShares memory userShares = userMarketShares[msg.sender][marketId];
require(!userShares.claimed, "Already claimed");
uint userWinningShares = userShares.shares[market.winningOptionIndex];
uint totalWinningShares = market.options[market.winningOptionIndex].shares;
uint rewardPerShare = market.prizePool / totalWinningShares;
uint userRewards = rewardPerShare * userShares.shares[market.winningOptionIndex];
uint userRewards = rewardPerShare * userWinningShares;

IERC20(USDC_BASE_SEPOLIA).transfer(msg.sender, userRewards);

emit Withdrawal(msg.sender, marketId, userWinningShares, reward);
}
}
15 changes: 13 additions & 2 deletions src/flattened/MutiOutcomePredictionMarket.flattened.sol
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ contract MultiOutcomePredictionMarket is IMultiOutcomePredictionMarket {
for (uint256 i = 0; i < initialPrices.length; i++) {
newMarket.options.push(Option(0, initialPrices[i], initialPrices[i], optionNames[i]));
}

marketCre
}

/**
Expand All @@ -219,6 +221,8 @@ contract MultiOutcomePredictionMarket is IMultiOutcomePredictionMarket {
require(winningOptionIndex < market.options.length , "Option out of array bounds");
market.winningOptionIndex = winningOptionIndex;
market.resolved = true;

emit MarketResolved(marketId, winningOptionIndex, getMarketWinner(marketId));
}

/**
Expand Down Expand Up @@ -269,6 +273,8 @@ contract MultiOutcomePredictionMarket is IMultiOutcomePredictionMarket {
IERC20(USDC_BASE_SEPOLIA).transferFrom(msg.sender, address(this), cost);

_updateMarketPrices(marketId);

emit(BoughtShares(msg.sender, marketId, optionId, quantity, cost));
}

/**
Expand Down Expand Up @@ -298,6 +304,8 @@ contract MultiOutcomePredictionMarket is IMultiOutcomePredictionMarket {
IERC20(USDC_BASE_SEPOLIA).transfer(msg.sender, sellReturn);

_updateMarketPrices(marketId);

emit SoldShares(user, marketId, optionId, quantity, sellReturn);
}

/**
Expand Down Expand Up @@ -370,7 +378,7 @@ contract MultiOutcomePredictionMarket is IMultiOutcomePredictionMarket {
// First share + arithmetic mean of remaining shares prices * number of remaining shares
return firstShareCost + (remainingShares * (secondSharePrice + lastSharePrice) / 2);
}

/**
* @notice Calculates the return from selling shares with exact price matching
* @param marketId ID of the target market
Expand Down Expand Up @@ -557,10 +565,13 @@ contract MultiOutcomePredictionMarket is IMultiOutcomePredictionMarket {
Market memory market = markets[marketId];
UserShares memory userShares = userMarketShares[msg.sender][marketId];
require(!userShares.claimed, "Already claimed");
uint userWinningShares = userShares.shares[market.winningOptionIndex];
uint totalWinningShares = market.options[market.winningOptionIndex].shares;
uint rewardPerShare = market.prizePool / totalWinningShares;
uint userRewards = rewardPerShare * userShares.shares[market.winningOptionIndex];
uint userRewards = rewardPerShare * userWinningShares;

IERC20(USDC_BASE_SEPOLIA).transfer(msg.sender, userRewards);

emit Withdrawal(msg.sender, marketId, userWinningShares, reward);
}
}

0 comments on commit b5e4c62

Please sign in to comment.