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.
- 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.