Order of fill orders#
Decided to keep the initial implementation.
It is unclear how orders are supposed to filled because there is no clear specification or documentation that states the different order scenarios and what should happen.
From reading the code and rarible documentation here's how orders could be filled:
- Either all of the left order is filled or all the right order is filled, or both are totally filled.
- The left order is filled if the right order take value is greater than the left order make value, otherwise the right order is filled.
- If fulfilling an order will cause an order (left or right) to be exchanged at less than its exchange rate then the transaction will revert.
However the above three rules are not completely followed because the
fillRight function returns
makerValue instead of
rightTakeValue. The rarible protocol has an unmerged closed pull request about this same thing here: https://github.com/rarible/protocol-contracts/pull/127
Specifically rule number 2 is violated in this scenario:
fillRight can be kept how it currently is if that is preferred. It seems rarible protocol is keeping it how it is. A good thing with how it currently works is that if someone makes a mistake and uses a bad/wrong exchange rate for the right order the exchange rate of the left order will be used.
I suggest writing tests for the fillOrder function that covers every scenario possible with filling orders, to be sure that orders are filled in every way expected in the future.
The rarible protocol has an example of testing different fill order scenarios here: https://github.com/rarible/protocol-contracts/blob/master/exchange-v2/test/v2/LibFill.test.js