Skip to content

Commit b5ea712

Browse files
Krishang NadgaudaKrishang Nadgauda
authored andcommitted
run prettier
1 parent b0e754e commit b5ea712

File tree

4 files changed

+106
-82
lines changed

4 files changed

+106
-82
lines changed

contracts/interfaces/IMultiwrap.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ import "./IThirdwebOwnable.sol";
99
* Thirdweb's Multiwrap contract lets you wrap arbitrary ERC20, ERC721 and ERC1155
1010
* tokens you own into a single wrapped token / NFT.
1111
*
12-
* A wrapped NFT can be unwrapped i.e. burned in exchange for its underlying contents.
12+
* A wrapped NFT can be unwrapped i.e. burned in exchange for its underlying contents.
1313
*/
1414

1515
interface IMultiwrap is IThirdwebContract, IThirdwebOwnable, IThirdwebRoyalty {
16-
1716
/// @notice The type of assets that can be wrapped.
18-
enum TokenType { ERC20, ERC721, ERC1155 }
17+
enum TokenType {
18+
ERC20,
19+
ERC721,
20+
ERC1155
21+
}
1922

2023
/**
2124
* @notice A generic interface to describe a token to wrap.
@@ -81,8 +84,5 @@ interface IMultiwrap is IThirdwebContract, IThirdwebOwnable, IThirdwebRoyalty {
8184
* @param tokenId The token Id of the wrapped NFT to unwrap.
8285
* @param recipient The recipient of the underlying ERC1155, ERC721, ERC20 tokens of the wrapped NFT.
8386
*/
84-
function unwrap(
85-
uint256 tokenId,
86-
address recipient
87-
) external;
87+
function unwrap(uint256 tokenId, address recipient) external;
8888
}

contracts/multiwrap/Multiwrap.sol

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ contract Multiwrap is
120120
modifier onlyMinter() {
121121
// if transfer is restricted on the contract, we still want to allow burning and minting
122122
if (!hasRole(MINTER_ROLE, address(0))) {
123-
require(hasRole(MINTER_ROLE, _msgSender()) , "restricted to MINTER_ROLE holders.");
123+
require(hasRole(MINTER_ROLE, _msgSender()), "restricted to MINTER_ROLE holders.");
124124
}
125125

126126
_;
@@ -195,7 +195,7 @@ contract Multiwrap is
195195
tokenId = nextTokenIdToMint;
196196
nextTokenIdToMint += 1;
197197

198-
for(uint256 i = 0; i < _wrappedContents.length; i += 1) {
198+
for (uint256 i = 0; i < _wrappedContents.length; i += 1) {
199199
wrappedContents[tokenId].token[i] = _wrappedContents[i];
200200
}
201201
wrappedContents[tokenId].count = _wrappedContents.length;
@@ -210,10 +210,7 @@ contract Multiwrap is
210210
}
211211

212212
/// @dev Unwrap a wrapped NFT to retrieve underlying ERC1155, ERC721, ERC20 tokens.
213-
function unwrap(
214-
uint256 _tokenId,
215-
address _recipient
216-
) external nonReentrant {
213+
function unwrap(uint256 _tokenId, address _recipient) external nonReentrant {
217214
require(_tokenId < nextTokenIdToMint, "invalid tokenId");
218215
require(_isApprovedOrOwner(_msgSender(), _tokenId), "unapproved called");
219216

@@ -222,7 +219,7 @@ contract Multiwrap is
222219
uint256 count = wrappedContents[_tokenId].count;
223220
Token[] memory tokensUnwrapped = new Token[](count);
224221

225-
for(uint256 i = 0; i < count; i += 1) {
222+
for (uint256 i = 0; i < count; i += 1) {
226223
tokensUnwrapped[i] = wrappedContents[_tokenId].token[i];
227224
transferToken(address(this), _recipient, tokensUnwrapped[i]);
228225
}
@@ -233,25 +230,33 @@ contract Multiwrap is
233230
}
234231

235232
/// @dev Transfers an arbitrary ERC20 / ERC721 / ERC1155 token.
236-
function transferToken(address _from, address _to, Token memory _token) internal {
237-
if(_token.tokenType == TokenType.ERC20) {
233+
function transferToken(
234+
address _from,
235+
address _to,
236+
Token memory _token
237+
) internal {
238+
if (_token.tokenType == TokenType.ERC20) {
238239
CurrencyTransferLib.transferCurrencyWithWrapper(
239240
_token.assetContract,
240241
_from,
241242
_to,
242243
_token.amount,
243244
nativeTokenWrapper
244245
);
245-
} else if(_token.tokenType == TokenType.ERC721) {
246+
} else if (_token.tokenType == TokenType.ERC721) {
246247
IERC721Upgradeable(_token.assetContract).safeTransferFrom(_from, _to, _token.tokenId);
247-
} else if(_token.tokenType == TokenType.ERC1155) {
248+
} else if (_token.tokenType == TokenType.ERC1155) {
248249
IERC1155Upgradeable(_token.assetContract).safeTransferFrom(_from, _to, _token.tokenId, _token.amount, "");
249250
}
250251
}
251252

252253
/// @dev Transfers multiple arbitrary ERC20 / ERC721 / ERC1155 tokens.
253-
function transferTokenBatch(address _from, address _to, Token[] memory _tokens) internal {
254-
for(uint256 i = 0; i < _tokens.length; i += 1) {
254+
function transferTokenBatch(
255+
address _from,
256+
address _to,
257+
Token[] memory _tokens
258+
) internal {
259+
for (uint256 i = 0; i < _tokens.length; i += 1) {
255260
transferToken(_from, _to, _tokens[i]);
256261
}
257262
}

src/test/Multiwrap.t.sol

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,30 @@ contract MultiwrapTest is BaseTest, IMultiwrapData {
7171
tokenOwner.setApprovalForAllERC1155(address(erc1155), address(multiwrap), true);
7272

7373
// Prepare wrapped contents.
74-
wrappedContents.push(IMultiwrap.Token({
75-
assetContract: address(erc20),
76-
tokenType: IMultiwrap.TokenType.ERC20,
77-
tokenId: 0,
78-
amount: erc20Amount
79-
}));
80-
wrappedContents.push(IMultiwrap.Token({
81-
assetContract: address(erc721),
82-
tokenType: IMultiwrap.TokenType.ERC721,
83-
tokenId: erc721TokenId,
84-
amount: 1
85-
}));
86-
wrappedContents.push(IMultiwrap.Token({
87-
assetContract: address(erc1155),
88-
tokenType: IMultiwrap.TokenType.ERC1155,
89-
tokenId: erc1155TokenId,
90-
amount: erc1155Amount
91-
}));
74+
wrappedContents.push(
75+
IMultiwrap.Token({
76+
assetContract: address(erc20),
77+
tokenType: IMultiwrap.TokenType.ERC20,
78+
tokenId: 0,
79+
amount: erc20Amount
80+
})
81+
);
82+
wrappedContents.push(
83+
IMultiwrap.Token({
84+
assetContract: address(erc721),
85+
tokenType: IMultiwrap.TokenType.ERC721,
86+
tokenId: erc721TokenId,
87+
amount: 1
88+
})
89+
);
90+
wrappedContents.push(
91+
IMultiwrap.Token({
92+
assetContract: address(erc1155),
93+
tokenType: IMultiwrap.TokenType.ERC1155,
94+
tokenId: erc1155TokenId,
95+
amount: erc1155Amount
96+
})
97+
);
9298
}
9399

94100
// ===== Initial state =====
@@ -112,7 +118,6 @@ contract MultiwrapTest is BaseTest, IMultiwrapData {
112118

113119
/// @dev Test `wrap`
114120
function test_wrap() public {
115-
116121
assertEq(erc20.balanceOf(address(tokenOwner)), erc20Amount);
117122
assertEq(erc721.ownerOf(erc721TokenId), address(tokenOwner));
118123
assertEq(erc1155.balanceOf(address(tokenOwner), erc1155TokenId), erc1155Amount);
@@ -194,7 +199,7 @@ contract MultiwrapTest is BaseTest, IMultiwrapData {
194199
uint256 tokenIdOfWrapped = multiwrap.nextTokenIdToMint();
195200

196201
IMultiwrap.Token[] memory contents = new IMultiwrap.Token[](wrappedContents.length);
197-
for(uint256 i = 0; i < wrappedContents.length; i += 1) {
202+
for (uint256 i = 0; i < wrappedContents.length; i += 1) {
198203
contents[i] = wrappedContents[i];
199204
}
200205

@@ -207,7 +212,6 @@ contract MultiwrapTest is BaseTest, IMultiwrapData {
207212

208213
/// @dev Test `unwrap`
209214

210-
211215
function test_unwrap() public {
212216
uint256 tokenIdOfWrapped = multiwrap.nextTokenIdToMint();
213217

@@ -246,20 +250,24 @@ contract MultiwrapTest is BaseTest, IMultiwrapData {
246250
multiwrap.unwrap(invalidId, address(wrappedTokenRecipient));
247251
}
248252

249-
250253
function test_unwrap_emit_Unwrapped() public {
251254
uint256 tokenIdOfWrapped = multiwrap.nextTokenIdToMint();
252255

253256
vm.prank(address(tokenOwner));
254257
multiwrap.wrap(wrappedContents, uriForWrappedToken, address(wrappedTokenRecipient));
255258

256259
IMultiwrap.Token[] memory contents = new IMultiwrap.Token[](wrappedContents.length);
257-
for(uint256 i = 0; i < wrappedContents.length; i += 1) {
260+
for (uint256 i = 0; i < wrappedContents.length; i += 1) {
258261
contents[i] = wrappedContents[i];
259262
}
260263

261264
vm.expectEmit(true, true, true, true);
262-
emit TokensUnwrapped(address(wrappedTokenRecipient), address(wrappedTokenRecipient), tokenIdOfWrapped, contents);
265+
emit TokensUnwrapped(
266+
address(wrappedTokenRecipient),
267+
address(wrappedTokenRecipient),
268+
tokenIdOfWrapped,
269+
contents
270+
);
263271

264272
vm.prank(address(wrappedTokenRecipient));
265273
multiwrap.unwrap(tokenIdOfWrapped, address(wrappedTokenRecipient));

src/test/benchmark/MultiwrapBenchmark.t.sol

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -64,48 +64,59 @@ contract MultiwrapBenchmarkTest is BaseTest {
6464

6565
// Prepare wrapped contents.
6666

67-
for(uint256 i = 0; i < 5; i += 1) {
68-
fiveERC721NFts.push(IMultiwrap.Token({
67+
for (uint256 i = 0; i < 5; i += 1) {
68+
fiveERC721NFts.push(
69+
IMultiwrap.Token({
70+
assetContract: address(erc721),
71+
tokenType: IMultiwrap.TokenType.ERC721,
72+
tokenId: i,
73+
amount: 1
74+
})
75+
);
76+
}
77+
78+
wrappedContents.push(
79+
IMultiwrap.Token({
80+
assetContract: address(erc20),
81+
tokenType: IMultiwrap.TokenType.ERC20,
82+
tokenId: 0,
83+
amount: erc20Amount
84+
})
85+
);
86+
wrappedContents.push(
87+
IMultiwrap.Token({
6988
assetContract: address(erc721),
7089
tokenType: IMultiwrap.TokenType.ERC721,
71-
tokenId: i,
90+
tokenId: erc721TokenId,
7291
amount: 1
73-
}));
74-
75-
}
92+
})
93+
);
94+
wrappedContents.push(
95+
IMultiwrap.Token({
96+
assetContract: address(erc1155),
97+
tokenType: IMultiwrap.TokenType.ERC1155,
98+
tokenId: erc1155TokenId,
99+
amount: erc1155Amount
100+
})
101+
);
102+
103+
oneERC721NFTWithERC20Token.push(
104+
IMultiwrap.Token({
105+
assetContract: address(erc20),
106+
tokenType: IMultiwrap.TokenType.ERC20,
107+
tokenId: 0,
108+
amount: erc20Amount
109+
})
110+
);
111+
oneERC721NFTWithERC20Token.push(
112+
IMultiwrap.Token({
113+
assetContract: address(erc721),
114+
tokenType: IMultiwrap.TokenType.ERC721,
115+
tokenId: erc721TokenId,
116+
amount: 1
117+
})
118+
);
76119

77-
wrappedContents.push(IMultiwrap.Token({
78-
assetContract: address(erc20),
79-
tokenType: IMultiwrap.TokenType.ERC20,
80-
tokenId: 0,
81-
amount: erc20Amount
82-
}));
83-
wrappedContents.push(IMultiwrap.Token({
84-
assetContract: address(erc721),
85-
tokenType: IMultiwrap.TokenType.ERC721,
86-
tokenId: erc721TokenId,
87-
amount: 1
88-
}));
89-
wrappedContents.push(IMultiwrap.Token({
90-
assetContract: address(erc1155),
91-
tokenType: IMultiwrap.TokenType.ERC1155,
92-
tokenId: erc1155TokenId,
93-
amount: erc1155Amount
94-
}));
95-
96-
oneERC721NFTWithERC20Token.push(IMultiwrap.Token({
97-
assetContract: address(erc20),
98-
tokenType: IMultiwrap.TokenType.ERC20,
99-
tokenId: 0,
100-
amount: erc20Amount
101-
}));
102-
oneERC721NFTWithERC20Token.push(IMultiwrap.Token({
103-
assetContract: address(erc721),
104-
tokenType: IMultiwrap.TokenType.ERC721,
105-
tokenId: erc721TokenId,
106-
amount: 1
107-
}));
108-
109120
vm.startPrank(address(tokenOwner));
110121
}
111122

0 commit comments

Comments
 (0)