-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge the develop branch to the master branch, preparation to v2.0.0-rc2
This update for the master branch contains the following set of changes: * [Improvement] Add support for ERC1155 (#28), closes #24 * [Other] Fix stack too deep error in coverage
- Loading branch information
Showing
57 changed files
with
2,513 additions
and
1,082 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
pragma solidity 0.7.5; | ||
|
||
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; | ||
|
||
interface IBurnableMintableERC1155Token is IERC1155 { | ||
function mint( | ||
address _to, | ||
uint256[] calldata _tokenIds, | ||
uint256[] calldata _values | ||
) external; | ||
|
||
function burn(uint256[] calldata _tokenId, uint256[] calldata _values) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
pragma solidity 0.7.5; | ||
|
||
/** | ||
Note: The ERC-165 identifier for this interface is 0x4e2312e0. | ||
*/ | ||
interface IERC1155TokenReceiver { | ||
/** | ||
@notice Handle the receipt of a single ERC1155 token type. | ||
@dev An ERC1155-compliant smart contract MUST call this function on the token recipient contract, at the end of a `safeTransferFrom` after the balance has been updated. | ||
This function MUST return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` (i.e. 0xf23a6e61) if it accepts the transfer. | ||
This function MUST revert if it rejects the transfer. | ||
Return of any other value than the prescribed keccak256 generated value MUST result in the transaction being reverted by the caller. | ||
@param _operator The address which initiated the transfer (i.e. msg.sender) | ||
@param _from The address which previously owned the token | ||
@param _id The ID of the token being transferred | ||
@param _value The amount of tokens being transferred | ||
@param _data Additional data with no specified format | ||
@return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` | ||
*/ | ||
function onERC1155Received( | ||
address _operator, | ||
address _from, | ||
uint256 _id, | ||
uint256 _value, | ||
bytes calldata _data | ||
) external returns (bytes4); | ||
|
||
/** | ||
@notice Handle the receipt of multiple ERC1155 token types. | ||
@dev An ERC1155-compliant smart contract MUST call this function on the token recipient contract, at the end of a `safeBatchTransferFrom` after the balances have been updated. | ||
This function MUST return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` (i.e. 0xbc197c81) if it accepts the transfer(s). | ||
This function MUST revert if it rejects the transfer(s). | ||
Return of any other value than the prescribed keccak256 generated value MUST result in the transaction being reverted by the caller. | ||
@param _operator The address which initiated the batch transfer (i.e. msg.sender) | ||
@param _from The address which previously owned the token | ||
@param _ids An array containing ids of each token being transferred (order and length must match _values array) | ||
@param _values An array containing amounts of each token being transferred (order and length must match _ids array) | ||
@param _data Additional data with no specified format | ||
@return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` | ||
*/ | ||
function onERC1155BatchReceived( | ||
address _operator, | ||
address _from, | ||
uint256[] calldata _ids, | ||
uint256[] calldata _values, | ||
bytes calldata _data | ||
) external returns (bytes4); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
pragma solidity 0.7.5; | ||
|
||
contract ERC1155ReceiverMock { | ||
function onERC1155Received( | ||
address _operator, | ||
address _from, | ||
uint256 _id, | ||
uint256 _value, | ||
bytes calldata _data | ||
) external returns (bytes4) { | ||
(_operator, _from, _id, _value, _data); | ||
return msg.sig; | ||
} | ||
|
||
function onERC1155BatchReceived( | ||
address _operator, | ||
address _from, | ||
uint256[] calldata _ids, | ||
uint256[] calldata _values, | ||
bytes calldata _data | ||
) external returns (bytes4) { | ||
(_operator, _from, _ids, _values, _data); | ||
return msg.sig; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
pragma solidity 0.7.5; | ||
|
||
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; | ||
import "../interfaces/IOwnable.sol"; | ||
import "../interfaces/IBurnableMintableERC1155Token.sol"; | ||
|
||
/** | ||
* @title ERC1155BridgeToken | ||
* @dev template token contract for bridged ERC1155 tokens. | ||
*/ | ||
contract ERC1155BridgeToken is ERC1155, IBurnableMintableERC1155Token { | ||
string public name; | ||
string public symbol; | ||
|
||
// Optional mapping for token URIs | ||
mapping(uint256 => string) private tokenURIs; | ||
// Base URI | ||
string private baseURI; | ||
|
||
address public bridgeContract; | ||
|
||
constructor( | ||
string memory _name, | ||
string memory _symbol, | ||
address _bridgeContract | ||
) ERC1155("") { | ||
name = _name; | ||
symbol = _symbol; | ||
bridgeContract = _bridgeContract; | ||
} | ||
|
||
/** | ||
* @dev Throws if sender is not a bridge contract. | ||
*/ | ||
modifier onlyBridge() { | ||
require(msg.sender == bridgeContract); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev Throws if sender is not a bridge contract or bridge contract owner. | ||
*/ | ||
modifier onlyOwner() { | ||
require(msg.sender == bridgeContract || msg.sender == IOwnable(bridgeContract).owner()); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev Mint a batch of new ERC1155 tokens. | ||
* Only bridge contract is authorized to mint tokens. | ||
* @param _to address of the newly created token owner. | ||
* @param _tokenIds array of token ids to mint. | ||
* @param _values array of corresponding mint amounts for each tokenId. | ||
*/ | ||
function mint( | ||
address _to, | ||
uint256[] memory _tokenIds, | ||
uint256[] memory _values | ||
) external override onlyBridge { | ||
_mintBatch(_to, _tokenIds, _values, new bytes(0)); | ||
} | ||
|
||
/** | ||
* @dev Burns a batch of ERC1155 tokens. | ||
* Only bridge contract is authorized to burn tokens. | ||
* @param _tokenIds array of token ids to burn. | ||
* @param _values array of corresponding burn amounts for each tokenId. | ||
*/ | ||
function burn(uint256[] memory _tokenIds, uint256[] memory _values) external override onlyBridge { | ||
_burnBatch(msg.sender, _tokenIds, _values); | ||
} | ||
|
||
/** | ||
* @dev Updates the bridge contract address. | ||
* Can be called by bridge owner after token contract was instantiated. | ||
* @param _bridgeContract address of the new bridge contract. | ||
*/ | ||
function setBridgeContract(address _bridgeContract) external onlyOwner { | ||
require(_bridgeContract != address(0)); | ||
bridgeContract = _bridgeContract; | ||
} | ||
|
||
/** | ||
* @dev Sets the base URI for all tokens. | ||
* Can be called by bridge owner after token contract was instantiated. | ||
* @param _baseURI new base URI. | ||
*/ | ||
function setBaseURI(string calldata _baseURI) external onlyOwner { | ||
baseURI = _baseURI; | ||
} | ||
|
||
/** | ||
* @dev Sets the URI for the particular token. | ||
* Can be called by bridge owner after token bridging. | ||
* @param _tokenId URI for the bridged token metadata. | ||
* @param _tokenURI new token URI. | ||
*/ | ||
function setTokenURI(uint256 _tokenId, string calldata _tokenURI) external onlyOwner { | ||
tokenURIs[_tokenId] = _tokenURI; | ||
} | ||
|
||
/** | ||
* @dev Tells the metadata URI for the particular tokenId. | ||
* @param _tokenId unique token id for which to return metadata URI. | ||
* @return token metadata URI. | ||
*/ | ||
function uri(uint256 _tokenId) external view override returns (string memory) { | ||
string memory tokenURI = tokenURIs[_tokenId]; | ||
string memory base = baseURI; | ||
|
||
// If there is no base URI, return the token URI. | ||
if (bytes(base).length == 0) { | ||
return tokenURI; | ||
} | ||
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). | ||
return string(abi.encodePacked(base, tokenURI)); | ||
} | ||
} |
Oops, something went wrong.