- Store the executor address when deploying instead.
- We would like to keep all instances of tload and tstore within the callback mechanism of our main TychoRouter contract for security reasons and to prevent any unexpected behaviour
- This way it's easy to reason that UniswapV4Executor will only ever execute a delegatecall to itself. Before it could in theory execute a delegatecall to any address. One had to look at all occurences of tstore(0, x) to ensure the address was constrained.
- This fee is not the same depending on the fork. For example, Pancake V2 uses a 0.25% fee, while the USV2 fee is 0.3%. We were wrongly hard-coding this fee to 0.3%.
- We have decided to now support calling our executors normally (without using delegatecalls) since they now support specifying token transfers.
- This was disabled for UniswapV3 in the past also because of data decoding issues. This seems to be the solution, though.
Do our own implementation. In the end this is much cleaner than I expected and I was able to do a few improvements:
- we don't need to use actions. using function selectors and delegate call instead
- we don't need to convert into V4 Router types
- we don't need to check balances to get the amount out, we can just use the returned value
--- don't change below this line ---
ENG-4437 Took 3 hours 56 minutes
Took 3 minutes
Took 11 minutes
- In Tycho Router
- Fix integration tests
- If the trade is cyclical, we can't do the balance check for the correctness of the amountOut transfers
- In encoding,
- if it is a wrap trade, the transfer should be just a normal Transfer (not TransferFrom nor a Permit2Transfer)
- add test names to println! statements
--- don't change below this line ---
ENG-4315 Took 1 hour 0 minutes
Took 30 seconds
Took 21 seconds
Took 16 seconds
Took 17 seconds
Add transfer in Executor and pass receiver address in encoding
This is done by using the TAKE action instead of TAKE_ALL
--- don't change below this line ---
ENG-4315 Took 1 hour 36 minutes
Took 2 minutes
Add transfer in Executor and pass receiver address in encoding
Remove integration test with StETH pool because we don't support it at simulation level and there is something weird with the amounts (that it is not worth it to investigate now)
--- don't change below this line ---
ENG-4315 Took 34 minutes
Took 2 minutes
- The out transfer is now a responsibility of the Executors -> remove this from router methods
- Also adding a check that the receiver got the full amount out
- In encoding, if it is the last swap, pass the receiver as the trade receiver and not the router address (fix encoding tests)
- Fixed some solidity tests (after rebasing with a PR that is still open, I will fix them all)
TODO: Adapt curve and uniswap v4 to support this
--- don't change below this line ---
ENG-4315 Took 3 hours 7 minutes
Took 20 minutes
Took 59 seconds
Took 7 minutes
- This needed to be in BalancerV2 so that the executor can also take care of transfers from the user into the tycho router, to avoid having transfer actions mixed between the router and executors
- This needed to be in Curve so that the executor can also take care of transfers from the user into the tycho router, to avoid having transfer actions mixed between the router and executors
- For protocols like Balancer and Curve, which expect funds to be in the router at the time of swap, we must support also transferring funds from the user into the router. Doing this in the router would mean we are dealing with transfers in two different places: in the router main methods and in the executors. To avoid this, we are now performing transfers just in the executors, and two transfer types have been added to support transfers into the router.
TODO:
- Add this for Balancer and Curve (only added for USV4 atm).
- TODO consider renaming TRANSFER_FROM and TRANSFER_PERMIT2 to include "pool" in the name
- Renamed ExecutorTransferMethods to TokenTransfer to avoid leaking information about how the transfer happens into the executor. The executor shouldn't care if there are multiple methods or one single method that takes care of everything.
- Also renamed TransferMethod to TransferType to match the rust encoding
- Also do some renamings and comment improvements:
transfer method -> type
- Remove integration tests since we no longer support direct calls to USV3 executor, even for testing.
- Renamed ExecutorTransferMethods to TokenTransfer to avoid leaking information about how the transfer happens into the executor. The executor shouldn't care if there are multiple methods or one single method that takes care of everything.
- Also renamed TransferMethod to TransferType to match the rust encoding
- This arbitrary sender should be same, since the sender is always set to be msg.sender from within the contract (no calldata can be sent specifying otherwise). This is just used to circumvent msg.sender being the pool/protocol during callbacks.
- Properly decode, update tests with proper decoding
- Added test case for each transfer method
- Also fully tested permit2 transferFrom and it works perfectly.
NOTE:
UniswapV3 doesn't support NONE as a transfer method.
TODO:
- Fix integration tests once encoding is implemented.
- Properly decode, update tests with proper decoding
- Added test case for each transfer method
- Also fully tested permit2 transferFrom and it works perfectly.
TODO:
- Fix integration tests once encoding is implemented.
- The old way was useful when we just had split swaps. Unfortunately, we now have split, sequential, and single swaps, which don't always require token indices or split percentages, so we need to decode differently for each case.
- Add some basic tests (will add more in next commits)
- Adapt sequential tests (which originally tested split swap)
- Adapt a forgotten single swap test
TODO:
- Fix encoding of single and sequential swaps to not expect the split sawp format every time (the split and the token indices are not necessary and consume unnecessary gas).
- We have always been ok with risk here and ensured this won't happen for our use case, but slither actions version was recently updated so this fails in CI.