Skip to content

Commit

Permalink
chore(fmt): format with forge fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
khayss committed Oct 18, 2024
1 parent 95723d9 commit 6f7cf23
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 395 deletions.
23 changes: 10 additions & 13 deletions src/Diamond.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/******************************************************************************\
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
*
* Implementation of a diamond.
/******************************************************************************/

/**
* \
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
*
* Implementation of a diamond.
* /*****************************************************************************
*/
import {LibDiamond} from "./libraries/LibDiamond.sol";
import {IDiamondCut} from "./interfaces/IDiamondCut.sol";

Expand Down Expand Up @@ -67,12 +68,8 @@ contract Diamond {
returndatacopy(0, 0, returndatasize())
// return any return value or error back to the caller
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
case 0 { revert(0, returndatasize()) }
default { return(0, returndatasize()) }
}
}

Expand Down
21 changes: 9 additions & 12 deletions src/facets/DiamondCutFacet.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/******************************************************************************\
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
/******************************************************************************/

import { IDiamondCut } from "../interfaces/IDiamondCut.sol";
import { LibDiamond } from "../libraries/LibDiamond.sol";
/**
* \
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
* /*****************************************************************************
*/
import {IDiamondCut} from "../interfaces/IDiamondCut.sol";
import {LibDiamond} from "../libraries/LibDiamond.sol";

contract DiamondCutFacet is IDiamondCut {
/// @notice Add/replace/remove any number of functions and optionally execute
Expand All @@ -16,11 +17,7 @@ contract DiamondCutFacet is IDiamondCut {
/// @param _init The address of the contract or facet to execute _calldata
/// @param _calldata A function call, including function selector and arguments
/// _calldata is executed with delegatecall on _init
function diamondCut(
FacetCut[] calldata _diamondCut,
address _init,
bytes calldata _calldata
) external override {
function diamondCut(FacetCut[] calldata _diamondCut, address _init, bytes calldata _calldata) external override {
LibDiamond.enforceIsContractOwner();
LibDiamond.diamondCut(_diamondCut, _init, _calldata);
}
Expand Down
31 changes: 19 additions & 12 deletions src/facets/DiamondLoupeFacet.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/******************************************************************************\
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
/******************************************************************************/
/**
* \
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
* /*****************************************************************************
*/

import { LibDiamond } from "../libraries/LibDiamond.sol";
import { IDiamondLoupe } from "../interfaces/IDiamondLoupe.sol";
import { IERC165 } from "../interfaces/IERC165.sol";
import {LibDiamond} from "../libraries/LibDiamond.sol";
import {IDiamondLoupe} from "../interfaces/IDiamondLoupe.sol";
import {IERC165} from "../interfaces/IERC165.sol";

contract DiamondLoupeFacet is IDiamondLoupe, IERC165 {
// Diamond Loupe Functions
Expand All @@ -21,7 +23,7 @@ contract DiamondLoupeFacet is IDiamondLoupe, IERC165 {

/// @notice Gets all facets and their selectors.
/// @return facets_ Facet
function facets() external override view returns (Facet[] memory facets_) {
function facets() external view override returns (Facet[] memory facets_) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
uint256 numFacets = ds.facetAddresses.length;
facets_ = new Facet[](numFacets);
Expand All @@ -35,14 +37,19 @@ contract DiamondLoupeFacet is IDiamondLoupe, IERC165 {
/// @notice Gets all the function selectors provided by a facet.
/// @param _facet The facet address.
/// @return facetFunctionSelectors_
function facetFunctionSelectors(address _facet) external override view returns (bytes4[] memory facetFunctionSelectors_) {
function facetFunctionSelectors(address _facet)
external
view
override
returns (bytes4[] memory facetFunctionSelectors_)
{
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
facetFunctionSelectors_ = ds.facetFunctionSelectors[_facet].functionSelectors;
}

/// @notice Get all the facet addresses used by a diamond.
/// @return facetAddresses_
function facetAddresses() external override view returns (address[] memory facetAddresses_) {
function facetAddresses() external view override returns (address[] memory facetAddresses_) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
facetAddresses_ = ds.facetAddresses;
}
Expand All @@ -51,13 +58,13 @@ contract DiamondLoupeFacet is IDiamondLoupe, IERC165 {
/// @dev If facet is not found return address(0).
/// @param _functionSelector The function selector.
/// @return facetAddress_ The facet address.
function facetAddress(bytes4 _functionSelector) external override view returns (address facetAddress_) {
function facetAddress(bytes4 _functionSelector) external view override returns (address facetAddress_) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
facetAddress_ = ds.selectorToFacetAndPosition[_functionSelector].facetAddress;
}

// This implements ERC-165.
function supportsInterface(bytes4 _interfaceId) external override view returns (bool) {
function supportsInterface(bytes4 _interfaceId) external view override returns (bool) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
return ds.supportedInterfaces[_interfaceId];
}
Expand Down
132 changes: 24 additions & 108 deletions src/facets/ERC721Facet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ contract ERC721Facet is IERC721 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(
bytes4 interfaceId
) public view virtual override returns (bool) {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
ds.supportedInterfaces[interfaceId];
return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId
|| ds.supportedInterfaces[interfaceId];
}

/**
Expand Down Expand Up @@ -64,16 +60,11 @@ contract ERC721Facet is IERC721 {
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(
uint256 tokenId
) public view virtual returns (string memory) {
function tokenURI(uint256 tokenId) public view virtual returns (string memory) {
_requireOwned(tokenId);

string memory baseURI = _baseURI();
return
bytes(baseURI).length > 0
? string.concat(baseURI, tokenId.toString())
: "";
return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : "";
}

/**
Expand All @@ -95,9 +86,7 @@ contract ERC721Facet is IERC721 {
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(
uint256 tokenId
) public view virtual returns (address) {
function getApproved(uint256 tokenId) public view virtual returns (address) {
_requireOwned(tokenId);

return _getApproved(tokenId);
Expand All @@ -113,22 +102,15 @@ contract ERC721Facet is IERC721 {
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(
address owner,
address operator
) public view virtual returns (bool) {
function isApprovedForAll(address owner, address operator) public view virtual returns (bool) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
return ds._operatorApprovals[owner][operator];
}

/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual {
function transferFrom(address from, address to, uint256 tokenId) public virtual {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
Expand All @@ -143,31 +125,16 @@ contract ERC721Facet is IERC721 {
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public {
function safeTransferFrom(address from, address to, uint256 tokenId) public {
safeTransferFrom(from, to, tokenId, "");
}

/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory data
) public virtual {
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual {
transferFrom(from, to, tokenId);
ERC721Utils.checkOnERC721Received(
_msgSender(),
from,
to,
tokenId,
data
);
ERC721Utils.checkOnERC721Received(_msgSender(), from, to, tokenId, data);
}

/**
Expand All @@ -187,9 +154,7 @@ contract ERC721Facet is IERC721 {
/**
* @dev Returns the approved address for `tokenId`. Returns 0 if `tokenId` is not minted.
*/
function _getApproved(
uint256 tokenId
) internal view virtual returns (address) {
function _getApproved(uint256 tokenId) internal view virtual returns (address) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();

return ds._tokenApprovals[tokenId];
Expand All @@ -202,16 +167,9 @@ contract ERC721Facet is IERC721 {
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
* assumption.
*/
function _isAuthorized(
address owner,
address spender,
uint256 tokenId
) internal view virtual returns (bool) {
return
spender != address(0) &&
(owner == spender ||
isApprovedForAll(owner, spender) ||
_getApproved(tokenId) == spender);
function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) {
return spender != address(0)
&& (owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender);
}

/**
Expand All @@ -223,11 +181,7 @@ contract ERC721Facet is IERC721 {
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
* assumption.
*/
function _checkAuthorized(
address owner,
address spender,
uint256 tokenId
) internal view virtual {
function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual {
if (!_isAuthorized(owner, spender, tokenId)) {
if (owner == address(0)) {
revert ERC721NonexistentToken(tokenId);
Expand Down Expand Up @@ -265,11 +219,7 @@ contract ERC721Facet is IERC721 {
*
* NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}.
*/
function _update(
address to,
uint256 tokenId,
address auth
) internal virtual returns (address) {
function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();

address from = _ownerOf(tokenId);
Expand Down Expand Up @@ -342,19 +292,9 @@ contract ERC721Facet is IERC721 {
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory data
) internal virtual {
function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
_mint(to, tokenId);
ERC721Utils.checkOnERC721Received(
_msgSender(),
address(0),
to,
tokenId,
data
);
ERC721Utils.checkOnERC721Received(_msgSender(), address(0), to, tokenId, data);
}

/**
Expand Down Expand Up @@ -425,20 +365,9 @@ contract ERC721Facet is IERC721 {
* @dev Same as {xref-ERC721-_safeTransfer-address-address-uint256-}[`_safeTransfer`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory data
) internal virtual {
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
_transfer(from, to, tokenId);
ERC721Utils.checkOnERC721Received(
_msgSender(),
from,
to,
tokenId,
data
);
ERC721Utils.checkOnERC721Received(_msgSender(), from, to, tokenId, data);
}

/**
Expand All @@ -459,23 +388,14 @@ contract ERC721Facet is IERC721 {
* @dev Variant of `_approve` with an optional flag to enable or disable the {Approval} event. The event is not
* emitted in the context of transfers.
*/
function _approve(
address to,
uint256 tokenId,
address auth,
bool emitEvent
) internal virtual {
function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
// Avoid reading the owner unless necessary
if (emitEvent || auth != address(0)) {
address owner = _requireOwned(tokenId);

// We do not use _isAuthorized because single-token approvals should not be able to call approve
if (
auth != address(0) &&
owner != auth &&
!isApprovedForAll(owner, auth)
) {
if (auth != address(0) && owner != auth && !isApprovedForAll(owner, auth)) {
revert ERC721InvalidApprover(auth);
}

Expand All @@ -495,11 +415,7 @@ contract ERC721Facet is IERC721 {
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();

if (operator == address(0)) {
Expand Down
Loading

0 comments on commit 6f7cf23

Please sign in to comment.