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

Feature/restructure market creation incentives #62

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 Oct 17, 2020
2e5ceef
Restrict setting initial creation incentives multiple times
udkreddySomish Oct 17, 2020
ba9a4aa
Handle rewards of market creators before the contract was upgraded
udkreddySomish Oct 18, 2020
b749437
corrected gas used variable
udkreddySomish Oct 19, 2020
1cb74a0
Added buffer gas for incentive calculation
udkreddySomish Oct 19, 2020
e5379b7
Added new contract for new creation incentive calculation
udkreddySomish Oct 19, 2020
256759b
Fetch the current gas price from chainlink and updated calculations
udkreddySomish Oct 19, 2020
ee8f9a9
Removed bPLOT incentives for market creation
udkreddySomish Oct 19, 2020
f860d92
Fixed price conversion issue
udkreddySomish Oct 19, 2020
6a97208
Updated testcases
udkreddySomish Oct 19, 2020
a655293
Updated buffer gas amount, and minor fixes
udkreddySomish Oct 20, 2020
4495eec
Updated testcases for new market creation incentives
udkreddySomish Oct 20, 2020
899d465
Updated incentive formulae and added authorized address check for set…
udkreddySomish Oct 20, 2020
9a5c7ad
Added code comments
udkreddySomish Oct 20, 2020
91000c9
Corrected comments
udkreddySomish Oct 20, 2020
5cfa0d8
Increased default balance in coverage script
udkreddySomish Oct 20, 2020
a450e1f
Increased default balance in coverage script
udkreddySomish Oct 20, 2020
5b40913
Removed commented code
udkreddySomish Oct 20, 2020
afec03d
Removed unused argument
udkreddySomish Oct 21, 2020
bb552f8
Covergae: Fixed issue with high gas while running coverage
udkreddySomish Oct 21, 2020
5d22c42
Removed redundant checks and corrected indentation
udkreddySomish Oct 21, 2020
ae4a176
Covergae: Fixed issue with low balance while running coverage
udkreddySomish Oct 21, 2020
902cd4f
Updated testcases
udkreddySomish Oct 21, 2020
e45297d
Added feature to distribute percent of reward pool share for market c…
udkreddySomish Oct 30, 2020
084863a
Fixed compile issues
udkreddySomish Oct 31, 2020
41ab257
Corrected event while claimingmarket creation incentives
udkreddySomish Oct 31, 2020
64c01e1
Corrected formulae
udkreddySomish Oct 31, 2020
1f4810b
Updated plot stake required for reward pool share percent
udkreddySomish Oct 31, 2020
cb76e15
Updated plot stake required for reward pool share percent
udkreddySomish Oct 31, 2020
d8849e8
Corrected formulae for reward pool share percent
udkreddySomish Oct 31, 2020
37ce6f5
Corrected formulae
udkreddySomish Nov 1, 2020
ab5dbd0
Removed unused variables
udkreddySomish Nov 1, 2020
390af34
Added code comments
udkreddySomish Nov 1, 2020
9ddc41e
Updated MarketCreationReward eventdata
udkreddySomish Nov 2, 2020
bcf1c30
Fixed minor issues
udkreddySomish Nov 2, 2020
0600070
Updated testcases for Market creation incentives
udkreddySomish Nov 2, 2020
c56df09
Fix broken test cases
udkreddySomish Nov 2, 2020
6020c5a
Implement old Market contract instead of rewriting whole code for new…
udkreddySomish Nov 2, 2020
4e39b02
Added new function for calling market result event instead of updatin…
udkreddySomish Nov 2, 2020
95d6cb7
Added more testcases
udkreddySomish Nov 2, 2020
fe9b407
Added a market leveraged participation threshold for reward pool shar…
udkreddySomish Nov 5, 2020
c059a93
Fixed minor issue
udkreddySomish Nov 5, 2020
b685a72
Updated testcases
udkreddySomish Nov 5, 2020
bc50cd3
Fixed broken testcases in coverage run
udkreddySomish Nov 6, 2020
abd3e1b
Fixed broken testcases
udkreddySomish Nov 6, 2020
7ce214f
Fixed broken testcases
udkreddySomish Nov 6, 2020
0e74370
Fixed issue while user claiming market creation rewards
udkreddySomish Nov 8, 2020
00adefc
Added a function to get users pending market creation rewards
udkreddySomish Nov 10, 2020
e2a0e84
Added event market creator reward pool share details
udkreddySomish Nov 11, 2020
f8fbe7a
Added user address argument to check pending market creation rewards
udkreddySomish Nov 12, 2020
c21755d
Updated testcases
udkreddySomish Nov 12, 2020
cf68f6b
Added a functionality to pause market creation of particular type thr…
udkreddySomish Nov 17, 2020
81e4714
Updated comments
udkreddySomish Nov 17, 2020
90ac621
Corrected event data
udkreddySomish Nov 18, 2020
bfc5622
Fixed bug in claim reward
udkreddySomish Nov 19, 2020
78c8be6
Updated testcases
udkreddySomish Nov 19, 2020
64cb3e2
Merge branch 'feature/restructure-marketCreationIncentives' into feat…
udkreddySomish Nov 19, 2020
ccedbf1
Merge pull request #119 from plotx/feature/pauseMarketCreationOfType
udkreddySomish Nov 19, 2020
e71c3cf
Updated test cases
udkreddySomish Nov 19, 2020
4edc39b
Fixed dependencies
udkreddySomish Nov 19, 2020
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
105 changes: 105 additions & 0 deletions contracts/MarketNew.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* 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 "./Market.sol";

contract MarketNew is Market {

/**
* @dev Check if threshold reached for reward pool share percent for market creator.
* Calculate total leveraged amount staked in market value in ETH
* @param _rewardPoolShareThreshold Threshold for reward pool share
*/
function _checkIfThresholdReachedForRPS(uint256 _rewardPoolShareThreshold) internal view returns(bool) {
uint256 ethStaked;
uint256 plotStaked;
for(uint256 i = 1; i<= totalOptions;i++) {
ethStaked = ethStaked.add(optionsAvailable[i].assetLeveraged[ETH_ADDRESS]);
plotStaked = plotStaked.add(optionsAvailable[i].assetLeveraged[plotToken]);
}
( , uint riskPercentage, , ) = marketUtility.getBasicMarketDetails();
ethStaked = _calculatePercentage(riskPercentage, ethStaked, 100);
plotStaked = _calculatePercentage(riskPercentage, plotStaked, 100);
plotStaked = marketUtility.getAssetValueETH(plotToken, plotStaked);
return (plotStaked.add(ethStaked) > _rewardPoolShareThreshold);
}

/**
* @dev Calculate the result of market.
* @param _value The current price of market currency.
*/
function _postResult(uint256 _value, uint256 _roundId) internal {
require(now >= marketSettleTime(),"Time not reached");
require(_value > 0,"value should be greater than 0");
uint riskPercentage;
( , riskPercentage, , ) = marketUtility.getBasicMarketDetails();
if(predictionStatus != PredictionStatus.InDispute) {
marketSettleData.settleTime = uint64(now);
} else {
delete marketSettleData.settleTime;
}
predictionStatus = PredictionStatus.Settled;
if(_value < marketData.neutralMinValue) {
marketSettleData.WinningOption = 1;
} else if(_value > marketData.neutralMaxValue) {
marketSettleData.WinningOption = 3;
} else {
marketSettleData.WinningOption = 2;
}
(uint256 rewardPoolSharePerc, uint256 rewardPoolShareThreshold) = marketRegistry.getMarketCreatorRPoolShareParams(address(this));
bool _thresholdReached = _checkIfThresholdReachedForRPS(rewardPoolShareThreshold);
uint[] memory totalReward = new uint256[](2);
uint[] memory marketCreatorIncentive = new uint256[](2);
if(optionsAvailable[marketSettleData.WinningOption].assetStaked[ETH_ADDRESS] > 0 ||
optionsAvailable[marketSettleData.WinningOption].assetStaked[plotToken] > 0
){
for(uint i=1;i <= totalOptions;i++){
if(i!=marketSettleData.WinningOption) {
uint256 leveragedAsset = _calculatePercentage(riskPercentage, optionsAvailable[i].assetLeveraged[plotToken], 100);
totalReward[0] = totalReward[0].add(leveragedAsset);
leveragedAsset = _calculatePercentage(riskPercentage, optionsAvailable[i].assetLeveraged[ETH_ADDRESS], 100);
totalReward[1] = totalReward[1].add(leveragedAsset);
}
}
if(_thresholdReached) {
marketCreatorIncentive[0] = _calculatePercentage(rewardPoolSharePerc, totalReward[0], 10000);
marketCreatorIncentive[1] = _calculatePercentage(rewardPoolSharePerc, totalReward[1], 10000);
}
totalReward[0] = totalReward[0].sub(marketCreatorIncentive[0]);
totalReward[1] = totalReward[1].sub(marketCreatorIncentive[1]);
rewardToDistribute = totalReward;
} else {
for(uint i=1;i <= totalOptions;i++){
uint256 leveragedAsset = _calculatePercentage(riskPercentage, optionsAvailable[i].assetLeveraged[plotToken], 100);
tokenAmountToPool = tokenAmountToPool.add(leveragedAsset);
leveragedAsset = _calculatePercentage(riskPercentage, optionsAvailable[i].assetLeveraged[ETH_ADDRESS], 100);
ethAmountToPool = ethAmountToPool.add(leveragedAsset);
}
if(_thresholdReached) {
marketCreatorIncentive[0] = _calculatePercentage(rewardPoolSharePerc, tokenAmountToPool, 10000);
marketCreatorIncentive[1] = _calculatePercentage(rewardPoolSharePerc, ethAmountToPool, 10000);
tokenAmountToPool = tokenAmountToPool.sub(marketCreatorIncentive[0]);
ethAmountToPool = ethAmountToPool.sub(marketCreatorIncentive[1]);
}
}
_transferAsset(ETH_ADDRESS, address(marketRegistry), ethAmountToPool.add(ethCommissionAmount).add(marketCreatorIncentive[1]));
_transferAsset(plotToken, address(marketRegistry), tokenAmountToPool.add(plotCommissionAmount).add(marketCreatorIncentive[0]));
delete ethCommissionAmount;
delete plotCommissionAmount;
marketRegistry.callMarketResultEventAndSetIncentives(rewardToDistribute, marketCreatorIncentive, marketSettleData.WinningOption, _value, _roundId);
}
}
Loading