Commit Graph

290 Commits

Author SHA1 Message Date
Diana Carvalho
1d263f8b4c fix: After rebase fixes
Took 6 minutes
2025-06-23 15:02:21 +01:00
Diana Carvalho
e09789f347 test: Refactor tests
- Move encoding integration tests to integration test folder (in the rust project)
- Move protocol integration tests be inside the protocol file. This way we can change the block without any problems and it is easier for integrators

Took 6 minutes

Took 6 minutes


Took 17 minutes
2025-06-23 15:02:20 +01:00
Diana Carvalho
4f58977007 fix(BalancerV3Executor): Do data.length check at the beginning of swap
Took 16 minutes
2025-06-06 17:24:07 +01:00
Diana Carvalho
c03df8aa1e feat: Add balancer v3 to transfer optimization constants
Also added a getForkBlock() on TychoRouterTestSetup.
 Moved the router balancer test inside the Balancer file and created a TychoRouterForBalancerV3Test to wrap it

Took 1 hour 10 minutes


Took 21 seconds
2025-06-06 10:41:35 +01:00
Diana Carvalho
269e328b5f feat: Add integration tests for balancer v3
Refactor BalancerV3Executor to have an inner _swapCallback method with the real swapping logic. Then we have two external methods:
- handleCallback: called by the router. Here we need to remove the first 68 bytes (4 selector + 32 dataOffset + 32 dataLength)
- swapCallback: called by the Vault directly if we are swapping against the executor directly (no router involved)

Took 1 minute
2025-06-05 17:22:17 +01:00
Diana Carvalho
806ce4e62c feat: Make BalancerV3Executor inherit from ICallback
Took 37 minutes
2025-06-05 14:59:22 +01:00
Diana Carvalho
f34db52f09 feat: Implement BalancerV3Executor
Took 2 hours 32 minutes


Took 8 seconds

Took 13 minutes
2025-06-05 14:59:22 +01:00
Diana Carvalho
4f85e3e88e chore: Move tests from strategy_encoders to tycho_encoders
Most of these tests were actually integration tests, so they should be in the outer level of the package.

Took 1 hour 5 minutes
2025-05-26 17:08:44 +01:00
Diana Carvalho
c62af2f232 feat: Don't sign permit2 objects
We don't want to be responsible for holding private keys -> the user is the one that should do this outside of tycho-execution

Done:
- Remove signature from EncodedSolution
- Introduce UserTransferType and pass that everywhere instead of is_permit2_active and token_in_already_in_router
- Remove signing from permit2. Added it to the encoding_utils.rs only
- Mark encode_full_calldata as deprecated
- Backwards compatibility: still accept a signer for the encode_full_calldata case
- Update all tests

Took 2 hours 10 minutes


Took 13 minutes
2025-05-26 12:50:11 +01:00
Diana Carvalho
75f2c3a1c5 feat: Create non alloy specific Permit and PermitDetails structs
- Add try_from methods to convert them to the corresponding Solidity representations
- Update tests

Took 56 seconds
2025-05-23 11:31:05 +01:00
Diana Carvalho
4e8c6ddc8c feat: Separate encoding swaps from encoding txs
This way the user is responsible for encoding the Tycho Router method inputs that are used as guardrails in execution.

Interface changes:
- Create EncodedSolution
- StrategyEncoder
  - don't need to know have permit2 or token_in_already_in_router as attributes anymore
  - encode_strategy returns EncodedSolution now (no method encoding done here now)
- TychoEncoder
  - add encode_solution() method. This is the recommended method for users
  - needs to have permit2, token_in_already_in_router and router_address as attributes
  - permit creation is made in the router now

Also:
- create encoding_utils.rs
- update all tests

Took 2 hours 42 minutes


Took 3 minutes

Took 13 minutes
2025-05-22 14:43:12 +01:00
Diana Carvalho
1f26fbce14 fix: Small misc improvements from audit
- In RestrictTransferFrom:
  - Compare tokenIn with tokenIn from storage
  - Correct docstrings
  - Recompute storage slots with new names
  - Rename transferFromNeeded to isTransferFromAllowed
  - Don't track amount spent but subtract from amount allowed
- In TychoRouter: Rename transferFromNeeded to isTransferFromAllowed

Took 32 minutes
2025-05-22 10:52:00 +01:00
Diana Carvalho
cc9e88cfed feat: Add transferFromNeeded to non permit2 methods
This will block an attempt to transfer from the user when we expect the funds to already be in the router.

chores:
- add docs
- in EncodingContext, rename transfer to transfer_type

Took 58 minutes
2025-05-19 12:02:57 +01:00
TAMARA LIPOWSKI
e0c195f63d fix: Fix remaining tests after latest encoding changes 2025-05-16 14:14:21 -04:00
Diana Carvalho
d4244a7089 fix: Fix tests (not there yet)
Took 58 minutes
2025-05-16 17:57:29 +01:00
Diana Carvalho
38748925b3 feat: Bring back TransferType and simplify encoding logic
Took 1 hour 53 minutes
2025-05-16 16:59:35 +01:00
TAMARA LIPOWSKI
9b59b8b434 Revert "chore: Remove permit2 from executor constructor..."
This reverts commit b0b98c5e5d.
2025-05-16 11:23:43 -04:00
TAMARA LIPOWSKI
7c26e56a85 test: Ensure revert when attempting two transferFroms 2025-05-15 13:36:34 -04:00
Diana Carvalho
09ff7691f8 chore: Make naming consistent: transfer_needed, approval_needed, etc
Took 46 minutes
2025-05-15 14:52:43 +01:00
TAMARA LIPOWSKI
4a0533b8ea chore: Remove transfer flag from curve + balancer
we will never perform a manual transfer into these protocols, as they require the tokens to be in the router contract in order to perform a transferFrom.
2025-05-15 09:15:32 -04:00
TAMARA LIPOWSKI
b0b98c5e5d chore: Remove permit2 from executor constructor...
whenever not needed.
2025-05-15 08:23:55 -04:00
Diana Carvalho
ee687038c5 fix: Make all tests pass!
Delete TokenTransfer.sol
Make slither happy

Bugfixes:
- Executors
  - Ekubo:
    - Fix the POOL_DATA_OFFSET value and remove sender from callback data
    - Use SafeERC20
  - Maverick and Univ2: Use safeTransfer and not safeTransferFrom
  - Univ3: update expected data length
  - Univ4: update the selectors (the signature changed)
- Router:
  - For split swap we don't need to pass the tokenInReceiver, it should always be the router address
  - For single and sequential: change order of the parameters (to be before the permit2 specific objects)
- Encoders:
  - Update selector signatures
  - For split swap pass the transfer_from (we might not need to if the token in is ETH)

Took 2 hours 51 minutes
2025-05-15 13:11:34 +01:00
TAMARA LIPOWSKI
27dfde3118 feat: Support new transfer logic in all executors
TODO:
- Fix failing tests
- Remove permit2 from initialization of contracts
2025-05-14 20:42:19 -04:00
Diana Carvalho
0f9af65846 feat: Support new transfer logic in encoding
The transfer from the user into the router is supposed to happen in the router (we only support this in the executors for callback constrained protocols). This is necessary because of some security concerns that were found in the audit. This way we reduce the space of attack.
- Refactored TransferOptimization not to handle TransferTypes anymore but just return bools.
- Split get_transfer_type into get_transfers and get_in_between_transfer. Updates tests
- Updated the strategies to use this
- Updated function signatures to pass transfer_from and funds_receiver
- Updated SwapEncoders to handle this
- SplitSwapStrategy just assumes all tokens are sent to and from the router at all times

Took 2 hours 46 minutes
2025-05-14 18:00:19 +01:00
Diana Carvalho
079759a75b feat: Choose single strategy if it's a grouped swap of the same protocol
Add and update tests

--- don't change below this line ---
ENG-4478 Took 45 minutes


Took 10 seconds

Took 14 seconds
2025-05-05 12:15:33 +01:00
TAMARA LIPOWSKI
d09497faca chore: Load maverick calldata from file
- Also remove irrelevant comment
2025-04-30 11:18:04 -04:00
TAMARA LIPOWSKI
bcef8f69f6 feat: Transfer Optimizations in MaverickV2
- Also added integration test to test the optimizations, where we can see the in and out transfers being optimized if we enable verbose foundry testing
- Fixed typo in swap encoder builder initialization
2025-04-29 15:46:19 -04:00
Tamara
b6a3ce624d Merge branch 'main' into feat/maverick-v2-executor 2025-04-29 12:01:20 -04:00
Diana Carvalho
0ff4aef0c7 chore: Write encoding rust calldata to file and read in solidity test
This way we can automatically replace the calldata when something changes. We don't need to manually replace the string ourselves.

--- don't change below this line ---
ENG-4453 Took 3 hours 26 minutes
2025-04-29 10:23:47 +01:00
TAMARA LIPOWSKI
8b55d90608 chore: rename dispatcher methods for clarity 2025-04-25 21:07:48 -04:00
Diana Carvalho
fa872f5f0e chore: move single tests to TychoRouterProtocolIntegration.t.sol
They were in TychoRouterSplitSwap.t.sol
Add docs to _balancerOf

Took 2 hours 8 minutes


Took 18 seconds
2025-04-24 13:06:50 +01:00
Diana Carvalho
02cbb67b38 fix: After merge test fixes
Took 11 minutes
2025-04-23 12:31:53 +01:00
dianacarvalho1
fc249d5977 Merge branch 'main' into router/tnl/more-protocol-integration 2025-04-23 12:31:53 +01:00
TAMARA LIPOWSKI
132eed4bb9 test: 5-hop Multi-protocol integration test
- Needed to add ekubo and uniswap v4 to callback-limited protocols.
- I had to bump the fork block in all of our integration tests: The way it was before meant that certain integration tests were using certain executor addresses, and others were using different ones, because of the redeployment. This was a pain to account for on the rust side. Instead, all tests now use an Ekubo-compatible fork block. Values needed to be updated because of price changes between blocks.
2025-04-23 12:31:53 +01:00
TAMARA LIPOWSKI
d5d6e37041 fix: Changes after rebase 2025-04-23 12:31:53 +01:00
TAMARA LIPOWSKI
4f9785fdac fix: Configurable fee on USV2 executor.
- 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%.
2025-04-23 12:31:53 +01:00
Diana Carvalho
7614e36f18 Merge branch 'refs/heads/main' into feature/gas-optimization
# Conflicts:
#	foundry/src/Dispatcher.sol
#	foundry/test/executors/CurveExecutor.t.sol

Took 4 minutes

Took 12 seconds
2025-04-23 12:31:51 +01:00
dianacarvalho1
4a3a8ac6a6 Merge pull request #172 from propeller-heads/router/tnl/ENG-4443-usv3-executor-swap
feat: Make USV3 callback work with direct executor call
2025-04-23 12:31:42 +01:00
Diana Carvalho
d024fe240b fix: Post rebase fixes
--- don't change below this line ---
ENG-4437 Took 2 minutes
2025-04-23 12:31:42 +01:00
TAMARA LIPOWSKI
5562dd210e feat: Make USV3 callback work with direct executor call
- 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.
2025-04-23 12:31:42 +01:00
Diana Carvalho
4a61de56b7 feat: Support using the TransferType in uniswap v4
Update tests

--- don't change below this line ---
ENG-4437 Took 1 hour 3 minutes

Took 2 minutes
2025-04-23 12:31:42 +01:00
Diana Carvalho
cebacc68fe test: Add integration test for it
--- don't change below this line ---
ENG-4446 Took 12 minutes
2025-04-23 12:31:42 +01:00
Diana Carvalho
a951dfb21a chore: Improve tests:
In both encoding and contracts:
- Make sure that the tests names/encoder match what is happening (we had test_split_... that was only a single swap).
- Made modules inside the encodings tests
  - In swap_encoders: there is one module per protocol
  - In strategy_encoders: there is one module per strategy and an extra protocol_integration module. Inside the sequential module there is another module called chained_swaps
- In contracts, each strategy has its own file. Integration tests per strategy should also be here. Renamed TychoRouterIntegration to TychoRouterProtocolIntegration. Only protocol integration tests should be in this file

--- don't change below this line ---
ENG-4327 Took 1 hour 13 minutes
2025-04-23 12:31:41 +01:00
Diana Carvalho
efe12cfcd6 feat: Support in between swaps optimizations
--- don't change below this line ---
ENG-4314 Took 31 seconds
2025-04-23 12:31:41 +01:00
Diana Carvalho
eb1aa6cdcd chore: Correct typo in all balancerAfter/Before (again)
--- don't change below this line ---
ENG-4314 Took 1 hour 14 minutes
2025-04-23 12:31:41 +01:00
Diana Carvalho
8145f416b7 fix: After rebase fixes
- 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
2025-04-23 12:31:41 +01:00
Diana Carvalho
ec87969aa6 feat: Add transfer out for Uniswap V4
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
2025-04-23 12:31:41 +01:00
Diana Carvalho
328a281a44 feat: Add transfer out for Curve
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
2025-04-23 12:31:41 +01:00
Diana Carvalho
9bcb58e5aa feat: Support out transfer straight to the receiver
- 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
2025-04-23 12:31:41 +01:00
TAMARA LIPOWSKI
cf0300dd72 fix: TransferType renaming after rebase 2025-04-23 12:31:41 +01:00