swaponline / MultiCurrencyWallet

Bitcoin, Ethereum, ERC20 crypto wallets with 0x and atomic swap exchange.
https://swaponline.github.io
MIT License
475 stars 484 forks source link

SOIP 3824: Improvements to orderbook protocol #3824

Open vladiuz1 opened 3 years ago

vladiuz1 commented 3 years ago

This is not really a proposal but rather a ticket that hopefully will spawn other tickets that eventually will polish orderbook and create protocol that the swaps are not only atomic but also practical.

Right now every swap is preceding with an order in the orderbook. The orderbook is advertised in a pubsub channel in a decentralised way.

However at the moment there are major problems with SO atomic swaps

Problems

vladiuz1 commented 3 years ago

Considerations

When we solve the problems mentioned in the ticket we need to keep in mind who SO is for.

It's for people who want the convenience of a hot wallet without huge concern to security, yet fans of decentralisation and non-custodial wallets and crypto exchanges. Our users are not traders, and SO is not an exchange or a highly secure wallet. To end-users SO is a a crypto an equivalent of cash clip you keep in your pocket with the functionality of atomic swaps.

Since users of the cash clip are quite niche, in order to offer decentralised exchange we need to distinguish between market makers and market takers. These are completely different user segments with different goals and tools required.

We shall solve the problems mentioned in the ticket keeping these factors in mind.

Market makers shall have instruments to make money on arbitrage, we can safely assume market makers would be willing to put down a stake as guarantee to their fair trading.

Market takers are looking for convenience to make a swap as fast as possible. Since swaps are performed in 4 stages, we can assume they would be willing to trade decentralisation for usability within reason.

vladiuz1 commented 3 years ago

Swap Protocol Solution Brief

Alice is a wallet user who wishes to swap her coins (e.g. sells BTC and buys ETH). Alice is a Market Taker, simply enters the amount of BTC she wants to buy. SO automatically picks the best offer from advertised orders by protocol, calculates exchange rate, and amount of ETH she is going to get.

Bob is a Market Maker running an arbitrage bot that seeks opportunities to turn profits while competing with other market makers for clients by offering more attractive rates.

Bob has signed an offer to sell a minimum of 1 ETH and maximum of 100 ETH at a rate of 50 ETH for 1 BTC.

Alice accepts an offer by signing a json object with offer meta data that includes the BTC amount she wants to sell (1) and wallet she wants to receive her ETH to:

POST /request
Body-Hash: 0xec577daf6f688addbbd920478d4d2ebb
Signature: [signature_for_hash]

{
    "offer-hash": "0x32d00f53460f222733bfaf343ef7693a",
    "spend-amount": 1,
    "spend-symbol": "BTC",
    "spend-address": "1rULxmvdtHACFXWWT1WcbqyynZTe1xHDF",
    "receive-amount": 50,
    "receive-address": "0x07910f3adca830aaaeaa1dbc43c836a40da876f3",
    "receive-symbol": "ETH",
    "stamp": 1608790200
}

The request is signed by private key of bitcoin spend address (1rULxmvdtHACFXWWT1WcbqyynZTe1xHDF).

Bob accepts request by sending this object signed by his Ethereum:

POST /accept
Body-Hash: 0x63fd198416e17347696a3ddb6a806e25
Signature: [signature_for_hash]

{
    "request-hash": "0xec577daf6f688addbbd920478d4d2ebb",
    "spend-amount": 50,
    "spend-symbol": "ETH",
    "spend-address": "0x851C09E79Bc97F3C4F4B5bB6B73Ec2Eaf8405275",
    "receive-amount": 1,
    "receive-address": "3LSn6xpJeYrVyHAc2qv4dbQyDbdja9xnym",
    "receive-symbol": "BTC",
    "stamp": 1608790201,
    "secret-hash": "0x46968e3f7fe7ecaedcc64b1381447af4"
}

The accept object hash is signed by Bob's profile private key.

Alice now makes a deposit with BTC HTLC contract using the secret hash provided by Bob.

to be continued

noxonsu commented 3 years ago

htlc контракт с двумя секретами?