Skip to content

Commit

Permalink
Update to solidity 0.5.3
Browse files Browse the repository at this point in the history
- update truffle
- update openzepplin-solidity
- update erc777 implementation to match the specs
  • Loading branch information
0xjac committed Apr 4, 2019
1 parent 5bc56da commit 6d27520
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 296 deletions.
20 changes: 10 additions & 10 deletions contracts/ERC20Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
* Do not use or deploy this code before reviewing it personally first.
*/
// solhint-disable-next-line compiler-fixed
pragma solidity ^0.4.24;
pragma solidity ^0.5.3;


interface ERC20Token {
function name() public view returns (string);
function symbol() public view returns (string);
function decimals() public view returns (uint8);
function totalSupply() public view returns (uint256);
function balanceOf(address owner) public view returns (uint256);
function transfer(address to, uint256 amount) public returns (bool);
function transferFrom(address from, address to, uint256 amount) public returns (bool);
function approve(address spender, uint256 amount) public returns (bool);
function allowance(address owner, address spender) public view returns (uint256);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address owner) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);

// solhint-disable-next-line no-simple-event-func-name
event Transfer(address indexed from, address indexed to, uint256 amount);
Expand Down
72 changes: 49 additions & 23 deletions contracts/ERC777BaseToken.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
pragma solidity 0.4.24;
pragma solidity 0.5.3;

import { ERC1820Client } from "erc1820/contracts/ERC1820Client.sol";
import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol";
Expand Down Expand Up @@ -32,7 +32,12 @@ contract ERC777BaseToken is ERC777Token, ERC1820Client {
/// @param _name Name of the new token
/// @param _symbol Symbol of the new token.
/// @param _granularity Minimum transferable chunk.
constructor(string _name, string _symbol, uint256 _granularity, address[] _defaultOperators) internal {
constructor(
string memory _name,
string memory _symbol,
uint256 _granularity,
address[] memory _defaultOperators
) internal {
mName = _name;
mSymbol = _symbol;
mTotalSupply = 0;
Expand All @@ -42,16 +47,16 @@ contract ERC777BaseToken is ERC777Token, ERC1820Client {
mDefaultOperators = _defaultOperators;
for (uint256 i = 0; i < mDefaultOperators.length; i++) { mIsDefaultOperator[mDefaultOperators[i]] = true; }

setInterfaceImplementation("ERC777Token", this);
setInterfaceImplementation("ERC777Token", address(this));
}

/* -- ERC777 Interface Implementation -- */
//
/// @return the name of the token
function name() public view returns (string) { return mName; }
function name() public view returns (string memory) { return mName; }

/// @return the symbol of the token
function symbol() public view returns (string) { return mSymbol; }
function symbol() public view returns (string memory) { return mSymbol; }

/// @return the granularity of the token
function granularity() public view returns (uint256) { return mGranularity; }
Expand All @@ -66,18 +71,18 @@ contract ERC777BaseToken is ERC777Token, ERC1820Client {

/// @notice Return the list of default operators
/// @return the list of all the default operators
function defaultOperators() public view returns (address[]) { return mDefaultOperators; }
function defaultOperators() public view returns (address[] memory) { return mDefaultOperators; }

/// @notice Send `_amount` of tokens to address `_to` passing `_data` to the recipient
/// @param _to The address of the recipient
/// @param _amount The number of tokens to be sent
function send(address _to, uint256 _amount, bytes _data) public {
function send(address _to, uint256 _amount, bytes calldata _data) external {
doSend(msg.sender, msg.sender, _to, _amount, _data, "", true);
}

/// @notice Authorize a third party `_operator` to manage (send) `msg.sender`'s tokens.
/// @param _operator The operator that wants to be Authorized
function authorizeOperator(address _operator) public {
function authorizeOperator(address _operator) external {
require(_operator != msg.sender, "Cannot authorize yourself as an operator");
if (mIsDefaultOperator[_operator]) {
mRevokedDefaultOperator[_operator][msg.sender] = false;
Expand All @@ -89,7 +94,7 @@ contract ERC777BaseToken is ERC777Token, ERC1820Client {

/// @notice Revoke a third party `_operator`'s rights to manage (send) `msg.sender`'s tokens.
/// @param _operator The operator that wants to be Revoked
function revokeOperator(address _operator) public {
function revokeOperator(address _operator) external {
require(_operator != msg.sender, "Cannot revoke yourself as an operator");
if (mIsDefaultOperator[_operator]) {
mRevokedDefaultOperator[_operator][msg.sender] = true;
Expand All @@ -115,16 +120,31 @@ contract ERC777BaseToken is ERC777Token, ERC1820Client {
/// @param _amount The number of tokens to be sent
/// @param _data Data generated by the user to be sent to the recipient
/// @param _operatorData Data generated by the operator to be sent to the recipient
function operatorSend(address _from, address _to, uint256 _amount, bytes _data, bytes _operatorData) public {
function operatorSend(
address _from,
address _to,
uint256 _amount,
bytes calldata _data,
bytes calldata _operatorData
)
external
{
require(isOperatorFor(msg.sender, _from), "Not an operator");
doSend(msg.sender, _from, _to, _amount, _data, _operatorData, true);
}

function burn(uint256 _amount, bytes _data) public {
function burn(uint256 _amount, bytes calldata _data) external {
doBurn(msg.sender, msg.sender, _amount, _data, "");
}

function operatorBurn(address _tokenHolder, uint256 _amount, bytes _data, bytes _operatorData) public {
function operatorBurn(
address _tokenHolder,
uint256 _amount,
bytes calldata _data,
bytes calldata _operatorData
)
external
{
require(isOperatorFor(msg.sender, _tokenHolder), "Not an operator");
doBurn(msg.sender, _tokenHolder, _amount, _data, _operatorData);
}
Expand All @@ -141,7 +161,7 @@ contract ERC777BaseToken is ERC777Token, ERC1820Client {
/// @param _addr Address of the contract that has to be checked
/// @return `true` if `_addr` is a regular address (not a contract)
function isRegularAddress(address _addr) internal view returns(bool) {
if (_addr == 0) { return false; }
if (_addr == address(0)) { return false; }
uint size;
assembly { size := extcodesize(_addr) } // solium-disable-line security/no-inline-assembly
return size == 0;
Expand All @@ -163,8 +183,8 @@ contract ERC777BaseToken is ERC777Token, ERC1820Client {
address _from,
address _to,
uint256 _amount,
bytes _data,
bytes _operatorData,
bytes memory _data,
bytes memory _operatorData,
bool _preventLocking
)
internal
Expand All @@ -190,10 +210,16 @@ contract ERC777BaseToken is ERC777Token, ERC1820Client {
/// @param _amount The number of tokens to be burnt
/// @param _data Data generated by the token holder
/// @param _operatorData Data generated by the operator
function doBurn(address _operator, address _tokenHolder, uint256 _amount, bytes _data, bytes _operatorData)
function doBurn(
address _operator,
address _tokenHolder,
uint256 _amount,
bytes memory _data,
bytes memory _operatorData
)
internal
{
callSender(_operator, _tokenHolder, 0x0, _amount, _data, _operatorData);
callSender(_operator, _tokenHolder, address(0), _amount, _data, _operatorData);

requireMultiple(_amount);
require(balanceOf(_tokenHolder) >= _amount, "Not enough funds");
Expand Down Expand Up @@ -221,14 +247,14 @@ contract ERC777BaseToken is ERC777Token, ERC1820Client {
address _from,
address _to,
uint256 _amount,
bytes _data,
bytes _operatorData,
bytes memory _data,
bytes memory _operatorData,
bool _preventLocking
)
internal
{
address recipientImplementation = interfaceAddr(_to, "ERC777TokensRecipient");
if (recipientImplementation != 0) {
if (recipientImplementation != address(0)) {
ERC777TokensRecipient(recipientImplementation).tokensReceived(
_operator, _from, _to, _amount, _data, _operatorData);
} else if (_preventLocking) {
Expand All @@ -251,13 +277,13 @@ contract ERC777BaseToken is ERC777Token, ERC1820Client {
address _from,
address _to,
uint256 _amount,
bytes _data,
bytes _operatorData
bytes memory _data,
bytes memory _operatorData
)
internal
{
address senderImplementation = interfaceAddr(_from, "ERC777TokensSender");
if (senderImplementation == 0) { return; }
if (senderImplementation == address(0)) { return; }
ERC777TokensSender(senderImplementation).tokensToSend(
_operator, _from, _to, _amount, _data, _operatorData);
}
Expand Down
24 changes: 15 additions & 9 deletions contracts/ERC777ERC20BaseToken.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
pragma solidity 0.4.24;
pragma solidity 0.5.3;


import { ERC20Token } from "./ERC20Token.sol";
Expand All @@ -14,15 +14,15 @@ contract ERC777ERC20BaseToken is ERC20Token, ERC777BaseToken {
mapping(address => mapping(address => uint256)) internal mAllowed;

constructor(
string _name,
string _symbol,
string memory _name,
string memory _symbol,
uint256 _granularity,
address[] _defaultOperators
address[] memory _defaultOperators
)
internal ERC777BaseToken(_name, _symbol, _granularity, _defaultOperators)
{
mErc20compatible = true;
setInterfaceImplementation("ERC20Token", this);
setInterfaceImplementation("ERC20Token", address(this));
}

/// @notice This modifier is applied to erc20 obsolete methods that are
Expand Down Expand Up @@ -86,8 +86,8 @@ contract ERC777ERC20BaseToken is ERC20Token, ERC777BaseToken {
address _from,
address _to,
uint256 _amount,
bytes _data,
bytes _operatorData,
bytes memory _data,
bytes memory _operatorData,
bool _preventLocking
)
internal
Expand All @@ -96,10 +96,16 @@ contract ERC777ERC20BaseToken is ERC20Token, ERC777BaseToken {
if (mErc20compatible) { emit Transfer(_from, _to, _amount); }
}

function doBurn(address _operator, address _tokenHolder, uint256 _amount, bytes _data, bytes _operatorData)
function doBurn(
address _operator,
address _tokenHolder,
uint256 _amount,
bytes memory _data,
bytes memory _operatorData
)
internal
{
super.doBurn(_operator, _tokenHolder, _amount, _data, _operatorData);
if (mErc20compatible) { emit Transfer(_tokenHolder, 0x0, _amount); }
if (mErc20compatible) { emit Transfer(_tokenHolder, address(0), _amount); }
}
}
38 changes: 22 additions & 16 deletions contracts/ERC777Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,32 @@
* Do not use or deploy this code before reviewing it personally first.
*/
// solhint-disable-next-line compiler-fixed
pragma solidity ^0.4.24;
pragma solidity ^0.5.3;


interface ERC777Token {
function name() public view returns (string);
function symbol() public view returns (string);
function totalSupply() public view returns (uint256);
function balanceOf(address owner) public view returns (uint256);
function granularity() public view returns (uint256);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function totalSupply() external view returns (uint256);
function balanceOf(address owner) external view returns (uint256);
function granularity() external view returns (uint256);

function defaultOperators() public view returns (address[]);
function isOperatorFor(address operator, address tokenHolder) public view returns (bool);
function authorizeOperator(address operator) public;
function revokeOperator(address operator) public;
function defaultOperators() external view returns (address[] memory);
function isOperatorFor(address operator, address tokenHolder) external view returns (bool);
function authorizeOperator(address operator) external;
function revokeOperator(address operator) external;

function send(address to, uint256 amount, bytes data) public;
function operatorSend(address from, address to, uint256 amount, bytes data, bytes operatorData) public;
function send(address to, uint256 amount, bytes calldata data) external;
function operatorSend(
address from,
address to,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
) external;

function burn(uint256 amount, bytes data) public;
function operatorBurn(address from, uint256 amount, bytes data, bytes operatorData) public;
function burn(uint256 amount, bytes calldata data) external;
function operatorBurn(address from, uint256 amount, bytes calldata data, bytes calldata operatorData) external;

event Sent(
address indexed operator,
Expand All @@ -34,8 +40,8 @@ interface ERC777Token {
uint256 amount,
bytes data,
bytes operatorData
); // solhint-disable-next-line separate-by-one-line-in-contract
event Minted(address indexed operator, address indexed to, uint256 amount, bytes operatorData);
);
event Minted(address indexed operator, address indexed to, uint256 amount, bytes data, bytes operatorData);
event Burned(address indexed operator, address indexed from, uint256 amount, bytes data, bytes operatorData);
event AuthorizedOperator(address indexed operator, address indexed tokenHolder);
event RevokedOperator(address indexed operator, address indexed tokenHolder);
Expand Down
8 changes: 4 additions & 4 deletions contracts/ERC777TokensRecipient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Do not use or deploy this code before reviewing it personally first.
*/
// solhint-disable-next-line compiler-fixed
pragma solidity ^0.4.24;
pragma solidity ^0.5.3;


interface ERC777TokensRecipient {
Expand All @@ -15,7 +15,7 @@ interface ERC777TokensRecipient {
address from,
address to,
uint256 amount,
bytes data,
bytes operatorData
) public;
bytes calldata data,
bytes calldata operatorData
) external;
}
8 changes: 4 additions & 4 deletions contracts/ERC777TokensSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Do not use or deploy this code before reviewing it personally first.
*/
// solhint-disable-next-line compiler-fixed
pragma solidity ^0.4.24;
pragma solidity ^0.5.3;


interface ERC777TokensSender {
Expand All @@ -15,7 +15,7 @@ interface ERC777TokensSender {
address from,
address to,
uint amount,
bytes userData,
bytes operatorData
) public;
bytes calldata userData,
bytes calldata operatorData
) external;
}
4 changes: 2 additions & 2 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* This code has not been reviewed.
* Do not use or deploy this code before reviewing it personally first.
*/
pragma solidity 0.4.24;
pragma solidity 0.5.3;


contract Migrations {
Expand All @@ -16,7 +16,7 @@ contract Migrations {
if (msg.sender == owner) _;
}

function Migrations() public {
constructor() public {
owner = msg.sender;
}

Expand Down
Loading

0 comments on commit 6d27520

Please sign in to comment.