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

Solidity 0.7.1 support #190

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions contracts/Events/CategoricalEvent.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.7.0;
import "../Events/Event.sol";
import "@gnosis.pm/util-contracts/contracts/Proxy.sol";

Expand All @@ -11,7 +12,6 @@ contract CategoricalEventProxy is Proxy, EventData {
/// @param outcomeCount Number of event outcomes
constructor(address proxied, address outcomeTokenMasterCopy, ERC20 _collateralToken, Oracle _oracle, uint8 outcomeCount)
Proxy(proxied)
public
{
// Validate input
require(address(_collateralToken) != address(0) && address(_oracle) != address(0) && outcomeCount >= 2);
Expand All @@ -34,9 +34,9 @@ contract CategoricalEvent is Proxied, Event {
* Public functions
*/
/// @dev Exchanges sender's winning outcome tokens for collateral tokens
/// @return Sender's winnings
/// @return winnings Sender's winnings
function redeemWinnings()
public
public override
returns (uint winnings)
{
// Winning outcome has to be set
Expand All @@ -53,7 +53,7 @@ contract CategoricalEvent is Proxied, Event {
/// @dev Calculates and returns event hash
/// @return Event hash
function getEventHash()
public
public override
view
returns (bytes32)
{
Expand Down
15 changes: 8 additions & 7 deletions contracts/Events/Event.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
pragma solidity ^0.5.0;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.7.0;
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "../Tokens/OutcomeToken.sol";
import "../Oracles/Oracle.sol";
import "@gnosis.pm/util-contracts/contracts/Proxy.sol";


contract EventData {
abstract contract EventData {

/*
* Events
Expand All @@ -28,7 +29,7 @@ contract EventData {

/// @title Event contract - Provide basic functionality required by different event types
/// @author Stefan George - <stefan@gnosis.pm>
contract Event is EventData {
abstract contract Event is EventData {

/*
* Public functions
Expand Down Expand Up @@ -82,7 +83,7 @@ contract Event is EventData {
}

/// @dev Returns outcome tokens array
/// @return Outcome tokens
/// @return OutcomeToken Outcome tokens
function getOutcomeTokens()
public
view
Expand All @@ -92,7 +93,7 @@ contract Event is EventData {
}

/// @dev Returns the amount of outcome tokens held by owner
/// @return Outcome token distribution
/// @return outcomeTokenDistribution Outcome token distribution
function getOutcomeTokenDistribution(address owner)
public
view
Expand All @@ -105,9 +106,9 @@ contract Event is EventData {

/// @dev Calculates and returns event hash
/// @return Event hash
function getEventHash() public view returns (bytes32);
function getEventHash() public view virtual returns (bytes32);

/// @dev Exchanges sender's winning outcome tokens for collateral tokens
/// @return Sender's winnings
function redeemWinnings() public returns (uint);
function redeemWinnings() public virtual returns (uint);
}
11 changes: 5 additions & 6 deletions contracts/Events/EventFactory.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.7.0;
import "../Events/CategoricalEvent.sol";
import "../Events/ScalarEvent.sol";

Expand Down Expand Up @@ -28,9 +29,7 @@ contract EventFactory {
constructor(
CategoricalEvent _categoricalEventMasterCopy,
ScalarEvent _scalarEventMasterCopy,
OutcomeToken _outcomeTokenMasterCopy
)
public
OutcomeToken _outcomeTokenMasterCopy)
{
categoricalEventMasterCopy = _categoricalEventMasterCopy;
scalarEventMasterCopy = _scalarEventMasterCopy;
Expand All @@ -41,7 +40,7 @@ contract EventFactory {
/// @param collateralToken Tokens used as collateral in exchange for outcome tokens
/// @param oracle Oracle contract used to resolve the event
/// @param outcomeCount Number of event outcomes
/// @return Event contract
/// @return eventContract Event contract
function createCategoricalEvent(
ERC20 collateralToken,
Oracle oracle,
Expand Down Expand Up @@ -70,7 +69,7 @@ contract EventFactory {
/// @param oracle Oracle contract used to resolve the event
/// @param lowerBound Lower bound for event outcome
/// @param upperBound Lower bound for event outcome
/// @return Event contract
/// @return eventContract Event contract
function createScalarEvent(
ERC20 collateralToken,
Oracle oracle,
Expand Down
10 changes: 5 additions & 5 deletions contracts/Events/ScalarEvent.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.7.0;
import "../Events/Event.sol";
import "@gnosis.pm/util-contracts/contracts/Proxy.sol";

Expand Down Expand Up @@ -35,7 +36,6 @@ contract ScalarEventProxy is Proxy, EventData, ScalarEventData {
int _upperBound
)
Proxy(proxied)
public
{
// Validate input
require(address(_collateralToken) != address(0) && address(_oracle) != address(0));
Expand Down Expand Up @@ -64,9 +64,9 @@ contract ScalarEvent is Proxied, Event, ScalarEventData {
* Public functions
*/
/// @dev Exchanges sender's winning outcome tokens for collateral tokens
/// @return Sender's winnings
/// @return winnings Sender's winnings
function redeemWinnings()
public
public override
returns (uint winnings)
{
// Winning outcome has to be set
Expand Down Expand Up @@ -98,7 +98,7 @@ contract ScalarEvent is Proxied, Event, ScalarEventData {
/// @dev Calculates and returns event hash
/// @return Event hash
function getEventHash()
public
public override
view
returns (bytes32)
{
Expand Down
29 changes: 16 additions & 13 deletions contracts/MarketMakers/LMSRMarketMaker.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma solidity ^0.5.0;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.7.0;
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/drafts/SignedSafeMath.sol";
import "../drafts/SignedSafeMath.sol";
import "@gnosis.pm/util-contracts/contracts/Fixed192x64Math.sol";
import "../MarketMakers/MarketMaker.sol";

Expand All @@ -23,9 +24,9 @@ contract LMSRMarketMaker is MarketMaker {
/// @dev Calculates the net cost for executing a given trade.
/// @param market Market contract
/// @param outcomeTokenAmounts Amounts of outcome tokens to buy from the market. If an amount is negative, represents an amount to sell to the market.
/// @return Net cost of trade. If positive, represents amount of collateral which would be paid to the market for the trade. If negative, represents amount of collateral which would be received from the market for the trade.
/// @return netCost Net cost of trade. If positive, represents amount of collateral which would be paid to the market for the trade. If negative, represents amount of collateral which would be received from the market for the trade.
function calcNetCost(Market market, int[] memory outcomeTokenAmounts)
public
public override
view
returns (int netCost)
{
Expand Down Expand Up @@ -61,9 +62,9 @@ contract LMSRMarketMaker is MarketMaker {
/// @param market Market contract
/// @param outcomeTokenIndex Index of outcome to buy
/// @param outcomeTokenCount Number of outcome tokens to buy
/// @return Cost
/// @return cost Cost
function calcCost(Market market, uint8 outcomeTokenIndex, uint outcomeTokenCount)
public
public override
view
returns (uint cost)
{
Expand Down Expand Up @@ -97,9 +98,9 @@ contract LMSRMarketMaker is MarketMaker {
/// @param market Market contract
/// @param outcomeTokenIndex Index of outcome to sell
/// @param outcomeTokenCount Number of outcome tokens to sell
/// @return Profit
/// @return profit Profit
function calcProfit(Market market, uint8 outcomeTokenIndex, uint outcomeTokenCount)
public
public override
view
returns (uint profit)
{
Expand All @@ -124,9 +125,9 @@ contract LMSRMarketMaker is MarketMaker {
/// @dev Returns marginal price of an outcome
/// @param market Market contract
/// @param outcomeTokenIndex Index of outcome to determine marginal price of
/// @return Marginal price of an outcome as a fixed point number
/// @return price Marginal price of an outcome as a fixed point number
function calcMarginalPrice(Market market, uint8 outcomeTokenIndex)
public
public override
view
returns (uint price)
{
Expand All @@ -149,7 +150,7 @@ contract LMSRMarketMaker is MarketMaker {
/// @param logN Logarithm of the number of outcomes
/// @param netOutcomeTokensSold Net outcome tokens sold by market
/// @param funding Initial funding for market
/// @return Cost level
/// @return costLevel Cost level
function calcCostLevel(int logN, int[] memory netOutcomeTokensSold, uint funding, Fixed192x64Math.EstimationMode estimationMode)
private
pure
Expand All @@ -170,7 +171,9 @@ contract LMSRMarketMaker is MarketMaker {
/// @param netOutcomeTokensSold Net outcome tokens sold by market
/// @param funding Initial funding for market
/// @param outcomeIndex Index of exponential term to extract (for use by marginal price function)
/// @return A result structure composed of the sum, the offset used, and the summand associated with the supplied index
/// @return sum A result structure composed of the sum, the offset used, and the summand associated with the supplied index
/// @return offset ditto
/// @return outcomeExpTerm ditto
function sumExpOffset(int logN, int[] memory netOutcomeTokensSold, uint funding, uint8 outcomeIndex, Fixed192x64Math.EstimationMode estimationMode)
private
pure
Expand Down Expand Up @@ -209,7 +212,7 @@ contract LMSRMarketMaker is MarketMaker {
/// number of collateral tokens (which is the same as the number of outcome tokens the
/// market created) subtracted by the quantity of that token held by the market.
/// @param market Market contract
/// @return Net outcome tokens sold by market
/// @return quantities Net outcome tokens sold by market
function getNetOutcomeTokensSold(Market market)
private
view
Expand Down
13 changes: 7 additions & 6 deletions contracts/MarketMakers/MarketMaker.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
pragma solidity ^0.5.0;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.7.0;
import "../Markets/Market.sol";


/// @title Abstract market maker contract - Functions to be implemented by market maker contracts
contract MarketMaker {
abstract contract MarketMaker {

/*
* Public functions
*/
function calcCost(Market market, uint8 outcomeTokenIndex, uint outcomeTokenCount) public view returns (uint);
function calcProfit(Market market, uint8 outcomeTokenIndex, uint outcomeTokenCount) public view returns (uint);
function calcNetCost(Market market, int[] memory outcomeTokenAmounts) public view returns (int);
function calcMarginalPrice(Market market, uint8 outcomeTokenIndex) public view returns (uint);
function calcCost(Market market, uint8 outcomeTokenIndex, uint outcomeTokenCount) public virtual view returns (uint);
function calcProfit(Market market, uint8 outcomeTokenIndex, uint outcomeTokenCount) public virtual view returns (uint);
function calcNetCost(Market market, int[] memory outcomeTokenAmounts) public virtual view returns (int);
function calcMarginalPrice(Market market, uint8 outcomeTokenIndex) public virtual view returns (uint);
}
15 changes: 7 additions & 8 deletions contracts/Markets/Campaign.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pragma solidity ^0.5.0;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.7.0;
import "../Events/Event.sol";
import "../Markets/StandardMarketFactory.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/drafts/SignedSafeMath.sol";
import "../drafts/SignedSafeMath.sol";
import "@gnosis.pm/util-contracts/contracts/Proxy.sol";

contract CampaignData {
Expand Down Expand Up @@ -53,7 +54,7 @@ contract CampaignData {
}

modifier timedTransitions() {
if (stage == Stages.AuctionStarted && deadline < now)
if (stage == Stages.AuctionStarted && deadline < block.timestamp)
stage = Stages.AuctionFailed;
_;
}
Expand All @@ -77,15 +78,14 @@ contract CampaignProxy is Proxy, CampaignData {
uint _deadline
)
Proxy(proxied)
public
{
// Validate input
require( address(_eventContract) != address(0)
&& address(_marketFactory) != address(0)
&& address(_marketMaker) != address(0)
&& _fee < FEE_RANGE
&& _funding > 0
&& now < _deadline);
&& block.timestamp < _deadline);
eventContract = _eventContract;
marketFactory = _marketFactory;
marketMaker = _marketMaker;
Expand Down Expand Up @@ -124,7 +124,7 @@ contract Campaign is Proxied, CampaignData {
}

/// @dev Withdraws refund amount
/// @return Refund amount
/// @return refundAmount Refund amount
function refund()
public
timedTransitions
Expand Down Expand Up @@ -155,7 +155,6 @@ contract Campaign is Proxied, CampaignData {
}

/// @dev Allows to withdraw fees from market contract to campaign contract
/// @return Fee amount
function closeMarket()
public
atStage(Stages.MarketCreated)
Expand All @@ -171,7 +170,7 @@ contract Campaign is Proxied, CampaignData {
}

/// @dev Allows to withdraw fees from campaign contract to contributor
/// @return Fee amount
/// @return fees Fee amount
function withdrawFees()
public
atStage(Stages.MarketClosed)
Expand Down
9 changes: 4 additions & 5 deletions contracts/Markets/CampaignFactory.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.7.0;
import "../Markets/Campaign.sol";


Expand All @@ -19,9 +20,7 @@ contract CampaignFactory {
/*
* Public functions
*/
constructor(Campaign _campaignMasterCopy)
public
{
constructor(Campaign _campaignMasterCopy) {
campaignMasterCopy = _campaignMasterCopy;
}

Expand All @@ -32,7 +31,7 @@ contract CampaignFactory {
/// @param fee Market fee
/// @param funding Initial funding for market
/// @param deadline Campaign deadline
/// @return Market contract
/// @return campaign Market contract
function createCampaign(
Event eventContract,
StandardMarketFactory marketFactory,
Expand Down
21 changes: 11 additions & 10 deletions contracts/Markets/Market.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.7.0;
import "../Events/Event.sol";
import "../MarketMakers/MarketMaker.sol";
import "@gnosis.pm/util-contracts/contracts/Proxy.sol";
Expand Down Expand Up @@ -36,16 +37,16 @@ contract MarketData {
}

/// @title Abstract market contract - Functions to be implemented by market contracts
contract Market is MarketData {
abstract contract Market is MarketData {
/*
* Public functions
*/
function fund(uint _funding) public;
function close() public;
function withdrawFees() public returns (uint);
function buy(uint8 outcomeTokenIndex, uint outcomeTokenCount, uint maxCost) public returns (uint);
function sell(uint8 outcomeTokenIndex, uint outcomeTokenCount, uint minProfit) public returns (uint);
function shortSell(uint8 outcomeTokenIndex, uint outcomeTokenCount, uint minProfit) public returns (uint);
function trade(int[] memory outcomeTokenAmounts, int costLimit) public returns (int);
function calcMarketFee(uint outcomeTokenCost) public view returns (uint);
function fund(uint _funding) public virtual;
function close() public virtual;
function withdrawFees() public virtual returns (uint);
function buy(uint8 outcomeTokenIndex, uint outcomeTokenCount, uint maxCost) public virtual returns (uint);
function sell(uint8 outcomeTokenIndex, uint outcomeTokenCount, uint minProfit) public virtual returns (uint);
function shortSell(uint8 outcomeTokenIndex, uint outcomeTokenCount, uint minProfit) public virtual returns (uint);
function trade(int[] memory outcomeTokenAmounts, int costLimit) public virtual returns (int);
function calcMarketFee(uint outcomeTokenCost) public virtual view returns (uint);
}
Loading