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
Apparently was not necessary and was causing clippy warnings.
```
warning: you seem to be trying to use `&Box<T>`. Consider using just `&T`
--> src/encoding/models.rs:91:32
|
91 | pub protocol_state: Option<&'a Box<dyn ProtocolSim>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a dyn ProtocolSim`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrowed_box
= note: `#[warn(clippy::borrowed_box)]` on by default
```
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
- 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
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
- The router address can be set when creating the SplitSwapStrategy, which now takes an Option<Bytes> as input during initialization (another breaking interface change)
- This change allows us to change our router address in the future with minimal effect on the users. Users should only pass the router address in the split swap initialization if they intend to use their own router for execution.
- This change also means that the router address does not need to be passed with the solution, even when using the executor strategy (which was pointless).
- I thought of having a router_address() method to set this in the encoder builder - but it seemed too messy, since we don't need the router address for execution for example. We would then potentially unnecessarily load and set the default router address when not needed. It is also not even used at the highest level EVMTychoEncoder, so it makes more sense for it to be directly associated with the swap strategy instead.
- Users will now not be able to encode for different routers without re-initializing the strategy. We assumed this use case to be very rare and not worth supporting.
- If the signer_pk is not passed -> use the swap method that expects the tokens to be already in the Router
- If it is passed -> compute permit2 and use swap method that does the token in transfer
- Extend builder to have another shortcut
- Add integration test with contract
- Update bin (and simplified it) and quickstart
--- don't change below this line ---
ENG-4255 Took 1 hour 51 minutes
Took 2 minutes
Took 7 seconds
- 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
- 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.
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