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

refactor obtainer to use normalized odds from storage also resize contract #290

Merged
merged 1 commit into from
Mar 3, 2023
Merged
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
265 changes: 143 additions & 122 deletions contracts/SportMarkets/Rundown/GamesOddsObtainer.sol

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions contracts/SportMarkets/Rundown/TherundownConsumer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ contract TherundownConsumer is Initializable, ProxyOwned, ProxyPausable {
marketCreated[address(market)] = true;
canMarketBeUpdated[address(market)] = true;

oddsObtainer.setFirstNormalizedOdds(game.gameId, address(market));

queues.dequeueGamesCreated();

emit CreateSportsMarket(address(market), game.gameId, game, tags, oddsObtainer.getNormalizedOdds(game.gameId));
Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/IGamesOddsObtainer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ interface IGamesOddsObtainer {
int24 _drawOdds
) external;

function setFirstNormalizedOdds(bytes32 _gameId, address _market) external;

function setBackupOddsAsMainOddsForGame(bytes32 _gameId) external;

function pauseUnpauseChildMarkets(address _main, bool _flag) external;
Expand Down
99 changes: 99 additions & 0 deletions scripts/abi/GamesOddsObtainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,25 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_market",
"type": "address"
}
],
"name": "getNormalizedChildOddsFromGameOddsStruct",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -1047,6 +1066,25 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "_gameId",
"type": "bytes32"
}
],
"name": "getNormalizedOddsFromGameOddsStruct",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -1278,6 +1316,49 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "normalizedOddsForMarket",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "normalizedOddsForMarketFulfilled",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -1527,6 +1608,24 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "_gameId",
"type": "bytes32"
},
{
"internalType": "address",
"name": "_market",
"type": "address"
}
],
"name": "setFirstNormalizedOdds",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down
18 changes: 18 additions & 0 deletions scripts/abi/IGamesOddsObtainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,24 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "_gameId",
"type": "bytes32"
},
{
"internalType": "address",
"name": "_market",
"type": "address"
}
],
"name": "setFirstNormalizedOdds",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down
33 changes: 33 additions & 0 deletions test/contracts/SportMarkets/TherundownConsumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2536,6 +2536,11 @@ contract('TheRundownConsumer', (accounts) => {

let marketAdd = await TherundownConsumerDeployed.marketPerGameId(gameFootballid1);

let normalizedFulfiled = await GamesOddsObtainerDeployed.normalizedOddsForMarketFulfilled(
marketAdd
);
assert.equal(true, normalizedFulfiled);

// check if event is emited
assert.eventEqual(tx_create.logs[tx_create.logs.length - 1], 'CreateSportsMarket', {
_marketAddress: marketAdd,
Expand All @@ -2558,6 +2563,18 @@ contract('TheRundownConsumer', (accounts) => {
}
);

normalizedFulfiled = await GamesOddsObtainerDeployed.normalizedOddsForMarketFulfilled(
marketAdd
);
assert.equal(true, normalizedFulfiled);

let normalizedFirst = await GamesOddsObtainerDeployed.normalizedOddsForMarket(marketAdd, 0);
assert.bnNotEqual(0, normalizedFirst);
let normalizedSecond = await GamesOddsObtainerDeployed.normalizedOddsForMarket(marketAdd, 1);
assert.bnNotEqual(0, normalizedSecond);
let normalizedThird = await GamesOddsObtainerDeployed.normalizedOddsForMarket(marketAdd, 2);
assert.bnNotEqual(0, normalizedThird);

let result_final = await GamesOddsObtainerDeployed.getOddsForGame(gameFootballid1);
assert.bnEqual(40000, result_final[0]);
assert.bnEqual(-12500, result_final[1]);
Expand Down Expand Up @@ -3463,6 +3480,22 @@ contract('TheRundownConsumer', (accounts) => {
await GamesOddsObtainerDeployed.currentActiveSpreadChildMarket(marketAdd)
);

let normalizedFulfiled = await GamesOddsObtainerDeployed.normalizedOddsForMarketFulfilled(
mainMarketSpreadChildMarket
);
assert.equal(true, normalizedFulfiled);

let normalizedFirst = await GamesOddsObtainerDeployed.normalizedOddsForMarket(
mainMarketSpreadChildMarket,
0
);
assert.bnNotEqual(0, normalizedFirst);
let normalizedSecond = await GamesOddsObtainerDeployed.normalizedOddsForMarket(
mainMarketSpreadChildMarket,
1
);
assert.bnNotEqual(0, normalizedSecond);

let childMarket = await SportPositionalMarketContract.at(mainMarketSpreadChildMarket);

assert.equal(false, await childMarket.canResolve());
Expand Down