From 668dcb7cf0a51efab22fdc5a7159919d8c099a5a Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Mon, 30 Apr 2018 13:51:21 -0700 Subject: Add batchTransferFrom to asset proxies --- .../current/protocol/AssetProxy/IAssetProxy.sol | 20 +++++++-- .../protocol/AssetProxy/proxies/ERC20Proxy.sol | 50 ++++++++++++++++++++-- .../protocol/AssetProxy/proxies/ERC721Proxy.sol | 50 ++++++++++++++++++++-- 3 files changed, 111 insertions(+), 9 deletions(-) (limited to 'packages') 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/proxies/ERC20Proxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC20Proxy.sol index c3cfd8c2e..d3cc0e804 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC20Proxy.sol +++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC20Proxy.sol @@ -17,6 +17,7 @@ */ pragma solidity ^0.4.21; +pragma experimental ABIEncoderV2; import "../IAssetProxy.sol"; import "../../../utils/LibBytes/LibBytes.sol"; @@ -33,9 +34,9 @@ contract ERC20Proxy is /// @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. + /// @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, @@ -43,6 +44,49 @@ contract ERC20Proxy is 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 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 { // 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..f0fac0259 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC721Proxy.sol +++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC721Proxy.sol @@ -17,6 +17,7 @@ */ pragma solidity ^0.4.21; +pragma experimental ABIEncoderV2; import "../IAssetProxy.sol"; import "../../../utils/LibBytes/LibBytes.sol"; @@ -33,9 +34,9 @@ contract ERC721Proxy is /// @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. + /// @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, @@ -43,6 +44,49 @@ contract ERC721Proxy is 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 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 { // Data must be intended for this proxy. require(uint8(assetMetadata[0]) == PROXY_ID); -- cgit v1.2.3