aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-05-03 02:32:27 +0800
committerGitHub <noreply@github.com>2018-05-03 02:32:27 +0800
commit853b5e1b72733c5dee862a62b549a6c784aeb4eb (patch)
treebca65c60509c28f8a2a20942c7c9fc35054b8945 /packages/contracts/src
parentb5c4b81aacaca83d8629718ff0357ccc3bba4698 (diff)
parent3355a39fe0359c76efc263b3ffe421c68d7a9495 (diff)
downloaddexon-sol-tools-853b5e1b72733c5dee862a62b549a6c784aeb4eb.tar
dexon-sol-tools-853b5e1b72733c5dee862a62b549a6c784aeb4eb.tar.gz
dexon-sol-tools-853b5e1b72733c5dee862a62b549a6c784aeb4eb.tar.bz2
dexon-sol-tools-853b5e1b72733c5dee862a62b549a6c784aeb4eb.tar.lz
dexon-sol-tools-853b5e1b72733c5dee862a62b549a6c784aeb4eb.tar.xz
dexon-sol-tools-853b5e1b72733c5dee862a62b549a6c784aeb4eb.tar.zst
dexon-sol-tools-853b5e1b72733c5dee862a62b549a6c784aeb4eb.zip
Merge pull request #569 from 0xProject/feature/contracts/batchTransfer
Batch transfers in proxies
Diffstat (limited to 'packages/contracts/src')
-rw-r--r--packages/contracts/src/contracts/current/protocol/AssetProxy/IAssetProxy.sol20
-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.sol25
-rw-r--r--packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC721Proxy.sol24
5 files changed, 150 insertions, 29 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxy/IAssetProxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxy/IAssetProxy.sol
index 43f45d200..df993a0ab 100644
--- a/packages/contracts/src/contracts/current/protocol/AssetProxy/IAssetProxy.sol
+++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/IAssetProxy.sol
@@ -17,6 +17,7 @@
*/
pragma solidity ^0.4.21;
+pragma experimental ABIEncoderV2;
import "../../utils/Authorizable/IAuthorizable.sol";
@@ -24,9 +25,9 @@ contract IAssetProxy is IAuthorizable {
/// @dev Transfers assets. Either succeeds or throws.
/// @param assetMetadata Byte array encoded for the respective asset proxy.
- /// @param from Address to transfer token from.
- /// @param to Address to transfer token to.
- /// @param amount Amount of token to transfer.
+ /// @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,
@@ -34,6 +35,18 @@ contract IAssetProxy is IAuthorizable {
uint256 amount)
external;
+ /// @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;
+
/// @dev Gets the proxy id associated with the proxy address.
/// @return Proxy id.
function getProxyId()
@@ -41,3 +54,4 @@ contract IAssetProxy is IAuthorizable {
view
returns (uint8);
}
+
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 c3cfd8c2e..713e8a6e6 100644
--- a/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC20Proxy.sol
+++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC20Proxy.sol
@@ -17,32 +17,31 @@
*/
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 token from.
- /// @param to Address to transfer token to.
- /// @param amount Amount of token to transfer.
- function transferFrom(
- bytes assetMetadata,
+ /// @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)
- external
- onlyAuthorized
+ internal
{
// Data must be intended for this proxy.
require(uint8(assetMetadata[0]) == PROXY_ID);
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 e11de6744..6a4475d48 100644
--- a/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC721Proxy.sol
+++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC721Proxy.sol
@@ -17,32 +17,30 @@
*/
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 token from.
- /// @param to Address to transfer token to.
- /// @param amount Amount of token to transfer.
- function transferFrom(
- bytes assetMetadata,
+ /// @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)
- external
- onlyAuthorized
+ internal
{
// Data must be intended for this proxy.
require(uint8(assetMetadata[0]) == PROXY_ID);