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

[Do Not Merge] benchmark tokenerc721 alt #625

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kumaryash90
Copy link
Member

No description provided.

@kumaryash90 kumaryash90 marked this pull request as draft March 11, 2024 19:38
@kumaryash90 kumaryash90 changed the title gas benchmarks for tokenerc721 [Do Not Merge] benchmark tokenerc721 alt Mar 11, 2024
function initialize(
address _defaultAdmin,
string memory _name,
string memory _symbol,

Check notice

Code scanning / Slither

Local variable shadowing Low

/// @dev Initializes the contract, like a constructor.
function initialize(
address _defaultAdmin,
string memory _name,

Check notice

Code scanning / Slither

Local variable shadowing Low

Comment on lines +48 to +375
tokenIdToMint = nextTokenIdToMint;
nextTokenIdToMint += 1;

_safeMint(_to, tokenIdToMint);

emit TokensMinted(_to, tokenIdToMint, "");
}

/// @dev Returns the address of the signer of the mint request.
function recoverAddress(MintRequest calldata _req, bytes calldata _signature) private view returns (address) {
return _hashTypedDataV4(keccak256(_encodeRequest(_req))).recover(_signature);
}

/// @dev Resolves 'stack too deep' error in `recoverAddress`.
function _encodeRequest(MintRequest calldata _req) private pure returns (bytes memory) {
return abi.encode(TYPEHASH, _req.to, _req.validityStartTimestamp, _req.validityEndTimestamp, _req.uid);
}

/// @dev Verifies that a mint request is valid.
function verifyRequest(MintRequest calldata _req, bytes calldata _signature) internal returns (address) {
(bool success, address signer) = verify(_req, _signature);
require(success, "invalid signature");

require(
_req.validityStartTimestamp <= block.timestamp && _req.validityEndTimestamp >= block.timestamp,
"request expired"
);
require(_req.to != address(0), "recipient undefined");

minted[_req.uid] = true;

return signer;
}

/// ===== Low-level overrides =====

/// @dev Burns `tokenId`. See {ERC721-_burn}.
function burn(uint256 tokenId) public virtual {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721Burnable: caller is not owner nor approved");
_burn(tokenId);
}

/// @dev See {ERC721-_beforeTokenTransfer}.
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId,
uint256 batchSize
) internal virtual override(ERC721EnumerableUpgradeable) {
super._beforeTokenTransfer(from, to, tokenId, batchSize);

// if transfer is restricted on the contract, we still want to allow burning and minting
if (!hasRole(TRANSFER_ROLE, address(0)) && from != address(0) && to != address(0)) {
require(hasRole(TRANSFER_ROLE, from) || hasRole(TRANSFER_ROLE, to), "restricted to TRANSFER_ROLE holders");
}
}

/// @dev Returns whether metadata can be set in the given execution context.
function _canSetMetadata() internal view virtual override returns (bool) {
return hasRole(METADATA_ROLE, _msgSender());
}

/// @dev Returns whether metadata can be frozen in the given execution context.
function _canFreezeMetadata() internal view virtual override returns (bool) {
return hasRole(METADATA_ROLE, _msgSender());
}

function supportsInterface(
bytes4 interfaceId
)
public
view
virtual
override(AccessControlEnumerableUpgradeable, ERC721EnumerableUpgradeable, IERC165Upgradeable, IERC165)
returns (bool)
{
return super.supportsInterface(interfaceId) || interfaceId == type(IERC2981Upgradeable).interfaceId;
}

function _msgSender()
internal
view
virtual
override(ContextUpgradeable, ERC2771ContextUpgradeable, Multicall)
returns (address sender)
{
return ERC2771ContextUpgradeable._msgSender();
}

function _msgData()
internal
view
virtual
override(ContextUpgradeable, ERC2771ContextUpgradeable)
returns (bytes calldata)
{
return ERC2771ContextUpgradeable._msgData();
}
}

Check warning

Code scanning / Slither

Missing inheritance Warning

TokenERC721Alt should inherit from IBurnableERC721
Copy link

codecov bot commented Mar 11, 2024

Codecov Report

Attention: Patch coverage is 51.42857% with 34 lines in your changes are missing coverage. Please review.

Project coverage is 64.58%. Comparing base (90ca7b4) to head (1491165).

Files Patch % Lines
contracts/prebuilts/token/TokenERC721Alt.sol 51.42% 34 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #625      +/-   ##
==========================================
- Coverage   64.72%   64.58%   -0.14%     
==========================================
  Files         216      217       +1     
  Lines        6702     6772      +70     
==========================================
+ Hits         4338     4374      +36     
- Misses       2364     2398      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant