Skip to content

Commit

Permalink
Merge pull request #290 from thales-markets/normalized_odds_change
Browse files Browse the repository at this point in the history
refactor obtainer to use normalized odds from storage also resize contract
  • Loading branch information
danijelthales authored Mar 3, 2023
2 parents 1525b54 + 8433e4c commit 557fee4
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 122 deletions.
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

0 comments on commit 557fee4

Please sign in to comment.