darkfi icon indicating copy to clipboard operation
darkfi copied to clipboard

feat(swapd): begin atomic swap implementation

Open noot opened this issue 1 year ago • 4 comments

This PR is the start of the ETH-DRK atomic swap implementation. The first "direction" to be implemented is that where ETH is the swap initiator (first-mover) and DRK is the second-mover.

what was done:

  • add swap protocol traits Initiator and Follower (not sure about naming yet, wanted to make it generic as it will eventually be both-ways).
  • implement initiator::Swap and follower::Swap which run the actual swap protocol; currently only initiator::Swap is implemented.
  • add the eth swap contract and bindings for it + test utils
  • implement the eth-side swap handler, which calls required methods on the contract when certain events happen
  • implement the eth-side event watcher, which sends events when certain contract events are emitted
  • add unit test test_initiator_swap_success which tests the success case with an ethereum Swap instance running with a mock no-op darkfi backend.

to do (either here on in a follow-up):

  • clean up the ethereum/forge readme and documentation
  • get rid of the #[allow(dead_code)] maybe? or can do in a follow up with CLI stuff

noot avatar Dec 18 '23 06:12 noot

Hi. I'd advise to follow these recommendations for your commit messages unless you want to squash everything into one later: https://darkrenaissance.github.io/darkfi/dev/dev.html#making-life-easy-for-others

Please do not include git submodules in the repo.

Do not use tokio. We use smol.

Please include the licensing header in your files like it is found in our other source files.

parazyd avatar Dec 18 '23 08:12 parazyd

@parazyd thanks for the feedback! do you guys squash and merge PRs? if not, i can squash all the commits before merging.

Please do not include git submodules in the repo.

this is due to using forge for building and managing the eth smart contracts, which uses git submodules for dependencies. the submodules are only required for compiling the contracts, which is done only on the test-utils feature (used only in tests). the alternative would be to just copy-paste the contract dependencies, which i can do if needed.

noot avatar Dec 18 '23 19:12 noot

Instead of async-oneshot, in our code we use https://docs.rs/smol/latest/smol/channel/fn.bounded.html We try to avoid adding unnecessary dependencies.

We can squash the PR, yes.

I suppose the submodule is fine then for now. We can decide later on what to do on that part.

parazyd avatar Dec 19 '23 12:12 parazyd

@parazyd updated to use smol::channel::bounded - this is ready for another look!

noot avatar Feb 27 '24 17:02 noot

closing for now as this has been moved into its own repository https://codeberg.org/darkrenaissance/swapd

noot avatar Mar 26 '24 22:03 noot