From b5ea712dce667fda3ffb3940ae75171955671109 Mon Sep 17 00:00:00 2001 From: Krishang Nadgauda Date: Fri, 1 Apr 2022 14:28:12 -0400 Subject: [PATCH] run prettier --- contracts/interfaces/IMultiwrap.sol | 14 ++-- contracts/multiwrap/Multiwrap.sol | 31 +++++--- src/test/Multiwrap.t.sol | 56 +++++++------ src/test/benchmark/MultiwrapBenchmark.t.sol | 87 ++++++++++++--------- 4 files changed, 106 insertions(+), 82 deletions(-) diff --git a/contracts/interfaces/IMultiwrap.sol b/contracts/interfaces/IMultiwrap.sol index d18ccdfea..ea4f0452f 100644 --- a/contracts/interfaces/IMultiwrap.sol +++ b/contracts/interfaces/IMultiwrap.sol @@ -9,13 +9,16 @@ import "./IThirdwebOwnable.sol"; * Thirdweb's Multiwrap contract lets you wrap arbitrary ERC20, ERC721 and ERC1155 * tokens you own into a single wrapped token / NFT. * - * A wrapped NFT can be unwrapped i.e. burned in exchange for its underlying contents. + * A wrapped NFT can be unwrapped i.e. burned in exchange for its underlying contents. */ interface IMultiwrap is IThirdwebContract, IThirdwebOwnable, IThirdwebRoyalty { - /// @notice The type of assets that can be wrapped. - enum TokenType { ERC20, ERC721, ERC1155 } + enum TokenType { + ERC20, + ERC721, + ERC1155 + } /** * @notice A generic interface to describe a token to wrap. @@ -81,8 +84,5 @@ interface IMultiwrap is IThirdwebContract, IThirdwebOwnable, IThirdwebRoyalty { * @param tokenId The token Id of the wrapped NFT to unwrap. * @param recipient The recipient of the underlying ERC1155, ERC721, ERC20 tokens of the wrapped NFT. */ - function unwrap( - uint256 tokenId, - address recipient - ) external; + function unwrap(uint256 tokenId, address recipient) external; } diff --git a/contracts/multiwrap/Multiwrap.sol b/contracts/multiwrap/Multiwrap.sol index ade262bee..df7fdd57f 100644 --- a/contracts/multiwrap/Multiwrap.sol +++ b/contracts/multiwrap/Multiwrap.sol @@ -120,7 +120,7 @@ contract Multiwrap is modifier onlyMinter() { // if transfer is restricted on the contract, we still want to allow burning and minting if (!hasRole(MINTER_ROLE, address(0))) { - require(hasRole(MINTER_ROLE, _msgSender()) , "restricted to MINTER_ROLE holders."); + require(hasRole(MINTER_ROLE, _msgSender()), "restricted to MINTER_ROLE holders."); } _; @@ -195,7 +195,7 @@ contract Multiwrap is tokenId = nextTokenIdToMint; nextTokenIdToMint += 1; - for(uint256 i = 0; i < _wrappedContents.length; i += 1) { + for (uint256 i = 0; i < _wrappedContents.length; i += 1) { wrappedContents[tokenId].token[i] = _wrappedContents[i]; } wrappedContents[tokenId].count = _wrappedContents.length; @@ -210,10 +210,7 @@ contract Multiwrap is } /// @dev Unwrap a wrapped NFT to retrieve underlying ERC1155, ERC721, ERC20 tokens. - function unwrap( - uint256 _tokenId, - address _recipient - ) external nonReentrant { + function unwrap(uint256 _tokenId, address _recipient) external nonReentrant { require(_tokenId < nextTokenIdToMint, "invalid tokenId"); require(_isApprovedOrOwner(_msgSender(), _tokenId), "unapproved called"); @@ -222,7 +219,7 @@ contract Multiwrap is uint256 count = wrappedContents[_tokenId].count; Token[] memory tokensUnwrapped = new Token[](count); - for(uint256 i = 0; i < count; i += 1) { + for (uint256 i = 0; i < count; i += 1) { tokensUnwrapped[i] = wrappedContents[_tokenId].token[i]; transferToken(address(this), _recipient, tokensUnwrapped[i]); } @@ -233,8 +230,12 @@ contract Multiwrap is } /// @dev Transfers an arbitrary ERC20 / ERC721 / ERC1155 token. - function transferToken(address _from, address _to, Token memory _token) internal { - if(_token.tokenType == TokenType.ERC20) { + function transferToken( + address _from, + address _to, + Token memory _token + ) internal { + if (_token.tokenType == TokenType.ERC20) { CurrencyTransferLib.transferCurrencyWithWrapper( _token.assetContract, _from, @@ -242,16 +243,20 @@ contract Multiwrap is _token.amount, nativeTokenWrapper ); - } else if(_token.tokenType == TokenType.ERC721) { + } else if (_token.tokenType == TokenType.ERC721) { IERC721Upgradeable(_token.assetContract).safeTransferFrom(_from, _to, _token.tokenId); - } else if(_token.tokenType == TokenType.ERC1155) { + } else if (_token.tokenType == TokenType.ERC1155) { IERC1155Upgradeable(_token.assetContract).safeTransferFrom(_from, _to, _token.tokenId, _token.amount, ""); } } /// @dev Transfers multiple arbitrary ERC20 / ERC721 / ERC1155 tokens. - function transferTokenBatch(address _from, address _to, Token[] memory _tokens) internal { - for(uint256 i = 0; i < _tokens.length; i += 1) { + function transferTokenBatch( + address _from, + address _to, + Token[] memory _tokens + ) internal { + for (uint256 i = 0; i < _tokens.length; i += 1) { transferToken(_from, _to, _tokens[i]); } } diff --git a/src/test/Multiwrap.t.sol b/src/test/Multiwrap.t.sol index 9928c53c2..fe9c76018 100644 --- a/src/test/Multiwrap.t.sol +++ b/src/test/Multiwrap.t.sol @@ -71,24 +71,30 @@ contract MultiwrapTest is BaseTest, IMultiwrapData { tokenOwner.setApprovalForAllERC1155(address(erc1155), address(multiwrap), true); // Prepare wrapped contents. - wrappedContents.push(IMultiwrap.Token({ - assetContract: address(erc20), - tokenType: IMultiwrap.TokenType.ERC20, - tokenId: 0, - amount: erc20Amount - })); - wrappedContents.push(IMultiwrap.Token({ - assetContract: address(erc721), - tokenType: IMultiwrap.TokenType.ERC721, - tokenId: erc721TokenId, - amount: 1 - })); - wrappedContents.push(IMultiwrap.Token({ - assetContract: address(erc1155), - tokenType: IMultiwrap.TokenType.ERC1155, - tokenId: erc1155TokenId, - amount: erc1155Amount - })); + wrappedContents.push( + IMultiwrap.Token({ + assetContract: address(erc20), + tokenType: IMultiwrap.TokenType.ERC20, + tokenId: 0, + amount: erc20Amount + }) + ); + wrappedContents.push( + IMultiwrap.Token({ + assetContract: address(erc721), + tokenType: IMultiwrap.TokenType.ERC721, + tokenId: erc721TokenId, + amount: 1 + }) + ); + wrappedContents.push( + IMultiwrap.Token({ + assetContract: address(erc1155), + tokenType: IMultiwrap.TokenType.ERC1155, + tokenId: erc1155TokenId, + amount: erc1155Amount + }) + ); } // ===== Initial state ===== @@ -112,7 +118,6 @@ contract MultiwrapTest is BaseTest, IMultiwrapData { /// @dev Test `wrap` function test_wrap() public { - assertEq(erc20.balanceOf(address(tokenOwner)), erc20Amount); assertEq(erc721.ownerOf(erc721TokenId), address(tokenOwner)); assertEq(erc1155.balanceOf(address(tokenOwner), erc1155TokenId), erc1155Amount); @@ -194,7 +199,7 @@ contract MultiwrapTest is BaseTest, IMultiwrapData { uint256 tokenIdOfWrapped = multiwrap.nextTokenIdToMint(); IMultiwrap.Token[] memory contents = new IMultiwrap.Token[](wrappedContents.length); - for(uint256 i = 0; i < wrappedContents.length; i += 1) { + for (uint256 i = 0; i < wrappedContents.length; i += 1) { contents[i] = wrappedContents[i]; } @@ -207,7 +212,6 @@ contract MultiwrapTest is BaseTest, IMultiwrapData { /// @dev Test `unwrap` - function test_unwrap() public { uint256 tokenIdOfWrapped = multiwrap.nextTokenIdToMint(); @@ -246,7 +250,6 @@ contract MultiwrapTest is BaseTest, IMultiwrapData { multiwrap.unwrap(invalidId, address(wrappedTokenRecipient)); } - function test_unwrap_emit_Unwrapped() public { uint256 tokenIdOfWrapped = multiwrap.nextTokenIdToMint(); @@ -254,12 +257,17 @@ contract MultiwrapTest is BaseTest, IMultiwrapData { multiwrap.wrap(wrappedContents, uriForWrappedToken, address(wrappedTokenRecipient)); IMultiwrap.Token[] memory contents = new IMultiwrap.Token[](wrappedContents.length); - for(uint256 i = 0; i < wrappedContents.length; i += 1) { + for (uint256 i = 0; i < wrappedContents.length; i += 1) { contents[i] = wrappedContents[i]; } vm.expectEmit(true, true, true, true); - emit TokensUnwrapped(address(wrappedTokenRecipient), address(wrappedTokenRecipient), tokenIdOfWrapped, contents); + emit TokensUnwrapped( + address(wrappedTokenRecipient), + address(wrappedTokenRecipient), + tokenIdOfWrapped, + contents + ); vm.prank(address(wrappedTokenRecipient)); multiwrap.unwrap(tokenIdOfWrapped, address(wrappedTokenRecipient)); diff --git a/src/test/benchmark/MultiwrapBenchmark.t.sol b/src/test/benchmark/MultiwrapBenchmark.t.sol index 8f20e66b6..6563e9862 100644 --- a/src/test/benchmark/MultiwrapBenchmark.t.sol +++ b/src/test/benchmark/MultiwrapBenchmark.t.sol @@ -64,48 +64,59 @@ contract MultiwrapBenchmarkTest is BaseTest { // Prepare wrapped contents. - for(uint256 i = 0; i < 5; i += 1) { - fiveERC721NFts.push(IMultiwrap.Token({ + for (uint256 i = 0; i < 5; i += 1) { + fiveERC721NFts.push( + IMultiwrap.Token({ + assetContract: address(erc721), + tokenType: IMultiwrap.TokenType.ERC721, + tokenId: i, + amount: 1 + }) + ); + } + + wrappedContents.push( + IMultiwrap.Token({ + assetContract: address(erc20), + tokenType: IMultiwrap.TokenType.ERC20, + tokenId: 0, + amount: erc20Amount + }) + ); + wrappedContents.push( + IMultiwrap.Token({ assetContract: address(erc721), tokenType: IMultiwrap.TokenType.ERC721, - tokenId: i, + tokenId: erc721TokenId, amount: 1 - })); - - } + }) + ); + wrappedContents.push( + IMultiwrap.Token({ + assetContract: address(erc1155), + tokenType: IMultiwrap.TokenType.ERC1155, + tokenId: erc1155TokenId, + amount: erc1155Amount + }) + ); + + oneERC721NFTWithERC20Token.push( + IMultiwrap.Token({ + assetContract: address(erc20), + tokenType: IMultiwrap.TokenType.ERC20, + tokenId: 0, + amount: erc20Amount + }) + ); + oneERC721NFTWithERC20Token.push( + IMultiwrap.Token({ + assetContract: address(erc721), + tokenType: IMultiwrap.TokenType.ERC721, + tokenId: erc721TokenId, + amount: 1 + }) + ); - wrappedContents.push(IMultiwrap.Token({ - assetContract: address(erc20), - tokenType: IMultiwrap.TokenType.ERC20, - tokenId: 0, - amount: erc20Amount - })); - wrappedContents.push(IMultiwrap.Token({ - assetContract: address(erc721), - tokenType: IMultiwrap.TokenType.ERC721, - tokenId: erc721TokenId, - amount: 1 - })); - wrappedContents.push(IMultiwrap.Token({ - assetContract: address(erc1155), - tokenType: IMultiwrap.TokenType.ERC1155, - tokenId: erc1155TokenId, - amount: erc1155Amount - })); - - oneERC721NFTWithERC20Token.push(IMultiwrap.Token({ - assetContract: address(erc20), - tokenType: IMultiwrap.TokenType.ERC20, - tokenId: 0, - amount: erc20Amount - })); - oneERC721NFTWithERC20Token.push(IMultiwrap.Token({ - assetContract: address(erc721), - tokenType: IMultiwrap.TokenType.ERC721, - tokenId: erc721TokenId, - amount: 1 - })); - vm.startPrank(address(tokenOwner)); }