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)

Wrapper ERC1155 contract code - Wrapper ERC1155 address

Wrapped Item name and symbol

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 -> iRARI
Wrapped Parallel:
  • name -> Parallel item
  • symbol -> iLL

Decimals

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.

Unwrapping / Re-wrapping Logic and Quantity

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 quantity 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 quantity 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.

Wrap an ERC1155

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

onERC1155Received

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 ERC1155
  • Address[] receivers -> address receivers of the Deck Item. Pass address(0) to set receiver as msg.sender. It can even be an address different from the msg.sender
values [] and receivers[] length must match .

onERC1155BatchReceived

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.

Unwrap Items

Burn

1
function burn(address account, uint256 itemId, uint256 amount, bytes memory data) override(Item, ItemProjection) public
Copied!
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 the msg.sender or not if the burn function is called from an approved operator address.
  • uint256 itemId -> represents the id of the wrapped Item to burn
  • uint256 amount ->represents the wrapped Item amount to burn
  • bytes data -> it is an encoded value and represents six parameters:
    • tokenAddress, the address of the original ERC1155 token to get back
    • tokenId, the id of the original ERC1155 token to get back
    • receiver, the address that will receive the original ERC1155 after the burn. Pass address(0) to set receiver as msg.sender. It can even be an address different from the msg.sender
    • payload, an optional payload that can be executed with the safeTransferFrom function
    • safe, 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.

Burn Batch

1
function burnBatch(address account, uint256[] calldata itemIds, uint256[] calldata amounts, bytes memory data) override(Item, ItemProjection) public
Copied!
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 and uint256[] amount-> are arrays of values since you can unwrap multiple tokens at once
  • bytes data ->The data parameter in bytes format is an encoded value and represents a bytes[] (one for each Item involved in the operation) containing the six parameters explained above in the burn section.