Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 35 additions & 37 deletions _deprecated/alloy-evm-connector/src/across_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use parking_lot::RwLock as AtomicLock;
use rust_decimal::dec;
use safe_math::safe;
use std::str::FromStr;
use std::sync::{Arc, RwLock as ComponentLock, Weak};
use std::sync::{Arc, Weak};
use symm_core::core::functional::{
IntoObservableSingleArc, IntoObservableSingleVTable, NotificationHandlerOnce,
IntoObservableSingleArc, IntoObservableSingleVTable, IntoObservableSingleVTableRef, NotificationHandlerOnce
};

use crate::chain_operations::ChainOperations;
Expand All @@ -28,8 +28,8 @@ use symm_core::core::{

pub struct AcrossCollateralBridge {
observer: Arc<AtomicLock<SingleObserver<CollateralRouterEvent>>>,
source: Arc<ComponentLock<EvmCollateralDesignation>>,
destination: Arc<ComponentLock<EvmCollateralDesignation>>,
source: Arc<EvmCollateralDesignation>,
destination: Arc<EvmCollateralDesignation>,

// Shared chain_operations injected by EvmConnector
chain_operations: Arc<AtomicLock<ChainOperations>>,
Expand All @@ -38,34 +38,32 @@ pub struct AcrossCollateralBridge {
impl AcrossCollateralBridge {
/// Constructor that accepts shared chain_operations from EvmConnector
pub fn new_with_shared_operations(
source: Arc<ComponentLock<EvmCollateralDesignation>>,
destination: Arc<ComponentLock<EvmCollateralDesignation>>,
source: Arc<EvmCollateralDesignation>,
destination: Arc<EvmCollateralDesignation>,
chain_operations: Arc<AtomicLock<ChainOperations>>,
) -> Arc<ComponentLock<Self>> {
Arc::new({
ComponentLock::new(Self {
observer: Arc::new(AtomicLock::new(SingleObserver::new())),
source,
destination,
chain_operations,
})
) -> Arc<Self> {
Arc::new(Self {
observer: Arc::new(AtomicLock::new(SingleObserver::new())),
source,
destination,
chain_operations,
})
}
}

impl IntoObservableSingleVTable<CollateralRouterEvent> for AcrossCollateralBridge {
fn set_observer(&mut self, observer: Box<dyn NotificationHandlerOnce<CollateralRouterEvent>>) {
impl IntoObservableSingleVTableRef<CollateralRouterEvent> for AcrossCollateralBridge {
fn set_observer(&self, observer: Box<dyn NotificationHandlerOnce<CollateralRouterEvent>>) {
self.observer.write().set_observer(observer);
}
}

impl CollateralBridge for AcrossCollateralBridge {
fn get_source(&self) -> Arc<ComponentLock<dyn CollateralDesignation>> {
(self.source).clone() as Arc<ComponentLock<dyn CollateralDesignation>>
fn get_source(&self) -> Arc<dyn CollateralDesignation> {
(self.source).clone() as Arc<dyn CollateralDesignation>
}

fn get_destination(&self) -> Arc<ComponentLock<dyn CollateralDesignation>> {
(self.destination).clone() as Arc<ComponentLock<dyn CollateralDesignation>>
fn get_destination(&self) -> Arc<dyn CollateralDesignation> {
(self.destination).clone() as Arc<dyn CollateralDesignation>
}

fn transfer_funds(
Expand All @@ -79,16 +77,16 @@ impl CollateralBridge for AcrossCollateralBridge {
cumulative_fee: Amount,
) -> eyre::Result<()> {
let observer = self.observer.clone();
let source = self.source.read().unwrap().get_full_name();
let destination = self.destination.read().unwrap().get_full_name();
let source = self.source.get_full_name();
let destination = self.destination.get_full_name();

if !(&source == "EVM:ARBITRUM:USDC" && &destination == "EVM:BASE:USDC") {
return Err(eyre::eyre!("Invalid source and destination"));
}

// Get designation details
let source_designation = self.source.read().unwrap();
let destination_designation = self.destination.read().unwrap();
let source_designation = &self.source;
let destination_designation = &self.destination;

// Use direct chain_operations.execute_command() instead of arbiter
let command = ChainCommand::ExecuteCompleteAcrossDeposit {
Expand All @@ -108,19 +106,19 @@ impl CollateralBridge for AcrossCollateralBridge {
let timestamp = Utc::now();
// Callback receives the original routing amounts passed through from chain operation
/*observer
.read()
.publish_single(CollateralRouterEvent::HopComplete {
chain_id,
address,
client_order_id: client_order_id.clone(),
timestamp,
source: source.clone(),
destination: destination.clone(),
route_from: route_from.clone(),
route_to: route_to.clone(),
amount: total_routed, // Now receives original_amount from chain operation
fee: fee_deducted, // Now receives original_cumulative_fee from chain operation
});*/
.read()
.publish_single(CollateralRouterEvent::HopComplete {
chain_id,
address,
client_order_id: client_order_id.clone(),
timestamp,
source: source.clone(),
destination: destination.clone(),
route_from: route_from.clone(),
route_to: route_to.clone(),
amount: total_routed, // Now receives original_amount from chain operation
fee: fee_deducted, // Now receives original_cumulative_fee from chain operation
});*/
Ok(())
}),
};
Expand Down
72 changes: 35 additions & 37 deletions _deprecated/alloy-evm-connector/src/erc20_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use alloy::primitives::B256;
use eyre::{OptionExt, Result};
use parking_lot::RwLock as AtomicLock;
use safe_math::safe;
use std::sync::{Arc, RwLock as ComponentLock};
use symm_core::core::functional::{IntoObservableSingleVTable, NotificationHandlerOnce};
use std::sync::Arc;
use symm_core::core::functional::{IntoObservableSingleVTable, IntoObservableSingleVTableRef, NotificationHandlerOnce};

use crate::chain_operations::ChainOperations;
use crate::commands::ChainCommand;
Expand All @@ -22,8 +22,8 @@ use symm_core::core::{

pub struct Erc20CollateralBridge {
observer: Arc<AtomicLock<SingleObserver<CollateralRouterEvent>>>,
source: Arc<ComponentLock<EvmCollateralDesignation>>,
destination: Arc<ComponentLock<EvmCollateralDesignation>>,
source: Arc<EvmCollateralDesignation>,
destination: Arc<EvmCollateralDesignation>,

// Shared chain_operations injected by EvmConnector
chain_operations: Arc<AtomicLock<ChainOperations>>,
Expand All @@ -32,34 +32,32 @@ pub struct Erc20CollateralBridge {
impl Erc20CollateralBridge {
/// Constructor that accepts shared chain_operations from EvmConnector
pub fn new_with_shared_operations(
source: Arc<ComponentLock<EvmCollateralDesignation>>,
destination: Arc<ComponentLock<EvmCollateralDesignation>>,
source: Arc<EvmCollateralDesignation>,
destination: Arc<EvmCollateralDesignation>,
chain_operations: Arc<AtomicLock<ChainOperations>>,
) -> Arc<ComponentLock<Self>> {
Arc::new({
ComponentLock::new(Self {
observer: Arc::new(AtomicLock::new(SingleObserver::new())),
source,
destination,
chain_operations,
})
) -> Arc<Self> {
Arc::new(Self {
observer: Arc::new(AtomicLock::new(SingleObserver::new())),
source,
destination,
chain_operations,
})
}
}

impl IntoObservableSingleVTable<CollateralRouterEvent> for Erc20CollateralBridge {
fn set_observer(&mut self, observer: Box<dyn NotificationHandlerOnce<CollateralRouterEvent>>) {
impl IntoObservableSingleVTableRef<CollateralRouterEvent> for Erc20CollateralBridge {
fn set_observer(&self, observer: Box<dyn NotificationHandlerOnce<CollateralRouterEvent>>) {
self.observer.write().set_observer(observer);
}
}

impl CollateralBridge for Erc20CollateralBridge {
fn get_source(&self) -> Arc<ComponentLock<dyn CollateralDesignation>> {
(self.source).clone() as Arc<ComponentLock<dyn CollateralDesignation>>
fn get_source(&self) -> Arc<dyn CollateralDesignation> {
(self.source).clone() as Arc<dyn CollateralDesignation>
}

fn get_destination(&self) -> Arc<ComponentLock<dyn CollateralDesignation>> {
(self.destination).clone() as Arc<ComponentLock<dyn CollateralDesignation>>
fn get_destination(&self) -> Arc<dyn CollateralDesignation> {
(self.destination).clone() as Arc<dyn CollateralDesignation>
}

fn transfer_funds(
Expand All @@ -73,12 +71,12 @@ impl CollateralBridge for Erc20CollateralBridge {
cumulative_fee: Amount,
) -> Result<()> {
let observer = self.observer.clone();
let source = self.source.read().unwrap().get_full_name();
let destination = self.destination.read().unwrap().get_full_name();
let source = self.source.get_full_name();
let destination = self.destination.get_full_name();

// Get designation details
let source_designation = self.source.read().unwrap();
let destination_designation = self.destination.read().unwrap();
let source_designation = &self.source;
let destination_designation = &self.destination;

// Use direct chain_operations.execute_command() for simple ERC20 transfer
let command = ChainCommand::Erc20Transfer {
Expand All @@ -93,19 +91,19 @@ impl CollateralBridge for Erc20CollateralBridge {
let timestamp = Utc::now();
// Callback receives the original routing amounts passed through from chain operation
/*observer
.read()
.publish_single(CollateralRouterEvent::HopComplete {
chain_id,
address,
client_order_id: client_order_id.clone(),
timestamp,
source: source.clone(),
destination: destination.clone(),
route_from: route_from.clone(),
route_to: route_to.clone(),
amount: total_transferred, // Now receives original_amount from chain operation
fee: fee_deducted, // Now receives original_cumulative_fee from chain operation
});*/
.read()
.publish_single(CollateralRouterEvent::HopComplete {
chain_id,
address,
client_order_id: client_order_id.clone(),
timestamp,
source: source.clone(),
destination: destination.clone(),
route_from: route_from.clone(),
route_to: route_to.clone(),
amount: total_transferred, // Now receives original_amount from chain operation
fee: fee_deducted, // Now receives original_cumulative_fee from chain operation
});*/
Ok(())
}),
};
Expand Down
33 changes: 15 additions & 18 deletions _deprecated/alloy-evm-connector/src/evm_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,14 @@ impl EvmConnector {
/// Generic bridge creation method - automatically selects bridge type based on designations
pub fn create_bridge(
&self,
source: Arc<std::sync::RwLock<EvmCollateralDesignation>>,
destination: Arc<std::sync::RwLock<EvmCollateralDesignation>>,
) -> Arc<std::sync::RwLock<dyn CollateralBridge>> {
let source_name = source.read().unwrap().get_name();
let destination_name = destination.read().unwrap().get_name();
source: Arc<EvmCollateralDesignation>,
destination: Arc<EvmCollateralDesignation>,
) -> Arc<dyn CollateralBridge> {
let source_name = source.get_name();
let destination_name = destination.get_name();

// Determine bridge type based on cross-chain check
let is_cross_chain = source
.read()
.unwrap()
.is_cross_chain(&*destination.read().unwrap());
let is_cross_chain = source.is_cross_chain(&destination);

if is_cross_chain {
// Cross-chain transfer - use Across bridge
Expand All @@ -179,7 +176,7 @@ impl EvmConnector {
self.chain_operations.clone(),
);

bridge as Arc<std::sync::RwLock<dyn CollateralBridge>>
bridge as Arc<dyn CollateralBridge>
} else {
// Same-chain transfer - use ERC20 bridge
let bridge = Erc20CollateralBridge::new_with_shared_operations(
Expand All @@ -188,16 +185,16 @@ impl EvmConnector {
self.chain_operations.clone(),
);

bridge as Arc<std::sync::RwLock<dyn CollateralBridge>>
bridge as Arc<dyn CollateralBridge>
}
}

/// Create a new AcrossCollateralBridge with shared chain_operations (legacy method)
pub fn create_across_bridge(
&self,
source: Arc<std::sync::RwLock<EvmCollateralDesignation>>,
destination: Arc<std::sync::RwLock<EvmCollateralDesignation>>,
) -> Arc<std::sync::RwLock<AcrossCollateralBridge>> {
source: Arc<EvmCollateralDesignation>,
destination: Arc<EvmCollateralDesignation>,
) -> Arc<AcrossCollateralBridge> {
AcrossCollateralBridge::new_with_shared_operations(
source,
destination,
Expand All @@ -208,9 +205,9 @@ impl EvmConnector {
/// Create a new Erc20CollateralBridge with shared chain_operations (legacy method)
pub fn create_erc20_bridge(
&self,
source: Arc<std::sync::RwLock<EvmCollateralDesignation>>,
destination: Arc<std::sync::RwLock<EvmCollateralDesignation>>,
) -> Arc<std::sync::RwLock<Erc20CollateralBridge>> {
source: Arc<EvmCollateralDesignation>,
destination: Arc<EvmCollateralDesignation>,
) -> Arc<Erc20CollateralBridge> {
Erc20CollateralBridge::new_with_shared_operations(
source,
destination,
Expand Down Expand Up @@ -322,7 +319,7 @@ impl ChainConnector for EvmConnector {
tracing::error!("Failed to send withdraw command: {}", e);
}
}

fn poll_once(&self, chain_id: u32, address: Address, symbol: Symbol) {
todo!()
}
Expand Down
Loading