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
This commit is contained in:
@@ -96,27 +96,6 @@ pub struct Transaction {
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
/// Represents the type of transfer to be performed into the pool.
|
||||
///
|
||||
/// # Fields
|
||||
///
|
||||
/// * `TransferToProtocol`: Transfer the token from the router into the protocol.
|
||||
/// * `TransferFromToProtocol`: Transfer the token from the sender to the protocol.
|
||||
/// * `TransferPermit2ToProtocol`: Transfer the token from the sender to the protocol using Permit2.
|
||||
/// * `TransferFromToRouter`: Transfer the token from the sender to the router.
|
||||
/// * `TransferPermit2ToRouter`: Transfer the token from the sender to the router using Permit2.
|
||||
/// * `None`: No transfer is needed. Tokens are already in the pool.
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum TransferType {
|
||||
TransferToProtocol = 0,
|
||||
TransferFromToProtocol = 1,
|
||||
TransferPermit2ToProtocol = 2,
|
||||
TransferFromToRouter = 3,
|
||||
TransferPermit2ToRouter = 4,
|
||||
None = 5,
|
||||
}
|
||||
|
||||
/// Represents necessary attributes for encoding an order.
|
||||
///
|
||||
/// # Fields
|
||||
@@ -127,6 +106,8 @@ pub enum TransferType {
|
||||
/// solution does not require router address.
|
||||
/// * `group_token_in`: Token to be used as the input for the group swap.
|
||||
/// * `group_token_out`: Token to be used as the output for the group swap.
|
||||
/// * `transfer_from`: true if the solution requires a transfer from the user to the router or pool.
|
||||
/// * `transfer`: true if the solution requires a transfer from the router to the pool.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct EncodingContext {
|
||||
pub receiver: Bytes,
|
||||
@@ -134,7 +115,8 @@ pub struct EncodingContext {
|
||||
pub router_address: Option<Bytes>,
|
||||
pub group_token_in: Bytes,
|
||||
pub group_token_out: Bytes,
|
||||
pub transfer_type: TransferType,
|
||||
pub transfer_from: bool,
|
||||
pub transfer: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
|
||||
Reference in New Issue
Block a user