diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-06-01 07:31:00 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-06-08 06:38:48 +0800 |
commit | 249a1e6d8d129d6b067a4ddadfb4b94733ddfc07 (patch) | |
tree | b4bc308a8653e14a67298cdf75c8d84278bb8195 /packages/contracts | |
parent | e042e0ad32cd2ac9e707cb8e52961957f58314ce (diff) | |
download | dexon-sol-tools-249a1e6d8d129d6b067a4ddadfb4b94733ddfc07.tar.gz dexon-sol-tools-249a1e6d8d129d6b067a4ddadfb4b94733ddfc07.tar.zst dexon-sol-tools-249a1e6d8d129d6b067a4ddadfb4b94733ddfc07.zip |
Removed the LibAssetProxyDecoder. Merged decode functions into the proxies. This way they can still be used by the forwarding contract. TestAssetDataDecoders inherits them in the same way the forwarding contract would
Diffstat (limited to 'packages/contracts')
-rw-r--r-- | packages/contracts/compiler.json | 2 | ||||
-rw-r--r-- | packages/contracts/package.json | 2 | ||||
-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 | ||||
-rw-r--r-- | packages/contracts/test/asset_proxy/decoder.ts | 10 |
9 files changed, 64 insertions, 95 deletions
diff --git a/packages/contracts/compiler.json b/packages/contracts/compiler.json index 464137d9b..6ef8e6a95 100644 --- a/packages/contracts/compiler.json +++ b/packages/contracts/compiler.json @@ -29,7 +29,7 @@ "MixinAuthorizable", "MultiSigWallet", "MultiSigWalletWithTimeLock", - "TestLibAssetProxyDecoder", + "TestAssetDataDecoders", "TestAssetProxyDispatcher", "TestLibBytes", "TestLibMem", diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 658f5ed60..e436ae15e 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -30,7 +30,7 @@ "test:circleci": "yarn test" }, "config": { - "abis": "../migrations/artifacts/2.0.0/@(AssetProxyOwner|DummyERC20Token|DummyERC721Token|DummyERC721Receiver|ERC20Proxy|ERC721Proxy|Exchange|MixinAuthorizable|MultiSigWallet|MultiSigWalletWithTimeLock|TestAssetProxyDispatcher|TestLibAssetProxyDecoder|TestLibBytes|TestLibMem|TestLibs|TestSignatureValidator|TokenRegistry|Whitelist|WETH9|ZRXToken).json" + "abis": "../migrations/artifacts/2.0.0/@(AssetProxyOwner|DummyERC20Token|DummyERC721Token|DummyERC721Receiver|ERC20Proxy|ERC721Proxy|Exchange|MixinAuthorizable|MultiSigWallet|MultiSigWalletWithTimeLock|TestAssetDataDecoders|TestAssetProxyDispatcher|TestLibBytes|TestLibMem|TestLibs|TestSignatureValidator|TokenRegistry|Whitelist|WETH9|ZRXToken).json" }, "repository": { "type": "git", 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', diff --git a/packages/contracts/test/asset_proxy/decoder.ts b/packages/contracts/test/asset_proxy/decoder.ts index 712ef8656..8c1253d5c 100644 --- a/packages/contracts/test/asset_proxy/decoder.ts +++ b/packages/contracts/test/asset_proxy/decoder.ts @@ -7,12 +7,12 @@ import * as chai from 'chai'; import ethUtil = require('ethereumjs-util'); import * as Web3 from 'web3'; -import { TestLibAssetProxyDecoderContract } from '../../src/contract_wrappers/generated/test_lib_asset_proxy_decoder'; +import { TestAssetDataDecodersContract } from '../../src/contract_wrappers/generated/test_asset_data_decoders'; import { artifacts } from '../../src/utils/artifacts'; import { assetProxyUtils } from '../../src/utils/asset_proxy_utils'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; -import { AssetProxyId, ERC20AssetData, ERC721AssetData, AssetData } from '../../src/utils/types'; +import { AssetData, AssetProxyId, ERC20AssetData, ERC721AssetData } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -21,7 +21,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); describe('LibAssetProxyDecoder', () => { let owner: string; - let testAssetProxyDecoder: TestLibAssetProxyDecoderContract; + let testAssetProxyDecoder: TestAssetDataDecodersContract; let testAddress: string; before(async () => { @@ -30,8 +30,8 @@ describe('LibAssetProxyDecoder', () => { owner = accounts[0]; testAddress = accounts[1]; // Deploy TestLibMem - testAssetProxyDecoder = await TestLibAssetProxyDecoderContract.deployFrom0xArtifactAsync( - artifacts.TestLibAssetProxyDecoder, + testAssetProxyDecoder = await TestAssetDataDecodersContract.deployFrom0xArtifactAsync( + artifacts.TestAssetDataDecoders, provider, txDefaults, ); |