Skip to content

Instantly share code, notes, and snippets.

@coderwithsense
Created March 30, 2025 09:49
Show Gist options
  • Save coderwithsense/638e85552603ae81f2be499c8627cfe6 to your computer and use it in GitHub Desktop.
Save coderwithsense/638e85552603ae81f2be499c8627cfe6 to your computer and use it in GitHub Desktop.
Deploys new PredictionGame contracts and tracks them by creator and token pair
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "./PredictionGame.sol";
contract PredictionFactory {
address[] public allGames;
mapping(address => address[]) public userGames;
event GameCreated(address game, address creator);
function createPredictionGame(
string memory pair,
uint256 targetPrice,
uint256 expiry,
uint256 creatorFee
) external {
PredictionGame game = new PredictionGame(
msg.sender,
pair,
targetPrice,
expiry,
creatorFee
);
allGames.push(address(game));
userGames[msg.sender].push(address(game));
emit GameCreated(address(game), msg.sender);
}
function getAllGames() external view returns (address[] memory) {
return allGames;
}
function getGamesByCreator(address user) external view returns (address[] memory) {
return userGames[user];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment