diff options
Diffstat (limited to 'packages/contracts/src')
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/AssetProxy/ERC20Proxy.sol | 24 | ||||
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/AssetProxy/ERC721Proxy.sol | 29 | ||||
-rw-r--r-- | packages/contracts/src/contracts/current/test/TestAssetDataDecoders/TestAssetDataDecoders.sol (renamed from packages/contracts/src/contracts/current/test/TestLibAssetProxyDecoder/TestLibAssetProxyDecoder.sol) | 12 | ||||
-rw-r--r-- | packages/contracts/src/contracts/current/utils/LibAssetProxyDecoder/LibAssetProxyDecoder.sol | 74 | ||||
-rw-r--r-- | packages/contracts/src/utils/artifacts.ts | 4 | ||||
-rw-r--r-- | packages/contracts/src/utils/types.ts | 2 |
6 files changed, 57 insertions, 88 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxy/ERC20Proxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxy/ERC20Proxy.sol index 5b4367fd9..11383adaf 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxy/ERC20Proxy.sol +++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/ERC20Proxy.sol @@ -20,14 +20,13 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; import "../../utils/LibBytes/LibBytes.sol"; -import "../../utils/LibAssetProxyDecoder/LibAssetProxyDecoder.sol"; +import "../../tokens/ERC20Token/IERC20Token.sol"; import "./MixinAssetProxy.sol"; import "./MixinAuthorizable.sol"; import "../../tokens/ERC20Token/IERC20Token.sol"; contract ERC20Proxy is LibBytes, - LibAssetProxyDecoder, MixinAssetProxy, MixinAuthorizable { @@ -52,7 +51,7 @@ contract ERC20Proxy is ( uint8 proxyId, address token - ) = decodeERC20Data(assetData); + ) = decodeERC20AssetData(assetData); // Data must be intended for this proxy. uint256 length = assetMetadata.length; @@ -79,4 +78,23 @@ contract ERC20Proxy is { return PROXY_ID; } + + /// @dev Decodes ERC20 Asset Proxy data + function decodeERC20AssetData(bytes memory assetData) + internal + pure + returns ( + uint8 proxyId, + address token + ) + { + require( + assetData.length == 21, + INVALID_ASSET_DATA_LENGTH + ); + proxyId = uint8(assetData[0]); + token = readAddress(assetData, 1); + + return (proxyId, token); + } } diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxy/ERC721Proxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxy/ERC721Proxy.sol index e2c445463..eb23736a0 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxy/ERC721Proxy.sol +++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/ERC721Proxy.sol @@ -20,14 +20,12 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; import "../../utils/LibBytes/LibBytes.sol"; -import "../../utils/LibAssetProxyDecoder/LibAssetProxyDecoder.sol"; import "./MixinAssetProxy.sol"; import "./MixinAuthorizable.sol"; import "../../tokens/ERC721Token/ERC721Token.sol"; contract ERC721Proxy is LibBytes, - LibAssetProxyDecoder, MixinAssetProxy, MixinAuthorizable { @@ -56,7 +54,7 @@ contract ERC721Proxy is address token, uint256 tokenId, bytes memory data - ) = decodeERC721Data(assetData); + ) = decodeERC721AssetData(assetData); // Data must be intended for this proxy. uint256 length = assetMetadata.length; @@ -92,4 +90,29 @@ contract ERC721Proxy is { return PROXY_ID; } + + /// @dev Decodes ERC721 Asset Proxy data + function decodeERC721AssetData(bytes memory assetData) + internal + pure + returns ( + uint8 proxyId, + address token, + uint256 tokenId, + bytes memory data + ) + { + require( + assetData.length >= 53, + INVALID_ASSET_DATA_LENGTH + ); + proxyId = uint8(assetData[0]); + token = readAddress(assetData, 1); + tokenId = readUint256(assetData, 21); + if (assetData.length > 53) { + data = readBytes(assetData, 53); + } + + return (proxyId, token, tokenId, data); + } } diff --git a/packages/contracts/src/contracts/current/test/TestLibAssetProxyDecoder/TestLibAssetProxyDecoder.sol b/packages/contracts/src/contracts/current/test/TestAssetDataDecoders/TestAssetDataDecoders.sol index 6d2866656..45787d88b 100644 --- a/packages/contracts/src/contracts/current/test/TestLibAssetProxyDecoder/TestLibAssetProxyDecoder.sol +++ b/packages/contracts/src/contracts/current/test/TestAssetDataDecoders/TestAssetDataDecoders.sol @@ -19,10 +19,12 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; -import "../../utils/LibAssetProxyDecoder/LibAssetProxyDecoder.sol"; +import "../../protocol/AssetProxy/ERC20Proxy.sol"; +import "../../protocol/AssetProxy/ERC721Proxy.sol"; -contract TestLibAssetProxyDecoder is - LibAssetProxyDecoder +contract TestAssetDataDecoders is + ERC20Proxy, + ERC721Proxy { /// @dev Decodes ERC721 Asset Proxy data @@ -31,7 +33,7 @@ contract TestLibAssetProxyDecoder is pure returns (uint8, address) { - return decodeERC20Data(assetData); + return ERC20Proxy.decodeERC20AssetData(assetData); } /// @dev Decodes ERC721 Asset Proxy data @@ -45,6 +47,6 @@ contract TestLibAssetProxyDecoder is bytes memory ) { - return decodeERC721Data(assetData); + return ERC721Proxy.decodeERC721AssetData(assetData); } } diff --git a/packages/contracts/src/contracts/current/utils/LibAssetProxyDecoder/LibAssetProxyDecoder.sol b/packages/contracts/src/contracts/current/utils/LibAssetProxyDecoder/LibAssetProxyDecoder.sol deleted file mode 100644 index ec27502a8..000000000 --- a/packages/contracts/src/contracts/current/utils/LibAssetProxyDecoder/LibAssetProxyDecoder.sol +++ /dev/null @@ -1,74 +0,0 @@ -/* - - 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. - -*/ - -pragma solidity ^0.4.24; -pragma experimental ABIEncoderV2; - -import "../LibBytes/LibBytes.sol"; - -contract LibAssetProxyDecoder is - LibBytes -{ - - string constant INVALID_ERC20_METADATA_LENGTH = "Metadata must have a length of 21."; - string constant INVALID_ERC721_METADATA_LENGTH = "Metadata must have a length of at least 53."; - - /// @dev Decodes ERC721 Asset Proxy data - function decodeERC20Data(bytes memory assetData) - internal - pure - returns ( - uint8 proxyId, - address token - ) - { - require( - assetData.length == 21, - INVALID_ERC20_METADATA_LENGTH - ); - proxyId = uint8(assetData[0]); - token = readAddress(assetData, 1); - - return (proxyId, token); - } - - /// @dev Decodes ERC721 Asset Proxy data - function decodeERC721Data(bytes memory assetData) - internal - pure - returns ( - uint8 proxyId, - address token, - uint256 tokenId, - bytes memory data - ) - { - require( - assetData.length >= 53, - INVALID_ERC721_METADATA_LENGTH - ); - proxyId = uint8(assetData[0]); - token = readAddress(assetData, 1); - tokenId = readUint256(assetData, 21); - if (assetData.length > 53) { - data = readBytes(assetData, 53); - } - - return (proxyId, token, tokenId, data); - } -} diff --git a/packages/contracts/src/utils/artifacts.ts b/packages/contracts/src/utils/artifacts.ts index a1c8483d8..42de7c921 100644 --- a/packages/contracts/src/utils/artifacts.ts +++ b/packages/contracts/src/utils/artifacts.ts @@ -11,7 +11,7 @@ import * as MixinAuthorizable from '../artifacts/MixinAuthorizable.json'; import * as MultiSigWallet from '../artifacts/MultiSigWallet.json'; import * as MultiSigWalletWithTimeLock from '../artifacts/MultiSigWalletWithTimeLock.json'; import * as TestAssetProxyDispatcher from '../artifacts/TestAssetProxyDispatcher.json'; -import * as TestLibAssetProxyDecoder from '../artifacts/TestLibAssetProxyDecoder.json'; +import * as TestAssetDataDecoders from '../artifacts/TestAssetDataDecoders.json'; import * as TestLibBytes from '../artifacts/TestLibBytes.json'; import * as TestLibMem from '../artifacts/TestLibMem.json'; import * as TestLibs from '../artifacts/TestLibs.json'; @@ -34,7 +34,7 @@ export const artifacts = { MultiSigWallet: (MultiSigWallet as any) as ContractArtifact, MultiSigWalletWithTimeLock: (MultiSigWalletWithTimeLock as any) as ContractArtifact, TestAssetProxyDispatcher: (TestAssetProxyDispatcher as any) as ContractArtifact, - TestLibAssetProxyDecoder: (TestLibAssetProxyDecoder as any) as ContractArtifact, + TestAssetDataDecoders: (TestAssetDataDecoders as any) as ContractArtifact, TestLibBytes: (TestLibBytes as any) as ContractArtifact, TestLibMem: (TestLibMem as any) as ContractArtifact, TestLibs: (TestLibs as any) as ContractArtifact, diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts index cccca5705..bb8c12088 100644 --- a/packages/contracts/src/utils/types.ts +++ b/packages/contracts/src/utils/types.ts @@ -90,7 +90,7 @@ export enum ContractName { AccountLevels = 'AccountLevels', EtherDelta = 'EtherDelta', Arbitrage = 'Arbitrage', - TestLibAssetProxyDecoder = 'TestLibAssetProxyDecoder', + TestAssetDataDecoders = 'TestAssetDataDecoders', TestAssetProxyDispatcher = 'TestAssetProxyDispatcher', TestLibMem = 'TestLibMem', TestLibs = 'TestLibs', |