XCP-BTC trading on the DEX - Better than centralized exchange?

The DEX is a cost-effective, convenient and low risk way of trading between XCP and BTC.

If Alice and Bob agree to trade 10,000 XCP for 35 BTC, they need to do this:

  • Alice places an offer to sell 10,000 XCP for 35 BTC with a very short three block deadline. The protocol escrows 10,000 of Alice’s XCP.

  • Simultaneously Bob places an opposing bid.

  • The protocol matches the orders and gives Bob 20 blocks to make the Bitcoin transfer.

  • Bob makes the BTC transfer.

That’s all! Trade is done!

Now there are some risks involved:

  • If Bob’s transfer takes more than 20 blocks to confirm, Alice’s XCP are no longer in escrow and she receives the BTC without giving Bob XCP in return.

  • Good software will use high priority fees and prevent this stuck-in-mempool concern. But even if it does get stuck, it’s relatively simple to chain transactions to make the stuck one go through in time.

  • After Alice places an order and before Bob makes a matching order, the price may move against Bob. If a significant move, Bob will be better off not placing the order.

  • Therefore it’s actually better if Bob’s the first one to place an order. Alice,if really questioning Bob, may wait for his order to confirm first, but in most cases they’ll be okay placing orders simultaneously. Both will use short deadlines.

  • During the 20 block BTCpay window Bob has a chance of backing out. This is about three and half hours of exchange rate risk for Alice.

  • However, for Bob it’s risky to wait too long. If the BTC transfer doesn’t confirm within the 20 block deadline, Alice will receive the BTC but not give Bob any XCP.

The advantages:

  • The example transaction is about $100,000 worth. Traditional exchanges take about ~0.2% or about $100 fee each. Counterparty’s fee is zero.

  • Centralized exchanges are risky in that they may lose your funds (get hacked) or annoying in that they delay deposits and withdrawals. Counteraprty only takes ~10 minutes to confirm (and Alice and Bob should agree to place their matching orders, so only ~10 minutes to wait for BTCpay and if Bob’s honest he’ll soon after send the BTC or in worst case wait near 20 blocks to do so)

  • It works with any asset against BTC. Can be PEPECASH-BTC, FLDC-BTC, you name it.

  • Oh yes, and for XCP-asset or asset-asset it’s even easier … in case you didn’t know :wink:

NOTE: Counterwallet does not currently support BTCPAY. Any wallet that does?

Joe Looney wrote a really great BTC dex interface which lives at http://btcpaymarket.com and the source code is available at https://github.com/loon3/btcpaymarket

Tried it but … Disclaimer: This site is in active development.
Keeps loading forever so cannot use it for testing either.

I dug into the code and the BTCPAY part is quite simple. You transfer the BTC amount together with an op_return message:
var prefix = "434e5452505254590000000b"; //CNTRPRTY + transaction id (11)
var data = prefix + order_txid_0 + order_txid_1

It used to be enabled in Counterwallet, so I suggest (when we upgrade this wallet) we re-enable it with a new module specific for BTC trading.

Guys - simplify buying XCP with BTC. You nailed it here! Wish to see in CounterWallet asap :heart_eyes:

Yes, the exchange portion of the site is not currently working due to neglect since I haven’t had time to maintain it.

The problem of BTCPAY has never been technically difficult. It’s a matter of improving the UX to a point where it’s usable. This was why btcpaymarket took a different approach than Counterwallet.

If I can find some time, I’ll get it up and running again.

1 Like

Really would like to have XCP-BTC exchange at counterwallet.