Add batchTransferFrom to asset proxies
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user