-
Notifications
You must be signed in to change notification settings - Fork 11
Feature/restructure market creation incentives #62
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
60
commits into
master
Choose a base branch
from
feature/restructure-marketCreationIncentives
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 18 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
9b32ef2
Distribute rewards based on gas price and bonus bPLOT
udkreddySomish 2e5ceef
Restrict setting initial creation incentives multiple times
udkreddySomish ba9a4aa
Handle rewards of market creators before the contract was upgraded
udkreddySomish b749437
corrected gas used variable
udkreddySomish 1cb74a0
Added buffer gas for incentive calculation
udkreddySomish e5379b7
Added new contract for new creation incentive calculation
udkreddySomish 256759b
Fetch the current gas price from chainlink and updated calculations
udkreddySomish ee8f9a9
Removed bPLOT incentives for market creation
udkreddySomish f860d92
Fixed price conversion issue
udkreddySomish 6a97208
Updated testcases
udkreddySomish a655293
Updated buffer gas amount, and minor fixes
udkreddySomish 4495eec
Updated testcases for new market creation incentives
udkreddySomish 899d465
Updated incentive formulae and added authorized address check for set…
udkreddySomish 9a5c7ad
Added code comments
udkreddySomish 91000c9
Corrected comments
udkreddySomish 5cfa0d8
Increased default balance in coverage script
udkreddySomish a450e1f
Increased default balance in coverage script
udkreddySomish 5b40913
Removed commented code
udkreddySomish afec03d
Removed unused argument
udkreddySomish bb552f8
Covergae: Fixed issue with high gas while running coverage
udkreddySomish 5d22c42
Removed redundant checks and corrected indentation
udkreddySomish ae4a176
Covergae: Fixed issue with low balance while running coverage
udkreddySomish 902cd4f
Updated testcases
udkreddySomish e45297d
Added feature to distribute percent of reward pool share for market c…
udkreddySomish 084863a
Fixed compile issues
udkreddySomish 41ab257
Corrected event while claimingmarket creation incentives
udkreddySomish 64c01e1
Corrected formulae
udkreddySomish 1f4810b
Updated plot stake required for reward pool share percent
udkreddySomish cb76e15
Updated plot stake required for reward pool share percent
udkreddySomish d8849e8
Corrected formulae for reward pool share percent
udkreddySomish 37ce6f5
Corrected formulae
udkreddySomish ab5dbd0
Removed unused variables
udkreddySomish 390af34
Added code comments
udkreddySomish 9ddc41e
Updated MarketCreationReward eventdata
udkreddySomish bcf1c30
Fixed minor issues
udkreddySomish 0600070
Updated testcases for Market creation incentives
udkreddySomish c56df09
Fix broken test cases
udkreddySomish 6020c5a
Implement old Market contract instead of rewriting whole code for new…
udkreddySomish 4e39b02
Added new function for calling market result event instead of updatin…
udkreddySomish 95d6cb7
Added more testcases
udkreddySomish fe9b407
Added a market leveraged participation threshold for reward pool shar…
udkreddySomish c059a93
Fixed minor issue
udkreddySomish b685a72
Updated testcases
udkreddySomish bc50cd3
Fixed broken testcases in coverage run
udkreddySomish abd3e1b
Fixed broken testcases
udkreddySomish 7ce214f
Fixed broken testcases
udkreddySomish 0e74370
Fixed issue while user claiming market creation rewards
udkreddySomish 00adefc
Added a function to get users pending market creation rewards
udkreddySomish e2a0e84
Added event market creator reward pool share details
udkreddySomish f8fbe7a
Added user address argument to check pending market creation rewards
udkreddySomish c21755d
Updated testcases
udkreddySomish cf68f6b
Added a functionality to pause market creation of particular type thr…
udkreddySomish 81e4714
Updated comments
udkreddySomish 90ac621
Corrected event data
udkreddySomish bfc5622
Fixed bug in claim reward
udkreddySomish 78c8be6
Updated testcases
udkreddySomish 64cb3e2
Merge branch 'feature/restructure-marketCreationIncentives' into feat…
udkreddySomish ccedbf1
Merge pull request #119 from plotx/feature/pauseMarketCreationOfType
udkreddySomish e71c3cf
Updated test cases
udkreddySomish 4edc39b
Fixed dependencies
udkreddySomish 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
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,140 @@ | ||
| /* 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 "./MarketRegistry.sol"; | ||
| import "./interfaces/IChainLinkOracle.sol"; | ||
| import "./external/openzeppelin-solidity/math/Math.sol"; | ||
|
|
||
| contract MarketRegistryNew is MarketRegistry { | ||
|
|
||
| uint256 internal maxGasPrice; | ||
| IChainLinkOracle public clGasPriceAggregator; | ||
|
|
||
| mapping(address => uint256) userIncentives; | ||
| event MarketCreationReward(address indexed createdBy, uint256 plotIncentive, uint256 gasUsed, uint256 gasCost, uint256 gasPriceConsidered, uint256 gasPriceGiven, uint256 maxGasCap); | ||
| event ClaimedMarketCreationReward(address indexed user, uint256 plotIncentive); | ||
|
|
||
| /** | ||
| * @dev Set initial market creation incentive params. | ||
| */ | ||
| function setGasPriceAggAndMaxGas(address _clGasPriceAggregator) external { | ||
| require(address(clGasPriceAggregator) == address(0)); | ||
| require(msg.sender == marketInitiater); | ||
| clGasPriceAggregator = IChainLinkOracle(_clGasPriceAggregator); | ||
| maxGasPrice = 100 * 10**9; | ||
| } | ||
|
|
||
| /** | ||
| * @dev Creates the new market | ||
| * @param _marketType The type of the market. | ||
| * @param _marketCurrencyIndex the index of market currency. | ||
| */ | ||
| function createMarket(uint256 _marketType, uint256 _marketCurrencyIndex) public payable{ | ||
| uint256 gasProvided = gasleft(); | ||
| address penultimateMarket = marketCreationData[_marketType][_marketCurrencyIndex].penultimateMarket; | ||
| if(penultimateMarket != address(0)) { | ||
| IMarket(penultimateMarket).settleMarket(); | ||
| } | ||
| if(marketCreationData[_marketType][_marketCurrencyIndex].marketAddress != address(0)) { | ||
| (,,,,,,,, uint _status) = getMarketDetails(marketCreationData[_marketType][_marketCurrencyIndex].marketAddress); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making |
||
| require(_status >= uint(IMarket.PredictionStatus.InSettlement)); | ||
| } | ||
| (uint8 _roundOfToNearest, bytes32 _currencyName, address _priceFeed) = IMarket(marketCurrencies[_marketCurrencyIndex].marketImplementation).getMarketFeedData(); | ||
| marketUtility.update(); | ||
| uint64 _marketStartTime = calculateStartTimeForMarket(_marketType, _marketCurrencyIndex); | ||
| uint64 _optionRangePerc = marketTypes[_marketType].optionRangePerc; | ||
| uint currentPrice = marketUtility.getAssetPriceUSD(_priceFeed); | ||
| _optionRangePerc = uint64(currentPrice.mul(_optionRangePerc.div(2)).div(10000)); | ||
|
maxsam4 marked this conversation as resolved.
|
||
| uint64 _decimals = marketCurrencies[_marketCurrencyIndex].decimals; | ||
| uint64 _minValue = uint64((ceil(currentPrice.sub(_optionRangePerc).div(_roundOfToNearest), 10**_decimals)).mul(_roundOfToNearest)); | ||
| uint64 _maxValue = uint64((ceil(currentPrice.add(_optionRangePerc).div(_roundOfToNearest), 10**_decimals)).mul(_roundOfToNearest)); | ||
|
maxsam4 marked this conversation as resolved.
|
||
| _createMarket(_marketType, _marketCurrencyIndex, _minValue, _maxValue, _marketStartTime, _currencyName); | ||
| uint256 gasUsed = gasProvided - gasleft(); | ||
| _calculateIncentive(gasUsed, _marketStartTime); | ||
| } | ||
|
|
||
| /** | ||
| * @dev internal function to calculate user incentive for market creation | ||
| */ | ||
| function _calculateIncentive(uint256 gasUsed, uint256 _marketStartTime) internal{ | ||
| //Adding buffer gas for below calculations | ||
| gasUsed = gasUsed + 38500; | ||
| uint256 gasPrice = _checkGasPrice(); | ||
| uint256 gasCost = gasUsed.mul(gasPrice); | ||
| (, uint256 incentive) = marketUtility.getValueAndMultiplierParameters(ETH_ADDRESS, gasCost); | ||
| userIncentives[msg.sender] = userIncentives[msg.sender].add(incentive); | ||
| emit MarketCreationReward(msg.sender, incentive, gasUsed, gasCost, gasPrice, tx.gasprice, maxGasPrice); | ||
| } | ||
|
|
||
| /** | ||
| * @dev internal function to calculate gas price for market creation incentives | ||
| */ | ||
| function _checkGasPrice() internal view returns(uint256) { | ||
| uint fastGas = uint(clGasPriceAggregator.latestAnswer()); | ||
| uint fastGasWithMaxDeviation = fastGas.mul(125).div(100); | ||
| return Math.min(Math.min(tx.gasprice,fastGasWithMaxDeviation), maxGasPrice); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @dev function to reward user for initiating market creation calls as per the new incetive calculations | ||
| */ | ||
| function claimCreationRewardV2() external { | ||
| uint256 pendingPLOTReward = userIncentives[msg.sender]; | ||
| require(pendingPLOTReward > 0); | ||
| require(plotToken.balanceOf(address(this)) > pendingPLOTReward); | ||
|
maxsam4 marked this conversation as resolved.
Outdated
|
||
| _transferAsset(address(plotToken), msg.sender, pendingPLOTReward); | ||
| emit ClaimedMarketCreationReward(msg.sender, pendingPLOTReward); | ||
| delete userIncentives[msg.sender]; | ||
|
maxsam4 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| /** | ||
| * @dev function to update address parameters of market | ||
| */ | ||
| function updateConfigAddressParameters(bytes8 code, address payable value) external onlyAuthorizedToGovern { | ||
| if(code == "GASAGG") { // Incentive to be distributed to user for market creation | ||
| clGasPriceAggregator = IChainLinkOracle(value); | ||
| } else { | ||
| marketUtility.updateAddressParameters(code, value); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @dev function to update integer parameters of market | ||
| */ | ||
| function updateUintParameters(bytes8 code, uint256 value) external onlyAuthorizedToGovern { | ||
| if(code == "MCRINC") { // Incentive to be distributed to user for market creation | ||
| marketCreationIncentive = value; | ||
| } else if(code == "MAXGAS") { // Maximum gas upto which is considered while calculating market creation incentives | ||
| maxGasPrice = value; | ||
| } else { | ||
| marketUtility.updateUintParameters(code, value); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @dev Get uint config parameters | ||
| */ | ||
| function getUintParameters(bytes8 code) external view returns(bytes8 codeVal, uint256 value) { | ||
| codeVal = code; | ||
| if(code == "MCRINC") { | ||
| value = marketCreationIncentive; | ||
| } else if(code == "MAXGAS") { | ||
| value = maxGasPrice; | ||
| } | ||
| } | ||
|
|
||
| } | ||
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
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,76 @@ | ||
| pragma solidity 0.5.7; | ||
|
|
||
| import "../interfaces/IChainLinkOracle.sol"; | ||
| contract MockChainLinkGasPriceAgg is IChainLinkOracle{ | ||
|
|
||
| int256 latestAns = 45000000000; | ||
| uint256 updatedAt = now; | ||
|
|
||
| struct RoundData { | ||
| uint80 roundId; | ||
| int256 answer; | ||
| uint256 startedAt; | ||
| uint256 updatedAt; | ||
| uint80 answeredInRound; | ||
| } | ||
|
|
||
| mapping(uint80 => RoundData) public roundData; | ||
| uint80 public currentRound; | ||
|
|
||
| constructor() public { | ||
| currentRound = 0; | ||
| roundData[0] = RoundData(uint80(0),latestAns, updatedAt, updatedAt, uint80(0)); | ||
| } | ||
|
|
||
| function decimals() external view returns (uint8) { | ||
| return uint8(8); | ||
| } | ||
| /** | ||
| * @dev Gets the latest answer of chainLink oracle. | ||
| * @return int256 representing the latest answer of chainLink oracle. | ||
| */ | ||
| function latestAnswer() external view returns (int256) | ||
| { | ||
| return roundData[currentRound].answer; | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * @dev Set the latest answer of chainLink oracle. | ||
| * @param _latestAnswer The latest anser of chainLink oracle. | ||
| */ | ||
| function setLatestAnswer(int256 _latestAnswer) public | ||
| { | ||
| currentRound = currentRound + uint80(1); | ||
| roundData[currentRound] = RoundData(currentRound,_latestAnswer, now, now, currentRound); | ||
| } | ||
|
|
||
| function getRoundData(uint80 _roundId) | ||
| external | ||
|
maxsam4 marked this conversation as resolved.
|
||
| view | ||
| returns ( | ||
| uint80 roundId, | ||
| int256 answer, | ||
| uint256 startedAt, | ||
| uint256 updatedAt, | ||
| uint80 answeredInRound | ||
| ) { | ||
| return (roundData[_roundId].roundId, roundData[_roundId].answer, roundData[_roundId].startedAt, | ||
| roundData[_roundId].updatedAt,roundData[_roundId].answeredInRound); | ||
| } | ||
|
|
||
| function latestRoundData() | ||
| external | ||
| view | ||
| returns ( | ||
| uint80 roundId, | ||
| int256 answer, | ||
| uint256 startedAt, | ||
| uint256 updatedAt, | ||
| uint80 answeredInRound | ||
| ) { | ||
| return (roundData[currentRound].roundId, roundData[currentRound].answer, roundData[currentRound].startedAt, | ||
| roundData[currentRound].updatedAt,roundData[currentRound].answeredInRound); | ||
| } | ||
|
|
||
| } | ||
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
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.