diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-07-11 06:41:33 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-07-23 23:00:23 +0800 |
commit | 6fb157488cf337a1b3c96fc4a9b04d81098bd27d (patch) | |
tree | 4d0eae30f24e1dea0a90d0971a3e60a1e3e287bb /packages/contracts/src/2.0.0/forwarder/MixinWeth.sol | |
parent | 814518dd8094d03908d77e39faa21b8758f1552b (diff) | |
download | dexon-sol-tools-6fb157488cf337a1b3c96fc4a9b04d81098bd27d.tar dexon-sol-tools-6fb157488cf337a1b3c96fc4a9b04d81098bd27d.tar.gz dexon-sol-tools-6fb157488cf337a1b3c96fc4a9b04d81098bd27d.tar.bz2 dexon-sol-tools-6fb157488cf337a1b3c96fc4a9b04d81098bd27d.tar.lz dexon-sol-tools-6fb157488cf337a1b3c96fc4a9b04d81098bd27d.tar.xz dexon-sol-tools-6fb157488cf337a1b3c96fc4a9b04d81098bd27d.tar.zst dexon-sol-tools-6fb157488cf337a1b3c96fc4a9b04d81098bd27d.zip |
Update transferEthFeeAndRefund, add check to ERC721 transfer
Diffstat (limited to 'packages/contracts/src/2.0.0/forwarder/MixinWeth.sol')
-rw-r--r-- | packages/contracts/src/2.0.0/forwarder/MixinWeth.sol | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinWeth.sol b/packages/contracts/src/2.0.0/forwarder/MixinWeth.sol index cbc81a11c..1d0c315f5 100644 --- a/packages/contracts/src/2.0.0/forwarder/MixinWeth.sol +++ b/packages/contracts/src/2.0.0/forwarder/MixinWeth.sol @@ -78,32 +78,46 @@ contract MixinWeth is ) internal { + // Ensure feePercentage is less than 5%. + require( + feePercentage <= MAX_FEE_PERCENTAGE, + "FEE_PERCENTAGE_TOO_LARGE" + ); + + // Calculate amount of WETH that hasn't been sold. uint256 wethRemaining = safeSub( msg.value, safeAdd(wethSoldExcludingFeeOrders, wethSoldForZrx) ); - ETHER_TOKEN.withdraw(wethRemaining); - require( - feePercentage <= MAX_FEE_PERCENTAGE, - "FEE_PERCENTAGE_TOO_LARGE" - ); + // Calculate ETH fee to pay to feeRecipient. uint256 ethFee = getPartialAmount( feePercentage, PERCENTAGE_DENOMINATOR, wethSoldExcludingFeeOrders ); + + // Ensure fee is less than amount of WETH remaining. require( - ethFee < wethRemaining, + ethFee <= wethRemaining, "MAX_FEE_EXCEEDED" ); - if (ethFee > 0) { - feeRecipient.transfer(ethFee); - } - - uint256 ethRefund = safeSub(wethRemaining, ethFee); - if (ethRefund > 0) { - msg.sender.transfer(ethRefund); + + // Do nothing if no WETH remaining + if (wethRemaining > 0) { + // Convert remaining WETH to ETH + ETHER_TOKEN.withdraw(wethRemaining); + + // Pay ETH to feeRecipient + if (ethFee > 0) { + feeRecipient.transfer(ethFee); + } + + // Refund remaining ETH to msg.sender. + uint256 ethRefund = safeSub(wethRemaining, ethFee); + if (ethRefund > 0) { + msg.sender.transfer(ethRefund); + } } } } |