Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Market view update #60

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contracts/interfaces/IMarket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,6 @@ interface IMarket is IERC721 {
function getPredictions(uint256 _tokenID) external view returns (bytes32[] memory);

function getScore(uint256 _tokenID) external view returns (uint256 totalPoints);

function isRanked(uint256 _tokenID) external view returns (bool isRanked(_tokenID););
}
11 changes: 11 additions & 0 deletions contracts/misc/MarketView.sol
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,17 @@ contract MarketView {
betInfo.ownerName = keyValue.username(betInfo.owner);
betInfo.predictions = getPredictions(market, tokenId);
betInfo.points = getScore(market, tokenId);
betInfo.closingTime = market.closingTime();
betInfo.isRanked = market.isRanked(tokenId);
bool hasWon = false
uint256[] prizes = getPrizes(market);
for (uint256 i = 0; i < prizes.length; i++) {
if (market.ranking(i).tokenID === tokenId) {
hasWon = true
break
}
}
betInfo.hasWon = hasWon
}

function getMarketFactoryAttrs(IMarketFactory marketFactory)
Expand Down
76 changes: 76 additions & 0 deletions scripts/markets/create-nba_match.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const hre = require("hardhat");
const {getChain, buildQuestionSingleSelectV2, toTimestamp, BASKET_MATCH_DURATION, orderQuestionsV2} = require("./helpers");
const ethers = hre.ethers;

const timeout = 129600; // 1.5 days

const teams = ['Warriors', 'Lakers']
const matchTs = toTimestamp("2023-05-02 23:00:00 GMT-3")
const openingTs = matchTs + BASKET_MATCH_DURATION;
const marketName = `NBA Playoffs 2023 - ${teams[0]} vs ${teams[1]} - Game 1`;
const teamsDraw = teams.concat('Draw');
const yesNo = ['Yes', 'No'];


const marketData = {
marketName: marketName,
marketSymbol: "PRODE",
closingTime: matchTs, // can bet until the beggining of the match
price: ethers.utils.parseUnits("1.0", "ether"), // 1 xDAI
creator: "0x0029ec18568F96AFE25Ea289Dac6c4703868924d",
creatorFee: 300,
minBond: ethers.utils.parseUnits("5.0", "ether"), // 5 xDAI
questions: [
buildQuestionSingleSelectV2(`What will be the result of ${marketName}?`, teams, openingTs, 'basketball'),
buildQuestionSingleSelectV2(`Will ${teams[0]} score more than 110 points at ${marketName}?`, yesNo, openingTs+1, 'basketball'),
buildQuestionSingleSelectV2(`Will ${teams[1]} score more than 110 points at ${marketName}?`, yesNo, openingTs+2, 'basketball'),
buildQuestionSingleSelectV2(`Which team will lead at the end of the first quarter in the ${marketName}?`, teamsDraw, openingTs+3, 'basketball'),
buildQuestionSingleSelectV2(`Which team will lead at the end of half-time in the ${marketName}?`, teamsDraw, openingTs+4, 'basketball'),
buildQuestionSingleSelectV2(`Which team will lead at the end of the third quarter in the ${marketName}?`, teamsDraw, openingTs+5, 'basketball'),
buildQuestionSingleSelectV2(`Will the handicap at the end of the game be greater than 4.5 in the ${marketName}?`, yesNo, openingTs+6, 'basketball'),
],
prizeWeights: [8000, 2000]
};

async function main() {
const chainId = hre.network.config.chainId;
const [deployer] = await ethers.getSigners();

console.log("Deploying contracts with the account:", deployer.address);
console.log("Account balance:", (await deployer.getBalance()).toString());
console.log("Chain Id:", chainId);
console.log(marketData)
const chainConfig = getChain(chainId);


// Sort questions by Realitio's question ID.
const orderedQuestions = orderQuestionsV2(
marketData,
timeout,
chainConfig.arbitrator,
chainConfig.realityEth,
chainConfig.factory
);

const MarketFactoryV2 = await ethers.getContractFactory("MarketFactoryV2");
const marketFactoryV2 = await MarketFactoryV2.attach(chainConfig.factoryV2);

await marketFactoryV2.createMarket(
marketData.marketName,
marketData.marketSymbol,
marketData.creator,
marketData.creatorFee,
marketData.closingTime,
marketData.price,
marketData.minBond,
orderedQuestions,
marketData.prizeWeights
);
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
7 changes: 5 additions & 2 deletions scripts/markets/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ const params = {
arbitrator: "0x29F39dE98D750eb77b5FAfb31B2837f079FcE222",
realityEth: "0xE78996A233895bE74a66F451f1019cA9734205cc",
factory: "0x67d3673CF19a6b0Ad70D76b4e9C6f715177eb48b",
factoryV2: "0x364Bc6fCdF1D2Ce014010aB4f479a892a8736014"
factoryV2: "0x364Bc6fCdF1D2Ce014010aB4f479a892a8736014",
realityRegistry: "0xaD3AA4da922Ab968d8e9733Ecf32699756970193"
},
31337: {
arbitrator: "0x29F39dE98D750eb77b5FAfb31B2837f079FcE222",
Expand All @@ -243,6 +244,7 @@ function getChain(chainId) {
const SOCCER_MATCH_DURATION = 60*60*2;
const TENNIS_MATCH_DURATION = 60*60*5;
const F1_RACE_DURATION = 60*60*2;
const BASKET_MATCH_DURATION = 60*60*2;

module.exports = {
buildQuestionHomevsAway,
Expand All @@ -263,5 +265,6 @@ module.exports = {
getChain,
SOCCER_MATCH_DURATION,
TENNIS_MATCH_DURATION,
F1_RACE_DURATION
F1_RACE_DURATION,
BASKET_MATCH_DURATION
}