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

feat(eth-swap): maker tpu v2 implementation #2211

Merged
merged 48 commits into from
Nov 8, 2024
Merged

feat(eth-swap): maker tpu v2 implementation #2211

merged 48 commits into from
Nov 8, 2024

Conversation

laruh
Copy link
Member

@laruh laruh commented Sep 5, 2024

  • impl MakerCoinSwapOpsV2 trait for ETH
  • eth taker and maker swap v2 implementations are stored in eth_swap_v2 module
  • added taker, maker and nft_maker gas limit v2 params and consts
  • Nft swap v2 methods started to use swap address from "swap_v2_contracts" coin field

In addition, added additional wait_for_maker_payment_spend function to MakerCoinSwapOpsV2 trait. It is needed to cover "taker doesnt wait for spend maker payment tx confirmation" issue which we faced in legacy swap protocol #2175 (comment)

Later we can add wait_for_maker_payment_spend usage in MakerPaymentSpent state before changing it to Completed

impl<MakerCoin: MmCoin + MakerCoinSwapOpsV2, TakerCoin: MmCoin + TakerCoinSwapOpsV2> State
for MakerPaymentSpent<MakerCoin, TakerCoin>
{
type StateMachine = TakerSwapStateMachine<MakerCoin, TakerCoin>;
async fn on_changed(self: Box<Self>, state_machine: &mut Self::StateMachine) -> StateResult<Self::StateMachine> {
Self::change_state(Completed::new(), state_machine).await
}
}

Note
Provided two test features to be able to test maker and taker swap v2 contracts separately on sepolia.

sepolia-maker-swap-v2-tests = []
sepolia-taker-swap-v2-tests = []

Copy link
Member

@borngraced borngraced left a comment

Choose a reason for hiding this comment

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

Great work! first review iteration

mm2src/coins/eth.rs Outdated Show resolved Hide resolved
mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs Outdated Show resolved Hide resolved
mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs Outdated Show resolved Hide resolved
mm2src/coins/eth/nft_swap_v2/mod.rs Show resolved Hide resolved
mm2src/coins/eth/nft_swap_v2/mod.rs Outdated Show resolved Hide resolved
mm2src/coins/eth/nft_swap_v2/mod.rs Outdated Show resolved Hide resolved
mm2src/coins/eth/nft_swap_v2/mod.rs Outdated Show resolved Hide resolved
mm2src/coins/eth/nft_swap_v2/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@borngraced borngraced left a comment

Choose a reason for hiding this comment

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

last notes

mm2src/coins/coin_errors.rs Show resolved Hide resolved
mm2src/coins/eth.rs Show resolved Hide resolved
mm2src/coins/eth.rs Show resolved Hide resolved
mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs Outdated Show resolved Hide resolved
Copy link
Member

@borngraced borngraced left a comment

Choose a reason for hiding this comment

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

welldone!

@shamardy
Copy link
Collaborator

shamardy commented Nov 8, 2024

@laruh I think there is nothing to test or document by @KomodoPlatform/qa for this PR, if that's the case please add To Test and nothing to the opening comment, otherwise add normal To Test and docs.

@shamardy shamardy merged commit 99cb87a into dev Nov 8, 2024
19 of 23 checks passed
@shamardy shamardy deleted the eth-maker-tpu-v2 branch November 8, 2024 14:10
Comment on lines +75 to 78
#[cfg(any(feature = "sepolia-maker-swap-v2-tests", feature = "sepolia-taker-swap-v2-tests"))]
lazy_static! {
pub static ref SEPOLIA_WEB3: Web3<Http> = Web3::new(Http::new(SEPOLIA_RPC_URL).unwrap());
pub static ref SEPOLIA_NONCE_LOCK: Mutex<()> = Mutex::new(());
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this use any docker instance? why don't we move such tests outside docker (to test_inner)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, yes, the Sepolia code doesn’t use Geth-generated addresses.
We could move the code to the sepolia_tests test crate.
However, there’s still a chance that when we update the Swap V2 smart contracts, for example add burnFee to the taker swap contract, this contract could start working on the Geth node (we faced similar issue during the NFT maker swap V2 implementation and testing). In that case, the code could be moved back to docker_tests.

Let’s plan this when we update the taker swap v2 contract, if it doesn’t work on Geth, we’ll move taker/maker Sepolia code to a separate test crate.

// Mutex used to prevent nonce re-usage during funding addresses used in tests
pub static ref GETH_NONCE_LOCK: Mutex<()> = Mutex::new(());
}

#[cfg(any(feature = "sepolia-maker-swap-v2-tests", feature = "sepolia-taker-swap-v2-tests"))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not merge the two features?

Copy link
Member Author

Choose a reason for hiding this comment

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

maker and taker methods are belong to different smart contracts. its better to have them separately, when you need to test only maker or only taker functionality

Copy link
Collaborator

Choose a reason for hiding this comment

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

tbh i would consider this (and not really much) only if these smart contracts are changed so often to justify having a feature to run them specifically, otherwise i would just go for merging these feature flags (or even ignoring the sepolia tests instead) and run tests by their names or name prefix.
i see features as more complexities if we can do without it.

dimxy added a commit that referenced this pull request Nov 11, 2024
* dev:
  fix(foot-shooting): remove leftover code that panics via RPC (#2270)
  refactor(MarketCoinOps): make `wait_for_htlc_tx_spend` async (#2265)
  feat(eth-swap): maker tpu v2 implementation (#2211)
  fix(nft): add token_id field to the tx history primary key, fix balance (#2209)
  feat(cosmos): support IBC types in tx history implementation (#2245)
  fix(hd-wallet): use `CoinBalanceMap` for UTXO and QTUM (#2259)
  fix(tests): add more sepolia endpoints in tests (#2262)
  fix(legacy-swap): check for confirmations on recover taker (#2242)
  fix(legacy-swap): remove the need for takers to confirm their payment (#2249)
  refactor(P2P): types and modules (#2256)
  fix(evm): correctly display eth addr in iguana v2 activation result (#2254)
  feat(utxo): prioritize electrum connections (#1966)
  refactor(SwapOps): make all methods async (#2251)
  refactor(SwapOps): make `send_maker_payment` async (#2250)
  remove old p2p implementation (#2248)
  feat(cosmos-offline-tests): prepare IBC channels inside the container  (#2246)
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