Skip to content

Commit

Permalink
fix: sync get_strategy_and_underlying_erc20_token with Go SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaRedHand committed Jan 6, 2025
1 parent 3ee4c7f commit b8792b4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
29 changes: 11 additions & 18 deletions crates/chainio/clients/elcontracts/src/reader.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -230,7 +233,6 @@ impl ELChainReader {
/// # Returns
///
/// - the strategy contract,
/// - the erc20 bindings for the underlying token
/// - and the underlying token address
///
/// # Errors
Expand All @@ -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<Http<Client>, 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
Expand Down
9 changes: 4 additions & 5 deletions crates/chainio/clients/elcontracts/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,13 @@ impl ELChainWriter {
amount: U256,
) -> Result<TxHash, ElContractsError> {
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);

Expand All @@ -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?;

Expand Down Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions crates/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,17 @@ 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<GasFiller, JoinFill<BlobGasFiller, JoinFill<NonceFiller, ChainIdFiller>>>,
>,
RootProvider<Http<Client>>,
Http<Client>,
Ethereum,
> {
>;

pub fn get_provider(rpc_url: &str) -> SdkProvider {
let url = Url::parse(rpc_url).expect("Wrong rpc url");
ProviderBuilder::new()
.with_recommended_fillers()
Expand Down

0 comments on commit b8792b4

Please sign in to comment.