diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-04-23 06:30:08 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-04-24 01:50:09 +0800 |
commit | a8a0a5cbfb7299cd22181c8713e1da6dec412dae (patch) | |
tree | cf564ece6c9cc948c8ff60432bdae938f0dfb0ab /packages/contracts/src | |
parent | 32e77753b518e0821d75c404b9dcd16af8f2cd8b (diff) | |
download | dexon-sol-tools-a8a0a5cbfb7299cd22181c8713e1da6dec412dae.tar dexon-sol-tools-a8a0a5cbfb7299cd22181c8713e1da6dec412dae.tar.gz dexon-sol-tools-a8a0a5cbfb7299cd22181c8713e1da6dec412dae.tar.bz2 dexon-sol-tools-a8a0a5cbfb7299cd22181c8713e1da6dec412dae.tar.lz dexon-sol-tools-a8a0a5cbfb7299cd22181c8713e1da6dec412dae.tar.xz dexon-sol-tools-a8a0a5cbfb7299cd22181c8713e1da6dec412dae.tar.zst dexon-sol-tools-a8a0a5cbfb7299cd22181c8713e1da6dec412dae.zip |
Combine Exchange with AssetProxyDispatcher
Diffstat (limited to 'packages/contracts/src')
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/AssetProxy/IAssetProxy.sol (renamed from packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/IAssetProxy.sol) | 0 | ||||
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC20Proxy.sol (renamed from packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC20Proxy.sol) | 0 | ||||
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC721Proxy.sol (renamed from packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC721Proxy.sol) | 0 | ||||
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/Exchange/Exchange.sol | 12 | ||||
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/Exchange/MixinAssetProxyDispatcher.sol (renamed from packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/AssetProxyDispatcher.sol) | 34 | ||||
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol (renamed from packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlementProxy.sol) | 57 | ||||
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/Exchange/mixins/MAssetProxyDispatcher.sol (renamed from packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/IAssetProxyDispatcher.sol) | 22 |
7 files changed, 58 insertions, 67 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/IAssetProxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxy/IAssetProxy.sol index 60e74723d..60e74723d 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/IAssetProxy.sol +++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/IAssetProxy.sol diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC20Proxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC20Proxy.sol index eef3a39db..eef3a39db 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC20Proxy.sol +++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC20Proxy.sol diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC721Proxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC721Proxy.sol index 466d0b871..466d0b871 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC721Proxy.sol +++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/proxies/ERC721Proxy.sol diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/Exchange.sol b/packages/contracts/src/contracts/current/protocol/Exchange/Exchange.sol index 995cbcf76..5ccb06b88 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/Exchange.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/Exchange.sol @@ -21,24 +21,26 @@ pragma experimental ABIEncoderV2; import "./MixinExchangeCore.sol"; import "./MixinSignatureValidator.sol"; -import "./MixinSettlementProxy.sol"; +import "./MixinSettlement.sol"; import "./MixinWrapperFunctions.sol"; +import "./MixinAssetProxyDispatcher.sol"; contract Exchange is MixinExchangeCore, MixinSignatureValidator, - MixinSettlementProxy, - MixinWrapperFunctions + MixinSettlement, + MixinWrapperFunctions, + MixinAssetProxyDispatcher { string constant public VERSION = "2.0.1-alpha"; function Exchange( - address _assetProxyDispatcher, bytes memory _zrxProxyData) public MixinExchangeCore() MixinSignatureValidator() - MixinSettlementProxy(_assetProxyDispatcher, _zrxProxyData) + MixinSettlement(_zrxProxyData) MixinWrapperFunctions() + MixinAssetProxyDispatcher() {} } diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/AssetProxyDispatcher.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinAssetProxyDispatcher.sol index 43fd7596e..eab8e04a1 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/AssetProxyDispatcher.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinAssetProxyDispatcher.sol @@ -18,39 +18,39 @@ pragma solidity ^0.4.21; -import "./IAssetProxyDispatcher.sol"; -import "./IAssetProxy.sol"; +import "./mixins/MAssetProxyDispatcher.sol"; +import "../AssetProxy/IAssetProxy.sol"; import "../../utils/Ownable/Ownable.sol"; -import "../../utils/Authorizable/Authorizable.sol"; -contract AssetProxyDispatcher is +contract MixinAssetProxyDispatcher is Ownable, - Authorizable, - IAssetProxyDispatcher + MAssetProxyDispatcher { // Mapping from Asset Proxy Id's to their respective Asset Proxy mapping (uint8 => IAssetProxy) public assetProxies; - /// @dev Transfers assets. Either succeeds or throws. + /// @dev Forwards arguments to assetProxy and calls `transferFrom`. 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. - function transferFrom( - bytes assetMetadata, + function dispatchTransferFrom( + bytes memory assetMetadata, address from, address to, uint256 amount) - external - onlyAuthorized + internal { - // Lookup asset proxy - require(assetMetadata.length >= 1); - uint8 assetProxyId = uint8(assetMetadata[0]); - IAssetProxy assetProxy = assetProxies[assetProxyId]; + // Do nothing if no amount should be transferred. + if (amount > 0) { + // Lookup asset proxy + require(assetMetadata.length >= 1); + uint8 assetProxyId = uint8(assetMetadata[0]); + IAssetProxy assetProxy = assetProxies[assetProxyId]; - // transferFrom will either succeed or throw. - assetProxy.transferFrom(assetMetadata, from, to, amount); + // transferFrom will either succeed or throw. + assetProxy.transferFrom(assetMetadata, from, to, amount); + } } /// @dev Registers an asset proxy to an asset proxy id. diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlementProxy.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol index 5fff2cd60..ae41c7a86 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlementProxy.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol @@ -20,24 +20,18 @@ pragma solidity ^0.4.21; pragma experimental ABIEncoderV2; import "./mixins/MSettlement.sol"; +import "./mixins/MAssetProxyDispatcher.sol"; import "./LibPartialAmount.sol"; -import "../AssetProxyDispatcher/IAssetProxy.sol"; +import "../AssetProxy/IAssetProxy.sol"; /// @dev Provides MixinSettlement -contract MixinSettlementProxy is +contract MixinSettlement is MSettlement, + MAssetProxyDispatcher, LibPartialAmount { - IAssetProxy ASSET_PROXY_DISPATCHER; bytes ZRX_PROXY_DATA; - function assetProxyDispatcher() - public view - returns (address) - { - return address(ASSET_PROXY_DISPATCHER); - } - function zrxProxyData() external view returns (bytes memory) @@ -45,12 +39,9 @@ contract MixinSettlementProxy is return ZRX_PROXY_DATA; } - function MixinSettlementProxy( - address _assetProxyDispatcher, - bytes memory _zrxProxyData) + function MixinSettlement(bytes memory _zrxProxyData) public { - ASSET_PROXY_DISPATCHER = IAssetProxy(_assetProxyDispatcher); ZRX_PROXY_DATA = _zrxProxyData; } @@ -66,38 +57,32 @@ contract MixinSettlementProxy is ) { makerAssetFilledAmount = getPartialAmount(takerAssetFilledAmount, order.takerAssetAmount, order.makerAssetAmount); - ASSET_PROXY_DISPATCHER.transferFrom( + dispatchTransferFrom( order.makerAssetData, order.makerAddress, takerAddress, makerAssetFilledAmount ); - ASSET_PROXY_DISPATCHER.transferFrom( + dispatchTransferFrom( order.takerAssetData, takerAddress, order.makerAddress, takerAssetFilledAmount ); - if (order.feeRecipientAddress != address(0)) { - if (order.makerFee > 0) { - makerFeePaid = getPartialAmount(takerAssetFilledAmount, order.takerAssetAmount, order.makerFee); - ASSET_PROXY_DISPATCHER.transferFrom( - ZRX_PROXY_DATA, - order.makerAddress, - order.feeRecipientAddress, - makerFeePaid - ); - } - if (order.takerFee > 0) { - takerFeePaid = getPartialAmount(takerAssetFilledAmount, order.takerAssetAmount, order.takerFee); - ASSET_PROXY_DISPATCHER.transferFrom( - ZRX_PROXY_DATA, - takerAddress, - order.feeRecipientAddress, - takerFeePaid - ); - } - } + makerFeePaid = getPartialAmount(takerAssetFilledAmount, order.takerAssetAmount, order.makerFee); + dispatchTransferFrom( + ZRX_PROXY_DATA, + order.makerAddress, + order.feeRecipientAddress, + makerFeePaid + ); + takerFeePaid = getPartialAmount(takerAssetFilledAmount, order.takerAssetAmount, order.takerFee); + dispatchTransferFrom( + ZRX_PROXY_DATA, + takerAddress, + order.feeRecipientAddress, + takerFeePaid + ); return (makerAssetFilledAmount, makerFeePaid, takerFeePaid); } } diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/IAssetProxyDispatcher.sol b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MAssetProxyDispatcher.sol index 88bc0d353..a46be9d0f 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/IAssetProxyDispatcher.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MAssetProxyDispatcher.sol @@ -18,15 +18,7 @@ pragma solidity ^0.4.21; -import "../../utils/Ownable/IOwnable.sol"; -import "../../utils/Authorizable/IAuthorizable.sol"; -import "./IAssetProxy.sol"; - -contract IAssetProxyDispatcher is - IOwnable, - IAuthorizable, - IAssetProxy -{ +contract MAssetProxyDispatcher { // Logs registration of new asset proxy event AssetProxySet( @@ -35,6 +27,18 @@ contract IAssetProxyDispatcher is address oldAssetProxy ); + /// @dev Forwards arguments to assetProxy and calls `transferFrom`. 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. + function dispatchTransferFrom( + bytes memory assetMetadata, + address from, + address to, + uint256 amount) + internal; + /// @dev Registers an asset proxy to an asset proxy id. /// An id can only be assigned to a single proxy at a given time, /// however, an asset proxy may be registered to multiple ids. |