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

Supports interface uses view #43

Merged
merged 5 commits into from
Aug 11, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/contracts/mocks/ERC20Mock.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma solidity ^0.8.0;

import "@0xsequence/erc-1155/contracts/interfaces/IERC20.sol";
import "@0xsequence/erc-1155/contracts/interfaces/IERC165.sol";

/**
* @title Standard ERC20 token
Expand All @@ -14,7 +15,7 @@
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/
contract ERC20 is IERC20 {
contract ERC20 is IERC20, IERC165 {
mapping (address => uint256) private _balances;

mapping (address => mapping (address => uint256)) private _allowed;
Expand Down Expand Up @@ -122,7 +123,7 @@
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));

Check warning on line 126 in src/contracts/mocks/ERC20Mock.sol

View workflow job for this annotation

GitHub Actions / Solidity lint

Provide an error message for require

_balances[from] -= value;
_balances[to] += value;
Expand All @@ -137,7 +138,7 @@
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0));

Check warning on line 141 in src/contracts/mocks/ERC20Mock.sol

View workflow job for this annotation

GitHub Actions / Solidity lint

Provide an error message for require

_totalSupply += value;
_balances[account] += value;
Expand All @@ -151,7 +152,7 @@
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0));

Check warning on line 155 in src/contracts/mocks/ERC20Mock.sol

View workflow job for this annotation

GitHub Actions / Solidity lint

Provide an error message for require

_totalSupply -= value;
_balances[account] -= value;
Expand All @@ -165,8 +166,8 @@
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));

Check warning on line 169 in src/contracts/mocks/ERC20Mock.sol

View workflow job for this annotation

GitHub Actions / Solidity lint

Provide an error message for require
require(owner != address(0));

Check warning on line 170 in src/contracts/mocks/ERC20Mock.sol

View workflow job for this annotation

GitHub Actions / Solidity lint

Provide an error message for require

_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
Expand All @@ -185,10 +186,19 @@
_approve(account, msg.sender, _allowed[account][msg.sender] - value);
}

/**
* @dev Indicates whether a contract implements the ERC-20 functions.
* @param interfaceID The ERC-165 interface ID that is queried for support.
* @return Whether ERC-165 or ERC-20 interfaces are supported.
*/
function supportsInterface(bytes4 interfaceID) public override view returns (bool) {
return interfaceID == type(IERC165).interfaceId || interfaceID == type(IERC20).interfaceId;
}

}


contract ERC20Mock is ERC20 {
constructor() public { }

function mockMint(address _address, uint256 _amount) public {
_mint(_address, _amount);
Expand Down
6 changes: 3 additions & 3 deletions src/contracts/wrapper/ERC20Wrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
|__________________________________*/

// Register ETH as ID #1 and address 0x1
constructor() public {
constructor() {
addressToID[ETH_ADDRESS] = ETH_ID;
IDtoAddress[ETH_ID] = ETH_ADDRESS;
}
Expand Down Expand Up @@ -143,7 +143,7 @@

} else {
require(_to != address(0), "ERC20Wrapper#withdraw: INVALID_RECIPIENT");
(bool success, ) = _to.call{value: _value}("");

Check warning on line 146 in src/contracts/wrapper/ERC20Wrapper.sol

View workflow job for this annotation

GitHub Actions / Solidity lint

Avoid to use low level calls
require(success, "ERC20Wrapper#withdraw: TRANSFER_FAILED");
}

Expand Down Expand Up @@ -260,7 +260,7 @@
}

// not sure what was returned: dont mark as success
default { }

Check warning on line 263 in src/contracts/wrapper/ERC20Wrapper.sol

View workflow job for this annotation

GitHub Actions / Solidity lint

Code contains empty blocks

}

Expand All @@ -274,10 +274,10 @@
* This function MUST NOT consume more than 5,000 gas.
* @return Wheter ERC-165 or ERC1155TokenReceiver interfaces are supported.
*/
function supportsInterface(bytes4 interfaceID) public override pure returns (bool) {
function supportsInterface(bytes4 interfaceID) public override view returns (bool) {
return interfaceID == type(IERC165).interfaceId ||
interfaceID == type(IERC1155).interfaceId ||
interfaceID == type(IERC1155TokenReceiver).interfaceId;
interfaceID == type(IERC1155TokenReceiver).interfaceId;
}

}
10 changes: 5 additions & 5 deletions src/contracts/wrapper/MetaERC20Wrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
|__________________________________*/

// Register ETH as ID #1 and address 0x1
constructor() public {
constructor() {
addressToID[ETH_ADDRESS] = ETH_ID;
IDtoAddress[ETH_ID] = ETH_ADDRESS;
}
Expand Down Expand Up @@ -144,7 +144,7 @@

} else {
require(_to != address(0), "MetaERC20Wrapper#withdraw: INVALID_RECIPIENT");
(bool success, ) = _to.call{value: _value}("");

Check warning on line 147 in src/contracts/wrapper/MetaERC20Wrapper.sol

View workflow job for this annotation

GitHub Actions / Solidity lint

Avoid to use low level calls
require(success, "MetaERC20Wrapper#withdraw: TRANSFER_FAILED");
}

Expand Down Expand Up @@ -261,7 +261,7 @@
}

// not sure what was returned: dont mark as success
default { }

Check warning on line 264 in src/contracts/wrapper/MetaERC20Wrapper.sol

View workflow job for this annotation

GitHub Actions / Solidity lint

Code contains empty blocks

}

Expand All @@ -270,15 +270,15 @@

/**
* @notice Indicates whether a contract implements the `ERC1155TokenReceiver` functions and so can accept ERC1155 token types.
* @param interfaceID The ERC-165 interface ID that is queried for support.s
* @param interfaceID The ERC-165 interface ID that is queried for support.
* @dev This function MUST return true if it implements the ERC1155TokenReceiver interface and ERC-165 interface.
* This function MUST NOT consume more than 5,000 gas.
* @return Wheter ERC-165 or ERC1155TokenReceiver interfaces are supported.
* @return Whether ERC-165 or ERC1155TokenReceiver interfaces are supported.
*/
function supportsInterface(bytes4 interfaceID) public override pure returns (bool) {
function supportsInterface(bytes4 interfaceID) public override view returns (bool) {
return interfaceID == type(IERC165).interfaceId ||
interfaceID == type(IERC1155).interfaceId ||
interfaceID == type(IERC1155TokenReceiver).interfaceId;
interfaceID == type(IERC1155TokenReceiver).interfaceId;
}

}
4 changes: 2 additions & 2 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0xsequence/erc20-meta-token",
"version": "4.0.1",
"version": "4.0.2",
"description": "General ERC20 to ERC1155 Token Wrapper Contract",
"repository": "https://github.com/0xsequence/erc20-meta-token",
"homepage": "https://sequence.build",
Expand All @@ -19,7 +19,7 @@
"ethers": "^5.0.32"
},
"dependencies": {
"@0xsequence/erc-1155": "^4.0.1"
"@0xsequence/erc-1155": "^4.0.2"
},
"devDependencies": {}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@0xsequence/erc-1155@^4.0.1":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@0xsequence/erc-1155/-/erc-1155-4.0.1.tgz#c991fe06b6ae385146e69cd9d1c4982b06487c10"
integrity sha512-KFLxBfiocOuHmPUkGYiWw5fLZ8uCDhXhcyzFFv8oe/KWXdxL37NTD7n6CmMSRiUxr4qaXuFV5u38vPFWFdOY0g==
"@0xsequence/erc-1155@^4.0.2":
version "4.0.2"
resolved "https://registry.yarnpkg.com/@0xsequence/erc-1155/-/erc-1155-4.0.2.tgz#619f1151133aa1f3627443e575bf26deb22c1055"
integrity sha512-76r4lMBu75AfkwIaApW2pjCY4JikuPa+y7RPdvG8fnInS3QRLwrUUviiG7BLc4oiJ7quQBBj/kM6e6Mw/ezJFQ==
optionalDependencies:
"@ethersproject/abi" "^5.7.0"
"@ethersproject/providers" "^5.7.2"
Expand Down