aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-04-18 04:36:11 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-21 04:56:18 +0800
commite80f203efc70ef5787a78626a9f10cf5517b178e (patch)
tree9364ea750e96671a5a29cfb801d8c5781733d2b9 /packages/contracts/src
parentdbd65cdb04ec2fac9da22e833669307e3ee33988 (diff)
downloaddexon-sol-tools-e80f203efc70ef5787a78626a9f10cf5517b178e.tar
dexon-sol-tools-e80f203efc70ef5787a78626a9f10cf5517b178e.tar.gz
dexon-sol-tools-e80f203efc70ef5787a78626a9f10cf5517b178e.tar.bz2
dexon-sol-tools-e80f203efc70ef5787a78626a9f10cf5517b178e.tar.lz
dexon-sol-tools-e80f203efc70ef5787a78626a9f10cf5517b178e.tar.xz
dexon-sol-tools-e80f203efc70ef5787a78626a9f10cf5517b178e.tar.zst
dexon-sol-tools-e80f203efc70ef5787a78626a9f10cf5517b178e.zip
Inlined decodeMetadata in the proxies and removed encodeMetadata (already exists in Typescript). This simplifies the code.
Diffstat (limited to 'packages/contracts/src')
-rw-r--r--packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC20Proxy.sol34
-rw-r--r--packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC721Proxy.sol43
2 files changed, 5 insertions, 72 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;
- }
}