daifoundation / maker-otc

The OasisDEX protocol - Simple on-chain market for ERC20 tokens
GNU Affero General Public License v3.0
101 stars 39 forks source link

initial matcher implementation #157

Closed r001 closed 6 years ago

r001 commented 7 years ago

The purpose of this pull request is to make automated offer matching otc.

Limitations:

Gas usage:

  1. Buy will be 115570 instead of 93593 gas.
  2. To insert a new offer with the help of the frontend 213252 vs original 157861.
  3. And to match a number of offers (ie. the matcher automatically buying N offers for you) will cost ≈ N * 92506 + 222731, where N is the number of offers that have been matched.

You can find the original idea of the matcher here: https://docs.google.com/document/d/1O-bLCwz88pTv_0wMBlbd98iyQAjcv6WmjT0aBDY2hAQ/edit?usp=sharing

r001 commented 7 years ago

Something is wrong with travis. It builds fine at my home computer, and does not build here.

nmushegian commented 7 years ago

given the 4M gas limit only 40 offers can be matched at a time. If we need more, I need to redesign the contract to make it execute in several different blocks.

We need to finish the discussion about the proper way to handle O(n) gas ops. There are a few issues with the approach right now e.g. I think it is a bit fragile to use from long-running contracts

r001 commented 7 years ago

We need to finish the discussion about the proper way to handle O(n) gas ops. There are a few issues with the approach right now e.g. I think it is a bit fragile to use from long-running contracts

I agree. My idea about this is to use keepers. But we want to limit keepers from doing arbitrage to receive some fee instead. The main reason for this is the fact that with Oasis we compete with other exchanges, and the arbitrage is simply too expensive for users. And offers that are too small are not worth buying, so they are never matched. What I propose is that all users placing an offer must send W-eth to the contract to cover the matching. On the contract side we would apply keepers to do the O(n) stuff outside of the contract (but without having to trust them), and we would limit the number of keepers that can connect to the system (to make matching somewhat profitable for them), and require a kind of responsivity, so that all offers are matched immediately. So we would create the group of Alpha Keepers, that should be 4 keepers at a time, that have the right to connect to the system, they must provide 99% of availability in order to have 99.9999% of availability for the Alpha Keepers combined. If keeper does not provide 99% he is kicked, and a new one gets a chance from the Keeper pool. This system is rather difficult, but provides O(1) for the contract to match offers; outside contracts can call offer() without having to provide an oracle and still execute in O(1); the price of matching is shared between the offer makers and the ones that actually do the matching, keepers do not receive arbitrage but receive fee for doing calculations. And probably whaat I wrote here is really hard to understand, so let's chat about it!