You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contracts/multiwrap/multiwrap.md
+57-19Lines changed: 57 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -1,32 +1,56 @@
1
1
# Multiwrap design document.
2
2
3
-
This is a live document that explains what the [thirdweb](https://thirdweb.com/)`Multiwrap` smart contract is, how it works and can be used, and why it is written the way it is.
3
+
This is a live document that explains what the [thirdweb](https://thirdweb.com/)`Multiwrap` smart contract is, how it works and can be used, and why it is designed the way it is.
4
4
5
-
The document is written for technical and non-technical readers. To ask further questions about thirdweb’s`Multiwrap`, please join the [thirdweb discord](https://discord.gg/thirdweb) or create a github issue.
5
+
The document is written for technical and non-technical readers. To ask further questions about thirdweb’s`Multiwrap` contract, please join the [thirdweb discord](https://discord.gg/thirdweb) or create a github issue.
6
6
7
7
---
8
8
9
9
## Background
10
10
11
11
The thirdweb Multiwrap contract lets you wrap arbitrary ERC20, ERC721 and ERC1155 tokens you own into a single wrapped token / NFT.
12
12
13
-
The`Multiwrap`contract is meant to be used for bundling up multiple assets (ERC20 / ERC721 / ERC1155) into a single wrapped token, which can then be unwrapped in exchange for the underlying tokens.
13
+
The`Multiwrap`contract is meant to be used for bundling up multiple assets (ERC20 / ERC721 / ERC1155) into a single wrapped token, which can then be unwrapped in exchange for the underlying tokens.
14
14
15
15
The single wrapped token received on bundling up multiple assets, as mentioned above, is an ERC721 NFT. It can be transferred, sold on any NFT Marketplace, and generate royalties just like any other NFTs.
16
16
17
+
### How the `Multiwrap` product *should* work
18
+
19
+

20
+
21
+
A token owner should be able to wrap any combination of *n* ERC20, ERC721 or ERC1155 tokens as a wrapped NFT. When wrapping, the token owner should be able to specify a recipient for the wrapped NFT. At the time of wrapping, the token owner should be able to set the metadata of the wrapped NFT that will be minted.
22
+
23
+
The wrapped NFT owner should be able to unwrap the the NFT to retrieve the underlying tokens of the wrapped NFT. At the time of unwrapping, the wrapped NFT owner should be able to specify a recipient for the underlying tokens of the wrapped NFT.
24
+
25
+
The `Multiwrap` contract creator should be able to apply the following role-based restrictions:
26
+
27
+
- Restrict what assets can be wrapped on the contract.
28
+
- Restrict which wallets can wrap tokens on the contract.
29
+
- Restrict what wallets can unwrap owned wrapped NFTs.
30
+
31
+
### Core parts of the `Multiwrap` product
32
+
- A token owner should be able to wrap any combination of *n* ERC20, ERC721 or ERC1155 tokens as a wrapped token.
33
+
- A wrapped token owner should be able to unwrap the token to retrieve the underlying contents of the wrapped token.
34
+
17
35
### Why we’re building `Multiwrap`
18
36
19
-
We're building`Multiwrap`for cases where an application wishes to bundle up / distribute / transact over*n*independent tokens all at once, as a single asset. This opens up several novel NFT use cases.
37
+
We're building`Multiwrap`for cases where an application wishes to bundle up / distribute / transact over*n*independent tokens all at once, as a single asset. This opens up several novel NFT use cases.
20
38
21
-
For example, consider a lending service where people can take out a loan while putting up an NFT as a collateral. Using`Multiwrap`, a borrower can wrap their NFT with some ether, and put up the resultant wrapped ERC721 NFT as collateral on the lending service. Now, the borrower's NFT, as collateral, has a floor value.
39
+
For example, consider a lending service where people can take out a loan while putting up an NFT as a collateral. Using`Multiwrap`, a borrower can wrap their NFT with some ether, and put up the resultant wrapped ERC721 NFT as collateral on the lending service. Now, the borrower's NFT, as collateral, has a floor value.
22
40
23
41
## Technical Details
24
42
25
-
The `Multiwrap` contract itself is an ERC721 contract. It lets you wrap arbitrary ERC20, ERC721 and ERC1155 tokens you own into a single wrapped token / NFT. This means escrowing the relevant ERC20, ERC721 and ERC1155 tokens into the `Multiwrap` contract, and receiving the wrapped NFT in exchange. This wrapped NFT can later be 'unwrapped' i.e. burned in exchange for the underlying tokens.
43
+
The `Multiwrap`contract itself is an ERC721 contract.
44
+
45
+
It lets you wrap arbitrary ERC20, ERC721 or ERC1155 tokens you own into a single wrapped token / NFT. This means escrowing the relevant ERC20, ERC721 and ERC1155 tokens into the `Multiwrap` contract, and receiving the wrapped NFT in exchange.
46
+
47
+
This wrapped NFT can later be 'unwrapped' i.e. burned in exchange for the underlying tokens.
26
48
27
49
### Wrapping tokens
28
50
29
-
To wrap multiple ERC20, ERC721 or ERC1155 tokens as a single wrapped NFT, a token owner must first approve the relevant tokens to be transfered by the `Multiwrap` contract, and the token owner must then specify the tokens to wrapped into a single wrapped NFT. The following is the format in which each token to be wrapped must be specified:
51
+
To wrap multiple ERC20, ERC721 or ERC1155 tokens as a single wrapped NFT, a token owner must:
52
+
- approve the relevant tokens to be transferred by the `Multiwrap` contract.
53
+
- specify the tokens to be wrapped into a single wrapped NFT. The following is the format in which each token to be wrapped must be specified:
30
54
31
55
```solidity
32
56
/// @notice The type of assets that can be wrapped.
@@ -47,7 +71,7 @@ struct Token {
47
71
| tokenId | uint256 | The token Id of the asset to wrap, if the asset is an ERC721 / ERC1155 NFT. |
48
72
| totalAmount | uint256 | The amount of the asset to wrap, if the asset is an ERC20 / ERC1155 fungible token. |
49
73
50
-
Each token in the bundle of tokens to be wrapped as a single wrapped NFT must be specified to the`Multiwrap` contract in the form of the`Token` struct. The contract handles the respective token based on the value of`tokenType`provided. Any incorrect values passed (e.g. the`totalAmount` specified to be wrapped exceeds the token owner's token balance) will cause the wrapping transaction to revert.
74
+
Each token in the bundle of tokens to be wrapped as a single wrapped NFT must be specified to the`Multiwrap` contract in the form of the`Token` struct. The contract handles the respective token based on the value of`tokenType`provided. Any incorrect values passed (e.g. the`totalAmount` specified to be wrapped exceeds the token owner's token balance) will cause the wrapping transaction to revert.
51
75
52
76
Multiple tokens can be wrapped as a single wrapped NFT by calling the following function:
53
77
@@ -65,11 +89,15 @@ function wrap(
65
89
| uriForWrappedToken | string | The metadata URI for the wrapped NFT. |
66
90
| recipient | address | The recipient of the wrapped NFT. |
67
91
68
-
When wrapping multiple assets into a single wrapped NFT, the assets are escrowed in the `Multiwrap` contract until the wrapped NFT is unwrapped.
69
-
70
92
### Unwrapping the wrapped NFT
71
93
72
-
The single wrapped NFT, received on wrapping multiple assets as explained in the previous section, can be unwrapped in exchange for the underlying assets. To unwrap a wrapped NFT, the wrapped NFT owner must specify the wrapped NFT's tokenId, and a recipient who shall receive the wrapped NFT's underlying assets.
94
+
The single wrapped NFT, received on wrapping multiple assets as explained in the previous section, can be unwrapped in exchange for the underlying assets.
95
+
96
+
A wrapped NFT can be unwrapped either by the owner, or a wallet approved by the owner to transfer the NFT via `setApprovalForAll` or `approve` ERC721 functions.
97
+
98
+
When unwrapping the wrapped NFT, the wrapped NFT is burned.****
99
+
100
+
A wrapped NFT can be unwrapped by calling the following function:
73
101
74
102
```solidity
75
103
function unwrap(
@@ -83,18 +111,28 @@ function unwrap(
83
111
| tokenId | Token[]| The token Id of the wrapped NFT to unwrap. |
84
112
| recipient | address | The recipient of the underlying ERC20, ERC721 or ERC1155 tokens of the wrapped NFT. |
85
113
86
-
When unwrapping the single wrapped NFT, the wrapped NFT is burned.
87
-
88
-
### EIPs supported / implemented
89
-
90
-
The `Multiwrap` contract itself is an ERC721 contract i.e. it implements the [ERC721 standard](https://eips.ethereum.org/EIPS/eip-721). The contract also implements receiver interfaces for ERC721 and ERC1155 so it can receive, and thus, escrow ERC721 and ERC1155 tokens.
114
+
## Permissions
91
115
92
-
The contract also implements the [ERC2981](https://eips.ethereum.org/EIPS/eip-2981) royalty standard. That means the single wrapped token received on bundling up multiple assets can generate royalties just like any other NFTs.
116
+
| Role name | Type (Switch / !Switch) | Purpose |
117
+
| -- | -- | -- |
118
+
| TRANSFER_ROLE | Switch | Only token transfers to or from role holders are allowed. |
119
+
| MINTER_ROLE | Switch | Only role holders can wrap tokens. |
120
+
| UNWRAP_ROLE | Switch | Only role holders can unwrap wrapped NFTs. |
121
+
| ASSET_ROLE | Switch | Only assets with the role can be wrapped. |
93
122
123
+
What does **Type (Switch / !Switch)** mean?
124
+
-**Switch:** If `address(0)` has `ROLE`, then the `ROLE` restrictions don't apply.
125
+
-**!Switch:**`ROLE` restrictions always apply.
94
126
95
-
## Limitations
127
+
## Relevant EIPs
96
128
97
-
Given the same interface for `wrap` and `unwrap`, the contract needs to be optimized for gas i.e. consume as much less gas as possible.
129
+
| EIP | Link | Relation to `Multiwrap`|
130
+
| -- | -- | -- |
131
+
| 721 |https://eips.ethereum.org/EIPS/eip-721| Multiwrap itself is an ERC721 contract. The wrapped NFT received by a token owner on wrapping is an ERC721 NFT. Additionally, ERC721 tokens can be wrapped. |
132
+
| 20 |https://eips.ethereum.org/EIPS/eip-20| ERC20 tokens can be wrapped. |
133
+
| 1155 |https://eips.ethereum.org/EIPS/eip-1155| ERC1155 tokens can be wrapped. |
134
+
| 2981 |https://eips.ethereum.org/EIPS/eip-2981| Multiwrap implements ERC 2981 for distributing royalties for sales of the wrapped NFTs. |
135
+
| 2771 |https://eips.ethereum.org/EIPS/eip-2771| Multiwrap implements ERC 2771 to support meta-transactions (aka “gasless” transactions). |
0 commit comments