From 80285a300d61bb45688c850d103df94ae589d5cc Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Wed, 16 May 2018 18:44:49 -0700 Subject: Wording of calculateMatchedFillResults --- .../current/protocol/Exchange/MixinMatchOrders.sol | 20 +++++++++++--------- 1 file 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: - // <= * - // <= * / - // * <= * + // 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: + // <= * + // <= * / + // * <= * 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. -- cgit v1.2.3