Commit Graph

67 Commits

Author SHA1 Message Date
Diana Carvalho
4f29022c42 fix: After rebase fixes
--- don't change below this line ---
ENG-4246 Took 2 minutes
2025-02-19 17:05:46 +00:00
Diana Carvalho
d9d56e7a8c chore: Rename signer_pk to swapper_pk
--- don't change below this line ---
ENG-4246 Took 15 minutes
2025-02-19 17:03:25 +00:00
Diana Carvalho
30b5ab9025 fix: After rebase fixes
Put the strategy_encoders.rs back inside the strategy_encoder directory

--- don't change below this line ---
ENG-4246 Took 3 minutes

Took 12 seconds
2025-02-19 17:03:22 +00:00
Diana Carvalho
03506fabe9 feat: Create a EVMEncoderBuilder
- It has two three methods to be created:
  - new: where the user can pass any custom StrategyEncoder
  - tycho_router: where the default SplitSwapStrategyEncoder with Tycho Router will be used
  - direct_execution: where the user can encode only the execution data and integrate this into their workflow.
- This replaces StrategyEncoderRegistry
- EVMTychoEncoder holds directly the StrategyEncoder and not the registry (per one init of the EVMTychoEncoder there is only one possible StrategyEncoder)
- Update quickstart
- Update bin (add subcommands to bin to create a different instance of EVMEncoderBuilder)

--- don't change below this line ---
ENG-4246 Took 33 minutes

Took 38 seconds

Took 38 seconds
2025-02-19 17:03:10 +00:00
TAMARA LIPOWSKI
5ab233ed0a refactor: PR comments
- rename utils.rs to group_swaps.rs
- extend instead of push in order to avoid calling abi_encode_packed again
2025-02-19 10:25:16 -05:00
TAMARA LIPOWSKI
ac831176d4 feat: Support swap grouping for executor strategy
- Also make sure the strategy errors if > 1 group.
2025-02-18 14:03:06 -05:00
TAMARA LIPOWSKI
962e460e34 refactor: Make group_swaps a util method
- In preparation for also using this for the executor encoder.
This also make test setup much easier for swap grouping - not having to init the encoder every time.
2025-02-18 12:12:08 -05:00
TAMARA LIPOWSKI
8f1e372c90 refactor: PR comments (moving things around/docs)...
- Move the validator into its own file, for organization purposes.
- Add missing elements to `SplitSwapStrategyEncoder` docstring
2025-02-17 23:57:01 -05:00
TAMARA LIPOWSKI
44aabf1761 feat: Merge USV4 strategy back into split strategy
- Since the group_swaps method is now generalized, there is no need to have an entirely separate method here.
2025-02-17 23:44:58 -05:00
TAMARA LIPOWSKI
47b61802ee feat: Generalize group_swaps method
- This can now be used for any groupable protocols - not just USV4.
2025-02-17 17:23:29 -05:00
TAMARA LIPOWSKI
957bf898f2 fix: Do not group split swaps
As far as we know, Uniswap V4 has no support for optimizing split swaps - only sequential swaps. We must make sure we don't accidentally group split swaps too - as this will likely revert due to mismatched input and output values.
2025-02-17 16:50:59 -05:00
TAMARA LIPOWSKI
e94154bc2d fix: Do not count intermediary tokens in indices
To achieve this, a small refactor was necessary with the introduction of a SwapGroup object, and a separate method to create a vec of these objects. This then separates all logic related to combining protocol data nicely and cleanly into its own method with its own tests.

TODO:
- Deal with split swaps and add test for split swap scenario
- Clean up all existing PR comments
2025-02-14 18:48:39 -05:00
TAMARA LIPOWSKI
556af0253d test: Add test for USV4 sequential swap 2025-02-14 00:51:06 -05:00
TAMARA LIPOWSKI
b452372714 refactor: deduplicate validation for Split & USV4 strategy
We use the same validation for both SplitSwapStrategy and UniswapV4Strategy - so, instead, put the validation into a Validator trait that gets initialized in both swap strategies in order to avoid duplication.
2025-02-13 15:30:09 -05:00
TAMARA LIPOWSKI
f32210bb1f feat: (WIP) UniswapV4 encoding
- To keep any knowledge of USV4 separate from regular splits, I've made a new USV4 encoding strategy that will be used only if we detect sequential USV4 swaps.
- For single USV4 swaps without necessary optimizations, the regular split swap strategy can be used
- No need to change the swap struct interface to take multiple swaps - this concatenation can be done at the swap strategy level.

TODO:
- test
- deduplicate code from split strategy
- UniswapV4SwapEncoder
2025-02-13 14:51:08 -05:00
TAMARA LIPOWSKI
1c565deb57 refactor: (Solution) replace check_amount with checked_amount
- This is to have consistency with checked_token
2025-02-11 11:25:58 -05:00
Diana Carvalho
dd7ecac324 feat: Add selector to Transaction
Return selector in the StrategyEncoder. This is needed for the ExecutorStrategyEncoder

--- don't change below this line ---
ENG-4088 Took 12 minutes


Took 13 seconds
2025-02-11 12:20:47 +00:00
Diana Carvalho
a234ff701f feat: Remove router_address from TychoEncoder
Make the router address mandatory for the Solution attribute instead

--- don't change below this line ---
ENG-4088 Took 30 minutes
2025-02-07 14:58:09 +00:00
Diana Carvalho
f5232f403e feat: Read default executors at compile time into a json
This way we don't have issues with paths and trying to read files that are at other locations after compile time

--- don't change below this line ---
ENG-4088 Took 44 seconds

Took 52 seconds
2025-02-07 12:16:46 +00:00
Diana Carvalho
b333d60d69 feat: Add clone to EVMTychoEncoder
--- don't change below this line ---
ENG-4088 Took 4 minutes

Took 8 seconds

Took 48 seconds
2025-02-07 12:16:46 +00:00
TAMARA LIPOWSKI
77d53c786a docs: Explain wrap/unwrap process in validate_swap_path 2025-02-06 11:52:43 -05:00
TAMARA LIPOWSKI
9adbab498c chore: merge main 2025-02-06 11:49:17 -05:00
TAMARA LIPOWSKI
2b94a3f213 docs: improvements from PR comments 2025-02-06 11:34:57 -05:00
TAMARA LIPOWSKI
1a07c7dc61 Fix: Do not let user specify the native/wrapped token
This puts too much burden on the user. Instead, specify native and wrapped tokens as methods which return hardcoded values.
2025-02-06 11:08:06 -05:00
TAMARA LIPOWSKI
e83b8d9aef feat: Take Chain object containing native/wrapped addresses
- This way this chain object contains everything we need, we don't need to worry about doing any transformation or calling any supplementary functions inside any of the encoders
- Needed to move our new Chain object to a higher level since this is used in the higher-level encoder traits. This required some weird default values in the constants in order to avoid using alloy's hex literal. I could have instead opted to make Bytes parse a string I think, though this would mean possibly returning an error at the constants level, which is not nice either.

Question:
- Do we want the user to be in charge of passing the native and wrapped token every single time? This may be a bit annoying for the user. For now, I have defaulted to those in constants.rs, this would take 5 mins to remove though if you don't like it, and it would get rid of this complicated bytes initialization.
2025-02-05 17:14:56 -05:00
TAMARA LIPOWSKI
2b43ecdf29 docs: Document validation functions 2025-02-05 16:44:28 -05:00
Tamara
021a179076 Merge branch 'main' into encoding/tnl/ENG-4205-code-docs 2025-02-05 16:35:54 -05:00
TAMARA LIPOWSKI
07457b5f76 docs: More docs and improvements of existing docs
- Tried not to leave a single public function undocumented, though did not double-document public function with obvious names
- Remove all mentions of the strategy selector in favour of the strategy registry (to avoid confusion)
2025-02-05 16:35:43 -05:00
TAMARA LIPOWSKI
44e8e0bb96 docs: Address comments, make clippy happy 2025-02-05 15:44:27 -05:00
TAMARA LIPOWSKI
f8b3baff55 chore: merge main 2025-02-05 13:48:00 -05:00
Harsh Vardhan Roy
9e61261a51 Update strategy_encoders.rs
Co-authored-by: Tamara <tamara@datarevenue.com>
2025-02-05 20:23:10 +05:30
Harsh Vardhan Roy
3803be897e Merge branch 'main' into encoder/hr/ENG-4083-Validate-SplitSwap 2025-02-05 19:39:00 +05:30
Diana Carvalho
3dcb8aee7b chore: Use tycho_core::dto objects instead of tycho_core::models
--- don't change below this line ---
ENG-4169 Took 11 minutes
2025-02-05 10:10:43 +00:00
TAMARA LIPOWSKI
52cce5f5c6 docs: (WIP) In-code docs for encoders
- TODO double check all this, look for missing docs
2025-02-04 18:14:32 -05:00
TAMARA LIPOWSKI
8cd7d9f76e feat: Get native/wrapped addresses from chain
- These were being hardcoded to ETH and WETH, which may not always be the case for EVM-compatible chains.
2025-02-04 16:59:01 -05:00
royvardhan
7b7226356d fix: get_mock_split_swap_strategy_encoder 2025-02-05 00:18:26 +05:30
Harsh Vardhan Roy
b19dc89c8c Merge branch 'main' into encoder/hr/ENG-4083-Validate-SplitSwap 2025-02-05 00:17:21 +05:30
royvardhan
c787f5e722 fix: use native action to validate path 2025-02-05 00:14:09 +05:30
Diana Carvalho
79f513c76b chore: After rebase with master fixes
Took 2 minutes
2025-02-04 17:32:14 +00:00
Diana Carvalho
c89f46a2e6 chore: Rename registry -> swap_encoder_registry
Took 14 minutes

Took 8 seconds
2025-02-04 17:30:19 +00:00
Diana Carvalho
23875b8b02 feat: Refactor Registries
Interface changes:
- Rename StrategySelector to StrategyEncoderRegistry
- Implement clone for SwapEncoder

The StrategyEncoderRegistry needs to be initialised at the highest level and the passed to the TychoEncoder.
The TychoEncoder doesn't hold the chain nor the signer_pk as attributes anymore
The StrategyEncoderRegistry does:
- Initialises the SwapEncoderRegistry
- Initialises all the strategies and saves them in a HashMap
- Later, the TychoEncoder only reads from this hashmap

The StrategyEncoder now each holds a SwapEncoderRegistry as an attribute and they use this to get the correct SwapEncoder instead of reading from the global SWAP_ENCODER_REGISTRY

Simplified the SwapEncoderRegistry to not need a Config (everything is done inside itself)
All SwapEncoders implement clone

Took 2 hours 29 minutes

Took 11 seconds

Took 2 minutes
2025-02-04 17:30:10 +00:00
royvardhan
2f0013a934 chore: naming 2025-02-04 22:34:53 +05:30
royvardhan
4da50ddc9e chore: naming 2025-02-04 22:34:53 +05:30
royvardhan
4d97c3f16d feat: add tests for wrap unwrap case 2025-02-04 22:34:10 +05:30
royvardhan
b0dda205b0 chore: break tests 2025-02-04 22:34:10 +05:30
royvardhan
b8013c6e7e chore: move validation methods inside impl 2025-02-04 22:34:10 +05:30
royvardhan
b69aef9b8f feat: add tests for split swap validations 2025-02-04 22:34:10 +05:30
royvardhan
95edd5b1fe fix: checks in validations 2025-02-04 22:34:10 +05:30
royvardhan
f80ffa924f feat: add validation for split swap 2025-02-04 22:34:10 +05:30
TAMARA LIPOWSKI
ff283bc333 fix: test fixes after merge 2025-02-04 11:49:27 -05:00