From fa455b8a6bba2265e98ba4a2a6a09ed9b0ba9cc3 Mon Sep 17 00:00:00 2001 From: Algozino Santiago Date: Mon, 1 May 2023 22:34:16 -0300 Subject: [PATCH 1/3] create nba script --- scripts/markets/create-nba_match.js | 76 +++++++++++++++++++++++++++++ scripts/markets/helpers.js | 7 ++- 2 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 scripts/markets/create-nba_match.js diff --git a/scripts/markets/create-nba_match.js b/scripts/markets/create-nba_match.js new file mode 100644 index 0000000..d9fe065 --- /dev/null +++ b/scripts/markets/create-nba_match.js @@ -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); + }); \ No newline at end of file diff --git a/scripts/markets/helpers.js b/scripts/markets/helpers.js index 3ae0430..7896343 100644 --- a/scripts/markets/helpers.js +++ b/scripts/markets/helpers.js @@ -221,7 +221,8 @@ const params = { arbitrator: "0x29F39dE98D750eb77b5FAfb31B2837f079FcE222", realityEth: "0xE78996A233895bE74a66F451f1019cA9734205cc", factory: "0x67d3673CF19a6b0Ad70D76b4e9C6f715177eb48b", - factoryV2: "0x364Bc6fCdF1D2Ce014010aB4f479a892a8736014" + factoryV2: "0x364Bc6fCdF1D2Ce014010aB4f479a892a8736014", + realityRegistry: "0xaD3AA4da922Ab968d8e9733Ecf32699756970193" }, 31337: { arbitrator: "0x29F39dE98D750eb77b5FAfb31B2837f079FcE222", @@ -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, @@ -263,5 +265,6 @@ module.exports = { getChain, SOCCER_MATCH_DURATION, TENNIS_MATCH_DURATION, - F1_RACE_DURATION + F1_RACE_DURATION, + BASKET_MATCH_DURATION } \ No newline at end of file From 05abd007c25bc30267dd3bb15aa9081d1b873ff7 Mon Sep 17 00:00:00 2001 From: Algozino Santiago Date: Sun, 7 May 2023 22:49:11 -0300 Subject: [PATCH 2/3] add closingTime of the market to the bet view --- contracts/misc/MarketView.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/misc/MarketView.sol b/contracts/misc/MarketView.sol index 018b252..d1cdb81 100644 --- a/contracts/misc/MarketView.sol +++ b/contracts/misc/MarketView.sol @@ -301,6 +301,7 @@ contract MarketView { betInfo.ownerName = keyValue.username(betInfo.owner); betInfo.predictions = getPredictions(market, tokenId); betInfo.points = getScore(market, tokenId); + betInfo.closingTime = market.closingTime(); } function getMarketFactoryAttrs(IMarketFactory marketFactory) From 5ab63eac5898624be3ff4a09741211ccf17d6a0a Mon Sep 17 00:00:00 2001 From: Algozino Santiago Date: Sun, 7 May 2023 23:00:25 -0300 Subject: [PATCH 3/3] add field to check if has won --- contracts/interfaces/IMarket.sol | 2 ++ contracts/misc/MarketView.sol | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/contracts/interfaces/IMarket.sol b/contracts/interfaces/IMarket.sol index 449cecf..cf3445f 100644 --- a/contracts/interfaces/IMarket.sol +++ b/contracts/interfaces/IMarket.sol @@ -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);); } diff --git a/contracts/misc/MarketView.sol b/contracts/misc/MarketView.sol index d1cdb81..70a4135 100644 --- a/contracts/misc/MarketView.sol +++ b/contracts/misc/MarketView.sol @@ -302,6 +302,16 @@ contract MarketView { 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)