Skip to content

Commit

Permalink
fix: revert changes to files other than for movement counterparty int…
Browse files Browse the repository at this point in the history
…egration tests
  • Loading branch information
andygolay committed Aug 23, 2024
1 parent 509e98f commit 103b48d
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 96 deletions.
33 changes: 15 additions & 18 deletions protocol-units/bridge/chains/ethereum/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::send_transaction;
use crate::utils::{calculate_storage_slot, send_transaction, send_transaction_rules};
use alloy::primitives::{private::serde::Deserialize, Address, FixedBytes, U256};
use alloy::providers::{Provider, ProviderBuilder, RootProvider};
use alloy::signers::k256::elliptic_curve::SecretKey;
Expand Down Expand Up @@ -26,7 +26,6 @@ use crate::types::{
AlloyProvider, AtomicBridgeCounterparty, AtomicBridgeInitiator, CounterpartyContract,
EthAddress, EthHash, InitiatorContract,
};
use crate::utils::{calculate_storage_slot, send_tx_rules};

const GAS_LIMIT: u128 = 10_000_000_000_000_000;
const RETRIES: u32 = 6;
Expand Down Expand Up @@ -127,7 +126,7 @@ impl EthClient {
) -> Result<(), anyhow::Error> {
let contract = self.initiator_contract().expect("Initiator contract not set");
let call = contract.initialize(weth.0, owner.0);
send_transaction(call.to_owned(), &send_tx_rules(), RETRIES, GAS_LIMIT)
send_transaction(call.to_owned(), &send_transaction_rules(), RETRIES, GAS_LIMIT)
.await
.expect("Failed to send transaction");
Ok(())
Expand Down Expand Up @@ -236,16 +235,14 @@ impl BridgeContractInitiator for EthClient {
U256::from(time_lock.0),
)
.value(U256::from(amount.0));
let receipt =
send_transaction(call, &send_tx_rules(), RETRIES, GAS_LIMIT)
.await
.map_err(|e| {
BridgeContractInitiatorError::GenericError(format!(
"Failed to send transaction: {}",
e
))
})?;
println!("receipt: {:?}", receipt);
let _ = send_transaction(call, &send_transaction_rules(), RETRIES, GAS_LIMIT)
.await
.map_err(|e| {
BridgeContractInitiatorError::GenericError(format!(
"Failed to send transaction: {}",
e
))
})?;
Ok(())
}

Expand All @@ -268,7 +265,7 @@ impl BridgeContractInitiator for EthClient {
AtomicBridgeInitiator::new(self.initiator_contract_address()?, &self.rpc_provider);
let call = contract
.completeBridgeTransfer(FixedBytes(bridge_transfer_id.0), FixedBytes(pre_image));
send_transaction(call, &send_tx_rules(), RETRIES, GAS_LIMIT)
send_transaction(call, &send_transaction_rules(), RETRIES, GAS_LIMIT)
.await
.expect("Failed to send transaction");
Ok(())
Expand All @@ -281,7 +278,7 @@ impl BridgeContractInitiator for EthClient {
let contract =
AtomicBridgeInitiator::new(self.initiator_contract_address()?, &self.rpc_provider);
let call = contract.refundBridgeTransfer(FixedBytes(bridge_transfer_id.0));
send_transaction(call, &send_tx_rules(), RETRIES, GAS_LIMIT)
send_transaction(call, &send_transaction_rules(), RETRIES, GAS_LIMIT)
.await
.expect("Failed to send transaction");
Ok(())
Expand Down Expand Up @@ -347,7 +344,7 @@ impl BridgeContractCounterparty for EthClient {
recipient.0 .0,
U256::from(amount.0),
);
send_transaction(call, &send_tx_rules(), RETRIES, GAS_LIMIT)
send_transaction(call, &send_transaction_rules(), RETRIES, GAS_LIMIT)
.await
.expect("Failed to send transaction");
Ok(())
Expand All @@ -365,7 +362,7 @@ impl BridgeContractCounterparty for EthClient {
let secret: [u8; 32] = secret.0.try_into().unwrap();
let call =
contract.completeBridgeTransfer(FixedBytes(bridge_transfer_id.0), FixedBytes(secret));
send_transaction(call, &send_tx_rules(), RETRIES, GAS_LIMIT)
send_transaction(call, &send_transaction_rules(), RETRIES, GAS_LIMIT)
.await
.expect("Failed to send transaction");
Ok(())
Expand All @@ -380,7 +377,7 @@ impl BridgeContractCounterparty for EthClient {
&self.rpc_provider,
);
let call = contract.abortBridgeTransfer(FixedBytes(bridge_transfer_id.0));
send_transaction(call, &send_tx_rules(), RETRIES, GAS_LIMIT)
send_transaction(call, &send_transaction_rules(), RETRIES, GAS_LIMIT)
.await
.expect("Failed to send transaction");
Ok(())
Expand Down
42 changes: 22 additions & 20 deletions protocol-units/bridge/chains/ethereum/src/event_logging.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::types::{EthAddress, EventName};
use crate::{EthChainEvent, Transaction};
use crate::EthChainEvent;
use alloy::dyn_abi::EventExt;
use alloy::eips::BlockNumberOrTag;
use alloy::primitives::{address, Address, LogData};
use alloy::primitives::{address, LogData};
use alloy::providers::{Provider, ProviderBuilder, RootProvider, WsConnect};
use alloy::rpc::types::{Filter, Log};
use alloy::{
Expand All @@ -21,6 +21,7 @@ use std::{pin::Pin, task::Poll};

use crate::types::{EthHash, COMPLETED_SELECT, INITIATED_SELECT, REFUNDED_SELECT};

#[allow(unused)]
pub struct EthInitiatorMonitoring<A, H> {
listener: UnboundedReceiver<EthChainEvent<A, H>>,
ws: RootProvider<PubSubFrontend>,
Expand All @@ -31,21 +32,21 @@ impl BridgeContractInitiatorMonitoring for EthInitiatorMonitoring<EthAddress, Et
type Hash = EthHash;
}

#[allow(unused)]
impl EthInitiatorMonitoring<EthAddress, EthHash> {
pub async fn run(
async fn run(
rpc_url: &str,
listener: UnboundedReceiver<EthChainEvent<EthAddress, EthHash>>,
signer_address: Address
) -> Result<Self, anyhow::Error> {
let ws = WsConnect::new(rpc_url);
let ws = ProviderBuilder::new().on_ws(ws).await?;
println!("Websocket connected");

//TODO: this should be an arg
let initiator_address = signer_address;
let initiator_address = address!("f39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
let filter = Filter::new()
.address(initiator_address)
//.event("BridgeTransferInitiated")
//.event("BridgeTransferCompleted");
.event("BridgeTransferInitiated(bytes32,address,bytes32,uint256)")
.event("BridgeTransferCompleted(bytes32,bytes32)")
.from_block(BlockNumberOrTag::Latest);

let sub = ws.subscribe_logs(&filter).await?;
Expand Down Expand Up @@ -101,6 +102,11 @@ impl Stream for EthInitiatorMonitoring<EthAddress, EthHash> {
bridge_transfer_id,
)))
}
SmartContractInitiatorEvent::RefundedBridgeTransfer(bridge_transfer_id) => {
return Poll::Ready(Some(BridgeContractInitiatorEvent::Refunded(
bridge_transfer_id,
)))
}
},
Err(e) => {
tracing::error!("Error in contract event: {:?}", e);
Expand Down Expand Up @@ -191,7 +197,7 @@ fn decode_log_data(
.ok_or_else(|| anyhow::anyhow!("Failed to decode BridgeTransferId"))?;
let initiator_address = decoded.indexed[1]
.as_address()
.map(|a| EthAddress(a))
.map(EthAddress)
.ok_or_else(|| anyhow::anyhow!("Failed to decode InitiatorAddress"))?;
let recipient_address = decoded.indexed[2]
.as_fixed_bytes()
Expand Down Expand Up @@ -219,35 +225,31 @@ fn decode_log_data(
amount,
};

return Ok(BridgeContractInitiatorEvent::Initiated(details));
Ok(BridgeContractInitiatorEvent::Initiated(details))
}
COMPLETED_SELECT => {
let bridge_transfer_id = decoded.indexed[0]
.as_fixed_bytes()
.map(coerce_bytes)
.ok_or_else(|| anyhow::anyhow!("Failed to decode BridgeTransferId"))?;

// We do nothing with the secret in the event here
return Ok(BridgeContractInitiatorEvent::Completed(BridgeTransferId(
bridge_transfer_id,
)));
Ok(BridgeContractInitiatorEvent::Completed(BridgeTransferId(bridge_transfer_id)))
}
REFUNDED_SELECT => {
let bridge_transfer_id = decoded.indexed[0]
.as_fixed_bytes()
.map(coerce_bytes)
.ok_or_else(|| anyhow::anyhow!("Failed to decode BridgeTransferId"))?;
return Ok(BridgeContractInitiatorEvent::Refunded(BridgeTransferId(
bridge_transfer_id,
)));

Ok(BridgeContractInitiatorEvent::Refunded(BridgeTransferId(bridge_transfer_id)))
}
_ => {
tracing::error!("Unknown event selector: {:x}", selector);
return Err(anyhow::anyhow!("failed to devode event selector"));
Err(anyhow::anyhow!("failed to decode event selector"))
}
};
}
} else {
tracing::error!("Failed to decode event selector");
return Err(anyhow::anyhow!("Failed to decode event selector"));
Err(anyhow::anyhow!("Failed to decode event selector"))
}
}
8 changes: 7 additions & 1 deletion protocol-units/bridge/chains/ethereum/src/event_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ use bridge_shared::{
use crate::types::{CompletedDetails, EthAddress};
use thiserror::Error;

#[allow(unused)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MoveCounterpartyEvent<A, H> {
LockedBridgeTransfer(LockDetails<A, H>),
CompletedBridgeTransfer(CompletedDetails<A, H>),
}

#[allow(unused)]
#[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum MoveCounterpartyError {
#[error("Transfer not found")]
Expand All @@ -22,6 +24,7 @@ pub enum MoveCounterpartyError {
InvalidHashLockPreImage,
}

#[allow(unused)]
#[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum EthInitiatorError {
#[error("Failed to initiate bridge transfer")]
Expand All @@ -32,6 +35,7 @@ pub enum EthInitiatorError {
InvalidHashLockPreImage,
}

#[allow(unused)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum EthChainEvent<A, H> {
InitiatorContractEvent(SCIResult<A, H>),
Expand All @@ -52,7 +56,9 @@ impl From<BridgeContractInitiatorEvent<EthAddress, [u8; 32]>>
BridgeContractInitiatorEvent::Completed(id) => EthChainEvent::InitiatorContractEvent(
Ok(SmartContractInitiatorEvent::CompletedBridgeTransfer(id)),
),
_ => unimplemented!(), // Refunded variant
BridgeContractInitiatorEvent::Refunded(id) => EthChainEvent::InitiatorContractEvent(
Ok(SmartContractInitiatorEvent::RefundedBridgeTransfer(id)),
),
}
}
}
5 changes: 3 additions & 2 deletions protocol-units/bridge/chains/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use types::CounterpartyCall;
use utils::RngSeededClone;

pub mod client;
pub mod event_logging;
pub mod event_types;
mod event_logging;
mod event_types;
pub mod types;
mod utils;

Expand All @@ -35,6 +35,7 @@ pub enum Transaction<A, H> {
Counterparty(CounterpartyCall<A, H>),
}

#[allow(unused)]
pub struct EthereumChain<A, H, R> {
pub name: String,
pub time: u64,
Expand Down
13 changes: 2 additions & 11 deletions protocol-units/bridge/chains/ethereum/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
use std::collections::HashMap;

use alloy::json_abi::Param;
use alloy::network::{Ethereum, EthereumWallet};
use alloy::primitives::{Address, FixedBytes};
use alloy::providers::fillers::{
ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller, WalletFiller,
};
use alloy::providers::RootProvider;
use alloy::pubsub::PubSubFrontend;
use alloy::rlp::{RlpDecodable, RlpEncodable};
use alloy::sol_types::SolEvent;
use alloy::transports::BoxTransport;
use bridge_shared::types::{
Amount, BridgeAddressType, BridgeHashType, BridgeTransferDetails, BridgeTransferId,
GenUniqueHash, HashLock, HashLockPreImage, InitiatorAddress, LockDetails, RecipientAddress,
TimeLock,
};
use bridge_shared::{
bridge_contracts::{BridgeContractCounterpartyError, BridgeContractInitiatorError},
bridge_monitoring::{BridgeContractCounterpartyEvent, BridgeContractInitiatorEvent},
Amount, BridgeTransferDetails, BridgeTransferId, HashLock, HashLockPreImage, InitiatorAddress,
LockDetails, RecipientAddress, TimeLock,
};
use futures::channel::mpsc::UnboundedReceiver;
use serde::{Deserialize, Serialize};

pub const INITIATED_SELECT: FixedBytes<32> =
Expand Down
24 changes: 0 additions & 24 deletions protocol-units/bridge/integration-tests/scripts/init_test.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ async fn test_eth_client_should_successfully_get_bridge_transfer_id() -> Result<
let rpc_url = "ws://localhost:8545";
let (_event_sender, event_receiver): (mpsc::UnboundedSender<_>, UnboundedReceiver<_>) = mpsc::unbounded();

let mut monitoring = EthInitiatorMonitoring::run(rpc_url, event_receiver, signer_address).await?;
//let mut monitoring = EthInitiatorMonitoring::run(rpc_url, event_receiver, signer_address).await?;

let recipient = harness.gen_aptos_account();
let hash_lock: [u8; 32] = keccak256("secret".to_string().as_bytes()).into();
Expand Down
29 changes: 15 additions & 14 deletions protocol-units/bridge/move-modules/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ version = "1.0.0"
authors = []

[addresses]
resource_addr = "0x92c5e407d5e13eb51ab95afd262e7d5223be49373489e88cc6dd4ff9d9a05779"
origin_addr = "0x7dc72e7296e4029142aba3e60612088d87573234828fa844c10ddeadb79f34fe"
atomic_bridge = "0x92c5e407d5e13eb51ab95afd262e7d5223be49373489e88cc6dd4ff9d9a05779"
moveth = "0x92c5e407d5e13eb51ab95afd262e7d5223be49373489e88cc6dd4ff9d9a05779"
master_minter = "0x92c5e407d5e13eb51ab95afd262e7d5223be49373489e88cc6dd4ff9d9a05779"
minter = "0x92c5e407d5e13eb51ab95afd262e7d5223be49373489e88cc6dd4ff9d9a05779"
admin = "0x92c5e407d5e13eb51ab95afd262e7d5223be49373489e88cc6dd4ff9d9a05779"
source_account = "0x7dc72e7296e4029142aba3e60612088d87573234828fa844c10ddeadb79f34fe"
resource_addr = "0xc3bb8488ab1a5815a9d543d7e41b0e0df46a7396f89b22821f07a4362f75ddc5"
origin_addr = "0xcafe"
atomic_bridge = "0xc3bb8488ab1a5815a9d543d7e41b0e0df46a7396f89b22821f07a4362f75ddc5"
moveth = "0xc3bb8488ab1a5815a9d543d7e41b0e0df46a7396f89b22821f07a4362f75ddc5"
master_minter = "0xc3bb8488ab1a5815a9d543d7e41b0e0df46a7396f89b22821f07a4362f75ddc5"
minter = "0xc3bb8488ab1a5815a9d543d7e41b0e0df46a7396f89b22821f07a4362f75ddc5"
admin = "0xc3bb8488ab1a5815a9d543d7e41b0e0df46a7396f89b22821f07a4362f75ddc5"
source_account = "0xc3bb8488ab1a5815a9d543d7e41b0e0df46a7396f89b22821f07a4362f75ddc5"
pauser = "0xdafe"
denylister = "0xcade"

[dev-addresses]
# moveth = "0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"0xbeef"
# atomic_bridge = "0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"0xfeef"
# master_minter = "0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"0xbab"
# minter = "0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"0xface"
# admin = "0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"0xad"
# moveth = "0xbeef"
# atomic_bridge = "0xfeef"
# master_minter = "0xbab"
# minter = "0xface"
# admin = "0xad"
# pauser = "_"
# denylister = "_"

Expand All @@ -30,4 +30,5 @@ git = "https://github.com/movementlabsxyz/aptos-core.git"
rev = "movement"
subdir = "aptos-move/framework/aptos-framework"

[dev-dependencies]
[dev-dependencies]

Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ module atomic_bridge::atomic_bridge_counterparty {
move_to(resource, bridge_transfer_store);
move_to(resource, bridge_config);
}



public fun lock_bridge_transfer_assets(
caller: &signer,
Expand Down Expand Up @@ -232,4 +230,4 @@ module atomic_bridge::atomic_bridge_counterparty {
assert!(transfer_details.hash_lock == hash_lock, 3);
assert!(transfer_details.initiator == initiator, 4);
}
}
}
2 changes: 0 additions & 2 deletions protocol-units/bridge/shared/src/bridge_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ impl BridgeContractInitiatorError {
pub enum BridgeContractCounterpartyError {
#[error("Failed to lock bridge transfer assets")]
LockTransferAssetsError,
#[error("Failed to serialize or deserialize")]
SerializationError,
#[error("Failed to complete bridge transfer")]
CompleteTransferError,
#[error("Failed to abort bridge transfer")]
Expand Down

0 comments on commit 103b48d

Please sign in to comment.