[Draft] One example for disregarded utlitity optimization #29
+668
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This Pr is not intended to be merged. Rather showing current work.
This PR contains a nasty example, showing how a manipulated orderbook could force market orders to be settled at their worst price using a fakeToken.
The output of the script is:
It shows clearly that the additional market order from the FakeToken to the market-order BuyToken generates high disregarded utility for the expected best solution.
If the price of the FakeToken is set to zero, we need to have huge buyOrders buying the FakeToken, which would then have also a very high negative utility.
Hence the optimal solution would, in this case, be around a price 0.9 and hence exploit the market order.
testplan:
A test case (the one from dex-contracts) has been added, but to make it proper code, we would have to add much more and I don't know whether it is worth the effort...