diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-08-25 09:48:29 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-08-25 09:48:29 +0800 |
commit | 878db3b84993d7c9724c0ed8591493a4e2b6cc94 (patch) | |
tree | dbae0bba04b7ca630b0e7d3011fc4facdc3eed3d | |
parent | ec2e726be0a653465d3c83e640aa4c1556a0f10f (diff) | |
download | dexon-sol-tools-878db3b84993d7c9724c0ed8591493a4e2b6cc94.tar dexon-sol-tools-878db3b84993d7c9724c0ed8591493a4e2b6cc94.tar.gz dexon-sol-tools-878db3b84993d7c9724c0ed8591493a4e2b6cc94.tar.bz2 dexon-sol-tools-878db3b84993d7c9724c0ed8591493a4e2b6cc94.tar.lz dexon-sol-tools-878db3b84993d7c9724c0ed8591493a4e2b6cc94.tar.xz dexon-sol-tools-878db3b84993d7c9724c0ed8591493a4e2b6cc94.tar.zst dexon-sol-tools-878db3b84993d7c9724c0ed8591493a4e2b6cc94.zip |
Added comments to order matching
-rw-r--r-- | packages/contracts/src/2.0.0/protocol/Exchange/MixinMatchOrders.sol | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinMatchOrders.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinMatchOrders.sol index 226a1bfb6..4b8360c23 100644 --- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinMatchOrders.sol +++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinMatchOrders.sol @@ -179,12 +179,22 @@ contract MixinMatchOrders is rightTakerAssetAmountRemaining ); - // Calculate fill results for maker and taker assets + // Calculate fill results for maker and taker assets: at least one order will be fully filled. + // The maximum amount the left maker can buy is `leftTakerAssetAmountRemaining` + // The maximum amount the right maker can sell is `rightMakerAssetAmountRemaining` + // We have two distinct cases for calculating the fill results: + // Case 1. + // If the left maker can buy more than the right maker can sell, then only the right order is fully filled. + // If the left maker can buy exactly what the right maker can sell, then both orders are fully filled. + // Case 2. + // If the left maker cannot buy more than the right maker can sell, then only the left order is fully filled. if (leftTakerAssetAmountRemaining >= rightMakerAssetAmountRemaining) { // Case 1: Right order is fully filled matchedFillResults.right.makerAssetFilledAmount = rightMakerAssetAmountRemaining; matchedFillResults.right.takerAssetFilledAmount = rightTakerAssetAmountRemaining; matchedFillResults.left.takerAssetFilledAmount = matchedFillResults.right.makerAssetFilledAmount; + // Round down to ensure the maker's exchange rate does not exceed the price specified by the order. + // We favor the maker when the exchange rate must be rounded. matchedFillResults.left.makerAssetFilledAmount = getPartialAmountFloor( leftOrder.makerAssetAmount, leftOrder.takerAssetAmount, @@ -195,6 +205,8 @@ contract MixinMatchOrders is matchedFillResults.left.makerAssetFilledAmount = leftMakerAssetAmountRemaining; matchedFillResults.left.takerAssetFilledAmount = leftTakerAssetAmountRemaining; matchedFillResults.right.makerAssetFilledAmount = matchedFillResults.left.takerAssetFilledAmount; + // Round up to ensure the maker's exchange rate does not exceed the price specified by the order. + // We favor the maker when the exchange rate must be rounded. matchedFillResults.right.takerAssetFilledAmount = getPartialAmountCeil( rightOrder.takerAssetAmount, rightOrder.makerAssetAmount, |