Commit Graph

310 Commits

Author SHA1 Message Date
Diana Carvalho
c42a5dae6a fix: Encode sequential swaps with unwrapping WETH correctly
Took 24 minutes


Took 1 minute

Took 24 seconds
2025-08-06 18:02:24 +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
TAMARA LIPOWSKI
a0531bdfad chore: typo fix 2025-07-11 17:18:32 -04:00
TAMARA LIPOWSKI
a53fa6502d test: rewrite testExecute without hack
- We can use the same transaction as the integration test, with a different low-fee USV3 pool.
- Don't need to roll the fork either.
2025-07-11 17:17:32 -04:00
TAMARA LIPOWSKI
4ba59192fc feat: add testExecuteIntegration
- Needed to change the integration test setup to use two USV3 pools instead of one V3 and V2, since the V2 pool was taking too much fees for the order to be fulfilled.
- Also needed to change the fork block to make this test work, which meant also needing to update the data for the existing testExecute.
2025-07-11 17:05:45 -04:00
TAMARA LIPOWSKI
4fef906e42 test: Use calldata in USX integration test
- Needed to update the filler address with the one from the test
- Removed unnecessary approval from non-integration test. The approval is now performed in the callback method.
2025-07-09 15:44:41 -04:00
Diana Carvalho
96d0bf4ba5 fix: Replicate a real Uniswap X order in integration test
Took 16 minutes
2025-07-09 14:38:48 -04:00
Diana Carvalho
d2ba255417 test: Add encoding test for a uniswap X integration test
Took 26 minutes
2025-07-09 14:38:48 -04:00
TAMARA LIPOWSKI
9e2f228a47 fix: use encodePacked to encode if approval needed
- Also approve max amount for the tycho router to use (to save on gas)
2025-07-09 14:32:43 -04:00
TAMARA LIPOWSKI
3752c155ea feat: Handle native ETH outputs
- In this case, the ETH needs to be manually transferred to the reactor.
- Native ETH input is not supported for UniswapX

Source:
https://support.uniswap.org/hc/en-us/articles/17544708791821-Are-there-network-costs-for-UniswapX
2025-07-09 12:21:12 -04:00
TAMARA LIPOWSKI
e243667f9e feat: (WIP) Handle approvals in UniswapXFiller
Reasons for using regular approvals instead of permit2:
- More simplicity, simpler setup
- Unfortunately we won't be able to "expire" approvals, which is a risk we may be okay with taking - since one advantage of this is that we will be able save on gas by not approving the reactor every single time (is this our intention?)

TODO:
- Do we really need input tokens to pass through our router?
- Handle native ETH (double check how this is transferred in the reactor)
2025-07-09 12:21:12 -04:00
TAMARA LIPOWSKI
a2d123a263 fix: disable slither warnings
- locked-ether: We do have a withdraw method. Not sure why it doesn't register with slither. Already tried renaming.
- low-level-calls: This low level call is integral to the design of our filler contract.=
2025-07-08 14:00:17 -04:00
TAMARA LIPOWSKI
a114dfc9da feat: UniswapXFiller callback - naive implementation
Added testCallback + execution integration test with real onchain data
2025-07-08 12:05:15 -04:00
TAMARA LIPOWSKI
00f22d62c1 feat: Take reactor address as input to UniswapXFiller
- Put reactor zero address check in separate line for more easy debugging.
- Also includes other small cosmetic changes.
2025-07-08 09:48:25 -04:00
TAMARA LIPOWSKI
ce1fe1dd94 feat: UniswapXFiller skeleton 2025-07-07 18:13:06 -04:00
die-herdplatte
5aaac2855e forge fmt 2025-06-24 17:42:28 +02:00
die-herdplatte
817aa35557 Merge remote-tracking branch 'upstream/main' into ekubo-mev-resist 2025-06-24 17:40:12 +02:00
Diana Carvalho
df63b87569 fix: Add optimized_transfers_integration_tests.rs
I forgot these tests in the previous PR

Took 24 minutes
2025-06-23 15:34:11 +01:00
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
die-herdplatte
b331a43392 forge fmt 2025-06-18 16:22:34 +02:00
die-herdplatte
58ce241c63 Add support for Ekubo MEV-resist extension 2025-06-17 11:02:37 +02: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