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

This commit is contained in:
Greg Hysen
2018-05-31 16:31:00 -07:00
parent e042e0ad32
commit 249a1e6d8d
9 changed files with 64 additions and 95 deletions

View File

@@ -29,7 +29,7 @@
"MixinAuthorizable", "MixinAuthorizable",
"MultiSigWallet", "MultiSigWallet",
"MultiSigWalletWithTimeLock", "MultiSigWalletWithTimeLock",
"TestLibAssetProxyDecoder", "TestAssetDataDecoders",
"TestAssetProxyDispatcher", "TestAssetProxyDispatcher",
"TestLibBytes", "TestLibBytes",
"TestLibMem", "TestLibMem",

View File

@@ -30,7 +30,7 @@
"test:circleci": "yarn test" "test:circleci": "yarn test"
}, },
"config": { "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": { "repository": {
"type": "git", "type": "git",

View File

@@ -20,14 +20,13 @@ pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../utils/LibBytes/LibBytes.sol"; import "../../utils/LibBytes/LibBytes.sol";
import "../../utils/LibAssetProxyDecoder/LibAssetProxyDecoder.sol"; import "../../tokens/ERC20Token/IERC20Token.sol";
import "./MixinAssetProxy.sol"; import "./MixinAssetProxy.sol";
import "./MixinAuthorizable.sol"; import "./MixinAuthorizable.sol";
import "../../tokens/ERC20Token/IERC20Token.sol"; import "../../tokens/ERC20Token/IERC20Token.sol";
contract ERC20Proxy is contract ERC20Proxy is
LibBytes, LibBytes,
LibAssetProxyDecoder,
MixinAssetProxy, MixinAssetProxy,
MixinAuthorizable MixinAuthorizable
{ {
@@ -52,7 +51,7 @@ contract ERC20Proxy is
( (
uint8 proxyId, uint8 proxyId,
address token address token
) = decodeERC20Data(assetData); ) = decodeERC20AssetData(assetData);
// Data must be intended for this proxy. // Data must be intended for this proxy.
uint256 length = assetMetadata.length; uint256 length = assetMetadata.length;
@@ -79,4 +78,23 @@ contract ERC20Proxy is
{ {
return PROXY_ID; 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);
}
} }

View File

@@ -20,14 +20,12 @@ pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../utils/LibBytes/LibBytes.sol"; import "../../utils/LibBytes/LibBytes.sol";
import "../../utils/LibAssetProxyDecoder/LibAssetProxyDecoder.sol";
import "./MixinAssetProxy.sol"; import "./MixinAssetProxy.sol";
import "./MixinAuthorizable.sol"; import "./MixinAuthorizable.sol";
import "../../tokens/ERC721Token/ERC721Token.sol"; import "../../tokens/ERC721Token/ERC721Token.sol";
contract ERC721Proxy is contract ERC721Proxy is
LibBytes, LibBytes,
LibAssetProxyDecoder,
MixinAssetProxy, MixinAssetProxy,
MixinAuthorizable MixinAuthorizable
{ {
@@ -56,7 +54,7 @@ contract ERC721Proxy is
address token, address token,
uint256 tokenId, uint256 tokenId,
bytes memory data bytes memory data
) = decodeERC721Data(assetData); ) = decodeERC721AssetData(assetData);
// Data must be intended for this proxy. // Data must be intended for this proxy.
uint256 length = assetMetadata.length; uint256 length = assetMetadata.length;
@@ -92,4 +90,29 @@ contract ERC721Proxy is
{ {
return PROXY_ID; 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);
}
} }

View File

@@ -19,10 +19,12 @@
pragma solidity ^0.4.24; pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../utils/LibAssetProxyDecoder/LibAssetProxyDecoder.sol"; import "../../protocol/AssetProxy/ERC20Proxy.sol";
import "../../protocol/AssetProxy/ERC721Proxy.sol";
contract TestLibAssetProxyDecoder is contract TestAssetDataDecoders is
LibAssetProxyDecoder ERC20Proxy,
ERC721Proxy
{ {
/// @dev Decodes ERC721 Asset Proxy data /// @dev Decodes ERC721 Asset Proxy data
@@ -31,7 +33,7 @@ contract TestLibAssetProxyDecoder is
pure pure
returns (uint8, address) returns (uint8, address)
{ {
return decodeERC20Data(assetData); return ERC20Proxy.decodeERC20AssetData(assetData);
} }
/// @dev Decodes ERC721 Asset Proxy data /// @dev Decodes ERC721 Asset Proxy data
@@ -45,6 +47,6 @@ contract TestLibAssetProxyDecoder is
bytes memory bytes memory
) )
{ {
return decodeERC721Data(assetData); return ERC721Proxy.decodeERC721AssetData(assetData);
} }
} }

View File

@@ -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);
}
}

View File

@@ -11,7 +11,7 @@ import * as MixinAuthorizable from '../artifacts/MixinAuthorizable.json';
import * as MultiSigWallet from '../artifacts/MultiSigWallet.json'; import * as MultiSigWallet from '../artifacts/MultiSigWallet.json';
import * as MultiSigWalletWithTimeLock from '../artifacts/MultiSigWalletWithTimeLock.json'; import * as MultiSigWalletWithTimeLock from '../artifacts/MultiSigWalletWithTimeLock.json';
import * as TestAssetProxyDispatcher from '../artifacts/TestAssetProxyDispatcher.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 TestLibBytes from '../artifacts/TestLibBytes.json';
import * as TestLibMem from '../artifacts/TestLibMem.json'; import * as TestLibMem from '../artifacts/TestLibMem.json';
import * as TestLibs from '../artifacts/TestLibs.json'; import * as TestLibs from '../artifacts/TestLibs.json';
@@ -34,7 +34,7 @@ export const artifacts = {
MultiSigWallet: (MultiSigWallet as any) as ContractArtifact, MultiSigWallet: (MultiSigWallet as any) as ContractArtifact,
MultiSigWalletWithTimeLock: (MultiSigWalletWithTimeLock as any) as ContractArtifact, MultiSigWalletWithTimeLock: (MultiSigWalletWithTimeLock as any) as ContractArtifact,
TestAssetProxyDispatcher: (TestAssetProxyDispatcher 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, TestLibBytes: (TestLibBytes as any) as ContractArtifact,
TestLibMem: (TestLibMem as any) as ContractArtifact, TestLibMem: (TestLibMem as any) as ContractArtifact,
TestLibs: (TestLibs as any) as ContractArtifact, TestLibs: (TestLibs as any) as ContractArtifact,

View File

@@ -90,7 +90,7 @@ export enum ContractName {
AccountLevels = 'AccountLevels', AccountLevels = 'AccountLevels',
EtherDelta = 'EtherDelta', EtherDelta = 'EtherDelta',
Arbitrage = 'Arbitrage', Arbitrage = 'Arbitrage',
TestLibAssetProxyDecoder = 'TestLibAssetProxyDecoder', TestAssetDataDecoders = 'TestAssetDataDecoders',
TestAssetProxyDispatcher = 'TestAssetProxyDispatcher', TestAssetProxyDispatcher = 'TestAssetProxyDispatcher',
TestLibMem = 'TestLibMem', TestLibMem = 'TestLibMem',
TestLibs = 'TestLibs', TestLibs = 'TestLibs',

View File

@@ -7,12 +7,12 @@ import * as chai from 'chai';
import ethUtil = require('ethereumjs-util'); import ethUtil = require('ethereumjs-util');
import * as Web3 from 'web3'; 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 { artifacts } from '../../src/utils/artifacts';
import { assetProxyUtils } from '../../src/utils/asset_proxy_utils'; import { assetProxyUtils } from '../../src/utils/asset_proxy_utils';
import { chaiSetup } from '../../src/utils/chai_setup'; import { chaiSetup } from '../../src/utils/chai_setup';
import { constants } from '../../src/utils/constants'; 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'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper';
chaiSetup.configure(); chaiSetup.configure();
@@ -21,7 +21,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('LibAssetProxyDecoder', () => { describe('LibAssetProxyDecoder', () => {
let owner: string; let owner: string;
let testAssetProxyDecoder: TestLibAssetProxyDecoderContract; let testAssetProxyDecoder: TestAssetDataDecodersContract;
let testAddress: string; let testAddress: string;
before(async () => { before(async () => {
@@ -30,8 +30,8 @@ describe('LibAssetProxyDecoder', () => {
owner = accounts[0]; owner = accounts[0];
testAddress = accounts[1]; testAddress = accounts[1];
// Deploy TestLibMem // Deploy TestLibMem
testAssetProxyDecoder = await TestLibAssetProxyDecoderContract.deployFrom0xArtifactAsync( testAssetProxyDecoder = await TestAssetDataDecodersContract.deployFrom0xArtifactAsync(
artifacts.TestLibAssetProxyDecoder, artifacts.TestAssetDataDecoders,
provider, provider,
txDefaults, txDefaults,
); );