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 contracts to solc-6 #40

Merged
merged 13 commits into from
Dec 7, 2020
3 changes: 2 additions & 1 deletion contracts/EtherToken.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.2;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.6.0;
import "./GnosisStandardToken.sol";

/// @title Token contract - Token exchanging Ether 1:1
Expand Down
15 changes: 8 additions & 7 deletions contracts/GnosisStandardToken.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.2;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.6.0;
import "./Token.sol";
import "./Math.sol";
import "./Proxy.sol";
Expand Down Expand Up @@ -29,7 +30,7 @@ contract GnosisStandardToken is Token, StandardTokenData {
/// @param to Address of token receiver
/// @param value Number of tokens to transfer
/// @return Was transfer successful?
function transfer(address to, uint value) public returns (bool) {
function transfer(address to, uint value) public override returns (bool) {
if (!balances[msg.sender].safeToSub(value) || !balances[to].safeToAdd(value)) {
return false;
}
Expand All @@ -45,7 +46,7 @@ contract GnosisStandardToken is Token, StandardTokenData {
/// @param to Address to where tokens are sent
/// @param value Number of tokens to transfer
/// @return Was transfer successful?
function transferFrom(address from, address to, uint value) public returns (bool) {
function transferFrom(address from, address to, uint value) public override returns (bool) {
if (!balances[from].safeToSub(value) || !allowances[from][msg.sender].safeToSub(
value
) || !balances[to].safeToAdd(value)) {
Expand All @@ -62,7 +63,7 @@ contract GnosisStandardToken is Token, StandardTokenData {
/// @param spender Address of allowed account
/// @param value Number of approved tokens
/// @return Was approval successful?
function approve(address spender, uint value) public returns (bool) {
function approve(address spender, uint value) public override returns (bool) {
allowances[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
Expand All @@ -72,20 +73,20 @@ contract GnosisStandardToken is Token, StandardTokenData {
/// @param owner Address of token owner
/// @param spender Address of token spender
/// @return Remaining allowance for spender
function allowance(address owner, address spender) public view returns (uint) {
function allowance(address owner, address spender) public override view returns (uint) {
return allowances[owner][spender];
}

/// @dev Returns number of tokens owned by given address
/// @param owner Address of token owner
/// @return Balance of owner
function balanceOf(address owner) public view returns (uint) {
function balanceOf(address owner) public override view returns (uint) {
return balances[owner];
}

/// @dev Returns total supply of tokens
/// @return Total supply
function totalSupply() public view returns (uint) {
function totalSupply() public override view returns (uint) {
return totalTokens;
}
}
12 changes: 7 additions & 5 deletions contracts/HumanFriendlyToken.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// SPDX-License-Identifier: LGPL-3.0-only

/// Implements ERC 20 Token standard including extra accessors for human readability.
/// See: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
pragma solidity ^0.5.2;
pragma solidity ^0.6.0;
import "./Token.sol";

/// @title Abstract human-friendly token contract - Functions to be implemented by token contracts
contract HumanFriendlyToken is Token {
abstract contract HumanFriendlyToken is Token {
/*
* Public functions
*/
function name() public view returns (string memory);
function symbol() public view returns (string memory);
function decimals() public view returns (uint8);
function name() public virtual view returns (string memory);
function symbol() public virtual view returns (string memory);
function decimals() public virtual view returns (uint8);
}
7 changes: 4 additions & 3 deletions contracts/Math.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.2;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.6.0;

/// @title Math library - Allows calculation of logarithmic and exponential functions
/// @author Alan Lu - <[email protected]>
Expand Down Expand Up @@ -137,7 +138,7 @@ library GnosisMath {

/// @dev Returns base 2 logarithm value of given x
/// @param x x
/// @return logarithmic value
/// @return lo - logarithmic value
function floorLog2(uint x) public pure returns (int lo) {
lo = -64;
int hi = 193;
Expand All @@ -152,7 +153,7 @@ library GnosisMath {

/// @dev Returns maximum of an array
/// @param nums Numbers to look through
/// @return Maximum number
/// @return maxNum - Maximum number
function max(int[] memory nums) public pure returns (int maxNum) {
require(nums.length > 0);
maxNum = -2 ** 255;
Expand Down
3 changes: 2 additions & 1 deletion contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.2;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.6.0;

contract Migrations {
address public owner;
Expand Down
31 changes: 24 additions & 7 deletions contracts/Proxy.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.2;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.6.0;

/// @title Proxied - indicates that a contract will be proxied. Also defines storage requirements for Proxy.
/// @author Alan Lu - <[email protected]>
Expand All @@ -17,19 +18,35 @@ contract Proxy is Proxied {
}

/// @dev Fallback function forwards all transactions and returns all received return data.
function() external payable {
function _fallback() internal {
address _masterCopy = masterCopy;
assembly {
calldatacopy(0, 0, calldatasize)
let success := delegatecall(not(0), _masterCopy, 0, calldatasize, 0, 0)
returndatacopy(0, 0, returndatasize)
calldatacopy(0, 0, calldatasize())
let success := delegatecall(not(0), _masterCopy, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch success
case 0 {
revert(0, returndatasize)
revert(0, returndatasize())
}
default {
return(0, returndatasize)
return(0, returndatasize())
}
}
}

/**
* @dev Fallback function that delegates calls to the masterCopy.
* Runs when no other function in the contract matches the call data.
*/
Comment on lines +37 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ubernit: There is a mix of doc-comment styles in this file, both /// and /** */ are used.

Copy link
Contributor Author

@bh2smith bh2smith Dec 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll fix this ASAP. Plan to merge and publish on Monday. Please feel free to approve.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please feel free to approve

Already have 😉

fallback () external payable {
_fallback();
}

/**
* @dev Fallback function that receives ether and delegates calls to masterCopy.
* Runs when call data is empty.
*/
receive () external payable {
_fallback();
}
}
3 changes: 2 additions & 1 deletion contracts/StorageAccessible.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.2;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.6.0;

/// @title StorageAccessible - generic base contract that allows callers to access all internal storage.
contract StorageAccessible {
Expand Down
17 changes: 9 additions & 8 deletions contracts/Token.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
/// Implements ERC 20 Token standard: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
pragma solidity ^0.5.2;
pragma solidity ^0.6.0;

/// @title Abstract token contract - Functions to be implemented by token contracts
contract Token {
abstract contract Token {
/*
* Events
*/
Expand All @@ -12,10 +13,10 @@ contract Token {
/*
* Public functions
*/
function transfer(address to, uint value) public returns (bool);
function transferFrom(address from, address to, uint value) public returns (bool);
function approve(address spender, uint value) public returns (bool);
function balanceOf(address owner) public view returns (uint);
function allowance(address owner, address spender) public view returns (uint);
function totalSupply() public view returns (uint);
function transfer(address to, uint value) public virtual returns (bool);
function transferFrom(address from, address to, uint value) public virtual returns (bool);
function approve(address spender, uint value) public virtual returns (bool);
function balanceOf(address owner) public virtual view returns (uint);
function allowance(address owner, address spender) public virtual view returns (uint);
function totalSupply() public virtual view returns (uint);
}
3 changes: 2 additions & 1 deletion contracts/test/StorageAccessibleWrapper.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.2;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.6.0;
import "../StorageAccessible.sol";

contract StorageAccessibleWrapper is StorageAccessible {
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
"eslint-plugin-standard": "^4.0.0",
"prettier": "^1.15.3",
"prettier-plugin-solidity-refactor": "^1.0.0-alpha.12",
"solc": "0.5.8",
"truffle": "^5.0.2",
"@truffle/contract": "^4.1.2"
"solc": "0.6.12",
"truffle": "^5.1.50"
},
"dependencies": {
"@truffle/hdwallet-provider": "^1.0.42"
"@truffle/hdwallet-provider": "^1.0.42",
"truffle-assertions": "^0.9.2"
}
}
2 changes: 1 addition & 1 deletion truffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (!privateKey && !mnemonic) {

// Solc
const solcUseDocker = process.env.SOLC_USE_DOCKER === 'true' || false
const solcVersion = '0.5.2'
const solcVersion = '0.6.12'

// Gas price
const gasPriceGWei = process.env.GAS_PRICE_GWEI || DEFAULT_GAS_PRICE_GWEI
Expand Down
Loading