-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from axieinfinity/feature/ERC1155Common
- Loading branch information
Showing
11 changed files
with
230 additions
and
73 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 |
---|---|---|
|
@@ -5,14 +5,14 @@ on: | |
branches: | ||
- main | ||
- dev | ||
- 'feature/*' | ||
- 'features/*' | ||
- "feature/*" | ||
- "features/*" | ||
pull_request: | ||
branches: | ||
- main | ||
- dev | ||
- 'feature/*' | ||
- 'features/*' | ||
- "feature/*" | ||
- "features/*" | ||
|
||
env: | ||
FOUNDRY_PROFILE: ci | ||
|
@@ -23,24 +23,21 @@ jobs: | |
fail-fast: true | ||
|
||
name: Foundry project | ||
runs-on: [self-hosted, dockerize] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- id: 'gh-app' | ||
name: 'Get Token' | ||
uses: 'tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a' #v1.7.0 | ||
with: | ||
app_id: ${{ secrets.GH_APP_ID }} | ||
private_key: ${{ secrets.GH_PRIVATE_KEY }} | ||
|
||
- uses: actions/[email protected] | ||
with: | ||
submodules: recursive | ||
token: ${{ steps.gh-app.outputs.token }} | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Install dependencies | ||
run: | | ||
forge install | ||
id: install | ||
|
||
- name: Run Forge build | ||
run: | | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
forge-std/=lib/forge-std/src/ | ||
ds-test/=lib/forge-std/lib/ds-test/src/ | ||
@openzeppelin/=./node_modules/@openzeppelin/ | ||
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ | ||
@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts |
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 |
---|---|---|
@@ -1,80 +1,145 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
// SPDX-License-Identifier: MIT | ||
// Compatible with OpenZeppelin Contracts ^5.0.0 | ||
pragma solidity ^0.8.20; | ||
|
||
import { IERC165 } from "@openzeppelin/contracts/interfaces/IERC165.sol"; | ||
import { AccessControlEnumerable } from "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; | ||
import { ERC1155 } from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; | ||
|
||
import { ERC1155Burnable } from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol"; | ||
import { ERC1155Pausable } from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Pausable.sol"; | ||
import { ERC1155Supply } from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol"; | ||
import { AccessControlEnumerable } from "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; | ||
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; | ||
import { IERC1155Common } from "./interfaces/IERC1155Common.sol"; | ||
|
||
contract ERC1155Common is AccessControlEnumerable, ERC1155, ERC1155Supply, IERC1155Common { | ||
contract ERC1155Common is | ||
ERC1155, | ||
AccessControlEnumerable, | ||
ERC1155Pausable, | ||
ERC1155Burnable, | ||
ERC1155Supply, | ||
IERC1155Common | ||
{ | ||
using Strings for uint256; | ||
|
||
bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE"); | ||
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); | ||
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); | ||
|
||
string private _name; | ||
string private _symbol; | ||
|
||
constructor(string memory name_, string memory symbol_, string memory baseTokenURI, address[] memory minters) | ||
payable | ||
ERC1155(baseTokenURI) | ||
{ | ||
constructor(address admin, string memory name_, string memory symbol_, string memory uri_) ERC1155(uri_) { | ||
_grantRole(DEFAULT_ADMIN_ROLE, admin); | ||
_grantRole(PAUSER_ROLE, admin); | ||
_grantRole(MINTER_ROLE, admin); | ||
_grantRole(URI_SETTER_ROLE, admin); | ||
|
||
_name = name_; | ||
_symbol = symbol_; | ||
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender()); | ||
bytes32 minterRole = MINTER_ROLE; | ||
|
||
uint256 length = minters.length; | ||
for (uint256 i; i < length;) { | ||
_grantRole(minterRole, minters[i]); | ||
unchecked { | ||
++i; | ||
} | ||
} | ||
} | ||
|
||
function uri(uint256 tokenId) public view override returns (string memory) { | ||
string memory _uri = super.uri(tokenId); | ||
return string(abi.encodePacked(_uri, tokenId.toString())); | ||
/** | ||
* @dev Set the URI for all token types. | ||
* Requirements: | ||
* - the caller must have the `URI_SETTER_ROLE`. | ||
*/ | ||
function setURI(string memory newURI) external onlyRole(URI_SETTER_ROLE) { | ||
_setURI(newURI); | ||
} | ||
|
||
/** | ||
* @dev Pauses all token transfers. | ||
* Requirements: | ||
* - the caller must have the `PAUSER_ROLE`. | ||
*/ | ||
function pause() external onlyRole(PAUSER_ROLE) { | ||
_pause(); | ||
} | ||
|
||
function name() external view returns (string memory) { | ||
return _name; | ||
/** | ||
* @dev Unpauses all token transfers. | ||
* Requirements: | ||
* - the caller must have the `PAUSER_ROLE`. | ||
*/ | ||
function unpause() external onlyRole(PAUSER_ROLE) { | ||
_unpause(); | ||
} | ||
|
||
function symbol() external view returns (string memory) { | ||
return _symbol; | ||
/// @inheritdoc IERC1155Common | ||
function mint(address account, uint256 id, uint256 amount, bytes calldata data) public virtual onlyRole(MINTER_ROLE) { | ||
_mint(account, id, amount, data); | ||
} | ||
|
||
/// @inheritdoc IERC1155Common | ||
function mintBatch(address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) | ||
public | ||
virtual | ||
onlyRole(MINTER_ROLE) | ||
{ | ||
_mintBatch(to, ids, amounts, data); | ||
} | ||
|
||
/** | ||
* @dev Mint single token to multiple addresses. | ||
* Requirements: | ||
* - the caller must have the `MINTER_ROLE`. | ||
*/ | ||
function bulkMint(uint256 id, address[] calldata tos, uint256[] calldata amounts, bytes[] calldata datas) | ||
public | ||
virtual | ||
onlyRole(MINTER_ROLE) | ||
{ | ||
uint256 length = tos.length; | ||
require(length != 0 && length == amounts.length && length == datas.length, "ERC1155: invalid array lengths"); | ||
|
||
for (uint256 i; i < length; ++i) { | ||
_mint(tos[i], id, amounts[i], datas[i]); | ||
} | ||
} | ||
|
||
/** | ||
* @dev Sets the base URI for metadata of ERC1155 tokens. | ||
* @param uri_ The new base URI. | ||
* @dev See {ERC1155-uri}. | ||
*/ | ||
function setURI(string calldata uri_) external onlyRole(DEFAULT_ADMIN_ROLE) { | ||
_setURI(uri_); | ||
function uri(uint256 tokenId) public view virtual override returns (string memory) { | ||
string memory uri_ = super.uri(tokenId); | ||
return string.concat(uri_, tokenId.toString()); | ||
} | ||
|
||
/// @inheritdoc IERC1155Common | ||
function mint(address to, uint256 id, uint256 amount) external onlyRole(MINTER_ROLE) { | ||
_mint(to, id, amount, ""); | ||
function name() public view virtual returns (string memory) { | ||
return _name; | ||
} | ||
|
||
/// @inheritdoc IERC1155Common | ||
function batchMint(address to, uint256[] calldata ids, uint256[] calldata amounts) external onlyRole(MINTER_ROLE) { | ||
_mintBatch(to, ids, amounts, ""); | ||
function symbol() public view virtual returns (string memory) { | ||
return _symbol; | ||
} | ||
|
||
function supportsInterface(bytes4 interfaceId) public view override(ERC1155, AccessControlEnumerable) returns (bool) { | ||
/** | ||
* @dev See {ERC165-supportsInterface}. | ||
*/ | ||
function supportsInterface(bytes4 interfaceId) | ||
public | ||
view | ||
virtual | ||
override(IERC165, ERC1155, AccessControlEnumerable) | ||
returns (bool) | ||
{ | ||
return interfaceId == type(IERC1155Common).interfaceId || super.supportsInterface(interfaceId); | ||
} | ||
|
||
/** | ||
* @dev See {ERC1155-_beforeTokenTransfer}. | ||
*/ | ||
function _beforeTokenTransfer( | ||
address operator, | ||
address from, | ||
address to, | ||
uint256[] memory ids, | ||
uint256[] memory amounts, | ||
bytes memory data | ||
) internal virtual override(ERC1155, ERC1155Supply) { | ||
) internal virtual override(ERC1155, ERC1155Pausable, ERC1155Supply) { | ||
super._beforeTokenTransfer(operator, from, to, ids, amounts, data); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,20 +1,51 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
interface IERC1155Common { | ||
import { IAccessControlEnumerable } from "@openzeppelin/contracts/access/IAccessControlEnumerable.sol"; | ||
import { IERC1155 } from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; | ||
|
||
interface IERC1155Common is IAccessControlEnumerable, IERC1155 { | ||
/// @dev Return the name of the collection. | ||
function name() external view returns (string memory); | ||
|
||
/// @dev Return the symbol of the collection. | ||
function symbol() external view returns (string memory); | ||
|
||
/** | ||
* @dev Mints a single ERC1155 token and assigns it to the specified address. | ||
* | ||
* Requirements: | ||
* - the caller must have the `MINTER_ROLE`. | ||
* | ||
* @param to The address to which the minted token will be assigned. | ||
* @param id The ID of the token to mint. | ||
* @param amount The amount of tokens to mint. | ||
* @param data Additional data with no specified format. | ||
*/ | ||
function mint(address to, uint256 id, uint256 amount) external; | ||
function mint(address to, uint256 id, uint256 amount, bytes calldata data) external; | ||
|
||
/** | ||
* @dev Mints multiple ERC1155 tokens and assigns them to the specified address. | ||
* | ||
* Requirements: | ||
* - the caller must have the `MINTER_ROLE`. | ||
* | ||
* @param to The address to which the minted tokens will be assigned. | ||
* @param ids The IDs of the tokens to mint. | ||
* @param amounts The amounts of tokens to mint. | ||
* @param data Additional data with no specified format. | ||
*/ | ||
function mintBatch(address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external; | ||
|
||
/** | ||
* @dev Mint single token to multiple addresses. | ||
* Requirements: | ||
* - the caller must have the `MINTER_ROLE`. | ||
* | ||
* @param id The ID of the token to mint. | ||
* @param tos The addresses to which the minted tokens will be assigned. | ||
* @param amounts The amounts of tokens to mint. | ||
* @param datas Additional data with no specified format. | ||
*/ | ||
function batchMint(address to, uint256[] calldata ids, uint256[] calldata amounts) external; | ||
function bulkMint(uint256 id, address[] calldata tos, uint256[] calldata amounts, bytes[] calldata datas) 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
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
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
Oops, something went wrong.