-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Summary
We propose an additional order matching function that maximally fills both orders (referred to as the left and right order). The matcher would receive profit denominated in either the left maker asset, the right maker asset, or a combination of both. This proposal allows matching relayers to execute trades without upfront capital, and does not modify the current matchOrders interface or implementation.
Motivation
The current implementation of matchOrders maximally fills the left order, returning a profit to the matcher that is taken from the left maker. The proposed implementation maximally fills both orders, returning a profit to the matcher that is taken from the left or right maker (or both). The former implementation is beneficial for arbitrage and the latter for matching relayers.
Note that the proposed functionality can also be achieved by calling matchOrders and subsequently fillOrder on the right order. This strategy has been implemented in the Order Matcher extension contract.
Specification
Comparison of Matching Strategies
The figure below compares how profit is generated by the current and proposed matching strategies, along with the respective formulas for computing the flow of value between makers and the matcher.
A Note on Rounding
In the formulas above, we round up or down to ensure that a maker's exchange rate does not exceed the price specified by their order. We favor the maker (opposed to the taker / matcher) when the exchange rate is rounded.
Interface
/// @dev Match two complementary orders that have a profitable spread.
/// Each order is maximally filled at their respective price point, and
/// the matcher receives a profit denominated in either the left maker asset,
/// right maker asset, or a combination of both.
/// @param leftOrder First order to match.
/// @param rightOrder Second order to match.
/// @param leftSignature Proof that order was created by the left maker.
/// @param rightSignature Proof that order was created by the right maker.
/// @return matchedFillResults Amounts filled by maker and taker of matched orders.
function matchOrdersWithMaximalFill(
LibOrder.Order memory leftOrder,
LibOrder.Order memory rightOrder,
bytes memory leftSignature,
bytes memory rightSignature
)
public
nonReentrant
returns (LibFillResults.MatchedFillResults memory matchedFillResults);
