Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into re…
Browse files Browse the repository at this point in the history
…f-network-stack

Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Sep 27, 2023
2 parents ec60bf9 + 6370fa5 commit c504939
Show file tree
Hide file tree
Showing 77 changed files with 4,835 additions and 814 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ jobs:
uses: ./.github/actions/cargo-cache

- name: Test
run: cargo test --test 'mm2_tests_main' --no-fail-fast
run: |
wget -O - https://raw.githubusercontent.com/KomodoPlatform/komodo/master/zcutil/fetch-params-alt.sh | bash
cargo test --test 'mm2_tests_main' --no-fail-fast
# https://docs.github.com/en/actions/learn-github-actions/usage-limits-billing-and-administration#usage-limits
# https://github.com/KomodoPlatform/atomicDEX-API/actions/runs/4419618128/jobs/7748266141#step:4:1790
Expand Down Expand Up @@ -161,7 +163,10 @@ jobs:
uses: ./.github/actions/cargo-cache

- name: Test
run: cargo test --test 'mm2_tests_main' --no-fail-fast
run: |
Invoke-WebRequest -Uri https://github.com/KomodoPlatform/komodo/raw/d456be35acd1f8584e1e4f971aea27bd0644d5c5/zcutil/wget64.exe -OutFile \wget64.exe
Invoke-WebRequest -Uri https://raw.githubusercontent.com/KomodoPlatform/komodo/master/zcutil/fetch-params-alt.bat -OutFile \cmd.bat && \cmd.bat
cargo test --test 'mm2_tests_main' --no-fail-fast
docker-tests:
timeout-minutes: 90
Expand Down
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
## v1.0.7-beta - 2023-09-08
**Features:**
- Trading Protocol Upgrade [#1895](https://github.com/KomodoPlatform/atomicDEX-API/issues/1895)
- SwapOpsV2 trait was added containing methods of the new protocol (WIP) in [#1927](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1927)
- SwapOpsV2 was implemented for UtxoStandardCoin in [#1927](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1927)
- Dockerized integration tests added, sending and spending/refunding "dex fee + premium" UTXO in [#1927](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1927)
- HD Wallet [#1838](https://github.com/KomodoPlatform/komodo-defi-framework/issues/1838)
- Global enabling of an account'/change/address_index path for all coins using hd_account_id config parameter was replaced by enable_hd which is a bool that defaults to false in [#1933](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1933)
- path_to_address parameter was added to coins activation requests to set the default account'/change/address_index path that will be used for swaps. If not provided, the default will be 0'/0/0 in [#1933](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1933)
- HD withdrawal from any account'/change/address_index path was implemented for UTXO, EVM and Tendermint coins in [#1933](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1933)
- Pirate Integration [#927](https://github.com/KomodoPlatform/komodo-defi-framework/issues/927)
- ARRR synchronization now supports using a specific start date. This allows users to specify a specific date as the starting point for synchronization as a substitute for the checkpoint block from config or syncing from the first block [#1922](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1922)

**Enhancements/Fixes:**
- Adex-CLI [#1682](https://github.com/KomodoPlatform/atomicDEX-API/issues/1682)
- The file permissions of the cli config file is now set to 660 in unix to disallow reading by other users [#1913](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1913)
- Activation types have been introduced to prevent malicious substitution of them in the activation scheme file [#1912](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1912)
- HTTPS connection support was added in [#1910](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1910)
- Activation scheme was changed so the related data types were refactored to be fit for it in [#1938](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1938)
- PoSV coins withdrawal issue was fixed. The issue was a missing n_time field in the generated transaction. The fix now correctly considers when n_time is required, and the rawtransaction can be broadcasted [#1925](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1925)
- Latest relayer channel is now used for tendermint test [#1929](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1929)
- Price urls were updated in [#1928](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1928)
- NFT transactions that transfer multiple NFT tokens were fixed in db, log_index is now used as part of the transfers history table primary key [#1926](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1926)
- State machine was refactored as a preparation step for StorableStateMachine pattern extension in [#1927](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1927)
- A fix was introduced to use kmd rewards for fees if change + interest is below dust threshold in [#1944](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1944)
- Debug info was removed from release binary to reduce the file size in [#1954](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1954)
- Failing tests due to BCHD were ignored in [#1955](https://github.com/KomodoPlatform/komodo-defi-framework/pull/1955)


## v1.0.6-beta - 2023-07-24

**Features:**
Expand Down
14 changes: 14 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ members = [
"mm2src/mm2_number",
"mm2src/mm2_p2p",
"mm2src/mm2_rpc",
"mm2src/mm2_state_machine",
"mm2src/mm2_test_helpers",
"mm2src/rpc_task",
"mm2src/trezor",
Expand All @@ -53,7 +54,7 @@ resolver = "2"
debug = 0
debug-assertions = false
opt-level = 3
# strip = true
strip = true
codegen-units = 1
# lto = true
panic = "abort"
Expand Down
17 changes: 14 additions & 3 deletions docs/DEV_ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
[Unix/Linux](https://github.com/KomodoPlatform/komodo/blob/master/zcutil/fetch-params.sh)
5. Create `.env.client` file with the following content
```
PASSPHRASE=spice describe gravity federal blast come thank unfair canal monkey style afraid
ALICE_PASSPHRASE=spice describe gravity federal blast come thank unfair canal monkey style afraid
```
6. Create `.env.seed` file with the following content
```
PASSPHRASE=also shoot benefit prefer juice shell elder veteran woman mimic image kidney
BOB_PASSPHRASE=also shoot benefit prefer juice shell elder veteran woman mimic image kidney
```
7. MacOS specific: run script (required after each reboot)
```shell
Expand Down Expand Up @@ -52,7 +52,7 @@
export BOB_PASSPHRASE="also shoot benefit prefer juice shell elder veteran woman mimic image kidney"
export ALICE_PASSPHRASE="spice describe gravity federal blast come thank unfair canal monkey style afraid"
```
6. Run WASM tests
5. Run WASM tests
- for Linux users:
```
wasm-pack test --firefox --headless mm2src/mm2_main
Expand All @@ -66,5 +66,16 @@
CC=/opt/homebrew/opt/llvm/bin/clang AR=/opt/homebrew/opt/llvm/bin/llvm-ar wasm-pack test --firefox --headless mm2src/mm2_main
```
Please note `CC` and `AR` must be specified in the same line as `wasm-pack test mm2src/mm2_main`.
#### Running specific WASM tests with Cargo</br>
- Install `wasm-bindgen-cli`: </br>
Make sure you have wasm-bindgen-cli installed with a version that matches the one specified in your Cargo.toml file.
You can install it using Cargo with the following command:
```
cargo install -f wasm-bindgen-cli --version <wasm-bindgen-version>
```
- Run
```
cargo test --target wasm32-unknown-unknown --package coins --lib utxo::utxo_block_header_storage::wasm::indexeddb_block_header_storage
```

PS If you notice that this guide is outdated, please submit a PR.
1 change: 1 addition & 0 deletions mm2src/coins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ mm2_metrics = { path = "../mm2_metrics" }
mm2_net = { path = "../mm2_net" }
mm2_number = { path = "../mm2_number"}
mm2_rpc = { path = "../mm2_rpc" }
mm2_state_machine = { path = "../mm2_state_machine" }
mocktopus = "0.8.0"
num-traits = "0.2"
parking_lot = { version = "0.12.0", features = ["nightly"] }
Expand Down
17 changes: 15 additions & 2 deletions mm2src/coins/coin_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,36 @@ use crate::{eth::Web3RpcError, my_tx_history_v2::MyTxHistoryErrorV2, utxo::rpc_c
use futures01::Future;
use mm2_err_handle::prelude::MmError;
use spv_validation::helpers_validation::SPVError;
use std::num::TryFromIntError;

/// Helper type used as result for swap payment validation function(s)
pub type ValidatePaymentFut<T> = Box<dyn Future<Item = T, Error = MmError<ValidatePaymentError>> + Send>;

/// Enum covering possible error cases of swap payment validation
#[derive(Debug, Display)]
pub enum ValidatePaymentError {
/// Should be used to indicate internal MM2 state problems (e.g., DB errors, etc.).
InternalError(String),
// Problem with deserializing the transaction, or one of the transaction parts is invalid.
/// Problem with deserializing the transaction, or one of the transaction parts is invalid.
TxDeserializationError(String),
/// One of the input parameters is invalid.
InvalidParameter(String),
/// Coin's RPC returned unexpected/invalid response during payment validation.
InvalidRpcResponse(String),
/// Payment transaction doesn't exist on-chain.
TxDoesNotExist(String),
/// SPV client error.
SPVError(SPVError),
/// Payment transaction is in unexpected state. E.g., `Uninitialized` instead of `Sent` for ETH payment.
UnexpectedPaymentState(String),
/// Transport (RPC) error.
Transport(String),
// Transaction has wrong properties, for example, it has been sent to a wrong address
/// Transaction has wrong properties, for example, it has been sent to a wrong address.
WrongPaymentTx(String),
/// Indicates error during watcher reward calculation.
WatcherRewardError(String),
/// Input payment timelock overflows the type used by specific coin.
TimelockOverflow(TryFromIntError),
}

impl From<rlp::DecoderError> for ValidatePaymentError {
Expand Down
25 changes: 18 additions & 7 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use serde_json::{self as json, Value as Json};
use serialization::{CompactInteger, Serializable, Stream};
use sha3::{Digest, Keccak256};
use std::collections::HashMap;
use std::convert::TryFrom;
use std::convert::{TryFrom, TryInto};
use std::ops::Deref;
#[cfg(not(target_arch = "wasm32"))] use std::path::PathBuf;
use std::str::FromStr;
Expand Down Expand Up @@ -1137,7 +1137,10 @@ impl SwapOps for EthCoin {
&self,
if_my_payment_sent_args: CheckIfMyPaymentSentArgs,
) -> Box<dyn Future<Item = Option<TransactionEnum>, Error = String> + Send> {
let id = self.etomic_swap_id(if_my_payment_sent_args.time_lock, if_my_payment_sent_args.secret_hash);
let id = self.etomic_swap_id(
try_fus!(if_my_payment_sent_args.time_lock.try_into()),
if_my_payment_sent_args.secret_hash,
);
let swap_contract_address = try_fus!(if_my_payment_sent_args.swap_contract_address.try_to_address());
let selfi = self.clone();
let from_block = if_my_payment_sent_args.search_from_block;
Expand Down Expand Up @@ -1420,7 +1423,7 @@ impl WatcherOps for EthCoin {
fn create_maker_payment_spend_preimage(
&self,
maker_payment_tx: &[u8],
_time_lock: u32,
_time_lock: u64,
_maker_pub: &[u8],
_secret_hash: &[u8],
_swap_unique_data: &[u8],
Expand All @@ -1435,7 +1438,7 @@ impl WatcherOps for EthCoin {
fn create_taker_payment_refund_preimage(
&self,
taker_payment_tx: &[u8],
_time_lock: u32,
_time_lock: u64,
_maker_pub: &[u8],
_secret_hash: &[u8],
_swap_contract_address: &Option<BytesJson>,
Expand Down Expand Up @@ -1476,9 +1479,13 @@ impl WatcherOps for EthCoin {
.map_to_mm(|err| ValidatePaymentError::TxDeserializationError(err.to_string())));
let sender = try_f!(addr_from_raw_pubkey(&input.taker_pub).map_to_mm(ValidatePaymentError::InvalidParameter));
let receiver = try_f!(addr_from_raw_pubkey(&input.maker_pub).map_to_mm(ValidatePaymentError::InvalidParameter));
let time_lock = try_f!(input
.time_lock
.try_into()
.map_to_mm(ValidatePaymentError::TimelockOverflow));

let selfi = self.clone();
let swap_id = selfi.etomic_swap_id(input.time_lock, &input.secret_hash);
let swap_id = selfi.etomic_swap_id(time_lock, &input.secret_hash);
let secret_hash = if input.secret_hash.len() == 32 {
ripemd160(&input.secret_hash).to_vec()
} else {
Expand Down Expand Up @@ -3023,7 +3030,7 @@ impl EthCoin {
fn send_hash_time_locked_payment(&self, args: SendPaymentArgs<'_>) -> EthTxFut {
let receiver_addr = try_tx_fus!(addr_from_raw_pubkey(args.other_pubkey));
let swap_contract_address = try_tx_fus!(args.swap_contract_address.try_to_address());
let id = self.etomic_swap_id(args.time_lock, args.secret_hash);
let id = self.etomic_swap_id(try_tx_fus!(args.time_lock.try_into()), args.secret_hash);
let trade_amount = try_tx_fus!(wei_from_big_decimal(&args.amount, self.decimals));

let time_lock = U256::from(args.time_lock);
Expand Down Expand Up @@ -3882,9 +3889,13 @@ impl EthCoin {
try_f!(SignedEthTx::new(unsigned)
.map_to_mm(|err| ValidatePaymentError::TxDeserializationError(err.to_string())));
let sender = try_f!(addr_from_raw_pubkey(&input.other_pub).map_to_mm(ValidatePaymentError::InvalidParameter));
let time_lock = try_f!(input
.time_lock
.try_into()
.map_to_mm(ValidatePaymentError::TimelockOverflow));

let selfi = self.clone();
let swap_id = selfi.etomic_swap_id(input.time_lock, &input.secret_hash);
let swap_id = selfi.etomic_swap_id(time_lock, &input.secret_hash);
let decimals = self.decimals;
let secret_hash = if input.secret_hash.len() == 32 {
ripemd160(&input.secret_hash).to_vec()
Expand Down
12 changes: 6 additions & 6 deletions mm2src/coins/eth/eth_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::IguanaPrivKey;
use common::{block_on, now_sec_u32, wait_until_sec};
use common::{block_on, now_sec, wait_until_sec};
use crypto::privkey::key_pair_from_seed;
use ethkey::{Generator, Random};
use mm2_core::mm_ctx::{MmArc, MmCtxBuilder};
Expand Down Expand Up @@ -60,7 +60,7 @@ pub fn jst_distributor() -> EthCoin {
"urls": ETH_DEV_NODES,
"swap_contract_address": ETH_DEV_SWAP_CONTRACT,
});
let seed = get_passphrase!(".env.client", "BOB_PASSPHRASE").unwrap();
let seed = get_passphrase!(".env.seed", "BOB_PASSPHRASE").unwrap();
let keypair = key_pair_from_seed(&seed).unwrap();
let priv_key_policy = PrivKeyBuildPolicy::IguanaPrivKey(keypair.private().secret);
block_on(eth_coin_from_conf_and_request(
Expand Down Expand Up @@ -343,7 +343,7 @@ fn send_and_refund_erc20_payment() {
abortable_system: AbortableQueue::default(),
}));

let time_lock = now_sec_u32() - 200;
let time_lock = now_sec() - 200;
let secret_hash = &[1; 20];
let maker_payment_args = SendPaymentArgs {
time_lock_duration: 0,
Expand All @@ -360,7 +360,7 @@ fn send_and_refund_erc20_payment() {
let payment = coin.send_maker_payment(maker_payment_args).wait().unwrap();
log!("{:?}", payment);

let swap_id = coin.etomic_swap_id(time_lock, secret_hash);
let swap_id = coin.etomic_swap_id(time_lock.try_into().unwrap(), secret_hash);
let status = block_on(
coin.payment_status(
Address::from_str(ETH_DEV_SWAP_CONTRACT).unwrap(),
Expand Down Expand Up @@ -429,7 +429,7 @@ fn send_and_refund_eth_payment() {
abortable_system: AbortableQueue::default(),
}));

let time_lock = now_sec_u32() - 200;
let time_lock = now_sec() - 200;
let secret_hash = &[1; 20];
let send_maker_payment_args = SendPaymentArgs {
time_lock_duration: 0,
Expand All @@ -447,7 +447,7 @@ fn send_and_refund_eth_payment() {

log!("{:?}", payment);

let swap_id = coin.etomic_swap_id(time_lock, secret_hash);
let swap_id = coin.etomic_swap_id(time_lock.try_into().unwrap(), secret_hash);
let status = block_on(
coin.payment_status(
Address::from_str(ETH_DEV_SWAP_CONTRACT).unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions mm2src/coins/lightning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ impl WatcherOps for LightningCoin {
fn create_maker_payment_spend_preimage(
&self,
_maker_payment_tx: &[u8],
_time_lock: u32,
_time_lock: u64,
_maker_pub: &[u8],
_secret_hash: &[u8],
_swap_unique_data: &[u8],
Expand All @@ -974,7 +974,7 @@ impl WatcherOps for LightningCoin {
fn create_taker_payment_refund_preimage(
&self,
_taker_payment_tx: &[u8],
_time_lock: u32,
_time_lock: u64,
_maker_pub: &[u8],
_secret_hash: &[u8],
_swap_contract_address: &Option<BytesJson>,
Expand Down
Loading

0 comments on commit c504939

Please sign in to comment.