Commit Graph

363 Commits

Author SHA1 Message Date
TAMARA LIPOWSKI
5b86ae4ac5 docs: (split strategy test) better calldata comments
...for clarity and debugging purposes.
2025-01-30 12:45:36 -05:00
Diana Carvalho
8fd3deba70 Merge branch 'refs/heads/main' into encoding/dc/ENG-4081-split-swap-strategy
# Conflicts:
#	src/encoding/evm/router_encoder.rs
#	src/encoding/evm/strategy_encoder/encoder.rs
#	src/encoding/evm/strategy_encoder/selector.rs
#	src/encoding/strategy_encoder.rs

Took 2 minutes
2025-01-30 16:08:08 +00:00
royvardhan
9c35da0760 chore: rename straight_to_pool to direct_execution 2025-01-30 21:17:25 +05:30
royvardhan
8cb95f0950 feat: remove exact_out from USV2 2025-01-30 21:17:25 +05:30
royvardhan
95d45975ad chore: encoder test naming 2025-01-30 21:17:25 +05:30
royvardhan
4ef9b0b82f chore: use Bytes 2025-01-30 21:17:25 +05:30
royvardhan
1b8bf56c75 feat: resolve pr comments 2025-01-30 21:17:25 +05:30
royvardhan
0196767eff feat: add swap test with hex for univ2 executor 2025-01-30 21:17:25 +05:30
royvardhan
c482e21a5f feat: add univ2 executor test with hex 2025-01-30 21:17:25 +05:30
royvardhan
0007c4924c chore: update executor encoder tests 2025-01-30 21:17:25 +05:30
royvardhan
d2289c3765 chore: update test 2025-01-30 21:17:25 +05:30
royvardhan
ad70a0d5a8 feat: add executor encoder test 2025-01-30 21:17:25 +05:30
royvardhan
5c396512cf feat: update ExecutorEncoder interface and relevant types 2025-01-30 21:17:25 +05:30
Diana Carvalho
82e671df39 fix: Use abi_encode_packed in ple_encode()
--- don't change below this line ---
ENG-4081 Took 17 minutes
2025-01-30 15:39:07 +00:00
TAMARA LIPOWSKI
83bbabddd1 chore: rename amountOwed -> amountIn
...for consistency.

Also remove comment. We will keep exact_out to avoid future interface changes.
2025-01-30 10:33:09 -05:00
Diana Carvalho
6e8d2ede59 feat: Simplify router encoder
Don't make selector() a member of the StrategyEncoder trait. It is needed only for certain strategies. The strategy should manage it itself.

--- don't change below this line ---
ENG-4081 Took 17 minutes
2025-01-30 15:19:09 +00:00
Diana Carvalho
089e7d2e0f feat: Add ChainId model
Remove to_chain_id helper method

--- don't change below this line ---
ENG-4081 Took 28 minutes
2025-01-30 15:01:53 +00:00
Diana Carvalho
0e70e827a0 chore: Rename encoder to strategy/swap_encoder
This was confusing me when I had all of them open at the same time. Better to be extra explicit

--- don't change below this line ---
ENG-4081 Took 2 minutes
2025-01-30 13:19:09 +00:00
Diana Carvalho
7a8872cc41 fix: Don't leak evm specific code to interfaces(PrivateKeySigner, Chain)
Pass the signer's private key as a string around and only create a PrivateKeySigner inside Permit2 (where it's needed)
Use tycho-core Chain instead of Alloy ChainID. Create a temp method to convert between them
Create a EVMSwapEncoder that implements the executor_selector (that is evm specific)

--- don't change below this line ---
ENG-4081 Took 1 hour 7 minutes
2025-01-30 13:17:23 +00:00
Diana Carvalho
feb91cc639 feat: Implement SplitSwapStrategyEncoder
The strategy works as follows:
- Manage approvals needed
- Compute min amount (if check amount is any):
  - if slippage is defined, apply slippage on the expected amount and take the min value between that and the check amount
  - if not, it's just the check amount
- Iterate through the swaps
  - call the corresponding swap encoder to encode the swap
  - add swap header (tokens indexes and split)
  - ple encode the swaps
- Add extra inputs (amounts, token addresses, min amount, (un)wrap, number of tokens and receiver)

Misc:
- Move executor address and selector encoding inside the SwapEncoder
- Add default executor_selector to SwapEncoder
- Pass router address inside the SplitSwapStrategyEncoder
- Move Permit2 inside the SplitSwapStrategyEncoder. It is a responsibility and a specificity of the strategy to need permit2 approvals

--- don't change below this line ---
ENG-4081 Took 1 hour 21 minutes
2025-01-30 11:23:32 +00:00
Diana Carvalho
3a69bbf603 feat: Remove generalisation on user approvals manager
This is a too early over generalisation. We need to encode the permit and the signature all together with the other method input variables. This way the return type will be specific to permit2 (instead Vec<u8>) anyway. For simplicity, decided to remove the generalisation and keep things simple

--- don't change below this line ---
ENG-4081 Took 2 hours 23 minutes


Took 9 seconds

Took 1 minute
2025-01-30 11:23:32 +00:00
TAMARA LIPOWSKI
d8b44f623b fix: Remove exactOut from USV3 encoding
- We don't support exactOut atm
2025-01-29 16:56:45 -05:00
royvardhan
877f625efc fix: clippy 2025-01-28 22:27:26 +05:30
Harsh Vardhan Roy
5f5f30ee2d Merge branch 'main' into router/hr/ENG-4035-Balancer-V2-Executor 2025-01-28 22:17:05 +05:30
TAMARA LIPOWSKI
d95b74bb4e chore: small improvements
- Easier less convoluted way to decode address from string
- No more tokio test (not necessary)
- zero_for_one -> zero_to_one for consistency
2025-01-28 09:54:49 -05:00
royvardhan
a6a624b740 fix: balancer v2 encoder bug 2025-01-28 19:49:08 +05:30
TAMARA LIPOWSKI
9c63e099a9 feat: UniswapV3SwapEncoder
- No more supply owed action type or action data - we will always transfer from our router using a regular transfer in the callback.
- The receiver will always be sent with the actual swap call, meaning that no forward received action type or data is necessary either.
- We decode the pool fee as le-bytes and not be-bytes because that's how it's stored: 3c08359cf1/substreams/ethereum-uniswap-v3/src/modules/1_map_pool_created.rs (L64)
2025-01-27 14:25:57 -05:00
royvardhan
7c198fff92 fix: async 2025-01-27 13:44:03 +05:30
royvardhan
9cecea8968 feat: add balance v2 encoder test 2025-01-27 13:44:03 +05:30
Diana Carvalho
b9cfc4a35b fix: Small improvements
- Rename test
- Improve error messages
- Remove unnecessary asserts

--- don't change below this line ---
ENG-4063 Took 52 seconds
2025-01-23 15:53:13 +00:00
Diana Carvalho
04e925fe81 fix: Correct encoding of the approvals
- Add data validations similar to the ones done in the Permit2 SDK
- Fix Domain main (!!!) It's Permit2 not Permit
- Return the whole function signature data (owner, permit_single, signature) encoded

test improvements:
- Don't compare the timestamps, this was making the test fail sometimes and pass other times
- Add a test to run on an anvil fork and actually call permit2 contract to double check the encoded data works

misc:
Rename get_allowance_data -> get_existing_allowance

--- don't change below this line ---
ENG-4063 Took 5 hours 19 minutes


Took 11 seconds
2025-01-23 15:52:19 +00:00
Diana Carvalho
ce9ae49e6f feat: Implement Permit2
- Retrieve allowance data from an RPC
- Encode approvals:
  - Create PermitSingle (and PermitDetails)
  - Use alloy eip712 to get signing hash on typed data
  - Sign data
- Add chrono and alloy eip712 and signer-local to Cargo.toml

--- don't change below this line ---
ENG-4063 Took 1 hour 58 minutes

Took 18 seconds

Took 32 seconds

Took 9 seconds

Took 1 minute


Took 32 minutes
2025-01-23 15:52:19 +00:00
TAMARA LIPOWSKI
ef07f49698 chore: merge main 2025-01-22 09:51:50 -05:00
TAMARA LIPOWSKI
748a3f06c3 chore: Renamings for clarity 2025-01-22 09:33:08 -05:00
TAMARA LIPOWSKI
cc979880e2 chore: Rename address_for_approvals -> router_address
When will this not be the router address that we use for approvals? It will always be the router address. address_for_approvals sounds to me very vague (which approvals?).
2025-01-21 16:35:19 -05:00
TAMARA LIPOWSKI
7b4bf0205d feat: UniswapV2 Swap Encoder 2025-01-21 16:35:19 -05:00
Diana Carvalho
979cdf7437 chore: Do not use expect
--- don't change below this line ---
ENG-4063 Took 57 minutes


Took 17 seconds

Took 45 seconds
2025-01-21 18:48:49 +00:00
Diana Carvalho
b155b273a0 chore: Add more descriptive error message
--- don't change below this line ---
ENG-4063 Took 14 minutes
2025-01-20 16:35:38 +00:00
Diana Carvalho
cbf2b4de5a feat: Implement ProtocolApprovalsManager
I decided to make ProtocolApprovalsManager public method sync not to propagate asynceness early on onto the rest of the code. If later we decide that it is better to have this async, it should be easier to make that change than the opposite one.

--- don't change below this line ---
ENG-4064 Took 24 minutes
2025-01-20 16:05:06 +00:00
Diana Carvalho
af6d73a540 fix: Add RecoverableError
--- don't change below this line ---
ENG-4076 <#DTT#>
2025-01-17 17:02:44 +00:00
Diana Carvalho
bab5caa6f8 feat: Add EncodingError
Change method signatures to expect it and raise it where it makes sense

--- don't change below this line ---
ENG-4076 <#DTT#>
2025-01-17 17:00:52 +00:00
Diana Carvalho
38b8bb0e78 feat: Simplify StrategyEncoders and RouterEncoder
No more SingleSwapStrategyEncoder or SequentialStrategyEncoder
No more batch routing (so no need for batch permits as well). If multiple solutions are found, return multiple Transactions

--- don't change below this line ---
ENG-4076 <#DTT#>
2025-01-17 16:21:26 +00:00
Diana Carvalho
6c6ba21894 feat: Add evm feature gate
- Move all evm code inside evm directory
- StrategyEncoder:
  - Kept StrategyEncoder trait but created a new one: EVMStrategyEncoder to implement encode_protocol_header (that is evm specific).
  - All StrategyEncoders implement both traits now
  - Renamed DefaultStrategySelector -> EVMStrategySelector
- RouterEncoder:
  - Created a RouterEncoder trait and a EVMRouterEncoder that implements it
- Moved utils inside evm directory as well
- Renamed config.json -> executor_addresses.json and moved it to a higher config directory
- Make alloy optional and dependent on the evm feature gate

--- don't change below this line ---
ENG-4075 <#DTT#>
2025-01-17 12:52:39 +00:00
Diana Carvalho
1d3ac22087 fix: Make executor_address a String instead of Address
--- don't change below this line ---
ENG-4075 <#DTT#>
2025-01-17 12:52:39 +00:00
Diana Carvalho
f5df1bbd87 feat: Add chain in config.json for the executor addresses
--- don't change below this line ---
ENG-4075 <#DTT#>
2025-01-17 12:52:39 +00:00
TAMARA LIPOWSKI
20fb01280c chore: add dummy test to make CI happy
Right now it complains and fails because no tests: `error: no tests to run`
2025-01-16 16:41:07 -05:00
TAMARA LIPOWSKI
f8e8a72c53 chore: fix clippy warnings and nightly fmt 2025-01-16 16:35:02 -05:00
Diana Carvalho
e93bf11a85 fix: Constrain new in SwapEncoder so it does not apply to trait objects 2025-01-16 17:18:11 +00:00
Diana Carvalho
30f2ac9f6b fix: Add new to SwapEncoder trait
Add executor_address in SwapEncoderBuilder::new and not in the builder pattern
2025-01-16 17:18:11 +00:00
Diana Carvalho
6d8cbcd80c feat: Add builder pattern and registry for SwapEncoders
Save swap executor addresses in a config file
2025-01-16 17:18:11 +00:00