Swapping is the most common activity in the Joint protocol. It involves the exchange of a token held in a user’s wallet for another token (liquidity) provided to a market.
A user usually initiates a swap to receive another token from a market in exchange for a token they possess in their wallet. For example, in an ETH/USDT market, users can swap USDT held in their wallet for ETH.
Users that swap are known as takers or swappers.
Types of Swap
There are two types of swaps a user can perform:
- Instant Swap: This is a swap between two tokens existing on-chain (ex: BTC for ETH).
- Synthetic Swap: This is a swap between two tokens where one exists on-chain while the other is a synthetic token representing an off-chain asset such as a local currency (e.g. USD, JPY, EUR). A synthetic swap is often called a P2P swap on centralized exchanges.
A synthetic swap involves swapping an on-chain token for an off-chain asset. In this type of swap, the synthetic asset can be anything that is transferred through an off-chain channel. So it can be anything — like a fiat, stocks etc.
Unlike instant swaps, a synthetic swap is not instant. Instead, it requires the swap participant to pass through a time-sensitive trade flow that involves securely sharing payment information, announcement and acknowledgement, releasing tokens to the taker and optionally dispute resolution if a conflict arises.
Synthetic Swap Phases
- Creation: The swap transaction is created here.
- Payment: In this phase, payment is expected to be made off-chain and announced.
- Grace: This phase is entered only when off-chain payment is not announced within the liquidity provider’s stipulated payment time.
- Cancellation: After the grace period elapses, the swap enters the cancellation phase, where the swap can be cancelled.
- Release: When payment is announced, the swap enters the release phase, where the token must be released after payment confirmation.
- Dispute: The dispute phase can be entered into after the payment announcement. Anyone of the trade participants can start a dispute.
The liquidity provider sets the swap price. A market can have many liquidity providers, each specifying a different price.
During the creation of a swap, the swapper must ensure they have enough quote tokens in their wallet. Otherwise, the swap will fail. For instance, in an ETH/USDT market where the price of 1 ETH = 1000 USDT, if the swapper intends to take 10 ETH, they must ensure they have 10,000 USDT in their wallet.
If the price of selected liquidity changes after a swap transaction has been created and broadcast to the blockchain, the swap will be cancelled if the updated price is greater than the price used in the transaction. Conversely, if the price is lower, the swap is executed using the lower price.
Depending on the market, a swap transaction is subject to at least one type of fee — market fee and protocol fee. Market fees are optional only if the market creator did not configure it.
In an instant swap, the fee is deducted from the base token received by the taker (ex: in ETH/BTC swap, the fee comes from ETH).
For a synthetic swap, the fee is deducted from the non-synthetic token.
A swap transaction will expire if it is not executed after a specified time; that is if it remained in the transaction pool for too long or the transaction was not broadcasted on time. Swap expiration is necessary to prevent the execution of a swap after the market conditions have long changed.
By default, the Joint Team interface sets the expiry time to 30 minutes but allows users to provide a custom value.
An instant swap cannot be cancelled; it can only be stopped if it expires before execution by the Joint protocol contracts. However, a synthetic swap can be cancelled if it enters the cancellation phase.