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

ETH/ERC20/UTXO swaps with watcher rewards #1750

Merged
merged 50 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f091e0c
add watcher reward functionality for eth-erc20-utxo swaps
caglaryucekaya Mar 29, 2023
0e82bb3
refactor watcher tests and add tests for eth-erc20-utxo swaps
caglaryucekaya Mar 29, 2023
5e4af1b
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya Mar 29, 2023
c4b78e3
fix merge problems
caglaryucekaya Mar 30, 2023
0311858
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya Mar 30, 2023
4722c72
update swap contract abi
caglaryucekaya Apr 1, 2023
b47f95e
use improved contract to allow only the taker to pay watcher rewards
caglaryucekaya Apr 9, 2023
35680b4
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya Apr 9, 2023
e3998b5
add changes to the CHANGELOG
caglaryucekaya Apr 10, 2023
b8f3493
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya Apr 12, 2023
23ff820
fix a problem with utxo swap watcher integration tests
caglaryucekaya Apr 13, 2023
1d55164
fix repeatable future usage
caglaryucekaya Apr 13, 2023
5ed3fd7
fix a bug in swap watcher docker tests
caglaryucekaya Apr 15, 2023
791b7d9
use cfg attribute for test specific code
caglaryucekaya Apr 15, 2023
be7f8e7
remove println
caglaryucekaya Apr 15, 2023
df30685
use enum for ETH payment states
caglaryucekaya Apr 15, 2023
cfd79f7
fix formatting
caglaryucekaya Apr 15, 2023
c7fa92e
replace match statement with map
caglaryucekaya Apr 16, 2023
0d79a6b
replace from_utf8_lossy with from_utf8
caglaryucekaya Apr 16, 2023
eebe736
move watcher reward functions to coins module
caglaryucekaya Apr 26, 2023
04ec0bd
add watcher_common module
caglaryucekaya Apr 26, 2023
39ac253
add cargo lock
caglaryucekaya Apr 26, 2023
82552ef
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya Apr 26, 2023
aa6c0c6
fix clippy errors
caglaryucekaya Apr 26, 2023
34a718f
fix bugs and use a better sepolia rpc endpoint
caglaryucekaya Apr 29, 2023
dde7f95
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya Apr 29, 2023
139b65a
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya May 2, 2023
89fedc7
remove println statements
caglaryucekaya May 2, 2023
855acbc
remove unused parameters from get_maker_watcher_reward method
caglaryucekaya May 2, 2023
0dfd60c
change the return type of the get_taker_watcher_reward method
caglaryucekaya May 2, 2023
f7915e9
fix watcher method signatures in solana and spl
caglaryucekaya May 2, 2023
e14cf23
minor fixes in swap watcher tests
caglaryucekaya May 2, 2023
d70f457
return a single Ok from validate_watcher_reward function
caglaryucekaya May 2, 2023
52c95cd
use timeout for gas price queries
caglaryucekaya May 3, 2023
7a4e755
remove the unused get_maker_watcher_reward function in utxo_common
caglaryucekaya May 3, 2023
5337256
update changelog
caglaryucekaya May 3, 2023
1b56782
define a separate get_base_price_in_rel function for tests
caglaryucekaya May 3, 2023
ee21dcb
get watcher reward inside watcher_validate_taker_payment
caglaryucekaya May 3, 2023
2403012
minor fixes
caglaryucekaya May 3, 2023
6c4c65b
implement checked_div method for BigDecimal and replace divs with it
caglaryucekaya May 4, 2023
6e1de72
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya May 4, 2023
3fc4f55
implement CheckedDiv for MmNumber and use it in get_cex_rates
caglaryucekaya May 4, 2023
a5fee0a
move the wasm-timer import to dev-dependencies in coins toml
caglaryucekaya May 5, 2023
96a4cb0
rename an environment variable used for tests
caglaryucekaya May 5, 2023
fad0116
use helper functions to get time
caglaryucekaya May 5, 2023
96f1fc7
remove derivation path from eth sepolia configuration
caglaryucekaya May 6, 2023
8ae9597
rename the local big_decimal module
caglaryucekaya May 6, 2023
e437d75
fix wasm issues
caglaryucekaya May 6, 2023
94f91e7
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya May 6, 2023
8331f4d
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into et…
caglaryucekaya May 9, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
- Some enhancements were done for `enable_bch_with_tokens`,`enable_eth_with_tokens`,`enable_tendermint_with_assets` RPCs in [#1762](https://github.com/KomodoPlatform/atomicDEX-API/pull/1762)
- A new parameter `get_balances` was added to the above methods requests, when this parameter is set to `false`, balances will not be returned in the response. The default value for this parameter is `true` to ensure backward compatibility.
- Token balances requests are now performed concurrently for the above methods.
- Swap watcher nodes [#1750](https://github.com/KomodoPlatform/atomicDEX-API/pull/1750)
- PoC for ETH/UTXO and ERC20/UTXO swaps with rewards
- Improved protocol to let only the taker pay the reward
- Add passive parent coin state for keeping tokens active when platform is disabled [#1763](https://github.com/KomodoPlatform/atomicDEX-API/pull/1763)


Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions mm2src/coins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enable-solana = [
"dep:spl-associated-token-account"
]
default = []
run-docker-tests = []

[lib]
name = "coins"
Expand Down Expand Up @@ -148,6 +149,7 @@ winapi = "0.3"

[dev-dependencies]
mm2_test_helpers = { path = "../mm2_test_helpers" }
wasm-timer = "0.2.4"

[build-dependencies]
prost-build = { version = "0.10.4", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions mm2src/coins/coin_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum ValidatePaymentError {
Transport(String),
// Transaction has wrong properties, for example, it has been sent to a wrong address
WrongPaymentTx(String),
WatcherRewardError(String),
}

impl From<rlp::DecoderError> for ValidatePaymentError {
Expand Down
618 changes: 447 additions & 171 deletions mm2src/coins/eth.rs

Large diffs are not rendered by default.

25 changes: 13 additions & 12 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;
use common::{block_on, now_sec_u32};
use mm2_core::mm_ctx::{MmArc, MmCtxBuilder};
use mm2_test_helpers::for_tests::{ETH_MAINNET_NODE, ETH_MAINNET_SWAP_CONTRACT};
use mocktopus::mocking::*;
Expand Down Expand Up @@ -254,7 +254,7 @@ fn send_and_refund_erc20_payment() {
}));
let maker_payment_args = SendPaymentArgs {
time_lock_duration: 0,
time_lock: (now_ms() / 1000) as u32 - 200,
time_lock: now_sec_u32() - 200,
other_pubkey: &DEX_FEE_ADDR_RAW_PUBKEY,
secret_hash: &[1; 20],
amount: "0.001".parse().unwrap(),
Expand All @@ -271,7 +271,7 @@ fn send_and_refund_erc20_payment() {

let maker_refunds_payment_args = RefundPaymentArgs {
payment_tx: &payment.tx_hex(),
time_lock: (now_ms() / 1000) as u32 - 200,
time_lock: now_sec_u32() - 200,
other_pubkey: &DEX_FEE_ADDR_RAW_PUBKEY,
secret_hash: &[1; 20],
swap_contract_address: &coin.swap_contract_address(),
Expand Down Expand Up @@ -325,7 +325,7 @@ fn send_and_refund_eth_payment() {
}));
let send_maker_payment_args = SendPaymentArgs {
time_lock_duration: 0,
time_lock: (now_ms() / 1000) as u32 - 200,
time_lock: now_sec_u32() - 200,
other_pubkey: &DEX_FEE_ADDR_RAW_PUBKEY,
secret_hash: &[1; 20],
amount: "0.001".parse().unwrap(),
Expand All @@ -342,7 +342,7 @@ fn send_and_refund_eth_payment() {
block_on(Timer::sleep(60.));
let maker_refunds_payment_args = RefundPaymentArgs {
payment_tx: &payment.tx_hex(),
time_lock: (now_ms() / 1000) as u32 - 200,
time_lock: now_sec_u32() - 200,
other_pubkey: &DEX_FEE_ADDR_RAW_PUBKEY,
secret_hash: &[1; 20],
swap_contract_address: &coin.swap_contract_address(),
Expand Down Expand Up @@ -466,7 +466,7 @@ fn test_wait_for_payment_spend_timeout() {
};

let coin = EthCoin(Arc::new(coin));
let wait_until = (now_ms() / 1000) - 1;
let wait_until = now_sec() - 1;
let from_block = 1;
// raw transaction bytes of https://etherscan.io/tx/0x0869be3e5d4456a29d488a533ad6c118620fef450f36778aecf31d356ff8b41f
let tx_bytes = [
Expand All @@ -483,14 +483,15 @@ fn test_wait_for_payment_spend_timeout() {
];

assert!(coin
.wait_for_htlc_tx_spend(
&tx_bytes,
&[],
.wait_for_htlc_tx_spend(WaitForHTLCTxSpendArgs {
tx_bytes: &tx_bytes,
secret_hash: &[],
wait_until,
from_block,
&coin.swap_contract_address(),
TAKER_PAYMENT_SPEND_SEARCH_INTERVAL
)
swap_contract_address: &coin.swap_contract_address(),
check_every: TAKER_PAYMENT_SPEND_SEARCH_INTERVAL,
watcher_reward: false
})
.wait()
.is_err());
}
Expand Down
77 changes: 48 additions & 29 deletions mm2src/coins/eth/swap_contract_abi.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "message",
"type": "string"
}
],
"name": "Log",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "number",
"type": "uint256"
}
],
"name": "LogNumber",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -139,6 +113,21 @@
"internalType": "uint64",
"name": "_lockTime",
"type": "uint64"
},
{
"internalType": "enum EtomicSwap.RewardTargetOnSpend",
"name": "_rewardTarget",
"type": "uint8"
},
{
"internalType": "bool",
"name": "_sendsContractRewardOnSpend",
"type": "bool"
},
{
"internalType": "uint256",
"name": "_rewardAmount",
"type": "uint256"
}
],
"name": "erc20PaymentReward",
Expand Down Expand Up @@ -196,9 +185,19 @@
"name": "_lockTime",
"type": "uint64"
},
{
"internalType": "enum EtomicSwap.RewardTargetOnSpend",
"name": "_rewardTarget",
"type": "uint8"
},
{
"internalType": "bool",
"name": "_sendsContractRewardOnSpend",
"type": "bool"
},
{
"internalType": "uint256",
"name": "_watcherReward",
"name": "_rewardAmount",
"type": "uint256"
}
],
Expand Down Expand Up @@ -272,9 +271,19 @@
"name": "_receiver",
"type": "address"
},
{
"internalType": "enum EtomicSwap.RewardTargetOnSpend",
"name": "_rewardTarget",
"type": "uint8"
},
{
"internalType": "bool",
"name": "_sendsContractRewardOnSpend",
"type": "bool"
},
{
"internalType": "uint256",
"name": "_watcherReward",
"name": "_rewardAmount",
"type": "uint256"
}
],
Expand Down Expand Up @@ -348,9 +357,19 @@
"name": "_receiver",
"type": "address"
},
{
"internalType": "enum EtomicSwap.RewardTargetOnSpend",
"name": "_rewardTarget",
"type": "uint8"
},
{
"internalType": "bool",
"name": "_sendsReward",
"type": "bool"
},
{
"internalType": "uint256",
"name": "_watcherReward",
"name": "_rewardAmount",
"type": "uint256"
}
],
Expand Down
Loading