From b8792b4a0d8da21894f5031bd8b15ac7a6fdb805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:32:45 -0300 Subject: [PATCH] fix: sync `get_strategy_and_underlying_erc20_token` with Go SDK --- .../chainio/clients/elcontracts/src/reader.rs | 29 +++++++------------ .../chainio/clients/elcontracts/src/writer.rs | 9 +++--- crates/utils/src/lib.rs | 9 +++--- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/crates/chainio/clients/elcontracts/src/reader.rs b/crates/chainio/clients/elcontracts/src/reader.rs index f042b44a..d75d9f6d 100644 --- a/crates/chainio/clients/elcontracts/src/reader.rs +++ b/crates/chainio/clients/elcontracts/src/reader.rs @@ -1,15 +1,18 @@ use crate::error::ElContractsError; -use alloy::providers::Provider; +use alloy::{ + providers::Provider, + transports::http::{Client, Http}, +}; use alloy_primitives::{ruint::aliases::U256, Address, FixedBytes}; use eigen_logging::logger::SharedLogger; use eigen_utils::{ allocationmanager::AllocationManager::{self, OperatorSet}, avsdirectory::AVSDirectory, delegationmanager::DelegationManager, - erc20::ERC20, get_provider, - istrategy::IStrategy, + istrategy::IStrategy::{self, IStrategyInstance}, permissioncontroller::PermissionController, + SdkProvider, }; #[derive(Debug, Clone)] @@ -230,7 +233,6 @@ impl ELChainReader { /// # Returns /// /// - the strategy contract, - /// - the erc20 bindings for the underlying token /// - and the underlying token address /// /// # Errors @@ -239,28 +241,19 @@ impl ELChainReader { pub async fn get_strategy_and_underlying_erc20_token( &self, strategy_addr: Address, - ) -> Result<(Address, Address, Address), ElContractsError> { + ) -> Result<(IStrategyInstance, SdkProvider>, Address), ElContractsError> { let provider = get_provider(&self.provider); - let contract_strategy = IStrategy::new(strategy_addr, &provider); + let contract_strategy = IStrategy::new(strategy_addr, provider); let underlying_token = contract_strategy .underlyingToken() .call() .await - .map_err(ElContractsError::AlloyContractError)?; - - let IStrategy::underlyingTokenReturn { - _0: underlying_token_addr, - } = underlying_token; - - let contract_ierc20 = ERC20::new(underlying_token_addr, &provider); + .map_err(ElContractsError::AlloyContractError)? + ._0; - Ok(( - strategy_addr, - *contract_ierc20.address(), - underlying_token_addr, - )) + Ok((contract_strategy, underlying_token)) } /// Check if the operator is registered diff --git a/crates/chainio/clients/elcontracts/src/writer.rs b/crates/chainio/clients/elcontracts/src/writer.rs index 1c41328f..26cb7fbe 100644 --- a/crates/chainio/clients/elcontracts/src/writer.rs +++ b/crates/chainio/clients/elcontracts/src/writer.rs @@ -179,14 +179,13 @@ impl ELChainWriter { amount: U256, ) -> Result { info!("depositing {amount:?} tokens into strategy {strategy_addr:?}"); - let tokens = self + let (_strategy, token_address) = self .el_chain_reader .get_strategy_and_underlying_erc20_token(strategy_addr) .await?; - let (_, underlying_token_contract, underlying_token) = tokens; let provider = get_signer(&self.signer.clone(), &self.provider); - let contract_underlying_token = ERC20::new(underlying_token_contract, &provider); + let contract_underlying_token = ERC20::new(token_address, &provider); let contract_call = contract_underlying_token.approve(self.strategy_manager, amount); @@ -195,7 +194,7 @@ impl ELChainWriter { let contract_strategy_manager = StrategyManager::new(self.strategy_manager, &provider); let deposit_contract_call = - contract_strategy_manager.depositIntoStrategy(strategy_addr, underlying_token, amount); + contract_strategy_manager.depositIntoStrategy(strategy_addr, token_address, amount); let tx = deposit_contract_call.send().await?; @@ -1113,7 +1112,7 @@ mod tests { new_test_writer(http_endpoint.to_string(), OPERATOR_PRIVATE_KEY.to_string()).await; let earner_address = address!("F2288D736d27C1584Ebf7be5f52f9E4d47251AeE"); - let (_, _, token_address) = el_chain_writer + let (_, token_address) = el_chain_writer .el_chain_reader .get_strategy_and_underlying_erc20_token( get_erc20_mock_strategy(http_endpoint.clone()).await, diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index a52ca7bf..bbab9373 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -201,10 +201,7 @@ pub fn get_signer( .on_http(url) } -#[allow(clippy::type_complexity)] -pub fn get_provider( - rpc_url: &str, -) -> FillProvider< +pub type SdkProvider = FillProvider< JoinFill< Identity, JoinFill>>, @@ -212,7 +209,9 @@ pub fn get_provider( RootProvider>, Http, Ethereum, -> { +>; + +pub fn get_provider(rpc_url: &str) -> SdkProvider { let url = Url::parse(rpc_url).expect("Wrong rpc url"); ProviderBuilder::new() .with_recommended_fillers()