Our own P2P exchange

Simple example (without arbitration) as I see it. I am Maker and you are Taker.

We agree I will sell you X grin for Y USD (or any fiat, whatever), we also agree on the means of transferring money. For security, we establish rules that security deposit for both of us is also X (so you need to have at least X grin to use this method and buy X more grin).

  1. We create 2-input 1-output transaction of total value 3X, I put 2X and you put 1X. This transaction is our multi-signature escrow.
  2. We wait 10 blocks until our outputs get combined on the chain into a single block.
  3. We form two transactions using multi-signatures, the first transaction (cancel) sends me 2X and sends you 1X. The second transaction (trade) sends me 1X and sends you 2X. In both cases we get our deposits back, they differ by who gets the traded funds. Transactions are prepared but are not valid until both of us sign any of them.
  4. Now I wait until you send me the Y USD transfer.

There are two possibilities (A), (B) and from each of them two more branch out:

A. You send the transfer and I receive it.
A.1 I sign the (trade) transaction and send you the signature because I’m honest.
A.2 I sign the (cancel) signature because I want to get away with your Y USD.

B. You change your mind and decide to not send it, I still wait pending your action.
B.1 You sign the (trade) transaction and send me signature hoping I sign and broadcast it.
B.2 You sign the (cancel) transaction and send me the signature.

Analysis of each of those scenarios.

A.1 In this scenario I received the USD and the (trade) transaction is signed by me is in your possession, you can also sign and broadcast. We both get deposits back and you get X grin and I get Y USD.
A.2 If you also sign (cancel) signature you lose Y USD, we both get deposits back and I keep my X grin. You should not sign it.

B.1 If I sign the (trade) transaction you get my X grin, we both get deposits back and you keep your Y USD. This is an equivalent of A.2 for your advantage, I should not sign it.
B.2 I assume you changed your mind, I also sign it, we both get security deposits back, I get my X grin back and you keep your USD. The only loss is time and transaction fees.

We could also not do anything… But then I lose traded funds and in addition we both lose the deposits, everyone is a loser.

It’s just a simple example to illustrate, of course it has to be more sophisticated and take into account various scenarios.