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

Update to Solidity v0.5 and Truffle v5.0 - 'v1' branch #170

Merged
merged 2 commits into from
Jul 22, 2019
Merged
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
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: node_js
node_js:
- 'node'
- '8'
- '7'
- '10'
- '9'
before_install:
- npm install -g npm codecov greenkeeper-lockfile@1
before_script: greenkeeper-lockfile-update
Expand All @@ -16,5 +16,5 @@ deploy:
on:
all_branches: true
tags: true
node: '8'
node: '10'
repo: gnosis/pm-contracts
6 changes: 3 additions & 3 deletions contracts/Events/CategoricalEvent.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;
import "../Events/Event.sol";
import "@gnosis.pm/util-contracts/contracts/Proxy.sol";

Expand All @@ -14,12 +14,12 @@ contract CategoricalEventProxy is Proxy, EventData {
public
{
// Validate input
require(address(_collateralToken) != 0 && address(_oracle) != 0 && outcomeCount >= 2);
require(address(_collateralToken) != address(0) && address(_oracle) != address(0) && outcomeCount >= 2);
collateralToken = _collateralToken;
oracle = _oracle;
// Create an outcome token for each outcome
for (uint8 i = 0; i < outcomeCount; i++) {
OutcomeToken outcomeToken = OutcomeToken(new OutcomeTokenProxy(outcomeTokenMasterCopy));
OutcomeToken outcomeToken = OutcomeToken(address(new OutcomeTokenProxy(outcomeTokenMasterCopy)));
outcomeTokens.push(outcomeToken);
emit OutcomeTokenCreation(outcomeToken, i);
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/Events/Event.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "../Tokens/OutcomeToken.sol";
import "../Oracles/Oracle.sol";
Expand Down Expand Up @@ -39,7 +39,7 @@ contract Event is EventData {
public
{
// Transfer collateral tokens to events contract
require(collateralToken.transferFrom(msg.sender, this, collateralTokenCount));
require(collateralToken.transferFrom(msg.sender, address(this), collateralTokenCount));
// Issue new outcome tokens to sender
for (uint8 i = 0; i < outcomeTokens.length; i++)
outcomeTokens[i].issue(msg.sender, collateralTokenCount);
Expand Down Expand Up @@ -86,7 +86,7 @@ contract Event is EventData {
function getOutcomeTokens()
public
view
returns (OutcomeToken[])
returns (OutcomeToken[] memory)
{
return outcomeTokens;
}
Expand All @@ -96,7 +96,7 @@ contract Event is EventData {
function getOutcomeTokenDistribution(address owner)
public
view
returns (uint[] outcomeTokenDistribution)
returns (uint[] memory outcomeTokenDistribution)
{
outcomeTokenDistribution = new uint[](outcomeTokens.length);
for (uint8 i = 0; i < outcomeTokenDistribution.length; i++)
Expand Down
22 changes: 11 additions & 11 deletions contracts/Events/EventFactory.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;
import "../Events/CategoricalEvent.sol";
import "../Events/ScalarEvent.sol";

Expand Down Expand Up @@ -52,15 +52,15 @@ contract EventFactory {
{
bytes32 eventHash = keccak256(abi.encodePacked(collateralToken, oracle, outcomeCount));
// Event should not exist yet
require(address(categoricalEvents[eventHash]) == 0);
require(address(categoricalEvents[eventHash]) == address(0));
// Create event
eventContract = CategoricalEvent(new CategoricalEventProxy(
categoricalEventMasterCopy,
outcomeTokenMasterCopy,
eventContract = CategoricalEvent(address(new CategoricalEventProxy(
address(categoricalEventMasterCopy),
address(outcomeTokenMasterCopy),
collateralToken,
oracle,
outcomeCount
));
)));
categoricalEvents[eventHash] = eventContract;
emit CategoricalEventCreation(msg.sender, eventContract, collateralToken, oracle, outcomeCount);
}
Expand All @@ -82,16 +82,16 @@ contract EventFactory {
{
bytes32 eventHash = keccak256(abi.encodePacked(collateralToken, oracle, lowerBound, upperBound));
// Event should not exist yet
require(address(scalarEvents[eventHash]) == 0);
require(address(scalarEvents[eventHash]) == address(0));
// Create event
eventContract = ScalarEvent(new ScalarEventProxy(
scalarEventMasterCopy,
outcomeTokenMasterCopy,
eventContract = ScalarEvent(address(new ScalarEventProxy(
address(scalarEventMasterCopy),
address(outcomeTokenMasterCopy),
collateralToken,
oracle,
lowerBound,
upperBound
));
)));
scalarEvents[eventHash] = eventContract;
emit ScalarEventCreation(msg.sender, eventContract, collateralToken, oracle, lowerBound, upperBound);
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/Events/ScalarEvent.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;
import "../Events/Event.sol";
import "@gnosis.pm/util-contracts/contracts/Proxy.sol";

Expand Down Expand Up @@ -38,12 +38,12 @@ contract ScalarEventProxy is Proxy, EventData, ScalarEventData {
public
{
// Validate input
require(address(_collateralToken) != 0 && address(_oracle) != 0);
require(address(_collateralToken) != address(0) && address(_oracle) != address(0));
collateralToken = _collateralToken;
oracle = _oracle;
// Create an outcome token for each outcome
for (uint8 i = 0; i < 2; i++) {
OutcomeToken outcomeToken = OutcomeToken(new OutcomeTokenProxy(outcomeTokenMasterCopy));
OutcomeToken outcomeToken = OutcomeToken(address(new OutcomeTokenProxy(outcomeTokenMasterCopy)));
outcomeTokens.push(outcomeToken);
emit OutcomeTokenCreation(outcomeToken, i);
}
Expand Down
14 changes: 8 additions & 6 deletions contracts/MarketMakers/LMSRMarketMaker.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/drafts/SignedSafeMath.sol";
import "@gnosis.pm/util-contracts/contracts/Fixed192x64Math.sol";
import "../MarketMakers/MarketMaker.sol";


/// @title LMSR market maker contract - Calculates share prices based on share distribution and initial funding
/// @author Alan Lu - <[email protected]>
contract LMSRMarketMaker is MarketMaker {
using SafeMath for *;
using SignedSafeMath for int;
using SafeMath for uint;

/*
* Constants
Expand All @@ -22,7 +24,7 @@ contract LMSRMarketMaker is MarketMaker {
/// @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.
function calcNetCost(Market market, int[] outcomeTokenAmounts)
function calcNetCost(Market market, int[] memory outcomeTokenAmounts)
public
view
returns (int netCost)
Expand Down Expand Up @@ -148,7 +150,7 @@ contract LMSRMarketMaker is MarketMaker {
/// @param netOutcomeTokensSold Net outcome tokens sold by market
/// @param funding Initial funding for market
/// @return Cost level
function calcCostLevel(int logN, int[] netOutcomeTokensSold, uint funding, Fixed192x64Math.EstimationMode estimationMode)
function calcCostLevel(int logN, int[] memory netOutcomeTokensSold, uint funding, Fixed192x64Math.EstimationMode estimationMode)
private
pure
returns(int costLevel)
Expand All @@ -169,7 +171,7 @@ contract LMSRMarketMaker is MarketMaker {
/// @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
function sumExpOffset(int logN, int[] netOutcomeTokensSold, uint funding, uint8 outcomeIndex, Fixed192x64Math.EstimationMode estimationMode)
function sumExpOffset(int logN, int[] memory netOutcomeTokensSold, uint funding, uint8 outcomeIndex, Fixed192x64Math.EstimationMode estimationMode)
private
pure
returns (uint sum, int offset, uint outcomeExpTerm)
Expand Down Expand Up @@ -211,7 +213,7 @@ contract LMSRMarketMaker is MarketMaker {
function getNetOutcomeTokensSold(Market market)
private
view
returns (int[] quantities)
returns (int[] memory quantities)
{
quantities = new int[](market.eventContract().getOutcomeCount());
for (uint8 i = 0; i < quantities.length; i++)
Expand Down
4 changes: 2 additions & 2 deletions contracts/MarketMakers/MarketMaker.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;
import "../Markets/Market.sol";


Expand All @@ -10,6 +10,6 @@ contract MarketMaker {
*/
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[] outcomeTokenAmounts) public view returns (int);
function calcNetCost(Market market, int[] memory outcomeTokenAmounts) public view returns (int);
function calcMarginalPrice(Market market, uint8 outcomeTokenIndex) public view returns (uint);
}
20 changes: 11 additions & 9 deletions contracts/Markets/Campaign.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;
import "../Events/Event.sol";
import "../Markets/StandardMarketFactory.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/drafts/SignedSafeMath.sol";
import "@gnosis.pm/util-contracts/contracts/Proxy.sol";

contract CampaignData {
Expand Down Expand Up @@ -79,9 +80,9 @@ contract CampaignProxy is Proxy, CampaignData {
public
{
// Validate input
require( address(_eventContract) != 0
&& address(_marketFactory) != 0
&& address(_marketMaker) != 0
require( address(_eventContract) != address(0)
&& address(_marketFactory) != address(0)
&& address(_marketMaker) != address(0)
&& _fee < FEE_RANGE
&& _funding > 0
&& now < _deadline);
Expand All @@ -97,7 +98,8 @@ contract CampaignProxy is Proxy, CampaignData {
/// @title Campaign contract - Allows to crowdfund a market
/// @author Stefan George - <[email protected]>
contract Campaign is Proxied, CampaignData {
using SafeMath for *;
using SignedSafeMath for int;
using SafeMath for uint;

/*
* Public functions
Expand All @@ -109,12 +111,12 @@ contract Campaign is Proxied, CampaignData {
timedTransitions
atStage(Stages.AuctionStarted)
{
uint raisedAmount = eventContract.collateralToken().balanceOf(this);
uint raisedAmount = eventContract.collateralToken().balanceOf(address(this));
uint maxAmount = funding.sub(raisedAmount);
if (maxAmount < amount)
amount = maxAmount;
// Collect collateral tokens
require(eventContract.collateralToken().transferFrom(msg.sender, this, amount));
require(eventContract.collateralToken().transferFrom(msg.sender, address(this), amount));
contributions[msg.sender] = contributions[msg.sender].add(amount);
if (amount == maxAmount)
stage = Stages.AuctionSuccessful;
Expand Down Expand Up @@ -145,7 +147,7 @@ contract Campaign is Proxied, CampaignData {
returns (Market)
{
market = marketFactory.createMarket(eventContract, marketMaker, fee);
require(eventContract.collateralToken().approve(market, funding));
require(eventContract.collateralToken().approve(address(market), funding));
market.fund(funding);
stage = Stages.MarketCreated;
emit MarketCreation(market);
Expand All @@ -163,7 +165,7 @@ contract Campaign is Proxied, CampaignData {
market.close();
market.withdrawFees();
eventContract.redeemWinnings();
finalBalance = eventContract.collateralToken().balanceOf(this);
finalBalance = eventContract.collateralToken().balanceOf(address(this));
stage = Stages.MarketClosed;
emit MarketClosing();
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/Markets/CampaignFactory.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;
import "../Markets/Campaign.sol";


Expand Down Expand Up @@ -44,8 +44,8 @@ contract CampaignFactory {
public
returns (Campaign campaign)
{
campaign = Campaign(new CampaignProxy(
campaignMasterCopy, eventContract, marketFactory, marketMaker, fee, funding, deadline));
campaign = Campaign(address(new CampaignProxy(
address(campaignMasterCopy), eventContract, marketFactory, marketMaker, fee, funding, deadline)));
emit CampaignCreation(msg.sender, campaign, eventContract, marketFactory, marketMaker, fee, funding, deadline);
}
}
4 changes: 2 additions & 2 deletions contracts/Markets/Market.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;
import "../Events/Event.sol";
import "../MarketMakers/MarketMaker.sol";
import "@gnosis.pm/util-contracts/contracts/Proxy.sol";
Expand Down Expand Up @@ -46,6 +46,6 @@ contract Market is MarketData {
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[] outcomeTokenAmounts, int costLimit) public returns (int);
function trade(int[] memory outcomeTokenAmounts, int costLimit) public returns (int);
function calcMarketFee(uint outcomeTokenCost) public view returns (uint);
}
Loading