gnosis / dex-services

Off-chain services for the Gnosis Protocol v1.
33 stars 9 forks source link

Approximate economic viability contstraint #1024

Open nlordell opened 4 years ago

nlordell commented 4 years ago

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.

fleupold commented 4 years ago

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).

nlordell commented 4 years ago

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 commented 3 years ago

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: