-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Order Matching Strategy #40
Comments
I ran three scenarios against the case 3 math and quickly realized that these formulas are missing support for partial fills as well as right/left swapping and negative differences. Here are the notes:
One other note: It would be optimal if the matcher could specify where the arb goes so it's a cheaper transaction with fewer transfers. The scenarios I tried: Scenario 1 (no price diff) Left Order “Buy 10@1” Right Order “Sell 9@1” Expect: exchange of 9 at 1 dollar, no arb Scenario 2 (price diff, full fillable) Left Order “Buy [email protected]” Right Order “Sell [email protected]” Expect: exchange of 10 at .9, 2 tokens remain -> Matcher, matcher determines PTP adjustment Scenario 3 (price diff and not both full fillable) Left Order “Buy [email protected]” Right Order “Sell [email protected]” Should be exchange of 8 at .9, 8.8/7.2 = 1.6 tokens remain -> Matcher, Matcher determines PTP adjustment |
@robdoesstuff Thank you for digging into this! Appreciate the feedback. For reference, this is how the scenarios you described map to our equations to produce your results.
Re negative differences. In the original implementation we constrained input such that the Left Order always has the higher price. This made the outcome more predictable: “Profits are always denominated in the maker asset of the left order.” That said, does enforcing this strict ordering complicate things on your end? The increase in gas should be negligible, so I'm open to supporting it if this makes the feature easier to use. Re partial fills. Any amount filled is subtracted from Re specifying where to send the arb. I like this idea +1. Let me bring @jalextowle into this discussion, who is currently implementing this ZEIP. Edit: I've updated the ZEIP for clarity. Please see "Order Constraints" and "Partial Fills" sections. |
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 subsequentlyfillOrder
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
The text was updated successfully, but these errors were encountered: