Skip to content

Commit

Permalink
@0x/contracts-zero-ex: Remove protocol fees from native orders in c…
Browse files Browse the repository at this point in the history
…ertain scenarios.
  • Loading branch information
merklejerk committed Nov 23, 2020
1 parent 85f5d32 commit e33b054
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 66 deletions.
16 changes: 3 additions & 13 deletions contracts/zero-ex/contracts/src/features/INativeOrdersFeature.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ interface INativeOrdersFeature {
/// @param taker The taker of the order.
/// @param takerTokenFilledAmount How much taker token was filled.
/// @param makerTokenFilledAmount How much maker token was filled.
/// @param protocolFeePaid How much protocol fee was paid.
/// @param pool The fee pool associated with this order.
event RfqOrderFilled(
bytes32 orderHash,
Expand All @@ -66,7 +65,6 @@ interface INativeOrdersFeature {
address takerToken,
uint128 takerTokenFilledAmount,
uint128 makerTokenFilledAmount,
uint256 protocolFeePaid,
bytes32 pool
);

Expand Down Expand Up @@ -115,8 +113,7 @@ interface INativeOrdersFeature {
returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);

/// @dev Fill an RFQ order for up to `takerTokenFillAmount` taker tokens.
/// The taker will be the caller. ETH should be attached to pay the
/// protocol fee.
/// The taker will be the caller.
/// @param order The RFQ order.
/// @param signature The order signature.
/// @param takerTokenFillAmount Maximum taker token amount to fill this order with.
Expand All @@ -128,7 +125,6 @@ interface INativeOrdersFeature {
uint128 takerTokenFillAmount
)
external
payable
returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);

/// @dev Fill an RFQ order for exactly `takerTokenFillAmount` taker tokens.
Expand All @@ -149,9 +145,7 @@ interface INativeOrdersFeature {
returns (uint128 makerTokenFilledAmount);

/// @dev Fill an RFQ order for exactly `takerTokenFillAmount` taker tokens.
/// The taker will be the caller. ETH protocol fees can be
/// attached to this call. Any unspent ETH will be refunded to
/// the caller.
/// The taker will be the caller.
/// @param order The RFQ order.
/// @param signature The order signature.
/// @param takerTokenFillAmount How much taker token to fill this order with.
Expand All @@ -162,7 +156,6 @@ interface INativeOrdersFeature {
uint128 takerTokenFillAmount
)
external
payable
returns (uint128 makerTokenFilledAmount);

/// @dev Fill a limit order. Internal variant. ETH protocol fees can be
Expand All @@ -186,9 +179,7 @@ interface INativeOrdersFeature {
payable
returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);

/// @dev Fill an RFQ order. Internal variant. ETH protocol fees can be
/// attached to this call. Any unspent ETH will be refunded to
/// `msg.sender` (not `sender`).
/// @dev Fill an RFQ order. Internal variant.
/// @param order The RFQ order.
/// @param signature The order signature.
/// @param takerTokenFillAmount Maximum taker token to fill this order with.
Expand All @@ -202,7 +193,6 @@ interface INativeOrdersFeature {
address taker
)
external
payable
returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);

/// @dev Cancel a single limit order. The caller must be the maker.
Expand Down
16 changes: 4 additions & 12 deletions contracts/zero-ex/contracts/src/features/NativeOrdersFeature.sol
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ contract NativeOrdersFeature is
)
public
override
payable
returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)
{
FillNativeOrderResults memory results =
Expand All @@ -219,7 +218,6 @@ contract NativeOrdersFeature is
takerTokenFillAmount,
msg.sender
);
_refundExcessProtocolFeeToSender(results.ethProtocolFeePaid);
(takerTokenFilledAmount, makerTokenFilledAmount) = (
results.takerTokenFilledAmount,
results.makerTokenFilledAmount
Expand Down Expand Up @@ -279,7 +277,6 @@ contract NativeOrdersFeature is
)
public
override
payable
returns (uint128 makerTokenFilledAmount)
{
FillNativeOrderResults memory results =
Expand All @@ -297,7 +294,6 @@ contract NativeOrdersFeature is
takerTokenFillAmount
).rrevert();
}
_refundExcessProtocolFeeToSender(results.ethProtocolFeePaid);
makerTokenFilledAmount = results.makerTokenFilledAmount;
}

Expand Down Expand Up @@ -356,7 +352,6 @@ contract NativeOrdersFeature is
)
public
override
payable
onlySelf
returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)
{
Expand All @@ -367,7 +362,6 @@ contract NativeOrdersFeature is
takerTokenFillAmount,
taker
);
_refundExcessProtocolFeeToSender(results.ethProtocolFeePaid);
(takerTokenFilledAmount, makerTokenFilledAmount) = (
results.takerTokenFilledAmount,
results.makerTokenFilledAmount
Expand Down Expand Up @@ -789,8 +783,10 @@ contract NativeOrdersFeature is
}
}

// Pay the protocol fee.
results.ethProtocolFeePaid = _collectProtocolFee(params.order.pool);
// Pay the protocol fee if this is an open-orderbook order (taker is not known).
if (params.order.taker == address(0)) {
results.ethProtocolFeePaid = _collectProtocolFee(params.order.pool);
}

// Settle between the maker and taker.
(results.takerTokenFilledAmount, results.makerTokenFilledAmount) = _settleOrder(
Expand Down Expand Up @@ -883,9 +879,6 @@ contract NativeOrdersFeature is
}
}

// Pay the protocol fee.
results.ethProtocolFeePaid = _collectProtocolFee(order.pool);

// Settle between the maker and taker.
(results.takerTokenFilledAmount, results.makerTokenFilledAmount) = _settleOrder(
SettleOrderInfo({
Expand All @@ -909,7 +902,6 @@ contract NativeOrdersFeature is
address(order.takerToken),
results.takerTokenFilledAmount,
results.makerTokenFilledAmount,
results.ethProtocolFeePaid,
order.pool
);
}
Expand Down
Loading

0 comments on commit e33b054

Please sign in to comment.