Skip to content

Commit

Permalink
Merge abe8451 into 8c8b9ff
Browse files Browse the repository at this point in the history
  • Loading branch information
vittominacori committed Apr 21, 2020
2 parents 8c8b9ff + abe8451 commit 073e161
Show file tree
Hide file tree
Showing 27 changed files with 111 additions and 93 deletions.
10 changes: 5 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"extends" : [
"standard",
"plugin:promise/recommended"
"plugin:promise/recommended",
],
"plugins": [
"mocha-no-only",
"promise"
"promise",
],
"env": {
"browser" : true,
"node" : true,
"mocha" : true,
"jest" : true
"jest" : true,
},
"globals" : {
"artifacts": false,
"contract": false,
"assert": false,
"web3": false
"web3": false,
},
"rules": {

Expand Down Expand Up @@ -54,7 +54,7 @@
"mocha-no-only/mocha-no-only": ["error"],

"promise/always-return": "off",
"promise/avoid-new": "off"
"promise/avoid-new": "off",
},
"parserOptions": {
"ecmaVersion": 2018
Expand Down
1 change: 0 additions & 1 deletion .node-version

This file was deleted.

1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
3 changes: 0 additions & 3 deletions .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ module.exports = {
testCommand: 'node --max-old-space-size=4096 ../node_modules/.bin/truffle test --network coverage',
compileCommand: 'node --max-old-space-size=4096 ../node_modules/.bin/truffle compile --network coverage',
client: require('ganache-cli'),
providerOptions: {
hardfork: 'istanbul',
},
copyPackages: [
'@openzeppelin/contracts',
],
Expand Down
10 changes: 3 additions & 7 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{
"extends": "solhint:recommended",
"rules": {
"indent": ["error", 4],
"func-order": "off",
"bracket-align": "off",
"compiler-fixed": "off",
"no-simple-event-func-name": "off",
"separate-by-one-line-in-contract": "off",
"two-lines-top-level-separator": "off",
"mark-callable-contracts": "off",
"compiler-version": ["error", "^0.5.16"]
"no-empty-blocks": "off",
"compiler-version": ["error", "0.6.0"],
"private-vars-leading-underscore": "error"
}
}
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
dist: trusty
sudo: false
group: beta
language: node_js
node_js:
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ npm install erc-payable-token
## Usage

```solidity
pragma solidity ^0.5.16;
pragma solidity ^0.6.0;
import "erc-payable-token/contracts/token/ERC1363/ERC1363.sol";
contract MyToken is ERC1363 {
constructor (
string memory name,
string memory symbol
) public payable ERC1363(name, symbol) {}
// your stuff
}
```
Expand Down
6 changes: 1 addition & 5 deletions buidler.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ usePlugin('@nomiclabs/buidler-truffle5'); // eslint-disable-line no-undef
module.exports = {
defaultNetwork: 'buidlerevm',
networks: {
buidlerevm: {
hardfork: 'istanbul',
},
coverage: {
url: 'http://127.0.0.1:8555',
gas: 0xfffffffffff,
gasPrice: 0x01,
},
},
solc: {
version: '0.5.16',
evmVersion: 'istanbul',
version: '0.6.6',
optimizer: {
enabled: true,
runs: 200,
Expand Down
6 changes: 3 additions & 3 deletions contracts/examples/ERC1363PayableCrowdsale.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.6.0;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand Down Expand Up @@ -99,7 +99,7 @@ contract ERC1363PayableCrowdsale is ERC1363Payable, ReentrancyGuard {
* @param value The amount of tokens transferred
* @param data Additional data with no specified format
*/
function _transferReceived(address operator, address from, uint256 value, bytes memory data) internal {
function _transferReceived(address operator, address from, uint256 value, bytes memory data) internal override {
_buyTokens(operator, from, value, data);
}

Expand All @@ -110,7 +110,7 @@ contract ERC1363PayableCrowdsale is ERC1363Payable, ReentrancyGuard {
* @param value uint256 The amount of tokens to be spent
* @param data bytes Additional data with no specified format
*/
function _approvalReceived(address owner, uint256 value, bytes memory data) internal {
function _approvalReceived(address owner, uint256 value, bytes memory data) internal override {
IERC20(acceptedToken()).transferFrom(owner, address(this), value);
_buyTokens(owner, owner, value, data);
}
Expand Down
9 changes: 7 additions & 2 deletions contracts/mocks/ERC1363Mock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.6.0;

import "../token/ERC1363/ERC1363.sol";

Expand All @@ -8,7 +8,12 @@ contract ERC1363Mock is ERC1363 {
/**
* @dev Constructor that gives msg.sender all of existing tokens.
*/
constructor(address initialAccount, uint256 initialBalance) public {
constructor (
string memory name,
string memory symbol,
address initialAccount,
uint256 initialBalance
) public payable ERC1363(name, symbol) {
_mint(initialAccount, initialBalance);
}
}
6 changes: 3 additions & 3 deletions contracts/mocks/ERC1363PayableMock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.6.0;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "../payment/ERC1363Payable.sol";
Expand All @@ -13,12 +13,12 @@ contract ERC1363PayableMock is ERC1363Payable {
constructor(IERC1363 acceptedToken) public ERC1363Payable(acceptedToken) {} // solhint-disable-line no-empty-blocks

// solhint-disable-next-line no-unused-vars
function _transferReceived(address operator, address from, uint256 value, bytes memory data) internal {
function _transferReceived(address operator, address from, uint256 value, bytes memory data) internal override {
transferNumber = transferNumber.add(1);
}

// solhint-disable-next-line no-unused-vars
function _approvalReceived(address owner, uint256 value, bytes memory data) internal {
function _approvalReceived(address owner, uint256 value, bytes memory data) internal override {
approvalNumber = approvalNumber.add(1);
}
}
4 changes: 2 additions & 2 deletions contracts/mocks/ERC1363ReceiverMock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.6.0;

import "../token/ERC1363/IERC1363Receiver.sol";

Expand All @@ -20,7 +20,7 @@ contract ERC1363ReceiverMock is IERC1363Receiver {
_reverts = reverts;
}

function onTransferReceived(address operator, address from, uint256 value, bytes memory data) public returns (bytes4) { // solhint-disable-line max-line-length
function onTransferReceived(address operator, address from, uint256 value, bytes memory data) public override returns (bytes4) { // solhint-disable-line max-line-length
require(!_reverts);
emit Received(operator, from, value, data, gasleft());
return _retval;
Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/ERC1363SpenderMock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.6.0;

import "../token/ERC1363/IERC1363Spender.sol";

Expand All @@ -19,7 +19,7 @@ contract ERC1363SpenderMock is IERC1363Spender {
_reverts = reverts;
}

function onApprovalReceived(address owner, uint256 value, bytes memory data) public returns (bytes4) {
function onApprovalReceived(address owner, uint256 value, bytes memory data) public override returns (bytes4) {
require(!_reverts);
emit Approved(owner, value, data, gasleft());
return _retval;
Expand Down
7 changes: 5 additions & 2 deletions contracts/mocks/ERC20Mock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.6.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

Expand All @@ -15,7 +15,10 @@ contract ERC20Mock is ERC20 {
/**
* @dev Constructor that gives msg.sender all of existing tokens.
*/
constructor() public {
constructor (
string memory name,
string memory symbol
) public payable ERC20(name, symbol) {
_mint(msg.sender, INITIAL_SUPPLY);
}
}
11 changes: 6 additions & 5 deletions contracts/payment/ERC1363Payable.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma solidity ^0.5.16;
pragma solidity ^0.6.0;

import "@openzeppelin/contracts/introspection/ERC165Checker.sol";
import "@openzeppelin/contracts/introspection/ERC165.sol";

import "../token/ERC1363/IERC1363.sol";
import "../token/ERC1363/IERC1363Receiver.sol";
Expand Down Expand Up @@ -86,7 +87,7 @@ contract ERC1363Payable is IERC1363Receiver, IERC1363Spender, ERC165 {
* @param value uint256 The amount of tokens transferred
* @param data bytes Additional data with no specified format
*/
function onTransferReceived(address operator, address from, uint256 value, bytes memory data) public returns (bytes4) { // solhint-disable-line max-line-length
function onTransferReceived(address operator, address from, uint256 value, bytes memory data) public override returns (bytes4) { // solhint-disable-line max-line-length
require(msg.sender == address(_acceptedToken));

emit TokensReceived(operator, from, value, data);
Expand All @@ -102,7 +103,7 @@ contract ERC1363Payable is IERC1363Receiver, IERC1363Spender, ERC165 {
* @param value uint256 The amount of tokens to be spent
* @param data bytes Additional data with no specified format
*/
function onApprovalReceived(address owner, uint256 value, bytes memory data) public returns (bytes4) {
function onApprovalReceived(address owner, uint256 value, bytes memory data) public override returns (bytes4) {
require(msg.sender == address(_acceptedToken));

emit TokensApproved(owner, value, data);
Expand All @@ -127,7 +128,7 @@ contract ERC1363Payable is IERC1363Receiver, IERC1363Spender, ERC165 {
* @param value uint256 The amount of tokens transferred
* @param data bytes Additional data with no specified format
*/
function _transferReceived(address operator, address from, uint256 value, bytes memory data) internal {
function _transferReceived(address operator, address from, uint256 value, bytes memory data) internal virtual {
// solhint-disable-previous-line no-empty-blocks

// optional override
Expand All @@ -140,7 +141,7 @@ contract ERC1363Payable is IERC1363Receiver, IERC1363Spender, ERC165 {
* @param value uint256 The amount of tokens to be spent
* @param data bytes Additional data with no specified format
*/
function _approvalReceived(address owner, uint256 value, bytes memory data) internal {
function _approvalReceived(address owner, uint256 value, bytes memory data) internal virtual {
// solhint-disable-previous-line no-empty-blocks

// optional override
Expand Down
22 changes: 13 additions & 9 deletions contracts/token/ERC1363/ERC1363.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pragma solidity ^0.5.16;
pragma solidity ^0.6.0;

import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/introspection/ERC165Checker.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/introspection/ERC165.sol";

import "./IERC1363.sol";
import "./IERC1363Receiver.sol";
Expand All @@ -13,7 +14,7 @@ import "./IERC1363Spender.sol";
* @author Vittorio Minacori (https://github.com/vittominacori)
* @dev Implementation of an ERC1363 interface
*/
contract ERC1363 is ERC20, IERC1363 {
contract ERC1363 is ERC20, IERC1363, ERC165 {
using Address for address;

/*
Expand Down Expand Up @@ -42,37 +43,40 @@ contract ERC1363 is ERC20, IERC1363 {
// which can be also obtained as `IERC1363Spender(0).onApprovalReceived.selector`
bytes4 private constant _ERC1363_APPROVED = 0x7b04a2d0;

constructor() public {
constructor (
string memory name,
string memory symbol
) public payable ERC20(name, symbol) {
// register the supported interfaces to conform to ERC1363 via ERC165
_registerInterface(_INTERFACE_ID_ERC1363_TRANSFER);
_registerInterface(_INTERFACE_ID_ERC1363_APPROVE);
}

function transferAndCall(address to, uint256 value) public returns (bool) {
function transferAndCall(address to, uint256 value) public override returns (bool) {
return transferAndCall(to, value, "");
}

function transferAndCall(address to, uint256 value, bytes memory data) public returns (bool) {
function transferAndCall(address to, uint256 value, bytes memory data) public override returns (bool) {
require(transfer(to, value));
require(_checkAndCallTransfer(msg.sender, to, value, data));
return true;
}

function transferFromAndCall(address from, address to, uint256 value) public returns (bool) {
function transferFromAndCall(address from, address to, uint256 value) public override returns (bool) {
return transferFromAndCall(from, to, value, "");
}

function transferFromAndCall(address from, address to, uint256 value, bytes memory data) public returns (bool) {
function transferFromAndCall(address from, address to, uint256 value, bytes memory data) public override returns (bool) {
require(transferFrom(from, to, value));
require(_checkAndCallTransfer(from, to, value, data));
return true;
}

function approveAndCall(address spender, uint256 value) public returns (bool) {
function approveAndCall(address spender, uint256 value) public override returns (bool) {
return approveAndCall(spender, value, "");
}

function approveAndCall(address spender, uint256 value, bytes memory data) public returns (bool) {
function approveAndCall(address spender, uint256 value, bytes memory data) public override returns (bool) {
approve(spender, value);
require(_checkAndCallApprove(spender, value, data));
return true;
Expand Down

0 comments on commit 073e161

Please sign in to comment.