Merge pull request #90 from propeller-heads/router/dc/deploy-executors

fix: Miscellaneous fixes
This commit is contained in:
dianacarvalho1
2025-02-27 15:02:58 +00:00
committed by GitHub
9 changed files with 65 additions and 45 deletions

View File

@@ -1,9 +1,9 @@
{ {
"ethereum": { "ethereum": {
"uniswap_v2": "0x00C1b81e3C8f6347E69e2DDb90454798A6Be975E", "uniswap_v2": "0x00C1b81e3C8f6347E69e2DDb90454798A6Be975E",
"uniswap_v3": "0x5C2F5a71f67c01775180ADc06909288B4C329308", "uniswap_v3": "0xF744EBfaA580cF3fFc25aD046E92BD8B770a0700",
"uniswap_v4": "0xF62849F9A0B5Bf2913b396098F7c7019b51A820a", "uniswap_v4": "0x90BE4620436354c9DfA58614B3Bdd5a80FBfAF31",
"vm:balancer_v2": "0x543778987b293C7E8Cf0722BB2e935ba6f4068D4" "vm:balancer_v2": "0xffe5B139b396c9A3d5d9ab89AAE78bF3070CbD64"
}, },
"tenderly_ethereum": { "tenderly_ethereum": {
"uniswap_v2": "0x00C1b81e3C8f6347E69e2DDb90454798A6Be975E", "uniswap_v2": "0x00C1b81e3C8f6347E69e2DDb90454798A6Be975E",

View File

@@ -27,11 +27,13 @@ module.exports = {
}, },
ethereum: { ethereum: {
url: process.env.RPC_URL, url: process.env.RPC_URL,
accounts: [process.env.PRIVATE_KEY] accounts: [process.env.PRIVATE_KEY],
chainId: 1
}, },
base: { base: {
url: process.env.RPC_URL, url: process.env.RPC_URL,
accounts: [process.env.PRIVATE_KEY] accounts: [process.env.PRIVATE_KEY],
chainId: 8453
} }
}, },

View File

@@ -51,7 +51,7 @@ async function main() {
// Set executors // Set executors
const executorAddresses = executorsToSet.map(executor => executor.executor); const executorAddresses = executorsToSet.map(executor => executor.executor);
const tx = await router.setExecutors(executorAddresses, { const tx = await router.setExecutors(executorAddresses, {
gasLimit: 100000 gasLimit: 200000 // should be around 50k per executor
}); });
await tx.wait(); // Wait for the transaction to be mined await tx.wait(); // Wait for the transaction to be mined
console.log(`Executors set at transaction: ${tx.hash}`); console.log(`Executors set at transaction: ${tx.hash}`);

View File

@@ -21,7 +21,7 @@ use crate::encoding::{
errors::EncodingError, errors::EncodingError,
evm::{ evm::{
approvals::protocol_approvals_manager::get_client, approvals::protocol_approvals_manager::get_client,
utils::{biguint_to_u256, bytes_to_address, encode_input}, utils::{biguint_to_u256, bytes_to_address, encode_input, get_runtime},
}, },
models::Chain, models::Chain,
}; };
@@ -70,15 +70,7 @@ sol! {
impl Permit2 { impl Permit2 {
pub fn new(swapper_pk: String, chain: Chain) -> Result<Self, EncodingError> { pub fn new(swapper_pk: String, chain: Chain) -> Result<Self, EncodingError> {
let (handle, runtime) = match Handle::try_current() { let (handle, runtime) = get_runtime()?;
Ok(h) => (h, None),
Err(_) => {
let rt = Arc::new(Runtime::new().map_err(|_| {
EncodingError::FatalError("Failed to create a new tokio runtime".to_string())
})?);
(rt.handle().clone(), Some(rt))
}
};
let client = block_in_place(|| handle.block_on(get_client()))?; let client = block_in_place(|| handle.block_on(get_client()))?;
let pk = B256::from_str(&swapper_pk).map_err(|_| { let pk = B256::from_str(&swapper_pk).map_err(|_| {
EncodingError::FatalError("Failed to convert swapper private key to B256".to_string()) EncodingError::FatalError("Failed to convert swapper private key to B256".to_string())

View File

@@ -8,21 +8,32 @@ use alloy::{
use alloy_primitives::{Address, Bytes, TxKind, U256}; use alloy_primitives::{Address, Bytes, TxKind, U256};
use alloy_sol_types::SolValue; use alloy_sol_types::SolValue;
use dotenv::dotenv; use dotenv::dotenv;
use tokio::runtime::Runtime; use tokio::{
runtime::{Handle, Runtime},
task::block_in_place,
};
use crate::encoding::{errors::EncodingError, evm::utils::encode_input}; use crate::encoding::{
errors::EncodingError,
evm::utils::{encode_input, get_runtime},
};
/// A manager for checking if an approval is needed for interacting with a certain spender. /// A manager for checking if an approval is needed for interacting with a certain spender.
pub struct ProtocolApprovalsManager { pub struct ProtocolApprovalsManager {
client: Arc<RootProvider<BoxTransport>>, client: Arc<RootProvider<BoxTransport>>,
runtime: Runtime, runtime_handle: Handle,
// Store the runtime to prevent it from being dropped before use.
// This is required since tycho-execution does not have a pre-existing runtime.
// However, if the library is used in a context where a runtime already exists, it is not
// necessary to store it.
#[allow(dead_code)]
runtime: Option<Arc<Runtime>>,
} }
impl ProtocolApprovalsManager { impl ProtocolApprovalsManager {
pub fn new() -> Result<Self, EncodingError> { pub fn new() -> Result<Self, EncodingError> {
let runtime = Runtime::new() let (handle, runtime) = get_runtime()?;
.map_err(|_| EncodingError::FatalError("Failed to create runtime".to_string()))?; let client = block_in_place(|| handle.block_on(get_client()))?;
let client = runtime.block_on(get_client())?; Ok(Self { client, runtime_handle: handle, runtime })
Ok(Self { client, runtime })
} }
/// Checks the current allowance for the given token, owner, and spender, and returns true /// Checks the current allowance for the given token, owner, and spender, and returns true
@@ -41,9 +52,10 @@ impl ProtocolApprovalsManager {
..Default::default() ..Default::default()
}; };
let output = self let output = block_in_place(|| {
.runtime self.runtime_handle
.block_on(async { self.client.call(&tx).await }); .block_on(async { self.client.call(&tx).await })
});
match output { match output {
Ok(response) => { Ok(response) => {
let allowance: U256 = U256::abi_decode(&response, true).map_err(|_| { let allowance: U256 = U256::abi_decode(&response, true).map_err(|_| {

View File

@@ -469,13 +469,13 @@ mod tests {
let pool_fee_usdc_eth = Bytes::from(BigInt::from(3000).to_signed_bytes_be()); let pool_fee_usdc_eth = Bytes::from(BigInt::from(3000).to_signed_bytes_be());
let tick_spacing_usdc_eth = Bytes::from(BigInt::from(60).to_signed_bytes_be()); let tick_spacing_usdc_eth = Bytes::from(BigInt::from(60).to_signed_bytes_be());
let mut static_attributes_usdc_eth: HashMap<String, Bytes> = HashMap::new(); let mut static_attributes_usdc_eth: HashMap<String, Bytes> = HashMap::new();
static_attributes_usdc_eth.insert("fee".into(), pool_fee_usdc_eth); static_attributes_usdc_eth.insert("key_lp_fee".into(), pool_fee_usdc_eth);
static_attributes_usdc_eth.insert("tick_spacing".into(), tick_spacing_usdc_eth); static_attributes_usdc_eth.insert("tick_spacing".into(), tick_spacing_usdc_eth);
let pool_fee_eth_pepe = Bytes::from(BigInt::from(25000).to_signed_bytes_be()); let pool_fee_eth_pepe = Bytes::from(BigInt::from(25000).to_signed_bytes_be());
let tick_spacing_eth_pepe = Bytes::from(BigInt::from(500).to_signed_bytes_be()); let tick_spacing_eth_pepe = Bytes::from(BigInt::from(500).to_signed_bytes_be());
let mut static_attributes_eth_pepe: HashMap<String, Bytes> = HashMap::new(); let mut static_attributes_eth_pepe: HashMap<String, Bytes> = HashMap::new();
static_attributes_eth_pepe.insert("fee".into(), pool_fee_eth_pepe); static_attributes_eth_pepe.insert("key_lp_fee".into(), pool_fee_eth_pepe);
static_attributes_eth_pepe.insert("tick_spacing".into(), tick_spacing_eth_pepe); static_attributes_eth_pepe.insert("tick_spacing".into(), tick_spacing_eth_pepe);
let swap_usdc_eth = Swap { let swap_usdc_eth = Swap {
@@ -525,7 +525,7 @@ mod tests {
let hex_protocol_data = encode(&protocol_data); let hex_protocol_data = encode(&protocol_data);
assert_eq!( assert_eq!(
executor_address, executor_address,
Bytes::from_str("0xF62849F9A0B5Bf2913b396098F7c7019b51A820a").unwrap() Bytes::from_str("0x90BE4620436354c9DfA58614B3Bdd5a80FBfAF31").unwrap()
); );
assert_eq!( assert_eq!(
hex_protocol_data, hex_protocol_data,
@@ -537,7 +537,7 @@ mod tests {
// zero for one // zero for one
"00", "00",
// executor address // executor address
"f62849f9a0b5bf2913b396098f7c7019b51a820a", "90be4620436354c9dfa58614b3bdd5a80fbfaf31",
// first pool intermediary token (ETH) // first pool intermediary token (ETH)
"0000000000000000000000000000000000000000", "0000000000000000000000000000000000000000",
// fee // fee
@@ -891,13 +891,13 @@ mod tests {
let pool_fee_usdc_eth = Bytes::from(BigInt::from(3000).to_signed_bytes_be()); let pool_fee_usdc_eth = Bytes::from(BigInt::from(3000).to_signed_bytes_be());
let tick_spacing_usdc_eth = Bytes::from(BigInt::from(60).to_signed_bytes_be()); let tick_spacing_usdc_eth = Bytes::from(BigInt::from(60).to_signed_bytes_be());
let mut static_attributes_usdc_eth: HashMap<String, Bytes> = HashMap::new(); let mut static_attributes_usdc_eth: HashMap<String, Bytes> = HashMap::new();
static_attributes_usdc_eth.insert("fee".into(), pool_fee_usdc_eth); static_attributes_usdc_eth.insert("key_lp_fee".into(), pool_fee_usdc_eth);
static_attributes_usdc_eth.insert("tick_spacing".into(), tick_spacing_usdc_eth); static_attributes_usdc_eth.insert("tick_spacing".into(), tick_spacing_usdc_eth);
let pool_fee_eth_pepe = Bytes::from(BigInt::from(25000).to_signed_bytes_be()); let pool_fee_eth_pepe = Bytes::from(BigInt::from(25000).to_signed_bytes_be());
let tick_spacing_eth_pepe = Bytes::from(BigInt::from(500).to_signed_bytes_be()); let tick_spacing_eth_pepe = Bytes::from(BigInt::from(500).to_signed_bytes_be());
let mut static_attributes_eth_pepe: HashMap<String, Bytes> = HashMap::new(); let mut static_attributes_eth_pepe: HashMap<String, Bytes> = HashMap::new();
static_attributes_eth_pepe.insert("fee".into(), pool_fee_eth_pepe); static_attributes_eth_pepe.insert("key_lp_fee".into(), pool_fee_eth_pepe);
static_attributes_eth_pepe.insert("tick_spacing".into(), tick_spacing_eth_pepe); static_attributes_eth_pepe.insert("tick_spacing".into(), tick_spacing_eth_pepe);
let swap_usdc_eth = Swap { let swap_usdc_eth = Swap {
@@ -990,12 +990,12 @@ mod tests {
"01", // token out index "01", // token out index
"000000", // split "000000", // split
// Swap data header // Swap data header
"f62849f9a0b5bf2913b396098f7c7019b51a820a", // executor address "90be4620436354c9dfa58614b3bdd5a80fbfaf31", // executor address
// Protocol data // Protocol data
"a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // group token in "a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // group token in
"6982508145454ce325ddbe47a25d4ec3d2311933", // group token in "6982508145454ce325ddbe47a25d4ec3d2311933", // group token in
"00", // zero2one "00", // zero2one
"f62849f9a0b5bf2913b396098f7c7019b51a820a", // executor address "90be4620436354c9dfa58614b3bdd5a80fbfaf31", // executor address
// First pool params // First pool params
"0000000000000000000000000000000000000000", // intermediary token (ETH) "0000000000000000000000000000000000000000", // intermediary token (ETH)
"000bb8", // fee "000bb8", // fee
@@ -1110,7 +1110,7 @@ mod tests {
let pool_fee_eth_pepe = Bytes::from(BigInt::from(25000).to_signed_bytes_be()); let pool_fee_eth_pepe = Bytes::from(BigInt::from(25000).to_signed_bytes_be());
let tick_spacing_eth_pepe = Bytes::from(BigInt::from(500).to_signed_bytes_be()); let tick_spacing_eth_pepe = Bytes::from(BigInt::from(500).to_signed_bytes_be());
let mut static_attributes_eth_pepe: HashMap<String, Bytes> = HashMap::new(); let mut static_attributes_eth_pepe: HashMap<String, Bytes> = HashMap::new();
static_attributes_eth_pepe.insert("fee".into(), pool_fee_eth_pepe); static_attributes_eth_pepe.insert("key_lp_fee".into(), pool_fee_eth_pepe);
static_attributes_eth_pepe.insert("tick_spacing".into(), tick_spacing_eth_pepe); static_attributes_eth_pepe.insert("tick_spacing".into(), tick_spacing_eth_pepe);
let swap_eth_pepe = Swap { let swap_eth_pepe = Swap {
@@ -1173,7 +1173,7 @@ mod tests {
let pool_fee_usdc_eth = Bytes::from(BigInt::from(3000).to_signed_bytes_be()); let pool_fee_usdc_eth = Bytes::from(BigInt::from(3000).to_signed_bytes_be());
let tick_spacing_usdc_eth = Bytes::from(BigInt::from(60).to_signed_bytes_be()); let tick_spacing_usdc_eth = Bytes::from(BigInt::from(60).to_signed_bytes_be());
let mut static_attributes_usdc_eth: HashMap<String, Bytes> = HashMap::new(); let mut static_attributes_usdc_eth: HashMap<String, Bytes> = HashMap::new();
static_attributes_usdc_eth.insert("fee".into(), pool_fee_usdc_eth); static_attributes_usdc_eth.insert("key_lp_fee".into(), pool_fee_usdc_eth);
static_attributes_usdc_eth.insert("tick_spacing".into(), tick_spacing_usdc_eth); static_attributes_usdc_eth.insert("tick_spacing".into(), tick_spacing_usdc_eth);
let swap_usdc_eth = Swap { let swap_usdc_eth = Swap {

View File

@@ -152,7 +152,7 @@ impl SwapEncoder for UniswapV4SwapEncoder {
swap: Swap, swap: Swap,
encoding_context: EncodingContext, encoding_context: EncodingContext,
) -> Result<Vec<u8>, EncodingError> { ) -> Result<Vec<u8>, EncodingError> {
let fee = get_static_attribute(&swap, "fee")?; let fee = get_static_attribute(&swap, "key_lp_fee")?;
let pool_fee_u24 = pad_to_fixed_size::<3>(&fee) let pool_fee_u24 = pad_to_fixed_size::<3>(&fee)
.map_err(|_| EncodingError::FatalError("Failed to pad fee bytes".to_string()))?; .map_err(|_| EncodingError::FatalError("Failed to pad fee bytes".to_string()))?;
@@ -417,7 +417,7 @@ mod tests {
let token_out = Bytes::from("0xdAC17F958D2ee523a2206206994597C13D831ec7"); // USDT let token_out = Bytes::from("0xdAC17F958D2ee523a2206206994597C13D831ec7"); // USDT
let mut static_attributes: HashMap<String, Bytes> = HashMap::new(); let mut static_attributes: HashMap<String, Bytes> = HashMap::new();
static_attributes.insert("fee".into(), Bytes::from(fee.to_signed_bytes_be())); static_attributes.insert("key_lp_fee".into(), Bytes::from(fee.to_signed_bytes_be()));
static_attributes static_attributes
.insert("tick_spacing".into(), Bytes::from(tick_spacing.to_signed_bytes_be())); .insert("tick_spacing".into(), Bytes::from(tick_spacing.to_signed_bytes_be()));
@@ -483,7 +483,7 @@ mod tests {
let token_out = Bytes::from("0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"); // WBTC let token_out = Bytes::from("0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"); // WBTC
let mut static_attributes: HashMap<String, Bytes> = HashMap::new(); let mut static_attributes: HashMap<String, Bytes> = HashMap::new();
static_attributes.insert("fee".into(), Bytes::from(fee.to_signed_bytes_be())); static_attributes.insert("key_lp_fee".into(), Bytes::from(fee.to_signed_bytes_be()));
static_attributes static_attributes
.insert("tick_spacing".into(), Bytes::from(tick_spacing.to_signed_bytes_be())); .insert("tick_spacing".into(), Bytes::from(tick_spacing.to_signed_bytes_be()));
@@ -553,7 +553,7 @@ mod tests {
let mut usde_usdt_static_attributes: HashMap<String, Bytes> = HashMap::new(); let mut usde_usdt_static_attributes: HashMap<String, Bytes> = HashMap::new();
usde_usdt_static_attributes usde_usdt_static_attributes
.insert("fee".into(), Bytes::from(usde_usdt_fee.to_signed_bytes_be())); .insert("key_lp_fee".into(), Bytes::from(usde_usdt_fee.to_signed_bytes_be()));
usde_usdt_static_attributes.insert( usde_usdt_static_attributes.insert(
"tick_spacing".into(), "tick_spacing".into(),
Bytes::from(usde_usdt_tick_spacing.to_signed_bytes_be()), Bytes::from(usde_usdt_tick_spacing.to_signed_bytes_be()),
@@ -571,7 +571,7 @@ mod tests {
let mut usdt_wbtc_static_attributes: HashMap<String, Bytes> = HashMap::new(); let mut usdt_wbtc_static_attributes: HashMap<String, Bytes> = HashMap::new();
usdt_wbtc_static_attributes usdt_wbtc_static_attributes
.insert("fee".into(), Bytes::from(usdt_wbtc_fee.to_signed_bytes_be())); .insert("key_lp_fee".into(), Bytes::from(usdt_wbtc_fee.to_signed_bytes_be()));
usdt_wbtc_static_attributes.insert( usdt_wbtc_static_attributes.insert(
"tick_spacing".into(), "tick_spacing".into(),
Bytes::from(usdt_wbtc_tick_spacing.to_signed_bytes_be()), Bytes::from(usdt_wbtc_tick_spacing.to_signed_bytes_be()),

View File

@@ -109,9 +109,10 @@ impl TychoEncoder for EVMTychoEncoder {
.strategy_encoder .strategy_encoder
.encode_strategy(solution.clone())?; .encode_strategy(solution.clone())?;
let value = match solution.native_action.as_ref() { let value = if solution.given_token == self.native_address {
Some(NativeAction::Wrap) => solution.given_amount.clone(), solution.given_amount.clone()
_ => BigUint::ZERO, } else {
BigUint::ZERO
}; };
transactions.push(Transaction { transactions.push(Transaction {

View File

@@ -1,7 +1,8 @@
use std::cmp::max; use std::{cmp::max, sync::Arc};
use alloy_primitives::{aliases::U24, keccak256, Address, FixedBytes, Keccak256, U256, U8}; use alloy_primitives::{aliases::U24, keccak256, Address, FixedBytes, Keccak256, U256, U8};
use num_bigint::BigUint; use num_bigint::BigUint;
use tokio::runtime::{Handle, Runtime};
use tycho_core::Bytes; use tycho_core::Bytes;
use crate::encoding::{ use crate::encoding::{
@@ -120,3 +121,15 @@ pub fn get_static_attribute(swap: &Swap, attribute_name: &str) -> Result<Vec<u8>
})? })?
.to_vec()) .to_vec())
} }
pub fn get_runtime() -> Result<(Handle, Option<Arc<Runtime>>), EncodingError> {
match Handle::try_current() {
Ok(h) => Ok((h, None)),
Err(_) => {
let rt = Arc::new(Runtime::new().map_err(|_| {
EncodingError::FatalError("Failed to create a new tokio runtime".to_string())
})?);
Ok((rt.handle().clone(), Some(rt)))
}
}
}