From 3151b19e3e02f09f9394f71d555f15ad3576ba95 Mon Sep 17 00:00:00 2001 From: Andrea Franz Date: Wed, 30 Sep 2020 12:17:50 +0200 Subject: [PATCH] Revert "downgrade solidity version to 0.5.16 in contracts" This reverts commit 9f4a48e2827765d4de3c6c1af08a301f04fdea8b. --- contracts/.gitkeep | 0 contracts/Bucket.sol | 12 ++++++------ contracts/ERC20Bucket.sol | 8 ++++---- contracts/ERC20BucketFactory.sol | 2 +- contracts/NFTBucket.sol | 12 ++++++------ contracts/NFTBucketFactory.sol | 2 +- contracts/Proxy.sol | 4 ++-- contracts/erc20/IERC20.sol | 2 +- contracts/erc20/IERC20Detailed.sol | 8 ++++---- contracts/erc20/StandardToken.sol | 8 +++++++- contracts/erc20/TestToken.sol | 5 ++--- contracts/erc721/IERC165.sol | 2 +- contracts/erc721/IERC721.sol | 4 ++-- contracts/erc721/IERC721Metadata.sol | 2 +- contracts/erc721/IERC721Receiver.sol | 4 ++-- contracts/erc721/TestNFT.sol | 22 +++++++++++----------- package.json => scripts/package.json | 0 yarn.lock => scripts/yarn.lock | 0 18 files changed, 51 insertions(+), 46 deletions(-) create mode 100644 contracts/.gitkeep rename package.json => scripts/package.json (100%) rename yarn.lock => scripts/yarn.lock (100%) diff --git a/contracts/.gitkeep b/contracts/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/contracts/Bucket.sol b/contracts/Bucket.sol index e247d1f..373573b 100644 --- a/contracts/Bucket.sol +++ b/contracts/Bucket.sol @@ -1,7 +1,7 @@ -pragma solidity ^0.5.16; +pragma solidity ^0.6.1; pragma experimental ABIEncoderV2; -contract Bucket { +abstract contract Bucket { bool initialized; address payable public owner; address public tokenAddress; @@ -50,7 +50,7 @@ contract Bucket { startTime = _startTime; expirationTime = _expirationTime; maxTxDelayInBlocks = _maxTxDelayInBlocks; - owner = address(uint160(_owner)); + owner = payable(_owner); DOMAIN_SEPARATOR = keccak256(abi.encode( EIP712DOMAIN_TYPEHASH, @@ -63,11 +63,11 @@ contract Bucket { initialized = true; } - function transferRedeemable(uint256 data, Redeem memory redeem) internal; + function transferRedeemable(uint256 data, Redeem memory redeem) virtual internal; - function transferRedeemablesToOwner() internal; + function transferRedeemablesToOwner() virtual internal; - function bucketType() external returns (uint256); + function bucketType() virtual external returns (uint256); function redeem(Redeem calldata _redeem, bytes calldata _sig) external { // validate Redeem diff --git a/contracts/ERC20Bucket.sol b/contracts/ERC20Bucket.sol index e2c68b5..1bf1e6e 100644 --- a/contracts/ERC20Bucket.sol +++ b/contracts/ERC20Bucket.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.5.16; +pragma solidity ^0.6.1; pragma experimental ABIEncoderV2; import "./Bucket.sol"; @@ -41,18 +41,18 @@ contract ERC20Bucket is Bucket { redeemableSupply += amount; } - function transferRedeemable(uint256 data, Redeem memory redeem) internal { + function transferRedeemable(uint256 data, Redeem memory redeem) internal override { require(redeemableSupply >= data, "not enough redeemable supply"); redeemableSupply -= data; IERC20(tokenAddress).transfer(redeem.receiver, data); } - function transferRedeemablesToOwner() internal { + function transferRedeemablesToOwner() internal override { bool success = IERC20(tokenAddress).transfer(owner, this.totalSupply()); assert(success); } - function bucketType() external returns (uint256) { + function bucketType() external override returns (uint256) { return 20; } } diff --git a/contracts/ERC20BucketFactory.sol b/contracts/ERC20BucketFactory.sol index 95f8192..c353b3c 100644 --- a/contracts/ERC20BucketFactory.sol +++ b/contracts/ERC20BucketFactory.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.5.16; +pragma solidity ^0.6.1; import "./ERC20Bucket.sol"; import "./Proxy.sol"; diff --git a/contracts/NFTBucket.sol b/contracts/NFTBucket.sol index f536205..7969d07 100644 --- a/contracts/NFTBucket.sol +++ b/contracts/NFTBucket.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.5.16; +pragma solidity ^0.6.1; pragma experimental ABIEncoderV2; import "./Bucket.sol"; @@ -15,24 +15,24 @@ contract NFTBucket is Bucket, IERC165, IERC721Receiver { uint256 _expirationTime, uint256 _maxTxDelayInBlocks) Bucket("KeycardNFTBucket", _tokenAddress, _startTime, _expirationTime, _maxTxDelayInBlocks) public {} - function transferRedeemable(uint256 data, Redeem memory redeem) internal { + function transferRedeemable(uint256 data, Redeem memory redeem) internal override { IERC721(tokenAddress).safeTransferFrom(address(this), redeem.receiver, data); } - function transferRedeemablesToOwner() internal { + function transferRedeemablesToOwner() internal override { IERC721(tokenAddress).setApprovalForAll(owner, true); assert(IERC721(tokenAddress).isApprovedForAll(address(this), owner)); } - function bucketType() external returns (uint256) { + function bucketType() external override returns (uint256) { return 721; } - function supportsInterface(bytes4 interfaceID) external view returns (bool) { + function supportsInterface(bytes4 interfaceID) external override(IERC165) view returns (bool) { return interfaceID == _ERC721_RECEIVED; } - function onERC721Received(address _operator, address _from, uint256 _tokenID, bytes calldata _data) external returns(bytes4) { + function onERC721Received(address _operator, address _from, uint256 _tokenID, bytes calldata _data) external override(IERC721Receiver) returns(bytes4) { require(msg.sender == tokenAddress, "only the NFT contract can call this"); require((_operator == owner) || (_from == owner), "only the owner can create redeemables"); require(_data.length == 52, "invalid data field"); diff --git a/contracts/NFTBucketFactory.sol b/contracts/NFTBucketFactory.sol index 66910ca..15d7e0b 100644 --- a/contracts/NFTBucketFactory.sol +++ b/contracts/NFTBucketFactory.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.5.16; +pragma solidity ^0.6.1; import "./NFTBucket.sol"; import "./Proxy.sol"; diff --git a/contracts/Proxy.sol b/contracts/Proxy.sol index af7933f..b90e19e 100644 --- a/contracts/Proxy.sol +++ b/contracts/Proxy.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.5.16; +pragma solidity ^0.6.1; contract Proxy { /** @@ -23,7 +23,7 @@ contract Proxy { * @dev Fallback function allowing to perform a delegatecall to the given implementation. * This function will return whatever the implementation call returns */ - function() external payable { + fallback() external payable { assembly { // solium-disable-line let contractLogic := sload(0xc5f16f0fcc639fa48a6947836d9850f504798523bf8c9a3a87d5876cf622bcf7) calldatacopy(0x0, 0x0, calldatasize()) diff --git a/contracts/erc20/IERC20.sol b/contracts/erc20/IERC20.sol index 27d3ab3..3fb727d 100644 --- a/contracts/erc20/IERC20.sol +++ b/contracts/erc20/IERC20.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.5.16; +pragma solidity ^0.6.1; // https://github.com/ethereum/EIPs/issues/20 diff --git a/contracts/erc20/IERC20Detailed.sol b/contracts/erc20/IERC20Detailed.sol index 3865937..d76f52e 100644 --- a/contracts/erc20/IERC20Detailed.sol +++ b/contracts/erc20/IERC20Detailed.sol @@ -1,9 +1,9 @@ -pragma solidity ^0.5.16; +pragma solidity >=0.5.0 <0.7.0; import "./IERC20.sol"; -contract IERC20Detailed is IERC20 { - function symbol() public view returns (string memory); - function decimals() public view returns (uint8); +abstract contract IERC20Detailed is IERC20 { + function symbol() virtual public view returns (string memory); + function decimals() virtual public view returns (uint8); } diff --git a/contracts/erc20/StandardToken.sol b/contracts/erc20/StandardToken.sol index 9fc0b23..9c15bcf 100644 --- a/contracts/erc20/StandardToken.sol +++ b/contracts/erc20/StandardToken.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.5.16; +pragma solidity ^0.6.1; import "./IERC20.sol"; @@ -15,6 +15,7 @@ contract StandardToken is IERC20 { uint256 _value ) external + override(IERC20) returns (bool success) { return transfer(msg.sender, _to, _value); @@ -22,6 +23,7 @@ contract StandardToken is IERC20 { function approve(address _spender, uint256 _value) external + override(IERC20) returns (bool success) { allowed[msg.sender][_spender] = _value; @@ -35,6 +37,7 @@ contract StandardToken is IERC20 { uint256 _value ) external + override(IERC20) returns (bool success) { if (balances[_from] >= _value && @@ -50,6 +53,7 @@ contract StandardToken is IERC20 { function allowance(address _owner, address _spender) external view + override(IERC20) returns (uint256 remaining) { return allowed[_owner][_spender]; @@ -58,6 +62,7 @@ contract StandardToken is IERC20 { function balanceOf(address _owner) external view + override(IERC20) returns (uint256 balance) { return balances[_owner]; @@ -66,6 +71,7 @@ contract StandardToken is IERC20 { function totalSupply() external view + override(IERC20) returns(uint256 currentTotalSupply) { return supply; diff --git a/contracts/erc20/TestToken.sol b/contracts/erc20/TestToken.sol index ffe37c9..7007ca3 100644 --- a/contracts/erc20/TestToken.sol +++ b/contracts/erc20/TestToken.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.5.16; +pragma solidity ^0.6.1; import "./StandardToken.sol"; @@ -16,8 +16,7 @@ contract TestToken is StandardToken { _decimals = decimals; } - // fallback - function() external { + fallback() external { uint256 amount = 5000; mint(amount * uint256(10)**_decimals); } diff --git a/contracts/erc721/IERC165.sol b/contracts/erc721/IERC165.sol index 1874cb9..f4e686f 100644 --- a/contracts/erc721/IERC165.sol +++ b/contracts/erc721/IERC165.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.5.16; +pragma solidity ^0.6.1; interface IERC165 { function supportsInterface(bytes4 interfaceId) external view returns (bool); diff --git a/contracts/erc721/IERC721.sol b/contracts/erc721/IERC721.sol index a0f2538..fa09845 100644 --- a/contracts/erc721/IERC721.sol +++ b/contracts/erc721/IERC721.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.5.16; +pragma solidity ^0.6.1; /** * @dev Required interface of an ERC721 compliant contract. @@ -22,4 +22,4 @@ interface IERC721 { function isApprovedForAll(address owner, address operator) external view returns (bool); function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; -} +} \ No newline at end of file diff --git a/contracts/erc721/IERC721Metadata.sol b/contracts/erc721/IERC721Metadata.sol index 690f8c4..1c15944 100644 --- a/contracts/erc721/IERC721Metadata.sol +++ b/contracts/erc721/IERC721Metadata.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.5.16; +pragma solidity ^0.6.1; /// @title ERC-721 Non-Fungible Token Standard, optional metadata extension /// @dev See https://eips.ethereum.org/EIPS/eip-721 diff --git a/contracts/erc721/IERC721Receiver.sol b/contracts/erc721/IERC721Receiver.sol index b854ef7..f598294 100644 --- a/contracts/erc721/IERC721Receiver.sol +++ b/contracts/erc721/IERC721Receiver.sol @@ -1,5 +1,5 @@ -pragma solidity ^0.5.16; +pragma solidity ^0.6.1; interface IERC721Receiver { function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4); -} +} \ No newline at end of file diff --git a/contracts/erc721/TestNFT.sol b/contracts/erc721/TestNFT.sol index f19ede1..4289688 100644 --- a/contracts/erc721/TestNFT.sol +++ b/contracts/erc721/TestNFT.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.5.16; +pragma solidity ^0.6.1; import "./IERC721.sol"; import "./IERC721Receiver.sol"; @@ -14,19 +14,19 @@ contract TestNFT is IERC165, IERC721 { bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; - function balanceOf(address owner) public view returns (uint256) { + function balanceOf(address owner) public override(IERC721) view returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _ownedTokensCount[owner]; } - function ownerOf(uint256 tokenId) public view returns (address) { + function ownerOf(uint256 tokenId) public override(IERC721) view returns (address) { address owner = _tokenOwner[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } - function approve(address to, uint256 tokenId) public { + function approve(address to, uint256 tokenId) public override(IERC721) { address owner = ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); @@ -38,34 +38,34 @@ contract TestNFT is IERC165, IERC721 { emit Approval(owner, to, tokenId); } - function getApproved(uint256 tokenId) public view returns (address) { + function getApproved(uint256 tokenId) public override(IERC721) view returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } - function setApprovalForAll(address to, bool approved) public { + function setApprovalForAll(address to, bool approved) public override(IERC721) { require(to != msg.sender, "ERC721: approve to caller"); _operatorApprovals[msg.sender][to] = approved; emit ApprovalForAll(msg.sender, to, approved); } - function isApprovedForAll(address owner, address operator) public view returns (bool) { + function isApprovedForAll(address owner, address operator) public override(IERC721) view returns (bool) { return _operatorApprovals[owner][operator]; } - function transferFrom(address from, address to, uint256 tokenId) public { + function transferFrom(address from, address to, uint256 tokenId) public override(IERC721) { require(_isApprovedOrOwner(msg.sender, tokenId), "ERC721: transfer caller is not owner nor approved"); _transferFrom(from, to, tokenId); } - function safeTransferFrom(address from, address to, uint256 tokenId) public { + function safeTransferFrom(address from, address to, uint256 tokenId) public override(IERC721) { safeTransferFrom(from, to, tokenId, ""); } - function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public { + function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public override(IERC721) { transferFrom(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } @@ -131,7 +131,7 @@ contract TestNFT is IERC165, IERC721 { return size > 0; } - function supportsInterface(bytes4 interfaceID) external view returns (bool) { + function supportsInterface(bytes4 interfaceID) external override(IERC165) view returns (bool) { return interfaceID == _INTERFACE_ID_ERC721; } } diff --git a/package.json b/scripts/package.json similarity index 100% rename from package.json rename to scripts/package.json diff --git a/yarn.lock b/scripts/yarn.lock similarity index 100% rename from yarn.lock rename to scripts/yarn.lock