diff options
Diffstat (limited to 'packages/contracts')
3 files changed, 5 insertions, 132 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC20Proxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC20Proxy.sol index b327eb7b6..e785bd26d 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC20Proxy.sol +++ b/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC20Proxy.sol @@ -42,39 +42,9 @@ contract ERC20Proxy is external onlyAuthorized { - address token = decodeMetadata(assetMetadata); + require(assetMetadata.length == 21); + address token = readAddress(assetMetadata, 1); bool success = ERC20Token(token).transferFrom(from, to, amount); require(success == true); } - - /// @dev Decodes ERC20-encoded byte array. - /// @param assetMetadata ERC20-encoded byte array. - /// @return tokenAddress Address of ERC20 token. - function decodeMetadata(bytes memory assetMetadata) - public pure - returns (address tokenAddress) - { - require(assetMetadata.length == 21); - return readAddress(assetMetadata, 1); - } - - /// @dev Encodes ERC20 byte array. - /// @param assetProxyId Id of the asset proxy. - /// @param tokenAddress Address of the asset. - /// @return assetMetadata ERC20-encoded byte. - function encodeMetadata( - uint8 assetProxyId, - address tokenAddress) - public pure - returns (bytes memory assetMetadata) - { - // 0 is reserved as invalid proxy id - require(assetProxyId != 0); - - // Encode fields into a byte array - assetMetadata = new bytes(21); - assetMetadata[0] = byte(assetProxyId); - writeAddress(assetMetadata, 1, tokenAddress); - return assetMetadata; - } } diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC721Proxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC721Proxy.sol index 404d1ca6e..9021acd40 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC721Proxy.sol +++ b/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC721Proxy.sol @@ -46,50 +46,13 @@ contract ERC721Proxy is require(amount == 1); // Decode metadata - address token; - uint256 tokenId; - (token, tokenId) = decodeMetadata(assetMetadata); + require(assetMetadata.length == 53); + address token = readAddress(assetMetadata, 1); + uint256 tokenId = readUint256(assetMetadata, 21); // Either succeeds or throws. // @TODO: Call safeTransferFrom if there is additional // data stored in `assetMetadata`. ERC721Token(token).transferFrom(from, to, tokenId); } - - /// @dev Decodes ERC721-encoded byte array. - /// @param assetMetadata ERC721-encoded byte array. - /// @return tokenAddress Address of ERC721 token. - /// @return tokenId Id of ERC721 token. - function decodeMetadata(bytes memory assetMetadata) - public pure - returns (address tokenAddress, uint256 tokenId) - { - require(assetMetadata.length == 53); - tokenAddress = readAddress(assetMetadata, 1); - tokenId = readUint256(assetMetadata, 21); - return (tokenAddress, tokenId); - } - - /// @dev Encodes ERC721 byte array. - /// @param assetProxyId Id of the asset proxy. - /// @param tokenAddress Address of the asset. - /// @param tokenId Id of ERC721 token. - /// @return assetMetadata ERC721-encoded byte array. - function encodeMetadata( - uint8 assetProxyId, - address tokenAddress, - uint256 tokenId) - public pure - returns (bytes memory assetMetadata) - { - // 0 is reserved as invalid proxy id - require(assetProxyId != 0); - - // Encode fields into a byte array - assetMetadata = new bytes(53); - assetMetadata[0] = byte(assetProxyId); - writeAddress(assetMetadata, 1, tokenAddress); - writeUint256(assetMetadata, 21, tokenId); - return assetMetadata; - } } diff --git a/packages/contracts/test/asset_proxy_dispatcher/proxies.ts b/packages/contracts/test/asset_proxy_dispatcher/proxies.ts index d1129761e..2a8b6d567 100644 --- a/packages/contracts/test/asset_proxy_dispatcher/proxies.ts +++ b/packages/contracts/test/asset_proxy_dispatcher/proxies.ts @@ -91,30 +91,6 @@ describe('Asset Transfer Proxies', () => { await blockchainLifecycle.revertAsync(); }); describe('Transfer Proxy - ERC20', () => { - it('should successfully encode/decode metadata', async () => { - const metadata = await erc20Proxy.encodeMetadata.callAsync(AssetProxyId.ERC20, zrx.address); - const address = await erc20Proxy.decodeMetadata.callAsync(metadata); - expect(address).to.be.equal(zrx.address); - }); - - it('should successfully decode metadata encoded by typescript helpers', async () => { - const metadata = encodeERC20ProxyData(zrx.address); - const address = await erc20Proxy.decodeMetadata.callAsync(metadata); - expect(address).to.be.equal(zrx.address); - }); - - it('should successfully encode/decode metadata padded with zeros', async () => { - const metadata = await erc20Proxy.encodeMetadata.callAsync(AssetProxyId.ERC20, testAddressPaddedWithZeros); - const address = await erc20Proxy.decodeMetadata.callAsync(metadata); - expect(address).to.be.equal(testAddressPaddedWithZeros); - }); - - it('should successfully decode metadata encoded padded with zeros by typescript helpers', async () => { - const metadata = encodeERC20ProxyData(testAddressPaddedWithZeros); - const address = await erc20Proxy.decodeMetadata.callAsync(metadata); - expect(address).to.be.equal(testAddressPaddedWithZeros); - }); - it('should successfully transfer tokens', async () => { // Construct metadata for ERC20 proxy const encodedProxyMetadata = encodeERC20ProxyData(zrx.address); @@ -192,42 +168,6 @@ describe('Asset Transfer Proxies', () => { }); describe('Transfer Proxy - ERC721', () => { - it('should successfully encode/decode metadata', async () => { - const metadata = await erc721Proxy.encodeMetadata.callAsync( - AssetProxyId.ERC721, - erc721Token.address, - makerTokenId, - ); - const [address, tokenId] = await erc721Proxy.decodeMetadata.callAsync(metadata); - expect(address).to.be.equal(erc721Token.address); - expect(tokenId).to.be.bignumber.equal(makerTokenId); - }); - - it('should successfully decode metadata encoded by typescript helpers', async () => { - const metadata = encodeERC721ProxyData(erc721Token.address, makerTokenId); - const [address, tokenId] = await erc721Proxy.decodeMetadata.callAsync(metadata); - expect(address).to.be.equal(erc721Token.address); - expect(tokenId).to.be.bignumber.equal(makerTokenId); - }); - - it('should successfully encode/decode metadata padded with zeros', async () => { - const metadata = await erc721Proxy.encodeMetadata.callAsync( - AssetProxyId.ERC721, - testAddressPaddedWithZeros, - makerTokenId, - ); - const [address, tokenId] = await erc721Proxy.decodeMetadata.callAsync(metadata); - expect(address).to.be.equal(testAddressPaddedWithZeros); - expect(tokenId).to.be.bignumber.equal(makerTokenId); - }); - - it('should successfully decode metadata encoded padded with zeros by typescript helpers', async () => { - const metadata = encodeERC721ProxyData(testAddressPaddedWithZeros, makerTokenId); - const [address, tokenId] = await erc721Proxy.decodeMetadata.callAsync(metadata); - expect(address).to.be.equal(testAddressPaddedWithZeros); - expect(tokenId).to.be.bignumber.equal(makerTokenId); - }); - it('should successfully transfer tokens', async () => { // Construct metadata for ERC721 proxy const encodedProxyMetadata = encodeERC721ProxyData(erc721Token.address, makerTokenId); |