Submitted by WatchPug, also found by harleythedog
Swap.sol L200-L225
When a user tries to swap unwrapped ETH to ERC20, even if there is a certain amount of ETH refunded, at L215, ethDelta will always be 0.
Thats because originalETHBalance already includes the msg.value sent by the caller.
Lets say the ETH balance of the contract is 1 ETH before the swap.
Similarly, erc20Delta is also computed wrong.
Consider a special case of a user trying to arbitrage from WBTC to WBTC, the originalERC20Balance already includes the input amount, erc20Delta will always be much lower than the actual delta amount.
For example, for an arb swap from 1 WBTC to 1.1 WBTC, the ethDelta will be 0.1 WBTC while it should be 1.1 WBTC.
Consider subtracting the input amount from the originalBalance.
Shadowfiend (Tally) confirmed:
0xean (judge) commented:
