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

feat: resolve conflicts caused by merging with release/v0.2.0 branch #25

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/checkout@v4.1.1
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: |
Expand Down
145 changes: 145 additions & 0 deletions src/ERC1155Common.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;

import { AccessControlEnumerable } from "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
import { IERC165 } from "@openzeppelin/contracts/interfaces/IERC165.sol";
import { ERC1155 } from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

import { IERC1155Common } from "./interfaces/IERC1155Common.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 { Strings } from "@openzeppelin/contracts/utils/Strings.sol";

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(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_;
}

/**
* @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();
}

/**
* @dev Unpauses all token transfers.
* Requirements:
* - the caller must have the `PAUSER_ROLE`.
*/
function unpause() external onlyRole(PAUSER_ROLE) {
_unpause();
}

/// @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");
huyhuynh3103 marked this conversation as resolved.
Show resolved Hide resolved

for (uint256 i; i < length; ++i) {
_mint(tos[i], id, amounts[i], datas[i]);
}
}

/**
* @dev See {ERC1155-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 name() public view virtual returns (string memory) {
return _name;
}

/// @inheritdoc IERC1155Common
function symbol() public view virtual returns (string memory) {
return _symbol;
}

/**
* @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-_update}.
*/
function _update(
address from,
address to,
uint256[] memory ids,
uint256[] memory values
) internal virtual override(ERC1155, ERC1155Supply, ERC1155Pausable) {
super._update(from, to, ids, values);
}
}
10 changes: 4 additions & 6 deletions src/ERC721Common.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import { IERC721State } from "./interfaces/IERC721State.sol";
import { ERC721Nonce } from "./refs/ERC721Nonce.sol";
import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol";

abstract contract ERC721Common is ERC721Nonce, ERC721PresetMinterPauserAutoIdCustomized, IERC721State, IERC721Common {
constructor(
string memory name_,
string memory symbol_,
string memory baseTokenURI
) ERC721PresetMinterPauserAutoIdCustomized(name_, symbol_, baseTokenURI) { }
contract ERC721Common is ERC721Nonce, ERC721PresetMinterPauserAutoIdCustomized, IERC721State, IERC721Common {
constructor(string memory name, string memory symbol, string memory baseTokenURI)
ERC721PresetMinterPauserAutoIdCustomized(name, symbol, baseTokenURI)
{ }

/// @inheritdoc IERC721State
function stateOf(
Expand Down
51 changes: 51 additions & 0 deletions src/interfaces/IERC1155Common.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import { IAccessControlEnumerable } from "@openzeppelin/contracts/access/extensions/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, 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 bulkMint(uint256 id, address[] calldata tos, uint256[] calldata amounts, bytes[] calldata datas) external;
}
30 changes: 30 additions & 0 deletions src/interfaces/launchpad/INFTPresale.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

/// @dev Interface for the NFT contract that compatible with the contract MavisPresale.
/// MUST be included ERC165 interface to support the detection of the contract's capabilities.
interface INFTPresale {
/**
* @dev Mint NFTs for the presale.
*
* Requirements:
* - The mintedTokenIds and mintedAmounts should have the same length.
* - The mintedTokenIds array should be unique.
* - For ERC721 NFTs, each minted token's quantity should always be 1.
* - For ERC1155 NFTs, each minted token's quantity should be actual minted amounts.
* - The total of minted amounts can be different from the input `quantity`.
*
* Examples:
* - ERC1155: If mintedTokenIds = [1, 2], then mintedAmounts = [10, 20]
* - ERC721: If mintedTokenIds = [1, 2], then mintedAmounts = [1, 1]
*
* @param to The address to mint the NFTs to.
* @param quantity The quantity of NFTs to mint.
* @param extraData The extra data for further customization.
* @return mintedTokenIds The token IDs of the minted NFTs.
* @return mintedAmounts The minted amounts according to the `mintedTokenIds`.
*/
function mintPresale(address to, uint256 quantity, bytes calldata extraData)
external
returns (uint256[] memory mintedTokenIds, uint256[] memory mintedAmounts);
}
6 changes: 2 additions & 4 deletions src/launchpad/NFTLaunchpadCommon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { INFTLaunchpad } from "../interfaces/launchpad/INFTLaunchpad.sol";

abstract contract NFTLaunchpadCommon is IERC165, INFTLaunchpad {
/// @dev Returns whether the contract supports the NFT launchpad interface.
function supportsInterface(
bytes4 interfaceId
) public view virtual returns (bool) {
return interfaceId == type(INFTLaunchpad).interfaceId;
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(INFTLaunchpad).interfaceId || interfaceId == type(IERC165).interfaceId;
huyhuynh3103 marked this conversation as resolved.
Show resolved Hide resolved
}
}
13 changes: 13 additions & 0 deletions src/launchpad/NFTPresaleCommon.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

import { IERC165 } from "@openzeppelin/contracts/interfaces/IERC165.sol";

import { INFTPresale } from "../interfaces/launchpad/INFTPresale.sol";

abstract contract NFTPresaleCommon is IERC165, INFTPresale {
/// @dev Returns whether the contract supports the NFT presale interface.
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(INFTPresale).interfaceId || interfaceId == type(IERC165).interfaceId;
huyhuynh3103 marked this conversation as resolved.
Show resolved Hide resolved
}
}
10 changes: 10 additions & 0 deletions src/mock/SampleERC1155.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "../ERC1155Common.sol";

contract SampleERC1155 is ERC1155Common {
constructor(address admin, string memory name, string memory symbol, string memory uri)
ERC1155Common(admin, name, symbol, uri)
{ }
}
26 changes: 13 additions & 13 deletions src/mock/launchpad/SampleNFT1155Launchpad.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
pragma solidity ^0.8.19;

import { NFTLaunchpadCommon } from "../../launchpad/NFTLaunchpadCommon.sol";
import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";
import { ERC1155 } from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import { SampleERC1155, ERC1155Common } from "../SampleERC1155.sol";

contract SampleNFT1155Launchpad is ERC1155, AccessControl, NFTLaunchpadCommon {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");

constructor(address admin, address minter, string memory uri_) ERC1155(uri_) {
_grantRole(DEFAULT_ADMIN_ROLE, admin);
_grantRole(MINTER_ROLE, minter);
}
contract SampleNFT1155Launchpad is SampleERC1155, NFTLaunchpadCommon {
constructor(address admin, string memory name, string memory symbol, string memory uri)
SampleERC1155(admin, name, symbol, uri)
{ }

/// @dev Mint NFTs for the launchpad.
function mintLaunchpad(
Expand All @@ -31,9 +27,13 @@ contract SampleNFT1155Launchpad is ERC1155, AccessControl, NFTLaunchpadCommon {
amounts[1] = 1;
}

function supportsInterface(
bytes4 interfaceId
) public view virtual override(ERC1155, AccessControl, NFTLaunchpadCommon) returns (bool) {
return super.supportsInterface(interfaceId);
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC1155Common, NFTLaunchpadCommon)
returns (bool)
{
return ERC1155Common.supportsInterface(interfaceId) || NFTLaunchpadCommon.supportsInterface(interfaceId);
}
}
12 changes: 8 additions & 4 deletions src/mock/launchpad/SampleNFT721Launchpad.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ contract SampleNFT721Launchpad is SampleERC721, NFTLaunchpadCommon {
}
}

function supportsInterface(
bytes4 interfaceId
) public view virtual override(ERC721Common, NFTLaunchpadCommon) returns (bool) {
return super.supportsInterface(interfaceId);
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721Common, NFTLaunchpadCommon)
returns (bool)
{
return ERC721Common.supportsInterface(interfaceId) || NFTLaunchpadCommon.supportsInterface(interfaceId);
}
}
Loading
Loading