AthanorLabs / atomic-swap

💫 ETH-XMR atomic swap implementation
GNU Lesser General Public License v3.0
344 stars 44 forks source link

swapd and swapcli design and implementation #20

Closed noot closed 2 years ago

noot commented 3 years ago

thinking about the design of this project further, this is my current idea/proposal of how it will work.

as I plan to add a discovery layer to the project, there should be a daemon process (swapd) and a client process (swapcli) to separate out the network discovery and protocol logic from the user interaction logic.

swapd components:

  1. networking layer which serves two purposes, a. discovery of peers who provide a coin, discovered via dht.FindProviders; b. communication with peers who we wish to perform the swap protocol with.
  2. monero backend, including wallet generation, wallet interaction, transfers, creation of lock account
  3. ethereum backend, including contract deployment and interaction
  4. RPC server, which the swapcli (or potentially a front-end) can use to interact with the daemon

swapcli components/commands:

  1. discover <desired-coin> : queries the daemon for peers who provide the given coin. optionally, can put amount and exchange rate. returns a list of peers who provide the desired coin, their maximum limit, and exchange rate (and their peer address)
  2. initiate <peer> <have-coin> <amount>: sends a notification to the daemon that we wish to begin the exchange protocol with the given peer, providing the given coin in the given amount. (this will probably need to be implemented with websockets, as the daemon will want to return to us some success or failure message)
  3. notification of swap request from a peer - the daemon will notify the user that some peer wants to do a swap with them (in response to the peer calling initiate). the user can accept or reject. if they accept, the swap proceeds, otherwise nothing happens or a failure is sent to the remote peer.

networking specifications (ie. stream protocols);

  1. /atomic-swap/query/0: when a peer opens this stream with you, they will send you a Query{Coin} message, asking about the coin you have said you provide, you will respond with a QueryResponse{Coin, MaxAmount, ExchangeRate} message, giving the peer the desired info. after this, either side is free to close the stream.
  2. /atomic-swap/protocol/0: when a peer opens this stream with you, they will send you a message Initiate{ProvidesCoin, ProvidesAmount, DesiredAmount, Keys} initiating the protocol and sending their keys (as in the first step of the swap protocol). if you accept, you will respond with your keys. otherwise, close the stream.

requirements:

  1. RPC server on the daemon
  2. websockets connection between daemon/client
  3. potentially, an RPC server on the client as well, so that an app/frontend can perform the user interactions

any thoughts or feedback is much appreciated :)

noot commented 2 years ago

1 has been done, what remains is the CLI and potentially websockets support.