universal-router
universal-router copied to clipboard
Consider removing (or editing) nested if logic in Dispatcher.
Since we're getting contributions and plan to deploy new contracts to support more protocols in the medium future, I'm open to getting rid of the nested if logic. Even when including 15 commands (which would likely be a big outlier), we hardly save 2k gas.
If this was a one time deploy, I think it would make a lot of sense. But for the sake of maintainability I think we should either:
- take it out.
- at least use
>
<
operators so that certain bits aren't muddying flags for lower numbers.
To make it more clear and gas efficient I thought of doing a mapping(bytes1 => bytes4) commandToFunction
and hardcode the different functions so the user only needs to call a addr.call(abi.encodeWithSignature(commandToFunction[commandType], commandType))
. I guess in this case it would be more efficient, the access to the function would be O(1) instead of O(n) where n is the number of functions. Idk if this kind of solution would be as safe as the current one tho.
SLOAD for every command lookup would almost definitely cost more gas IMO. happy to review a gas-snapshotted PoC if you have one and prove me wrong :)
https://github.com/Uniswap/universal-router/pull/181