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

Upgrade solc to 0.5.x #70

Merged
merged 8 commits into from
Jan 3, 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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
key: protocol-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Compile contracts
command: $(npm bin)/truffle compile
command: npm install && $(npm bin)/truffle compile
- save_cache:
key: protocol-completed-build-{{ .Environment.CIRCLE_SHA1 }}
paths:
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
- checkout
- run:
name: Install Dependencies
command: apk add make git python g++ && npm install --quiet
command: apk add make git python g++ curl && npm install --quiet
- run:
name: Run coverage
command: npm run coverage
Expand Down
2 changes: 1 addition & 1 deletion contracts/ContractCreator.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 "./Registry.sol";

Expand Down
20 changes: 10 additions & 10 deletions contracts/Derivative.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

TODO: Implement tax function
*/
pragma solidity >=0.4.24;
pragma solidity ^0.5.0;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "./OracleInterface.sol";
Expand Down Expand Up @@ -52,7 +52,7 @@ contract Derivative {
}

struct ContractParty {
address accountAddress;
address payable accountAddress;
int256 balance;
bool hasConfirmedPrice;
}
Expand All @@ -76,13 +76,13 @@ contract Derivative {
int256 public npv; // Net present value is measured in Wei

constructor(
address _makerAddress,
address _takerAddress,
address payable _makerAddress,
address payable _takerAddress,
address _oracleAddress,
int256 _defaultPenalty,
int256 _requiredMargin,
uint expiry,
string _product,
string memory _product,
uint _notional
) public payable {
// Address information
Expand Down Expand Up @@ -361,13 +361,13 @@ contract Derivative {
contract SimpleDerivative is Derivative {

constructor(
address _ownerAddress,
address _counterpartyAddress,
address payable _ownerAddress,
address payable _counterpartyAddress,
address _oracleAddress,
int256 _defaultPenalty,
int256 _requiredMargin,
uint expiry,
string product,
string memory product,
uint notional
) public payable Derivative(
_ownerAddress,
Expand Down Expand Up @@ -397,11 +397,11 @@ contract DerivativeCreator is ContractCreator {
ContractCreator(registryAddress, _oracleAddress) {} // solhint-disable-line no-empty-blocks

function createDerivative(
address counterparty,
address payable counterparty,
int256 defaultPenalty,
int256 requiredMargin,
uint expiry,
string product,
string calldata product,
uint notional
)
external
Expand Down
2 changes: 1 addition & 1 deletion contracts/Migrations.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;


contract Migrations {
Expand Down
2 changes: 1 addition & 1 deletion contracts/OracleInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
OracleInterface contract.
The interface that contracts use to query verified and unverified price feeds.
*/
pragma solidity >=0.4.24;
pragma solidity ^0.5.0;


// This interface allows contracts to query verified and unverified prices from the VoteToken.
Expand Down
2 changes: 1 addition & 1 deletion contracts/OracleMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Simple mock implementation of a Vote Token to be used by a derivative for querying price feeds.
*/
pragma solidity >=0.4.24;
pragma solidity ^0.5.0;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/PriceTime.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
PriceTime Library
*/
pragma solidity >=0.4.24;
pragma solidity ^0.5.0;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/Registry.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/ownership/Ownable.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/Testable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Base class that provides time overrides, but only if being run in test mode.
*/

pragma solidity >=0.4.24;
pragma solidity ^0.5.0;

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";

Expand Down
36 changes: 18 additions & 18 deletions contracts/TokenizedDerivative.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Implements a simplified version of tokenized Product/ETH Products.
*/
pragma solidity >=0.4.24;
pragma solidity ^0.5.0;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
Expand Down Expand Up @@ -71,7 +71,7 @@ contract TokenizedDerivative is ERC20 {
}

struct ContractParty {
address accountAddress;
address payable accountAddress;
int256 balance;
bool hasConfirmedPrice;
uint marginRequirement; // Percentage of nav*10^18
Expand Down Expand Up @@ -118,7 +118,7 @@ contract TokenizedDerivative is ERC20 {
uint deposit;
}

Dispute public dispute;
Dispute public disputeInfo;

// The information in the following struct is only valid if in the midst of a Default or Termination.
struct Termination {
Expand Down Expand Up @@ -148,13 +148,13 @@ contract TokenizedDerivative is ERC20 {
}

constructor(
address _providerAddress,
address _investorAddress,
address payable _providerAddress,
address payable _investorAddress,
address _oracleAddress,
uint _defaultPenalty, // Percentage of nav*10^18
uint _terminationFee, // Percentage of nav*10^18
uint _providerRequiredMargin, // Percentage of nav*10^18
string _product,
string memory _product,
uint _fixedYearlyFee, // Percentage of nav * 10^18
uint _disputeDeposit, // Percentage of nav * 10^18
address _returnCalculator,
Expand Down Expand Up @@ -249,8 +249,8 @@ contract TokenizedDerivative is ERC20 {

uint initialSupply = totalSupply();

require(this.transferFrom(msg.sender, this, numTokens));
_burn(this, numTokens);
require(this.transferFrom(msg.sender, address(this), numTokens));
_burn(address(this), numTokens);


int256 investorBalance = investor.balance;
Expand Down Expand Up @@ -312,9 +312,9 @@ contract TokenizedDerivative is ERC20 {

state = State.Disputed;
endTime = lastRemarginTime;
dispute.disputedNav = nav;
dispute.disputer = msg.sender;
dispute.deposit = requiredDeposit;
disputeInfo.disputedNav = nav;
disputeInfo.disputer = msg.sender;
disputeInfo.deposit = requiredDeposit;

msg.sender.transfer(refund);
}
Expand Down Expand Up @@ -343,9 +343,9 @@ contract TokenizedDerivative is ERC20 {
require(startingState == State.Disputed || startingState == State.Expired || startingState == State.Defaulted);
_settleVerifiedPrice();
if (startingState == State.Disputed) {
(ContractParty storage disputer, ContractParty storage notDisputer) = _whoAmI(dispute.disputer);
int256 depositValue = int256(dispute.deposit);
if (nav == dispute.disputedNav) {
(ContractParty storage disputer, ContractParty storage notDisputer) = _whoAmI(disputeInfo.disputer);
int256 depositValue = int256(disputeInfo.deposit);
if (nav == disputeInfo.disputedNav) {
disputer.balance += depositValue;
} else {
notDisputer.balance += depositValue;
Expand Down Expand Up @@ -539,7 +539,7 @@ contract TokenizedDerivative is ERC20 {
if (state != State.Live) {
didReduce = additionalAuthorizedNav != 0;
additionalAuthorizedNav = 0;
return;
return didReduce;
}

int256 totalAuthorizedNav = currentNav + int256(additionalAuthorizedNav);
Expand Down Expand Up @@ -630,12 +630,12 @@ contract TokenizedDerivativeCreator is ContractCreator {
ContractCreator(registryAddress, _oracleAddress) {} // solhint-disable-line no-empty-blocks

function createTokenizedDerivative(
address provider,
address investor,
address payable provider,
address payable investor,
uint defaultPenalty,
uint terminationFee,
uint providerRequiredMargin,
string product,
string calldata product,
uint fixedYearlyFee,
uint disputeDeposit,
address returnCalculator,
Expand Down
30 changes: 17 additions & 13 deletions contracts/Vote.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Allows users to vote yes/no on whether a price is accurate

*/
pragma solidity >=0.4.24;
pragma solidity ^0.5.0;

pragma experimental ABIEncoderV2;

Expand Down Expand Up @@ -72,7 +72,7 @@ library Poll {
}
}

function _addProposal(Data storage self, string ipfsHash) internal {
function _addProposal(Data storage self, string memory ipfsHash) internal {
uint idx = self.proposals.length++;
self.proposals[idx].ipfsHash = ipfsHash;
}
Expand Down Expand Up @@ -107,7 +107,7 @@ library VotePeriod {
mapping(string => bool) ipfsHashSet;
}

function _proposeFeed(Data storage self, string ipfsHash) internal {
function _proposeFeed(Data storage self, string memory ipfsHash) internal {
require(!self.ipfsHashSet[ipfsHash]);
self.ipfsHashSet[ipfsHash] = true;
self.runoffPoll._addProposal(ipfsHash);
Expand Down Expand Up @@ -210,7 +210,7 @@ contract VoteCoin is ERC20, VoteInterface, OracleInterface, Testable {

PeriodTiming[5] private periodTimings;

constructor(string _product, uint _priceInterval, bool isTest) public Testable(isTest) {
constructor(string memory _product, uint _priceInterval, bool isTest) public Testable(isTest) {
_mint(msg.sender, 10000);
product = _product;
priceInterval = _priceInterval;
Expand Down Expand Up @@ -269,20 +269,20 @@ contract VoteCoin is ERC20, VoteInterface, OracleInterface, Testable {
_getCurrentVotePeriod()._revealVote(voteOption, salt, balanceOf(msg.sender), period);
}

function proposeFeed(string ipfsHash) public {
function proposeFeed(string memory ipfsHash) public {
checkTimeAndUpdateState();
require(period == VotePeriod.PeriodType.Commit || period == VotePeriod.PeriodType.Reveal);

_getCurrentVotePeriod()._proposeFeed(ipfsHash);
}

function addUnverifiedPrice(PriceTime.Data priceTime) public {
function addUnverifiedPrice(PriceTime.Data memory priceTime) public {
PriceTime.Data[] memory priceTimes = new PriceTime.Data[](1);
priceTimes[0] = priceTime;
addUnverifiedPrices(priceTimes);
}

function getProposals() public view returns (Proposal.Data[] proposals) {
function getProposals() public view returns (Proposal.Data[] memory proposals) {
uint time = getCurrentTime();
uint computedStartTime = _getStartOfPeriod(time);

Expand All @@ -307,23 +307,23 @@ contract VoteCoin is ERC20, VoteInterface, OracleInterface, Testable {
}
}

function getCurrentPeriodType() public view returns (string periodType) {
function getCurrentPeriodType() public view returns (string memory periodType) {
uint currentTime = getCurrentTime();
return _getStringPeriodType(_getPeriodType(_getStartOfPeriod(currentTime), currentTime));
}

function getProduct() public view returns (string _product) {
function getProduct() public view returns (string memory _product) {
return product;
}

function getDefaultProposalPrices() public view returns (PriceTime.Data[] prices) {
function getDefaultProposalPrices() public view returns (PriceTime.Data[] memory prices) {
// TODO(mrice32): we may want to subtract some time offset to ensure all unverifiedPrices being voted on are
// in before the voting period starts.
// Note: this will fail if the entire voting period of prices previous do not exist.
VotePeriod.Data storage votePeriod = _getCurrentVotePeriod();
(uint startTime, uint endTime) = votePeriod._getPricePeriod(totalVotingDuration);
if (unverifiedPrices.length == 0 || startTime < unverifiedPrices[0].time) {
return;
return prices;
}
uint startIndex = unverifiedPrices._getIndex(startTime, priceInterval);

Expand Down Expand Up @@ -469,7 +469,11 @@ contract VoteCoin is ERC20, VoteInterface, OracleInterface, Testable {
return timestamp.sub(epochOffset).div(totalVotingDuration).mul(totalVotingDuration).add(epochOffset);
}

function _getStringPeriodType(VotePeriod.PeriodType periodType) private pure returns (string stringPeriodType) {
function _getStringPeriodType(VotePeriod.PeriodType periodType)
private
pure
returns (string memory stringPeriodType)
{
if (periodType == VotePeriod.PeriodType.Commit) {
return "commit";
} else if (periodType == VotePeriod.PeriodType.Reveal) {
Expand All @@ -488,7 +492,7 @@ contract VoteCoin is ERC20, VoteInterface, OracleInterface, Testable {
function _initPeriodTiming(uint startOffset, uint duration, VotePeriod.PeriodType periodType)
private
view
returns (PeriodTiming periodTiming, uint nextStartOffset)
returns (PeriodTiming memory periodTiming, uint nextStartOffset)
{
periodTiming.startOffset = startOffset;
periodTiming.endOffset = startOffset.add(duration);
Expand Down
8 changes: 4 additions & 4 deletions contracts/VoteInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ contract VoteInterface {
function getCurrentCommitRevealPeriods() public view returns (Period[] memory periods);

// Returns the current period type ("commit", "reveal", or "none").
function getCurrentPeriodType() public view returns (string periodType);
function getCurrentPeriodType() public view returns (string memory periodType);

// Gets the product that the price votes apply to.
function getProduct() public view returns (string product);
function getProduct() public view returns (string memory product);

// Gets the runoff/alternative proposals for the current period.
function getProposals() public view returns (Proposal.Data[] proposals);
function getProposals() public view returns (Proposal.Data[] memory proposals);

// Gets the default proposal (option 1 during the primary vote period) for the current period.
function getDefaultProposalPrices() public view returns (PriceTime.Data[] defaultProposal);
function getDefaultProposalPrices() public view returns (PriceTime.Data[] memory defaultProposal);

// Gets the default proposal (option 1 during the primary vote period) price for a particular time during the
// current period.
Expand Down
Loading