-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65e2808
commit 5bb5de6
Showing
9 changed files
with
133 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.25; | ||
|
||
import {Script, console} from "forge-std/Script.sol"; | ||
import {PredictionMarket} from "../../src/predictionmarket/PredictionMarket.sol"; | ||
|
||
import {TicTacToe} from "../../src/tictactoe/TicTacToe.sol"; | ||
import {TicTacToePredictionMarketFactory} from "../../src/predictionmarket/factories/TicTacToePredictionMarketFactory.sol"; | ||
import {MockMarketFactory} from "../../src/predictionmarket/factories/MockMarketFactory.sol"; | ||
contract DeployScript is Script { | ||
function setUp() public {} | ||
|
||
function run() public { | ||
// Only Prediction Market App Chain | ||
require(block.chainid == 901); | ||
|
||
// sanity check that this is deployed with an eth_call | ||
TicTacToe tictactoe = TicTacToe(address(0xe405EE520988f6F4f508f64108436911B7816135)); | ||
console.log("Querying TicTacToe contract"); | ||
tictactoe.nextGameId(); | ||
|
||
vm.broadcast(); | ||
|
||
// Deploy Prediction Market | ||
PredictionMarket market = new PredictionMarket{salt: "predictionmarket"}(); | ||
|
||
// Deploy Factories for the different kinds of markets | ||
TicTacToePredictionMarketFactory factory = new TicTacToePredictionMarketFactory{salt: "tictactoefactory"}(tictactoe, market); | ||
MockMarketFactory mockFactory = new MockMarketFactory{salt: "mockfactory"}(market); | ||
|
||
console.log("PredictionMarket Deployed at: ", address(market)); | ||
console.log("TicTacToePredictionMarketFactory Deployed at: ", address(factory)); | ||
console.log("MockMarketFactory Deployed at: ", address(mockFactory)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
contracts/src/predictionmarket/factories/MockMarketFactory.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import {PredictionMarket} from "../PredictionMarket.sol"; | ||
import {MockResolver} from "../resolvers/MockResolver.sol"; | ||
|
||
contract MockMarketFactory { | ||
// @notice PredictionMarket contract | ||
PredictionMarket public predictionMarket; | ||
|
||
constructor(PredictionMarket _predictionMarket) { | ||
predictionMarket = _predictionMarket; | ||
} | ||
|
||
function newMarket() external { | ||
MockResolver resolver = new MockResolver(); | ||
predictionMarket.newMarket(resolver); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
contracts/src/predictionmarket/resolvers/L1BlockResolver.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import {Predeploys} from "@contracts-bedrock/libraries/Predeploys.sol"; | ||
import {ICrossL2Inbox} from "@contracts-bedrock/L2/interfaces/ICrossL2Inbox.sol"; | ||
|
||
import { IMarketResolver, MarketOutcome } from "../MarketResolver.sol"; | ||
|
||
contract L1BlockResolver is IMarketResolver { | ||
// @notice Chain ID of the L2 chain | ||
uint256 public chainId; | ||
|
||
// @notice block height of this bet | ||
uint256 public blockNumber; | ||
|
||
// @notice whether the block hash is odd or even | ||
bool public isOdd; | ||
|
||
// @notice current outcome of this bet | ||
MarketOutcome public outcome; | ||
|
||
constructor(uint256 _chainId, uint256 _blockNumber, bool _isOdd) { | ||
outcome = MarketOutcome.UNDECIDED; | ||
|
||
chainId = _chainId; | ||
blockNumber = _blockNumber; | ||
isOdd = _isOdd; | ||
} | ||
|
||
function resolve(ICrossL2Inbox.Identifier calldata _id, bytes calldata _data) external { | ||
require(_id.origin == Predeploys.L1_BLOCK_ATTRIBUTES); | ||
ICrossL2Inbox(Predeploys.CROSS_L2_INBOX).validateMessage(_id, keccak256(_data)); | ||
|
||
require(_id.chainId == chainId); | ||
|
||
if (uint256(blockhash(blockNumber)) % 2 == 0 && isOdd) { | ||
outcome = MarketOutcome.NO; | ||
} else { | ||
outcome = MarketOutcome.YES; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import {IMarketResolver, MarketOutcome} from "../MarketResolver.sol"; | ||
|
||
contract MockResolver is IMarketResolver { | ||
MarketOutcome public outcome; | ||
|
||
function setOutcome(MarketOutcome _outcome) public { | ||
require(outcome == MarketOutcome.UNDECIDED); | ||
require(_outcome != MarketOutcome.UNDECIDED); | ||
|
||
outcome = _outcome; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.