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
This commit is contained in:
Diana Carvalho
2025-05-23 18:22:19 +01:00
parent cdb67f742f
commit c62af2f232
11 changed files with 512 additions and 352 deletions

View File

@@ -1,3 +1,4 @@
use clap::ValueEnum;
use hex;
use num_bigint::BigUint;
use serde::{Deserialize, Serialize};
@@ -8,6 +9,31 @@ use tycho_common::{
use crate::encoding::{errors::EncodingError, serde_primitives::biguint_string};
/// Specifies the method for transferring user funds into Tycho execution.
///
/// Options:
///
/// - `TransferFromPermit2`: Use Permit2 for token transfer.
/// - You must manually approve the Permit2 contract and sign the permit object externally
/// (outside `tycho-execution`).
///
/// - `TransferFrom`: Use standard ERC-20 approval and `transferFrom`.
/// - You must approve the Tycho Router contract to spend your tokens via standard `approve()`
/// calls.
///
/// - `None`: No transfer will be performed.
/// - Assumes the tokens are already present in the Tycho Router.
/// - **Warning**: This is an advanced mode. Ensure your logic guarantees that the tokens are
/// already in the router at the time of execution.
/// - The Tycho router is **not** designed to safely hold tokens. If tokens are not transferred
/// and used in the **same transaction**, they will be permanently lost.
#[derive(Clone, Debug, PartialEq, ValueEnum)]
pub enum UserTransferType {
TransferFromPermit2,
TransferFrom,
None,
}
/// Represents a solution containing details describing an order, and instructions for filling
/// the order.
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
@@ -95,7 +121,6 @@ pub struct Transaction {
/// * `selector`: The selector of the function to be called.
/// * `n_tokens`: Number of tokens in the swap.
/// * `permit`: Optional permit for the swap (if permit2 is enabled).
/// * `signature`: Optional signature for the swap (if permit2 is enabled).
#[derive(Clone, Debug)]
pub struct EncodedSolution {
pub swaps: Vec<u8>,
@@ -103,7 +128,6 @@ pub struct EncodedSolution {
pub selector: String,
pub n_tokens: usize,
pub permit: Option<PermitSingle>,
pub signature: Option<Vec<u8>>,
}
/// Represents a single permit for permit2.