Use interfaces for contract types

This commit is contained in:
Remco Bloemen
2018-02-06 17:45:10 -08:00
committed by Amir Bandeali
parent f12e4f8889
commit a7f4701698
3 changed files with 33 additions and 36 deletions

View File

@@ -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()

View File

@@ -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,

View File

@@ -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 MixinSettlementProxy(address proxyContract, address zrxToken)
function zrxToken()
external view
returns (IToken)
{
return ZRX_TOKEN;
}
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;
}
}