aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-05-17 09:44:49 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-05-19 08:01:06 +0800
commit80285a300d61bb45688c850d103df94ae589d5cc (patch)
treeb2e289c312eecfd728fc999180aa3849b1b6a329
parent2eb5819851252eb90207765ed64a119ad138c0ad (diff)
downloaddexon-0x-contracts-80285a300d61bb45688c850d103df94ae589d5cc.tar.gz
dexon-0x-contracts-80285a300d61bb45688c850d103df94ae589d5cc.tar.zst
dexon-0x-contracts-80285a300d61bb45688c850d103df94ae589d5cc.zip
Wording of calculateMatchedFillResults
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinMatchOrders.sol20
1 files changed, 11 insertions, 9 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinMatchOrders.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinMatchOrders.sol
index d53653fbf..e353b19e8 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinMatchOrders.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinMatchOrders.sol
@@ -228,13 +228,15 @@ contract MixinMatchOrders is
internal
returns (MatchedFillResults memory matchedFillResults)
{
- // We settle orders at the price point defined by the right order (profit goes to the order taker)
- // The constraint can be either on the left or on the right.
- // The constraint is on the left iff the amount required to fill the left order
- // is less than or equal to the amount we can spend from the right order:
- // <leftTakerAssetAmountRemaining> <= <rightTakerAssetAmountRemaining> * <rightMakerToTakerRatio>
- // <leftTakerAssetAmountRemaining> <= <rightTakerAssetAmountRemaining> * <rightOrder.makerAssetAmount> / <rightOrder.takerAssetAmount>
- // <leftTakerAssetAmountRemaining> * <rightOrder.takerAssetAmount> <= <rightTakerAssetAmountRemaining> * <rightOrder.makerAssetAmount>
+ // We settle orders at the exchange rate of the right order.
+ // The amount saved by the left maker goes to the taker.
+ // Either the left or right order will be fully filled; possibly both.
+ // The left order is fully filled iff the right order can sell more than left can buy.
+ // That is: the amount required to fill the left order is less than or equal to
+ // the amount we can spend from the right order:
+ // <leftTakerAssetAmountRemaining> <= <rightTakerAssetAmountRemaining> * <rightMakerToTakerRatio>
+ // <leftTakerAssetAmountRemaining> <= <rightTakerAssetAmountRemaining> * <rightOrder.makerAssetAmount> / <rightOrder.takerAssetAmount>
+ // <leftTakerAssetAmountRemaining> * <rightOrder.takerAssetAmount> <= <rightTakerAssetAmountRemaining> * <rightOrder.makerAssetAmount>
uint256 rightTakerAssetAmountRemaining = safeSub(rightOrder.takerAssetAmount, rightOrderFilledAmount);
uint256 leftTakerAssetAmountRemaining = safeSub(leftOrder.takerAssetAmount, leftOrderFilledAmount);
uint256 leftOrderAmountToFill;
@@ -243,7 +245,7 @@ contract MixinMatchOrders is
safeMul(leftTakerAssetAmountRemaining, rightOrder.takerAssetAmount) <=
safeMul(rightTakerAssetAmountRemaining, rightOrder.makerAssetAmount)
) {
- // Left order is the constraint: maximally fill left
+ // Left order will be fully filled: maximally fill left
leftOrderAmountToFill = leftTakerAssetAmountRemaining;
// The right order receives an amount proportional to how much was spent.
@@ -254,7 +256,7 @@ contract MixinMatchOrders is
leftOrderAmountToFill
);
} else {
- // Right order is the constraint: maximally fill right
+ // Right order will be fully filled: maximally fill right
rightOrderAmountToFill = rightTakerAssetAmountRemaining;
// The left order receives an amount proportional to how much was spent.