Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into taker-failed-swaps-mar…
Browse files Browse the repository at this point in the history
…ked-successful
  • Loading branch information
laruh committed Sep 5, 2024
2 parents 5c47ef0 + ffed860 commit 3117c5f
Show file tree
Hide file tree
Showing 44 changed files with 2,643 additions and 1,888 deletions.
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ codegen-units = 1
# lto = true
panic = "abort"

[profile.test]
# required to avoid a long running process of librustcash additional chain validation that is enabled with debug assertions
debug-assertions = false

[profile.dev]
opt-level = 0
debug = 1
Expand All @@ -74,4 +70,4 @@ incremental = true
codegen-units = 256

[profile.release.package.mocktopus]
opt-level = 1 # TODO: MIR fails on optimizing this dependency, remove that..
opt-level = 1 # TODO: MIR fails on optimizing this dependency, remove that..
11 changes: 8 additions & 3 deletions mm2src/coins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ enable-solana = [
]
enable-sia = [
"dep:reqwest",
"blake2b_simd"
"dep:blake2b_simd",
"dep:sia-rust"
]
default = []
run-docker-tests = []
Expand All @@ -41,13 +42,14 @@ byteorder = "1.3"
bytes = "0.4"
cfg-if = "1.0"
chain = { path = "../mm2_bitcoin/chain" }
chrono = { version = "0.4.23", "features" = ["serde"] }
common = { path = "../common" }
cosmrs = { version = "0.14.0", default-features = false }
crossbeam = "0.8"
crypto = { path = "../crypto" }
db_common = { path = "../db_common" }
derive_more = "0.99"
ed25519-dalek = "1.0.1"
ed25519-dalek = { version = "1.0.1", features = ["serde"] }
enum_derives = { path = "../derives/enum_derives" }
ethabi = { version = "17.0.0" }
ethcore-transaction = { git = "https://github.com/KomodoPlatform/mm2-parity-ethereum.git", rev = "mm2-v2.1.1" }
Expand All @@ -69,13 +71,14 @@ jsonrpc-core = "18.0.0"
keys = { path = "../mm2_bitcoin/keys" }
lazy_static = "1.4"
libc = "0.2"
nom = "6.1.2"
mm2_core = { path = "../mm2_core" }
mm2_err_handle = { path = "../mm2_err_handle" }
mm2_event_stream = { path = "../mm2_event_stream" }
mm2_git = { path = "../mm2_git" }
mm2_io = { path = "../mm2_io" }
mm2_metrics = { path = "../mm2_metrics" }
mm2_net = { path = "../mm2_net" }
mm2_net = { path = "../mm2_net", features = ["p2p"] }
mm2_number = { path = "../mm2_number"}
mm2_rpc = { path = "../mm2_rpc" }
mm2_state_machine = { path = "../mm2_state_machine" }
Expand All @@ -101,8 +104,10 @@ ser_error_derive = { path = "../derives/ser_error_derive" }
serde = "1.0"
serde_derive = "1.0"
serde_json = { version = "1", features = ["preserve_order", "raw_value"] }
serde_with = "1.14.0"
serialization = { path = "../mm2_bitcoin/serialization" }
serialization_derive = { path = "../mm2_bitcoin/serialization_derive" }
sia-rust = { git = "https://github.com/KomodoPlatform/sia-rust", rev = "9f188b80b3213bcb604e7619275251ce08fae808", optional = true }
spv_validation = { path = "../mm2_bitcoin/spv_validation" }
sha2 = "0.10"
sha3 = "0.9"
Expand Down
20 changes: 15 additions & 5 deletions mm2src/coins/coin_errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::eth::nft_swap_v2::errors::{Erc721FunctionError, HtlcParamsError, PaymentStatusErr, PrepareTxDataError};
use crate::eth::eth_swap_v2::{PaymentStatusErr, ValidatePaymentV2Err};
use crate::eth::nft_swap_v2::errors::{Erc721FunctionError, HtlcParamsError, PrepareTxDataError};
use crate::eth::{EthAssocTypesError, EthNftAssocTypesError, Web3RpcError};
use crate::{utxo::rpc_clients::UtxoRpcError, NumConversError, UnexpectedDerivationMethod};
use enum_derives::EnumFromStringify;
Expand Down Expand Up @@ -50,6 +51,7 @@ pub enum ValidatePaymentError {
TimelockOverflow(TryFromIntError),
#[display(fmt = "Nft Protocol is not supported yet!")]
NftProtocolNotSupported,
InvalidData(String),
}

impl From<SPVError> for ValidatePaymentError {
Expand Down Expand Up @@ -84,9 +86,8 @@ impl From<PaymentStatusErr> for ValidatePaymentError {
fn from(err: PaymentStatusErr) -> Self {
match err {
PaymentStatusErr::Transport(e) => Self::Transport(e),
PaymentStatusErr::AbiError(e)
| PaymentStatusErr::Internal(e)
| PaymentStatusErr::TxDeserializationError(e) => Self::InternalError(e),
PaymentStatusErr::ABIError(e) | PaymentStatusErr::Internal(e) => Self::InternalError(e),
PaymentStatusErr::InvalidData(e) => Self::InvalidData(e),
}
}
}
Expand All @@ -95,7 +96,16 @@ impl From<HtlcParamsError> for ValidatePaymentError {
fn from(err: HtlcParamsError) -> Self {
match err {
HtlcParamsError::WrongPaymentTx(e) => ValidatePaymentError::WrongPaymentTx(e),
HtlcParamsError::TxDeserializationError(e) => ValidatePaymentError::TxDeserializationError(e),
HtlcParamsError::ABIError(e) | HtlcParamsError::InvalidData(e) => ValidatePaymentError::InvalidData(e),
}
}
}

impl From<ValidatePaymentV2Err> for ValidatePaymentError {
fn from(err: ValidatePaymentV2Err) -> Self {
match err {
ValidatePaymentV2Err::UnexpectedPaymentState(e) => ValidatePaymentError::UnexpectedPaymentState(e),
ValidatePaymentV2Err::WrongPaymentTx(e) => ValidatePaymentError::WrongPaymentTx(e),
}
}
}
Expand Down
100 changes: 78 additions & 22 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ mod eip1559_gas_fee;
pub(crate) use eip1559_gas_fee::FeePerGasEstimated;
use eip1559_gas_fee::{BlocknativeGasApiCaller, FeePerGasSimpleEstimator, GasApiConfig, GasApiProvider,
InfuraGasApiCaller};
mod eth_swap_v2;
pub(crate) mod eth_swap_v2;

/// https://github.com/artemii235/etomic-swap/blob/master/contracts/EtomicSwap.sol
/// Dev chain (195.201.137.5:8565) contract address: 0x83965C539899cC0F918552e5A26915de40ee8852
Expand Down Expand Up @@ -827,9 +827,18 @@ impl EthCoinImpl {
/// The id used to differentiate payments on Etomic swap smart contract
pub(crate) fn etomic_swap_id(&self, time_lock: u32, secret_hash: &[u8]) -> Vec<u8> {
let timelock_bytes = time_lock.to_le_bytes();
self.generate_etomic_swap_id(&timelock_bytes, secret_hash)
}

let mut input = Vec::with_capacity(timelock_bytes.len() + secret_hash.len());
input.extend_from_slice(&timelock_bytes);
/// The id used to differentiate payments on Etomic swap v2 smart contracts
pub(crate) fn etomic_swap_id_v2(&self, time_lock: u64, secret_hash: &[u8]) -> Vec<u8> {
let timelock_bytes = time_lock.to_le_bytes();
self.generate_etomic_swap_id(&timelock_bytes, secret_hash)
}

fn generate_etomic_swap_id(&self, time_lock_bytes: &[u8], secret_hash: &[u8]) -> Vec<u8> {
let mut input = Vec::with_capacity(time_lock_bytes.len() + secret_hash.len());
input.extend_from_slice(time_lock_bytes);
input.extend_from_slice(secret_hash);
sha256(&input).to_vec()
}
Expand Down Expand Up @@ -7031,32 +7040,38 @@ impl Eip1559Ops for EthCoin {

#[async_trait]
impl TakerCoinSwapOpsV2 for EthCoin {
/// Wrapper for [EthCoin::send_taker_funding_impl]
async fn send_taker_funding(&self, args: SendTakerFundingArgs<'_>) -> Result<Self::Tx, TransactionErr> {
self.send_taker_funding_impl(args).await
}

async fn validate_taker_funding(&self, _args: ValidateTakerFundingArgs<'_, Self>) -> ValidateSwapV2TxResult {
todo!()
/// Wrapper for [EthCoin::validate_taker_funding_impl]
async fn validate_taker_funding(&self, args: ValidateTakerFundingArgs<'_, Self>) -> ValidateSwapV2TxResult {
self.validate_taker_funding_impl(args).await
}

async fn refund_taker_funding_timelock(&self, _args: RefundPaymentArgs<'_>) -> Result<Self::Tx, TransactionErr> {
todo!()
async fn refund_taker_funding_timelock(
&self,
args: RefundTakerPaymentArgs<'_>,
) -> Result<Self::Tx, TransactionErr> {
self.refund_taker_payment_with_timelock_impl(args).await
}

async fn refund_taker_funding_secret(
&self,
_args: RefundFundingSecretArgs<'_, Self>,
args: RefundFundingSecretArgs<'_, Self>,
) -> Result<Self::Tx, TransactionErr> {
todo!()
self.refund_taker_funding_secret_impl(args).await
}

/// Wrapper for [EthCoin::search_for_taker_funding_spend_impl]
async fn search_for_taker_funding_spend(
&self,
_tx: &Self::Tx,
tx: &Self::Tx,
_from_block: u64,
_secret_hash: &[u8],
) -> Result<Option<FundingTxSpend<Self>>, SearchForFundingSpendErr> {
todo!()
self.search_for_taker_funding_spend_impl(tx).await
}

/// Eth doesnt have preimages
Expand All @@ -7080,18 +7095,21 @@ impl TakerCoinSwapOpsV2 for EthCoin {
Ok(())
}

/// Eth doesnt use multisig
/// Wrapper for [EthCoin::taker_payment_approve]
async fn sign_and_send_taker_funding_spend(
&self,
_preimage: &TxPreimageWithSig<Self>,
_args: &GenTakerFundingSpendArgs<'_, Self>,
args: &GenTakerFundingSpendArgs<'_, Self>,
_swap_unique_data: &[u8],
) -> Result<Self::Tx, TransactionErr> {
todo!()
self.taker_payment_approve(args).await
}

async fn refund_combined_taker_payment(&self, _args: RefundPaymentArgs<'_>) -> Result<Self::Tx, TransactionErr> {
todo!()
async fn refund_combined_taker_payment(
&self,
args: RefundTakerPaymentArgs<'_>,
) -> Result<Self::Tx, TransactionErr> {
self.refund_taker_payment_with_timelock_impl(args).await
}

/// Eth doesnt have preimages
Expand All @@ -7115,23 +7133,25 @@ impl TakerCoinSwapOpsV2 for EthCoin {
Ok(())
}

/// Wrapper for [EthCoin::sign_and_broadcast_taker_payment_spend_impl]
async fn sign_and_broadcast_taker_payment_spend(
&self,
_preimage: &TxPreimageWithSig<Self>,
_gen_args: &GenTakerPaymentSpendArgs<'_, Self>,
_secret: &[u8],
gen_args: &GenTakerPaymentSpendArgs<'_, Self>,
secret: &[u8],
_swap_unique_data: &[u8],
) -> Result<Self::Tx, TransactionErr> {
todo!()
self.sign_and_broadcast_taker_payment_spend_impl(gen_args, secret).await
}

/// Wrapper for [EthCoin::wait_for_taker_payment_spend_impl]
async fn wait_for_taker_payment_spend(
&self,
_taker_payment: &Self::Tx,
taker_payment: &Self::Tx,
_from_block: u64,
_wait_until: u64,
wait_until: u64,
) -> MmResult<Self::Tx, WaitForTakerPaymentSpendError> {
todo!()
self.wait_for_taker_payment_spend_impl(taker_payment, wait_until).await
}
}

Expand Down Expand Up @@ -7162,3 +7182,39 @@ impl CommonSwapOpsV2 for EthCoin {
self.derive_htlc_pubkey_v2(swap_unique_data).to_bytes()
}
}

#[cfg(all(feature = "for-tests", not(target_arch = "wasm32")))]
impl EthCoin {
pub async fn set_coin_type(&self, new_coin_type: EthCoinType) -> EthCoin {
let coin = EthCoinImpl {
ticker: self.ticker.clone(),
coin_type: new_coin_type,
priv_key_policy: self.priv_key_policy.clone(),
derivation_method: Arc::clone(&self.derivation_method),
sign_message_prefix: self.sign_message_prefix.clone(),
swap_contract_address: self.swap_contract_address,
swap_v2_contracts: self.swap_v2_contracts,
fallback_swap_contract: self.fallback_swap_contract,
contract_supports_watchers: self.contract_supports_watchers,
web3_instances: AsyncMutex::new(self.web3_instances.lock().await.clone()),
decimals: self.decimals,
history_sync_state: Mutex::new(self.history_sync_state.lock().unwrap().clone()),
required_confirmations: AtomicU64::new(
self.required_confirmations.load(std::sync::atomic::Ordering::SeqCst),
),
swap_txfee_policy: Mutex::new(self.swap_txfee_policy.lock().unwrap().clone()),
max_eth_tx_type: self.max_eth_tx_type,
ctx: self.ctx.clone(),
chain_id: self.chain_id,
trezor_coin: self.trezor_coin.clone(),
logs_block_range: self.logs_block_range,
address_nonce_locks: Arc::clone(&self.address_nonce_locks),
erc20_tokens_infos: Arc::clone(&self.erc20_tokens_infos),
nfts_infos: Arc::clone(&self.nfts_infos),
platform_fee_estimator_state: Arc::clone(&self.platform_fee_estimator_state),
gas_limit: EthGasLimit::default(),
abortable_system: self.abortable_system.create_subsystem().unwrap(),
};
EthCoin(Arc::new(coin))
}
}
Loading

0 comments on commit 3117c5f

Please sign in to comment.