feat(curve): Add CurveEncoder

We don't know the pool tokens in the ProtocolComponent, so we can't infer the indexes correctly. Added a call to the MetaRegistry curve contract to get the correct token indexes. To do this, I had to move the get_client to utils. We could actually refactor the transaction logic into its' own struct and use it here and in the approval logic
It was assumed that all the pools will have a "factory" static attribute, even if empty

--- don't change below this line ---
ENG-4306 Took 2 hours 28 minutes


Took 27 seconds
This commit is contained in:
Diana Carvalho
2025-04-04 13:48:10 +01:00
parent f7cdc6f537
commit e9bb8c576a
8 changed files with 371 additions and 40 deletions

View File

@@ -19,10 +19,7 @@ use tycho_common::Bytes;
use crate::encoding::{
errors::EncodingError,
evm::{
approvals::protocol_approvals_manager::get_client,
utils::{biguint_to_u256, bytes_to_address, encode_input, get_runtime},
},
evm::utils::{biguint_to_u256, bytes_to_address, encode_input, get_client, get_runtime},
models::Chain,
};

View File

@@ -1,13 +1,12 @@
use std::{env, sync::Arc};
use std::sync::Arc;
use alloy::{
providers::{Provider, ProviderBuilder, RootProvider},
providers::{Provider, RootProvider},
rpc::types::{TransactionInput, TransactionRequest},
transports::BoxTransport,
};
use alloy_primitives::{Address, Bytes, TxKind, U256};
use alloy_sol_types::SolValue;
use dotenv::dotenv;
use tokio::{
runtime::{Handle, Runtime},
task::block_in_place,
@@ -15,7 +14,7 @@ use tokio::{
use crate::encoding::{
errors::EncodingError,
evm::utils::{encode_input, get_runtime},
evm::utils::{encode_input, get_client, get_runtime},
};
/// A manager for checking if an approval is needed for interacting with a certain spender.
@@ -72,18 +71,6 @@ impl ProtocolApprovalsManager {
}
}
/// Gets the client used for interacting with the EVM-compatible network.
pub async fn get_client() -> Result<Arc<RootProvider<BoxTransport>>, EncodingError> {
dotenv().ok();
let eth_rpc_url = env::var("RPC_URL")
.map_err(|_| EncodingError::FatalError("Missing RPC_URL in environment".to_string()))?;
let client = ProviderBuilder::new()
.on_builtin(&eth_rpc_url)
.await
.map_err(|_| EncodingError::FatalError("Failed to build provider".to_string()))?;
Ok(Arc::new(client))
}
#[cfg(test)]
mod tests {
use std::str::FromStr;