Skip to content

Commit

Permalink
Merge pull request #26 from axieinfinity/release/v0.2.0
Browse files Browse the repository at this point in the history
feat: add ERC1155Common, support launchpad/presale and adapt OZ v5.
  • Loading branch information
huyhuynh3103 authored Dec 29, 2024
2 parents fa36abc + c8d186c commit 2027c61
Show file tree
Hide file tree
Showing 34 changed files with 500 additions and 259 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ on:
- dev
- "feature/*"
- "features/*"
- "feature/*"
- "features/*"
pull_request:
branches:
- main
- dev
- "feature/*"
- "features/*"
- "feature/*"
- "features/*"

env:
FOUNDRY_PROFILE: ci
Expand All @@ -24,6 +28,7 @@ jobs:

name: Foundry project
runs-on: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
Expand All @@ -36,7 +41,7 @@ jobs:

- name: Install dependencies
run: |
forge install
forge soldeer update
id: install

- name: Run Forge build
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ artifacts/
typechain-types/
.idea
.env

dependencies
12 changes: 0 additions & 12 deletions .gitmodules

This file was deleted.

32 changes: 31 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,36 @@ extra_output = ["devdoc", "userdoc", "storagelayout"]
fs_permissions = [{ access = "read-write", path = "./" }]

[fmt]
tab_width = 2
line_length = 120
tab_width = 2
bracket_spacing = true
multiline_func_header = 'params_first'
single_line_statement_blocks = 'single'
sort_imports = true
number_underscore = "thousands"
wrap_comments = true

[dependencies]
"openzeppelin" = { version = "5.0.2", url = "https://github.com/OpenZeppelin/openzeppelin-contracts/archive/refs/tags/v5.0.2.zip" }
"openzeppelin-upgradeable" = { version = "5.0.2", url = "https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/archive/refs/tags/v5.0.2.zip" }
forge-std = { version = "1.9.3", url = "https://github.com/foundry-rs/forge-std/archive/refs/tags/v1.9.3.zip" }

[soldeer]
# whether soldeer manages remappings
remappings_generate = false

# whether soldeer re-generates all remappings when installing, updating or uninstalling deps
remappings_regenerate = false

# whether to suffix the remapping with the version: `name-a.b.c`
remappings_version = true

# a prefix to add to the remappings ("@" would give `@name`)
remappings_prefix = "@"

# where to store the remappings ("txt" for `remappings.txt` or "config" for `foundry.toml`)
# ignored when `soldeer.toml` is used as config (uses `remappings.txt`)
remappings_location = "txt"

# whether to install sub-dependencies or not. If true this wil install the dependencies of dependencies 1 level down.
recursive_deps = true
1 change: 0 additions & 1 deletion lib/forge-std
Submodule forge-std deleted from fc560f
1 change: 0 additions & 1 deletion lib/openzeppelin-contracts
Submodule openzeppelin-contracts deleted from d00ace
1 change: 0 additions & 1 deletion lib/openzeppelin-contracts-upgradeable
Submodule openzeppelin-contracts-upgradeable deleted from a40cb0
7 changes: 3 additions & 4 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
forge-std/=lib/forge-std/src/
ds-test/=lib/forge-std/lib/ds-test/src/
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts
forge-std/=dependencies/forge-std-1.9.3/src/
@openzeppelin/contracts/=dependencies/openzeppelin-5.0.2/contracts/
@openzeppelin/contracts-upgradeable/=dependencies/openzeppelin-upgradeable-5.0.2/contracts/
27 changes: 27 additions & 0 deletions soldeer.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[[dependencies]]
name = "contract-template"
version = "0.1.0"
source = "https://github.com/axieinfinity/contract-template/archive/refs/tags/release-v0.1.0.zip"
checksum = "56676e92b8825974abab8e381a98d0cc55da7057a18b3d325a13def760fa69d3"
integrity = "9fda9db2e8c24bb37378b1a14f41e1338967d101282bcdc0df9e98d7cf0edcda"

[[dependencies]]
name = "forge-std"
version = "1.9.3"
source = "https://github.com/foundry-rs/forge-std/archive/refs/tags/v1.9.3.zip"
checksum = "cc61148ae1a47f2415956a95ada670501b10ebd7f65cc00eda6ea7025770f42b"
integrity = "d53734fbd7201cd9e44de730ae045ed8958dd2c7b9493c30b322f6e6c21ca8b2"

[[dependencies]]
name = "openzeppelin"
version = "5.0.2"
source = "https://github.com/OpenZeppelin/openzeppelin-contracts/archive/refs/tags/v5.0.2.zip"
checksum = "ca49e0776066328da0087977864dfaef0d5e54a0ea9859236a7cd9ad02abb9e5"
integrity = "6f8fc028520b958667ef1e96460c64140f42fef60ff02bc63110780c557b7c7e"

[[dependencies]]
name = "openzeppelin-upgradeable"
version = "5.0.2"
source = "https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/archive/refs/tags/v5.0.2.zip"
checksum = "4790d4f592cb46c868916ea50613997df1e28fd42b4d32e0999f0a4b9d1a7cf8"
integrity = "085dfc37ec3b96f0ea95ae99d8c044b0b407eab88a78d7cb552284bccf1130ba"
56 changes: 28 additions & 28 deletions src/ERC1155Common.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// 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 { AccessControlEnumerable } from "@openzeppelin/contracts/access/AccessControlEnumerable.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";
import { IERC1155Common } from "./interfaces/IERC1155Common.sol";

contract ERC1155Common is
ERC1155,
Expand Down Expand Up @@ -44,7 +44,9 @@ contract ERC1155Common is
* Requirements:
* - the caller must have the `URI_SETTER_ROLE`.
*/
function setURI(string memory newURI) external onlyRole(URI_SETTER_ROLE) {
function setURI(
string memory newURI
) external onlyRole(URI_SETTER_ROLE) {
_setURI(newURI);
}

Expand Down Expand Up @@ -72,11 +74,12 @@ contract ERC1155Common is
}

/// @inheritdoc IERC1155Common
function mintBatch(address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data)
public
virtual
onlyRole(MINTER_ROLE)
{
function mintBatch(
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) public virtual onlyRole(MINTER_ROLE) {
_mintBatch(to, ids, amounts, data);
}

Expand All @@ -85,11 +88,12 @@ contract ERC1155Common is
* 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)
{
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");

Expand All @@ -101,7 +105,9 @@ contract ERC1155Common is
/**
* @dev See {ERC1155-uri}.
*/
function uri(uint256 tokenId) public view virtual override returns (string memory) {
function uri(
uint256 tokenId
) public view virtual override returns (string memory) {
string memory uri_ = super.uri(tokenId);
return string.concat(uri_, tokenId.toString());
}
Expand All @@ -119,27 +125,21 @@ contract ERC1155Common is
/**
* @dev See {ERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(IERC165, ERC1155, AccessControlEnumerable)
returns (bool)
{
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}.
* @dev See {ERC1155-_update}.
*/
function _beforeTokenTransfer(
address operator,
function _update(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual override(ERC1155, ERC1155Pausable, ERC1155Supply) {
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
uint256[] memory values
) internal virtual override(ERC1155, ERC1155Supply, ERC1155Pausable) {
super._update(from, to, ids, values);
}
}
75 changes: 41 additions & 34 deletions src/ERC721Common.sol
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "./interfaces/IERC721State.sol";
import "./interfaces/IERC721Common.sol";
import "./refs/ERC721Nonce.sol";
import "./ERC721PresetMinterPauserAutoIdCustomized.sol";
import { ERC721PresetMinterPauserAutoIdCustomized } from "./ERC721PresetMinterPauserAutoIdCustomized.sol";
import { IERC721Common } from "./interfaces/IERC721Common.sol";
import { IERC721State } from "./interfaces/IERC721State.sol";
import { ERC721Nonce } from "./refs/ERC721Nonce.sol";
import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol";

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

/// @inheritdoc IERC721State
function stateOf(uint256 _tokenId) external view virtual override returns (bytes memory) {
require(_exists(_tokenId), "ERC721Common: query for non-existent token");
return abi.encodePacked(ownerOf(_tokenId), nonces[_tokenId], _tokenId);
function stateOf(
uint256 tokenId
) external view virtual override returns (bytes memory) {
return abi.encodePacked(ownerOf(tokenId), nonces[tokenId], tokenId);
}

/**
Expand All @@ -33,26 +37,32 @@ contract ERC721Common is ERC721Nonce, ERC721PresetMinterPauserAutoIdCustomized,
/**
* @dev Override `IERC165-supportsInterface`.
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721, ERC721PresetMinterPauserAutoIdCustomized)
returns (bool)
{
function supportsInterface(
bytes4 interfaceId
) public view virtual override(ERC721, ERC721PresetMinterPauserAutoIdCustomized) returns (bool) {
return interfaceId == type(IERC721Common).interfaceId || interfaceId == type(IERC721State).interfaceId
|| super.supportsInterface(interfaceId);
}

/**
* @dev Override `ERC721PresetMinterPauserAutoIdCustomized-_beforeTokenTransfer`.
* @dev Override `ERC721PresetMinterPauserAutoIdCustomized-_update`.
*/
function _beforeTokenTransfer(address _from, address _to, uint256 _firstTokenId, uint256 _batchSize)
internal
virtual
override(ERC721Nonce, ERC721PresetMinterPauserAutoIdCustomized)
{
super._beforeTokenTransfer(_from, _to, _firstTokenId, _batchSize);
function _update(
address to,
uint256 tokenId,
address auth
) internal virtual override(ERC721Nonce, ERC721PresetMinterPauserAutoIdCustomized) returns (address from) {
return super._update(to, tokenId, auth);
}

/**
* @dev See {ERC721-_increaseBalance}.
*/
function _increaseBalance(
address account,
uint128 amount
) internal virtual override(ERC721, ERC721PresetMinterPauserAutoIdCustomized) {
super._increaseBalance(account, amount);
}

/**
Expand All @@ -66,17 +76,14 @@ contract ERC721Common is ERC721Nonce, ERC721PresetMinterPauserAutoIdCustomized,
*
* - the caller must have the `MINTER_ROLE`.
*/
function bulkMint(address[] calldata _recipients)
external
virtual
onlyRole(MINTER_ROLE)
returns (uint256[] memory _tokenIds)
{
require(_recipients.length > 0, "ERC721Common: invalid array lengths");
_tokenIds = new uint256[](_recipients.length);
function bulkMint(
address[] calldata recipients
) external virtual onlyRole(MINTER_ROLE) returns (uint256[] memory tokenIds) {
require(recipients.length > 0, "ERC721Common: invalid array lengths");
tokenIds = new uint256[](recipients.length);

for (uint256 _i = 0; _i < _recipients.length; _i++) {
_tokenIds[_i] = _mintFor(_recipients[_i]);
for (uint256 i; i < recipients.length; i++) {
tokenIds[i] = _mintFor(recipients[i]);
}
}
}
Loading

0 comments on commit 2027c61

Please sign in to comment.