diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-05-17 09:44:49 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-05-19 08:01:06 +0800 |
commit | 80285a300d61bb45688c850d103df94ae589d5cc (patch) | |
tree | b2e289c312eecfd728fc999180aa3849b1b6a329 | |
parent | 2eb5819851252eb90207765ed64a119ad138c0ad (diff) | |
download | dexon-sol-tools-80285a300d61bb45688c850d103df94ae589d5cc.tar dexon-sol-tools-80285a300d61bb45688c850d103df94ae589d5cc.tar.gz dexon-sol-tools-80285a300d61bb45688c850d103df94ae589d5cc.tar.bz2 dexon-sol-tools-80285a300d61bb45688c850d103df94ae589d5cc.tar.lz dexon-sol-tools-80285a300d61bb45688c850d103df94ae589d5cc.tar.xz dexon-sol-tools-80285a300d61bb45688c850d103df94ae589d5cc.tar.zst dexon-sol-tools-80285a300d61bb45688c850d103df94ae589d5cc.zip |
Wording of calculateMatchedFillResults
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/Exchange/MixinMatchOrders.sol | 20 |
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. |