-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support ERC1155: MultiToken Standard #24
Labels
protocol-transition-complete
Protocol has transitioned to the new state
vote-accepted
Vote for this change has been accepted
Comments
ERC1155 |
I made this a few months ago to test 0x with 1155, might find it useful, although not optimized at all : Click to see code/*
Copyright 2018 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* TO DO :
* + Add support for batchTransferFrom
* + Add support for safeBatchTransferFrom
* + Convert to assembly code
*/
pragma solidity 0.4.24;
import "../../utils/LibBytes/LibBytes.sol";
import "./MixinAuthorizable.sol";
import "multi-token-standard/contracts/token/IERC1155.sol";
contract ERC1155Proxy is MixinAuthorizable
{
using LibBytes for bytes;
// assetData index constants
uint256 constant internal TOKEN_ADDRESS_INDEX = 16; // To use with readAddress()
uint256 constant internal TOKEN_ID_INDEX = 36; // To use with readUint256()
// uint8 constant internal TOKEN_AMOUNT_INDEX = 0x68; // To use with readUint256()
// Id of this proxy.
bytes4 constant internal PROXY_ID = bytes4(keccak256("ERC1155Token(address,uint256)"));
/// @dev Transfers assets. Either succeeds or throws.
/// @param assetData Byte array encoded for the respective asset proxy.
/// @param from Address to transfer asset from.
/// @param to Address to transfer asset to.
/// @param amount Amount of asset to transfer.
function transferFrom(
bytes assetData,
address from,
address to,
uint256 amount
)
external
{
// Asset data itself is encoded as follows:
//
// | Area | Offset | Length | Contents |
// |----------|--------|---------|-------------------------------------|
// | Header | 0 | 4 | Proxy ID |
// | Params | | 2 * 32 | Function parameters: |
// | | 4 | 12 + 20 | 1. Token address |
// | | 36 | 32 | 2. Token Id |
// | | | | |
// Token address
address token = assetData.readAddress(TOKEN_ADDRESS_INDEX);
// Token Id
uint256 tokenId = assetData.readUint256(TOKEN_ID_INDEX);
// Transfer token in ERC155 contract
IERC1155(token).safeTransferFrom(from, to, tokenId, amount, '');
}
/// @dev Gets the proxy id associated with the proxy address.
/// @return Proxy id.
function getProxyId()
external
pure
returns (bytes4)
{
return PROXY_ID;
}
} |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
protocol-transition-complete
Protocol has transitioned to the new state
vote-accepted
Vote for this change has been accepted
Summary
The current
AssetProxy
contracts allow an order to buy or sell ERC20 and ERC721 assets. This proposes a newAssetProxy
to enable the exchange of assets managed by an ERC1155 contract, which provides a standard interface for managing a collection of fungible and non-fungible assets.Motivation
Existing token standards (ERC20, ERC721) require a separate smart contract to manage each asset. ERC1155 defines an interface for a contract that manages a collection of assets. Applications range from game assets to deposit and staking contracts.
Specification
Requirements
ERC1155Proxy
should be able to transfer any number of fungible/non-fungible ERC1155 assetsERC1155Proxy
should only be callable by approved senders (the exchange contract and multi asset proxy)ERC1155Proxy
should support partial fills: the amount of each asset transferred should be proportional to the amount that the order is filled (see Fill Scenarios section below).Asset Data Encoding
The ERC1155Proxy should expect data to be encoded using the following function signature:
Arguments:
Fill Scenarios
Fills operate in a similar way to the MultiAssetProxy. Values encoded in the asset data are multiplied by the amount to compute the total quantity of an asset to transfer.
Note that partial fills of non-fungible assets should be prohibited by the maker by setting the amount to 1. The proxy cannot distinguish between fungible and non-fungible assets, so it cannot force partial fills to fail in this scenario. If the amount is not set to 1 and an asset is non-fungible then the behavior depends on the implementation of the ERC1155 contract.
Architecture
The
ERC1155Proxy
inheritsMixinAuthorizable
. Like theERC20Proxy
andERC721Proxy
, this contract must be registered with theExchange
andMultiAssetProxy
, which in turn must be authorized to callERC1155Proxy.transferFrom
.When an order's asset data specifies the
ERC1155Proxy
, the chain of calls looks like:Exchange
contractExchange
callsERC1155Proxy
ERC1155Proxy
callsbatchTransferFrom
on the destination ERC1155 contractOR
Exchange
contractExchange
callsMultiAssetProxy
MultiAssetProxy
decodes the 1155 asset data and callsERC1155Proxy
ERC1155Proxy
callsbatchTransferFrom
on the destination ERC1155 contractReference Implementation
Below is the reference implementation for the
ERC1155Proxy
contract. The optimized version is under development and can be found in the 0x codebase here.Issues
makerAssetAmount
ortakerAssetAmount
to 1. That said, this is the same trust model used by existing proxies, like theMultiAssetProxy
which has the same issue.The text was updated successfully, but these errors were encountered: