Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[r2r] Watcher rewards for ETH swaps #1658

Merged
merged 27 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
384b143
add watcher_validate_taker_payment unit tests for eth, erc20 and utxo
caglaryucekaya Jan 20, 2023
0855843
reuse ethereum validate_fee method for watcher validations
caglaryucekaya Jan 22, 2023
fe4d410
add contract support parameter to eth coin activation parameters
caglaryucekaya Jan 27, 2023
966bdd3
fix lock_duration overflow bug by adding validation
caglaryucekaya Jan 29, 2023
36ce113
use the refactored etomic swap contract
caglaryucekaya Jan 30, 2023
19c22a8
fix a watcher bug in wait_for_htlc_tx_spend and add a test case
caglaryucekaya Jan 30, 2023
c4dea58
change swap contract address and abi
caglaryucekaya Feb 4, 2023
5d1d029
remove the contract_supports_watchers method
caglaryucekaya Feb 7, 2023
79366f9
add watcher_reward to negotiaton data
caglaryucekaya Feb 8, 2023
4b8c6f5
add watcher reward functionality
caglaryucekaya Feb 15, 2023
3ceae5f
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya Feb 15, 2023
4ca9d6e
fix merge conflicts
caglaryucekaya Feb 15, 2023
dc73825
remove log file
caglaryucekaya Feb 15, 2023
2958563
remove watcher reward related parts from negotiation data
caglaryucekaya Feb 15, 2023
601c2a8
disable the watcher rewards
caglaryucekaya Feb 15, 2023
38f9be0
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya Feb 16, 2023
bb4ecbb
small fixes
caglaryucekaya Feb 16, 2023
b287ba4
disable watcher rewards
caglaryucekaya Feb 16, 2023
69f1f0f
remove log file
caglaryucekaya Feb 22, 2023
a0ed8f1
minor fixes
caglaryucekaya Feb 22, 2023
0d7e859
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya Feb 22, 2023
5df9858
add test case for multiple watchers spending the same payment
caglaryucekaya Feb 23, 2023
c52c2ca
use serde default for contract_supports_watchers field
caglaryucekaya Feb 23, 2023
efbfdc2
use multiple attempts to get gas price for watcher rewards
caglaryucekaya Feb 23, 2023
8502034
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya Feb 23, 2023
3578aa4
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya Feb 27, 2023
5ea8f3c
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya Mar 6, 2023
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
950 changes: 488 additions & 462 deletions mm2src/coins/eth.rs

Large diffs are not rendered by default.

68 changes: 48 additions & 20 deletions mm2src/coins/eth/eth_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ fn eth_coin_for_test(
priv_key_policy: key_pair.into(),
swap_contract_address: Address::from_str("0x7Bc1bBDD6A0a722fC9bffC49c921B685ECB84b94").unwrap(),
fallback_swap_contract,
contract_supports_watchers: false,
ticker,
web3_instances: vec![Web3Instance {
web3: web3.clone(),
Expand Down Expand Up @@ -232,6 +233,7 @@ fn send_and_refund_erc20_payment() {
priv_key_policy: key_pair.into(),
swap_contract_address: Address::from_str("0x7Bc1bBDD6A0a722fC9bffC49c921B685ECB84b94").unwrap(),
fallback_swap_contract: None,
contract_supports_watchers: false,
web3_instances: vec![Web3Instance {
web3: web3.clone(),
is_parity: true,
Expand All @@ -250,7 +252,7 @@ fn send_and_refund_erc20_payment() {
erc20_tokens_infos: Default::default(),
abortable_system: AbortableQueue::default(),
}));
let maker_payment_args = SendMakerPaymentArgs {
let maker_payment_args = SendPaymentArgs {
time_lock_duration: 0,
time_lock: (now_ms() / 1000) as u32 - 200,
other_pubkey: &DEX_FEE_ADDR_RAW_PUBKEY,
Expand All @@ -259,19 +261,21 @@ fn send_and_refund_erc20_payment() {
swap_contract_address: &coin.swap_contract_address(),
swap_unique_data: &[],
payment_instructions: &None,
watcher_reward: None,
};
let payment = coin.send_maker_payment(maker_payment_args).wait().unwrap();
log!("{:?}", payment);

block_on(Timer::sleep(60.));

let maker_refunds_payment_args = SendMakerRefundsPaymentArgs {
let maker_refunds_payment_args = RefundPaymentArgs {
payment_tx: &payment.tx_hex(),
time_lock: (now_ms() / 1000) as u32 - 200,
other_pubkey: &DEX_FEE_ADDR_RAW_PUBKEY,
secret_hash: &[1; 20],
swap_contract_address: &coin.swap_contract_address(),
swap_unique_data: &[],
watcher_reward: false,
};
let refund = coin
.send_maker_refunds_payment(maker_refunds_payment_args)
Expand Down Expand Up @@ -299,6 +303,7 @@ fn send_and_refund_eth_payment() {
priv_key_policy: key_pair.into(),
swap_contract_address: Address::from_str("0x7Bc1bBDD6A0a722fC9bffC49c921B685ECB84b94").unwrap(),
fallback_swap_contract: None,
contract_supports_watchers: false,
web3_instances: vec![Web3Instance {
web3: web3.clone(),
is_parity: true,
Expand All @@ -317,7 +322,7 @@ fn send_and_refund_eth_payment() {
erc20_tokens_infos: Default::default(),
abortable_system: AbortableQueue::default(),
}));
let send_maker_payment_args = SendMakerPaymentArgs {
let send_maker_payment_args = SendPaymentArgs {
time_lock_duration: 0,
time_lock: (now_ms() / 1000) as u32 - 200,
other_pubkey: &DEX_FEE_ADDR_RAW_PUBKEY,
Expand All @@ -326,19 +331,21 @@ fn send_and_refund_eth_payment() {
swap_contract_address: &coin.swap_contract_address(),
swap_unique_data: &[],
payment_instructions: &None,
watcher_reward: None,
};
let payment = coin.send_maker_payment(send_maker_payment_args).wait().unwrap();

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

block_on(Timer::sleep(60.));
let maker_refunds_payment_args = SendMakerRefundsPaymentArgs {
let maker_refunds_payment_args = RefundPaymentArgs {
payment_tx: &payment.tx_hex(),
time_lock: (now_ms() / 1000) as u32 - 200,
other_pubkey: &DEX_FEE_ADDR_RAW_PUBKEY,
secret_hash: &[1; 20],
swap_contract_address: &coin.swap_contract_address(),
swap_unique_data: &[],
watcher_reward: false,
};
let refund = coin
.send_maker_refunds_payment(maker_refunds_payment_args)
Expand Down Expand Up @@ -374,6 +381,7 @@ fn test_nonce_several_urls() {
priv_key_policy: key_pair.into(),
swap_contract_address: Address::from_str("0x7Bc1bBDD6A0a722fC9bffC49c921B685ECB84b94").unwrap(),
fallback_swap_contract: None,
contract_supports_watchers: false,
web3_instances: vec![
Web3Instance {
web3: web3_infura.clone(),
Expand Down Expand Up @@ -439,6 +447,7 @@ fn test_wait_for_payment_spend_timeout() {
priv_key_policy: key_pair.into(),
swap_contract_address: Address::from_str("0x7Bc1bBDD6A0a722fC9bffC49c921B685ECB84b94").unwrap(),
fallback_swap_contract: None,
contract_supports_watchers: false,
ticker: "ETH".into(),
web3_instances: vec![Web3Instance {
web3: web3.clone(),
Expand Down Expand Up @@ -509,6 +518,7 @@ fn test_search_for_swap_tx_spend_was_spent() {
priv_key_policy: key_pair.into(),
swap_contract_address,
fallback_swap_contract: None,
contract_supports_watchers: false,
ticker: "ETH".into(),
web3_instances: vec![Web3Instance {
web3: web3.clone(),
Expand Down Expand Up @@ -553,9 +563,10 @@ fn test_search_for_swap_tx_spend_was_spent() {
];
let spend_tx = FoundSwapTxSpend::Spent(signed_eth_tx_from_bytes(&spend_tx).unwrap().into());

let found_tx = block_on(coin.search_for_swap_tx_spend(&payment_tx, swap_contract_address, &[0; 20], 15643279))
.unwrap()
.unwrap();
let found_tx =
block_on(coin.search_for_swap_tx_spend(&payment_tx, swap_contract_address, &[0; 20], 15643279, false))
.unwrap()
.unwrap();
assert_eq!(spend_tx, found_tx);
}

Expand Down Expand Up @@ -620,6 +631,7 @@ fn test_search_for_swap_tx_spend_was_refunded() {
priv_key_policy: key_pair.into(),
swap_contract_address,
fallback_swap_contract: None,
contract_supports_watchers: false,
ticker: "BAT".into(),
web3_instances: vec![Web3Instance {
web3: web3.clone(),
Expand Down Expand Up @@ -667,9 +679,10 @@ fn test_search_for_swap_tx_spend_was_refunded() {
];
let refund_tx = FoundSwapTxSpend::Refunded(signed_eth_tx_from_bytes(&refund_tx).unwrap().into());

let found_tx = block_on(coin.search_for_swap_tx_spend(&payment_tx, swap_contract_address, &[0; 20], 13638713))
.unwrap()
.unwrap();
let found_tx =
block_on(coin.search_for_swap_tx_spend(&payment_tx, swap_contract_address, &[0; 20], 13638713, false))
.unwrap()
.unwrap();
assert_eq!(refund_tx, found_tx);
}

Expand Down Expand Up @@ -1036,8 +1049,11 @@ fn validate_dex_fee_invalid_sender_eth() {
min_block_number: 0,
uuid: &[],
};
let validate_err = coin.validate_fee(validate_fee_args).wait().unwrap_err();
assert!(validate_err.contains("was sent from wrong address"));
let error = coin.validate_fee(validate_fee_args).wait().unwrap_err().into_inner();
match error {
ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("was sent from wrong address")),
_ => panic!("Expected `WrongPaymentTx` wrong sender address, found {:?}", error),
}
}

#[test]
Expand Down Expand Up @@ -1067,8 +1083,11 @@ fn validate_dex_fee_invalid_sender_erc() {
min_block_number: 0,
uuid: &[],
};
let validate_err = coin.validate_fee(validate_fee_args).wait().unwrap_err();
assert!(validate_err.contains("was sent from wrong address"));
let error = coin.validate_fee(validate_fee_args).wait().unwrap_err().into_inner();
match error {
ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("was sent from wrong address")),
_ => panic!("Expected `WrongPaymentTx` wrong sender address, found {:?}", error),
}
}

fn sender_compressed_pub(tx: &SignedEthTx) -> [u8; 33] {
Expand Down Expand Up @@ -1102,8 +1121,11 @@ fn validate_dex_fee_eth_confirmed_before_min_block() {
min_block_number: 11784793,
uuid: &[],
};
let validate_err = coin.validate_fee(validate_fee_args).wait().unwrap_err();
assert!(validate_err.contains("confirmed before min_block"));
let error = coin.validate_fee(validate_fee_args).wait().unwrap_err().into_inner();
match error {
ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("confirmed before min_block")),
_ => panic!("Expected `WrongPaymentTx` early confirmation, found {:?}", error),
}
}

#[test]
Expand Down Expand Up @@ -1136,8 +1158,11 @@ fn validate_dex_fee_erc_confirmed_before_min_block() {
min_block_number: 11823975,
uuid: &[],
};
let validate_err = coin.validate_fee(validate_fee_args).wait().unwrap_err();
assert!(validate_err.contains("confirmed before min_block"));
let error = coin.validate_fee(validate_fee_args).wait().unwrap_err().into_inner();
match error {
ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("confirmed before min_block")),
_ => panic!("Expected `WrongPaymentTx` early confirmation, found {:?}", error),
}
}

#[test]
Expand Down Expand Up @@ -1276,6 +1301,7 @@ fn test_message_hash() {
priv_key_policy: key_pair.into(),
swap_contract_address: Address::from_str("0x7Bc1bBDD6A0a722fC9bffC49c921B685ECB84b94").unwrap(),
fallback_swap_contract: None,
contract_supports_watchers: false,
web3_instances: vec![Web3Instance {
web3: web3.clone(),
is_parity: true,
Expand Down Expand Up @@ -1320,6 +1346,7 @@ fn test_sign_verify_message() {
priv_key_policy: key_pair.into(),
swap_contract_address: Address::from_str("0x7Bc1bBDD6A0a722fC9bffC49c921B685ECB84b94").unwrap(),
fallback_swap_contract: None,
contract_supports_watchers: false,
web3_instances: vec![Web3Instance {
web3: web3.clone(),
is_parity: true,
Expand Down Expand Up @@ -1375,6 +1402,7 @@ fn test_eth_extract_secret() {
priv_key_policy: key_pair.into(),
swap_contract_address,
fallback_swap_contract: None,
contract_supports_watchers: false,
ticker: "ETH".into(),
web3_instances: vec![Web3Instance {
web3: web3.clone(),
Expand Down Expand Up @@ -1404,7 +1432,7 @@ fn test_eth_extract_secret() {
100, 189, 72, 74, 221, 144, 66, 170, 68, 121, 29, 105, 19, 194, 35, 245, 196, 131, 236, 29, 105, 101, 30,
];

let secret = block_on(coin.extract_secret(&[0u8; 20], tx_bytes.as_slice()));
let secret = block_on(coin.extract_secret(&[0u8; 20], tx_bytes.as_slice(), false));
assert!(secret.is_ok());
let expect_secret = &[
168, 151, 11, 232, 224, 253, 63, 180, 26, 114, 23, 184, 27, 10, 161, 80, 178, 251, 73, 204, 80, 174, 97, 118,
Expand All @@ -1427,7 +1455,7 @@ fn test_eth_extract_secret() {
6, 108, 165, 181, 188, 40, 56, 47, 211, 229, 221, 73, 5, 15, 89, 81, 117, 225, 216, 108, 98, 226, 119, 232, 94,
184, 42, 106,
];
let secret = block_on(coin.extract_secret(&[0u8; 20], tx_bytes.as_slice()))
let secret = block_on(coin.extract_secret(&[0u8; 20], tx_bytes.as_slice(), false))
.err()
.unwrap();
assert!(secret.contains("Expected 'receiverSpend' contract call signature"));
Expand Down
4 changes: 3 additions & 1 deletion mm2src/coins/eth/eth_wasm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async fn test_send() {
priv_key_policy: key_pair.into(),
swap_contract_address: Address::from_str("0x7Bc1bBDD6A0a722fC9bffC49c921B685ECB84b94").unwrap(),
fallback_swap_contract: None,
contract_supports_watchers: false,
web3_instances: vec![Web3Instance {
web3: web3.clone(),
is_parity: true,
Expand All @@ -49,7 +50,7 @@ async fn test_send() {
erc20_tokens_infos: Default::default(),
abortable_system: AbortableQueue::default(),
}));
let maker_payment_args = SendMakerPaymentArgs {
let maker_payment_args = SendPaymentArgs {
time_lock_duration: 0,
time_lock: 1000,
other_pubkey: &DEX_FEE_ADDR_RAW_PUBKEY,
Expand All @@ -58,6 +59,7 @@ async fn test_send() {
swap_contract_address: &None,
swap_unique_data: &[],
payment_instructions: &None,
watcher_reward: None,
};
let tx = coin.send_maker_payment(maker_payment_args).compat().await;
console::log_1(&format!("{:?}", tx).into());
Expand Down
Loading