aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src
diff options
context:
space:
mode:
authorRemco Bloemen <remco@wicked.ventures>2018-08-24 07:00:01 +0800
committerRemco Bloemen <remco@wicked.ventures>2018-08-25 07:46:23 +0800
commita1d89435525795f6f412a823241740f10cbdf1d8 (patch)
treedfe129cfc963ce61c30c3565686d2300ab5a64ac /packages/contracts/src
parent07e56b3cc7f1171cb199b5f0e286971d0704adb6 (diff)
downloaddexon-sol-tools-a1d89435525795f6f412a823241740f10cbdf1d8.tar
dexon-sol-tools-a1d89435525795f6f412a823241740f10cbdf1d8.tar.gz
dexon-sol-tools-a1d89435525795f6f412a823241740f10cbdf1d8.tar.bz2
dexon-sol-tools-a1d89435525795f6f412a823241740f10cbdf1d8.tar.lz
dexon-sol-tools-a1d89435525795f6f412a823241740f10cbdf1d8.tar.xz
dexon-sol-tools-a1d89435525795f6f412a823241740f10cbdf1d8.tar.zst
dexon-sol-tools-a1d89435525795f6f412a823241740f10cbdf1d8.zip
Document accetable price check
Diffstat (limited to 'packages/contracts/src')
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/MixinExchangeCore.sol18
1 files changed, 16 insertions, 2 deletions
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinExchangeCore.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinExchangeCore.sol
index b3671e7e8..e5bd306dd 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinExchangeCore.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinExchangeCore.sol
@@ -343,13 +343,27 @@ contract MixinExchangeCore is
"BUG_ORDER_OVERFILL"
);
- // Make sure order is filled at acceptable price
+ // Make sure order is filled at acceptable price.
+ // The order has an implied price from the makers perspective:
+ // order price = order.makerAssetAmount / order.takerAssetAmount
+ // i.e. the number of makerAsset maker is paying per takerAsset. The
+ // maker is guaranteed to get this price or a better (lower) one. The
+ // actual price maker is getting in this fill is:
+ // fill price = makerAssetFilledAmount / takerAssetFilledAmount
+ // We need `fill price <= order price` for the fill to be fair to maker.
+ // This amounts to:
+ // makerAssetFilledAmount order.makerAssetAmount
+ // ------------------------ <= -----------------------
+ // takerAssetFilledAmount order.takerAssetAmount
+ // or, equivalently:
+ // makerAssetFilledAmount * order.takerAssetAmount <=
+ // order.makerAssetAmount * takerAssetFilledAmount
// NOTE: This assertion should never fail, it is here
// as an extra defence against potential bugs.
require(
safeMul(makerAssetFilledAmount, order.takerAssetAmount)
<=
- safeMul(takerAssetFilledAmount, order.makerAssetAmount),
+ safeMul(order.makerAssetAmount, takerAssetFilledAmount),
"BUG_ORDER_FILL_PRICING"
);