Skip to content

feat(trading-proto-upgrade): locked amounts, kmd burn and other impl#2046

Merged
shamardy merged 60 commits intodevfrom
swap-proto-upgrade-iteration-5
Feb 21, 2024
Merged

feat(trading-proto-upgrade): locked amounts, kmd burn and other impl#2046
shamardy merged 60 commits intodevfrom
swap-proto-upgrade-iteration-5

Conversation

@artemii235
Copy link
Copy Markdown

@artemii235 artemii235 commented Jan 8, 2024

#1895

What's done:

  • Locked amount handling for UTXO swaps (more work will be needed for ETH/ERC20)
  • Implemented conditional wait for maker payment confirmation before signing funding tx spend preimage on taker's side.
  • active_swaps V2 RPC
  • Handling accept_only_from for swap messages (validation of the sender)
  • Added swap_uuid for swap v2 messages to avoid reusage of the messages generated for other swaps
  • Implemented maker payment immediate refund path handling
  • Implemented KMD dex fee burn for upgraded swaps
  • Added dockerized Geth node for ETH-related integration tests (more to be done in the next sprints)
  • Fixed ETH watcher tests

Updated deps:

  • test-containers (other Cargo.lock updates are triggered by it). The purpose is to rely on the official version instead of using the fork. The fork also didn't allow passing additional arguments to the image (only docker run options were available).

artemii235 and others added 30 commits December 25, 2023 13:26
Start handling require_maker_payment_confirm_before_funding_spend.
@artemii235
Copy link
Copy Markdown
Author

@laruh I added doc comments and fixed typos, thanks 🙂

shamardy
shamardy previously approved these changes Feb 1, 2024
Copy link
Copy Markdown
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but a few non-blockers!

Comment on lines +3424 to +3432
// TODO tests passed without this change, need to research on how it worked
if reward.send_contract_reward_on_spend {
let eth_reward_amount =
try_tx_fus!(wei_from_big_decimal(&reward.amount, ETH_DECIMALS));
value += eth_reward_amount;
eth_reward_amount
} else {
0.into()
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please specify which tests pass? As I can see when RewardTarget is PaymentReceiver https://github.com/KomodoPlatform/komodo-defi-framework/blob/52aaa1683fc33c9c151fa44a1116142369ee63cd/mm2src/coins/utxo/utxo_common.rs#L2859
send_contract_reward_on_spend is always false
https://github.com/KomodoPlatform/komodo-defi-framework/blob/52aaa1683fc33c9c151fa44a1116142369ee63cd/mm2src/coins/utxo/utxo_common.rs#L2892
The RewardTarget::PaymentReceiver variant seems to be used for UTXO coins only for the case of UTXO taker / ETH maker - UTXO taker / ERC20 maker here #1750 (comment) this is probably why this check was not needed in eth code.
P.S. I think watchers code needs a lot of refactors to separate it from default swap case logic.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, all watcher tests were passing with old testnet environment but started to fail after switching to dockerized Geth. send_contract_reward_on_spend can be true in get_maker_watcher_reward if other_coin.is_eth():
https://github.com/KomodoPlatform/komodo-defi-framework/blob/8635ed94a7c3334bce94c4f6d5fabbf5f227e92c/mm2src/coins/eth.rs#L2052

And when it's true, the contract attempts to send additional ETH, which isn't available on its balance. With this change, the reward ETH is also transferred to a contract during payment, making ETH/ERC20 watcher tests pass.

P.S. I think watchers code needs a lot of refactors to separate it from default swap case logic.

I agree with this. My goal was to make tests green and learn ETH watchers code/understand it better. It seems that RewardTarget and send_contract_reward_on_spend can be removed to handle most of the logic on smart contract side. I would like to either work on it myself in the future or guide the developer who will take the task.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

send_contract_reward_on_spend can be true in get_maker_watcher_reward if other_coin.is_eth()

Yeah, missed this since I was looking for cases with RewardTarget::PaymentReceive as looking for None case is not logical.

I would like to either work on it myself in the future or guide the developer who will take the task.

Sure. Thanks a lot for offering your help on this :)

Comment on lines +925 to +926
let total_payment_value =
&(&state_machine.taker_volume + &state_machine.dex_fee.total_spend_amount()) + &state_machine.taker_premium;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we agreed we should include funding transaction spend fee in the total payment value of the taker. I guess you will do that in next iterations.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I will try to do it in the current iteration 🙂

@shamardy
Copy link
Copy Markdown
Collaborator

shamardy commented Feb 2, 2024

@onur-ozkan @dimxy please check if your comments are resolved or not so that I can merge this PR. It will be good to have dockerized geth dev node and eth tests in dev branch asap.

Copy link
Copy Markdown

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did one more iteration quickly (I have no time for reviews due to my current sprint tasks), I am happy to approve the PR if everyone else approved.

@shamardy
Copy link
Copy Markdown
Collaborator

@artemii235 can you please fix conflicts so that I can re-approve and merge this PR.

Artem Vitae added 2 commits February 21, 2024 16:43
…ration-5

# Conflicts:
#	Cargo.lock
#	mm2src/coins/eth.rs
#	mm2src/coins/utxo/utxo_common.rs
#	mm2src/mm2_bitcoin/script/src/builder.rs
#	mm2src/mm2_main/src/database.rs
@artemii235
Copy link
Copy Markdown
Author

@shamardy Done 🙂

@shamardy shamardy merged commit af57160 into dev Feb 21, 2024
@shamardy shamardy deleted the swap-proto-upgrade-iteration-5 branch February 21, 2024 12:20
dimxy pushed a commit to dimxy/komodo-defi-framework that referenced this pull request Feb 25, 2024
* dev:
  feat(zcoin): ARRR WASM implementation (GLEECBTC#1957)
  feat(trading-proto-upgrade): locked amounts, kmd burn and other impl (GLEECBTC#2046)
  fix(indexeddb): set stop on success cursor condition (GLEECBTC#2067)
  feat(config): add `max_concurrent_connections` to mm2 config (GLEECBTC#2063)
  feat(stats_swaps): add gui/mm_version in stats db (GLEECBTC#2061)
  fix(indexeddb): fix IDB cursor.continue_() call after drop (GLEECBTC#2028)
  security bump for `h2` (GLEECBTC#2062)
  fix(makerbot): allow more than one prices url in makerbot (GLEECBTC#2027)
  fix(wasm worker env): refactor direct usage of `window` (GLEECBTC#1953)
  feat(nft): nft abi in withdraw_nft RPC, clear_nft_db RPC (GLEECBTC#2039)
  refactor(utxo): refactor utxo output script creation (GLEECBTC#1960)
  feat(ETH): balance event streaming for ETH (GLEECBTC#2041)
  chore(release): bump mm2 version to 2.1.0-beta (GLEECBTC#2044)
  feat(trezor): add segwit support for withdraw with trezor (GLEECBTC#1984)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants