Skip to content

Instantly share code, notes, and snippets.

@PhABC
Last active November 19, 2018 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PhABC/fdbdcc90865f404628e68d4af47d62f8 to your computer and use it in GitHub Desktop.
Save PhABC/fdbdcc90865f404628e68d4af47d62f8 to your computer and use it in GitHub Desktop.
/*
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment