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:
@@ -29,7 +29,7 @@
|
||||
"MixinAuthorizable",
|
||||
"MultiSigWallet",
|
||||
"MultiSigWalletWithTimeLock",
|
||||
"TestLibAssetProxyDecoder",
|
||||
"TestAssetDataDecoders",
|
||||
"TestAssetProxyDispatcher",
|
||||
"TestLibBytes",
|
||||
"TestLibMem",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -90,7 +90,7 @@ export enum ContractName {
|
||||
AccountLevels = 'AccountLevels',
|
||||
EtherDelta = 'EtherDelta',
|
||||
Arbitrage = 'Arbitrage',
|
||||
TestLibAssetProxyDecoder = 'TestLibAssetProxyDecoder',
|
||||
TestAssetDataDecoders = 'TestAssetDataDecoders',
|
||||
TestAssetProxyDispatcher = 'TestAssetProxyDispatcher',
|
||||
TestLibMem = 'TestLibMem',
|
||||
TestLibs = 'TestLibs',
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user