How does the counterparty decentralized exchange work?

Where does the orderbook live? Does it live in bitcoin transactions? or does it live only in the memory of Counterparty servers?

This video might help:

The orderbook lives on the bitcoin blockchain (all transactions, including placing sell and buy orders, are recorded there).
There’s an “extracted” copy of the current and past trades in the DB of Counterparty servers (Sqlite).

why is BTC disabled?
– also, comparing to bitstamp is misleading, those are real exchanges which exchange real assets (like BTC and fiat), not app tokens.

How do you solve the problem that if miners control the transactions that will be mined in the block then they essentially have front-running priority on any trade on your exchange?

Also can you escrow BTC for orders instead of just XCP and other app tokens?

I am not sure how much of an issue this is (I’d like to hear what others think).
The DEx is by definition “slow” - each offer has to be recorded on the blockchain which takes time and costs (transaction fee).

  • From a seller perspective, once you make an offer, you don’t really care who matches it.

  • From a buyer perspective, yes, a miner can frontrun your offer. Say someone is selling 1 A for 10 B. You make an offer (offering 10 B for 1 A) and a miner does the same and includes his offer before yours. Assuming the DEx parses these in the exact order, your offer wouldn’t be matched.
    While this provides additional opportunities for miners, normally a regular buyer can get up to date information from any centralized crypto-exchange (which update their prices with a much higher granularity) so the both of them can act on DEx opportunities, but the miner has a better chance of success.

Now, in practical terms, the DEx - because it works the way it does - is great for risk-free trades (I think one of greatest use case scenarios is institutional settlements or pre-agreed sales where the two parties want to do a secure buy-sell).

A DEx buyer who is afraid of being front-run, when he spots a good buy opportunity in mempool, can offer a higher miner fee so that all miners are motivated to include his transaction faster. While his transaction would cost a bit more, it would likely be profitable except for trivial (small) orders. For example, if 1 A sells for an equivalent of $49 whereas on Poloniex it’s $50, a buyer could pay a higher miner fee (up to $0.5, for example, which is probably 3-5x of what people normally pay) and the front-running miner would then have a much lower chance of winning.

I can’t estimate the exact figures, of course, but my basic assumption is if you’re a miner from a very large pool (say, 20% share), you could not be sure that you’d beat my order that all pools are trying to include with a higher priority.

At the moment DEx orders are few and small because people prefer to trade fast and cheap, so it’s not a lucrative opportunity, but I think it’d be great for the ecosystem if someone actually tried to use this strategy, because that might make it possible to sell tokens and XCP on DEx at a price that’s close to the price found on centralized exchanges.

Is there an over-the-counter (OTC), but still on-blockchain, method of buying BTC, XCP and other tokens?

I.e. not using the DEx necessarily, but escrowing and matching a trade directly between two parties. E.g. I meet someone with 1000 XCP. I want to buy that 1000 XCP for 5 BTC. How do we achieve this in a trust-less manner?

@counterpart, you could try on Counterparty Skype chat group I suppose.
There was one time someone looked for a buyer here (on the forum), I remember.

The safest way is to find someone who wants to trade with you and agree to meet on DEx (you make a BTC for XCP offer, he makes a XCP for BTC offer).
But, there’s a complexity for those who use BTC to buy anything on the DEx: namely, you cannot use the GUI to create BTC-based offers (the CLI must be used).
But even if you go through this trouble (of setting up a Counterparty server), it may not be cost effective enough to justify it. I think for the amount you mention, it’s better to watch the main markets and buy in smaller amounts (say, in increments of 50 XCP, it’d be 20 purchases, which I think is more time-efficient than using the DEx, maybe even more cost-efficient).

Thank you for the reply. This strikes me as an odd oversight. Should there not be a feature (especially with BTC) where an individual makes an order to buy, say 1000 XCP, for 5 BTC. Another individual commits to the trade and their 1000 XCP is escrowed by the protocol. As soon as the 5 BTC is transacted and confirmed the XCP is released from escrow?

Direct Trustless Trades?

I believe that the reason for BTC being disabled is due to legal no guidance, but dont quote me on that, I think @brighton36 could help answer that

I was comparing it to the fact that bitstamp holds your bitcoin private keys, the DEX does not

Well, it is how it works, it’s just that the DEx will match the best, and not specific (by seller address, or maybe amount), offer.

The reason why “BTC Sell” was removed from Counterwallet was that more people used it than tried to understand it.

As a consequence, they’d place their BTC sell order (another way to look at it: XCP buy order, in exchange for BTC) and log out. Because they’d have to be online to pay, even if their order matched, their transaction would not happen, they’d pay transaction fees and get nothing in return. Because the ignorant constantly outnumbered those who read the docs or forums, complaints about this were too numerous to deal with.

So now those who want to sell BTC on the DEx have to use the CLI, while the person buying BTC (or: selling XCP or other Counterparty token) can use CW.

good to know, and that makes sense. Thanks something!

So if the profit to be made here is $1, why wouldn’t every miner put their own transaction in front of it? There is no fee that I could put on the transaction that could possibly incentivize the miner more than profit to be gained by front running my order himself. Yes, any given one miner may not win, but as it is profitable for EVERY miner to front run this order, then it can be assumed that ALL miners will put in their very own front run order, in which case, guaranteed that one of them will win out. Seems like really good reason why I would never want to trade anything on the DEX if there is another market where I can be arb’d on by miners.

Very interesting. Thank you.

Does this mean that CP can only escrow value in XCP and not in BTC directly?


If there’s another (Counterparty) transaction for which there’s a fee of $1.05, for example, it’d made sense to include it rather than my own buy transaction from which the miner would make $1.

But what if there’s no such transaction? I believe in this case the miner would have to be willing to focus on arbitrage (include their own order) rather than mining. Apparently not many are willing to do that. Like I said there are elements of specialization (needs to run Counterparty and some centralized exchange API to do this) and risk in the approach because even the largest pool (say, with a 20% market share) has fairly poor chance (20%) of beating other miners who’d include whatever comes their way), so they’d have to try 5 times to score once. If they have to pay 5 cents for each try (a transaction) then it wouldn’t be a profitable operation.

I think only non-trivial transactions would provide such opportunities (say, over $20), but at the same time it is exactly such transactions that are risky to execute on DEx as well (if you want to instantly sell $50 worth of XCP, let alone some less traded token, you may need to give up 2-3% of the price as opposed to selling it over a 5 min period). So sizeable transactions provide good buy opportunities, but at the same time raise the risk of a loss when selling on a centralized exchange.

I think there’s not enough volume on the DEx to justify writing and running such a system. When BTC sell was possible from the Counterwallet GUI, at times it may have been possible.

Additionally, on a related topic, I think best (or better, at least) opportunities lie in “harvesting” old sell or buy offers, which can be done with or without front-running (and still can, but now there isn’t enough volume on the DEx to justify that). For example A:B is 1:10, someone places a 24-hour sell order 1 A for 11 B, nothing happens because it’s too expensive, but then B on Polo drops to 13 and you can buy 13 B on Polo and go to the DEx to get 1 A for just 11 of them. Last year when markets were “hot”, people were scanning the DEx on a regular basis and such opportunities would disappear fairly quickly.

If the markets become hot again, because there are no barriers to entry, there would be enough front-running miner-traders that would make it less profitable than it looks like, I think.

I think that it won’t be much extra ‘work’ on the part of the miner. The fact that CP is using Blockchain is mostly a good thing but in this regard it ends up hurting it. IF we assume that liquidity in CP assets grow, then it would be a simple task for a mining operator to scan for arbitrage opportunities as part of its own transaction valuation process which each one of them already perform when they receive a transaction in order to determine where in their queue they insert it in.

If I have to pay as a miner fee, some amount which eliminates all my gains from a potential arbitrage, what that means is that essentially all the arbitrage opportunities will belong only to the miners. Which means that there will be little incentive for me as an individual actor to participate in this market, which means this market will never achieve that level of liquidity.

I think it’d be great if bitcoin miners hunted for DEx orders.

As long as there’s more than one, prices that sellers could obtain would be better and grow to the point where the miners would get an ROI on front-running the trades similar to the one centralized exchanges make inter-mediating between the buyers and sellers.

The seller is willing to sell at the price that the miner would like to front-run (otherwise he wouldn’t make such an offer to sell). By front-running other people’s buy orders, the miner just helps the seller complete his transaction faster.

Knowing that you can sell quickly (instead of having your order hang in there for hours) at a decent price (close to Shapeshift’s perhaps?) would be great for the users. Because right now there’s little liquidity and it costs BTC to place an order, people go for the safer option and use centralized exchanges (or Shapeshift, when in need for speed).

I think there may be less incentive for you to participate as a buyer, but more incentive to participate as a seller.
I even think some buyers (like those on the go, those who don’t want to deal with centralized exchanges, etc.) may prefer to pay a slight premium over the going exchange price to use the DEx.
Right now there’s little activity on the DEx. Period. With the miners hunting for “cheap” sell orders, how could it be worse?