dex-services icon indicating copy to clipboard operation
dex-services copied to clipboard

Approximate economic viability contstraint

Open nlordell opened this issue 4 years ago • 3 comments

We can approximate the economic viability constraint by checking the traded amounts in the transitive orders against connected OWL limit prices. We would then discard any transitive orders that do not satisfy these constraints.

nlordell avatar Jun 17 '20 09:06 nlordell

Instead of discarding transitive orders, should we reduce all direct orders that would not be matchable due to that constraint in a pre-processing step? I'm worried that if we ignored transitive orders, we might fill parts of larger orders which in their entirety could lead to better prices.

E.g. consider the transitive order A->C via A->B->C. If B->C doesn't have enough volume to be economically viable we should only ignore this part and not the complete transitive order A->B->C as the other part (A->B) could still be used in a transitive order (e.g. A->B->D->C).

fleupold avatar Jun 17 '20 10:06 fleupold

I'm worried that if we ignored transitive orders, we might fill parts of larger orders which in their entirety could lead to better prices.

My hope is that this won't be too much of an issue, since we are failing to satisfy the economic viability constraint then the amounts should be small. So the larger part of the order will still be available. If it isn't, then this transitive order would have only been able to fulfill a small amount of the full buy amount and is unlikely to affect the final price estimate (unless it is the proverbial last drop in the bucket)...

E.g. consider the transitive order [...]

...But this is a great suggestion! I think this can be done fairly easily with the current model.

nlordell avatar Jun 17 '20 12:06 nlordell

I thought about this a bunch, and I think the best way to implement this would be the same way we implemented the rounding buffer, so outside the pricegraph and in the price estimator. This would require computing price estimates for all tokens on every orderbook update and create the Pricegraph with orders that are filtered to be economically viable.

The implementation would be fairly straight forward:

  • Compute the min trade amount for each token:
    • Compute the min average fee m (using the existing EconomicViability component).
    • Compute the price estimate p for a token (using the exisitng Pricegraph::estimate_token_price API).
    • The minimum trade amount is 2000 * p * m / 1e18 (I think)
  • Create a Pricegraph instance filtering out all orders with effective_remaining_sell_amount < min_trade_amount.
  • Use the above Pricegraph created in the previous step to compute the price estimate with an added check that the sell_amount used for the price estimate is > min_trade_amount (returning None if it isn't).

nlordell avatar Sep 06 '20 11:09 nlordell