diff options
author | Remco Bloemen <remco@wicked.ventures> | 2018-02-07 09:45:10 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-04-21 04:56:16 +0800 |
commit | a7f47016980e7b4ad0ff6400cc741c4168ed64a3 (patch) | |
tree | 62788d613918e167679e86b9327de35d07deeb9a | |
parent | f12e4f8889d887952c2cd0b129fa926d1f3b9044 (diff) | |
download | dexon-sol-tools-a7f47016980e7b4ad0ff6400cc741c4168ed64a3.tar.gz dexon-sol-tools-a7f47016980e7b4ad0ff6400cc741c4168ed64a3.tar.zst dexon-sol-tools-a7f47016980e7b4ad0ff6400cc741c4168ed64a3.zip |
Use interfaces for contract types
3 files changed, 33 insertions, 36 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/Exchange.sol b/packages/contracts/src/contracts/current/protocol/Exchange/Exchange.sol index 8f0bb45c5..5c513341b 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/Exchange.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/Exchange.sol @@ -31,7 +31,10 @@ contract Exchange is { string constant public VERSION = "2.0.0-alpha"; - function Exchange(address _zrxToken, address _tokenTransferProxy) + function Exchange( + IToken _zrxToken, + ITokenTransferProxy _tokenTransferProxy + ) public MixinExchangeCore() MixinSignatureValidatorEcrecover() diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol index 4db4eb448..c61006374 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol @@ -132,10 +132,7 @@ contract MixinExchangeCore is filled[order.orderHash] = safeAdd(filled[order.orderHash], takerTokenFilledAmount); // Settle order - uint256 filledMakerTokenAmount; - uint256 makerFeePaid; - uint256 takerFeePaid; - (filledMakerTokenAmount, makerFeePaid, takerFeePaid) = + var (makerTokenFilledAmount, makerFeePaid, takerFeePaid) = settleOrder(order, msg.sender, takerTokenFilledAmount); // Log order @@ -145,7 +142,7 @@ contract MixinExchangeCore is order.feeRecipient, order.makerToken, order.takerToken, - filledMakerTokenAmount, + makerTokenFilledAmount, takerTokenFilledAmount, makerFeePaid, takerFeePaid, diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlementProxy.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlementProxy.sol index 85488b383..83614ec8f 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlementProxy.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlementProxy.sol @@ -29,15 +29,31 @@ contract MixinSettlementProxy is LibPartialAmount { - address public TOKEN_TRANSFER_PROXY_CONTRACT; + ITokenTransferProxy TRANSFER_PROXY; + IToken ZRX_TOKEN; - address public ZRX_TOKEN_CONTRACT; + function transferProxy() + external view + returns (ITokenTransferProxy) + { + return TRANSFER_PROXY; + } + + function zrxToken() + external view + returns (IToken) + { + return ZRX_TOKEN; + } - function MixinSettlementProxy(address proxyContract, address zrxToken) + function MixinSettlementProxy( + ITokenTransferProxy proxyContract, + IToken zrxToken + ) public { - ZRX_TOKEN_CONTRACT = zrxToken; - TOKEN_TRANSFER_PROXY_CONTRACT = proxyContract; + ZRX_TOKEN = zrxToken; + TRANSFER_PROXY = proxyContract; } function settleOrder( @@ -52,13 +68,13 @@ contract MixinSettlementProxy is ) { makerTokenFilledAmount = getPartialAmount(takerTokenFilledAmount, order.takerTokenAmount, order.makerTokenAmount); - require(transferViaTokenTransferProxy( + require(TRANSFER_PROXY.transferFrom( order.makerToken, order.maker, taker, makerTokenFilledAmount )); - require(transferViaTokenTransferProxy( + require(TRANSFER_PROXY.transferFrom( order.takerToken, taker, order.maker, @@ -67,8 +83,8 @@ contract MixinSettlementProxy is if (order.feeRecipient != address(0)) { if (order.makerFee > 0) { makerFeePaid = getPartialAmount(takerTokenFilledAmount, order.takerTokenAmount, order.makerFee); - require(transferViaTokenTransferProxy( - ZRX_TOKEN_CONTRACT, + require(TRANSFER_PROXY.transferFrom( + ZRX_TOKEN, order.maker, order.feeRecipient, makerFeePaid @@ -76,8 +92,8 @@ contract MixinSettlementProxy is } if (order.takerFee > 0) { takerFeePaid = getPartialAmount(takerTokenFilledAmount, order.takerTokenAmount, order.takerFee); - require(transferViaTokenTransferProxy( - ZRX_TOKEN_CONTRACT, + require(TRANSFER_PROXY.transferFrom( + ZRX_TOKEN, taker, order.feeRecipient, takerFeePaid @@ -86,23 +102,4 @@ contract MixinSettlementProxy is } return (makerTokenFilledAmount, makerFeePaid, takerFeePaid); } - - /// @dev Transfers a token using TokenTransferProxy transferFrom function. - /// @param token Address of token to transferFrom. - /// @param from Address transfering token. - /// @param to Address receiving token. - /// @param value Amount of token to transfer. - /// @return Success of token transfer. - function transferViaTokenTransferProxy( - address token, - address from, - address to, - uint256 value) - internal - returns (bool success) - { - success = ITokenTransferProxy(TOKEN_TRANSFER_PROXY_CONTRACT).transferFrom(token, from, to, value); - return success; - } - } |