xmr-btc-swap/docs/asb/README.md
Daniel Karzel 14baba0529
Update ASB docs
- remove outdated known limitations
- link to latest release
- mention of resuming swap upon restart and Bitcoin commands
2021-04-07 11:58:28 +10:00

6.4 KiB

XMR to BTC Atomic Swap - Automated Swap Backend (ASB)

Quick Start ASB

  1. Download latest release of the asb binary
  2. Ensure that you have the Monero Wallet RPC running with --wallet-dir and --disable-rpc-login:
    1. monero-wallet-rpc --stagenet --daemon-host STAGENET-NODE-URL --rpc-bind-port STAGENET-NODE-PORT --disable-rpc-login --wallet-dir PATH/TO/WALLET/DIR
  3. Run the ASB in terminal: ./asb start
  4. Follow the setup wizard in the terminal

Public Monero stagenet nodes for running the Monero Wallet RPC:

  • monero-stagenet.exan.tech:38081
  • stagenet.community.xmr.to:38081

Run ./asb --help for more information.

ASB Details

The ASB is a long running daemon that acts as the trading partner to the swap CLI. The CLI user is buying XMR (i.e. receives XMR, sends BTC), the ASB service provider is selling XMR (i.e. sends XMR, receives BTC). The ASB can handle multiple swaps with different peers concurrently. The ASB communicates with the CLI on various libp2p-based network protocols.

Both the ASB and the CLI can be run by anybody. The CLI is designed to run one specific swap against an ASB. The ASB is designed to run 24/7 as a daemon that responds to CLIs connecting. Since the ASB is a long running task we specify the person running an ASB as service provider.

ASB discovery

Currently, there is no automated discovery for service providers running an ASB. A service provider has to manually provide the connection details to users that will run the CLI.

Libp2p addressing is used to identify a service provider by multi-address and peer-id. The Peer-ID is printed upon startup of the ASB. The multi-address typically consists of IP-address or URL (if DNS entry configured) of the service provider.

Each service provider running an ASB can decide how/where to share these connection details.

Service Provider scenarios

Eventually, more elaborate discovery mechanisms can be added.

The CLI user can specify a service providers's multiaddress and peer-id with --seller-addr and --seller-peer, see ./swap --help for details.

Setup Details

In order to understand the different components of the ASB and CLI better here is a component diagram showcasing the ASB and CLI setup using public Bitcoin and Monero infrastructure:

Service Provider scenarios

Contrary, here is a diagram that showcases a service provider running it's own blockchain infrastructure for the ASB:

Service Provider scenarios

The diagram shows that the asb group (representing the asb binary) consists of three components:

  1. Monero Wallet
  2. Bitcoin Wallet
  3. ASB

The ASB depicted in the diagram actually consists of multiple components (protocol impl, network communication, ...) that sums up the functionality to execute concurrent swaps in the role of Alice.

Monero Wallet Setup

The ASB uses the running Monero wallet RPC to create / open Monero wallets. Currently you cannot connect to an existing Monero wallet, but the ASB will create the wallet asb-wallet upon intial startup. In order to accept trades with a CLI you will have to send XMR to that wallet. The wallet's address is printed upon startup of the ASB. Currently the asb-wallet does not have a password.

Upon startup of the ASB the asb-wallet is opened in the wallet RPC. You can then interact with the wallet RPC for basic wallet management as well.

Bitcoin Wallet Setup

The ASB has an internally managed Bitcoin wallet. The Bitcoin wallet is created upon initial startup and stored in the data folder of the ASB (configured through initial startup wizard).

Market Making

In order to be able to trade, the ASB must define a price to be able to agree on the amounts to be swapped with a CLI. Currently we use a spot-price mode, i.e. the ASB dictates the price to the CLI.

A CLI can connect to the ASB at any time and request a quote for buying XMR. The ASB then returns the current price and the maximum amount tradeable.

The maximum amount tradeable can be configured with the --max-buy-btc parameter.

The XMR<>BTC price is currently determined by the price from the central exchange Kraken. Upon startup the ASB connects to the Kraken price websocket and listens on the stream for price updates.

Currently the spot price is equal to the market price on Kraken.

Swap Execution

Swap execution within the ASB is automated. Incoming swaps request will be automatically processed and the swap will execute automatically. Swaps where Bob does not act, so Alice cannot redeem, will be automatically refunded or punished. When the ASB is restarted unfinished swaps will be resumed automatically.

The refund scenario is a scenario where the CLI refunds the Bitcoin. The ASB can then refund the Monero which will be automatically transferred to the asb-wallet.

The punish scenario is a scenario where the CLI does not refund and hence the ASB cannot refund the Monero. After a second timelock expires the ASB will automatically punish the CLI user by taking the Bitcoin.

More information about the protocol in this presentation and this blog post.

All claimed Bitcoin ends up in the internal Bitcoin wallet of the ASB. The ASB offers a commands to withdraw Bitcoin and check the balance, run ./asb --help for details.

If the ASB has insufficient Monero funds to accept a swap the swap setup is rejected. Note that currently there is no specific error sent back to the CLI for such kind of cases, so a user might not know why the swap execution was rejected. Note that there is currently no notification service implemented for low funds. The ASB provider has to monitor Monero funds to make sure the ASB still has liquidity.