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
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use alloy_primitives::{Address, Bytes as AlloyBytes};
|
||||
use alloy_primitives::{Address, Bytes as AlloyBytes, FixedBytes};
|
||||
use alloy_sol_types::SolValue;
|
||||
use tycho_core::keccak256;
|
||||
|
||||
use crate::encoding::{
|
||||
errors::EncodingError,
|
||||
@@ -12,10 +13,18 @@ use crate::encoding::{
|
||||
swap_encoder::SwapEncoder,
|
||||
};
|
||||
|
||||
pub trait EVMSwapEncoder: SwapEncoder {
|
||||
fn executor_selector(&self) -> FixedBytes<4> {
|
||||
let hash = keccak256("swap(uint256,bytes)".as_bytes());
|
||||
FixedBytes::<4>::from([hash[0], hash[1], hash[2], hash[3]])
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UniswapV2SwapEncoder {
|
||||
executor_address: String,
|
||||
}
|
||||
|
||||
impl EVMSwapEncoder for UniswapV2SwapEncoder {}
|
||||
impl UniswapV2SwapEncoder {
|
||||
fn get_zero_to_one(sell_token_address: Address, buy_token_address: Address) -> bool {
|
||||
sell_token_address < buy_token_address
|
||||
@@ -63,6 +72,7 @@ impl SwapEncoder for UniswapV2SwapEncoder {
|
||||
pub struct UniswapV3SwapEncoder {
|
||||
executor_address: String,
|
||||
}
|
||||
impl EVMSwapEncoder for UniswapV3SwapEncoder {}
|
||||
|
||||
impl UniswapV3SwapEncoder {
|
||||
fn get_zero_to_one(sell_token_address: Address, buy_token_address: Address) -> bool {
|
||||
@@ -135,6 +145,8 @@ pub struct BalancerV2SwapEncoder {
|
||||
vault_address: String,
|
||||
}
|
||||
|
||||
impl EVMSwapEncoder for BalancerV2SwapEncoder {}
|
||||
|
||||
impl SwapEncoder for BalancerV2SwapEncoder {
|
||||
fn new(executor_address: String) -> Self {
|
||||
Self {
|
||||
|
||||
Reference in New Issue
Block a user