ERC1155 Wrapper
The ERC1155 Wrapper contract allows for the wrapping of ERC1155, and for the burning of Item-wrapped ERC1155 to retrieve the original tokens.
You can wrap ERC1155 as Items:
- ERC1155 standard with 0 decimals
- ERC1155 with 18 decimals (such as Items)
A wrapped ERC1155 Item has the following metadata:
- Name -> "ERC1155 token wrapped name" + item
- Symbol -> i"ERC1155 token wrapped symbol"
Example
Wrapped Rarible:
name -> Rarible item symbol -> iRARIWrapped Parallel:
name -> Parallel item symbol -> iLL
All Item-wrapped ERC1155s always have 18 decimals, both as ERC1155 (using the Item Main Interface) and as ERC20 (using the Item Interoperable Interface).
Example
1)Wrapping 3 Zerion (which has no decimals) becomes 3000000000000000000 (3e18) wrapped Item Zerion.2)Wrapping 1 Parallel (which has no decimals) becomes 1000000000000000000 (1e18) wrapped Item Parallel.
The unwrapping / re-wrapping logic for an ERC1155 depends on its decimals and total supply (i.e. the wrapped quantity of that 1155).
- If the original ERC1155 is an Item, and so was wrapped using its Main Interface with 18 decimals, it is a fungible token. In this case, you can unwrap and then re-wrap any quantity.
- If the original ERC1155 token has the standard 0 decimals, and its total supply is 1, the unwrap / re-wrap logic for it is the same logic of the wrapper 721 explained here.
- If the original ERC1155 token has the standard 0 decimals, and its total supply is greater than 1, you can only unwrap it by burning unitary quantities such as 1e18, 2e18 etc. You can, however, transfer any quantity of it that you like.
Example:
To unwrap 1 such Item-wrapped ERC1155, you must burn 1e18. To unwrap 5, you must burn 5e18. If you re-wrap 1 such un-wrapped ERC1155 token, you receive 1e18 wrapped Items. If you re-wrap 5, you receive 5e18.
Before wrapping your ERC1155, make sure your token follows the ERC1155 standard. In particular, make sure that your token:
- integrates the standard IERC1155 interface
- has 0 or 18 decimals
- has a
safeTransferFrom/safeBatchTranfserfFrom
function in order to correctly wrap and unwrap the token
In order to wrap 1155, you can use the
safeTransferFrom
sending the 1155 token to the Wrapper ERC1155 contract invoking the onERC1155Received
function. The
data
parameter of the safeTransferFrom
function must contain an encoded value that represents two parameters:Uint256[] values
-> represents the amount of Wrapped item to send to each receiver address. The values must be expressed in 0 decimals (such as 1, 2, 3 and so on) if you're wrapping a 0 decimals ERC1155 or in 18 decimals (1e18,2e18 and so on) if you're wrapping a 18 decimals ERC1155Address[] receivers
-> address receivers of the Deck Item. Passaddress(0)
to set receiver asmsg.sender
. It can even be an address different from themsg.sender
values []
and receivers[]
length must match .You can also use the
safeBatchTransferFrom
sending multiple 1155 tokens to the Wrapper ERC1155 contract invoking the onERC1155BatchReceived
function. The
data
parameter of the safeBatchTransferFrom
function must be a bytes[]. Each element of the array must contain the following encoded parameters for each id you're wrapping:Uint256 [] values
Address[] receivers
These two parameters are explained above in the onERC1155Received section.
When you're going to wrap an ERC1155 as a Wrapped Item, and the Wrapped Item's totalSupply is <1, you obtain
1e18-Wrapped Item total supply
. You have to pass 1 as
amounts
parameter of the safeTransferFrom
function whenever more of that ERC1155 is wrapped if it's an ERC1155 with 0 decimals or you have to pass 1e18-Wrapped Item total supply
if it's an ERC1155 with 18 decimals.Examples
1)Parallel Wrapped Items totalSupply 0.3e18When you wrap your Parallel, you obtain 0.7e18 Parallel Wrapped Item and you have to pass 1 as amounts parameter of safeTransferFrom/safeBatchTransferFrom2)Parallel Wrapped Items totalSupply 0.1e18When you wrap 2 Parallel ERC1155s, you obtain 1.9e18 Parallel Wrapped Items, and you have to pass 1 (receiving 0.9e18) as amounts parameter for the first one, and 1e18 for the second one ofsafeTransferFrom/safeBtachTransferFrom
.
function burn(address account, uint256 itemId, uint256 amount, bytes memory data) override(Item, ItemProjection) public
The
burn
function can be used to burn any amount of a wrapped ERC1155, and thereby retrieve that amount of the original ERC1155 tokens.The function takes as input:
address
account
-> represents the address that holds the Item to burn. The address account can correspond to themsg.sender
or not if theburn
function is called from an approvedoperator
address.uint256
itemId
-> represents the id of the wrapped Item to burnuint256
amount
->represents the wrapped Item amount to burnbytes
data
-> it is an encoded value and represents six parameters:tokenAddress
, the address of the original ERC1155 token to get backtokenId
, the id of the original ERC1155 token to get backreceiver
, the address that will receive the original ERC1155 after the burn. Passaddress(0)
to set receiver asmsg.sender
. It can even be an address different from themsg.sender
payload
, an optional payload that can be executed with the safeTransferFrom functionsafe
, a boolean value that represents whether safeTransferFrom will be executed (true) or transferFrom/transfer will be executed (false)withData
, a boolean value that represents whether safeTransferFrom will be executed with the additional payload (true) or without one (false). If safe is false, transferFrom without a payload will be executed, regardless of how withData is populated.
function burnBatch(address account, uint256[] calldata itemIds, uint256[] calldata amounts, bytes memory data) override(Item, ItemProjection) public
The
burnBatch
function can be used to burn multiple wrapped ERC1155 Items amounts and retrieve the relative amounts of the original ERC1155 tokens.The function parameters are the same of the burn function with the following differences:
uint256[]
itemId
anduint256[]
amount
-> are arrays of values since you can unwrap multiple tokens at oncebytes
data
->Thedata
parameter in bytes format is an encoded value and represents abytes[]
(one for each Item involved in the operation) containing the six parameters explained above in the burn section.
Last modified 5mo ago