diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-05-01 04:51:21 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-05-02 04:38:41 +0800 |
commit | 668dcb7cf0a51efab22fdc5a7159919d8c099a5a (patch) | |
tree | 2b26edf1b0fe961cda1505071a3cba3224f39484 /packages/contracts | |
parent | b5c4b81aacaca83d8629718ff0357ccc3bba4698 (diff) | |
download | dexon-sol-tools-668dcb7cf0a51efab22fdc5a7159919d8c099a5a.tar dexon-sol-tools-668dcb7cf0a51efab22fdc5a7159919d8c099a5a.tar.gz dexon-sol-tools-668dcb7cf0a51efab22fdc5a7159919d8c099a5a.tar.bz2 dexon-sol-tools-668dcb7cf0a51efab22fdc5a7159919d8c099a5a.tar.lz dexon-sol-tools-668dcb7cf0a51efab22fdc5a7159919d8c099a5a.tar.xz dexon-sol-tools-668dcb7cf0a51efab22fdc5a7159919d8c099a5a.tar.zst dexon-sol-tools-668dcb7cf0a51efab22fdc5a7159919d8c099a5a.zip |
Add batchTransferFrom to asset proxies
Diffstat (limited to 'packages/contracts')
3 files changed, 111 insertions, 9 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/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, @@ -44,6 +45,49 @@ contract ERC20Proxy is 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, @@ -44,6 +45,49 @@ contract ERC721Proxy is 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); |