Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4d79ac4
Changes option pricing formula, added check for min liquidity provide…
PremSOMISH May 14, 2021
cf7d34b
Added check for valid market in getOptionPrice()
PremSOMISH May 20, 2021
e2d7a1b
Added test cases for option pricing in acyclic markets
PremSOMISH May 20, 2021
f06f466
Added more test cases fpr covering branches in acyclic test cases
PremSOMISH May 21, 2021
37524e3
initializing nowTime in test cases
PremSOMISH May 21, 2021
d2e58c5
Fixed one test case for acyclic markets
PremSOMISH May 22, 2021
2817deb
Added function to predict on behalf of
udkreddySomish May 24, 2021
66b3099
Added an external contract to swap any token and predict with plot
udkreddySomish May 24, 2021
548e76c
Updated swap functionality
udkreddySomish May 25, 2021
706d66e
Fixed swap eth to token
udkreddySomish May 25, 2021
62a5802
Added auth checks
udkreddySomish May 26, 2021
a49beaa
Updated code comments
udkreddySomish May 26, 2021
b8f2ddc
Updated comments
udkreddySomish May 26, 2021
4f83d67
Fixed approval for prediction after swap
udkreddySomish May 27, 2021
1a12453
Updated migrations and added testcases for Swap and predict
udkreddySomish May 27, 2021
8bb5de0
Added more checks and refactored swapAndPlacePrediction
udkreddySomish May 28, 2021
7b5daba
Wrap transfer in require condition
udkreddySomish May 28, 2021
c4ae344
Fixed internal audit issues
udkreddySomish May 28, 2021
5ca9b3f
Added null address checks
udkreddySomish May 28, 2021
df99ace
Fixed broken testcases
udkreddySomish May 28, 2021
2d60785
Added test cases for ETH based predictions
udkreddySomish May 28, 2021
c59cd2b
Updated comments
udkreddySomish May 28, 2021
30dc703
Updated testcases
udkreddySomish May 28, 2021
5298297
Updated badge
udkreddySomish May 29, 2021
10c7920
Added function to withdraw any assets left in contract
udkreddySomish May 31, 2021
00d47e2
Removed function to withdraw any left over assets
udkreddySomish May 31, 2021
9a61df9
Updated testcases
udkreddySomish May 31, 2021
06e9cf4
Updated testcases
udkreddySomish May 31, 2021
f908547
Removed harcoding
udkreddySomish May 31, 2021
3231417
Removed slippage
udkreddySomish May 31, 2021
82ac455
Read min output amount
udkreddySomish May 31, 2021
248803e
Minor fix
udkreddySomish May 31, 2021
caf6e51
Removed stack too deep erro
udkreddySomish May 31, 2021
49df691
Fixed broken testcases
udkreddySomish May 31, 2021
5f7268d
Added null address check
udkreddySomish May 31, 2021
1e66df4
Allow only whitelisted tokens for swap and place prediction
udkreddySomish May 31, 2021
2a3cf1c
Fix broken testcases
udkreddySomish May 31, 2021
e6942e7
Added token whitelist testcases
udkreddySomish Jun 1, 2021
d622e70
Merge pull request #12 from plotx/feature/predictFor
udkreddySomish Jun 1, 2021
6168534
Update README.md
udkreddySomish Jun 1, 2021
1da7aaf
Delete coverage.zip
PremSOMISH Jun 1, 2021
f6fd8fb
Merge pull request #14 from plotx/feature/predictFor
udkreddySomish Jun 2, 2021
faf60f9
Added swapAndPredict testcases for acyclic markets
udkreddySomish Jun 2, 2021
e33a947
Added function to allow user creat acyclic markets for one time
udkreddySomish Jun 2, 2021
32309ea
Updated variable name
udkreddySomish Jun 2, 2021
e3c61ef
Merge pull request #15 from plotx/Acyclic-tempMarketCreator
udkreddySomish Jun 3, 2021
eac4753
Merge pull request #13 from plotx/Acyclic-FormulaChanges
udkreddySomish Jun 3, 2021
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
53 changes: 27 additions & 26 deletions contracts/AcyclicMarkets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ contract AcyclicMarkets is IAuth, NativeMetaTransaction {
mapping(address => uint256) public marketCreationReward;
mapping (address => uint256) public relayerFeeEarned;
mapping(address => bool) public whiteListedMarketCreators;
mapping(address => bool) public oneTimeMarketCreator;

mapping(address => mapping(uint256 => bool)) public multiplierApplied;

Expand All @@ -81,6 +82,7 @@ contract AcyclicMarkets is IAuth, NativeMetaTransaction {
uint internal predictionDecimalMultiplier;
uint internal minPredictionAmount;
uint internal maxPredictionAmount;
uint64 internal minLiquidityByCreator;

modifier onlyAllMarkets {
require(msg.sender == address(allMarkets));
Expand Down Expand Up @@ -114,9 +116,19 @@ contract AcyclicMarkets is IAuth, NativeMetaTransaction {
maxPredictionAmount = 100000 ether; // Need to be updated
minTimePassed = 10 hours; // need to set
predictionDecimalMultiplier = 10;
minLiquidityByCreator = 100 * 10**8;
_initializeEIP712("AC");
}

/**
* @dev Whitelist a Market Creator temporarily for one market
* @param _userAdd Address of the creator
*/
function addTemporaryMarketCreator(address _userAdd) external onlyAuthorized {
require(_userAdd != address(0));
oneTimeMarketCreator[_userAdd] = true;
}

/**
* @dev Whitelisting Market Creators
* @param _userAdd Address of the creator
Expand Down Expand Up @@ -175,7 +187,9 @@ contract AcyclicMarkets is IAuth, NativeMetaTransaction {
function createMarket(string calldata _questionDetails, uint64[] calldata _optionRanges, uint32[] calldata _marketTimes,bytes8 _marketType, bytes32 _marketCurr, uint64 _marketInitialLiquidity) external {
require(!paused);
// address _marketCreator = _msgSender();
require(whiteListedMarketCreators[_msgSender()]);
require(whiteListedMarketCreators[_msgSender()] || oneTimeMarketCreator[_msgSender()]);
delete oneTimeMarketCreator[_msgSender()];
require(_marketInitialLiquidity >= minLiquidityByCreator);
uint32[] memory _timesArray = new uint32[](_marketTimes.length+1);
_timesArray[0] = uint32(now);
_timesArray[1] = _marketTimes[0].sub(uint32(now));
Expand Down Expand Up @@ -370,41 +384,20 @@ contract AcyclicMarkets is IAuth, NativeMetaTransaction {
* @return option price
**/
function getOptionPrice(uint _marketId, uint256 _prediction) public view returns(uint64) {
require(marketData[_marketId].marketCreator != address(0),"Invalid Market id");
uint optionLen = allMarkets.getTotalOptions(_marketId);
(uint[] memory _optionPricingParams, uint32 _startTime) = allMarkets.getMarketOptionPricingParams(_marketId,_prediction);
(uint[] memory _optionPricingParams,) = allMarkets.getMarketOptionPricingParams(_marketId,_prediction);
PricingData storage _marketPricingData = marketData[_marketId].pricingData;
(,,uint _predictionTime,,) = allMarkets.getMarketData(_marketId);
uint stakingFactorConst;
uint optionPrice;

// Checking if current stake in market reached minimum stake required for considering staking factor.
if(_optionPricingParams[1] < _marketPricingData.stakingFactorMinStake)
if(_optionPricingParams[1] < _marketPricingData.stakingFactorMinStake || _optionPricingParams[0] == 0)
{

return uint64(uint(100000).div(optionLen));

} else {
// 10000 / staking weightage
stakingFactorConst = uint(10000).div(_marketPricingData.stakingFactorWeightage);
// (stakingFactorConst x Amount staked in option x 10^18) / Total staked in market --- (1)
optionPrice = (stakingFactorConst.mul(_optionPricingParams[0]).mul(10**18).div(_optionPricingParams[1]));
return uint64(uint(100000).mul(_optionPricingParams[0]).div(_optionPricingParams[1]));
}
uint timeElapsedFactor = uint(now).sub(_startTime);
// max(timeElapsed, minTimePassed)
if(timeElapsedFactor < _marketPricingData.minTimePassed) {
timeElapsedFactor = _marketPricingData.minTimePassed;
}

// (Time Elapsed x 10000) / (Time Weightage)
timeElapsedFactor = timeElapsedFactor.mul(10000).div(_marketPricingData.timeWeightage);

// (1) + ( timeFactor x 10^18 / Total Prediction Time) -- (2)
optionPrice = optionPrice.add((timeElapsedFactor).mul(10**18).div(_predictionTime));
// (2) / ((stakingFactorConst x 10^13) + timeFactor x 10^13 / Total Prediction Time)
optionPrice = optionPrice.div(stakingFactorConst.mul(10**13).add(optionLen.mul(timeElapsedFactor).mul(10**13).div(_predictionTime)));

// option price for `_prediction` in 10^5 format
return uint64(optionPrice);

}

Expand Down Expand Up @@ -448,6 +441,10 @@ contract AcyclicMarkets is IAuth, NativeMetaTransaction {
value = marketFeeParams.refereeFeePercent;
} else if(code == "MCF") { // Market Creator fee percent in Cummulative fee
value = marketFeeParams.marketCreatorFeePercent;
} else if(code == "MTP") {
value = minTimePassed;
} else if(code == "MLC") {
value = minLiquidityByCreator;
}
}

Expand All @@ -472,6 +469,10 @@ contract AcyclicMarkets is IAuth, NativeMetaTransaction {
uint32 _val = uint32(value);
require(_val == value); // to avoid overflow while type casting
minTimePassed = _val;
} else if(code == "MLC") {
uint64 _val = uint64(value);
require(_val == value); // to avoid overflow while type casting
minLiquidityByCreator = _val;
} else {
MarketFeeParams storage _marketFeeParams = marketFeeParams;
require(value < 10000);
Expand Down
77 changes: 77 additions & 0 deletions contracts/AllPlotMarkets_2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* Copyright (C) 2021 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 "./AllPlotMarkets.sol";

contract AllPlotMarkets_2 is AllPlotMarkets {

mapping(address => bool) public authToProxyPrediction;

/**
* @dev Function to add an authorized address to place proxy predictions
* @param _proxyAddress Address to whitelist
*/
function addAuthorizedProxyPreditictor(address _proxyAddress) external onlyAuthorized {
require(_proxyAddress != address(0));
authToProxyPrediction[_proxyAddress] = true;
}

/**
* @dev Function to deposit prediction token for participation in markets
* @param _amount Amount of prediction token to deposit
*/
function _depositFor(uint _amount, address _msgSenderAddress, address _depositForAddress) internal {
_transferTokenFrom(predictionToken, _msgSenderAddress, address(this), _amount);
UserData storage _userData = userData[_depositForAddress];
_userData.unusedBalance = _userData.unusedBalance.add(_amount);
emit Deposited(_depositForAddress, _amount, now);
}

/**
* @dev Deposit and Place prediction on behalf of another address
* @param _predictFor Address of user, to place prediction for
* @param _marketId Index of the market
* @param _tokenDeposit prediction token amount to deposit
* @param _asset The asset used by user during prediction whether it is prediction token address or in Bonus token.
* @param _prediction The option on which user placed prediction.
* @param _plotPredictionAmount The PLOT amount staked by user at the time of prediction.
* @param _bPLOTPredictionAmount The BPLOT amount staked by user at the time of prediction.
* _tokenDeposit should be passed with 18 decimals
* _plotPredictionAmount and _bPLOTPredictionAmount should be passed with 8 decimals, reduced it to 8 decimals to reduce the storage space of prediction data
*/
function depositAndPredictFor(address _predictFor, uint _tokenDeposit, uint _marketId, address _asset, uint256 _prediction, uint64 _plotPredictionAmount, uint64 _bPLOTPredictionAmount) external {
require(_predictFor != address(0));
address payable _msgSenderAddress = _msgSender();
require(authToProxyPrediction[_msgSenderAddress]);
uint64 _predictionStake = _plotPredictionAmount.add(_bPLOTPredictionAmount);
//Can deposit only if prediction stake amount contains plot
if(_plotPredictionAmount > 0 && _tokenDeposit > 0) {
_depositFor(_tokenDeposit, _msgSenderAddress, _predictFor);
}
if(_bPLOTPredictionAmount > 0) {
UserData storage _userData = userData[_predictFor];
require(!_userData.userMarketData[_marketId].predictedWithBlot);
_userData.userMarketData[_marketId].predictedWithBlot = true;
uint256 _amount = (10**predictionDecimalMultiplier).mul(_bPLOTPredictionAmount);
bPLOTInstance.convertToPLOT(_predictFor, address(this), _amount);
_userData.unusedBalance = _userData.unusedBalance.add(_amount);
}
require(_asset == plotToken);
_placePrediction(_marketId, _predictFor, _asset, _predictionStake, _prediction);
}

}
Loading