Commit Graph

38 Commits

Author SHA1 Message Date
Diana Carvalho
5eb9973dbd feat: Add estimated_amount_in to Swap. Add SwapBuilder
Use SwapBuilder everywhere inside crate
Integration tests will be done later

--- don't change below this line ---
ENG-4696 Took 1 hour 56 minutes

Took 4 minutes
2025-08-13 18:05:17 +01:00
TAMARA LIPOWSKI
c217702560 feat: Add protocol state to Swap object
- This consists of lots of necessary battles with lifetimes.
2025-07-22 12:13:39 -04:00
Diana Carvalho
2c25b5a18f feat: Use Chain from tycho-core and remove current implementation
--- don't change below this line ---
ENG-4705 Took 29 minutes
2025-07-10 17:20:53 +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
e704151404 fix: Remove unnecessary clones from encoding
Use references if possible

Took 3 minutes
2025-06-23 12:54:09 +01:00
Diana Carvalho
95994250b1 fix: When choosing strategy, check if the grouped solution has any split
This came from a reported bug where the single strategy was being chosen for a solution on a groupable protocol (univ4) but the solution was composed of 2 splits only. Like a trade from WETH to USDC through two different univ4 pools

Took 47 minutes


Took 15 seconds
2025-06-13 09:52:06 +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
06ce28c8fd feat: Add BalancerV3Encoder
Took 1 hour 7 minutes


Took 2 minutes
2025-06-05 17:22:16 +01:00
Diana Carvalho
eec50f8822 feat: Extend Swap to hold user_data: Option<Bytes>
Took 25 minutes
2025-06-05 15:47:40 +01:00
Diana Carvalho
5fa97d08e5 feat: Upgrade alloy to "1.0.6"
Took 18 minutes
2025-05-30 11:55:44 +01:00
Diana Carvalho
73c1a2db6a chore: Rename selector to function signature
Took 8 minutes
2025-05-27 09:37:24 +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
f5d9ab03da chore: Improve docstrings
Took 23 minutes
2025-05-26 12:50:11 +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
5aff28e345 feat: Add encode_full_calldata to TychoEncoder trait
This is so that people can easily use it without downcasting the encoder

Took 32 minutes
2025-05-22 14:43:12 +01:00
Diana Carvalho
facdf716bd feat: Add interacting_with to EncodedSolution
- Remove encode_full_calldata from the TychoEncoder trait
- Make the TychoExecutorEncoder use encode_solutions instead of encode_full_calldata
- Update tycho-encode.rs accordingly

Took 1 hour 3 minutes


Took 12 seconds
2025-05-22 14:43:12 +01:00
Diana Carvalho
08056c4a6c feat: Remove slippage and expected_amount from Solution
The user is responsible for coming up with a sensible value for this themselves

Took 37 minutes
2025-05-22 14:43:12 +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
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
Diana Carvalho
38748925b3 feat: Bring back TransferType and simplify encoding logic
Took 1 hour 53 minutes
2025-05-16 16:59:35 +01:00
Diana Carvalho
09ff7691f8 chore: Make naming consistent: transfer_needed, approval_needed, etc
Took 46 minutes
2025-05-15 14:52:43 +01: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
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
f99bd296a1 fix: Derive Clone in TychoEncoders 2025-04-29 17:06:41 -04:00
Diana Carvalho
7bf0b48ea6 fix: Make clippy happy after new format! format
Took 19 minutes
2025-04-24 13:34:08 +01:00
Diana Carvalho
df92be8875 feat: Allow for token_in_already_in_router
--- don't change below this line ---
ENG-4446 Took 31 minutes


Took 26 seconds
2025-04-23 12:31:42 +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
TAMARA LIPOWSKI
30dc3f7682 chore: renamings for clarity
- Also added a check for length in the Curve executor.
2025-04-23 12:31:41 +01:00
TAMARA LIPOWSKI
a301a1cef3 feat: (WIP) Support selection of transfer into router
- 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
2025-04-23 12:31:41 +01:00
TAMARA LIPOWSKI
59a80dc392 feat: Optimize transfer to first pool
TODO: Update integration tests on solidity side, since a few were now updated on the encoding side to use a transferFrom.
2025-04-23 12:31:41 +01:00
TAMARA LIPOWSKI
f3c4128eda fix: USV3 encoding/decoding after rebase
- 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.
2025-04-23 12:31:41 +01:00
TAMARA LIPOWSKI
61c0163bee fix: test fix after rebase 2025-04-23 12:31:41 +01:00
Diana Carvalho
26ec30852d fix: Fixes after merge with feature branch
Update some tests calldata

Took 9 minutes
2025-04-23 12:31:40 +01:00
Diana Carvalho
f5e712e0ff feat(tycho-router-encoder): Select strategy depending on the solution
- The tycho router address default is set at the EncoderBuilder level (not inside the strategies)
- Rename TychoCoreChain to TychoCommonChain
- Only take TychoCommonChain as an argument at the outermost level: EncoderBuilder. Everywhere else we use the execution Chain right away

--- don't change below this line ---
ENG-4332 Took 1 hour 10 minutes
2025-04-23 12:30:13 +01:00
Diana Carvalho
6fd0ab54c1 docs: Improve doc
--- don't change below this line ---
ENG-4306 Took 4 minutes
2025-04-23 12:30:13 +01:00
Diana Carvalho
8b4b79b353 feat: Refactor TychoEncoder
We have a trait TychoEncoder and then two implementations: TychoRouterEncoder and TychoExecutorEncoder.
This way we go a level above with the decision if it is a direct execution or if it should use the tycho router.

- Created two builders: one for each tycho encoder
- Delete ExecutorStrategyEncoder and move code straight into the TychoExecutorEncoder
- Add validate_solution to trait TychoEncoder
- Move group_swaps.rs a level up
- Update tests and usage cases

Doing this we get rid of all that weird stuff we were doing before

--- don't change below this line ---
ENG-4306 Took 2 hours 6 minutes


Took 12 seconds
2025-04-23 12:30:13 +01:00