Swap Protocol Explained
This article tries to simplify and bring an understanding of the Swap Protocol: A peer to peer protocol for trading ethereum tokens whitepaper.
What is SWAP?
Swap in a protocol to enable peer-to-peer trading of ERC-20 tokens. Swap protocol essentially helps in finding 2 parties interested in exchanging the 2 tokens, get to an exchange value privately and finally trade the tokens.
How is it different from existing solutions?
The existing solutions work on blockchain order books.
An order book is like a ledger at an exchange, suppose you’ve to buy IBM stock at an exchange when that order comes in it is kept in a ledger like
So bidding of buying of 100 IBM stocks at 99.5 prices. This is an oversimplification of what a buy order looks like. The cost of maintaining such a system on the decentralised system such as blockchain is huge and proportionately adds to the performance constraints with increasing size of order-books. This one of the reasons why the standard practice over blockchain suffers but I digress.
In contrast to this, the approach taken by the Swap protocol is that of a pure peer-to-peer system, which supports discovery for exchange and negotiation.
Pros of the decentralized approach to trading:
- No human intervention, thereby no lag and no permission approval process.
- No control over the fund's size ie no limit on withdrawal currency.
- Open source, no risk of freezing your funds.
Before moving on understanding Swap protocol, we should cover some of the terminologies used in the protocol.
Maker: Party that provides an order.
An example can be a peer wanting to buy EOS in exchange for TRON
Taker: Party that fills the order.
A peer who wants to do the reverse as a maker is a taker.
Note: Both Maker and Taker are peers, so any party can take up any role.
Service responsible for indexing and matching various makers and takers.
Off-chain service to provide prices of orders
Contract: Smart contract on Ethereum which can be used by Taker to process an order.
Steps to a Successful trade with Peer Protocol
- Peer Discovery (this step is centralised though)
- Price Discovery
Overall the first step is peer discovery, wherein the Maker provides the trades they’re willing to make ie trade token A for a token B. At this point, no information is given about the prices publically thereby maintaining the efficiency from the peers who want to manipulate the system to change prices.
In this step, the taker can ask a maker for that particular trade.
This step involves the Taker who is interested in the trade offered by a/or many Makers.
This can make use of Oracle Protocol (optional). Wherein a party can make use of an off-chain service (3rd party) to query what is the fair price for exchanging a token with another one.
The Maker can proceed and provide the information to Taker of what price it can trade for.
Execution, Clearing and Custody
The last 3 steps are actually combined into 1 part since it involves the work done by the Smart Contract.
Once the Maker has sent an order for Taker. It can be executed by the Taker using the Smart Contract which helps in exchanging the tokens.
This step involves 2 parts in preliminary steps:
A. Check for expiration date given by Maker by the Smart Contract.
B. Check for approval by both Taker and Maker in the previous step.
Note: This makes use of approve rule available in ERC-20
Smart Contract on getting the approval can provide the clearing (this makes use of `transferFrom` available in ERC-20.
This providing the custody for respective tokens to each of the parties.
To conclude there are a lot of positives to the Swap protocol among which a few are privacy (prices are not available to the public thus less susceptible to price changes), low transaction cost (since it’s peer-to-peer and done using a smart contract) and open-source (Indexer and Oracle protocols, thus giving freedom and transparency to both end-users and implementers).
Where to go Next?
The next place would be to check out Swap Protocol White Paper and various decentralised exchanges such as Airswap, 0x, Kyber. Other than that also see Loopring (which uses its own protocol called Loopring though still decentralized).