In AUniswapDecoder, all actions that require forwarding value are decoded and value is appended.
Arbitrage bots buy and sell the same pairs, with a resulting small value transfer when using a chain's native token.
We could therefore temporary store (memory or transient storage) a int256 value, add and subtract based on whether CurrencyOut is native, then convert to the minimum between 0 and uint256(value) (or int256 casted to uint256). This would allow forwarding only necessary value. Technically, this would not save gas unless the swaps resulted in exact native amount in and out, and diff token amount in and out (which is generally not the case); by contrast, there is a slight increase in gas consumption for extra condition handling. However, this would allow taking advantage of uniswap's v4 flash accounting.
This could be implemented in the fix of #903 as we could reduce value to forward when the output token is native for v4 swaps. For combinations of v2+v3+v4 swaps would not necessarily work - could plan for a later release.
In AUniswapDecoder, all actions that require forwarding
valueare decoded and value is appended.Arbitrage bots buy and sell the same pairs, with a resulting small value transfer when using a chain's native token.
We could therefore temporary store (memory or transient storage) a int256 value, add and subtract based on whether CurrencyOut is native, then convert to the minimum between 0 and uint256(value) (or int256 casted to uint256). This would allow forwarding only necessary value. Technically, this would not save gas unless the swaps resulted in exact native amount in and out, and diff token amount in and out (which is generally not the case); by contrast, there is a slight increase in gas consumption for extra condition handling. However, this would allow taking advantage of uniswap's v4 flash accounting.
This could be implemented in the fix of #903 as we could reduce value to forward when the output token is native for v4 swaps. For combinations of v2+v3+v4 swaps would not necessarily work - could plan for a later release.