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

forge fmt #50

Merged
merged 1 commit into from
Mar 4, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/common/Permission.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import { IPermission } from "../interface/common/IPermission.sol";
import { PermissionStorage } from "../storage/common/PermissionStorage.sol";
import {IPermission} from "../interface/common/IPermission.sol";
import {PermissionStorage} from "../storage/common/PermissionStorage.sol";

contract Permission is IPermission {
/*//////////////////////////////////////////////////////////////
Expand Down
127 changes: 49 additions & 78 deletions src/core/token/ERC1155Core.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import { Initializable } from "@solady/utils/Initializable.sol";
import { Multicallable } from "@solady/utils/Multicallable.sol";
import {Initializable} from "@solady/utils/Initializable.sol";
import {Multicallable} from "@solady/utils/Multicallable.sol";

import { IERC7572 } from "../../interface/eip/IERC7572.sol";
import { IERC1155CoreCustomErrors } from "../../interface/errors/IERC1155CoreCustomErrors.sol";
import { IERC1155Hook } from "../../interface/hook/IERC1155Hook.sol";
import { IERC1155HookInstaller } from "../../interface/hook/IERC1155HookInstaller.sol";
import { IInitCall } from "../../interface/common/IInitCall.sol";
import { ERC1155Initializable } from "./ERC1155Initializable.sol";
import { IHook, HookInstaller } from "../../hook/HookInstaller.sol";
import { Permission } from "../../common/Permission.sol";
import {IERC7572} from "../../interface/eip/IERC7572.sol";
import {IERC1155CoreCustomErrors} from "../../interface/errors/IERC1155CoreCustomErrors.sol";
import {IERC1155Hook} from "../../interface/hook/IERC1155Hook.sol";
import {IERC1155HookInstaller} from "../../interface/hook/IERC1155HookInstaller.sol";
import {IInitCall} from "../../interface/common/IInitCall.sol";
import {ERC1155Initializable} from "./ERC1155Initializable.sol";
import {IHook, HookInstaller} from "../../hook/HookInstaller.sol";
import {Permission} from "../../common/Permission.sol";

import { ERC1155CoreStorage } from "../../storage/core/ERC1155CoreStorage.sol";
import {ERC1155CoreStorage} from "../../storage/core/ERC1155CoreStorage.sol";

contract ERC1155Core is
Initializable,
Expand All @@ -31,25 +31,25 @@ contract ERC1155Core is
//////////////////////////////////////////////////////////////*/

/// @notice Bits representing the before mint hook.
uint256 public constant BEFORE_MINT_FLAG = 2**1;
uint256 public constant BEFORE_MINT_FLAG = 2 ** 1;

/// @notice Bits representing the before transfer hook.
uint256 public constant BEFORE_TRANSFER_FLAG = 2**2;
uint256 public constant BEFORE_TRANSFER_FLAG = 2 ** 2;

/// @notice Bits representing the before burn hook.
uint256 public constant BEFORE_BURN_FLAG = 2**3;
uint256 public constant BEFORE_BURN_FLAG = 2 ** 3;

/// @notice Bits representing the before approve hook.
uint256 public constant BEFORE_APPROVE_FLAG = 2**4;
uint256 public constant BEFORE_APPROVE_FLAG = 2 ** 4;

/// @notice Bits representing the token URI hook.
uint256 public constant TOKEN_URI_FLAG = 2**5;
uint256 public constant TOKEN_URI_FLAG = 2 ** 5;

/// @notice Bits representing the royalty hook.
uint256 public constant ROYALTY_INFO_FLAG = 2**6;
uint256 public constant ROYALTY_INFO_FLAG = 2 ** 6;

/// @notice Bits representing the before transfer hook.
uint256 public constant BEFORE_BATCH_TRANSFER_FLAG = 2**7;
uint256 public constant BEFORE_BATCH_TRANSFER_FLAG = 2 ** 7;

/*//////////////////////////////////////////////////////////////
CONSTRUCTOR + INITIALIZE
Expand Down Expand Up @@ -86,7 +86,7 @@ contract ERC1155Core is

if (_initCall.target != address(0)) {
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returnData) = _initCall.target.call{ value: _initCall.value }(_initCall.data);
(bool success, bytes memory returnData) = _initCall.target.call{value: _initCall.value}(_initCall.data);
if (!success) {
if (returnData.length > 0) {
// solhint-disable-next-line no-inline-assembly
Expand Down Expand Up @@ -151,11 +151,10 @@ contract ERC1155Core is
* @param _interfaceId The interface ID of the interface to check for
*/
function supportsInterface(bytes4 _interfaceId) public pure override returns (bool) {
return
_interfaceId == 0x01ffc9a7 || // ERC165 Interface ID for ERC165
_interfaceId == 0xd9b67a26 || // ERC165 Interface ID for ERC1155
_interfaceId == 0x0e89341c || // ERC165 Interface ID for ERC1155MetadataURI
_interfaceId == 0x2a55205a; // ERC165 Interface ID for ERC-2981
return _interfaceId == 0x01ffc9a7 // ERC165 Interface ID for ERC165
|| _interfaceId == 0xd9b67a26 // ERC165 Interface ID for ERC1155
|| _interfaceId == 0x0e89341c // ERC165 Interface ID for ERC1155MetadataURI
|| _interfaceId == 0x2a55205a; // ERC165 Interface ID for ERC-2981
}

/*//////////////////////////////////////////////////////////////
Expand All @@ -179,12 +178,7 @@ contract ERC1155Core is
* @param _value The amount of tokens to burn.
* @param _encodedBeforeBurnArgs ABI encoded arguments to pass to the beforeBurn hook.
*/
function burn(
address _from,
uint256 _tokenId,
uint256 _value,
bytes memory _encodedBeforeBurnArgs
) external {
function burn(address _from, uint256 _tokenId, uint256 _value, bytes memory _encodedBeforeBurnArgs) external {
if (_from != msg.sender && isApprovedForAll(_from, msg.sender)) {
revert ERC1155NotApprovedOrOwner(msg.sender);
}
Expand All @@ -201,12 +195,10 @@ contract ERC1155Core is
* @param _value The amount of tokens to mint.
* @param _encodedBeforeMintArgs ABI encoded arguments to pass to the beforeMint hook.
*/
function mint(
address _to,
uint256 _tokenId,
uint256 _value,
bytes memory _encodedBeforeMintArgs
) external payable {
function mint(address _to, uint256 _tokenId, uint256 _value, bytes memory _encodedBeforeMintArgs)
external
payable
{
(uint256 tokenIdToMint, uint256 quantityToMint) = _beforeMint(_to, _tokenId, _value, _encodedBeforeMintArgs);
_mint(_to, tokenIdToMint, quantityToMint, "");
}
Expand All @@ -218,13 +210,10 @@ contract ERC1155Core is
* @param _to The address to transfer to
* @param _tokenId The token ID of the NFT
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
uint256 _value,
bytes calldata _data
) public override {
function safeTransferFrom(address _from, address _to, uint256 _tokenId, uint256 _value, bytes calldata _data)
public
override
{
_beforeTransfer(_from, _to, _tokenId, _value);
super.safeTransferFrom(_from, _to, _tokenId, _value, _data);
}
Expand Down Expand Up @@ -288,33 +277,23 @@ contract ERC1155Core is
//////////////////////////////////////////////////////////////*/

/// @dev Calls the beforeMint hook.
function _beforeMint(
address _to,
uint256 _tokenId,
uint256 _value,
bytes memory _data
) internal virtual returns (uint256 tokenIdToMint, uint256 quantityToMint) {
function _beforeMint(address _to, uint256 _tokenId, uint256 _value, bytes memory _data)
internal
virtual
returns (uint256 tokenIdToMint, uint256 quantityToMint)
{
address hook = getHookImplementation(BEFORE_MINT_FLAG);

if (hook != address(0)) {
(tokenIdToMint, quantityToMint) = IERC1155Hook(hook).beforeMint{ value: msg.value }(
_to,
_tokenId,
_value,
_data
);
(tokenIdToMint, quantityToMint) =
IERC1155Hook(hook).beforeMint{value: msg.value}(_to, _tokenId, _value, _data);
} else {
revert ERC1155CoreMintingDisabled();
}
}

/// @dev Calls the beforeTransfer hook, if installed.
function _beforeTransfer(
address _from,
address _to,
uint256 _tokenId,
uint256 _value
) internal virtual {
function _beforeTransfer(address _from, address _to, uint256 _tokenId, uint256 _value) internal virtual {
address hook = getHookImplementation(BEFORE_TRANSFER_FLAG);

if (hook != address(0)) {
Expand All @@ -323,12 +302,10 @@ contract ERC1155Core is
}

/// @dev Calls the beforeTransfer hook, if installed.
function _beforeBatchTransfer(
address _from,
address _to,
uint256[] calldata _tokenIds,
uint256[] calldata _values
) internal virtual {
function _beforeBatchTransfer(address _from, address _to, uint256[] calldata _tokenIds, uint256[] calldata _values)
internal
virtual
{
address hook = getHookImplementation(BEFORE_BATCH_TRANSFER_FLAG);

if (hook != address(0)) {
Expand All @@ -337,12 +314,10 @@ contract ERC1155Core is
}

/// @dev Calls the beforeBurn hook, if installed.
function _beforeBurn(
address _from,
uint256 _tokenId,
uint256 _value,
bytes memory _encodedBeforeBurnArgs
) internal virtual {
function _beforeBurn(address _from, uint256 _tokenId, uint256 _value, bytes memory _encodedBeforeBurnArgs)
internal
virtual
{
address hook = getHookImplementation(BEFORE_BURN_FLAG);

if (hook != address(0)) {
Expand All @@ -351,11 +326,7 @@ contract ERC1155Core is
}

/// @dev Calls the beforeApprove hook, if installed.
function _beforeApprove(
address _from,
address _to,
bool _approved
) internal virtual {
function _beforeApprove(address _from, address _to, bool _approved) internal virtual {
address hook = getHookImplementation(BEFORE_APPROVE_FLAG);

if (hook != address(0)) {
Expand Down
61 changes: 24 additions & 37 deletions src/core/token/ERC1155Initializable.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import { Initializable } from "@solady/utils/Initializable.sol";
import {Initializable} from "@solady/utils/Initializable.sol";

import { IERC1155 } from "../../interface/eip/IERC1155.sol";
import { IERC1155Supply } from "../../interface/eip/IERC1155Supply.sol";
import { IERC1155MetadataURI } from "../../interface/eip/IERC1155Metadata.sol";
import { IERC1155CustomErrors } from "../../interface/errors/IERC1155CustomErrors.sol";
import { IERC1155Receiver } from "../../interface/eip/IERC1155Receiver.sol";
import { IERC2981 } from "../../interface/eip/IERC2981.sol";
import {IERC1155} from "../../interface/eip/IERC1155.sol";
import {IERC1155Supply} from "../../interface/eip/IERC1155Supply.sol";
import {IERC1155MetadataURI} from "../../interface/eip/IERC1155Metadata.sol";
import {IERC1155CustomErrors} from "../../interface/errors/IERC1155CustomErrors.sol";
import {IERC1155Receiver} from "../../interface/eip/IERC1155Receiver.sol";
import {IERC2981} from "../../interface/eip/IERC2981.sol";

import { ERC1155InitializableStorage } from "../../storage/core/ERC1155InitializableStorage.sol";
import {ERC1155InitializableStorage} from "../../storage/core/ERC1155InitializableStorage.sol";

abstract contract ERC1155Initializable is
Initializable,
Expand Down Expand Up @@ -99,10 +99,9 @@ abstract contract ERC1155Initializable is
* @param _interfaceId The interface ID of the interface to check for
*/
function supportsInterface(bytes4 _interfaceId) public view virtual returns (bool) {
return
_interfaceId == 0x01ffc9a7 || // ERC165 Interface ID for ERC165
_interfaceId == 0xd9b67a26 || // ERC165 Interface ID for ERC1155
_interfaceId == 0x0e89341c; // ERC165 Interface ID for ERC1155MetadataURI
return _interfaceId == 0x01ffc9a7 // ERC165 Interface ID for ERC165
|| _interfaceId == 0xd9b67a26 // ERC165 Interface ID for ERC1155
|| _interfaceId == 0x0e89341c; // ERC165 Interface ID for ERC1155MetadataURI
}

/*//////////////////////////////////////////////////////////////
Expand All @@ -129,13 +128,10 @@ abstract contract ERC1155Initializable is
* @param _value Total number of NFTs with that id
* @param _data data
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
uint256 _value,
bytes calldata _data
) public virtual {
function safeTransferFrom(address _from, address _to, uint256 _tokenId, uint256 _value, bytes calldata _data)
public
virtual
{
ERC1155InitializableStorage.Data storage data = ERC1155InitializableStorage.data();

if (msg.sender != _from && !data.isApprovedForAll[_from][msg.sender]) {
Expand All @@ -150,8 +146,8 @@ abstract contract ERC1155Initializable is
if (
_to.code.length == 0
? _to == address(0)
: IERC1155Receiver(_to).onERC1155Received(msg.sender, _from, _tokenId, _value, _data) !=
IERC1155Receiver.onERC1155Received.selector
: IERC1155Receiver(_to).onERC1155Received(msg.sender, _from, _tokenId, _value, _data)
!= IERC1155Receiver.onERC1155Received.selector
) {
revert ERC1155UnsafeRecipient(_to);
}
Expand Down Expand Up @@ -186,7 +182,7 @@ abstract contract ERC1155Initializable is
uint256 id;
uint256 value;

for (uint256 i = 0; i < _tokenIds.length; ) {
for (uint256 i = 0; i < _tokenIds.length;) {
id = _tokenIds[i];
value = _values[i];

Expand All @@ -205,8 +201,8 @@ abstract contract ERC1155Initializable is
if (
_to.code.length == 0
? _to == address(0)
: IERC1155Receiver(_to).onERC1155BatchReceived(msg.sender, _from, _tokenIds, _values, _data) !=
IERC1155Receiver.onERC1155BatchReceived.selector
: IERC1155Receiver(_to).onERC1155BatchReceived(msg.sender, _from, _tokenIds, _values, _data)
!= IERC1155Receiver.onERC1155BatchReceived.selector
) {
revert ERC1155UnsafeRecipient(_to);
}
Expand All @@ -216,12 +212,7 @@ abstract contract ERC1155Initializable is
INTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/

function _mint(
address _to,
uint256 _tokenId,
uint256 _value,
bytes memory _data
) internal virtual {
function _mint(address _to, uint256 _tokenId, uint256 _value, bytes memory _data) internal virtual {
ERC1155InitializableStorage.data().balanceOf[_to][_tokenId] += _value;
ERC1155InitializableStorage.data().totalSupply[_tokenId] += _value;

Expand All @@ -230,18 +221,14 @@ abstract contract ERC1155Initializable is
if (
_to.code.length == 0
? _to == address(0)
: IERC1155Receiver(_to).onERC1155Received(msg.sender, address(0), _tokenId, _value, _data) !=
IERC1155Receiver.onERC1155Received.selector
: IERC1155Receiver(_to).onERC1155Received(msg.sender, address(0), _tokenId, _value, _data)
!= IERC1155Receiver.onERC1155Received.selector
) {
revert ERC1155UnsafeRecipient(_to);
}
}

function _burn(
address _from,
uint256 _tokenId,
uint256 _value
) internal virtual {
function _burn(address _from, uint256 _tokenId, uint256 _value) internal virtual {
if (_from == address(0)) {
revert ERC1155BurnFromZeroAddress();
}
Expand Down
Loading