-
Notifications
You must be signed in to change notification settings - Fork 10
Added option to provide round id while settling the market #129
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
Open
udkreddySomish
wants to merge
9
commits into
master
Choose a base branch
from
fix-marketSettlement
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
552a00d
Added option to provide round id while settling the market
udkreddySomish 084af17
Corrected the text for scenario in testcase file 26
udkreddySomish 23c98b6
Renamed function and updated comments
udkreddySomish 4f228ad
Renamed MarketUtilityV3 to MarketUtilityV2_1
udkreddySomish e89e3df
Removed a redundant condition
udkreddySomish d7712f9
Added Require condition in settleMarket, round id should be greater t…
udkreddySomish 8ec7d9a
Updated testcases
udkreddySomish f7d80b8
added bLOTTokenV2
smrMadhan d9f475c
minor change in migrate function
smrMadhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,103 @@ | ||
/* Copyright (C) 2020 PlotX.io | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see http://www.gnu.org/licenses/ */ | ||
|
||
pragma solidity 0.5.7; | ||
|
||
import "./AllMarkets.sol"; | ||
|
||
contract AllMarketsV2 is AllMarkets { | ||
|
||
/** | ||
* @dev Changes the master address and update it's instance | ||
*/ | ||
function setMasterAddress() public { | ||
} | ||
|
||
/** | ||
* @dev Start the initial market and set initial variables. | ||
*/ | ||
function addInitialMarketTypesAndStart(address _marketCreationRewards,address _ethAddress, address _marketUtility, uint32 _marketStartTime, address _ethFeed, address _btcFeed) external { | ||
} | ||
|
||
/** | ||
* @dev Create the market. | ||
* @param _marketCurrencyIndex The index of market currency feed | ||
* @param _marketTypeIndex The time duration of market. | ||
*/ | ||
function createMarket(uint32 _marketCurrencyIndex,uint32 _marketTypeIndex) public payable { | ||
} | ||
|
||
/** | ||
* @dev Create the market and settle the prenultimate market. | ||
* @param _marketCurrencyIndex The index of market currency feed | ||
* @param _marketTypeIndex The time duration of market. | ||
* @param _roundId The chainlink round id of the penultimate market, with the round updated time closest to market settlement time | ||
*/ | ||
function createMarketAndSettle(uint32 _marketCurrencyIndex,uint32 _marketTypeIndex, uint80 _roundId) public { | ||
uint256 gasProvided = gasleft(); | ||
require(!marketCreationPaused && !marketTypeArray[_marketTypeIndex].paused); | ||
_closePreviousMarketWithRoundId( _marketTypeIndex, _marketCurrencyIndex, _roundId); | ||
marketUtility.update(); | ||
uint32 _startTime = calculateStartTimeForMarket(_marketCurrencyIndex, _marketTypeIndex); | ||
(uint64 _minValue, uint64 _maxValue) = marketUtility.calculateOptionRange(marketTypeArray[_marketTypeIndex].optionRangePerc, marketCurrencies[_marketCurrencyIndex].decimals, marketCurrencies[_marketCurrencyIndex].roundOfToNearest, marketCurrencies[_marketCurrencyIndex].marketFeed); | ||
uint64 _marketIndex = uint64(marketBasicData.length); | ||
marketBasicData.push(MarketBasicData(_marketTypeIndex,_marketCurrencyIndex,_startTime, marketTypeArray[_marketTypeIndex].predictionTime,_minValue,_maxValue)); | ||
marketDataExtended[_marketIndex].ethCommission = commissionPercGlobal.ethCommission; | ||
marketDataExtended[_marketIndex].plotCommission = commissionPercGlobal.plotCommission; | ||
(marketCreationData[_marketTypeIndex][_marketCurrencyIndex].penultimateMarket, marketCreationData[_marketTypeIndex][_marketCurrencyIndex].latestMarket) = | ||
(marketCreationData[_marketTypeIndex][_marketCurrencyIndex].latestMarket, _marketIndex); | ||
emit MarketQuestion(_marketIndex, marketCurrencies[_marketCurrencyIndex].currencyName, _marketTypeIndex, _startTime, marketTypeArray[_marketTypeIndex].predictionTime, _minValue, _maxValue); | ||
marketCreationRewards.calculateMarketCreationIncentive(msg.sender, gasProvided - gasleft(), _marketIndex); | ||
} | ||
|
||
/** | ||
* @dev Internal function to settle the previous market | ||
*/ | ||
function _closePreviousMarket(uint64 _marketTypeIndex, uint64 _marketCurrencyIndex) internal { | ||
} | ||
|
||
/** | ||
* @dev Internal function to settle the previous market | ||
*/ | ||
function _closePreviousMarketWithRoundId(uint64 _marketTypeIndex, uint64 _marketCurrencyIndex, uint80 _roundId) internal { | ||
uint64 currentMarket = marketCreationData[_marketTypeIndex][_marketCurrencyIndex].latestMarket; | ||
if(currentMarket != 0) { | ||
require(marketStatus(currentMarket) >= PredictionStatus.InSettlement); | ||
uint64 penultimateMarket = marketCreationData[_marketTypeIndex][_marketCurrencyIndex].penultimateMarket; | ||
if(penultimateMarket > 0 && now >= marketSettleTime(penultimateMarket)) { | ||
settleMarketByRoundId(penultimateMarket, _roundId); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @dev Settle the market, setting the winning option | ||
*/ | ||
function settleMarket(uint256 _marketId) public { | ||
} | ||
|
||
/** | ||
* @dev Settle the market, setting the winning option | ||
* @param _marketId Index of market. | ||
* @param _roundId Index of the nearest price feed round from which the price to be taken from. | ||
*/ | ||
function settleMarketByRoundId(uint256 _marketId, uint80 _roundId) public { | ||
if(marketStatus(_marketId) == PredictionStatus.InSettlement) { | ||
require(_roundId > 0); | ||
(uint256 _value, uint256 _roundIdUsed) = marketUtility.getSettlemetPriceByRoundId(marketCurrencies[marketBasicData[_marketId].currency].marketFeed, marketSettleTime(_marketId), _roundId); | ||
_postResult(_value, _roundIdUsed, _marketId); | ||
} | ||
} | ||
} |
This file contains hidden or 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,51 @@ | ||
/* Copyright (C) 2020 PlotX.io | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see http://www.gnu.org/licenses/ */ | ||
|
||
pragma solidity 0.5.7; | ||
|
||
import "./MarketUtilityV2.sol"; | ||
|
||
contract MarketUtilityV2_1 is MarketUtilityV2 { | ||
/** | ||
* @dev Get price of provided feed address | ||
* @param _currencyFeedAddress Feed Address of currency on which market options are based on | ||
* @return Current price of the market currency | ||
**/ | ||
function getSettlemetPriceByRoundId( | ||
address _currencyFeedAddress, | ||
uint256 _settleTime, | ||
uint80 _roundId | ||
) public view returns (uint256 latestAnswer, uint256 roundId) { | ||
uint80 roundIdToCheck; | ||
uint256 currentRoundTime; | ||
int256 currentRoundAnswer; | ||
(roundIdToCheck, currentRoundAnswer, , currentRoundTime, )= IChainLinkOracle(_currencyFeedAddress).latestRoundData(); | ||
if(roundIdToCheck == _roundId) { | ||
if(currentRoundTime <= _settleTime) { | ||
return (uint256(currentRoundAnswer), roundIdToCheck); | ||
} | ||
} else { | ||
(roundIdToCheck, currentRoundAnswer, , currentRoundTime, )= IChainLinkOracle(_currencyFeedAddress).getRoundData(_roundId + 1); | ||
require(currentRoundTime > _settleTime); | ||
roundIdToCheck = _roundId + 1; | ||
maxsam4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
while(currentRoundTime > _settleTime) { | ||
roundIdToCheck--; | ||
maxsam4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(roundIdToCheck, currentRoundAnswer, , currentRoundTime, )= IChainLinkOracle(_currencyFeedAddress).getRoundData(roundIdToCheck); | ||
} | ||
return | ||
(uint256(currentRoundAnswer), roundIdToCheck); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.