aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-05-03 02:30:26 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-05-03 02:30:26 +0800
commit3355a39fe0359c76efc263b3ffe421c68d7a9495 (patch)
treebca65c60509c28f8a2a20942c7c9fc35054b8945 /packages/contracts/src
parent0cb357a0e908d1cc4eac883df88d64c7b66e230c (diff)
downloaddexon-sol-tools-3355a39fe0359c76efc263b3ffe421c68d7a9495.tar.gz
dexon-sol-tools-3355a39fe0359c76efc263b3ffe421c68d7a9495.tar.zst
dexon-sol-tools-3355a39fe0359c76efc263b3ffe421c68d7a9495.zip
Add MixinAssetProxy to reuse redundant code
Diffstat (limited to 'packages/contracts/src')
-rw-r--r--packages/contracts/src/contracts/current/protocol/AssetProxy/MixinAssetProxy.sol75
-rw-r--r--packages/contracts/src/contracts/current/protocol/AssetProxy/mixins/MAssetProxy.sol35
-rw-r--r--packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC20Proxy.sol53
-rw-r--r--packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC721Proxy.sol52
4 files changed, 117 insertions, 98 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxy/MixinAssetProxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxy/MixinAssetProxy.sol
new file mode 100644
index 000000000..23dce6a8b
--- /dev/null
+++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/MixinAssetProxy.sol
@@ -0,0 +1,75 @@
+/*
+
+ 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.21;
+pragma experimental ABIEncoderV2;
+
+import "./mixins/MAssetProxy.sol";
+import "./IAssetProxy.sol";
+import "../../utils/Authorizable/Authorizable.sol";
+
+contract MixinAssetProxy is
+ IAssetProxy,
+ MAssetProxy,
+ Authorizable
+{
+
+ /// @dev Transfers assets. Either succeeds or throws.
+ /// @param assetMetadata Encoded byte array.
+ /// @param from Address to transfer asset from.
+ /// @param to Address to transfer asset to.
+ /// @param amount Amount of asset to transfer.
+ function transferFrom(
+ bytes assetMetadata,
+ address from,
+ address to,
+ uint256 amount)
+ external
+ onlyAuthorized
+ {
+ transferFromInternal(
+ assetMetadata,
+ from,
+ to,
+ amount
+ );
+ }
+
+ /// @dev Makes multiple transfers of assets. Either succeeds or throws.
+ /// @param assetMetadata Array of byte arrays encoded for the respective asset proxy.
+ /// @param from Array of addresses to transfer assets from.
+ /// @param to Array of addresses to transfer assets to.
+ /// @param amounts Array of amounts of assets to transfer.
+ function batchTransferFrom(
+ bytes[] memory assetMetadata,
+ address[] memory from,
+ address[] memory to,
+ uint256[] memory amounts)
+ public
+ onlyAuthorized
+ {
+ for (uint256 i = 0; i < assetMetadata.length; i++) {
+ transferFromInternal(
+ assetMetadata[i],
+ from[i],
+ to[i],
+ amounts[i]
+ );
+ }
+ }
+}
diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxy/mixins/MAssetProxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxy/mixins/MAssetProxy.sol
new file mode 100644
index 000000000..8e9b3bc65
--- /dev/null
+++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/mixins/MAssetProxy.sol
@@ -0,0 +1,35 @@
+/*
+
+ 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.21;
+pragma experimental ABIEncoderV2;
+
+contract MAssetProxy {
+
+ /// @dev Internal version of `transferFrom`.
+ /// @param assetMetadata Encoded byte array.
+ /// @param from Address to transfer asset from.
+ /// @param to Address to transfer asset to.
+ /// @param amount Amount of asset to transfer.
+ function transferFromInternal(
+ bytes memory assetMetadata,
+ address from,
+ address to,
+ uint256 amount)
+ internal;
+}
diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC20Proxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC20Proxy.sol
index d3cc0e804..713e8a6e6 100644
--- a/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC20Proxy.sol
+++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC20Proxy.sol
@@ -19,65 +19,20 @@
pragma solidity ^0.4.21;
pragma experimental ABIEncoderV2;
-import "../IAssetProxy.sol";
+
import "../../../utils/LibBytes/LibBytes.sol";
-import "../../../utils/Authorizable/Authorizable.sol";
import "../../../tokens/ERC20Token/IERC20Token.sol";
+import "../MixinAssetProxy.sol";
contract ERC20Proxy is
LibBytes,
- Authorizable,
- IAssetProxy
+ MixinAssetProxy
{
uint8 constant PROXY_ID = 1;
- /// @dev Transfers ERC20 tokens. Either succeeds or throws.
- /// @param assetMetadata ERC20-encoded byte array.
- /// @param from Address to transfer asset from.
- /// @param to Address to transfer asset to.
- /// @param amount Amount of asset to transfer.
- function transferFrom(
- bytes assetMetadata,
- address from,
- address to,
- uint256 amount)
- external
- onlyAuthorized
- {
- transferFromInternal(
- assetMetadata,
- from,
- to,
- amount
- );
- }
-
- /// @dev Makes multiple transfers of assets. Either succeeds or throws.
- /// @param assetMetadata Array of byte arrays encoded for the respective asset proxy.
- /// @param from Array of addresses to transfer assets from.
- /// @param to Array of addresses to transfer assets to.
- /// @param amounts Array of amounts of assets to transfer.
- function batchTransferFrom(
- bytes[] memory assetMetadata,
- address[] memory from,
- address[] memory to,
- uint256[] memory amounts)
- public
- onlyAuthorized
- {
- for (uint256 i = 0; i < assetMetadata.length; i++) {
- transferFromInternal(
- assetMetadata[i],
- from[i],
- to[i],
- amounts[i]
- );
- }
- }
-
/// @dev Internal version of `transferFrom`.
- /// @param assetMetadata ERC20-encoded byte array.
+ /// @param assetMetadata Encoded byte array.
/// @param from Address to transfer asset from.
/// @param to Address to transfer asset to.
/// @param amount Amount of asset to transfer.
diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC721Proxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC721Proxy.sol
index f0fac0259..6a4475d48 100644
--- a/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC721Proxy.sol
+++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC721Proxy.sol
@@ -19,65 +19,19 @@
pragma solidity ^0.4.21;
pragma experimental ABIEncoderV2;
-import "../IAssetProxy.sol";
import "../../../utils/LibBytes/LibBytes.sol";
-import "../../../utils/Authorizable/Authorizable.sol";
import "../../../tokens/ERC721Token/ERC721Token.sol";
+import "../MixinAssetProxy.sol";
contract ERC721Proxy is
LibBytes,
- Authorizable,
- IAssetProxy
+ MixinAssetProxy
{
uint8 constant PROXY_ID = 2;
- /// @dev Transfers ERC721 tokens. Either succeeds or throws.
- /// @param assetMetadata ERC721-encoded byte array
- /// @param from Address to transfer asset from.
- /// @param to Address to transfer asset to.
- /// @param amount Amount of asset to transfer.
- function transferFrom(
- bytes assetMetadata,
- address from,
- address to,
- uint256 amount)
- external
- onlyAuthorized
- {
- transferFromInternal(
- assetMetadata,
- from,
- to,
- amount
- );
- }
-
- /// @dev Makes multiple transfers of assets. Either succeeds or throws.
- /// @param assetMetadata Array of byte arrays encoded for the respective asset proxy.
- /// @param from Array of addresses to transfer assets from.
- /// @param to Array of addresses to transfer assets to.
- /// @param amounts Array of amounts of assets to transfer.
- function batchTransferFrom(
- bytes[] memory assetMetadata,
- address[] memory from,
- address[] memory to,
- uint256[] memory amounts)
- public
- onlyAuthorized
- {
- for (uint256 i = 0; i < assetMetadata.length; i++) {
- transferFromInternal(
- assetMetadata[i],
- from[i],
- to[i],
- amounts[i]
- );
- }
- }
-
/// @dev Internal version of `transferFrom`.
- /// @param assetMetadata ERC20-encoded byte array.
+ /// @param assetMetadata Encoded byte array.
/// @param from Address to transfer asset from.
/// @param to Address to transfer asset to.
/// @param amount Amount of asset to transfer.